Macros | Functions | Variables
mon-util.c File Reference

Monster manipulation utilities. More...

#include "angband.h"
#include "game-world.h"
#include "init.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-msg.h"
#include "mon-spell.h"
#include "mon-timed.h"
#include "mon-list.h"
#include "mon-util.h"
#include "obj-desc.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-pile.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "player-util.h"
#include "list-mon-race-flags.h"


#define RF(a, b, c)   { RF_##a, b, c },


const char * describe_race_flag (int flag)
 Return a description for the given monster race flag. More...
void create_mon_flag_mask (bitflag *f,...)
 Create a mask of monster flags of a specific type. More...
struct monster_racelookup_monster (const char *name)
 Returns the monster with the given name. More...
struct monster_baselookup_monster_base (const char *name)
 Return the monster base matching the given name. More...
bool match_monster_bases (const struct monster_base *base,...)
 Return whether the given base matches any of the names given. More...
bool monster_is_nonliving (struct monster_race *race)
 Nonliving monsters are immune to life drain. More...
bool monster_is_unusual (struct monster_race *race)
 Nonliving and stupid monsters are destroyed rather than dying. More...
void update_mon (struct monster *mon, struct chunk *c, bool full)
 This function updates the monster record of the given monster. More...
void update_monsters (bool full)
 Updates all the (non-dead) monsters via update_mon(). More...
bool monster_carry (struct chunk *c, struct monster *mon, struct object *obj)
 Add the given object to the given monster's inventory. More...
void monster_swap (int y1, int x1, int y2, int x2)
 Swap the players/monsters (if any) at two locations. More...
void become_aware (struct monster *mon)
 Make player fully aware of the given mimic. More...
bool is_mimicking (struct monster *mon)
 Returns true if the given monster is currently mimicking an item. More...
void update_smart_learn (struct monster *m, struct player *p, int flag, int pflag, int element)
 The given monster learns about an "observed" resistance or other player state property, or lack of it. More...


static const struct monster_flag monster_flag_table []

Detailed Description

Monster manipulation utilities.

