Angband
Data Structures | Functions | Variables
obj-slays.c File Reference

Functions for manipulating slays/brands. More...

#include "angband.h"
#include "init.h"
#include "mon-lore.h"
#include "obj-desc.h"
#include "obj-identify.h"
#include "obj-slays.h"
#include "obj-util.h"

Data Structures

struct  brand_info
struct  slay_info

Functions

void copy_slay (struct slay **dest, struct slay *source)
 Copy all the slays from one structure to another.
void copy_brand (struct brand **dest, struct brand *source)
 Copy all the brands from one structure to another.
void free_slay (struct slay *source)
 Free all the slays in a structure.
void free_brand (struct brand *source)
 Free all the brands in a structure.
bool append_random_brand (struct brand *current, char **name)
 Append a random brand, currently to a randart This will later change so that selection is done elsewhere.
bool append_random_slay (struct slay *current, char **name)
 Append a random slay, currently to a randart This will later change so that selection is done elsewhere.
int brand_count (struct brand *brands)
 Count the brands in a struct brand.
int slay_count (struct slay *slays)
 Count the slays in a struct slay.
struct brandbrand_collect (const object_type *obj1, const object_type *obj2, int *total, bool known)
 Collect the (optionally known) brands from one or two objects into a linked array.
struct slayslay_collect (const object_type *obj1, const object_type *obj2, int *total, bool known)
 Collect the (optionally known) slays from one or two objects into a linked array.
bool react_to_specific_slay (struct slay *slay, const struct monster *mon)
 React to slays which hurt a monster.
void object_notice_brands (object_type *o_ptr, const monster_type *m_ptr)
 Notice any brands on a particular object which affect a particular monster.
void object_notice_slays (object_type *o_ptr, const monster_type *m_ptr)
 Notice any slays on a particular object which affect a particular monster.
void improve_attack_modifier (object_type *o_ptr, const monster_type *m_ptr, const struct brand **brand_used, const struct slay **slay_used, char *verb, bool real, bool known_only)
 Extract the multiplier from a given object hitting a given monster.
bool react_to_slay (struct object *obj, const struct monster *mon)
 React to slays which hurt a monster.
bool brands_are_equal (struct brand *brand1, struct brand *brand2)
 Determine whether two lists of brands are the same.
bool slays_are_equal (struct slay *slay1, struct slay *slay2)
 Determine whether two lists of slays are the same.
void wipe_brands (struct brand *brands)
 Remove a list of brands and de-allocate their memory.
void wipe_slays (struct slay *slays)
 Remove a list of slays and de-allocate their memory.
s32b check_slay_cache (const object_type *obj)
 Check the slay cache for a combination of slays and brands.
bool fill_slay_cache (const object_type *obj, s32b value)
 Fill in a value in the slay cache.
errr create_slay_cache (struct ego_item *items)
 Create a cache of slay/brand combinations found on ego items, and the values of these combinations.
void free_slay_cache (void)
 Free the slay cache.

Variables

static struct slay_cacheslay_cache
 Cache of slay values (for object_power)
struct brand_info brand_names []
 Brand info The verbs here probably should go in list-elements.h, when that's been sorted properly, and there will also need to be a list of possibilities in obj-randart.c.
