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

Go to the source code of this file.

Macros

#define ADD_EXP(exptotal, exp)   do { exptotal += exp; if (exptotal > MAX_EXPERIENCE) exptotal = MAX_EXPERIENCE; } while (0)
 
#define ADD_TOTALEXP(exptotal, exp)   do { exptotal += exp; if (exptotal > MAX_TOTAL_EXPERIENCE) exptotal = MAX_TOTAL_EXPERIENCE; } while(0)
 
#define DIFF_MSG(flag, subtype1, subtype2, msg1, msg2)   draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, (flag > 0) ? subtype1 : subtype2, (flag > 0) ? msg1 : msg2);
 
#define FLOAT_CON_BONUS   0
 
#define FLOAT_DEX_BONUS   1
 
#define FLOAT_GRACE_BONUS   3
 
#define FLOAT_SP_BONUS   2
 
#define INT_CHA_BONUS   4
 
#define INT_CLERIC_CHANCE   2
 
#define INT_DAM_BONUS   6
 
#define INT_DEX_BONUS   5
 
#define INT_FEAR_BONUS   0
 
#define INT_LEARN_SPELL   3
 
#define INT_THAC0_BONUS   7
 
#define INT_TURN_BONUS   1
 
#define INT_WEIGHT_LIMIT   8
 
#define MAX_EXPERIENCE   levels[settings.max_level]
 
#define MAX_SAVE_LEVEL   110
 
#define NUM_FLOAT_BONUSES   4
 
#define NUM_INT_BONUSES   9
 

Functions

static void add_player_exp (object *op, int64_t exp, const char *skill_name, int flag)
 
void add_statbonus (object *op)
 
int allowed_class (const object *op)
 
void apply_death_exp_penalty (object *op)
 
void calc_perm_exp (object *op)
 
int change_abil (object *op, object *tmp)
 
void change_attr_value (living *stats, int attr, int8_t value)
 
void change_exp (object *op, int64_t exp, const char *skill_name, int flag)
 
void change_luck (object *op, int value)
 
int64_t check_exp_adjust (const object *op, int64_t exp)
 
int64_t check_exp_loss (const object *op, int64_t exp)
 
void check_stat_bounds (living *stats, int8_t min_stat, int8_t max_stat)
 
int did_make_save (const object *op, int level, int bonus)
 
static void dragon_level_gain (object *who)
 
void drain_specific_stat (object *op, int deplete_stats)
 
void drain_stat (object *op)
 
int exp_level (int64_t exp)
 
objectfind_applied_skill_by_name (const object *op, const char *name)
 
void fix_object (object *op)
 
static void fix_player (object *op, int *ac, int *wc, const object *grace_obj, const object *mana_obj, const object *wc_obj, int weapon_speed, float added_speed)
 
int8_t get_attr_value (const living *stats, int attr)
 
int get_cha_bonus (int stat)
 
int get_cleric_chance (int stat)
 
static float get_con_bonus (int stat)
 
int get_dam_bonus (int stat)
 
int get_dex_bonus (int stat)
 
int get_fear_bonus (int stat)
 
static float get_grace_bonus (int stat)
 
static size_t get_index (int stat, size_t max_index)
 
int get_learn_spell (int stat)
 
static float get_sp_bonus (int stat)
 
float get_speed_bonus (int stat)
 
int get_thaco_bonus (int stat)
 
int get_turn_bonus (int stat)
 
uint32_t get_weight_limit (int stat)
 
objectgive_skill_by_name (object *op, const char *skill_name)
 
void init_stats (int reload)
 
int64_t level_exp (int level, double expmul)
 
static int load_table_float (float **bonuses, FILE *fp, char *bonus_name)
 
static int load_table_int (int **bonuses, FILE *fp, char *bonus_name)
 
void player_lvl_adj (object *who, object *op)
 
int remove_depletion (object *op, int level)
 
void remove_statbonus (object *op)
 
void set_attr_value (living *stats, int attr, int8_t value)
 
void set_dragon_name (object *pl, const object *abil, const object *skin)
 
void share_exp (object *op, int64_t exp, const char *skill, int flag)
 
static void subtract_player_exp (object *op, int64_t exp, const char *skill, int flag)
 

Variables

const char *const attacks [NROFATTACKS]
 
const char *const drain_msg [NUM_STATS]
 
static const char * float_bonus_names [NUM_FLOAT_BONUSES]
 
static float * float_bonuses [NUM_FLOAT_BONUSES]
 
const char *const gain_msg [NUM_STATS]
 
static const char * int_bonus_names [NUM_INT_BONUSES]
 
static int * int_bonuses [NUM_INT_BONUSES]
 
int64_t * levels
 
const char *const lose_msg [NUM_STATS]
 
const char *const restore_msg [NUM_STATS]
 
static const int savethrow [MAX_SAVE_LEVEL+1]
 
const char *const short_stat_name [NUM_STATS]
 
const char *const statname [NUM_STATS]
 

Detailed Description

Functions related to attributes, weight, experience, which concern only living things.

Todo:
make "stat"/"attr" coherent.

Definition in file living.c.

Macro Definition Documentation

◆ ADD_EXP

#define ADD_EXP (   exptotal,
  exp 
)    do { exptotal += exp; if (exptotal > MAX_EXPERIENCE) exptotal = MAX_EXPERIENCE; } while (0)

Handy little macro that adds exp and keeps it within bounds. Since we are now using 64 bit values, I'm not all concerned about overflow issues with exptotal wrapping. exptotal is typically op->exp, or op->total_exp

Definition at line 42 of file living.c.

◆ ADD_TOTALEXP

#define ADD_TOTALEXP (   exptotal,
  exp 
)    do { exptotal += exp; if (exptotal > MAX_TOTAL_EXPERIENCE) exptotal = MAX_TOTAL_EXPERIENCE; } while(0)