Copyright (c) 1997-2007 Ben Harrison, James E. Wilson, Robert A. Koeneke

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define RF (   a,
)    { RF_##a, b, c },

Function Documentation

void become_aware ( struct monster mon)
void create_mon_flag_mask ( bitflag f,

Create a mask of monster flags of a specific type.

fis the flag array we're filling the list of flags we're looking for

N.B. RFT_MAX must be the last item in the ... list

References args, i, monster_flag::index, RF_MAX, rf_on, rf_wipe, RFT_MAX, and monster_flag::type.

Referenced by lore_append_abilities(), lore_append_movement(), and lore_update().

const char* describe_race_flag ( int  flag)

Return a description for the given monster race flag.


Returns an empty string for an out-of-range flag.

flagis one of the RF_ flags.

References monster_flag::desc, flag, and RF_MAX.

Referenced by lore_append_abilities(), lore_append_clause(), and lore_append_movement().

bool is_mimicking ( struct monster mon)
struct monster_race* lookup_monster ( const char *  name)

Returns the monster with the given name.

If no monster has the exact name given, returns the first monster with the given name as a (case-insensitive) substring.

References i, my_stricmp(), my_stristr(), monster_race::name, NULL, r_info, angband_constants::r_max, and z_info.

Referenced by finish_parse_lore(), finish_parse_monster(), get_debug_command(), parse_lore_name(), parse_pit_mon_ban(), parse_prefs_monster(), parse_quest_race(), rd_item(), rd_monster(), rd_monster_memory(), and test_match_monster_bases().

struct monster_base* lookup_monster_base ( const char *  name)
bool match_monster_bases ( const struct monster_base base,

Return whether the given base matches any of the names given.

Accepts a variable-length list of name strings. The list must end with NULL.

References lookup_monster_base(), name, NULL, and ok.

Referenced by summon_specific_okay(), and test_match_monster_bases().

bool monster_carry ( struct chunk c,
struct monster mon,
struct object obj 

Add the given object to the given monster's inventory.

Currently always returns true - it is left as a bool rather than void in case a limit on monster inventory size is proposed in future.

References object::held_m_idx, monster::held_obj, object::ix, object::iy, list_object(), monster::midx, object::next, object_absorb(), object_similar(), OSTACK_MONSTER, and pile_insert().

Referenced by become_aware(), melee_effect_handler_EAT_GOLD(), melee_effect_handler_EAT_ITEM(), mon_create_drop(), place_monster(), and process_monster_grab_objects().

bool monster_is_nonliving ( struct monster_race race)

Nonliving monsters are immune to life drain.

References FLAG_END, monster_race::flags, flags_test(), RF_DEMON, and RF_SIZE.

Referenced by monster_is_unusual(), and project_monster_handler_MON_DRAIN().

bool monster_is_unusual ( struct monster_race race)

Nonliving and stupid monsters are destroyed rather than dying.

References monster_race::flags, monster_is_nonliving(), and rf_has.

Referenced by look_mon_desc(), mon_take_hit(), project_m(), and ranged_helper().

void monster_swap ( int  y1,
int  x1,
int  y2,
int  x2 
void update_mon ( struct monster mon,
struct chunk c,
bool  full 

This function updates the monster record of the given monster.

This involves extracting the distance to the player (if requested), and then checking for visibility (natural, infravision, see-invis, telepathy), updating the monster visibility flag, redrawing (or erasing) the monster when its visibility changes, and taking note of any interesting monster flags (cold-blooded, invisible, etc).

Note the new "mflag" field which encodes several monster state flags, including "view" for when the monster is currently in line of sight, and "mark" for when the monster is currently visible via detection.

The only monster fields that are changed here are "cdis" (the distance from the player), "ml" (visible to the player), and "mflag" (to maintain the "MFLAG_VIEW" flag).

Note the special "update_monsters()" function which can be used to call this function once for every monster.

Note the "full" flag which requests that the "cdis" field be updated; this is only needed when the monster (or the player) has moved.

Every time a monster moves, we must call this function for that monster, and update the distance, and the visibility. Every time the player moves, we must call this function for every monster, and update the distance, and the visibility. Whenever the player "state" changes in certain ways ("blindness", "infravision", "telepathy", and "see invisible"), we must call this function for every monster, and update the visibility.

Routines that change the "illumination" of a grid must also call this function for any monster in that grid, since the "visibility" of some monsters may be based on the illumination of their grid.

Note that this function is called once per monster every time the player moves. When the player is running, this function is one of the primary bottlenecks, along with "update_view()" and the "process_monsters()" code, so efficiency is important.

Note the optimized "inline" version of the "distance()" function.

A monster is "visible" to the player if (1) it has been detected by the player, (2) it is close to the player and the player has telepathy, or (3) it is close to the player, and in line of sight of the player, and it is "illuminated" by some combination of infravision, torch light, or permanent light (invisible monsters are only affected by "light" if the player can see invisible).

Monsters which are not on the current panel may be "visible" to the player, and their descriptions will include an "offscreen" reference. Currently, offscreen monsters cannot be targeted or viewed directly, but old targets will remain set. XXX XXX

The player can choose to be disturbed by several things, including "OPT(player, disturb_near)" (monster which is "easily" viewable moves in some way). Note that "moves" includes "appears" and "disappears".

References monster::cdis, character_dungeon, disturb(), flag, FLAG_END, monster_lore::flags, monster_race::flags, flags_set(), monster::fx, monster::fy, get_lore(), player_upkeep::health_who, chunk::height, ignore_item_ok(), is_mimicking(), mask, monster::mflag, mflag_has, mflag_off, mflag_on, mflag_union, monster::midx, monster::mimicked_obj, NULL, OPT, player_of_has(), PR_HEALTH, PR_MONLIST, player::px, player::py, monster::race, player_upkeep::redraw, rf_has, rf_on, RF_SIZE, monster_lore::sights, square_isno_esp(), square_isseen(), square_isview(), square_light_spot(), player::timed, player::upkeep, and chunk::width.

Referenced by effect_handler_DETECT_EVIL(), effect_handler_DETECT_INVISIBLE_MONSTERS(), effect_handler_DETECT_VISIBLE_MONSTERS(), monster_swap(), place_monster(), process_player_cleanup(), project_m(), and update_monsters().

void update_monsters ( bool  full)

Updates all the (non-dead) monsters via update_mon().

References cave, cave_monster(), cave_monster_max(), i, monster::race, and update_mon().

Referenced by update_stuff().

void update_smart_learn ( struct monster m,
struct player p,
int  flag,
int  pflag,
int  element 

Variable Documentation

const struct monster_flag monster_flag_table[]