--- deliantra/server/common/living.C 2007/04/30 04:25:29 1.45 +++ deliantra/server/common/living.C 2007/05/12 18:34:19 1.52 @@ -235,112 +235,27 @@ }; /* - * 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; - - 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; - default: - LOG (llevError, "Invalid attribute in change_attr_value: %d\n", attr); - } -} - -/* - * returns the specified stat. See also set_attr_value(). - */ - -sint8 -get_attr_value (const living *stats, int attr) -{ - switch (attr) - { - 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; + stats->stat (attr) += value; } /* * 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 +274,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 @@ -368,7 +283,7 @@ int change_abil (object *op, object *tmp) { - int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, i, j, success = 0; + int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, success = 0; char message[MAX_BUF]; int potion_max = 0; @@ -383,15 +298,13 @@ if (tmp->type == POTION) { potion_max = 1; - for (j = 0; j < NUM_STATS; j++) + for (int j = 0; j < NUM_STATS; j++) { - int nstat, ostat; - - ostat = get_attr_value (&(op->contr->orig_stats), j); - i = get_attr_value (&(tmp->stats), j); + int ostat = op->contr->orig_stats.stat (j); + int i = tmp->stats.stat (j); /* nstat is what the stat will be after use of the potion */ - nstat = flag * i + ostat; + int nstat = flag * i + ostat; /* Do some bounds checking. While I don't think any * potions do so right now, there is the potential for potions @@ -400,14 +313,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) @@ -421,35 +332,35 @@ * sure if this is strictly necessary, being that fix_player probably * recalculates this anyway. */ - for (j = 0; j < NUM_STATS; j++) - change_attr_value (&(op->stats), j, flag * get_attr_value (&(tmp->stats), j)); + for (int j = 0; j < NUM_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 */ } - /* reset attributes that fix_player doesn't reset since it doesn't search + /* reset attributes that update_stats doesn't reset since it doesn't search * everything to set */ 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 update_stats always has to be called after * change_ability then might as well call it from here */ op->update_stats (); - /* Fix player won't add the bows ability to the player, so don't + /* update_stats won't add the bows ability to the player, so don't * print out message if this is a bow. */ if (tmp->attacktype & AT_CONFUSION && tmp->type != BOW) @@ -499,9 +410,10 @@ /* double conditional - second case covers if you have move_fly_low - * in that case, you don't actually land */ - DIFF_MSG (flag, "You soar into the air air!.", + DIFF_MSG (flag, "You soar into the 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"); @@ -639,7 +551,7 @@ } /* Messages for changed resistance */ - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) { if (i == ATNR_PHYSICAL) continue; /* Don't display about armour */ @@ -658,9 +570,9 @@ if (!potion_max) { - for (j = 0; j < NUM_STATS; j++) + for (int j = 0; j < NUM_STATS; j++) { - if ((i = get_attr_value (&(tmp->stats), j)) != 0) + if (int i = tmp->stats.stat (j)) { success = 1; DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]); @@ -675,7 +587,6 @@ * Stat draining by Vick 930307 * (Feeling evil, I made it work as well now. -Frank 8) */ - void object::drain_stat () { @@ -774,21 +685,12 @@ void object::remove_statbonus () { - stats.Str -= arch->clone.stats.Str; - stats.Dex -= arch->clone.stats.Dex; - stats.Con -= arch->clone.stats.Con; - stats.Wis -= arch->clone.stats.Wis; - stats.Pow -= arch->clone.stats.Pow; - stats.Cha -= arch->clone.stats.Cha; - stats.Int -= arch->clone.stats.Int; - - contr->orig_stats.Str -= arch->clone.stats.Str; - contr->orig_stats.Dex -= arch->clone.stats.Dex; - contr->orig_stats.Con -= arch->clone.stats.Con; - contr->orig_stats.Wis -= arch->clone.stats.Wis; - contr->orig_stats.Pow -= arch->clone.stats.Pow; - contr->orig_stats.Cha -= arch->clone.stats.Cha; - contr->orig_stats.Int -= arch->clone.stats.Int; + for (int i = 0; i < NUM_STATS; ++i) + { + sint8 v = arch->clone.stats.stat (i); + stats.stat (i) -= v; + contr->orig_stats.stat (i) -= v; + } } /* @@ -797,21 +699,12 @@ void object::add_statbonus () { - stats.Str += arch->clone.stats.Str; - stats.Dex += arch->clone.stats.Dex; - stats.Con += arch->clone.stats.Con; - stats.Wis += arch->clone.stats.Wis; - stats.Pow += arch->clone.stats.Pow; - stats.Cha += arch->clone.stats.Cha; - stats.Int += arch->clone.stats.Int; - - contr->orig_stats.Str += arch->clone.stats.Str; - contr->orig_stats.Dex += arch->clone.stats.Dex; - contr->orig_stats.Con += arch->clone.stats.Con; - contr->orig_stats.Wis += arch->clone.stats.Wis; - contr->orig_stats.Pow += arch->clone.stats.Pow; - contr->orig_stats.Cha += arch->clone.stats.Cha; - contr->orig_stats.Int += arch->clone.stats.Int; + for (int i = 0; i < NUM_STATS; ++i) + { + sint8 v = arch->clone.stats.stat (i); + stats.stat (i) += v; + contr->orig_stats.stat (i) += v; + } } /* @@ -839,7 +732,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 +747,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; @@ -879,7 +773,7 @@ glow_radius = arch->clone.glow_radius; move_type = arch->clone.move_type; - chosen_skill = NULL; + chosen_skill = 0; /* initializing resistances from the values in player/monster's * archetype clone @@ -892,6 +786,7 @@ prot[i] = resist[i], vuln[i] = 0; else vuln[i] = -(resist[i]), prot[i] = 0; + potion_resist[i] = 0; } @@ -964,7 +859,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 @@ -972,21 +867,25 @@ { if (type == PLAYER) { + 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; @@ -996,11 +895,16 @@ contr->item_power += tmp->item_power; } } /* if this is a player */ + else + { + if (tmp->type == WEAPON) + current_weapon = tmp; + } /* 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) { @@ -1037,14 +941,16 @@ } /* There may be other things that should not adjust the attacktype */ - if (tmp->type != BOW && tmp->type != SYMPTOM) - attacktype |= tmp->attacktype; - - path_attuned |= tmp->path_attuned; - path_repelled |= tmp->path_repelled; - path_denied |= tmp->path_denied; - move_type |= tmp->move_type; - stats.luck += tmp->stats.luck; + if ((tmp->type != WEAPON && tmp->type != BOW && tmp->type != SYMPTOM) + || current_weapon == tmp) + { + attacktype |= tmp->attacktype; + path_attuned |= tmp->path_attuned; + path_repelled |= tmp->path_repelled; + path_denied |= tmp->path_denied; + move_type |= tmp->move_type; + stats.luck += tmp->stats.luck; + } if (QUERY_FLAG (tmp, FLAG_LIFESAVE )) SET_FLAG (this, FLAG_LIFESAVE); if (QUERY_FLAG (tmp, FLAG_REFL_SPELL )) SET_FLAG (this, FLAG_REFL_SPELL); @@ -1076,15 +982,14 @@ switch (tmp->type) { +#if 0 case WAND: case ROD: case HORN: - if (type == PLAYER) - { - contr->ranged_skill = this; - contr->ranged_ob = tmp; - } + if (type != PLAYER || current_weapon == tmp) + chosen_skill = tmp; break; +#endif /* skills modifying the character -b.t. */ /* for all skills and skill granting objects */ @@ -1127,12 +1032,6 @@ if (settings.spell_encumbrance == TRUE && type == PLAYER) contr->encumbrance += (int) 3 *tmp->weight / 1000; - if (type == PLAYER) - { - contr->ranged_skill = this; - contr->ranged_ob = tmp; - } - break; case SKILL_TOOL: @@ -1140,12 +1039,6 @@ LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name); chosen_skill = tmp; - - if (type == PLAYER) - { - contr->ranged_skill = this; - contr->ranged_ob = tmp; - } break; case SHIELD: @@ -1171,9 +1064,7 @@ case BOW: case WEAPON: - if (type != PLAYER - || (contr->combat_skill && contr->combat_skill->type == SKILL && (skill_flags [contr->combat_skill->subtype] & SF_NEED_BOW ) && tmp->type == BOW ) - || (contr->combat_skill && contr->combat_skill->type == SKILL && (skill_flags [contr->combat_skill->subtype] & SF_NEED_WEAPON) && tmp->type == WEAPON)) + if (type != PLAYER || current_weapon == tmp) { wc -= tmp->stats.wc + tmp->magic; @@ -1194,15 +1085,9 @@ * go. */ - current_weapon = tmp; - if (type == PLAYER) - { - contr->combat_ob = tmp; - - if (settings.spell_encumbrance) - contr->encumbrance += tmp->weight * 3 / 1000; - } + if (settings.spell_encumbrance) + contr->encumbrance += tmp->weight * 3 / 1000; } break; @@ -1838,11 +1723,11 @@ /* prevents some forms of abuse. */ if (op->contr->braced) - exp = exp / 5; + exp /= 5; /* Try to find the matching skill. * We do a shortcut/time saving mechanism first - see if it matches - * chosen_skill. This means we don't need to search through + * chosen_skill. This means we don't need to search through * the players inventory. */ if (skill_name)