Definition at line 43 of file living.c.

◆ DIFF_MSG

#define DIFF_MSG (   flag,
  subtype1,
  subtype2,
  msg1,
  msg2 
)    draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, (flag > 0) ? subtype1 : subtype2, (flag > 0) ? msg1 : msg2);

Rather than having a whole bunch of if (flag) draw.. else _draw, make this macro to clean those up. Not usuable outside change_abil function since some of the values passed to draw_ext_info are hardcoded.

Definition at line 370 of file living.c.

◆ FLOAT_CON_BONUS

#define FLOAT_CON_BONUS   0

This is basically same as above, but for bonuses in which we store the value as a float.

Definition at line 86 of file living.c.

◆ FLOAT_DEX_BONUS

#define FLOAT_DEX_BONUS   1

Definition at line 87 of file living.c.

◆ FLOAT_GRACE_BONUS

#define FLOAT_GRACE_BONUS   3

Definition at line 89 of file living.c.

◆ FLOAT_SP_BONUS

#define FLOAT_SP_BONUS   2

Definition at line 88 of file living.c.

◆ INT_CHA_BONUS

#define INT_CHA_BONUS   4

Definition at line 63 of file living.c.

◆ INT_CLERIC_CHANCE

#define INT_CLERIC_CHANCE   2

Definition at line 61 of file living.c.

◆ INT_DAM_BONUS

#define INT_DAM_BONUS   6

Definition at line 65 of file living.c.

◆ INT_DEX_BONUS

#define INT_DEX_BONUS   5

Definition at line 64 of file living.c.

◆ INT_FEAR_BONUS

#define INT_FEAR_BONUS   0

The definitions below are indexes into the bonuses[] array. Rather than have a bunch of different variables, it is easier to just have a single array - all access to these is done through the get_cha_...() function in any case - making it an array makes processing simpler.

The INT_ prefix is to note the type of array the bonus goes into (vs FLOAT) - it is unfortunately that it is also the name of one of the stats.

The NUM_BONUSES is how many bonuses they are (size of the array), so is equal to last value +1.

Definition at line 59 of file living.c.

◆ INT_LEARN_SPELL

#define INT_LEARN_SPELL   3

Definition at line 62 of file living.c.

◆ INT_THAC0_BONUS

#define INT_THAC0_BONUS   7

Definition at line 66 of file living.c.

◆ INT_TURN_BONUS

#define INT_TURN_BONUS   1

Definition at line 60 of file living.c.

◆ INT_WEIGHT_LIMIT

#define INT_WEIGHT_LIMIT   8

Definition at line 67 of file living.c.

◆ MAX_EXPERIENCE

#define MAX_EXPERIENCE   levels[settings.max_level]

Definition at line 100 of file living.c.

◆ MAX_SAVE_LEVEL

#define MAX_SAVE_LEVEL   110

Definition at line 104 of file living.c.

◆ NUM_FLOAT_BONUSES

#define NUM_FLOAT_BONUSES   4

Definition at line 90 of file living.c.

◆ NUM_INT_BONUSES

#define NUM_INT_BONUSES   9

Definition at line 68 of file living.c.

Function Documentation

◆ add_player_exp()

static void add_player_exp ( object op,
int64_t  exp,
const char *  skill_name,
int  flag 
)
static

Add experience to a player - exp should only be positive. Updates permanent exp for the skill we are adding to.

Parameters
opobject we add exp to.
expexperience to gain. Can be 0, but not that useful to call in that case...
skill_nameskill to add exp to. Can be NULL, in which case exp increases the players general total, but not any particular skill.
flagwhat to do if the player doesn't have the skill. Combination of SK_EXP_xxx flags.

Definition at line 1960 of file living.c.

References ADD_EXP, ADD_TOTALEXP, calc_perm_exp(), liv::exp, obj::expmul, find_applied_skill_by_name(), give_skill_by_name(), obj::level, levels, Settings::max_level, give::op, Settings::permanent_exp_ratio, player_lvl_adj(), settings, SK_EXP_ADD_SKILL, SK_EXP_NONE, SKILL, obj::stats, and obj::total_exp.

Referenced by change_exp().

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

◆ add_statbonus()

void add_statbonus ( object op)

Adds stat-bonuses given by the class which the player has chosen.

Parameters
opobject which must be a player with contr not NULL.

Definition at line 869 of file living.c.

References give::op.

Referenced by apply_race_and_class(), key_change_class(), and key_roll_stat().

+ Here is the caller graph for this function:

◆ allowed_class()

int allowed_class ( const object op)

Returns true if the given player is a legal class. The function to add and remove class-bonuses to the stats doesn't check if the stat becomes negative, thus this function merely checks that all stats are 1 or more, and returns false otherwise.

Parameters
opobject to check.
Returns
1 if allowed, 0 else.

Definition at line 1652 of file living.c.

References give::op.

Referenced by apply_race_and_class(), and key_change_class().

+ Here is the caller graph for this function:

◆ apply_death_exp_penalty()

void apply_death_exp_penalty ( object op)

Applies a death penalty experience, the size of this is defined by the settings death_penalty_percentage and death_penalty_levels, and by the amount of permenent experience, whichever gives the lowest loss.

Parameters
opvictim of the penalty. Must not be NULL.

Definition at line 2233 of file living.c.

References check_exp_loss(), Settings::death_penalty_level, Settings::death_penalty_ratio, FOR_INV_FINISH, FOR_INV_PREPARE, levels, MAX, MIN, give::op, player_lvl_adj(), settings, SKILL, and Ice::tmp.

Referenced by kill_player_not_permadeath().

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

◆ calc_perm_exp()

