LI2 Roguelite
Functions
inventory.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include "state.h"
#include "player.h"
#include "inventory.h"
#include "item.h"
#include "combat.h"
#include "map.h"
#include "menu.h"
Include dependency graph for inventory.c:

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...
 

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