LI2 Roguelite
Classes | Macros | Typedefs | Functions
inventory.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  inventory
 Inventory structure represents the player inventory. More...
 

Macros

#define INVENTORY_SIZE   10
 

Typedefs

typedef struct item Item
 
typedef struct state State
 
typedef struct inventory Inventory
 Inventory structure represents the player inventory. More...
 

Functions

InventoryinitInventory ()
 Initializes a new inventory. Allocates memory for a new inventory and initializes its fields. More...
 
void addItem (Inventory *i, Item *item)
 Adds an item to the inventory. More...
 
void removeItem (Inventory *i, Item *item)
 Removes an item from the inventory. More...
 
void sellEquippedItem (State *st, Inventory *i)
 Sells the equipped item. More...
 
void switchEquippedItem (Inventory *i)
 Switches the equipped item on a inventory. More...
 
void freeInventory (void *p)
 Frees the memory allocated for an inventory. More...
 
void useEquippedItem (State *st)
 Uses the equipped item. More...
 

Macro Definition Documentation

◆ INVENTORY_SIZE

#define INVENTORY_SIZE   10

Typedef Documentation

◆ Inventory

typedef struct inventory Inventory

Inventory structure represents the player inventory.

This struct represents the player inventory. It contains the items the player has picked up, the equipped item and is index in the inventory, and the amount of gold.

Parameters
itemsthe items in the inventory
nr_itemsthe number of items in the inventory
equipped_itemthe equipped item
equiped_indexthe index of the equipped item
equipped_swordthe equipped sword
equipped_armorthe equipped armor
goldthe amount of gold in the inventory

◆ Item

typedef struct item Item

◆ State

typedef struct state State

Function Documentation

◆ addItem()

void addItem ( Inventory i,
Item item 
)

Adds an item to the inventory.

Adds an item to the inventory. If the inventory is full, the item is not added. If the item is a rock, the number of rocks is increased. // free item

Parameters
iInventory to add item to
itemItem to add
Returns
void

◆ freeInventory()

void freeInventory ( void *  p)

Frees the memory allocated for an inventory.

Frees the memory allocated for an inventory.

Parameters
pInventory to free
Returns
void

◆ initInventory()

Inventory* initInventory ( )

Initializes a new inventory. Allocates memory for a new inventory and initializes its fields.

Returns
Inventory* Initialized inventory

◆ removeItem()

void removeItem ( Inventory i,
Item item 
)

Removes an item from the inventory.

Removes an item from the inventory. If the item is not in the inventory, nothing happens.

Parameters
iInventory to remove item from
itemItem to remove
Returns
void

◆ sellEquippedItem()

void sellEquippedItem ( State st,
Inventory i 
)

Sells the equipped item.

Sells the equipped item. If the equipped item is NULL, nothing happens.

Parameters
iInventory to sell equipped item
stState to send menu message (Other option send msg before calling this function)
Returns
void

◆ switchEquippedItem()

void switchEquippedItem ( Inventory i)

Switches the equipped item on a inventory.

Switches the equipped item on a inventory. If there is no possible equipable item, nothing happens.

Parameters
iInventory to switch equipped item
Returns
void

◆ useEquippedItem()

void useEquippedItem ( State st)

Uses the equipped item.

Uses the equipped item. If the equipped item is a potion of healing, the player's health is increased. Receives a State struct as argument because needs to update the player, the map and game stats.

Parameters
stState to use the equipped item
Returns
void