void calc_perm_exp ( object op)

Ensure that the permanent experience requirements in an exp object are met. This really just checks 'op to make sure the perm_exp value is within proper range. Note that the checking of what is passed through has been reduced. Since there is now a proper field for perm_exp, this can now work on a much larger set of objects.

Parameters
opobject to check.

Definition at line 1903 of file living.c.

References MAX_EXPERIENCE, give::op, Settings::permanent_exp_ratio, and settings.

Referenced by add_player_exp(), and command_addexp().

+ Here is the caller graph for this function:

◆ change_abil()

int change_abil ( object op,
object tmp 
)

Permanently alters an object's stats/flags based on another object.

Returns
1 if we sucessfully changed a stat, 0 if nothing was changed.
Note
flag is set to 1 if we are applying the object, -1 if we are removing the object.
It is the calling functions responsibilty to check to see if the object can be applied or not. The main purpose of calling this function is the messages that are displayed - fix_object should really always be called after this when removing an object - that is because it is impossible to know if some object is the only source of an attacktype or spell attunement, so this function will clear the bits, but the player may still have some other object that gives them that ability.
Todo:
check logic, and things like that. Is the call to fix_object always required?

Definition at line 395 of file living.c.

References add_string(), AT_CONFUSION, ATNR_PHYSICAL, BOW, change_attr_value(), change_resist_msg, check_stat_bounds(), CLEAR_FLAG, DIFF_MSG, draw_ext_info(), draw_ext_info_format(), fix_object(), FLAG_APPLIED, FLAG_BLIND, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_UNDEAD, FLAG_WIZ, FLAG_XRAYS, free_string(), gain_msg, get_attr_value(), lose_msg, Settings::max_stat, MIN_STAT, MOVE_FLY_HIGH, MOVE_FLY_LOW, MOVE_SWIM, obj::move_type, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_ATTACKTYPE_GAIN, MSG_TYPE_ATTRIBUTE_ATTACKTYPE_LOSS, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_START, MSG_TYPE_ATTRIBUTE_MOVE, MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN, MSG_TYPE_ATTRIBUTE_PROTECTION_LOSS, MSG_TYPE_ATTRIBUTE_RACE, MSG_TYPE_ATTRIBUTE_STAT_GAIN, MSG_TYPE_ATTRIBUTE_STAT_LOSS, NDI_BLUE, NDI_UNIQUE, NROFATTACKS, NUM_STATS, object_check_move_on(), give::op, PLAYER, POTION, QUERY_FLAG, obj::resist, set_attr_value(), SET_FLAG, settings, SKILL, and Ice::tmp.

Referenced by apply_special(), become_follower(), blind_living(), blindness_type_process(), cast_bless(), cast_change_ability(), cast_curse(), cfapi_object_change_abil(), create_aura(), eat_special_food(), potion_type_apply(), remove_force(), swap_random_stats(), and unapply_special().

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

◆ change_attr_value()

void change_attr_value ( living stats,
int  attr,
int8_t  value 
)

Like set_attr_value(), but instead the value (which can be negative) is added to the specified stat.

Parameters
statsitem to modify. Must not be NULL.
attrattribute to change.
valuedelta (can be positive).
Todo:
check if attr is valid? Checks result valus is valid?

Definition at line 265 of file living.c.

References liv::Cha, CHARISMA, liv::Con, CONSTITUTION, liv::Dex, DEXTERITY, liv::Int, INTELLIGENCE, llevError, LOG(), liv::Pow, POWER, liv::Str, STRENGTH, autojail::value, liv::Wis, and WISDOM.

Referenced by add_abilities(), alchemy_failure_effect(), apply_changes_to_player(), change_abil(), drain_specific_stat(), fix_object(), and kill_player_not_permadeath().

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

◆ change_exp()

void change_exp ( object op,
int64_t  exp,
const char *  skill_name,
int  flag 
)

Changes experience to a player/monster. This does bounds checking to make sure we don't overflow the max exp.

The exp passed is typically not modified much by this function - it is assumed the caller has modified the exp as needed. skill_name is the skill that should get the exp added. flag is what to do if player doesn't have the skill. these last two values are only used for players.

Parameters
opvictim to alter.
expexperience to gain (positive) or lose (negative).
skill_nameskill to change. Can be NULL.
flag
  • if experience gain, what to do if player doesn't have the skill
  • if experience loss, whether to remove from all skills or only specified skill
See also
share_exp() for a party-aware version.

Definition at line 2168 of file living.c.

References add_player_exp(), ADD_TOTALEXP, FABS, FLAG_ALIVE, level_exp(), llevError, LOG(), MAX_EXPERIENCE, give::op, PLAYER, QUERY_FLAG, subtract_player_exp(), and WEAPON.

Referenced by attempt_do_alchemy(), book_type_apply(), cfapi_object_change_exp(), cure_disease(), do_harvest(), do_hidden_move(), do_skill(), examine(), god_examines_priest(), hit_with_one_attacktype(), peacemaker_type_process(), scroll_type_apply(), sell_item(), share_exp(), shop_pay_unpaid(), spellbook_type_apply(), and try_leave_cult().

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

◆ change_luck()

void change_luck ( object op,
int  value 
)

Alter the object's luck.

Parameters
opobject to altar.
valuedelta to apply. 0 indicates timeout (moves luck towards 0), otherwise change the luck of the object via an applied bad_luck object in inventory.

Definition at line 797 of file living.c.

References arch_present_in_ob(), arch_to_object(), FABS, find_archetype(), FLAG_APPLIED, object_insert_in_ob(), give::op, RANDOM, SET_FLAG, Ice::tmp, and autojail::value.

Referenced by fix_luck(), and kill_object().

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

◆ check_exp_adjust()

