Angband
|
Functions for monster utilities. More...
Go to the source code of this file.
Functions | |
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_race * | lookup_monster (const char *name) |
Returns the monster with the given name. More... | |
struct monster_base * | lookup_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... | |
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 (struct loc grid1, struct loc grid2) |
Swap the players/monsters (if any) at two locations. More... | |
void | monster_wake (struct monster *mon, bool notify, int aware_chance) |
Monster wakes up and possibly becomes aware of the player. More... | |
bool | monster_can_see (struct chunk *c, struct monster *mon, struct loc grid) |
Monster can see a grid. More... | |
void | become_aware (struct monster *m) |
Make player fully aware of the given mimic. More... | |
void | update_smart_learn (struct monster *mon, 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... | |
bool | find_any_nearby_injured_kin (struct chunk *c, const struct monster *mon) |
Find out if there are any injured monsters nearby. More... | |
struct monster * | choose_nearby_injured_kin (struct chunk *c, const struct monster *mon) |
Choose one injured monster of the same base in LOS of the provided monster. More... | |
void | monster_death (struct monster *mon, bool stats) |
Handles the "death" of a monster. More... | |
bool | mon_take_nonplayer_hit (int dam, struct monster *t_mon, enum mon_messages hurt_msg, enum mon_messages die_msg) |
Deal damage to a monster from another monster (or at least not the player). More... | |
bool | mon_take_hit (struct monster *mon, int dam, bool *fear, const char *note) |
Decreases a monster's hit points by dam and handle monster death. More... | |
void | kill_arena_monster (struct monster *mon) |
void | monster_take_terrain_damage (struct monster *mon) |
Terrain damages monster. More... | |
struct monster * | get_commanded_monster (void) |
Returns the monster currently commanded, or NULL. More... | |
struct object * | get_random_monster_object (struct monster *mon) |
Get a random object from a monster's inventory. More... | |
void | steal_monster_item (struct monster *mon, int midx) |
Player or monster midx steals an item from a monster. More... | |
bool | monster_change_shape (struct monster *mon) |
Monster shapechange. More... | |
bool | monster_revert_shape (struct monster *mon) |
Monster reverse shapechange. More... | |
Functions for monster 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.
Make player fully aware of the given mimic.
When a player becomes aware of a mimic, we update the monster memory and delete the "fake item" that the monster was mimicking.
References cave, delist_object(), monster_lore::flags, monster_race::flags, get_lore(), monster::grid, object::grid, monster::mflag, mflag_has, mflag_off, monster::mimicked_obj, object::mimicking_m_idx, monster_carry(), msg, object_delete(), object_desc(), ODESC_BASE, PR_ITEMLIST, PR_MONLIST, PU_MONSTERS, PU_UPDATE_VIEW, monster::race, player_upkeep::redraw, rf_has, rf_on, square_excise_object(), square_isseen(), square_light_spot(), square_note_spot(), player_upkeep::update, and player::upkeep.
Referenced by do_cmd_open(), make_ranged_attack(), mon_take_hit(), monster_turn(), monster_turn_try_push(), move_player(), and project_o().
Choose one injured monster of the same base in LOS of the provided monster.
Scan MAX_KIN_RADIUS grids around the monster to find potential grids, make a list of kin, and choose a random one.
References get_injured_kin(), monster::grid, MAX_KIN_RADIUS, set_add(), set_choose(), set_free(), set_new(), loc::x, and loc::y.
Referenced by effect_handler_MON_HEAL_KIN().
Create a mask of monster flags of a specific type.
f | is the flag array we're filling |
... | is 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().
Return a description for the given monster race flag.
Returns an empty string for an out-of-range flag.
flag | is 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().
Find out if there are any injured monsters nearby.
See get_injured_kin() above for more details on what monsters qualify.
References get_injured_kin(), monster::grid, MAX_KIN_RADIUS, loc::x, and loc::y.
Referenced by remove_bad_spells().
Returns the monster currently commanded, or NULL.
References cave, cave_monster(), cave_monster_max(), i, monster::m_timed, and monster::race.
Referenced by decrease_timeouts(), and do_cmd_mon_command().
Get a random object from a monster's inventory.
References monster::held_obj, object::next, and randint1.
Referenced by do_cmd_mon_command(), and steal_monster_item().
References cave, cave_monster(), monster::hp, monster::midx, player_kill_monster(), and update_mon().
Referenced by run_game_loop().
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, 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 | ) |
Return the monster base matching the given name.
References monster_base::name, monster_base::next, rb_info, and streq.
Referenced by get_message_type(), match_monster_bases(), parse_lore_base(), parse_lore_friends_base(), parse_monster_base(), parse_monster_friends_base(), parse_monster_shape(), parse_pit_mon_base(), parse_prefs_monster_base(), parse_slay_base(), parse_summon_base(), player_kill_monster(), and test_defaults().
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.
This function is currently unused, except in a test... -NRM-
References lookup_monster_base(), name, and ok.
Referenced by test_match_monster_bases().
Decreases a monster's hit points by dam
and handle monster death.
Hack – we "delay" fear messages by passing around a "fear" flag.
We announce monster death (using an optional "death message" (note
) if given, and a otherwise a generic killed/destroyed message).
Returns true if the monster has been killed (and deleted).
TODO: Consider decreasing monster experience over time, say, by using "(m_exp * m_lev * (m_lev)) / (p_lev * (m_lev + n_killed))" instead of simply "(m_exp * m_lev) / (p_lev)", to make the first monster worth more than subsequent monsters. This would also need to induce changes in the monster recall code. XXX XXX XXX
References player_upkeep::arena_level, become_aware(), player_upkeep::generate_level, player_upkeep::health_who, monster::hp, mon_clear_timed(), MON_TMD_FLG_NOTIFY, monster_is_camouflaged(), monster_scared_by_damage(), monster_wake(), player_kill_monster(), PR_HEALTH, player_upkeep::redraw, and player::upkeep.
Referenced by attempt_shield_bash(), blow_knock_back(), effect_handler_CURSE(), effect_handler_JUMP_AND_BITE(), effect_handler_TAP_UNLIFE(), project_m_player_attack(), py_attack_real(), and ranged_helper().
bool mon_take_nonplayer_hit | ( | int | dam, |
struct monster * | t_mon, | ||
enum mon_messages | hurt_msg, | ||
enum mon_messages | die_msg | ||
) |
Deal damage to a monster from another monster (or at least not the player).
This is a helper for melee handlers. It is very similar to mon_take_hit(), but eliminates the player-oriented stuff of that function.
context | is the project_m context. |
hurt_msg | is the message if the monster is hurt (if any). |
References add_monster_message(), delete_monster_idx(), monster_race::flags, player_upkeep::health_who, monster::hp, monster::m_timed, message_pain(), monster::midx, monster_death(), monster_is_mimicking(), monster_scared_by_damage(), monster_wake(), PR_HEALTH, monster::race, player_upkeep::redraw, rf_has, player::upkeep, and void().
Referenced by effect_handler_DAMAGE(), melee_effect_elemental(), melee_effect_experience(), monster_damage_target(), and monster_take_terrain_damage().
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::grid, object::held_m_idx, monster::held_obj, list_object(), loc(), monster::midx, object::next, object_absorb(), object_similar(), OSTACK_MONSTER, and pile_insert().
Referenced by become_aware(), melee_effect_handler_EAT_GOLD(), mon_create_drop(), mon_create_mimicked_object(), monster_turn_grab_objects(), steal_monster_item(), and steal_player_item().
bool monster_change_shape | ( | struct monster * | mon | ) |
Monster shapechange.
References monster_shape::base, monster_race::base, cave, create_mon_spell_mask(), player::depth, monster_spell::effect, effect_simple(), FLAG_END, FLAG_START, get_mon_num(), get_mon_num_prep(), monster::grid, i, index, kin_base, monster::midx, monster_base_shape_okay(), monster_passes_walls(), monster_spell_by_index(), monster_shape::next, monster_race::num_shapes, monster::original_race, monster_shape::race, monster::race, randint0, rsf_inter, rsf_next, RSF_SIZE, RST_NONE, RST_SUMMON, select_shape(), monster_race::shapes, source_monster(), monster_race::spell_flags, square_iswall(), effect::subtype, summon_name_to_idx(), loc::x, and loc::y.
Referenced by mon_set_timed().
Handles the "death" of a monster.
Disperses treasures carried by the monster centered at the monster location. Note that objects dropped may disappear in crowded rooms.
Checks for "Quest" completion when a quest monster is killed.
Note that only the player can induce "monster_death()" on Uniques. Thus (for now) all Quest monsters should be Uniques.
If stats
is true, then we skip updating the monster memory. This is used by stats-generation code, for efficiency.
References cave, drop_near(), monster::grid, object::held_m_idx, monster::held_obj, monster_race::light, lore_treasure(), monster::mimicked_obj, monster_is_unique(), monster_is_visible(), object::next, object_delete(), object::origin, pile_excise(), PR_MONLIST, PU_UPDATE_VIEW, quest_check(), monster::race, player_upkeep::redraw, tval_is_money(), player_upkeep::update, and player::upkeep.
Referenced by mon_take_nonplayer_hit(), player_kill_monster(), and project_m_monster_attack().
bool monster_revert_shape | ( | struct monster * | mon | ) |
Monster reverse shapechange.
References cave, effect_simple(), monster::grid, monster::midx, monster_passes_walls(), monster::original_race, monster::race, source_monster(), square_iswall(), loc::x, and loc::y.
Referenced by mon_set_timed(), and player_kill_monster().
Swap the players/monsters (if any) at two locations.
References cave, cave_find_decoy(), cave_monster(), distance(), monster::grid, player::grid, monster_race::light, loc_is_zero(), angband_constants::max_sight, square::mon, PR_DTRAP, PR_MONLIST, PU_DISTANCE, PU_PANEL, PU_UPDATE_VIEW, monster::race, player_upkeep::redraw, square_destroy_decoy(), square_light_spot(), square_set_mon(), chunk::squares, player_upkeep::update, update_mon(), player::upkeep, loc::x, loc::y, and z_info.
Referenced by blow_knock_back(), call_monster(), do_cmd_mon_command(), effect_handler_EARTHQUAKE(), effect_handler_JUMP_AND_BITE(), effect_handler_TELEPORT(), effect_handler_TELEPORT_TO(), hit_trap(), monster_turn(), monster_turn_try_push(), move_player(), and thrust_away().
Terrain damages monster.
References add_monster_message(), cave, monster_race::flags, monster::grid, mon_take_nonplayer_hit(), monster_is_visible(), monster::race, randint1, rf_has, and square_isfiery().
Referenced by reset_monsters(), and thrust_away().
Monster wakes up and possibly becomes aware of the player.
References flag, monster::mflag, mflag_on, mon_clear_timed(), MON_TMD_FLG_NOMESSAGE, MON_TMD_FLG_NOTIFY, and randint0.
Referenced by call_monster(), cave_light(), do_cmd_open(), effect_handler_COMMAND(), effect_handler_EARTHQUAKE(), effect_handler_WAKE(), mon_take_hit(), mon_take_nonplayer_hit(), monster_group_rouse(), monster_reduce_sleep(), move_player(), project_m_monster_attack(), project_monster_handler_MON_HEAL(), py_attack_real(), and steal_monster_item().
Player or monster midx steals an item from a monster.
mon | Monster stolen from |
midx | Index of the thief |
References adj_dex_th, player::au, cave, player::cave, cave_monster(), delist_object(), effect_simple(), monster_race::flags, get_random_monster_object(), object::held_m_idx, monster::held_obj, inven_carry(), object::known, monster_race::level, monster::m_timed, MAX, MDESC_STANDARD, MDESC_TARG, monster::midx, mon_dec_timed(), MON_TMD_FLG_NOTIFY, monster_carry(), monster_desc(), monster_wake(), msg, monster::mspeed, object_delete(), object_desc(), object_grab(), object_see(), ODESC_FULL, ODESC_PREFIX, one_in_, pile_excise(), player_clear_timed(), object::pval, monster::race, randint1, react_to_slay(), rf_has, SKILL_STEALTH, player_state::skills, source_monster(), source_player(), player_state::speed, player_state::stat_ind, player::state, strnfmt(), player::timed, tval_is_money(), void(), and object::weight.
Referenced by do_cmd_alter_aux(), and melee_effect_handler_EAT_ITEM().
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 ABS, cave, monster::cdis, character_dungeon, disturb(), flag, FLAG_END, monster_lore::flags, monster_race::flags, flags_set(), get_lore(), monster::grid, player::grid, player_upkeep::health_who, chunk::height, ignore_item_ok(), loc(), monster::mflag, mflag_has, mflag_off, mflag_on, monster::mimicked_obj, monster_is_esp_detectable(), monster_is_in_view(), monster_is_invisible(), monster_is_mimicking(), monster_is_visible(), OPT, path_analyse(), player_of_has(), PR_HEALTH, PR_MONLIST, 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, chunk::width, loc::x, and loc::y.
Referenced by arena_gen(), detect_monsters(), kill_arena_monster(), 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 * | mon, |
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.
Note that this function is robust to being called with element
as an arbitrary PROJ_ type
References player_state::el_info, ELEM_MAX, equip_learn_element(), equip_learn_flag(), player_state::flags, monster::known_pstate, monster_is_smart(), monster_is_stupid(), of_off, of_on, one_in_, OPT, pf_has, player_state::pflags, player_of_has(), element_info::res_level, and player::state.
Referenced by effect_handler_DRAIN_MANA(), melee_effect_elemental(), melee_effect_experience(), melee_effect_handler_DISENCHANT(), melee_effect_handler_HALLU(), melee_effect_handler_POISON(), melee_effect_timed(), and player_inc_check().