/******************************************************************************************
	CRTEST PS   (c) 1999-2001 ISL

	inventory.h:			Inventory stuff
******************************************************************************************/

#ifndef _INVENTORY_H_
#define _INVENTORY_H_

#ifndef _MAIN_H_
	#include "main.h"	// for "void_subroutine"
#endif


// Only one set of "inventory screen" sprites can be loaded at a time.
// It's one of these:-
enum
{
	STREAMBANK_NONE,
	STREAMBANK_INVENTORYACT1,
	STREAMBANK_INVENTORYACT2,
	STREAMBANK_INVENTORYACT4,
	STREAMBANK_MAP,
	STREAMBANK_A1_PLAN1,			//5
	STREAMBANK_A1_PLAN2,			//6
	STREAMBANK_A1_PLAN3,			//7
	STREAMBANK_A2_PLAN1,			//8
	STREAMBANK_A2_PLAN2,
	STREAMBANK_A2_PLAN3,
	STREAMBANK_A2_PLAN4,
	STREAMBANK_A4_PLAN1,
	STREAMBANK_A4_PLAN2,
	STREAMBANK_A4_PLAN3,
	STREAMBANK_A4_PLAN4
};

// 5 bytes, indicating which of the above plans are available each time you
// access the inventory screen... this is determined by looking at which level we're on

extern char inventoryPlansAvailable[5];
extern char *inventoryPlanNames[5];			// And the description that's printed on the paper


// And you call this to make sure the one you want's loaded
int inventoryEnsureStreamBank(int n);



// Values returned by inventoryPickUpItem()

enum{
	INV_OK = 100,				// ok
	INV_NOSPACE,				// couldnt pick up object - not enough free slots
	INV_INVALIDOBJECT,			// this object is not recognised as something pick up-able
	INV_ALREADYHOLDING,			// we're already carrying this object, can't pick it up again
	INV_HOLDINGEGGS};			// we're already carrying six eggs, can't pick up anything else until we've gotten rid of them

// List of items within the game, sizes and the screen text that will appear when they are selected
// (basically, the list of states for each of the six slots)
// NB keep in same order as other things

enum{	
	EMPTY,

	BUTTER_KNIFE,	// Act1 items...
	RUSTY_SHEARS,
	WIRE_CUTTERS,

	A1POLES,		// Act1 part II items
	GLOVES,
	BOOTS,
	NIGHTDRESS,

	SPOON,			// Act 2 items...
	COOKING_WEIGHTS,
	MATCHES,
	FIREWORKS,
	TENNIS_RACKET,
	PRAM_CHASSIS,
	STRONG_CORD,
	BROKEN_LADDER,
	BONE,
					// Act 4 items...
	EGG,
	COGS,
	TOOLS,
	WOOD,
	OIL_CAN,
	ENGINE,
	CHAIN,
	A4POLES,
	YARN,
	BINOCULARS,
	LAUNDRY,
	GNOME,
					// Map pieces
	MAP1,
	MAP2,
	MAP3,
	MAP4,
	MAP5,
	MAP6,
	MAP7,
	MAP8,
	MAP9,
	MAP10,
	MAP11,
	MAP12,
	MAP13,
	MAP14,

	SPROUTS,

	REEL1,
	REEL2,
	REEL3,
	REEL4,
	REEL5,
	
	PIC1,
	PIC2,
	PIC3,
	PIC4,
	PIC5,
	PIC6,
	PIC7,
	PIC8,
	PIC9,
	PIC10,
	PIC11,
	PIC12,
	PIC13,
	PIC14,
	PIC15,
	PIC16,
	PIC17,
	PIC18,
	PIC19,
	PIC20,
	PIC21,
	PIC22,
	PIC23,
	PIC24,
	PIC25,
	PIC26,
	PIC27,
	PIC28,
	PIC29,
	PIC30,

	TOTAL_ITEMS};

// Also used to identify the scenic obe's
extern char *inventory_tmap_names[];

typedef struct {
	unsigned short empty_slots;				// Number of slots remaining
	unsigned short slot_contents[6];		// Contents of each slot
	unsigned short selected_slot;			// Currently selected slot
	unsigned short selected_item;			// Currently selected item
	} inventoryType;							

// Function prototypes
void inventoryLoad(void);						// Load the BG, sprites etc
void inventoryLoadMap(void);
void inventoryEnd(void);					
void inventoryCycle(void);
void inventoryStart(void);
void inventoryUploadBG(unsigned long *addr);	// Upload the BG Tim from RAM to VRAM
void inventoryDrawBG(void);
void inventoryPrintContentsToConsole(void);		// Print inventory contents to console window
void inventoryDrawSelectSquare(int x, int y, int w, int h, unsigned int colour);
void inventorySort(void);
void inventoryDrawBGOnly(void);
void inventoryDrawPlan(void);
void fmaDrawPlan(void);
void inventoryDrawMap(void);
void inventoryDrawTicksOnPlans(void);
void inventoryShowStretchedImage(TextureType *spr, int x, int y, int depth, int size, int equipped, unsigned long colour);
void inventoryDrawQuitMessage(void);
void inventoryRefreshPointers(void);
void inventoryRefreshBackPointers(void);
void inventoryBeginLevel();
void inventoryLoadInventory(void);
static void inventoryDrawNumber(int number, int x, int y, int r, int g, int b);

void inventoryRemoveDuplicateMapPieces(void);
int inventoryCheckForPlanCompletion(int plan_number);

// CPW: external variables
//extern inventoryType gingerInv;
//extern inventoryType rockyInv;
//extern inventoryType nickInv;
//extern inventoryType fetcherInv;
extern inventoryType *currentInv;





// Note that the save-game grabs the following info...
enum
{
	INVNO_GINGER,
//	INVNO_ROCKY,
//	INVNO_NICK,
//	INVNO_FETCHER,
	NUM_CHARACTER_INVS
};









extern VOID_SUBROUTINE old_draw_routine ;
extern VOID_SUBROUTINE old_cycle_routine;

// Remove an item from the inventory
unsigned short inventoryRemoveItem(unsigned short item);

// Swap an item from one inventory to another
unsigned short inventorySwapItem(unsigned short item, inventoryType *sourceInv, inventoryType *destInv);

// Check whether a particular item is held
// returns 1 if we are carrying it, otherwise 0
unsigned short inventoryCheckForItem(unsigned short item);

// Reset (empty) the inventory
void inventoryReset(void);						

// Return contents of a particular slot
unsigned short inventorySlotStatus(unsigned short slot_number); 

// Loads the required plan
void inventoryLoadPlan(int planNum);
/* Pick up an item - returns an errorcode, or INV_OK.
  
Example: -

	unsigned short pickupresult;
 
	pickupresult=inventoryPickUpItem(BONE);
	
	if(pickupresult==INV_NOSPACE)
		debugPrintf("Unable to pick up object - no space!");

	else if(pickupresult==INV_INVALIDOBJECT)
		debugPrintf("Unable to pick up object - object not recognised!");
	
	else if(pickupresult==INV_ALREADYHOLDING)
		debugPrintf("Unable to pick up object - already carrying this!");

	else 
		debugPrintf("Item picked up ok");
*/

unsigned short inventoryPickUpItem(unsigned short item);

void inventoryDoTestData(void);

extern TextureBankType *streamed_bank;
extern int	streamed_bankno;
extern TextureType *objectpics[TOTAL_ITEMS];

void inventoryEquippedItemOverlayDraw();

// Returns 1 if anything happened, or 0 if the request was ignored (in which case, you might like to try other "X" button antics)
int inventoryUseObject(int item, int autocall);
void inventoryQuit(void);

#endif