int64_t check_exp_adjust ( const object op,
int64_t  exp 
)

Returns the maximum experience the object can gain or lose.

Parameters
opobject which will be the victim.
expexperience to gain or lose.
Returns
maximum value op can gain or lose (can be positive or negative).

Definition at line 2091 of file living.c.

References check_exp_loss(), MAX_EXPERIENCE, MIN, and give::op.

Referenced by command_addexp().

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

◆ check_exp_loss()

int64_t check_exp_loss ( const object op,
int64_t  exp 
)

This function checks to make sure that object 'op' can lose 'exp' experience. It basically makes adjustments based on permanent exp and the like. This function should always be used for losing experience - the 'exp' value passed should be positive - this is the amount that should get subtract from the player.

Parameters
opobject from which to subtract.
expexperience to lose.
Returns
the amount of exp object 'op' can in fact lose -

Definition at line 2066 of file living.c.

References give::op, PERM_EXP, PERM_EXP_MAX_LOSS_RATIO, Settings::permanent_exp_ratio, and settings.

Referenced by apply_death_exp_penalty(), check_exp_adjust(), kill_object(), and subtract_player_exp().

+ Here is the caller graph for this function:

◆ check_stat_bounds()

void check_stat_bounds ( living stats,
int8_t  min_stat,
int8_t  max_stat 
)

