--- deliantra/server/common/living.C 2007/08/07 21:58:25 1.74 +++ deliantra/server/common/living.C 2007/08/07 22:36:18 1.75 @@ -759,19 +759,19 @@ void object::update_stats () { - int i, j; float f, max_speed = 9, added_speed = 0, bonus_speed = 0, speed_reduce_from_disease = 1; int weapon_weight = 0, weapon_speed = 0; int best_wc = 0, best_ac = 0, wc = 0, ac = 0; int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS]; object *grace_obj = NULL, *mana_obj = NULL, *tmp; float old_speed = speed; + int stat_sum [NUM_STATS]; /* First task is to clear all the values back to their original values */ if (type == PLAYER) { - for (i = 0; i < NUM_STATS; i++) - stats.stat (i) = contr->orig_stats.stat (i); + for (int i = 0; i < NUM_STATS; i++) + stat_sum [i] = contr->orig_stats.stat (i); if (settings.spell_encumbrance == TRUE) contr->encumbrance = 0; @@ -819,7 +819,7 @@ */ memcpy (&resist, &arch->resist, sizeof (resist)); - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) { if (resist[i] > 0) prot[i] = resist[i], vuln[i] = 0; @@ -917,11 +917,11 @@ for (int i = 0; i < NUM_STATS; i++) if (expect_false (tmp->stats.stat (i))) - stats.stat (i) = clamp (stats.stat (i) + tmp->stats.stat (i), MIN_STAT, MAX_STAT); + stat_sum [i] = clamp (stat_sum [i] + tmp->stats.stat (i), MIN_STAT, MAX_STAT); if (digest_types [tmp->type]) { - contr->digestion = clamp (int (contr->digestion) + tmp->stats.food, MIN_DIGESTION, MAX_DIGESTION); + contr->digestion += tmp->stats.food; contr->gen_hp += tmp->stats.hp; contr->gen_sp += tmp->stats.sp; contr->gen_grace += tmp->stats.grace; @@ -936,7 +936,7 @@ /* Update slots used for items */ if (QUERY_FLAG (tmp, FLAG_APPLIED)) - for (i = 0; i < NUM_BODY_LOCATIONS; i++) + for (int i = 0; i < NUM_BODY_LOCATIONS; i++) slot[i].used += tmp->slot[i].info; if (tmp->type == SYMPTOM) @@ -954,7 +954,7 @@ */ if (tmp->type != POTION) { - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) { /* Potential for cursed potions, in which case we just can use * a straight MAX, as potion_resist is initialised to zero. @@ -1169,7 +1169,7 @@ * If there is a cursed (and no uncursed) potion in effect, we take * 'total resistance = vulnerability from cursed potion'. */ - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) { resist[i] = prot[i] - vuln[i]; @@ -1177,9 +1177,15 @@ resist[i] = potion_resist[i]; } - /* Figure out the players sp/mana/hp totals. */ if (type == PLAYER) { + // clamp various player stats + for (int i = 0; i < NUM_STATS; ++i) + stats.stat (i) = clamp (stat_sum [i], MIN_STAT, MAX_STAT); + + contr->digestion = clamp (contr->digestion, MIN_DIGESTION, MAX_DIGESTION); + + /* Figure out the players sp/mana/hp totals. */ int pl_level; check_stat_bounds (&(stats)); @@ -1191,9 +1197,10 @@ /* You basically get half a con bonus/level. But we do take into account rounding, * so if your bonus is 7, you still get 7 worth of bonus every 2 levels. */ - for (i = 1, stats.maxhp = 0; i <= pl_level && i <= 10; i++) + stats.maxhp = 0; + for (int i = 1; i <= min (10, pl_level); i++) { - j = contr->levhp[i] + con_bonus[stats.Con] / 2; + int j = contr->levhp[i] + con_bonus[stats.Con] / 2; if (i % 2 && con_bonus[stats.Con] % 2) if (con_bonus[stats.Con] > 0) @@ -1204,8 +1211,7 @@ stats.maxhp += j > 1 ? j : 1; /* always get at least 1 hp/level */ } - for (i = 11; i <= level; i++) - stats.maxhp += 2; + stats.maxhp += 2 * max (0, level - 10); if (stats.hp > stats.maxhp) stats.hp = stats.maxhp; @@ -1230,7 +1236,7 @@ { float sp_tmp = 0.f; - for (i = 1; i <= min (10, mana_obj->level); i++) + for (int i = 1; i <= min (10, mana_obj->level); i++) { float stmp; @@ -1264,7 +1270,7 @@ */ float sp_tmp = 0.f; - for (i = 1; i <= min (10, grace_obj->level); i++) + for (int i = 1; i <= min (10, grace_obj->level); i++) { float grace_tmp = 0.f; @@ -1308,7 +1314,7 @@ { wc -= wc_obj->level + thaco_bonus[stats.Str]; - for (i = 1; i < wc_obj->level; i++) + for (int i = 1; i < wc_obj->level; i++) { /* additional wc every 6 levels */ if (!(i % 6))