Crossfire Server, Trunk  R20513
Macros | Functions
monster.c File Reference

This deals with monster moving, attacking, using items and such. More...

#include "global.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "skills.h"
#include "spells.h"
#include "sproto.h"
Include dependency graph for monster.c:

Go to the source code of this file.

Macros

#define MAX_EXPLORE   5000
 Maximum map size to consider when finding a path in monster_compute_path(). More...
 
#define MAX_KNOWN_SPELLS   20
 Maximum number of spells to consider when choosing a spell for a monster. More...
 
#define MIN_MON_RADIUS   3
 Minimum monster detection radius. More...
 

Functions

static const char * get_reply_text_other (reply_type rt)
 Return the verb for the player's dialog type seen from others (third person). More...
 
static const char * get_reply_text_own (reply_type rt)
 Return the verb for the player's dialog type. More...
 
static void monster_apply_below (object *monster)
 If a monster who's eager to apply things encounters something apply-able, then make him apply it. More...
 
int monster_can_detect_enemy (object *op, object *enemy, rv_vector *rv)
 Determine if we can 'detect' the enemy. More...
 
static int monster_can_hit (object *ob1, object *ob2, rv_vector *rv)
 Checks if monster can hit in hand-to-hand combat. More...
 
static int monster_can_pick (object *monster, object *item)
 Check if the monster can and is interested in picking up an item. More...
 
int monster_can_see_enemy (object *op, object *enemy)
 Assuming no walls/barriers, lets check to see if its possible to see an enemy. More...
 
static int monster_cast_spell (object *head, object *part, object *pl, int dir)
 Tries to make a (part of a) monster cast a spell. More...
 
static void monster_check_apply (object *mon, object *item)
 Called after an item is inserted in a monster. More...
 
void monster_check_apply_all (object *monster)
 Calls monster_check_apply() for all inventory objects. More...
 
void monster_check_doors (object *op, mapstruct *m, int x, int y)
 Living creature attempts to open a door. More...
 
void monster_check_earthwalls (object *op, mapstruct *m, int x, int y)
 Living creature attempts to hit an earthwall. More...
 
objectmonster_check_enemy (object *npc, rv_vector *rv)
 Checks npc->enemy and returns that enemy if still valid, NULL otherwise. More...
 
static int monster_check_good_armour (object *who, object *item)
 Checks if using armor 'item' would be better for 'who'. More...
 
static int monster_check_good_weapon (object *who, object *item)
 Checks if using weapon 'item' would be better for 'who'. More...
 
static void monster_check_pickup (object *monster)
 Checks for items that monster can pick up. More...
 
static int monster_check_wakeup (object *op, object *enemy, rv_vector *rv)
 Sees if this monster should wake up. More...
 
static objectmonster_choose_random_spell (object *monster)
 Selects a spell to cast for a monster. More...
 
static void monster_circ1_move (object *ob)
 Move the monster in a specified movement pattern. More...
 
static void monster_circ2_move (object *ob)
 Move the monster in a specified movement pattern. More...
 
void monster_communicate (object *op, const char *txt)
 This function looks for an object or creature that is listening to said text. More...
 
int monster_compute_path (object *source, object *target, int default_dir)
 Computes a path from source to target. More...
 
static int monster_dist_att (int dir, object *enemy, object *part, rv_vector *rv)
 Return the direction the monster should move or look to attack an enemy. More...
 
static int monster_disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 Return the next direction the monster should move for a specific movement type. More...
 
void monster_do_living (object *op)
 For a monster, regenerate hp and sp, potentially clear scared status. More...
 
void monster_do_say (const mapstruct *map, const char *message)
 Output a NPC message on a map. More...
 
static int monster_do_talk_npc (object *npc, talk_info *info)
 Checks the messages of a NPC for a matching text. More...
 
static objectmonster_find_enemy (object *npc, rv_vector *rv)
 Tries to find an enmy for npc. More...
 
objectmonster_find_nearest_living_creature (object *npc)
 Returns the nearest living creature (monster or generator). More...
 
objectmonster_find_throw_ob (object *op)
 Find an item for the monster to throw. More...
 
static StringBuffermonster_format_say (const object *npc, const char *message)
 Format an NPC message. More...
 
static int monster_get_armour_quality (const object *item)
 Returns the "quality" value of an armour of a monster. More...
 
static int monster_get_weapon_quality (const object *item)
 Returns the "quality" value of a weapon of a monster. More...
 
static int monster_hitrun_att (int dir, object *ob, object *enemy)
 Return the next direction the monster should move for a specific movement type. More...
 
int monster_move (object *op)
 Main monster processing routine. More...
 
static int monster_move_no_enemy (object *op)
 Makes a monster without any enemy move. More...
 
static int monster_move_randomly (object *op)
 Handles random object movement. More...
 
void monster_npc_call_help (object *op)
 A monster calls for help against its enemy. More...
 
void monster_npc_say (object *npc, const char *cp)
 Simple function to have some NPC say something. More...
 
static void monster_pace2_moveh (object *ob)
 Move the monster in a specified movement pattern. More...
 
static void monster_pace2_movev (object *ob)
 Move the monster in a specified movement pattern. More...
 
static void monster_pace_moveh (object *ob)
 Move the monster in a specified movement pattern. More...
 
