Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/monst.c File Reference


Detailed Description

Monster AI, combat, placement etc.

Definition in file monst.c.

#include "crogue.h"

Go to the source code of this file.

Defines

#define NUM_HALLUNAMES   10

Functions

void monstmove (sint i)
sint monst_facing (sint monst)
void monst_remove (uint monstid)
int monst_attack_plr (int attacknum, int monster)
sint monstcanmove (sshort monst, sshort x, sshort y)
int monst_is_aligned_with_plr (int m)
sint monstbytile (ushort x, ushort y)
void compress_monsters (void)
 Rearrange the monster table so that all monsters are consecutive.

void place_monster (monster *monst, ushort x, ushort y)
 Add a monster to the monster table and the map.

const char * monstname (sint n)
 Get the name of a monster from its handle.

sint player_can_see (uint m)
 Returns whether the player can see m.

int calculate_hit (int to_hit, int defense)
 Determines whether an attack lands.

int monst_hit_plr (int attacknum, int monster)
int monst_hit_monst (int attacknum, int attacker, int target)
int monst_attack_type (int trigger, int monst, int always_hit)
void addrandommonst (void)
void addmonster (ushort x, ushort y, filelink type)
void addmonster_ptr (filelink *type, ushort x, ushort y)
void monst_takedamage (sint monstid, sint damage, sint is_melee)
void monst_heal (uint monstid, uint amt)
void monstmoveto (sint monst, sint x, sint y)
ushort monst_detect_player (ushort i)
ushort monst_can_attack_player (ushort i)
void monstmoverandomly (sint i, uint attack)
void monstmovetowardsplayer (sint i)
void monstmoveawayfromplayer (sint i)
int monst_is_peaceful (int monstid)
int monst_is_pet (int monstid)
void monst_anger (int monstid)
void scare_monster (ushort monstid)
void scare_monster_force (int monstid)
void confuse_monster (int monstid)
void gather_wandering_monsters (void)
void place_wandering_monsters (void)

Variables

const char * hallunames [NUM_HALLUNAMES]
const uint hit_chance [21]


Define Documentation

#define NUM_HALLUNAMES   10
 

Definition at line 185 of file monst.c.

Referenced by monstname().


Function Documentation

void addmonster ushort  x,
ushort  y,
filelink  type
 

Definition at line 372 of file monst.c.

References monstdesc::ai, deref_file_ptr(), deref_file_ptr_partial(), monster::energy, monster::flags, monstdesc::flags, monster::hps, monstdesc::hps_max, MONSTFLAG_GROUP, place_monster(), monster::power, monstdesc::power_max, monster::type, and uint.

Referenced by addmonster_ptr(), addrandommonst(), make_connections(), and place_shop().

void addmonster_ptr filelink type,
ushort  x,
ushort  y
 

Definition at line 396 of file monst.c.

References addmonster().

void addrandommonst void   ) 
 

Definition at line 356 of file monst.c.

References addmonster(), tile::flags, MAPDESC_CURRENT, MAPSIZE_X, MAPSIZE_Y, RANGE, world::t, TFLAG_OCCUPIED, TILEDESC, and w.

Referenced by gen_map(), and timepass().

int calculate_hit int  to_hit,
int  defense
 

Determines whether an attack lands.

Decides whether a hit is landed when an attacker with attack strength to_hit attacks a defender with DV defense. This is similar to the D20 function in that f(n, n)=1/2 and df/dH = df/dDV. However, the scale is extended to +/- 20 instead of +/- 10, and the first derivitave falls off as the to-hit and defense values separate. (Maybe some graphs should go here?)

Definition at line 250 of file monst.c.

References hit_chance, lrand(), sint, and uint.

Referenced by monst_hit_monst(), monst_hit_plr(), and plr_attack_monster_roll().

void compress_monsters void   ) 
 

Rearrange the monster table so that all monsters are consecutive.

Rearranges the monster table to improve compressibility, by making them all consecutive at the beginning of the table.

Definition at line 112 of file monst.c.

References isNull, world::m, MONSTERS_MAX, monster::type, and w.