struct slay_info slay_names []
 Slay info These should go into obj-randart.c, but can wait for brands to be done (because they're more complicated) - NRM.

Detailed Description

Functions for manipulating slays/brands.

Copyright (c) 2010 Chris Carr and Peter Denison Copyright (c) 2014 Nick McConnell

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.

Function Documentation

bool append_random_brand ( struct brand current,
char **  name 
)

Append a random brand, currently to a randart This will later change so that selection is done elsewhere.

Parameters
currentthe list of brands the object already has
namethe name to report for randart logging

References brand::element, FALSE, mem_zalloc(), brand::multiplier, N_ELEMENTS, brand_info::name, brand::name, brand::next, randint0, streq, string_make(), and TRUE.

Referenced by add_brand().

bool append_random_slay ( struct slay current,
char **  name 
)

Append a random slay, currently to a randart This will later change so that selection is done elsewhere.

Parameters
currentthe list of slays the object already has
namethe name to report for randart logging

References FALSE, mem_zalloc(), slay_info::multiplier, slay::multiplier, N_ELEMENTS, slay_info::name, slay::name, slay::next, slay_info::race_flag, slay::race_flag, randint0, streq, string_make(), and TRUE.

Referenced by add_slay().

struct brand* brand_collect ( const object_type obj1,
const object_type obj2,
int total,
bool  known 
)
read

Collect the (optionally known) brands from one or two objects into a linked array.

Parameters
obj1the first object (not NULL)
obj2the second object (can be NULL)
totalcounts the brands found
knownwhether we are after only known brands
Returns
a pointer to the first brand

References object::brands, brand::element, i, brand::known, mem_zalloc(), brand::multiplier, brand::name, brand::next, and string_make().

Referenced by obj_known_damage(), and slay_power().

int brand_count ( struct brand brands)

Count the brands in a struct brand.

Parameters
brands

References brand::next.

Referenced by parse_frequencies().

bool brands_are_equal ( struct brand brand1,
struct brand brand2 
)

Determine whether two lists of brands are the same.

Parameters
brand1
brand2the lists being compared

References brand::element, FALSE, brand::multiplier, brand::name, brand::next, streq, and TRUE.

Referenced by check_slay_cache(), create_slay_cache(), and fill_slay_cache().

s32b check_slay_cache ( const object_type obj)

Check the slay cache for a combination of slays and brands.

Parameters
objis the object the combination is on
Returns
the power value of the combination

References slay_cache::brands, object::brands, brands_are_equal(), i, slay_cache::slays, slays, object::slays, slays_are_equal(), and slay_cache::value.

Referenced by slay_power().

void copy_brand ( struct brand **  dest,
struct brand source 
)

Copy all the brands from one structure to another.

Parameters
destthe address the brands are going to
sourcethe brands being copied

References brand::element, mem_zalloc(), brand::multiplier, brand::name, brand::next, and string_make().

Referenced by choose_item(), copy_artifact_data(), create_slay_cache(), ego_apply_magic(), object_copy(), and object_prep().

void copy_slay ( struct slay **  dest,
struct slay source 
)

Copy all the slays from one structure to another.

Parameters
destthe address the slays are going to
sourcethe slays being copied

References mem_zalloc(), slay::multiplier, slay::name, slay::next, slay::race_flag, and string_make().

Referenced by choose_item(), copy_artifact_data(), create_slay_cache(), ego_apply_magic(), object_copy(), and object_prep().

errr create_slay_cache ( struct ego_item items)

Create a cache of slay/brand combinations found on ego items, and the values of these combinations.

This is to speed up slay_power(), which will be called many times for ego items during the game.

Parameters
itemsis the set of ego types from which we are extracting slay combinations

References slay_cache::brands, ego_item::brands, brands_are_equal(), copy_brand(), copy_slay(), angband_constants::e_max, free_brand(), free_slay(), i, mem_free(), mem_zalloc(), slay_cache::slays, slays, ego_item::slays, slays_are_equal(), slay_cache::value, and z_info.

Referenced by finish_parse_ego().

bool fill_slay_cache ( const object_type obj,
s32b  value 
)

Fill in a value in the slay cache.

Return TRUE if a change is made.

Parameters
objis the object the combination is on
valueis the value of the slay flags on the object

References slay_cache::brands, object::brands, brands_are_equal(), FALSE, i, slay_cache::slays, slays, object::slays, slays_are_equal(), TRUE, slay_cache::value, and value.

Referenced by slay_power().

void free_brand ( struct brand source)

Free all the brands in a structure.

Parameters
sourcethe brands being freed

References mem_free(), brand::name, and brand::next.

Referenced by cleanup_artifact(), cleanup_ego(), cleanup_object(), create_slay_cache(), free_slay_cache(), object_delete(), and wiz_reroll_item().

void free_slay ( struct slay source)

Free all the slays in a structure.

Parameters
sourcethe slays being freed

References mem_free(), slay::name, and slay::next.

Referenced by cleanup_artifact(), cleanup_ego(), cleanup_object(), create_slay_cache(), free_slay_cache(), object_delete(), and wiz_reroll_item().

void free_slay_cache ( void  )

Free the slay cache.

References slay_cache::brands, free_brand(), free_slay(), i, mem_free(), and slays.

Referenced by cleanup_ego().

void improve_attack_modifier ( object_type o_ptr,
const monster_type m_ptr,
const struct brand **  brand_used,
const struct slay **  slay_used,
char *  verb,
bool  real,
bool  known_only 
)

Extract the multiplier from a given object hitting a given monster.

Parameters
o_ptris the object being used to attack
m_ptris the monster being attacked
brand_usedis the brand that gave the best multiplier, or NULL
slay_usedis the slay that gave the best multiplier, or NULL
verbis the verb used in the attack ("smite", etc)
realis whether this is a real attack (where we update lore) or a simulation (where we don't)
known_onlyis whether we are using all the brands and slays, or only the ones we already know about

References object::brands, brand::element, monster_lore::flags, monster_race::flags, get_lore(), brand::known, slay::known, brand_info::melee_verb, brand_info::melee_verb_weak, monster::mflag, mflag_has, brand::multiplier, slay::multiplier, my_strcpy(), brand::next, slay::next, object_notice_brands(), object_notice_slays(), monster::race, slay::race_flag, react_to_specific_slay(), brand_info::resist_flag, rf_has, rf_on, and object::slays.

Referenced by make_ranged_shot(), make_ranged_throw(), py_attack_real(), and slay_power().

void object_notice_brands ( object_type o_ptr,
const monster_type m_ptr 
)

Notice any brands on a particular object which affect a particular monster.

Parameters
o_ptris the object on which we are noticing brands
m_ptrthe monster we are hitting, if there is one

References brand_info::active_verb, object::brands, brand::element, monster_race::flags, brand::known, msg, brand::next, object_check_for_ident(), object_desc(), object_notice_ego(), ODESC_BASE, ODESC_SINGULAR, monster::race, brand_info::resist_flag, rf_has, and TRUE.

Referenced by improve_attack_modifier(), and object_notice_on_wield().

void object_notice_slays ( object_type o_ptr,
const monster_type m_ptr 
)

Notice any slays on a particular object which affect a particular monster.

Parameters
o_ptris the object on which we are noticing slays
m_ptrthe monster we are trying to slay

References slay::known, msg, slay::multiplier, slay::next, object_check_for_ident(), object_desc(), object_notice_ego(), ODESC_BASE, ODESC_SINGULAR, react_to_specific_slay(), object::slays, and TRUE.

Referenced by improve_attack_modifier().

bool react_to_slay ( struct object obj,
const struct monster mon 
)

React to slays which hurt a monster.

Parameters
objis the object we're testing for slays
monis the monster we're testing for being slain

References FALSE, slay::next, react_to_specific_slay(), object::slays, and TRUE.

Referenced by process_monster_grab_objects().

bool react_to_specific_slay ( struct slay slay,
const struct monster mon 
)

React to slays which hurt a monster.

Parameters
slayis the slay we're testing for effectiveness
monis the monster we're testing for being slain

References monster_race::base, FALSE, monster_race::flags, slay::name, monster_base::name, monster::race, slay::race_flag, rf_has, streq, and TRUE.

Referenced by improve_attack_modifier(), object_notice_slays(), and react_to_slay().

struct slay* slay_collect ( const object_type obj1,
const object_type obj2,
int total,
bool  known 
)
read

Collect the (optionally known) slays from one or two objects into a linked array.

Parameters
obj1the first object (not NULL)
obj2the second object (can be NULL)
totalcounts the slays found
knownwhether we are after only known slays
Returns
a pointer to the first slay

References i, slay::known, mem_zalloc(), slay::multiplier, slay::name, slay::next, slay::race_flag, object::slays, and string_make().

Referenced by obj_known_damage(), and slay_power().

int slay_count ( struct slay slays)

Count the slays in a struct slay.

Parameters
slays

References slay::next.

Referenced by parse_frequencies().

bool slays_are_equal ( struct slay slay1,
struct slay slay2 
)

Determine whether two lists of slays are the same.

Parameters
slay1
slay2the lists being compared

References FALSE, slay::multiplier, slay::name, slay::next, slay::race_flag, s1, s2, streq, and TRUE.

Referenced by check_slay_cache(), create_slay_cache(), and fill_slay_cache().

void wipe_brands ( struct brand brands)

Remove a list of brands and de-allocate their memory.

References mem_free(), and brand::next.

Referenced by scramble_artifact().

void wipe_slays ( struct slay slays)

Remove a list of slays and de-allocate their memory.

References mem_free(), slay::next, s1, and slays.

Referenced by scramble_artifact().

Variable Documentation

struct brand_info brand_names[]
Initial value:
{
{ "acid", "spits", "dissolve", "corrode", RF_IM_ACID },
{ "lightning", "crackles", "shock", "zap", RF_IM_ELEC },
{ "fire", "flares", "burn", "singe", RF_IM_FIRE },
{ "cold", "grows cold", "freeze", "chill", RF_IM_COLD },
{ "poison", "seethes", "poison", "sicken", RF_IM_POIS }
}

Brand info The verbs here probably should go in list-elements.h, when that's been sorted properly, and there will also need to be a list of possibilities in obj-randart.c.

struct slay_cache* slay_cache
static

Cache of slay values (for object_power)

struct slay_info slay_names[]
Initial value:
{
{ "evil creatures", RF_EVIL, 2 },
{ "animals", RF_ANIMAL, 2 },
{ "orcs", RF_ORC, 3 },
{ "trolls", RF_TROLL, 3 },
{ "giants", RF_GIANT, 3 },
{ "demons", RF_DEMON, 3 },
{ "dragons", RF_DRAGON, 3 },
{ "undead", RF_UNDEAD, 3 },
{ "demons", RF_DEMON, 5 },
{ "dragons", RF_DRAGON, 5 },
{ "undead", RF_UNDEAD, 5 }
}

Slay info These should go into obj-randart.c, but can wait for brands to be done (because they're more complicated) - NRM.