static void monster_pace_movev (object *ob)
 Move the monster in a specified movement pattern. More...
 
static void monster_rand_move (object *ob)
 Move the monster in a specified movement pattern. More...
 
static int monster_run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 Return the next direction the monster should move for a specific movement type. More...
 
static int monster_should_cast_spell (object *spell_ob)
 Checks if a monster should cast a spell. More...
 
int monster_stand_in_light (object *op)
 Determine if op stands in a lighted square. More...
 
static int monster_talk_to_npc (object *npc, talk_info *info)
 Give an object the chance to handle something being said. More...
 
static int monster_use_bow (object *head, object *part, object *pl, int dir)
 Tries to make a (part of a) monster fire a bow. More...
 
static int monster_use_range (object *head, object *part, object *pl, int dir)
 Monster will use a ranged attack (ROD, WAND, ...). More...
 
static int monster_use_scroll (object *head, object *part, object *pl, int dir)
 Tries to make a (part of a) monster apply a spell. More...
 
static int monster_use_skill (object *head, object *part, object *pl, int dir)
 A monster attempts using a skill. More...
 
static int monster_wait_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 Return the next direction the monster should move for a specific movement type. More...
 
static int monster_wait_att2 (int dir, rv_vector *rv)
 Return the next direction the monster should move for a specific movement type. More...
 

Detailed Description

This deals with monster moving, attacking, using items and such.

The core function is monster_move().

Definition in file monster.c.

Macro Definition Documentation

#define MAX_EXPLORE   5000

Maximum map size to consider when finding a path in monster_compute_path().

Definition at line 375 of file monster.c.

Referenced by monster_compute_path().

#define MAX_KNOWN_SPELLS   20

Maximum number of spells to consider when choosing a spell for a monster.

Definition at line 975 of file monster.c.

Referenced by monster_choose_random_spell().

#define MIN_MON_RADIUS   3

Minimum monster detection radius.

Definition at line 55 of file monster.c.

Referenced by monster_can_detect_enemy(), and monster_check_wakeup().

Function Documentation

static const char* get_reply_text_other ( reply_type  rt)
static

Return the verb for the player's dialog type seen from others (third person).

Parameters
rtdialog type.
Returns
verb.

Definition at line 2080 of file monster.c.

References rt_question, rt_reply, and rt_say.

Referenced by monster_communicate().

Here is the caller graph for this function:

static const char* get_reply_text_own ( reply_type  rt)
static

Return the verb for the player's dialog type.

Parameters
rtdialog type.
Returns
verb.

Definition at line 2062 of file monster.c.

References rt_question, rt_reply, and rt_say.

Referenced by monster_communicate().

Here is the caller graph for this function:

static void monster_apply_below ( object monster)
static

If a monster who's eager to apply things encounters something apply-able, then make him apply it.

Author
Vick's (vick@.nosp@m.bern.nosp@m..docs.nosp@m..uu..nosp@m.se)
Date
921107

Definition at line 1734 of file monster.c.

References apply_manual(), CF_HANDLE, FLAG_IS_FLOOR, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, QUERY_FLAG, TREASURE, TRIGGER, obj::will_apply, WILL_APPLY_HANDLE, and WILL_APPLY_TREASURE.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

int monster_can_detect_enemy ( object op,
object enemy,
rv_vector rv 
)

Determine if we can 'detect' the enemy.

Check for walls blocking the los. Also, just because its hidden/invisible, we may be sensitive/smart enough (based on Wis & Int) to figure out where the enemy is. -b.t.

Modified by MSW to use the get_rangevector so that map tiling works properly. I also so odd code in place that checked for x distance OR y distance being within some range - that seemed wrong - both should be within the valid range. MSW 2001-08-05

Parameters
opwho should detect.
enemywhat to detect.
rvif the function returns 1, contains the range vector towards enemy.
Returns
0 if enemy can not be detected, 1 if it is detected

Definition at line 2322 of file monster.c.

References obj::contr, mapdef::darkness, rv_vector::distance, draw_ext_info_format(), find_skill_by_number(), FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_WIZ, get_rangevector(), pl::hidden, obj::hide, liv::Int, obj::invisible, is_true_undead(), obj::level, llevError, LOG(), make_visible(), obj::map, MAX, MAX_BUF, MIN_MON_RADIUS, monster_can_see_enemy(), monster_stand_in_light(), MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, obj::name, NDI_UNIQUE, PLAYER, player_can_view(), QUERY_FLAG, query_name(), RANDOM, SK_HIDING, obj::stats, pl::tmp_invis, obj::type, and liv::Wis.

Referenced by attempt_steal(), get_nearest_player(), monster_check_enemy(), and pets_get_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_can_hit ( object ob1,
object ob2,
rv_vector rv 
)
static

Checks if monster can hit in hand-to-hand combat.

Multitile aware.

Parameters
ob1monster trying to hit.
ob2target to hit.
rvvector from ob1 to ob2.
Returns
1 if ob1 is adjacent to ob2, 0 else.
Todo:
rename to something more clear (is_adjacent?).

Definition at line 909 of file monster.c.

References rv_vector::distance_x, rv_vector::distance_y, FLAG_CONFUSED, get_rangevector(), obj::more, QUERY_FLAG, and RANDOM.

Referenced by monster_dist_att(), monster_move(), monster_run_att(), and monster_wait_att().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_can_pick ( object monster,
object item 
)
static

