Crossfire Server, Trunk
monster.c File Reference
#include "global.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "skills.h"
#include "spells.h"
#include "sproto.h"
#include "minheap.h"
+ Include dependency graph for monster.c:

Go to the source code of this file.

Data Structures

struct  path_data
 

Macros

#define MAX_EXPLORE   5000
 
#define MAX_KNOWN_SPELLS   20
 
#define MIN_MON_RADIUS   3
 

Functions

static uint16_t estimate_distance (int16_t ax, int16_t ay, int16_t bx, int16_t by)
 
static const char * get_reply_text_other (reply_type rt)
 
const char * get_reply_text_own (reply_type rt)
 
static int is_enemy (object *who, object *owner)
 
static void monster_apply_below (object *monster)
 
int monster_can_detect_enemy (object *op, object *enemy, rv_vector *rv)
 
static int monster_can_hit (object *ob1, object *ob2, rv_vector *rv)
 
static int monster_can_pick (object *monster, object *item)
 
int monster_can_see_enemy (object *op, object *enemy)
 
static int monster_cast_spell (object *head, object *part, object *pl, int dir)
 
static void monster_check_apply (object *mon, object *item)
 
void monster_check_apply_all (object *monster)
 
void monster_check_doors (object *op, mapstruct *m, int x, int y)
 
void monster_check_earthwalls (object *op, mapstruct *m, int x, int y)
 
objectmonster_check_enemy (object *npc, rv_vector *rv)
 
static int monster_check_good_armour (object *who, object *item)
 
static int monster_check_good_weapon (object *who, object *item)
 
static void monster_check_pickup (object *monster)
 
static int monster_check_wakeup (object *op, object *enemy, rv_vector *rv)
 
static objectmonster_choose_random_spell (object *monster)
 
static void monster_circ1_move (object *ob)
 
static void monster_circ2_move (object *ob)
 
void monster_communicate (object *op, const char *txt)
 
int monster_compute_path (object *source, object *target, int default_dir)
 
static int monster_dist_att (int dir, object *enemy, object *part, rv_vector *rv)
 
static int monster_disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 
void monster_do_living (object *op)
 
void monster_do_say (const mapstruct *map, const char *message)
 
static int monster_do_talk_npc (object *npc, talk_info *info)
 
static objectmonster_find_enemy (object *npc, rv_vector *rv)
 
objectmonster_find_nearest_enemy (object *npc, object *owner)
 
objectmonster_find_throw_ob (object *op)
 
static StringBuffermonster_format_say (const object *npc, const char *message)
 
static int monster_get_armour_quality (const object *item)
 
static int monster_get_weapon_quality (const object *item)
 
static int monster_hitrun_att (int dir, object *ob)
 
int monster_move (object *op)
 
static int monster_move_no_enemy (object *op)
 
static int monster_move_randomly (object *op)
 
void monster_npc_call_help (object *op)
 
void monster_npc_say (object *npc, const char *cp)
 
static void monster_pace2_moveh (object *ob)
 
static void monster_pace2_movev (object *ob)
 
static void monster_pace_moveh (object *ob)
 
static void monster_pace_movev (object *ob)
 
static void monster_rand_move (object *ob)
 
static int monster_run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 
static int monster_should_cast_spell (object *spell_ob)
 
int monster_stand_in_light (object *op)
 
static int monster_talk_to_npc (object *npc, talk_info *info)
 
static int monster_use_bow (object *head, object *part, object *pl, int dir)
 
static int monster_use_range (object *head, object *part, object *pl, int dir)
 
static int monster_use_scroll (object *head, object *part, object *pl, int dir)
 
static int monster_use_skill (object *head, object *part, object *pl, int dir)
 
static int monster_wait_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
 
static int monster_wait_att2 (int dir, rv_vector *rv)
 
int path_measure_func (const void *ob)
 

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

◆ MAX_EXPLORE

#define MAX_EXPLORE   5000

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

Definition at line 410 of file monster.c.

◆ MAX_KNOWN_SPELLS

#define MAX_KNOWN_SPELLS   20

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

Definition at line 1203 of file monster.c.

◆ MIN_MON_RADIUS

#define MIN_MON_RADIUS   3

Minimum monster detection radius.

Definition at line 56 of file monster.c.

Function Documentation

◆ estimate_distance()

static uint16_t estimate_distance ( int16_t  ax,
int16_t  ay,
int16_t  bx,
int16_t  by 
)
inlinestatic

Heuristic function to make the pathing follow an A* search.

(ax, ay) and (bx, by) are the cooridnates we are estinating the distance between.

Definition at line 443 of file monster.c.

References FABS, MAX, and MIN.

Referenced by monster_compute_path().

+ Here is the caller graph for this function:

◆ get_reply_text_other()

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 2328 of file monster.c.

References rt_question, rt_reply, and rt_say.

Referenced by monster_communicate().

+ Here is the caller graph for this function:

◆ get_reply_text_own()

const char* get_reply_text_own ( reply_type  rt)

Return the verb for the player's dialog type.

Parameters
rtdialog type.
Returns
verb.

Definition at line 2310 of file monster.c.

References rt_question, rt_reply, and rt_say.

Referenced by convertType(), CREMessageTypeDelegate::createEditor(), and monster_communicate().

+ Here is the caller graph for this function:

◆ is_enemy()

static int is_enemy ( object who,
object owner 
)
static

Determine if an object can be considered an enemy.

Parameters
whowho to consider, must not be NULL.
ownerpotential owner of the object we're searching an enemy for.
Returns
1 if enemy, 0 else.

Definition at line 142 of file monster.c.

References obj::contr, FLAG_GENERATOR, FLAG_MONSTER, object_get_owner(), pl::peaceful, PLAYER, QUERY_FLAG, obj::type, and autojail::who.

Referenced by monster_find_nearest_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_apply_below()

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 1968 of file monster.c.

References apply_manual(), CF_HANDLE, FLAG_IS_FLOOR, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, QUERY_FLAG, Ice::tmp, 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:

◆ monster_can_detect_enemy()

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 2569 of file monster.c.

References obj::contr, 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, obj::invisible, is_true_undead(), obj::level, llevError, LOG(), make_visible(), disinfect::map, obj::map, MAX, MAX_BUF, MIN_MON_RADIUS, monster_can_see_enemy(), monster_stand_in_light(), MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, give::name, NDI_UNIQUE, give::op, PLAYER, player_can_view(), QUERY_FLAG, query_name(), RANDOM, SK_HIDING, pl::tmp_invis, and obj::type.

Referenced by attempt_steal(), get_nearest_criminal(), 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:

◆ monster_can_hit()

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 1137 of file monster.c.

References rv_vector::distance_x, rv_vector::distance_y, FLAG_CONFUSED, get_rangevector(), obj::more, guildbuy::ob1, guildbuy::ob2, 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:

◆ monster_can_pick()

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 1887 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, and WAND.

Referenced by monster_check_pickup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_can_see_enemy()

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 2752 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, give::op, 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:

◆ monster_cast_spell()

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 1258 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, obj::type, and guild_entry::x1.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_apply()

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 1726 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, IS_ARMOR, IS_SHIELD, llevDebug, llevMonster, LOG(), mon, monster_check_good_armour(), monster_check_good_weapon(), monster_should_cast_spell(), object_find_by_type_and_race(), QUERY_FLAG, RING, ROD, SCROLL, SET_FLAG, SKILL, SPELLBOOK, TREASURE, 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:

◆ monster_check_apply_all()

void monster_check_apply_all ( object monster)

Calls monster_check_apply() for all inventory objects.

Parameters
monsterthe monster to operate on

Definition at line 1991 of file monster.c.

References fix_object(), FOR_INV_FINISH, FOR_INV_PREPARE, obj::head, commongive::inv, and monster_check_apply().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_doors()

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 2270 of file monster.c.

References AT_PHYSICAL, DOOR, FOR_MAP_FINISH, FOR_MAP_PREPARE, hit_player(), m, give::op, Ice::tmp, diamondslots::x, and diamondslots::y.

Referenced by move_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_earthwalls()

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 2254 of file monster.c.

References AT_PHYSICAL, EARTHWALL, FOR_MAP_FINISH, FOR_MAP_PREPARE, hit_player(), m, give::op, Ice::tmp, diamondslots::x, and diamondslots::y.

Referenced by move_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_enemy()

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 72 of file monster.c.

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

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:

◆ monster_check_good_armour()

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 1691 of file monster.c.

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

Referenced by monster_check_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_good_weapon()

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 1644 of file monster.c.

References monster_get_weapon_quality(), object_find_by_type_applied(), and autojail::who.

Referenced by monster_check_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_pickup()

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 1843 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, THROWN_OBJ, Ice::tmp, nlohmann::detail::void(), and obj::weight.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_check_wakeup()

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 331 of file monster.c.

References CLEAR_FLAG, rv_vector::distance, FLAG_BLIND, FLAG_SEE_IN_DARK, FLAG_SEE_INVISIBLE, FLAG_SLEEP, FLAG_STEALTH, obj::invisible, MAX, MIN_MON_RADIUS, monster_stand_in_light(), give::op, and QUERY_FLAG.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_choose_random_spell()

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 1220 of file monster.c.

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

Referenced by monster_cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_circ1_move()

static void monster_circ1_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2152 of file monster.c.

References move_object(), guildjoin::ob, RANDOM, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_circ2_move()

static void monster_circ2_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2165 of file monster.c.

References move_object(), guildjoin::ob, RANDOM, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_communicate()

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 2366 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(), MAX_BUF, talk_info::message, talk_info::message_type, monster_do_say(), monster_talk_to_npc(), MSG_TYPE_COMMUNICATION, MSG_TYPE_COMMUNICATION_SAY, NDI_WHITE, npc_dialog::npc, talk_info::npc_msg_count, talk_info::npc_msgs, give::op, P_OUT_OF_MAP, talk_info::replies, talk_info::replies_count, talk_info::replies_words, SIZEOFFREE2, talk_info::text, talk_info::who, diamondslots::x, and diamondslots::y.

Referenced by command_say().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_compute_path()

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.

Computes the path from target to source, so that the last direction is the one we need.

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 adjustment and such things to not compute all the time ; try directions randomly.

Also, do a quick check to make sure our source monster is not completely sandwiched Do this before we malloc our distance array since we can check this without needing that array.

Does not do multitile right: I keep seeing two-tile monsters that can only go south not do so because of this code. So skip multitile monsters. – 2018-05-28

It is worth noting that the variables used here are also used later – their info here is irrelevant there, and vice versa. Daniel Hawkins 2018-02-12

Definition at line 465 of file monster.c.

References absdir(), obj::attack_movement, replace::current, path_data::distance, estimate_distance(), fatal(), FOR_OB_AND_ABOVE_FINISH, FOR_OB_AND_ABOVE_PREPARE, freearr_x, freearr_y, GET_MAP_OB, mapdef::height, path_data::heuristic_dist, liv::Int, obj::map, MAX_EXPLORE, minheap_init_static(), minheap_insert(), minheap_remove(), obj::more, obj::move_type, MOVE_WALK, path_data::movement_penalty, ob_blocked(), OUT_OF_MEMORY, OUT_OF_REAL_MAP, path_measure_func(), RANDOM, RUSH, obj::stats, Ice::tmp, mapdef::width, liv::Wis, diamondslots::x, obj::x, path_data::x, diamondslots::y, obj::y, and path_data::y.

Referenced by monster_move(), and move_to().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_dist_att()

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 2046 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:

◆ monster_disthit_att()

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 2123 of file monster.c.

References absdir(), monster_dist_att(), and guildjoin::ob.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_do_living()

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 715 of file monster.c.

References CLEAR_FLAG, FABS, FLAG_MONSTER, FLAG_RUN_AWAY, FLAG_SCARED, make_face_from_files::int, MIN, give::op, QUERY_FLAG, and RANDOM.

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

+ Here is the caller graph for this function:

◆ monster_do_say()

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 2284 of file monster.c.

References ext_info_map(), disinfect::map, diamondslots::message, 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:

◆ monster_do_talk_npc()

static int monster_do_talk_npc ( object npc,
talk_info info 
)
static

Checks the messages of a NPC for a matching text. Will not call plugin events. Called by monster_talk_to_npc().

Parameters
npcobject that gets a chance to reply.
infomessage information.
Returns
1 if npc talked, 0 else.

Definition at line 2440 of file monster.c.

References add_string(), ext_info_map(), get_dialog_message(), MAGIC_EAR, MAX_NPC, MAX_REPLIES, talk_info::message, diamondslots::message, talk_info::message_type, monster_format_say(), MSG_TYPE_DIALOG, MSG_TYPE_DIALOG_MAGIC_EAR, NDI_DELAYED, NDI_NAVY, NDI_UNIQUE, npc_dialog::npc, talk_info::npc_msg_count, talk_info::npc_msgs, object_set_value(), talk_info::replies, talk_info::replies_count, talk_info::replies_words, say::reply, stringbuffer_finish_shared(), talk_info::text, use_trigger(), and autojail::value.

Referenced by monster_talk_to_npc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_find_enemy()

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 234 of file monster.c.

References buf, CLEAR_FLAG, obj::count, FLAG_BERSERK, FLAG_FRIENDLY, FLAG_NEUTRAL, FLAG_SLEEP, FLAG_UNAGGRESSIVE, get_nearest_criminal(), get_nearest_player(), get_rangevector(), HI4, MAX_BUF, monster_check_enemy(), monster_find_nearest_enemy(), monster_npc_say(), npc_dialog::npc, object_set_enemy(), object_value_set(), on_same_map(), PETMOVE, pets_get_enemy(), PLAYER, QUERY_FLAG, Ice::tmp, and obj::type.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_find_nearest_enemy()

object* monster_find_nearest_enemy ( object npc,
object owner 
)

Returns the nearest enemy (monster or generator) which is visible to npc. Directions are randomized so if multiple monsters are at the same distance, the same won't always be selected. This function is map tile aware.

Parameters
npcmonster to consider
ownerif not NULL, then search will:
  • ignore peaceful players if owner is peaceful
  • ignore other monsters with the same owner
Returns
enemy, or NULL if none found.

Definition at line 175 of file monster.c.

References can_see_monsterP(), FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, get_map_flags(), get_search_arr(), is_enemy(), llevDebug, LOG(), m, npc_dialog::npc, P_IS_ALIVE, P_OUT_OF_MAP, SIZEOFFREE, and Ice::tmp.

Referenced by monster_find_enemy(), pets_get_enemy(), and START_TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_find_throw_ob()

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 2530 of file monster.c.

References FLAG_APPLIED, FLAG_IS_THROWN, FOR_INV_FINISH, FOR_INV_PREPARE, llevDebug, LOG(), MAX_BUF, give::op, QUERY_FLAG, query_name(), and Ice::tmp.

Referenced by skill_throw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_format_say()

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 2295 of file monster.c.

References buf, MAX_BUF, diamondslots::message, give::name, npc_dialog::npc, 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:

◆ monster_get_armour_quality()

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 1670 of file monster.c.

References ATNR_PHYSICAL.

Referenced by monster_check_good_armour().

+ Here is the caller graph for this function:

◆ monster_get_weapon_quality()

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 1618 of file monster.c.

References get_attr_value(), and NUM_STATS.

Referenced by monster_check_good_weapon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_hitrun_att()

static int monster_hitrun_att ( int  dir,
object ob 
)
static

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

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

Definition at line 2080 of file monster.c.

References absdir(), and guildjoin::ob.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_move()

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 850 of file monster.c.

References absdir(), add_refcount(), ALLRUN, animate_object(), obj::attacked_by, obj::attacked_by_count, CLEAR_FLAG, rv_vector::direction, DISTATT, DISTHIT, do_hidden_move(), FABS, obj::face, 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, HITRUN, llevDebug, llevMonster, LO4, LOG(), m, 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(), give::op, rv_vector::part, mapdef::path, PETMOVE, pets_follow_owner(), QUERY_FLAG, RANDOM, remove_friendly_object(), RUNATT, RUSH, skill_attack(), obj::stats, WAIT2, WAITATT, liv::wc, obj::x, and obj::y.

Referenced by process_object().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_move_no_enemy()

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 778 of file monster.c.

References 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(), give::op, 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:

◆ monster_move_randomly()

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 377 of file monster.c.

References FLAG_UNAGGRESSIVE, move_object(), object_get_value(), object_set_value(), give::op, QUERY_FLAG, RANDOM, sstring, and autojail::value.

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:

◆ monster_npc_call_help()

void monster_npc_call_help ( object op)

A monster calls for help against its enemy.

Parameters
opmonster calling for help.

Definition at line 2004 of file monster.c.

References CLEAR_FLAG, FLAG_ALIVE, FLAG_UNAGGRESSIVE, FOR_MAP_FINISH, FOR_MAP_PREPARE, get_map_flags(), llevDebug, LOG(), m, npc_dialog::npc, object_get_value(), object_set_enemy(), give::op, P_IS_ALIVE, P_OUT_OF_MAP, QUERY_FLAG, autojail::value, diamondslots::x, and diamondslots::y.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_npc_say()

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 2485 of file monster.c.

References buf, diamondslots::message, monster_do_say(), monster_format_say(), npc_dialog::npc, and stringbuffer_finish().

Referenced by cfapi_object_say(), and monster_find_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_pace2_moveh()

static void monster_pace2_moveh ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2219 of file monster.c.

References move_object(), guildjoin::ob, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_pace2_movev()

static void monster_pace2_movev ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2204 of file monster.c.

References move_object(), guildjoin::ob, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_pace_moveh()

static void monster_pace_moveh ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2191 of file monster.c.

References move_object(), guildjoin::ob, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_pace_movev()

static void monster_pace_movev ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2178 of file monster.c.

References move_object(), guildjoin::ob, and nlohmann::detail::void().

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_rand_move()

static void monster_rand_move ( object ob)
static

Move the monster in a specified movement pattern.

Parameters
obmonster.

Definition at line 2234 of file monster.c.

References move_object(), guildjoin::ob, and RANDOM.

Referenced by monster_move_no_enemy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_run_att()

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 2065 of file monster.c.

References absdir(), monster_can_hit(), and guildjoin::ob.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_should_cast_spell()

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 1180 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:

◆ monster_stand_in_light()

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 2709 of file monster.c.

References get_map_flags(), GET_MAP_LIGHT, isqrt(), m, MAX_LIGHT_RADII, give::op, P_OUT_OF_MAP, diamondslots::x, guild_entry::x1, diamondslots::y, and guild_entry::y1.

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:

◆ monster_talk_to_npc()

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 2502 of file monster.c.

References events_execute_object_say(), FOR_INV_FINISH, FOR_INV_PREPARE, monster_do_talk_npc(), npc_dialog::npc, and talk_info::who.

Referenced by monster_communicate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_use_bow()

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 1561 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(), disinfect::map, obj::map, MOVE_FLY_LOW, object_get_owner(), QUERY_FLAG, diamondslots::x, obj::x, diamondslots::y, and obj::y.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_use_range()

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 1485 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:

◆ monster_use_scroll()

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 1344 of file monster.c.

References animate_object(), obj::animation, apply_manual(), 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(), object_get_owner(), path_to_player(), QUERY_FLAG, obj::range, SCROLL, Ice::tmp, and guild_entry::x1.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_use_skill()

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 1428 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, is_valid_types_gen::found, 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:

◆ monster_wait_att()

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 2098 of file monster.c.

References absdir(), monster_can_hit(), and guildjoin::ob.

Referenced by monster_move().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ monster_wait_att2()

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 2142 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:

◆ path_measure_func()

int path_measure_func ( const void *  ob)

Function to retrieve the measurement the minheap will organize by.

Parameters
obThe path_data object we with to observe, stored as a void *.
Returns
The estimated distance to fulfill the shortest path.

Definition at line 433 of file monster.c.

References path_data::distance, path_data::heuristic_dist, and guildjoin::ob.

Referenced by monster_compute_path().

+ Here is the caller graph for this function: