--- deliantra/server/common/living.C 2007/05/01 05:48:19 1.46 +++ deliantra/server/common/living.C 2007/05/12 18:14:47 1.50 @@ -235,112 +235,65 @@ }; /* - * sets Str/Dex/con/Wis/Cha/Int/Pow in stats to value, depending on - * what attr is (STR to POW). - */ -void -set_attr_value (living *stats, int attr, sint8 value) -{ - switch (attr) - { - case STR: - stats->Str = value; - break; - case DEX: - stats->Dex = value; - break; - case CON: - stats->Con = value; - break; - case WIS: - stats->Wis = value; - break; - case POW: - stats->Pow = value; - break; - case CHA: - stats->Cha = value; - break; - case INT: - stats->Int = value; - break; - } -} - -/* * Like set_attr_value(), but instead the value (which can be negative) * is added to the specified stat. */ void change_attr_value (living *stats, int attr, sint8 value) { - if (value == 0) - return; + stats->stat (attr) += value; +} - switch (attr) +sint8 & +living::stat (int index) +{ + switch (index) { - case STR: - stats->Str += value; - break; - case DEX: - stats->Dex += value; - break; - case CON: - stats->Con += value; - break; - case WIS: - stats->Wis += value; - break; - case POW: - stats->Pow += value; - break; - case CHA: - stats->Cha += value; - break; - case INT: - stats->Int += value; - break; - default: - LOG (llevError, "Invalid attribute in change_attr_value: %d\n", attr); - } + case STR: return Str; + case DEX: return Dex; + case CON: return Con; + case INT: return Int; + case WIS: return Wis; + case POW: return Pow; + case CHA: return Cha; + } + + LOG (llevError | logBacktrace, "living.stat() called with out-of-range stat index"); + static sint8 dummy; + return dummy; } -/* - * returns the specified stat. See also set_attr_value(). - */ - sint8 -get_attr_value (const living *stats, int attr) +living::stat (int index) const { - switch (attr) + switch (index) { - case STR: return stats->Str; - case DEX: return stats->Dex; - case CON: return stats->Con; - case WIS: return stats->Wis; - case CHA: return stats->Cha; - case INT: return stats->Int; - case POW: return stats->Pow; - } - - return 0; + case STR: return Str; + case DEX: return Dex; + case CON: return Con; + case INT: return Int; + case WIS: return Wis; + case POW: return Pow; + case CHA: return Cha; + } + + LOG (llevError | logBacktrace, "living.stat() called with out-of-range stat index"); + static sint8 dummy; + return dummy; } /* * Ensures that all stats (str/dex/con/wis/cha/int) are within the * 1-30 stat limit. */ - void check_stat_bounds (living *stats) { - int i, v; - - for (i = 0; i < NUM_STATS; i++) - if ((v = get_attr_value (stats, i)) > MAX_STAT) - set_attr_value (stats, i, MAX_STAT); - else if (v < MIN_STAT) - set_attr_value (stats, i, MIN_STAT); + for (int i = 0; i < NUM_STATS; i++) + { + sint8 &v = stats->stat (i); + v = clamp (v, MIN_STAT, MAX_STAT); + } } #define ORIG_S(xyz,abc) (op->contr->orig_stats.abc) @@ -359,7 +312,7 @@ * 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_player should really always be called after this when + * displayed - update_stats 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 @@ -387,8 +340,8 @@ { int nstat, ostat; - ostat = get_attr_value (&(op->contr->orig_stats), j); - i = get_attr_value (&(tmp->stats), j); + ostat = op->contr->orig_stats.stat (j); + i = tmp->stats.stat (j); /* nstat is what the stat will be after use of the potion */ nstat = flag * i + ostat; @@ -400,14 +353,12 @@ */ if (nstat < 1 && i * flag < 0) nstat = 1; - else if (nstat > 20 + get_attr_value (&(op->arch->clone.stats), j)) - { - nstat = 20 + get_attr_value (&(op->arch->clone.stats), j); - } + else if (nstat > 20 + op->arch->clone.stats.stat (j)) + nstat = 20 + op->arch->clone.stats.stat (j); if (nstat != ostat) { - set_attr_value (&(op->contr->orig_stats), j, nstat); + op->contr->orig_stats.stat (j) = nstat; potion_max = 0; } else if (i) @@ -422,9 +373,9 @@ * recalculates this anyway. */ for (j = 0; j < NUM_STATS; j++) - change_attr_value (&(op->stats), j, flag * get_attr_value (&(tmp->stats), j)); + change_attr_value (&op->stats, j, flag * tmp->stats.stat (j)); - check_stat_bounds (&(op->stats)); + check_stat_bounds (&op->stats); } /* end of potion handling code */ } @@ -433,18 +384,18 @@ */ if (flag == -1) { - op->attacktype &= ~tmp->attacktype; - op->path_attuned &= ~tmp->path_attuned; + op->attacktype &= ~tmp->attacktype; + op->path_attuned &= ~tmp->path_attuned; op->path_repelled &= ~tmp->path_repelled; - op->path_denied &= ~tmp->path_denied; + op->path_denied &= ~tmp->path_denied; /* Presuming here that creatures only have move_type, * and not the other move_ fields. */ - op->move_type &= ~tmp->move_type; + op->move_type &= ~tmp->move_type; } /* call fix_player since op object could have whatever attribute due - * to multiple items. if fix_player always has to be called after + * to multiple items. if fix_player always has to be called after * change_ability then might as well call it from here */ op->update_stats (); @@ -502,6 +453,7 @@ DIFF_MSG (flag, "You soar into the air air!.", (op->move_type & MOVE_FLY_LOW ? "You fly lower in the air" : "You float down to the ground.")); } + if (tmp->move_type & MOVE_SWIM) DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming"); @@ -660,7 +612,7 @@ { for (j = 0; j < NUM_STATS; j++) { - if ((i = get_attr_value (&(tmp->stats), j)) != 0) + if ((i = tmp->stats.stat (j))) { success = 1; DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]); @@ -675,7 +627,6 @@ * Stat draining by Vick 930307 * (Feeling evil, I made it work as well now. -Frank 8) */ - void object::drain_stat () { @@ -839,7 +790,7 @@ if (type == PLAYER) { for (i = 0; i < NUM_STATS; i++) - set_attr_value (&(stats), i, get_attr_value (&(contr->orig_stats), i)); + stats.stat (i) = contr->orig_stats.stat (i); if (settings.spell_encumbrance == TRUE) contr->encumbrance = 0; @@ -854,7 +805,8 @@ contr->item_power = 0; } - memcpy (body_used, body_info, sizeof (body_info)); + for (int i = NUM_BODY_LOCATIONS; i--; ) + slot[i].used = slot[i].info; slaying = 0; @@ -965,7 +917,7 @@ * because the skill shouldn't count against body positions being used * up, etc. */ - if ((QUERY_FLAG (tmp, FLAG_APPLIED) + if ((tmp->flag [FLAG_APPLIED] && tmp->type != CONTAINER && tmp->type != CLOSE_CON) || (tmp->type == SKILL @@ -973,25 +925,25 @@ { if (type == PLAYER) { - if ((tmp->type == WEAPON || tmp->type == BOW) - && tmp != current_weapon) - continue; + if (tmp == contr->combat_ob || tmp == contr->ranged_ob) + if (tmp != current_weapon && (tmp->type != SKILL || tmp->subtype != SK_PRAYING)) + continue; for (i = 0; i < NUM_STATS; i++) - change_attr_value (&stats, i, get_attr_value (&tmp->stats, i)); + change_attr_value (&stats, i, tmp->stats.stat (i)); /* these are the items that currently can change digestion, regeneration, * spell point recovery and mana point recovery. Seems sort of an arbitary * list, but other items store other info into stats array. */ - if ((tmp->type == WEAPON) || (tmp->type == BOW) || - (tmp->type == ARMOUR) || (tmp->type == HELMET) || - (tmp->type == SHIELD) || (tmp->type == RING) || - (tmp->type == BOOTS) || (tmp->type == GLOVES) || - (tmp->type == AMULET) || (tmp->type == GIRDLE) || - (tmp->type == BRACERS) || (tmp->type == CLOAK) || - (tmp->type == DISEASE) || (tmp->type == FORCE) || - (tmp->type == SKILL)) + if (tmp->type == WEAPON || tmp->type == BOW || + tmp->type == ARMOUR || tmp->type == HELMET || + tmp->type == SHIELD || tmp->type == RING || + tmp->type == BOOTS || tmp->type == GLOVES || + tmp->type == AMULET || tmp->type == GIRDLE || + tmp->type == BRACERS || tmp->type == CLOAK || + tmp->type == DISEASE || tmp->type == FORCE || + tmp->type == SKILL) { contr->digestion += tmp->stats.food; contr->gen_hp += tmp->stats.hp; @@ -1010,7 +962,7 @@ /* Update slots used for items */ if (QUERY_FLAG (tmp, FLAG_APPLIED)) for (i = 0; i < NUM_BODY_LOCATIONS; i++) - body_used[i] += tmp->body_info[i]; + slot[i].used += tmp->slot[i].info; if (tmp->type == SYMPTOM) {