Check if the monster can and is interested in picking up an item.

Parameters
monstermonster to check.
itemwhat item to check against
Returns
  • 0 if item can or should not be picked by monster.
  • 1 if monster picks item.

Definition at line 1653 of file monster.c.

References obj::arch, ARROW, obj::body_info, BOW, archt::clone, FLAG_CAN_USE_SKILL, FLAG_CAST_SPELL, FLAG_IS_THROWN, FLAG_UNPAID, FLAG_USE_ARMOUR, FLAG_USE_BOW, FLAG_USE_RANGE, FLAG_USE_RING, FLAG_USE_SCROLL, FLAG_USE_SHIELD, FLAG_USE_WEAPON, FOOD, GEM, IS_ARMOR, IS_SHIELD, IS_WEAPON, MONEY, NUM_BODY_LOCATIONS, object_can_pick(), object_find_by_type_subtype(), obj::pick_up, QUERY_FLAG, RING, ROD, SCROLL, SK_THROWING, SKILL, SPELLBOOK, obj::type, and WAND.

Referenced by monster_check_pickup().

Here is the call graph for this function:

Here is the caller graph for this function:

int monster_can_see_enemy ( object op,
object enemy 
)

Assuming no walls/barriers, lets check to see if its possible to see an enemy.

Note, "detection" is different from "seeing". See monster_can_detect_enemy() for more details. -b.t.

Parameters
opwho is trying to see enemy.
enemyvictim op is trying to see.
Returns
0 if can't be seen, 1 if can be

Definition at line 2505 of file monster.c.

References mapdef::darkness, draw_ext_info(), FLAG_ALIVE, FLAG_BLIND, FLAG_SEE_IN_DARK, FLAG_SEE_INVISIBLE, FLAG_XRAYS, has_carried_lights(), HEAD, obj::hide, obj::invisible, is_true_undead(), make_visible(), makes_invisible_to(), obj::map, monster_stand_in_light(), MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, NDI_UNIQUE, PLAYER, player_can_view(), QUERY_FLAG, and obj::type.

Referenced by adj_attackroll(), attack_ob_simple(), monster_can_detect_enemy(), and pets_get_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_cast_spell ( object head,
object part,
object pl,
int  dir 
)
static

Tries to make a (part of a) monster cast a spell.

Handles sp/gr limits, and confusion.

Parameters
headhead of the monster.
partpart of the monster that we use to cast.
pltarget.
dirdirection to cast.
Returns
1 if monster casted a spell, 0 else.

Definition at line 1030 of file monster.c.

References cast_spell(), CLEAR_FLAG, liv::dam, dirdiff(), rv_vector::direction, FLAG_CAST_SPELL, FLAG_CONFUSED, FLAG_FRIENDLY, get_randomized_dir(), get_rangevector(), liv::grace, obj::inv, llevError, llevMonster, LOG(), monster_choose_random_spell(), obj::name, object_get_owner(), path_to_player(), QUERY_FLAG, obj::range, liv::sp, SP_level_spellpoint_cost(), SPELL_GRACE, SPELL_MANA, SPELLBOOK, obj::spellitem, obj::stats, and obj::type.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_check_apply ( object mon,
object item 
)
static

Called after an item is inserted in a monster.

Will look if item should be applied to replace another item.

Parameters
monmonster who picked an item.
itemwhat was picked up.
Note
Sept 96, fixed this so skills will be readied -b.t.

Definition at line 1498 of file monster.c.

References AP_APPLY, AP_IGNORE_CURSE, AP_NOPRINT, apply_can_apply_object(), apply_manual(), obj::arch, ARROW, BOW, CAN_APPLY_NOT_MASK, archt::clone, obj::count, FLAG_APPLIED, FLAG_CAST_SPELL, FLAG_READY_BOW, FLAG_READY_RANGE, FLAG_READY_SCROLL, FLAG_READY_SKILL, FLAG_USE_BOW, FLAG_USE_SCROLL, FOOD, obj::inv, IS_ARMOR, IS_SHIELD, llevDebug, llevMonster, LOG(), monster_check_good_armour(), monster_check_good_weapon(), monster_should_cast_spell(), object_find_by_type_and_race(), QUERY_FLAG, obj::race, RING, ROD, SCROLL, SET_FLAG, SKILL, SPELLBOOK, TREASURE, obj::type, WAND, WEAPON, obj::will_apply, WILL_APPLY_FOOD, and WILL_APPLY_TREASURE.

Referenced by monster_check_apply_all(), and monster_check_pickup().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_check_apply_all ( object monster)

Calls monster_check_apply() for all inventory objects.

Parameters
monsterthe monster to operate on

Definition at line 1757 of file monster.c.

References FOR_INV_FINISH, FOR_INV_PREPARE, and monster_check_apply().

Referenced by apply_auto_fix(), command_create(), fix_summon_pet(), generate_monster_arch(), generate_monster_inv(), pets_summon_object(), and polymorph_living().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_check_doors ( object op,
mapstruct m,
int  x,
int  y 
)

Living creature attempts to open a door.

Parameters
opcreature to consider.
mmap to consider.
xcoordinate.
ycoordinate.

Definition at line 2022 of file monster.c.

References AT_PHYSICAL, liv::dam, DOOR, FOR_MAP_FINISH, FOR_MAP_PREPARE, hit_player(), and obj::stats.