Referenced by save_level().

void confuse_monster int  monstid  ) 
 

Definition at line 622 of file monst.c.

References monster::flags, world::m, message(), MONST_CONFUSED, monstname(), player_can_see(), and w.

Referenced by cause_confusion(), and potion_hit_confuse().

void gather_wandering_monsters void   ) 
 

Definition at line 631 of file monst.c.

References debug_realloc, isNull, world::m, monst_is_peaceful(), monst_is_pet(), monst_remove(), monstcanmove(), MONSTERS_MAX, world::plr, monster::type, w, world::wandering_monsters, world::wandering_monsters_num, player::x, and player::y.

Referenced by follow_connection().

void monst_anger int  monstid  ) 
 

Definition at line 588 of file monst.c.

References call_aifunc, monster::flags, world::m, MDESC, message(), MONST_ACTIVE, MONST_CUST_ANGER, MONST_FRIENDLY, MONST_MIMIC, MONST_PEACEFUL, monstname(), and w.

Referenced by attack_tile(), monst_attack_monst(), plr_attack(), and throw_item().

int monst_attack_plr int  attacknum,
int  monster
[static]
 

Definition at line 301 of file monst.c.

References call_attackfunc(), player::extrinsic, MATTACK, MDESC, message(), world::plr, rrandom(), STAT_DV, STAT_PV, and w.

Referenced by monst_attack_type().

int monst_attack_type int  trigger,
int  monst,
int  always_hit
 

Definition at line 320 of file monst.c.

References player::extrinsic, FACING_BEHIND, isNull, world::m, MATTACK, MDESC, message(), monst_attack_plr(), monst_facing(), monst_hit_plr(), monstname(), world::plr, STAT_DV, STAT_PV, monster::type, and w.

Referenced by monst_takedamage(), monstmove(), monstmoveto(), and plr_attack().

ushort monst_can_attack_player ushort  i  ) 
 

Definition at line 506 of file monst.c.

References distancesquare, world::m, world::plr, ushort, w, player::x, monster::x, player::y, and monster::y.

ushort monst_detect_player ushort  i  ) 
 

Definition at line 489 of file monst.c.

References distancesquare, tile::flags, world::m, world::plr, world::t, TFLAG_LIT, ushort, w, player::x, monster::x, player::y, and monster::y.

Referenced by monstmove().

sint monst_facing sint  monst  ) 
 

Definition at line 268 of file monst.c.

References delta_facing(), FACING_BEHIND, FACING_FLANK, FACING_FRONT, facing_towards(), world::m, player_facing(), sint, w, monster::x, and monster::y.

Referenced by monst_attack_type(), and monst_hit_plr().

void monst_heal uint  monstid,
uint  amt
 

Definition at line 446 of file monst.c.

References monster::hps, world::m, MDESC, and w.

Referenced by potion_hit_extra_heal(), potion_hit_full_heal(), and potion_hit_heal().

int monst_hit_monst int  attacknum,
int  attacker,
int  target
 

Definition at line 292 of file monst.c.

References calculate_hit(), MATTACK, and MDESC.

Referenced by monst_swing_monst().

int monst_hit_plr int  attacknum,
int  monster
 

Definition at line 282 of file monst.c.

References calculate_hit(), player::extrinsic, FACING_BEHIND, MATTACK, MDESC, monst_facing(), world::plr, STAT_DV, and w.

Referenced by monst_attack_type().

int monst_is_aligned_with_plr int  m  ) 
 

Definition at line 81 of file monst.c.

References world::m, world::plr, tracevision(), w, player::x, monster::x, player::y, and monster::y.

Referenced by monstmove().

int monst_is_peaceful int  monstid  ) 
 

Definition at line 570 of file monst.c.

References monster::flags, world::m, MONST_FRIENDLY, MONST_PET, and w.

Referenced by cause_confusion(), gather_wandering_monsters(), monstcanmove(), pet_move(), and plr_walk().

int monst_is_pet int  monstid  ) 
 

Definition at line 579 of file monst.c.

References monster::flags, world::m, MONST_PET, and w.

Referenced by gather_wandering_monsters(), monst_battle_pet(), monstcanmove(), and plr_walk().

void monst_remove uint  monstid  ) 
 

Definition at line 402 of file monst.c.

References draw_tile(), filelink_null, tile::flags, world::m, world::t, TFLAG_OCCUPIED, monster::type, w, monster::x, and monster::y.

Referenced by gather_wandering_monsters(), and monst_takedamage().

void monst_takedamage sint  monstid,
sint  damage,
sint  is_melee
 

Definition at line 410 of file monst.c.

References awardXP(), call_killfunc, monster::hps, world::m, max(), MDESC, message(), monst_attack_type(), monst_remove(), monstname(), MTRIGGER_DEATH, MTRIGGER_DEFENSE, player_can_see(), RANGE, scare_monster(), and w.

Referenced by attack_tile(), plr_attack(), potion_hit_sickness(), and throw_item().

sint monstbytile ushort  x,
ushort  y
 

Definition at line 92 of file monst.c.

References tile::flags, isNull, world::m, MONSTERS_MAX, sint, world::t, TFLAG_OCCUPIED, monster::type, w, monster::x, and monster::y.

Referenced by attack_tile(), draw_tile(), manip_door(), monst_battle_pet(), monstcanmove(), monstmoveto(), pet_move(), player_facing(), plr_walk(), throw_item(), tool_holysymbol(), and webspinner_cower().

sint monstcanmove sshort  monst,
sshort  x,
sshort  y
 

Definition at line 34 of file monst.c.

References distancesquare, tile::flags, world::m, MAPSIZE_X, MAPSIZE_Y, MDESC, monst_is_peaceful(), monst_is_pet(), monstbytile(), MONSTFLAG_HASHANDS, MONSTFLAG_PASSWALL, tiledesc::passable, world::plr, sint, world::t, TFLAG_OCCUPIED, world::tiledescs, tile::type, w, player::x, monster::x, player::y, and monster::y.

Referenced by gather_wandering_monsters(), monst_chat(), monstmove(), monstmoveawayfromplayer(), monstmoverandomly(), monstmovetowardsplayer(), and webspinner_build().

void monstmove sint  i  ) 
 

Definition at line 50 of file ai.c.

References call_aifunc, distancesquare, monster::flags, monster::hps, world::m, MDESC, message(), MONST_ACTIVE, monst_attack_type(), monst_battle_pet(), MONST_CONFUSED, MONST_CUST_WHEN_ACTIVE, MONST_CUST_WHEN_IDLE, monst_detect_player(), MONST_FRIENDLY, monst_is_aligned_with_plr(), MONST_PARALYZED, MONST_PEACEFUL, MONST_PET, MONST_SCARED, MONST_WANDER_WHEN_IDLE, monstcanmove(), MONSTFLAG_REGENERATE, monstmoveawayfromplayer(), monstmoverandomly(), monstmovetowardsplayer(), monstname(), MTRIGGER_RANGED, MTRIGGER_SEEN, pet_move(), player_can_see(), world::plr, monster::power, RANGE, w, monster::x, player::x, monster::y, and player::y.

Referenced by timepass().

void monstmoveawayfromplayer sint  i  ) 
 

Definition at line 548 of file monst.c.

References distancesquare, world::m, monstcanmove(), monstmoveto(), world::plr, sint, uint, w, player::x, monster::x, player::y, and monster::y.

Referenced by monstmove().

void monstmoverandomly sint  i,
uint  attack
 

Definition at line 513 of file monst.c.

References world::m, monstcanmove(), monstmoveto(), world::plr, RANGE, w, player::x, monster::x, player::y, and monster::y.

Referenced by monstmove(), and pet_move().

void monstmoveto sint  monst,
sint  x,
sint  y
 

Definition at line 457 of file monst.c.

References calc_light(), draw_tile(), tile::flags, world::m, monst_attack_type(), monst_swing_monst(), monstbytile(), MTRIGGER_NORMAL, MTRIGGER_RANGED, world::plr, world::t, TFLAG_OCCUPIED, tile::type, w, monster::x, player::x, monster::y, and player::y.

Referenced by monstmoveawayfromplayer(), monstmoverandomly(), monstmovetowardsplayer(), webspinner_build(), and webspinner_cower().

void monstmovetowardsplayer sint  i  ) 
 

Definition at line 526 of file monst.c.

References distancesquare, world::m, monstcanmove(), monstmoveto(), world::plr, sint, uint, w, player::x, monster::x, player::y, and monster::y.

Referenced by monstmove(), pet_move(), and webspinner_cower().

const char* monstname sint  n  ) 
 

Get the name of a monster from its handle.

Definition at line 201 of file monst.c.

References deref_file_ptr(), player::extrinsic, hallunames, MDESC, NUM_HALLUNAMES, world::plr, RANGE, STAT_FLAG_HALLUCINATING, STAT_FLAGS, and w.

Referenced by attack_tile(), confuse_monster(), monst_anger(), monst_attack_type(), monst_swing_monst(), monst_takedamage(), monstmove(), plr_attack(), plr_walk(), potion_hit_extra_heal(), potion_hit_full_heal(), potion_hit_heal(), potion_hit_sickness(), scare_monster_force(), and throw_item().

void place_monster monster monst,
ushort  x,
ushort  y
 

Add a monster to the monster table and the map.

If the indicated tile (x, y) is filled, the nearest clear tile is used instead. If the monster table is full, the function fails silently and nothing is done.

Definition at line 140 of file monst.c.

References distancesquare, draw_tile(), tile::flags, isNull, world::m, MAPSIZE_X, MAPSIZE_Y, MONSTERS_MAX, sint, world::t, TFLAG_OCCUPIED, TILEDESC, monster::type, uint, w, monster::x, and monster::y.

Referenced by addmonster(), and place_wandering_monsters().

void place_wandering_monsters void   ) 
 

Definition at line 649 of file monst.c.

References debug_free, place_monster(), world::plr, w, world::wandering_monsters, world::wandering_monsters_num, player::x, and player::y.

Referenced by follow_connection().

sint player_can_see uint  m  ) 
 

Returns whether the player can see m.

Definition at line 211 of file monst.c.

References player::extrinsic, tile::flags, world::m, MDESC, MONSTFLAG_INVISIBLE, world::plr, sint, STAT_FLAG_SEEINVIS, STAT_FLAGS, world::t, TFLAG_LIT, w, monster::x, and monster::y.

Referenced by confuse_monster(), draw_tile(), monst_swing_monst(), monst_takedamage(), monstmove(), and scare_monster_force().

void scare_monster ushort  monstid  ) 
 

Definition at line 606 of file monst.c.

References MDESC, MONSTFLAG_FEARLESS, and scare_monster_force().

Referenced by monst_takedamage().

void scare_monster_force int  monstid  ) 
 

Definition at line 614 of file monst.c.

References monster::flags, world::m, message(), MONST_SCARED, monstname(), player_can_see(), and w.

Referenced by scare_monster(), and tool_holysymbol().


Variable Documentation

const char* hallunames[NUM_HALLUNAMES] [static]
 

Initial value:

 {
    gettext("bugblatter beast of Traal"),
    gettext("greater hell beast"),
    gettext("invisible Asmodeus"),
    gettext("power grid bug"),
    gettext("pet kitten"),
    gettext("Usenet troll"),
    gettext("quantum mechanic"),
    gettext("Santa Claus"),
    gettext("Grinch"),
    gettext("giant hair")
}

Definition at line 186 of file monst.c.

Referenced by monstname().

const uint hit_chance[21] [static]
 

Initial value:

 {
        500, 542,
        583, 621,
        655, 685,
        711, 734,
        753, 770,
        785, 798,
        810, 820,
        829, 838,
        845, 852,
        859, 864,
        870
    }

Definition at line 227 of file monst.c.

Referenced by calculate_hit().


Generated on Thu May 20 13:12:13 2004 for CalcRogue by doxygen 1.3.6