Ensures that all stats (str/dex/con/wis/cha/int) are within the passed in range of min_stat and max_stat. Often, the caller will pass in MIN_STAT and MAX_STAT, but in case of force objects or temporary calculations, we want things outside the range (force objects may have negative stats, but we don't want them too negative)

Parameters
statsattributes to check.
min_statlowest the stat can be
max_stathighest the stat can be

Definition at line 355 of file living.c.

References get_attr_value(), NUM_STATS, and set_attr_value().

Referenced by change_abil(), do_symptoms(), fix_object(), fix_player(), and kill_player_not_permadeath().

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

◆ did_make_save()

int did_make_save ( const object op,
int  level,
int  bonus 
)

This function takes an object (monster/player, op), and determines if it makes a basic save throw by looking at the save_throw table.

Parameters
oppotential victim.
levelthe effective level to make the save at
bonusany plus/bonus (typically based on resistance to particular attacktype).
Returns
1 if op makes his save, 0 if he failed

Definition at line 2282 of file living.c.

References MAX_SAVE_LEVEL, give::op, PREFER_HIGH, random_roll(), and savethrow.

Referenced by flee_player(), hit_player(), hit_with_one_attacktype(), mood_change(), and polymorph_living().

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

◆ dragon_level_gain()

static void dragon_level_gain ( object who)
static

This function is called when a dragon-player gains an overall level. Here, the dragon might gain new abilities or change the ability-focus.

Parameters
whodragon's object.

Definition at line 1719 of file living.c.

References atnr_is_dragon_enabled(), change_resist_msg, dragon_ability_gain(), draw_ext_info_format(), liv::exp, FORCE, obj::last_eat, obj::level, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, NDI_BLUE, NDI_UNIQUE, object_find_by_type_and_arch_name(), obj::resist, set_dragon_name(), obj::stats, and autojail::who.

Referenced by player_lvl_adj().

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

◆ drain_specific_stat()

void drain_specific_stat ( object op,
int  deplete_stats 
)

Drain a specified stat from op.

Parameters
opvictim to drain.
deplete_statsstatistic to drain.

Definition at line 729 of file living.c.

References ARCH_DEPLETION, arch_present_in_ob(), arch_to_object(), change_attr_value(), drain_msg, draw_ext_info(), find_archetype(), fix_object(), FLAG_APPLIED, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_STAT_LOSS, NDI_UNIQUE, object_insert_in_ob(), give::op, SET_FLAG, and Ice::tmp.

Referenced by cfapi_object_drain(), drain_stat(), and write_scroll().

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

◆ drain_stat()

void drain_stat ( object op)

Drains a random stat from op. Stat draining by Vick 930307 (Feeling evil, I made it work as well now. -Frank 8)

Parameters
opobject to drain.

Definition at line 717 of file living.c.

References drain_specific_stat(), NUM_STATS, give::op, and RANDOM.

Referenced by hit_with_one_attacktype(), and potion_type_apply().

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

◆ exp_level()

int exp_level ( int64_t  exp)

Returns the level for a given exp.

Parameters
expexperince points to look up in the level table

Definition at line 1886 of file living.c.

References level, levels, Settings::max_level, and settings.

Referenced by show_skills().

+ Here is the caller graph for this function:

◆ find_applied_skill_by_name()

object* find_applied_skill_by_name ( const object op,
const char *  name 
)

Find a skill by name using the last_skill_ob list. Assume last_skill_ob was correctly updated before.

This is defined here rather than server/skill_util.c because things defined in libserver.a are not available when libcommon.a is linked.

Definition at line 1921 of file living.c.

References FLAG_REMOVED, llevDebug, llevError, LOG(), MAX_SKILLS, give::name, give::op, and QUERY_FLAG.

Referenced by add_player_exp(), caster_level(), and kill_object().

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

◆ fix_object()

void fix_object ( object op)

Updates all abilities given by applied objects in the inventory of the given object.

This functions starts from base values (archetype or player object) and then adjusts them according to what the player/monster has equipped.

Note that a player always has stats reset to their initial value.

July 95 - inserted stuff to handle new skills/exp system - b.t. spell system split, grace points now added to system –peterm

November 2006: max armor speed is always taken into account, no exception.

Parameters
opobject to reset.
Todo:
this function is too long, and should be cleaned / split.

Definition at line 1126 of file living.c.

References curse_on_apply::ac, add_refcount(), AMULET, ARCH_DEPLETION, ARMOUR, ARMOUR_SPEED, AT_PHYSICAL, ATNR_PHYSICAL, BOOTS, BOW, BRACERS, change_attr_value(), check_stat_bounds(), CLEAR_FLAG, CLOAK, CLOSE_CON, CONTAINER, DISEASE, fix_player(), FLAG_APPLIED, FLAG_BLIND, FLAG_CONFUSED, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_MONSTER, FLAG_PROBE, FLAG_READY_WEAPON, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_UNDEAD, FLAG_USE_ARMOUR, FLAG_WIZ, FLAG_XRAYS, FOR_INV_FINISH, FOR_INV_PREPARE, FORCE, free_string(), get_attr_value(), GIRDLE, GLOVES, HELMET, if(), make_face_from_files::int, IS_COMBAT_SKILL, IS_GRACE_SKILL, IS_MANA_SKILL, obj::level, llevDebug, llevInfo, LOG(), MAX, say::max, Settings::max_level, Settings::max_stat, MIN_ACTIVE_SPEED, MOVE_FLY_HIGH, MOVE_FLY_LOW, MOVE_WALK, NROFATTACKS, NUM_BODY_LOCATIONS, NUM_STATS, object_update_speed(), give::op, PLAYER, POTION, POTION_RESIST_EFFECT, QUERY_FLAG, range_bow, range_misc, range_skill, RING, ROD, set_attr_value(), SET_FLAG, settings, SHIELD, SK_PRAYING, SKILL, SKILL_TOOL, Settings::spell_encumbrance, SYMPTOM, Ice::tmp, TRUE, autojail::value, WAND, WEAPON, and WEAPON_SPEED.

Referenced by animate_weapon(), apply_race_and_class(), apply_special(), blind_living(), blindness_type_process(), cast_curse(), cfapi_object_fix(), cfapi_object_set_property(), change_abil(), check_login(), command_abil(), command_brace(), command_drop(), command_dropall(), command_fix_me(), command_possess(), command_search_items(), command_take(), create_aura(), do_light(), do_skill(), do_symptoms(), do_turn(), dragon_eat_flesh(), drain_specific_stat(), drop_object(), eat_special_food(), examine_monster(), fire_bow(), fix_weight(), hit_with_one_attacktype(), improve_armour(), improve_weapon_stat(), key_change_class(), kill_player_not_permadeath(), monster_check_apply_all(), monsterFight(), object_decrease_nrof(), object_insert_in_ob(), object_remove(), pay_for_amount(), pay_for_item(), pick_up_object(), player_changer_type_process(), player_lvl_adj(), poison_living(), poisoning_type_process(), potion_type_apply(), put_object_in_sack(), remove_depletion(), remove_force(), remove_symptoms(), roll_stats(), save_life(), slow_living_by(), START_TEST(), stop_jump(), swap_random_stats(), swap_stat(), and unapply_special().

+ Here is the call graph for this function:

◆ fix_player()

static void fix_player ( object op,
int *  ac,
int *  wc,
const object grace_obj,
const object mana_obj,
const object wc_obj,
int  weapon_speed,
float  added_speed 
)
static

Complement to fix_object() for player. Figure out the players sp/mana/hp totals. Also do encumberance and various speeds.

Parameters
opobject being fixed, must not be NULL.
accurrent ac, may be adjusted.
wccurrent wc, may be adjusted.
grace_objpraying skill, can be NULL.
mana_objspell-casting skill, can be NULL.
wc_objapplied combat skill, can be NULL.
weapon_speedcurrent weapon's speed.
added_speedspeed bonus from items.

Definition at line 898 of file living.c.

References curse_on_apply::ac, BASE_WEAPON_SPEED, check_stat_bounds(), esrv_update_spells(), FREE_PLAYER_LOAD_PERCENT, get_con_bonus(), get_dam_bonus(), get_dex_bonus(), get_grace_bonus(), get_sp_bonus(), get_speed_bonus(), get_thaco_bonus(), get_weight_limit(), if(), make_face_from_files::int, obj::level, MAX_PLAYER_SPEED, Settings::max_stat, MIN_PLAYER_SPEED, MIN_STAT, object_get_value(), give::op, PLAYER, Settings::search_items, and settings.

Referenced by fix_object().

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

◆ get_attr_value()

int8_t get_attr_value ( const living stats,
int  attr 
)

◆ get_cha_bonus()

int get_cha_bonus ( int  stat)

Definition at line 2350 of file living.c.

References get_index(), int_bonuses, INT_CHA_BONUS, Settings::max_stat, and settings.

+ Here is the call graph for this function:

◆ get_cleric_chance()

int get_cleric_chance ( int  stat)

Definition at line 2370 of file living.c.

References get_index(), int_bonuses, INT_CLERIC_CHANCE, Settings::max_stat, and settings.

Referenced by cast_spell().

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

◆ get_con_bonus()

static float get_con_bonus ( int  stat)
static

Definition at line 2390 of file living.c.

References float_bonuses, FLOAT_CON_BONUS, get_index(), Settings::max_stat, and settings.

Referenced by fix_player().

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

◆ get_dam_bonus()

int get_dam_bonus ( int  stat)

Definition at line 2378 of file living.c.

References get_index(), int_bonuses, INT_DAM_BONUS, Settings::max_stat, and settings.

Referenced by do_throw(), fire_bow(), and fix_player().

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

◆ get_dex_bonus()

int get_dex_bonus ( int  stat)

Definition at line 2354 of file living.c.

References get_index(), int_bonuses, INT_DEX_BONUS, Settings::max_stat, and settings.

Referenced by do_throw(), fire_bow(), and fix_player().

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

◆ get_fear_bonus()

int get_fear_bonus ( int  stat)

Definition at line 2386 of file living.c.

References get_index(), int_bonuses, INT_FEAR_BONUS, Settings::max_stat, and settings.

Referenced by cast_cone().

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

◆ get_grace_bonus()

static float get_grace_bonus ( int  stat)
static

Definition at line 2398 of file living.c.

References float_bonuses, FLOAT_GRACE_BONUS, get_index(), Settings::max_stat, and settings.

Referenced by fix_player().

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

◆ get_index()

static size_t get_index ( int  stat,
size_t  max_index 
)
static

Limits a stat value to [0..max_index].

Parameters
statindex of the stat to get.
max_indexthe maximum index (inclusive).
Returns
the limited index.

Definition at line 2410 of file living.c.

References npc_dialog::index, and MIN.

Referenced by get_cha_bonus(), get_cleric_chance(), get_con_bonus(), get_dam_bonus(), get_dex_bonus(), get_fear_bonus(), get_grace_bonus(), get_learn_spell(), get_sp_bonus(), get_speed_bonus(), get_thaco_bonus(), get_turn_bonus(), and get_weight_limit().

+ Here is the caller graph for this function:

◆ get_learn_spell()

int get_learn_spell ( int  stat)

Definition at line 2366 of file living.c.

References get_index(), int_bonuses, INT_LEARN_SPELL, Settings::max_stat, and settings.

Referenced by learn_skill(), and spellbook_type_apply().

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

◆ get_sp_bonus()

static float get_sp_bonus ( int  stat)
static

Definition at line 2394 of file living.c.

References float_bonuses, FLOAT_SP_BONUS, get_index(), Settings::max_stat, and settings.

Referenced by fix_player().

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

◆ get_speed_bonus()

float get_speed_bonus ( int  stat)

Definition at line 2382 of file living.c.

References float_bonuses, FLOAT_DEX_BONUS, get_index(), Settings::max_stat, and settings.

Referenced by do_throw(), and fix_player().

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

◆ get_thaco_bonus()

int get_thaco_bonus ( int  stat)

Definition at line 2358 of file living.c.

References get_index(), int_bonuses, INT_THAC0_BONUS, Settings::max_stat, and settings.

Referenced by do_throw(), fire_bow(), and fix_player().

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

◆ get_turn_bonus()

int get_turn_bonus ( int  stat)

Definition at line 2374 of file living.c.

References get_index(), int_bonuses, INT_TURN_BONUS, Settings::max_stat, and settings.

Referenced by cast_cone(), and hit_with_one_attacktype().

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

◆ get_weight_limit()

uint32_t get_weight_limit ( int  stat)

Definition at line 2362 of file living.c.

References get_index(), int_bonuses, INT_WEIGHT_LIMIT, Settings::max_stat, and settings.

Referenced by do_harvest(), do_throw(), esrv_update_stats(), fix_player(), monster_check_pickup(), object_can_pick(), and pick_up_object().

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

◆ give_skill_by_name()

object* give_skill_by_name ( object op,
const char *  skill_name 
)

Given the skill name skill_name, we find the skill archetype/object, set appropriate values, and insert it into the object (op) that is passed.

We return the skill - this makes it easier for calling functions that want to do something with it immediately.

Parameters
opobject to which to give the skill. Must not be NULL.
skill_nameskill to give. Must not be NULL.
Returns
newly created skill, or NULL if failure (logger with error level).
Note
this doesn't check whether the object already has the skill or not.

Definition at line 1779 of file living.c.

References arch_to_object(), CLEAR_FLAG, liv::exp, FLAG_CAN_USE_SKILL, get_archetype_by_skill_name(), obj::level, link_player_skills(), llevError, LOG(), object_insert_in_ob(), give::op, SKILL, and obj::stats.

Referenced by add_player_exp(), adjust_skill_tool(), become_follower(), cfapi_object_give_skill(), do_skill(), food_type_apply(), and learn_skill().

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

◆ init_stats()

void init_stats ( int  reload)

This loads statistic bonus/penalties from the stat_bonus file. If reload is false (eg, this is initial start time load), then any error becomes fatal, as system needs working bonuses.

Parameters
reloadIf set, this is reloading new values - this can be useful for real time adjustment of stat bonuses - however, it also has some more restraints - in particular, max_stat can not decrease (that could be made to work but is more work) and also errors are not fatal - it will just use the old stat bonus tables in the case of any errors. TODO: add code that uses reload
Note
will call exit() if file is invalid or not found.

Definition at line 2594 of file living.c.

References buf, Settings::confdir, float_bonus_names, float_bonuses, FREE_AND_CLEAR, int_bonus_names, int_bonuses, llevError, load_table_float(), load_table_int(), LOG(), MAX_BUF, Settings::max_stat, MIN_STAT, NUM_FLOAT_BONUSES, NUM_INT_BONUSES, and settings.

Referenced by cctk_init_std_archetypes(), and init_library().

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

◆ level_exp()

int64_t level_exp ( int  level,
double  expmul 
)

Returns how much experience is needed for a player to become the given level. level should really never exceed max_level

Parameters
levellevel player wants to reach
expmulpenality/bonus for experience.

Definition at line 1874 of file living.c.

References level, levels, Settings::max_level, and settings.

Referenced by calculate_difficulty(), change_exp(), command_statistics(), place_monsters(), player_lvl_adj(), and show_skills().

+ Here is the caller graph for this function:

◆ load_table_float()

static int load_table_float ( float **  bonuses,
FILE *  fp,
char *  bonus_name 
)
static

This loads up a stat table from the file - basically, it keeps processing until it gets the closing brace.

Parameters
bonusesan array will be allocated and the bonus put into this allocated array.
fpFile to load the data from.
bonus_nameUsed purely for error messages to make it easier to identify where in the file an error is.
Returns
0 on success, 1 on error. In general, the error will be too many or too few bonus values.

Definition at line 2514 of file living.c.

References buf, llevError, LOG(), MAX_BUF, Settings::max_stat, and settings.

Referenced by init_stats().

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

◆ load_table_int()

static int load_table_int ( int **  bonuses,
FILE *  fp,
char *  bonus_name 
)
static

This loads up a stat table from the file - basically, it keeps processing until it gets the closing brace.

Parameters
bonusesan array will be allocated and the bonus put into this allocated array.
fpFile to load the data from.
bonus_nameUsed purely for error messages to make it easier to identify where in the file an error is.
Returns
0 on success, 1 on error. In general, the error will be too many or too few bonus values.

Definition at line 2438 of file living.c.

References buf, llevError, LOG(), MAX_BUF, Settings::max_stat, and settings.

Referenced by init_stats().

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

◆ player_lvl_adj()

void player_lvl_adj ( object who,
object op 
)

For the new exp system. we are concerned with whether the player gets more hp, sp and new levels. Note this this function should only be called for players. Monsters don't really gain levels

Will tell the player about changed levels. A single call will handle mutiple level changes to one object from one effect. The only difference between this and the recursive version is this cannot handle a level that both increases and decreases simultaneously.

Parameters
whoplayer, must not be NULL.
opwhat we are checking to gain the level (eg, skill), can be NULL.

Definition at line 1819 of file living.c.

References buf, die_roll(), dragon_level_gain(), draw_ext_info(), fix_object(), is_dragon_pl(), level_exp(), MAX_BUF, Settings::max_level, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_LEVEL_GAIN, MSG_TYPE_ATTRIBUTE_LEVEL_LOSS, NDI_RED, NDI_UNIQUE, give::op, PLAYER, PREFER_HIGH, settings, and autojail::who.

Referenced by add_player_exp(), apply_death_exp_penalty(), command_addexp(), and subtract_player_exp().

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

◆ remove_depletion()

int remove_depletion ( object op,
int  level 
)

Remove depletion from op, if present, and warn player of such restorations.

Parameters
opwho to remove depletion from.
levelmaximum depletion level to remove, if -1 no maximum.
Returns
0 if no depletion (or with no drained statistics) was present or level was insufficient, 1 if something was removed.

Definition at line 756 of file living.c.

References ARCH_DEPLETION, arch_present_in_ob(), disinfect::count, draw_ext_info(), find_archetype(), fix_object(), get_attr_value(), MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END, NDI_UNIQUE, NUM_STATS, object_free_drop_inventory(), object_remove(), give::op, restore_msg, and obj::stats.

Referenced by cfapi_object_remove_depletion(), god_intervention(), and potion_type_apply().

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

◆ remove_statbonus()

void remove_statbonus ( object op)

Subtracts stat-bonuses given by the class which the player has chosen.

Parameters
opobject which must be a player with contr not NULL.

Definition at line 846 of file living.c.

References give::op.

Referenced by key_change_class().

+ Here is the caller graph for this function:

◆ set_attr_value()

void set_attr_value ( living stats,
int  attr,
int8_t  value 
)

Sets Str/Dex/con/Wis/Cha/Int/Pow in stats to value, depending on what attr is (STR to POW).

Parameters
statsitem to modify. Must not be NULL.
attrattribute to change.
valuenew value.
Todo:
check if attr is valid? Check whether value is valid or not.

Definition at line 219 of file living.c.

References liv::Cha, CHARISMA, liv::Con, CONSTITUTION, liv::Dex, DEXTERITY, liv::Int, INTELLIGENCE, liv::Pow, POWER, liv::Str, STRENGTH, autojail::value, liv::Wis, and WISDOM.

Referenced by apply_changes_to_player(), apply_race_and_class(), cast_change_ability(), change_abil(), check_race_and_class(), check_stat_bounds(), create_player_cmd(), do_symptoms(), eat_special_food(), fix_object(), set_ring_bonus(), swap_random_stats(), and swap_stat().

+ Here is the caller graph for this function:

◆ set_dragon_name()

void set_dragon_name ( object pl,
const object abil,
const object skin 
)

Set the new dragon name after gaining levels or changing ability focus (later this can be extended to eventually change the player's face and animation)

Note that the title is written to 'own_title' in the player struct. This should be changed to 'ext_title' as soon as clients support this! Please, anyone, write support for 'ext_title'.

Parameters
plplayer's object to change.
abildragon's innate abilities.
skindragon's skin.

Definition at line 1679 of file living.c.

References atnr_is_dragon_enabled(), attacks, liv::exp, make_face_from_files::int, NROFATTACKS, player_set_dragon_title(), obj::resist, and obj::stats.

Referenced by check_login(), and dragon_level_gain().

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

◆ share_exp()

void share_exp ( object op,
int64_t  exp,
const char *  skill,
int  flag 
)

Gives experience to a player/monster, sharing it with party if applicable. This does bounds checking to make sure we don't overflow the max exp.

The exp passed is typically not modified much by this function - it is assumed the caller has modified the exp as needed.

This is merely a wrapper for change_exp().

Parameters
opvictim to alter.
expexperience to gain (positive) or lose (negative).
skillskill to change. Can be NULL.
flag
  • if experience gain, what to do if player doesn't have the skill
  • if experience loss, whether to remove from all skills or only specified skill
Note
flag only applies to op, not other players in same party.

Definition at line 2312 of file living.c.

References change_exp(), obj::contr, disinfect::count, first_player, obj::level, pl::next, pl::ob, on_same_map(), give::op, pl::party, altar_valkyrie::pl, PLAYER, and SK_EXP_TOTAL.

Referenced by kill_object(), and mood_change().

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

◆ subtract_player_exp()

static void subtract_player_exp ( object op,
int64_t  exp,
const char *  skill,
int  flag 
)
static

Subtracts experience from player.

Eg, if we figure the player is losing 10% of his total exp, what happens is he loses 10% from all his skills. Note that if permanent exp is used, player may not in fact lose as much as listed. Eg, if player has gotten reduced to the point where everything is at the minimum perm exp, he would lose nothing.

Parameters
opvictim we want to substract from
expvalue to substract. Should be positive.
skillskill to substract exp from. Can be NULL.
flagif SK_SUBTRACT_SKILL_EXP and skill is set, only subtract from the matching skill. Otherwise, this subtracts a portion from all skills the player has.
Todo:
check whether flag is necessary, can't it be only based on skill==null?

Definition at line 2120 of file living.c.

References check_exp_loss(), FOR_INV_FINISH, FOR_INV_PREPARE, give::op, player_lvl_adj(), SK_SUBTRACT_SKILL_EXP, SKILL, and Ice::tmp.

Referenced by change_exp().

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

Variable Documentation

◆ attacks

const char* const attacks[NROFATTACKS]
Initial value:
= {
"physical", "magical", "fire", "electricity", "cold",
"confusion", "acid", "drain", "weaponmagic", "ghosthit",
"poison", "slow", "paralyze", "turn undead", "fear",
"cancellation", "depletion", "death", "chaos", "counterspell",
"god power", "holy power", "blinding", "", "life stealing",
"disease"
}

Attack type names.

Definition at line 130 of file living.c.

Referenced by CREScriptEngine::CREScriptEngine(), describe_attacktype(), did_make_save_item(), and set_dragon_name().

◆ drain_msg

const char* const drain_msg[NUM_STATS]
Initial value:
= {
"You feel drained of strength.",
"You feel drained of agility.",
"You feel drained of health.",
"You feel drained of wisdom.",
"You feel drained of charisma.",
"You feel drained of intelligence.",
"You feel drained of power."
}

Message when a player is drained of a stat.

Definition at line 140 of file living.c.

Referenced by drain_specific_stat(), and kill_player_not_permadeath().

◆ float_bonus_names

const char* float_bonus_names[NUM_FLOAT_BONUSES]
static
Initial value:
= {
"con_hp_bonus", "dex_speed_bonus", "pow_int_sp_bonus", "wis_pow_grace_bonus"
}

Definition at line 92 of file living.c.

Referenced by init_stats().

◆ float_bonuses

float* float_bonuses[NUM_FLOAT_BONUSES]
static

Definition at line 91 of file living.c.

Referenced by get_con_bonus(), get_grace_bonus(), get_sp_bonus(), get_speed_bonus(), and init_stats().

◆ gain_msg

const char* const gain_msg[NUM_STATS]
Initial value:
= {
"You feel stronger.",
"You feel more agile.",
"You feel healthy.",
"You feel wiser.",
"You seem to look better.",
"You feel smarter.",
"You feel more potent."
}

Message when a player increases permanently a stat.

Definition at line 162 of file living.c.

Referenced by change_abil().

◆ int_bonus_names

const char* int_bonus_names[NUM_INT_BONUSES]
static
Initial value:
= {
"cha_fear_bonus", "wis_turn_bonus", "wis_cleric_chance", "int_wis_learn_spell",
"cha_shop_bonus", "dex_bonus", "str_damage_bonus", "str_hit_bonus",
"str_weight_limit",
}

Following array corresponds to the defines above, but are the text names as found in the file. In this way, processing of file is simpler.

Definition at line 76 of file living.c.

Referenced by init_stats().

◆ int_bonuses

◆ levels

◆ lose_msg

const char* const lose_msg[NUM_STATS]
Initial value:
= {
"You feel weaker!",
"You feel clumsy!",
"You feel less healthy!",
"You feel foolish!",
"You look ugly!",
"You feel stupid!",
"You feel less potent!"
}

Message when a player decreases permanently a stat.

Definition at line 173 of file living.c.

Referenced by change_abil(), and kill_player_not_permadeath().

◆ restore_msg

const char* const restore_msg[NUM_STATS]
Initial value:
= {
"You feel your strength return.",
"You feel your agility return.",
"You feel your health return.",
"You feel your wisdom return.",
"You feel your charisma return.",
"You feel your intelligence return.",
"You feel your power return."
}

Message when a player has a stat restored.

Definition at line 151 of file living.c.

Referenced by remove_depletion().

◆ savethrow

const int savethrow[MAX_SAVE_LEVEL+1]
static
Initial value:
= {
18,
18, 17, 16, 15, 14, 14, 13, 13, 12, 12,
12, 11, 11, 11, 11, 10, 10, 10, 10, 9,
9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
5, 5, 5, 5, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
}

Probability to avoid something.

This no longer needs to be changed anytime the number of levels is increased - rather, did_make_save() will do the right thing and always use range within this table. for safety, savethrow should not be accessed directly anymore, and instead did_make_save() should be used instead.

Definition at line 114 of file living.c.

Referenced by did_make_save().

◆ short_stat_name

const char* const short_stat_name[NUM_STATS]
Initial value:
= {
"Str",
"Dex",
"Con",
"Wis",
"Cha",
"Int",
"Pow"
}

Short name of stats.

Definition at line 195 of file living.c.

Referenced by create_player_cmd(), describe_item(), key_roll_stat(), ring_desc(), send_new_char_info(), and swap_stat().

◆ statname

const char* const statname[NUM_STATS]
Initial value:
= {
"strength",
"dexterity",
"constitution",
"wisdom",
"charisma",
"intelligence",
"power"
}

Name of stats.

Definition at line 184 of file living.c.

Referenced by improve_weapon_stat(), and perceive_self().