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

Functions

MonsterinitMonster (int x, int y, int health, int attack, int defense, char symbol, char *name, int color, int pathfinding, int gold, const char *noise, int index)
 Initialize a new monster. More...
 
MonsterinitRat (int x, int y, int index)
 Initialize a new monster: rat. More...
 
MonsterinitGoblin (int x, int y, int index)
 Initialize a new monster: goblin. More...
 
MonsterinitOrc (int x, int y, int index)
 Initialize a new monster: orc. More...
 
MonsterinitTroll (int x, int y, int index)
 Initialize a new monster: troll. More...
 
MonsterinitDragon (int x, int y, int index)
 Initialize a new monster: dragon. More...
 
void drawMonster (State *st, Monster *monster, int mode)
 Draw the monster on the map. More...
 
void drawMonsters (State *st)
 Draw all the monsters on the map. More...
 
void moveMonster (State *st, Monster *monster, int x, int y)
 Move the monster to the given coordinates. More...
 
void moveMonsterRandom (State *st, Monster *monster)
 Move the monster randomly. More...
 
void monsterPathfinding (State *st, Monster *monster)
 Pathfinding algorithm to find the shortest path to the player. More...
 
void monsterPathfindingAway (State *st, Monster *monster)
 Pathfinding algorithm to find the furthest path to the player. More...
 
MonstergenerateMonster (Map *map, int index)
 Generate one monster randomly. More...
 
Monster ** generateMonsters (Map *map)
 Generate monsters array randomly. More...
 
void moveMonsters (State *st, Monster **monsters, int nMonsters)
 Move all the monsters. More...
 
void freeMonster (void *p)
 Free the monster. More...
 

Function Documentation

◆ drawMonster()

void drawMonster ( State st,
Monster monster,
int  mode 
)

Draw the monster on the map.

Parameters
stThe game state
monsterMonster to draw
modeThe game mode draw monsters in (VISION_MODE, NORMAL_MODE, DISTANCE_MODE)

◆ drawMonsters()

void drawMonsters ( State st)

Draw all the monsters on the map.

Parameters
stThe game state

◆ freeMonster()

void freeMonster ( void *  p)

Free the monster.

Parameters
pa pointer to the Monster to free
Returns
void

◆ generateMonster()

Monster* generateMonster ( Map map,
int  index 
)

Generate one monster randomly.

Same probability for each monster type.

Parameters
mapThe game map
indexMonster index relative to the monsters array
Returns
Monster* The generated monster

◆ generateMonsters()

Monster** generateMonsters ( Map map)

Generate monsters array randomly.

Parameters
mapThe game map
Returns
Monster** The monsters array with NUMBER_OF_MONSTERS monsters

◆ initDragon()

Monster* initDragon ( int  x,
int  y,
int  index 
)

Initialize a new monster: dragon.

Parameters
xStarting x coordinate
yStarting y coordinate
indexMonster index relative to the monsters array
Returns
Monster*

◆ initGoblin()

Monster* initGoblin ( int  x,
int  y,
int  index 
)

Initialize a new monster: goblin.

Parameters
xStarting x coordinate
yStarting y coordinate
indexMonster index relative to the monsters array
Returns
Monster*

◆ initMonster()

Monster* initMonster ( int  x,
int  y,
int  health,
int  attack,
int  defense,
char  symbol,
char *  name,
int  color,
int  pathfinding,
int  gold,
const char *  noise,
int  index 
)

Initialize a new monster.

Parameters
xMonster x coordinate
yMonster y coordinate
healthMonster health points
attackMonster attack points
defenseMonster defense points
symbolMonster symbol
nameMonster name
colorMonster color
pathfindingMonster pathfinding type
goldMonster gold value when killed
noiseMonster noise
indexMonster index in the monsters array also stored in the cell (used as a pointer)
Returns
Monster*

◆ initOrc()

Monster* initOrc ( int  x,
int  y,
int  index 
)

Initialize a new monster: orc.

Parameters
xStarting x coordinate
yStarting y coordinate
indexMonster index relative to the monsters array
Returns
Monster*

◆ initRat()

Monster* initRat ( int  x,
int  y,
int  index 
)

Initialize a new monster: rat.

Parameters
xStarting x coordinate
yStarting y coordinate
indexMonster index relative to the monsters array
Returns
Monster*

◆ initTroll()

Monster* initTroll ( int  x,
int  y,
int  index 
)

Initialize a new monster: troll.

Parameters
xStarting x coordinate
yStarting y coordinate
indexMonster index relative to the monsters array
Returns
Monster*

◆ monsterPathfinding()

void monsterPathfinding ( State st,
Monster monster 
)

Pathfinding algorithm to find the shortest path to the player.

Calculates the path if any else return a message to the menu. Moves the monster to the cell in the path with the lowest distance to the player.

Parameters
stThe game state
monsterThe monster to move

◆ monsterPathfindingAway()

void monsterPathfindingAway ( State st,
Monster monster 
)

Pathfinding algorithm to find the furthest path to the player.

Checks the distance field of the cells around the monster and moves to the cell with the highest distance to the player.

Parameters
stThe game state
monsterThe monster to move

◆ moveMonster()

void moveMonster ( State st,
Monster monster,
int  x,
int  y 
)

Move the monster to the given coordinates.

Update the monster's coordinates and the cell's monster_index

Parameters
stThe game state
monsterThe monster to move
xX coordinates to move the monster to
yY coordinates to move the monster to

◆ moveMonsterRandom()

void moveMonsterRandom ( State st,
Monster monster 
)

Move the monster randomly.

Checks the available walkable cells around the monster and moves the monster randomly to one of them.

Parameters
stThe game state
monsterThe monster to move randomly

◆ moveMonsters()

void moveMonsters ( State st,
Monster **  monsters,
int  nMonsters 
)

Move all the monsters.

Monster movements vary depending on the monster pathfinding type and the map obstacles.

Parameters
stThe game state
monstersThe monsters array
nMonstersThe number of monsters
Returns
void