--- deliantra/server/common/living.C 2007/04/29 04:14:57 1.38 +++ deliantra/server/common/living.C 2007/05/12 18:23:51 1.51 @@ -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; } -} -/* - * returns the specified stat. See also set_attr_value(). - */ + LOG (llevError | logBacktrace, "living.stat() called with out-of-range stat index"); + static sint8 dummy; + return dummy; +} 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; + 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; } - return 0; + 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 @@ -368,7 +321,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 +336,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 +351,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 +370,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 +448,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 +589,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 +608,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 +625,6 @@ * Stat draining by Vick 930307 * (Feeling evil, I made it work as well now. -Frank 8) */ - void object::drain_stat () { @@ -774,21 +723,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 +737,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,30 +770,23 @@ 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; attacktype = 0; - contr->digestion = 0; - contr->gen_hp = 0; - contr->gen_sp = 0; - contr->gen_grace = 0; - contr->gen_sp_armour = 10; - contr->item_power = 0; - /* Don't clobber all the range_ values. range_golem otherwise - * gets reset for no good reason, and we don't want to reset - * range_magic (what spell is readied). These three below - * well get filled in based on what the player has equipped. - */ - contr->ranges[range_bow] = 0; - contr->ranges[range_misc] = 0; - contr->ranges[range_skill] = 0; + contr->digestion = 0; + contr->gen_hp = 0; + contr->gen_sp = 0; + contr->gen_grace = 0; + contr->gen_sp_armour = 10; + 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; @@ -881,12 +805,13 @@ if (!QUERY_FLAG (&arch->clone, FLAG_UNDEAD )) CLEAR_FLAG (this, FLAG_UNDEAD); if (!QUERY_FLAG (&arch->clone, FLAG_SEE_IN_DARK )) CLEAR_FLAG (this, FLAG_SEE_IN_DARK); - path_attuned = arch->clone.path_attuned; + path_attuned = arch->clone.path_attuned; path_repelled = arch->clone.path_repelled; - path_denied = arch->clone.path_denied; - glow_radius = arch->clone.glow_radius; - move_type = arch->clone.move_type; - chosen_skill = NULL; + path_denied = arch->clone.path_denied; + glow_radius = arch->clone.glow_radius; + move_type = arch->clone.move_type; + + chosen_skill = 0; /* initializing resistances from the values in player/monster's * archetype clone @@ -899,6 +824,7 @@ prot[i] = resist[i], vuln[i] = 0; else vuln[i] = -(resist[i]), prot[i] = 0; + potion_resist[i] = 0; } @@ -935,7 +861,7 @@ glow_radius = tmp->glow_radius; /* This happens because apply_potion calls change_abil with the potion - * applied so we can tell the player what chagned. But change_abil + * applied so we can tell the player what changed. But change_abil * then calls this function. */ if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION) @@ -971,32 +897,33 @@ * because the skill shouldn't count against body positions being used * up, etc. */ - if ((QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type != CONTAINER && tmp->type != CLOSE_CON) || - (tmp->type == SKILL && tmp->subtype == SK_PRAYING)) + if ((tmp->flag [FLAG_APPLIED] + && tmp->type != CONTAINER + && tmp->type != CLOSE_CON) + || (tmp->type == SKILL + && tmp->subtype == SK_PRAYING)) { if (type == PLAYER) { - if (tmp->type == BOW) - contr->ranges[range_bow] = tmp; - - if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) - contr->ranges[range_misc] = tmp; + 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; @@ -1006,15 +933,21 @@ 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) { - speed_reduce_from_disease = tmp->last_sp / 100.0; + speed_reduce_from_disease = tmp->last_sp / 100.f; + if (speed_reduce_from_disease == 0) speed_reduce_from_disease = 1; } @@ -1046,14 +979,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; - stats.luck += tmp->stats.luck; - move_type |= tmp->move_type; + 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 +1011,24 @@ { if (tmp->stats.exp > 0) { - added_speed += (float) tmp->stats.exp / 3.0; - bonus_speed += 1.0 + (float) tmp->stats.exp / 3.0; + added_speed += tmp->stats.exp / 3.f; + bonus_speed += tmp->stats.exp / 3.f + 1.f; } else - added_speed += (float) tmp->stats.exp; + added_speed += tmp->stats.exp; } switch (tmp->type) { +#if 0 + case WAND: + case ROD: + case HORN: + if (type != PLAYER || current_weapon == tmp) + chosen_skill = tmp; + break; +#endif + /* skills modifying the character -b.t. */ /* for all skills and skill granting objects */ case SKILL: @@ -1102,7 +1046,7 @@ if (tmp->stats.dam > 0) { /* skill is a 'weapon' */ if (!QUERY_FLAG (this, FLAG_READY_WEAPON)) - weapon_speed = (int) WEAPON_SPEED (tmp); + weapon_speed = WEAPON_SPEED (tmp); if (weapon_speed < 0) weapon_speed = 0; @@ -1115,20 +1059,17 @@ } if (tmp->stats.wc) - wc -= (tmp->stats.wc + tmp->magic); + wc -= tmp->stats.wc + tmp->magic; - if (tmp->slaying != NULL) + if (tmp->slaying) slaying = tmp->slaying; if (tmp->stats.ac) - ac -= (tmp->stats.ac + tmp->magic); + ac -= tmp->stats.ac + tmp->magic; if (settings.spell_encumbrance == TRUE && type == PLAYER) contr->encumbrance += (int) 3 *tmp->weight / 1000; - if (type == PLAYER) - contr->ranges[range_skill] = this; - break; case SKILL_TOOL: @@ -1136,9 +1077,6 @@ LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name); chosen_skill = tmp; - - if (type == PLAYER) - contr->ranges[range_skill] = this; break; case SHIELD: @@ -1164,32 +1102,37 @@ case BOW: case WEAPON: - wc -= tmp->stats.wc + tmp->magic; + if (type != PLAYER || current_weapon == tmp) + { + wc -= tmp->stats.wc + tmp->magic; - if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) - ac -= tmp->stats.ac + tmp->magic; + if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) + ac -= tmp->stats.ac + tmp->magic; - stats.dam += tmp->stats.dam + tmp->magic; - weapon_weight = tmp->weight; - weapon_speed = ((int) WEAPON_SPEED (tmp) * 2 - tmp->magic) / 2; - - if (weapon_speed < 0) - weapon_speed = 0; - - slaying = tmp->slaying; - /* If there is desire that two handed weapons should do - * extra strength damage, this is where the code should - * go. - */ - current_weapon = tmp; - if (settings.spell_encumbrance == TRUE && type == PLAYER) - contr->encumbrance += (int) 3 *tmp->weight / 1000; + stats.dam += tmp->stats.dam + tmp->magic; + weapon_weight = tmp->weight; + weapon_speed = (WEAPON_SPEED (tmp) * 2 - tmp->magic) / 2; + + if (weapon_speed < 0) + weapon_speed = 0; + + slaying = tmp->slaying; + + /* If there is desire that two handed weapons should do + * extra strength damage, this is where the code should + * go. + */ + + if (type == PLAYER) + if (settings.spell_encumbrance) + contr->encumbrance += tmp->weight * 3 / 1000; + } break; case ARMOUR: /* Only the best of these three are used: */ if (settings.spell_encumbrance == TRUE && type == PLAYER) - contr->encumbrance += (int) tmp->weight / 1000; + contr->encumbrance += tmp->weight / 1000; case BRACERS: case FORCE: @@ -1221,8 +1164,8 @@ if (tmp->stats.ac) ac -= (tmp->stats.ac + tmp->magic); - if (ARMOUR_SPEED (tmp) && ARMOUR_SPEED (tmp) / 10.0 < max) - max = ARMOUR_SPEED (tmp) / 10.0; + if (ARMOUR_SPEED (tmp) && ARMOUR_SPEED (tmp) / 10.f < max) + max = ARMOUR_SPEED (tmp) / 10.f; break; } /* switch tmp->type */ @@ -1300,7 +1243,7 @@ stats.maxsp = 1; else { - sp_tmp = 0.0; + sp_tmp = 0.f; for (i = 1; i <= mana_obj->level && i <= 10; i++) { @@ -1308,17 +1251,17 @@ /* Got some extra bonus at first level */ if (i < 2) - stmp = contr->levsp[i] + ((2.0 * (float) sp_bonus[stats.Pow] + (float) sp_bonus[stats.Int]) / 6.0); + stmp = contr->levsp[i] + (2.f * sp_bonus[stats.Pow] + sp_bonus[stats.Int]) / 6.f; else - stmp = (float) contr->levsp[i] + (2.0 * (float) sp_bonus[stats.Pow] + (float) sp_bonus[stats.Int]) / 12.0; + stmp = contr->levsp[i] + (2.f * sp_bonus[stats.Pow] + sp_bonus[stats.Int]) / 12.f; - if (stmp < 1.0) - stmp = 1.0; + if (stmp < 1.f) + stmp = 1.f; sp_tmp += stmp; } - stats.maxsp = (int) sp_tmp; + stats.maxsp = (sint16)sp_tmp; for (i = 11; i <= mana_obj->level; i++) stats.maxsp += 2; @@ -1340,26 +1283,24 @@ * becomes big jumps when the sums of the bonuses jump to the next * step of 8 - with floats, even fractional ones are useful. */ - sp_tmp = 0.0; + sp_tmp = 0.f; for (i = 1, stats.maxgrace = 0; i <= grace_obj->level && i <= 10; i++) { - float grace_tmp = 0.0; + float grace_tmp = 0.f; /* Got some extra bonus at first level */ if (i < 2) - grace_tmp = contr->levgrace[i] + (((float) grace_bonus[stats.Pow] + - 2.0 * (float) grace_bonus[stats.Wis]) / 6.0); + grace_tmp = contr->levgrace[i] + (grace_bonus[stats.Pow] + 2.f * grace_bonus[stats.Wis]) / 6.f; else - grace_tmp = (float) contr->levgrace[i] - + ((float) grace_bonus[stats.Pow] + 2.0 * (float) grace_bonus[stats.Wis]) / 12.0; + grace_tmp = contr->levgrace[i] + (grace_bonus[stats.Pow] + 2.f * grace_bonus[stats.Wis]) / 12.f; - if (grace_tmp < 1.0) - grace_tmp = 1.0; + if (grace_tmp < 1.f) + grace_tmp = 1.f; sp_tmp += grace_tmp; } - stats.maxgrace = (int) sp_tmp; + stats.maxgrace = (sint16)sp_tmp; /* two grace points per level after 11 */ for (i = 11; i <= grace_obj->level; i++) @@ -1410,7 +1351,7 @@ if (stats.dam < 1) stats.dam = 1; - speed = 1.0 + speed_bonus[stats.Dex]; + speed = 1.f + speed_bonus[stats.Dex]; if (settings.search_items && contr->search_str[0]) speed -= 1; @@ -1421,9 +1362,9 @@ } /* End if player */ if (added_speed >= 0) - speed += added_speed / 10.0; + speed += added_speed / 10.f; else /* Something wrong here...: */ - speed /= (float) (1.0 - added_speed); + speed /= 1.f - added_speed; /* Max is determined by armour */ if (speed > max) @@ -1438,43 +1379,45 @@ */ f = (carrying / 1000) - max_carry[stats.Str]; if (f > 0) - speed = speed / (1.0 + f / max_carry[stats.Str]); + speed = speed / (1.f + f / max_carry[stats.Str]); } - speed += bonus_speed / 10.0; /* Not affected by limits */ + speed += bonus_speed / 10.f; /* Not affected by limits */ /* 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.01 && type == PLAYER) - speed = 0.01; + if (speed < 0.01f && type == PLAYER) + speed = 0.01f; if (type == PLAYER) { - float M, W, s, D, K, S, M2; - /* (This formula was made by vidarl@ifi.uio.no) * Note that we never used these values again - basically * all of these could be subbed into one big equation, but * that would just be a real pain to read. */ - M = (max_carry[stats.Str] - 121) / 121.0; - M2 = max_carry[stats.Str] / 100.0; - W = weapon_weight / 20000.0; - s = 2 - weapon_speed / 10.0; - D = (stats.Dex - 14) / 14.0; - K = 1 + M / 3.0 - W / (3 * M2) + speed / 5.0 + D / 2.0; - K *= (4 + level) / (float) (6 + level) * 1.2; - if (K <= 0) - K = 0.01; - S = speed / (K * s); + float M = (max_carry[stats.Str] - 121) / 121.f; + float M2 = max_carry[stats.Str] / 100.f; + float W = weapon_weight / 20000.f; + float s = 2 - weapon_speed / 10.f; + float D = (stats.Dex - 14) / 14.f; + float K = 1 + M / 3.f - W / (3 * M2) + speed / 5.f + D / 2.f; + + K *= (4 + level) *1.2f / (6 + level); + + if (K <= 0.f) + K = 0.01f; + + float S = speed / (K * s); + contr->weapon_sp = S; } /* I want to limit the power of small monsters with big weapons: */ - if (type != PLAYER && arch != NULL && stats.dam > arch->clone.stats.dam * 3) + if (type != PLAYER && arch && stats.dam > arch->clone.stats.dam * 3) stats.dam = arch->clone.stats.dam * 3; /* Prevent overflows of wc - best you can get is ABS(120) - this @@ -1533,8 +1476,13 @@ int allowed_class (const object *op) { - return op->stats.Dex > 0 && op->stats.Str > 0 && op->stats.Con > 0 && - op->stats.Int > 0 && op->stats.Wis > 0 && op->stats.Pow > 0 && op->stats.Cha > 0; + return op->stats.Dex > 0 + && op->stats.Str > 0 + && op->stats.Con > 0 + && op->stats.Int > 0 + && op->stats.Wis > 0 + && op->stats.Pow > 0 + && op->stats.Cha > 0; } /* @@ -1766,6 +1714,7 @@ { if (level > settings.max_level) return (sint64) (expmul * levels[settings.max_level]); + return (sint64) (expmul * levels[level]); } @@ -1812,11 +1761,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)