Referenced by move_ob().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_check_earthwalls ( object op,
mapstruct m,
int  x,
int  y 
)

Living creature attempts to hit an earthwall.

Parameters
opcreature to consider.
mmap to consider.
xcoordinate.
ycoordinate.

Definition at line 2006 of file monster.c.

References AT_PHYSICAL, liv::dam, EARTHWALL, FOR_MAP_FINISH, FOR_MAP_PREPARE, hit_player(), and obj::stats.

Referenced by move_ob().

Here is the call graph for this function:

Here is the caller graph for this function:

object* monster_check_enemy ( object npc,
rv_vector rv 
)

Checks npc->enemy and returns that enemy if still valid, NULL otherwise.

This is map tile aware. If this returns an enemy, the range vector rv should also be set to sane values.

Parameters
npcmonster we're considering
[out]rvwill contain vector to go to enemy if function returns not NULL.
Returns
valid enemy for npc.

Definition at line 71 of file monster.c.

References obj::attack_movement, obj::enemy, FLAG_FREED, FLAG_FRIENDLY, FLAG_GENERATOR, FLAG_MONSTER, FLAG_NEUTRAL, FLAG_REMOVED, GOLEM, HI4, monster_can_detect_enemy(), object_get_owner(), object_set_enemy(), on_same_map(), PETMOVE, pets_should_arena_attack(), PLAYER, QUERY_FLAG, and obj::type.

Referenced by monster_find_enemy(), and pets_get_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_check_good_armour ( object who,
object item 
)
static

Checks if using armor 'item' would be better for 'who'.

This is a very simplistic check - also checking things like speed and ac are also relevant.

Parameters
whocreature considering to apply item.
itemitem to check.
Returns
1 if item is a better object, 0 else.

Definition at line 1463 of file monster.c.

References monster_get_armour_quality(), NROFATTACKS, object_find_by_type_applied(), obj::resist, and obj::type.

Referenced by monster_check_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_check_good_weapon ( object who,
object item 
)
static

Checks if using weapon 'item' would be better for 'who'.

This is a very simplistic check - also checking things like speed and ac are also relevant.

Parameters
whocreature considering to apply item.
itemitem to check.
Returns
1 if item is a better object, 0 else.

Definition at line 1416 of file monster.c.

References monster_get_weapon_quality(), object_find_by_type_applied(), and obj::type.

Referenced by monster_check_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_check_pickup ( object monster)
static

Checks for items that monster can pick up.

Vick's (vick(at)bern.docs.uu.se) fix 921030 for the sweeper blob. Each time the blob passes over some treasure, it will grab it a.s.a.p.

Eneq((at)csd.uu.se): This can now be defined in the archetypes, added code to handle this.

