--- deliantra/server/common/living.C 2007/05/12 17:26:51 1.49 +++ 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) @@ -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,12 +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) @@ -420,7 +373,7 @@ * 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); } /* end of potion handling code */ @@ -659,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]); @@ -837,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; @@ -977,7 +930,7 @@ 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