Angband
Typedefs | Enumerations | Functions
mon-lore.c File Reference

Monster memory code. More...

#include "angband.h"
#include "effects.h"
#include "init.h"
#include "mon-blows.h"
#include "mon-init.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-predicate.h"
#include "mon-spell.h"
#include "mon-util.h"
#include "obj-gear.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "project.h"
#include "z-textblock.h"

Typedefs

typedef enum monster_sex monster_sex_t
 

Enumerations

enum  monster_sex { MON_SEX_NEUTER = 0, MON_SEX_MALE, MON_SEX_FEMALE, MON_SEX_MAX }
 Monster genders. More...
 

Functions

int spell_color (struct player *p, int spell_index)
 Determine the color to code a monster spell. More...
 
int blow_color (struct player *p, int blow_idx)
 Determine the color to code a monster melee blow effect. More...
 
void lore_learn_spell_if_has (struct monster_lore *lore, const struct monster_race *race, int flag)
 
void lore_learn_spell_if_visible (struct monster_lore *lore, const struct monster *mon, int flag)
 
void lore_learn_flag_if_visible (struct monster_lore *lore, const struct monster *mon, int flag)
 
void lore_update (const struct monster_race *race, struct monster_lore *lore)
 Update which bits of lore are known. More...
 
void cheat_monster_lore (const struct monster_race *race, struct monster_lore *lore)
 Learn everything about a monster. More...
 
void wipe_monster_lore (const struct monster_race *race, struct monster_lore *lore)
 Forget everything about a monster. More...
 
void lore_do_probe (struct monster *mon)
 Learn about a monster (by "probing" it) More...
 
bool lore_is_fully_known (const struct monster_race *race)
 Determine whether the monster is fully known. More...
 
void lore_treasure (struct monster *mon, int num_item, int num_gold)
 Take note that the given monster just dropped some treasure. More...
 
