LI2 Roguelite
Functions
item.c File Reference
#include <stdlib.h>
#include <ncurses.h>
#include "item.h"
#include "map.h"
#include "cell.h"
#include "inventory.h"
Include dependency graph for item.c:

Functions

IteminitItem (char *name, char symbol, int type, int value, int x, int y, int damage, int defense, int hp, int color)
 Initialize a new item. More...
 
IteminitRock ()
 Initialize a new item: rock (weapon projectile) More...
 
IteminitSmokeBomb ()
 Initialize a new item: Smoke bomb (weapon projectile) More...
 
IteminitFireBomb ()
 Initialize a new item: Fire bomb (weapon projectile) More...
 
IteminitIceBomb ()
 Initialize a new item: Ice bomb (weapon projectile) More...
 
IteminitIronSword ()
 Initialize a new item: Iron Sword (weapon body) More...
 
IteminitGoldSword ()
 Initialize a new item: Gold Sword (weapon body) More...
 
IteminitDiamondSword ()
 Initialize a new item: Diamond Sword (weapon body) More...
 
IteminitLeatherArmor ()
 Initialize a new item: Leather armor (armor) More...
 
IteminitChainmailArmor ()
 Initialize a new item: Chainmail armor (armor) More...
 
IteminitPlateArmor ()
 Initialize a new item: Plate armor (armor) More...
 
IteminitPotionOfHealing ()
 Initialize a new item: Potion of healing. More...
 
IteminitSensoryPotion ()
 Initialize a new item: Sensory Potion. More...
 
IteminitPotionOfInvincibility ()
 Initialize a new item: Potion of invincibility. More...
 
IteminitPotOfGold ()
 Initialize a new item: Pot of gold. More...
 
ItemgenerateItem ()
 Generate a item randomly based on the probability of each item. More...
 
Item ** generateItems (int n)
 Generate n random items. More...
 
void drawItem (Item *i)
 Draw an item. More...
 
void drawAllItems (Item **items, int n)
 Draw all items in the Map. More...
 
void drawVisibleItems (Map *map, Item **items, int n)
 Draw all visible items in the Map. More...
 
ItemgetItem (Item **items, int nr_items, unsigned int x, unsigned int y)
 Get item at (x, y) in the map, also removes it from the array. More...
 
int insertItem (Item **items, int nr_items, Item *item)
 insert item into the items array (inventory) More...
 
void freeItem (void *i)
 Free an item. More...
 

Function Documentation

◆ drawAllItems()

void drawAllItems ( Item **  items,
int  n 
)

Draw all items in the Map.

Parameters
itemsArray of items to draw
nNumber of items in the array
Returns
void

◆ drawItem()

void drawItem ( Item i)

Draw an item.

Parameters
iItem to draw
Returns
void

◆ drawVisibleItems()

void drawVisibleItems ( Map map,
Item **  items,
int  n 
)

Draw all visible items in the Map.

Parameters
mapMap
itemsArray of items to draw
nNumber of items in the array
Returns
void

◆ freeItem()

void freeItem ( void *  i)

Free an item.

Parameters
iItem to free
Returns
void

◆ generateItem()

Item* generateItem ( )

Generate a item randomly based on the probability of each item.

TODO: Global variables for the probability of each item maybe

Returns
Item* Item generated

◆ generateItems()

Item** generateItems ( int  n)

Generate n random items.

Used to generate items to distribute on the map.

random items are generated based on each item probability.

Parameters
nNumber of items to generate
Returns
Item** Array of items

◆ getItem()

Item* getItem ( Item **  items,
int  nr_items,
unsigned int  x,
unsigned int  y 
)

Get item at (x, y) in the map, also removes it from the array.

TODO: use cell->item_index instead of x, y

◆ initChainmailArmor()

Item* initChainmailArmor ( )

Initialize a new item: Chainmail armor (armor)

Returns
(Item *) Chainmail armor

◆ initDiamondSword()

Item* initDiamondSword ( )

Initialize a new item: Diamond Sword (weapon body)

Returns
(Item *) Diamond Sword

◆ initFireBomb()

Item* initFireBomb ( )

Initialize a new item: Fire bomb (weapon projectile)

Returns
(Item *) Fire bomb

◆ initGoldSword()

Item* initGoldSword ( )

Initialize a new item: Gold Sword (weapon body)

Returns
(Item *) Gold Sword

◆ initIceBomb()

Item* initIceBomb ( )

Initialize a new item: Ice bomb (weapon projectile)

Returns
(Item *) Ice bomb

◆ initIronSword()

Item* initIronSword ( )

Initialize a new item: Iron Sword (weapon body)

Returns
(Item *) Iron Sword

◆ initItem()

Item* initItem ( char *  name,
char  symbol,
int  type,
int  value,
int  x,
int  y,
int  damage,
int  defense,
int  hp,
int  color 
)

Initialize a new item.

Parameters
xItem x coordinate on the map if any
yItem y coordinate on the map if any
nameItem name
symbolItem symbol
typeItem type
valueItem value
damageItem damage
defenseItem defense
hpItem hp (Healing potion)
colorItem color
Returns
Item*

◆ initLeatherArmor()

Item* initLeatherArmor ( )

Initialize a new item: Leather armor (armor)

Returns
(Item *) Leather armor

◆ initPlateArmor()

Item* initPlateArmor ( )

Initialize a new item: Plate armor (armor)

Returns
(Item *) Plate armor

◆ initPotionOfHealing()

Item* initPotionOfHealing ( )

Initialize a new item: Potion of healing.

Returns
(Item *) Potion of healing

◆ initPotionOfInvincibility()

Item* initPotionOfInvincibility ( )

Initialize a new item: Potion of invincibility.

Returns
(Item *) Potion of invincibility

◆ initPotOfGold()

Item* initPotOfGold ( )

Initialize a new item: Pot of gold.

Pot of gold is a special item that can be used to bribe the gate keeper.

It's value is between 10 and 100 gold.

It's added as gold to the player's inventory.

Returns
(Item *) Pot of gold

◆ initRock()

Item* initRock ( )

Initialize a new item: rock (weapon projectile)

Returns
(Item *) Rock

◆ initSensoryPotion()

Item* initSensoryPotion ( )

Initialize a new item: Sensory Potion.

TODO: Implement sensory potion width effect

Returns
(Item *) Sensory Potion

◆ initSmokeBomb()

Item* initSmokeBomb ( )

Initialize a new item: Smoke bomb (weapon projectile)

TODO: Implement smoke bomb effect in pathfinding functions to cut the line of sight

Returns
(Item *) Smoke bomb

◆ insertItem()

int insertItem ( Item **  items,
int  nr_items,
Item item 
)

insert item into the items array (inventory)

Returns
int the number of items in the array