--- deliantra/server/common/living.C 2007/08/07 21:58:25 1.74 +++ deliantra/server/common/living.C 2007/08/07 23:38:12 1.77 @@ -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; @@ -916,12 +916,11 @@ continue; 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] = stat_sum [i] + tmp->stats.stat (i); 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,16 +935,12 @@ /* 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) - { - speed_reduce_from_disease = tmp->last_sp / 100.f; - - if (speed_reduce_from_disease == 0) - speed_reduce_from_disease = 1; - } + speed_reduce_from_disease = + min (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f); /* Pos. and neg. protections are counted seperate (-> pro/vuln). * (Negative protections are calculated exactly like positive.) @@ -954,7 +949,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 +1164,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 +1172,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 +1192,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 +1206,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 +1231,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 +1265,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 +1309,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)) @@ -1358,14 +1359,17 @@ speed += bonus_speed / 10.f; /* Not affected by limits */ + speed = speed * speed_reduce_from_disease; + /* Put a lower limit on speed. Note with this speed, you move once every * 100 ticks or so. This amounts to once every 12 seconds of realtime. */ - speed = speed * speed_reduce_from_disease; - if (speed < 0.01f && type == PLAYER) speed = 0.01f; + if (speed != old_speed) + set_speed (speed); + if (type == PLAYER) { /* (This formula was made by vidarl@ifi.uio.no) @@ -1406,9 +1410,6 @@ else if (move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) move_type &= ~MOVE_WALK; - if (speed != old_speed) - set_speed (speed); - /* It is quite possible that a player's spell costing might have changed, * so we will check that now. */