void monster_flags_known (const struct monster_race *race, const struct monster_lore *lore, bitflag flags[RF_SIZE])
 Copies into flags the flags of the given monster race that are known to the given lore structure (usually the player's knowledge). More...
 
static const char * lore_describe_awareness (s16b awareness)
 Return a description for the given monster race awareness value. More...
 
static const char * lore_describe_speed (byte speed)
 Return a description for the given monster race speed value. More...
 
static monster_sex_t lore_monster_sex (const struct monster_race *race)
 Return a value describing the sex of the provided monster race. More...
 
static const char * lore_pronoun_nominative (monster_sex_t sex, bool title_case)
 Return a pronoun for a monster; used as the subject of a sentence. More...
 
static const char * lore_pronoun_possessive (monster_sex_t sex, bool title_case)
 Return a possessive pronoun for a monster. More...
 
static void lore_append_clause (textblock *tb, bitflag *f, byte attr, const char *start, const char *conjunction, const char *end)
 Append a clause containing a list of descriptions of monster flags from list-mon-race-flags.h to a textblock. More...
 
static void lore_append_spell_clause (textblock *tb, bitflag *f, bool know_hp, const struct monster_race *race, const char *conjunction, const char *end)
 Append a list of spell descriptions. More...
 
void lore_append_kills (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, const bitflag known_flags[RF_SIZE])
 Append the kill history to a texblock for a given monster race. More...
 
void lore_append_flavor (textblock *tb, const struct monster_race *race, bool append_utf8)
 Append the monster race description to a textblock. More...
 
void lore_append_movement (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster type, location, and movement patterns to a textblock. More...
 
void lore_append_toughness (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster AC, HP, and hit chance to a textblock. More...
 
void lore_append_exp (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the experience value description to a textblock. More...
 
void lore_append_drop (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster drop description to a textblock. More...
 
void lore_append_abilities (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster abilities (resists, weaknesses, other traits) to a textblock. More...
 
void lore_append_awareness (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append how the monster reacts to intruders and at what distance it does so. More...
 
void lore_append_friends (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append information about what other races the monster appears with and if they work together. More...
 
void lore_append_spells (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster's attack spells to a textblock. More...
 
void lore_append_attack (textblock *tb, const struct monster_race *race, const struct monster_lore *lore, bitflag known_flags[RF_SIZE])
 Append the monster's melee attacks to a textblock. More...
 
struct monster_loreget_lore (const struct monster_race *race)
 Get the lore record for this monster race. More...
 
void write_lore_entries (ang_file *fff)
 Write the monster lore. More...
 
bool lore_save (const char *name)
 Save the lore to a file in the user directory. More...
 

Detailed Description

Monster memory code.

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.

Typedef Documentation

typedef enum monster_sex monster_sex_t

Enumeration Type Documentation

Monster genders.

Enumerator
MON_SEX_NEUTER 
MON_SEX_MALE 
MON_SEX_FEMALE 
MON_SEX_MAX 

Function Documentation

int blow_color ( struct player p,
int  blow_idx 
)

Determine the color to code a monster melee blow effect.

This function assigns a color to each monster blow effect, depending on how dangerous the attack is to the player given current state. Blows may be colored green (least dangerous), yellow, orange, or red (most dangerous).

References adj_dex_safe, blow_effects, blow_effect::effect_type, player_state::el_info, player_state::flags, object::flags, i, player_upkeep::inven, player::known_state, player::lev, blow_effect::lore_attr, blow_effect::lore_attr_immune, blow_effect::lore_attr_resist, blow_effect::name, of_has, angband_constants::pack_size, proj_name_to_idx(), object::pval, element_info::res_level, blow_effect::resist, slot_by_name(), slot_object(), player_state::stat_ind, streq, object::timeout, tval_can_have_charges(), tval_is_edible(), player::upkeep, and z_info.

Referenced by lore_append_attack().

void cheat_monster_lore ( const struct monster_race race,
struct monster_lore lore 
)

Learn everything about a monster.

Sets the all_known variable, all flags and all relevant spell flags.

References monster_lore::all_known, and lore_update().

Referenced by get_debug_command(), and lore_description().

struct monster_lore* get_lore ( const struct monster_race race)
void lore_append_abilities ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster abilities (resists, weaknesses, other traits) to a textblock.

Known race flags are passed in for simplicity/efficiency. Note the macros that are used to simplify the code.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References COLOUR_L_UMBER, COLOUR_ORANGE, COLOUR_VIOLET, COLOUR_WHITE, create_mon_flag_mask(), describe_race_flag(), flag, FLAG_START, monster_lore::flags, format(), lore_append_clause(), lore_monster_sex(), lore_pronoun_nominative(), lore_pronoun_possessive(), MON_SEX_NEUTER, my_strcpy(), prev, rf_has, rf_inter, rf_is_empty, rf_next, rf_off, rf_on, RF_SIZE, rf_wipe, RFT_ALTER, RFT_DET, RFT_MAX, RFT_PROT, RFT_RES, RFT_VULN, RFT_VULN_I, start, streq, textblock_append(), and textblock_append_c().

Referenced by lore_description().

void lore_append_attack ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster's melee attacks to a textblock.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.
melee_colorsis a list of colors that is associated with each blow effect.

References random::base, monster_race::blow, blow_color(), blow_index(), monster_lore::blow_known, COLOUR_L_GREEN, blow_method::desc, blow_effect::desc, random::dice, monster_blow::dice, monster_blow::effect, i, index, lore_monster_sex(), lore_pronoun_nominative(), lore_pronoun_possessive(), random::m_bonus, monster_blow::method, angband_constants::mon_blows_max, MON_SEX_NEUTER, blow_effect::name, NULL, rf_has, random::sides, textblock_append(), textblock_append_c(), and z_info.

Referenced by lore_description().

void lore_append_awareness ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append how the monster reacts to intruders and at what distance it does so.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References COLOUR_L_BLUE, monster_race::hearing, lore_describe_awareness(), lore_monster_sex(), lore_pronoun_nominative(), MON_SEX_NEUTER, monster_race::sleep, monster_lore::sleep_known, textblock_append(), and textblock_append_c().

Referenced by lore_description().

static void lore_append_clause ( textblock tb,
bitflag f,
byte  attr,
const char *  start,
const char *  conjunction,
const char *  end 
)
static

Append a clause containing a list of descriptions of monster flags from list-mon-race-flags.h to a textblock.

The text that joins the list is drawn using the default attributes. The list uses a serial comma ("a, b, c, and d").

Parameters
tbis the textblock we are adding to.
fis the set of flags to be described.
attris the attribute each list item will be drawn with.
startis a string to start the clause.
conjunctionis a string that is added before the last item.
endis a string that is added after the last item.

References describe_race_flag(), flag, FLAG_END, FLAG_START, rf_count, rf_next, textblock_append(), and textblock_append_c().

Referenced by lore_append_abilities().

void lore_append_drop ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster drop description to a textblock.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References COLOUR_BLUE, monster_lore::drop_known, format(), lore_monster_sex(), lore_pronoun_nominative(), mon_create_drop_count(), MON_SEX_NEUTER, PLURAL, rf_has, textblock_append(), and textblock_append_c().

Referenced by lore_description().

void lore_append_exp ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the experience value description to a textblock.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References buf, COLOUR_BLUE, format(), player::lev, level, monster_race::level, monster_race::mexp, my_strcat(), PLURAL, rf_has, RF_UNIQUE, strnfmt(), textblock_append(), and textblock_append_c().

Referenced by lore_description().

void lore_append_flavor ( textblock tb,
const struct monster_race race,
bool  append_utf8 
)

Append the monster race description to a textblock.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
append_utf8indicates if we should append the flavor text as UTF-8 (which is preferred for spoiler files).

References monster_race::text, textblock_append(), and textblock_append_utf8().

Referenced by lore_description().

void lore_append_friends ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append information about what other races the monster appears with and if they work together.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References monster_race::friends, monster_race::friends_base, lore_monster_sex(), lore_pronoun_nominative(), MON_SEX_NEUTER, rf_has, and textblock_append().

Referenced by lore_description().

void lore_append_kills ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
const bitflag  known_flags[RF_SIZE] 
)

Append the kill history to a texblock for a given monster race.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References COLOUR_RED, monster_lore::deaths, lore_monster_sex(), lore_pronoun_nominative(), monster_race::max_num, MON_SEX_NEUTER, monster_lore::pkills, rf_has, RF_UNIQUE, textblock_append(), textblock_append_c(), monster_lore::tkills, and VERB_AGREEMENT.

Referenced by lore_description().

void lore_append_movement ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster type, location, and movement patterns to a textblock.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References COLOUR_GREEN, COLOUR_L_BLUE, COLOUR_L_GREEN, COLOUR_RED, create_mon_flag_mask(), describe_race_flag(), FLAG_END, FLAG_START, monster_race::flags, flags, flags_test(), monster_race::level, lore_describe_speed(), player::max_depth, rf_has, rf_inter, rf_next, RF_SIZE, RFT_MAX, RFT_RACE_A, RFT_RACE_N, monster_race::speed, textblock_append(), and textblock_append_c().

Referenced by lore_description().

static void lore_append_spell_clause ( textblock tb,
bitflag f,
bool  know_hp,
const struct monster_race race,
const char *  conjunction,
const char *  end 
)
static

Append a list of spell descriptions.

This is a modified version of lore_append_clause() to format spells.

Parameters
tbis the textblock we are adding to.
fis the set of flags to be described.
know_hpis whether the player knows the monster's AC.
raceis the monster race.
conjunctionis a string that is added before the last item.
endis a string that is added after the last item.

References FLAG_END, FLAG_START, mon_spell_lore_damage(), mon_spell_lore_description(), rsf_count, rsf_next, spell_color(), textblock_append(), and textblock_append_c().

Referenced by lore_append_spells().

void lore_append_spells ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster's attack spells to a textblock.

Known race flags are passed in for simplicity/efficiency. Note the macros that are used to simplify the code.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References monster_lore::armour_known, monster_lore::cast_innate, monster_lore::cast_spell, COLOUR_L_GREEN, COLOUR_L_RED, create_mon_spell_mask(), monster_race::freq_innate, monster_race::freq_spell, lore_append_spell_clause(), lore_monster_sex(), lore_pronoun_nominative(), MON_SEX_NEUTER, rf_has, rsf_copy, rsf_diff, rsf_inter, rsf_is_empty, RSF_SIZE, RST_BREATH, RST_INNATE, RST_NONE, monster_lore::spell_flags, monster_lore::spell_freq_known, textblock_append(), and textblock_append_c().

Referenced by lore_description().

void lore_append_toughness ( textblock tb,
const struct monster_race race,
const struct monster_lore lore,
bitflag  known_flags[RF_SIZE] 
)

Append the monster AC, HP, and hit chance to a textblock.

Known race flags are passed in for simplicity/efficiency.

Parameters
tbis the textblock we are adding to.
raceis the monster race we are describing.
loreis the known information about the monster race.
known_flagsis the preprocessed bitfield of race flags known to the player.

References monster_race::ac, monster_lore::armour_known, monster_race::avg_hp, COLOUR_L_BLUE, equipped_item_by_slot_name(), lore_monster_sex(), lore_pronoun_nominative(), MON_SEX_NEUTER, py_attack_hit_chance(), rf_has, RF_UNIQUE, textblock_append(), and textblock_append_c().

Referenced by lore_description().

static const char* lore_describe_awareness ( s16b  awareness)
static

Return a description for the given monster race awareness value.

Descriptions are in a table within the function. Returns a sensible string for values not in the table.

Parameters
awarenessis the inactivity counter of the race (monster_race.sleep).

References NULL.

Referenced by lore_append_awareness().

static const char* lore_describe_speed ( byte  speed)
static

Return a description for the given monster race speed value.

Descriptions are in a table within the function. Returns a sensible string for values not in the table.

Parameters
speedis the speed rating of the race (monster_race.speed).

References NULL.

Referenced by lore_append_movement().

void lore_do_probe ( struct monster mon)
bool lore_is_fully_known ( const struct monster_race race)
void lore_learn_flag_if_visible ( struct monster_lore lore,
const struct monster mon,
int  flag 
)

References monster_lore::flags, monster_is_visible(), and rf_on.

Referenced by does_resist().

void lore_learn_spell_if_has ( struct monster_lore lore,
const struct monster_race race,
int  flag 
)
void lore_learn_spell_if_visible ( struct monster_lore lore,
const struct monster mon,
int  flag 
)
static monster_sex_t lore_monster_sex ( const struct monster_race race)
static
static const char* lore_pronoun_nominative ( monster_sex_t  sex,
bool  title_case 
)
static

Return a pronoun for a monster; used as the subject of a sentence.

Descriptions are in a table within the function. Table must match monster_sex_t values.

Parameters
sexis the gender value (as provided by lore_monster_sex().
title_caseindicates whether the initial letter should be capitalized; true is capitalized, false is not.

References MON_SEX_MAX, and MON_SEX_NEUTER.

Referenced by lore_append_abilities(), lore_append_attack(), lore_append_awareness(), lore_append_drop(), lore_append_friends(), lore_append_kills(), lore_append_spells(), and lore_append_toughness().

static const char* lore_pronoun_possessive ( monster_sex_t  sex,
bool  title_case 
)
static

Return a possessive pronoun for a monster.

Descriptions are in a table within the function. Table must match monster_sex_t values.

Parameters
sexis the gender value (as provided by lore_monster_sex().
title_caseindicates whether the initial letter should be capitalized; true is capitalized, false is not.

References MON_SEX_MAX, and MON_SEX_NEUTER.

Referenced by lore_append_abilities(), and lore_append_attack().

bool lore_save ( const char *  name)

Save the lore to a file in the user directory.

Parameters
nameis the filename
Returns
true on success, false otherwise.

References ANGBAND_DIR_USER, msg, path, path_build(), text_lines_to_file(), and write_lore_entries().

Referenced by save_game().

void lore_treasure ( struct monster mon,
int  num_item,
int  num_gold 
)

Take note that the given monster just dropped some treasure.

Note that learning the "GOOD"/"GREAT" flags gives information about the treasure (even when the monster is killed for the first time, such as uniques, and the treasure has not been examined yet).

This "indirect" method is used to prevent the player from learning exactly how much treasure a monster can drop from observing only a single example of a drop. This method actually observes how much gold and items are dropped, and remembers that information to be described later by the monster recall code.

References monster_lore::drop_gold, monster_lore::drop_item, monster_lore::flags, get_lore(), player_upkeep::monster_race, PR_MONSTER, monster::race, player_upkeep::redraw, rf_on, and player::upkeep.

Referenced by monster_death().

void lore_update ( const struct monster_race race,
struct monster_lore lore 
)
void monster_flags_known ( const struct monster_race race,
const struct monster_lore lore,
bitflag  flags[RF_SIZE] 
)

Copies into flags the flags of the given monster race that are known to the given lore structure (usually the player's knowledge).

Known flags will be 1 for present, or 0 for not present. Unknown flags will always be 0.

References monster_lore::flags, monster_race::flags, flags, rf_copy, and rf_inter.

Referenced by lore_description().

int spell_color ( struct player p,
int  spell_index 
)

Determine the color to code a monster spell.

This function assigns a color to each monster spell, depending on how dangerous the attack is to the player given current state. Spells may be colored green (least dangerous), yellow, orange, or red (most dangerous).

References COLOUR_DARK, monster_spell::effect, player_state::el_info, player_state::flags, effect::index, player::known_state, monster_spell::lore_attr, monster_spell::lore_attr_immune, monster_spell::lore_attr_resist, monster_spell_by_index(), effect::next, NULL, of_has, effect::params, player_inc_check(), element_info::res_level, monster_spell::save_message, SKILL_SAVE, and player_state::skills.

Referenced by lore_append_spell_clause().

void wipe_monster_lore ( const struct monster_race race,
struct monster_lore lore 
)
void write_lore_entries ( ang_file fff)