This function was seen be continueing looping at one point (tmp->below became a recursive loop. It may be better to call monster_check_apply after we pick everything up, since that function may call others which affect stacking on this space.

Parameters
monstermonster that can pick up items.

Definition at line 1615 of file monster.c.

References obj::carrying, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, get_weight_limit(), MAX, MIN, monster_can_pick(), monster_check_apply(), obj::more, object_insert_in_ob(), object_split(), obj::stats, liv::Str, and obj::weight.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_check_wakeup ( object op,
object enemy,
rv_vector rv 
)
static

Sees if this monster should wake up.

Currently, this is only called from monster_move(), and if enemy is set, then so should be rv.

Parameters
opmonster to check.
enemyenemy that can cause to wake up.
[out]rvvector pointing to enemy.
Returns
1 if the monster should wake up, 0 otherwise.
Note
will return 0 if enemy is NULL.

Definition at line 296 of file monster.c.

References CLEAR_FLAG, mapdef::darkness, rv_vector::distance, FLAG_BLIND, FLAG_SEE_IN_DARK, FLAG_SEE_INVISIBLE, FLAG_SLEEP, FLAG_STEALTH, obj::invisible, obj::map, MAX, MIN_MON_RADIUS, monster_stand_in_light(), QUERY_FLAG, obj::stats, and liv::Wis.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static object* monster_choose_random_spell ( object monster)
static

Selects a spell to cast for a monster.

Returns a randomly selected spell. This logic is still less than ideal. This code also only seems to deal with wizard spells, as the check is against sp, and not grace. can monsters know cleric spells?

Parameters
monstermonster trying to cast a spell.
Returns
spell to cast, NULL if none suitable found.
Note
Will only consider the first MAX_KNOWN_SPELLS spells found.

Definition at line 992 of file monster.c.

References FOR_INV_FINISH, FOR_INV_PREPARE, MAX_KNOWN_SPELLS, monster_should_cast_spell(), RANDOM, SPELL, and SPELLBOOK.

Referenced by monster_cast_spell().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_circ1_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1904 of file monster.c.

References move_object(), obj::move_status, and RANDOM.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_circ2_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1917 of file monster.c.

References move_object(), obj::move_status, and RANDOM.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_communicate ( object op,
const char *  txt 
)

This function looks for an object or creature that is listening to said text.

The process is such:

  • first, build up information on NPCs reacting to what is said, replies
  • second, figure what the player will be displayed as said
  • third, have the player actually talk
  • fourth, the NPCs talk too
  • fifth: show the player available replies

There is a rare event that the orig_map is used for - basically, if a player says the magic word that gets him teleported off the map, it can result in the new map putting the object count too high, which forces the swap out of some other map. In some cases, the map the player was just on now gets swapped out - thus, the object on that map are no longer in memory. So check to see if the players map changes, and if so, don't process any further. If it does change, most likely we don't care about the results of further conversation. Also, depending on the value of i, the conversation would continue on the new map, which probably isn't what is really wanted either.

Parameters
opwho is saying something.
txtwhat is said.

Definition at line 2118 of file monster.c.

References draw_ext_info(), draw_ext_info_format(), ext_info_map_except(), FOR_MAP_FINISH, FOR_MAP_PREPARE, free_string(), freearr_x, freearr_y, get_map_flags(), get_reply_text_other(), get_reply_text_own(), llevDebug, LOG(), obj::map, MAX_BUF, talk_info::message, talk_info::message_type, monster_do_say(), monster_talk_to_npc(), MSG_TYPE_COMMUNICATION, MSG_TYPE_COMMUNICATION_SAY, obj::name, NDI_WHITE, talk_info::npc_msg_count, talk_info::npc_msgs, P_OUT_OF_MAP, talk_info::replies, talk_info::replies_count, talk_info::replies_words, SIZEOFFREE2, snprintf, talk_info::text, talk_info::who, obj::x, and obj::y.

Referenced by command_say().

Here is the call graph for this function:

Here is the caller graph for this function:

int monster_compute_path ( object source,
object target,
int  default_dir 
)

Computes a path from source to target.

Takes into account walls, other living things, and such. Only works if both items are on same map.

Parameters
sourcewhat wants to move.
targettarget to go to.
default_dirgeneral direction from source to target.
Returns
direction to go into. Will be default_dir if no path found.
Todo:
cache path, smart ajustment and such things to not compute all the time ; try directions randomly.

Definition at line 391 of file monster.c.

References absdir(), fatal(), freearr_x, freearr_y, mapdef::height, obj::map, MAX_EXPLORE, ob_blocked(), OUT_OF_MEMORY, OUT_OF_REAL_MAP, RANDOM, mapdef::width, obj::x, and obj::y.

Referenced by monster_move(), and move_to().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_dist_att ( int  dir,
object enemy,
object part,
rv_vector rv 
)
static

Return the direction the monster should move or look to attack an enemy.

Parameters
dirdirection the monster is currently facing.
enemytarget of the monster.
partmonster's part we're considering.
rvvector to enemy.
Returns
direction to go into.

Definition at line 1797 of file monster.c.

References absdir(), rv_vector::distance, and monster_can_hit().

Referenced by monster_disthit_att(), and monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_disthit_att ( int  dir,
object ob,
object enemy,
object part,
rv_vector rv 
)
static

Return the next direction the monster should move for a specific movement type.

Parameters
dirdirection the monster is currently facing.
obunused.
enemytarget of the monster.
partmonster's part we're considering.
rvvector to enemy.
Returns
direction to go into.

Definition at line 1875 of file monster.c.

References absdir(), liv::hp, liv::maxhp, monster_dist_att(), obj::run_away, and obj::stats.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_do_living ( object op)

For a monster, regenerate hp and sp, potentially clear scared status.

Parameters
opmonster. Must have FLAG_MONSTER set.

Definition at line 500 of file monster.c.

References CLEAR_FLAG, liv::Con, FABS, FLAG_MONSTER, FLAG_RUN_AWAY, FLAG_SCARED, liv::hp, obj::last_heal, obj::last_sp, liv::maxhp, liv::maxsp, MIN, liv::Pow, QUERY_FLAG, RANDOM, obj::run_away, liv::sp, obj::speed, and obj::stats.

Referenced by CRECombatSimulator::fight(), monster_move(), and monsterFight().

Here is the caller graph for this function:

void monster_do_say ( const mapstruct map,
const char *  message 
)

Output a NPC message on a map.

Parameters
mapwhere to talk to.
messagewhat to say.

Definition at line 2036 of file monster.c.

References ext_info_map(), MSG_TYPE_DIALOG, MSG_TYPE_DIALOG_NPC, NDI_NAVY, and NDI_UNIQUE.

Referenced by monster_communicate(), and monster_npc_say().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_do_talk_npc ( object npc,
talk_info info 
)
static
static object* monster_find_enemy ( object npc,
rv_vector rv 
)
static

Tries to find an enmy for npc.

We pass the range vector since our caller will find the information useful. Currently, only monster_move() calls this function. Fix function so that we always make calls to get_rangevector if we have a valid target - function as not doing so in many cases.

Parameters
npcmonster we're considering.
[out]rvvector that will contain how to reach the target. Must not be NULL.
Returns
enemy npc wants to attack, or NULL if nont found.

Definition at line 209 of file monster.c.

References obj::attack_movement, obj::attacked_by, obj::attacked_by_count, CLEAR_FLAG, obj::count, obj::enemy, FLAG_BERSERK, FLAG_FRIENDLY, FLAG_NEUTRAL, FLAG_SLEEP, FLAG_UNAGGRESSIVE, get_nearest_player(), get_rangevector(), HI4, monster_check_enemy(), monster_find_nearest_living_creature(), object_set_enemy(), on_same_map(), PETMOVE, pets_get_enemy(), PLAYER, QUERY_FLAG, and obj::type.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

object* monster_find_nearest_living_creature ( object npc)

Returns the nearest living creature (monster or generator).

Modified to deal with tiled maps properly. Also fixed logic so that monsters in the lower directions were more likely to be skipped - instead of just skipping the 'start' number of direction, revisit them after looking at all the other spaces.

Note that being this may skip some number of spaces, it will not necessarily find the nearest living creature - it basically chooses one from within a 3 space radius, and since it skips the first few directions, it could very well choose something 3 spaces away even though something directly north is closer.

This function is map tile aware.

Parameters
npcmonster to consider
Returns
living creature, or NULL if none found.

Definition at line 152 of file monster.c.

References can_see_monsterP(), FLAG_GENERATOR, FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, get_map_flags(), get_search_arr(), llevDebug, LOG(), obj::map, P_IS_ALIVE, P_OUT_OF_MAP, mapdef::path, PLAYER, QUERY_FLAG, SIZEOFFREE, obj::x, and obj::y.

Referenced by monster_find_enemy(), and pets_get_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

object* monster_find_throw_ob ( object op)

Find an item for the monster to throw.

Modeled on find_throw_ob(). This is probably overly simplistic as it is now - We want monsters to throw things like chairs and other pieces of furniture, even if they are not good throwable objects. Probably better to have the monster throw a throwable object first, then throw any non equipped weapon.

Parameters
opmonster to find an item to throw for.
Returns
item, NULL if none suitable.

Definition at line 2283 of file monster.c.

References FLAG_APPLIED, FLAG_IS_THROWN, FOR_INV_FINISH, FOR_INV_PREPARE, llevDebug, LOG(), MAX_BUF, obj::name, QUERY_FLAG, and query_name().

Referenced by skill_throw().

Here is the call graph for this function:

Here is the caller graph for this function:

static StringBuffer* monster_format_say ( const object npc,
const char *  message 
)
static

Format an NPC message.

Parameters
npcwho is talking.
messagewhat is being said.
Returns
new StringBuffer containing the text.

Definition at line 2047 of file monster.c.

References MAX_BUF, query_name(), stringbuffer_append_printf(), and stringbuffer_new().

Referenced by monster_do_talk_npc(), and monster_npc_say().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_get_armour_quality ( const object item)
static

Returns the "quality" value of an armour of a monster.

Higher quality values are considered better.

Parameters
itemthe item to check
Returns
the quality value

Definition at line 1442 of file monster.c.

References liv::ac, ATNR_PHYSICAL, obj::magic, obj::resist, and obj::stats.

Referenced by monster_check_good_armour().

Here is the caller graph for this function:

static int monster_get_weapon_quality ( const object item)
static

Returns the "quality" value of a weapon of a monster.

Higher quality values are considered better.

Parameters
itemthe item to check
Returns
the quality value

Definition at line 1390 of file monster.c.

References liv::dam, get_attr_value(), obj::magic, NUM_STATS, and obj::stats.

Referenced by monster_check_good_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_hitrun_att ( int  dir,
object ob,
object enemy 
)
static

Return the next direction the monster should move for a specific movement type.

Parameters
dirdirection the monster is currently facing.
obunused.
enemytarget of the monster.
Returns
direction to go into.

Definition at line 1832 of file monster.c.

References absdir(), and obj::move_status.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

int monster_move ( object op)

Main monster processing routine.

Will regenerate spell points, hit points. Moves the monster, handle attack, item applying, pickup, ...

Parameters
opmonster to process.
Returns
1 if the object has been freed, otherwise 0.

Definition at line 635 of file monster.c.

References absdir(), add_refcount(), ALLRUN, animate_object(), obj::animation_id, obj::attack_movement, obj::attacked_by, obj::attacked_by_count, CLEAR_FLAG, obj::count, mapdef::darkness, obj::direction, rv_vector::direction, DISTATT, DISTHIT, do_hidden_move(), obj::enemy, FABS, obj::face, obj::facing, FLAG_BLIND, FLAG_CAST_SPELL, FLAG_CONFUSED, FLAG_FREED, FLAG_FRIENDLY, FLAG_NO_ATTACK, FLAG_ONLY_ATTACK, FLAG_PARALYZED, FLAG_READY_BOW, FLAG_READY_RANGE, FLAG_READY_SCROLL, FLAG_READY_SKILL, FLAG_REMOVED, FLAG_RUN_AWAY, FLAG_SCARED, FLAG_SEE_IN_DARK, FLAG_SEE_INVISIBLE, FLAG_SLEEP, FLAG_STAND_STILL, free_string(), get_nearest_player(), get_randomized_dir(), get_rangevector(), HI4, obj::hide, HITRUN, llevDebug, LO4, LOG(), obj::map, MIN_ACTIVE_SPEED, monster_apply_below(), monster_can_hit(), monster_cast_spell(), monster_check_pickup(), monster_check_wakeup(), monster_compute_path(), monster_dist_att(), monster_disthit_att(), monster_do_living(), monster_find_enemy(), monster_hitrun_att(), monster_move_no_enemy(), monster_move_randomly(), monster_run_att(), monster_use_bow(), monster_use_range(), monster_use_scroll(), monster_use_skill(), monster_wait_att(), monster_wait_att2(), move_object(), obj::name, object_free_drop_inventory(), object_get_owner(), object_remove(), object_set_enemy(), on_same_map(), rv_vector::part, PETMOVE, pets_follow_owner(), obj::pick_up, QUERY_FLAG, obj::race, RANDOM, remove_friendly_object(), RUNATT, RUSH, skill_attack(), obj::speed, obj::stats, WAIT2, WAITATT, liv::wc, and obj::will_apply.

Referenced by process_object().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_move_no_enemy ( object op)
static

Makes a monster without any enemy move.

Parameters
opmonster, must have FLAG_MONSTER set.
Returns
1 if monster was removed, 0 else.

Definition at line 563 of file monster.c.

References obj::attack_movement, CIRCLE1, CIRCLE2, FLAG_MONSTER, FLAG_ONLY_ATTACK, FLAG_RANDOM_MOVE, FLAG_STAND_STILL, HI4, monster_circ1_move(), monster_circ2_move(), monster_move_randomly(), monster_pace2_moveh(), monster_pace2_movev(), monster_pace_moveh(), monster_pace_movev(), monster_rand_move(), object_free_drop_inventory(), object_remove(), PACEH, PACEH2, PACEV, PACEV2, PETMOVE, pets_move(), QUERY_FLAG, RANDO, and RANDO2.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_move_randomly ( object op)
static

Handles random object movement.

If the monster was talked to lately, then don't move and reduce wait time.

Parameters
opobject to move.
Returns
1 if moved or should wait (talked to), 0 else.

Definition at line 342 of file monster.c.

References FLAG_UNAGGRESSIVE, move_object(), object_get_value(), object_set_value(), QUERY_FLAG, and RANDOM.

Referenced by monster_move(), and monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_npc_call_help ( object op)

A monster calls for help against its enemy.

Parameters
opmonster calling for help.

Definition at line 1767 of file monster.c.

References obj::enemy, FLAG_ALIVE, FLAG_UNAGGRESSIVE, FOR_MAP_FINISH, FOR_MAP_PREPARE, get_map_flags(), obj::map, object_set_enemy(), P_IS_ALIVE, P_OUT_OF_MAP, QUERY_FLAG, obj::x, and obj::y.

Referenced by alchemy_failure_effect(), attack_ob_simple(), attempt_steal(), and hit_player().

Here is the call graph for this function:

Here is the caller graph for this function:

void monster_npc_say ( object npc,
const char *  cp 
)

Simple function to have some NPC say something.

Parameters
npcwho should say something.
cpwhat is being said.

Definition at line 2237 of file monster.c.

References obj::map, monster_do_say(), monster_format_say(), and stringbuffer_finish().

Referenced by cfapi_object_say().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_pace2_moveh ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1971 of file monster.c.

References move_object(), and obj::move_status.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_pace2_movev ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1956 of file monster.c.

References move_object(), and obj::move_status.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_pace_moveh ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1943 of file monster.c.

References move_object(), and obj::move_status.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_pace_movev ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1930 of file monster.c.

References move_object(), and obj::move_status.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static void monster_rand_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 1986 of file monster.c.

References move_object(), obj::move_status, and RANDOM.

Referenced by monster_move_no_enemy().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_run_att ( int  dir,
object ob,
object enemy,
object part,
rv_vector rv 
)
static

Return the next direction the monster should move for a specific movement type.

Parameters
dirdirection the monster is currently facing.
obunused.
enemytarget of the monster.
partmonster's part we're considering.
rvvector to enemy.
Returns
direction to go into.

Definition at line 1816 of file monster.c.

References absdir(), monster_can_hit(), and obj::move_status.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_should_cast_spell ( object spell_ob)
static

Checks if a monster should cast a spell.

Note that this function does not check to see if the monster can in fact cast the spell (sp dependencies and what not.) That is because this function is also sued to see if the monster should use spell items (rod/horn/wand/scroll).

Note that there are certainly other offensive spells that could be included, but I decided to leave out the spells that may kill more monsters than players (eg, disease).

This could be a lot smarter - if there are few monsters around, then disease might not be as bad. Likewise, if the monster is damaged, the right type of healing spell could be useful.

Parameters
spell_obspell considered.
Returns
1 is monster should cast spell sp, 0 else.
Todo:
improve logic, take enemy into consideration.

Definition at line 952 of file monster.c.

References SP_BOLT, SP_BOMB, SP_BULLET, SP_CONE, SP_EXPLOSION, SP_INVISIBLE, SP_MAGIC_MISSILE, SP_MAGIC_WALL, SP_MOVING_BALL, SP_SMITE, SP_SUMMON_GOLEM, SP_SUMMON_MONSTER, SP_SWARM, and obj::subtype.

Referenced by monster_check_apply(), monster_choose_random_spell(), and monster_use_scroll().

Here is the caller graph for this function:

int monster_stand_in_light ( object op)

Determine if op stands in a lighted square.

This is not a very intellegent algorithm. For one thing, we ignore los here, SO it is possible for a bright light to illuminate a player on the other side of a wall (!).

Parameters
opwho to check.
Returns
1 if op is in lighe, 0 else.

Definition at line 2462 of file monster.c.

References get_map_flags(), GET_MAP_LIGHT, obj::glow_radius, isqrt(), obj::map, MAX_LIGHT_RADII, P_OUT_OF_MAP, obj::x, and obj::y.

Referenced by adj_attackroll(), monster_can_detect_enemy(), monster_can_see_enemy(), and monster_check_wakeup().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_talk_to_npc ( object npc,
talk_info info 
)
static

Give an object the chance to handle something being said.

Plugin hooks will be called, including in the NPC's inventory.

Parameters
npcobject to try to talk to. Can be an NPC or a MAGIC_EAR.
infomessage information.
Returns
0 if text was handled by a plugin or not handled, 1 if handled internally by the server.

Definition at line 2254 of file monster.c.

References FOR_INV_FINISH, FOR_INV_PREPARE, monster_do_talk_npc(), plugin_event_say(), and talk_info::who.

Referenced by monster_communicate().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_use_bow ( object head,
object part,
object pl,
int  dir 
)
static

Tries to make a (part of a) monster fire a bow.

Handles confusion effect.

Parameters
headhead of the monster.
partpart of the monster that we use to cast.
pltarget.
dirdirection to cast.
Returns
1 if monster fired something, 0 else.

Definition at line 1333 of file monster.c.

References rv_vector::direction, rv_vector::distance, rv_vector::distance_x, rv_vector::distance_y, fire_bow(), FLAG_CONFUSED, FLAG_FRIENDLY, freearr_x, freearr_y, get_map_from_coord(), GET_MAP_MOVE_BLOCK, get_randomized_dir(), get_rangevector(), llevError, LOG(), obj::map, MOVE_FLY_LOW, object_get_owner(), QUERY_FLAG, obj::x, and obj::y.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_use_range ( object head,
object part,
object pl,
int  dir 
)
static

Monster will use a ranged attack (ROD, WAND, ...).

Parameters
headhead of the monster.
partpart of the monster that can do a range attack.
pltarget.
dirdirection to fire.
Returns
1 if monster casted a spell, 0 else.

Definition at line 1257 of file monster.c.

References cast_spell(), CLEAR_FLAG, obj::count, dirdiff(), rv_vector::direction, drain_rod_charge(), drain_wand_charge(), FLAG_CONFUSED, FLAG_FRIENDLY, FLAG_READY_RANGE, FOR_INV_FINISH, FOR_INV_PREPARE, get_randomized_dir(), get_rangevector(), obj::inv, llevError, LOG(), MAX, obj::name, object_get_owner(), path_to_player(), QUERY_FLAG, ROD, and WAND.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_use_scroll ( object head,
object part,
object pl,
int  dir 
)
static

Tries to make a (part of a) monster apply a spell.

Parameters
headhead of the monster.
partpart of the monster that we use to cast.
pltarget.
dirdirection to cast.
Returns
1 if monster applied a scroll, 0 else.

Definition at line 1116 of file monster.c.

References animate_object(), obj::animation_id, CLEAR_FLAG, dirdiff(), obj::direction, rv_vector::direction, obj::facing, FLAG_CONFUSED, FLAG_FRIENDLY, FLAG_READY_SCROLL, FOR_INV_FINISH, FOR_INV_PREPARE, get_randomized_dir(), get_rangevector(), obj::inv, monster_should_cast_spell(), ob_apply(), object_get_owner(), path_to_player(), QUERY_FLAG, obj::range, and SCROLL.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_use_skill ( object head,
object part,
object pl,
int  dir 
)
static

A monster attempts using a skill.

Implemented 95-04-28 to allow monster skill use. Note that monsters do not need the skills SK_MELEE_WEAPON and SK_MISSILE_WEAPON to make those respective attacks, if we required that we would drastically increase the memory requirements of CF!!

The skills we are treating here are all but those. -b.t.

At the moment this is only useful for throwing, perhaps for stealing. TODO: This should be more integrated in the game. -MT, 25.11.01

Will switch between at most 2 skills.

Parameters
headhead of the monster.
partpart of the monster that may use a skill.
pltarget.
dirdirection to cast.
Returns
1 if monster used a skill, 0 else.
Todo:
improve skill logic? Fix comments.

Definition at line 1200 of file monster.c.

References obj::chosen_skill, CLEAR_FLAG, obj::count, dirdiff(), rv_vector::direction, do_skill(), FLAG_CONFUSED, FLAG_FRIENDLY, FLAG_READY_SKILL, FOR_INV_FINISH, FOR_INV_PREPARE, get_randomized_dir(), get_rangevector(), llevDebug, LOG(), obj::name, object_get_owner(), path_to_player(), QUERY_FLAG, and SKILL.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_wait_att ( int  dir,
object ob,
object enemy,
object part,
rv_vector rv 
)
static

Return the next direction the monster should move for a specific movement type.

Parameters
dirdirection the monster is currently facing.
obunused.
enemytarget of the monster.
partmonster's part we're considering.
rvvector to enemy.
Returns
direction to go into.

Definition at line 1850 of file monster.c.

References absdir(), monster_can_hit(), and obj::move_status.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function:

static int monster_wait_att2 ( int  dir,
rv_vector rv 
)
static

Return the next direction the monster should move for a specific movement type.

Parameters
dirdirection the monster is currently facing.
rvvector to enemy.
Returns
direction to go into.

Definition at line 1894 of file monster.c.

References absdir(), and rv_vector::distance.

Referenced by monster_move().

Here is the call graph for this function:

Here is the caller graph for this function: