--- deliantra/server/common/living.C 2007/05/12 18:14:47 1.50 +++ deliantra/server/common/living.C 2007/06/04 13:04:00 1.67 @@ -1,25 +1,25 @@ /* - * CrossFire, A Multiplayer game + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Crossfire TRT is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * You should have received a copy of the GNU General Public License along + * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ #include @@ -244,44 +244,6 @@ stats->stat (attr) += value; } -sint8 & -living::stat (int index) -{ - switch (index) - { - 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; -} - -sint8 -living::stat (int index) const -{ - switch (index) - { - 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. @@ -321,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; @@ -336,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 = op->contr->orig_stats.stat (j); - i = tmp->stats.stat (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 @@ -353,8 +313,8 @@ */ if (nstat < 1 && i * flag < 0) nstat = 1; - else if (nstat > 20 + op->arch->clone.stats.stat (j)) - nstat = 20 + op->arch->clone.stats.stat (j); + else if (nstat > 20 + op->arch->stats.stat (j)) + nstat = 20 + op->arch->stats.stat (j); if (nstat != ostat) { @@ -372,14 +332,14 @@ * sure if this is strictly necessary, being that fix_player probably * recalculates this anyway. */ - for (j = 0; j < NUM_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); } /* 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) @@ -395,12 +355,12 @@ } /* 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) @@ -450,7 +410,7 @@ /* 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.")); } @@ -464,7 +424,7 @@ /* becoming UNDEAD... a special treatment for this flag. Only those not * originally undead may change their status */ - if (!QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) + if (!QUERY_FLAG (op->arch, FLAG_UNDEAD)) if (QUERY_FLAG (op, FLAG_UNDEAD) != QUERY_FLAG (&refop, FLAG_UNDEAD)) { success = 1; @@ -475,7 +435,7 @@ } else { - op->race = op->arch->clone.race; + op->race = op->arch->race; new_draw_info (NDI_UNIQUE, 0, op, "Your lifeforce returns!"); } } @@ -591,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 */ @@ -610,9 +570,9 @@ if (!potion_max) { - for (j = 0; j < NUM_STATS; j++) + for (int j = 0; j < NUM_STATS; j++) { - if ((i = tmp->stats.stat (j))) + if (int i = tmp->stats.stat (j)) { success = 1; DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]); @@ -725,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->stats.stat (i); + stats.stat (i) -= v; + contr->orig_stats.stat (i) -= v; + } } /* @@ -748,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->stats.stat (i); + stats.stat (i) += v; + contr->orig_stats.stat (i) += v; + } } /* @@ -783,7 +725,7 @@ 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, *wc_obj = NULL, *tmp; + object *grace_obj = NULL, *mana_obj = NULL, *tmp; float old_speed = speed; /* First task is to clear all the values back to their original values */ @@ -820,23 +762,23 @@ CLEAR_FLAG (this, FLAG_STEALTH); CLEAR_FLAG (this, FLAG_BLIND); - if (!QUERY_FLAG (&arch->clone, FLAG_REFL_SPELL )) CLEAR_FLAG (this, FLAG_REFL_SPELL); - if (!QUERY_FLAG (&arch->clone, FLAG_REFL_MISSILE)) CLEAR_FLAG (this, FLAG_REFL_MISSILE); - 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_repelled = arch->clone.path_repelled; - path_denied = arch->clone.path_denied; - glow_radius = arch->clone.glow_radius; - move_type = arch->clone.move_type; + if (!QUERY_FLAG (arch, FLAG_REFL_SPELL )) CLEAR_FLAG (this, FLAG_REFL_SPELL); + if (!QUERY_FLAG (arch, FLAG_REFL_MISSILE)) CLEAR_FLAG (this, FLAG_REFL_MISSILE); + if (!QUERY_FLAG (arch, FLAG_UNDEAD )) CLEAR_FLAG (this, FLAG_UNDEAD); + if (!QUERY_FLAG (arch, FLAG_SEE_IN_DARK )) CLEAR_FLAG (this, FLAG_SEE_IN_DARK); + + path_attuned = arch->path_attuned; + path_repelled = arch->path_repelled; + path_denied = arch->path_denied; + glow_radius = arch->glow_radius; + move_type = arch->move_type; chosen_skill = 0; /* initializing resistances from the values in player/monster's * archetype clone */ - memcpy (&resist, &arch->clone.resist, sizeof (resist)); + memcpy (&resist, &arch->resist, sizeof (resist)); for (i = 0; i < NROFATTACKS; i++) { @@ -848,8 +790,8 @@ potion_resist[i] = 0; } - wc = arch->clone.stats.wc; - stats.dam = arch->clone.stats.dam; + wc = arch->stats.wc; + stats.dam = arch->stats.dam; /* for players which cannot use armour, they gain AC -1 per 3 levels, * plus a small amount of physical resist, those poor suckers. ;) @@ -860,26 +802,20 @@ */ if (!QUERY_FLAG (this, FLAG_USE_ARMOUR) && type == PLAYER) { - ac = MAX (-10, arch->clone.stats.ac - level / 3); + ac = MAX (-10, arch->stats.ac - level / 3); prot[ATNR_PHYSICAL] += ((100 - prot[AT_PHYSICAL]) * (80 * level / settings.max_level)) / 100; } else - ac = arch->clone.stats.ac; + ac = arch->stats.ac; - stats.luck = arch->clone.stats.luck; - speed = arch->clone.speed; + stats.luck = arch->stats.luck; + speed = arch->speed; /* OK - we've reset most all the objects attributes to sane values. * now go through and make adjustments for what the player has equipped. */ for (tmp = inv; tmp; tmp = tmp->below) { - /* See note in map.c:update_position about making this additive - * since light sources are never applied, need to put check here. - */ - if (tmp->glow_radius > glow_radius) - glow_radius = tmp->glow_radius; - /* This happens because apply_potion calls change_abil with the potion * applied so we can tell the player what changed. But change_abil * then calls this function. @@ -887,6 +823,12 @@ if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION) continue; + /* See note in map.c:update_position about making this additive + * since light sources are never applied, need to put check here. + */ + if (tmp->glow_radius > glow_radius) + glow_radius = tmp->glow_radius; + /* For some things, we don't care what is equipped */ if (tmp->type == SKILL) { @@ -926,14 +868,17 @@ if (type == PLAYER) { if (tmp == contr->combat_ob || tmp == contr->ranged_ob) - if (tmp != current_weapon && (tmp->type != SKILL || tmp->subtype != SK_PRAYING)) + if (tmp != current_weapon + && (tmp->type != SKILL || tmp->subtype != SK_PRAYING) + && !tmp->flag [FLAG_CURSED] + && !tmp->flag [FLAG_DAMNED]) continue; for (i = 0; i < NUM_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 + /* 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 || @@ -999,8 +944,7 @@ } /* There may be other things that should not adjust the attacktype */ - if ((tmp->type != WEAPON && tmp->type != BOW && tmp->type != SYMPTOM) - || current_weapon == tmp) + if (tmp->type != SYMPTOM) { attacktype |= tmp->attacktype; path_attuned |= tmp->path_attuned; @@ -1018,7 +962,7 @@ if (QUERY_FLAG (tmp, FLAG_BLIND )) SET_FLAG (this, FLAG_BLIND); if (QUERY_FLAG (tmp, FLAG_SEE_IN_DARK )) SET_FLAG (this, FLAG_SEE_IN_DARK); - if (QUERY_FLAG (tmp, FLAG_UNDEAD) && !QUERY_FLAG (&arch->clone, FLAG_UNDEAD)) + if (QUERY_FLAG (tmp, FLAG_UNDEAD) && !QUERY_FLAG (arch, FLAG_UNDEAD)) SET_FLAG (this, FLAG_UNDEAD); if (QUERY_FLAG (tmp, FLAG_MAKE_INVIS)) @@ -1052,51 +996,50 @@ /* skills modifying the character -b.t. */ /* for all skills and skill granting objects */ case SKILL: - if (!QUERY_FLAG (tmp, FLAG_APPLIED)) - break; - - if (IS_COMBAT_SKILL (tmp->subtype)) - wc_obj = tmp; - - if (chosen_skill) - LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name); - - chosen_skill = tmp; + { + if (!QUERY_FLAG (tmp, FLAG_APPLIED) || skill_flags [tmp->subtype] & SF_APPLY) + break; - if (tmp->stats.dam > 0) - { /* skill is a 'weapon' */ - if (!QUERY_FLAG (this, FLAG_READY_WEAPON)) - weapon_speed = WEAPON_SPEED (tmp); + if (chosen_skill) + { + LOG (llevDebug, "fix_player, op %s has multiple skills applied (%s and %s)\n", + &name, &chosen_skill->name, &tmp->name); - if (weapon_speed < 0) - weapon_speed = 0; + tmp->flag [FLAG_APPLIED] = false; + update_stats (); + return; + } + else + chosen_skill = tmp; - weapon_weight = tmp->weight; - stats.dam += tmp->stats.dam * (1 + (chosen_skill->level / 9)); + if (tmp->stats.dam > 0) + { /* skill is a 'weapon' */ + if (!QUERY_FLAG (this, FLAG_READY_WEAPON)) + weapon_speed = WEAPON_SPEED (tmp); - if (tmp->magic) - stats.dam += tmp->magic; - } + if (weapon_speed < 0) + weapon_speed = 0; - if (tmp->stats.wc) - wc -= tmp->stats.wc + tmp->magic; + weapon_weight = tmp->weight; + stats.dam += 1 + chosen_skill->level * tmp->stats.dam / 9; - if (tmp->slaying) - slaying = tmp->slaying; + if (tmp->magic) + stats.dam += tmp->magic; + } - if (tmp->stats.ac) - ac -= tmp->stats.ac + tmp->magic; + if (tmp->stats.wc) + wc -= tmp->stats.wc + tmp->magic; - if (settings.spell_encumbrance == TRUE && type == PLAYER) - contr->encumbrance += (int) 3 *tmp->weight / 1000; + if (tmp->slaying) + slaying = tmp->slaying; - break; + if (tmp->stats.ac) + ac -= tmp->stats.ac + tmp->magic; - case SKILL_TOOL: - if (chosen_skill) - LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name); + if (settings.spell_encumbrance == TRUE && type == PLAYER) + contr->encumbrance += (int) 3 *tmp->weight / 1000; + } - chosen_skill = tmp; break; case SHIELD: @@ -1286,6 +1229,7 @@ for (i = 11; i <= mana_obj->level; i++) stats.maxsp += 2; } + /* Characters can get their sp supercharged via rune of transferrance */ if (stats.sp > stats.maxsp * 2) stats.sp = stats.maxsp * 2; @@ -1326,6 +1270,7 @@ for (i = 11; i <= grace_obj->level; i++) stats.maxgrace += 2; } + /* No limit on grace vs maxgrace */ if (contr->braced) @@ -1347,18 +1292,19 @@ * to make up for the change. Note that I left the * monster bonus the same as before. -b.t. */ + object *wc_obj = chosen_skill; - if (type == PLAYER && wc_obj && wc_obj->level > 1) + if (contr && wc_obj && wc_obj->level > 1) { wc -= wc_obj->level + thaco_bonus[stats.Str]; for (i = 1; i < wc_obj->level; i++) { - /* addtional wc every 6 levels */ + /* additional wc every 6 levels */ if (!(i % 6)) wc--; - /* addtional dam every 4 levels. */ + /* additional dam every 4 levels. */ if (!(i % 4) && dam_bonus[stats.Str] >= 0) stats.dam += 1 + dam_bonus[stats.Str] / 5; } @@ -1377,8 +1323,7 @@ speed -= 1; if (attacktype == 0) - attacktype = arch->clone.attacktype; - + attacktype = arch->attacktype; } /* End if player */ if (added_speed >= 0) @@ -1422,41 +1367,24 @@ 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 s = (20 - 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); + K *= (4 + level) * 1.2f / (6 + level); - if (K <= 0.f) + if (K <= 0.01f) K = 0.01f; - float S = speed / (K * s); - - contr->weapon_sp = S; + contr->weapon_sp = K * s * .5f; //TODO: balance the .5 } /* I want to limit the power of small monsters with big weapons: */ - 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 - * should be more than enough - remember, AC is also in 8 bits, - * so its value is the same. - */ - if (wc > 120) - wc = 120; - else if (wc < -120) - wc = -120; - - stats.wc = wc; - - if (ac > 120) - ac = 120; - else if (ac < -120) - ac = -120; + if (type != PLAYER && arch && stats.dam > arch->stats.dam * 3) + stats.dam = arch->stats.dam * 3; - stats.ac = ac; + stats.wc = clamp (wc, MIN_WC, MAX_WC); + stats.ac = clamp (ac, MIN_AC, MAX_AC); /* if for some reason the creature doesn't have any move type, * give them walking as a default. @@ -1588,9 +1516,9 @@ for (tmp = who->inv; tmp; tmp = tmp->below) if (tmp->type == FORCE) - if (tmp->arch->name == dragon_ability_force) + if (tmp->arch->archname == dragon_ability_force) abil = tmp; - else if (tmp->arch->name == dragon_skin_force) + else if (tmp->arch->archname == dragon_skin_force) skin = tmp; /* if the force is missing -> bail out */ @@ -1646,6 +1574,7 @@ LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name); return NULL; } + /* clear the flag - exp goes into this bucket, but player * still doesn't know it. */ @@ -1654,17 +1583,16 @@ skill_obj->level = 1; insert_ob_in_ob (skill_obj, op); - if (op->contr) + if (player *pl = op->contr) { - op->contr->last_skill_ob [skill_obj->subtype] = skill_obj; - if (op->contr->ns) - op->contr->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous + pl->last_skill_ob [skill_obj->subtype] = skill_obj; + if (pl->ns) + pl->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous } return skill_obj; } - /* player_lvl_adj() - for the new exp system. we are concerned with * whether the player gets more hp, sp and new levels. * Note this this function should only be called for players. Monstes @@ -1684,7 +1612,7 @@ { op->level++; - if (op != NULL && op == who && op->stats.exp > 1 && is_dragon_pl (who)) + if (op && op == who && op->stats.exp > 1 && is_dragon_pl (who)) dragon_level_gain (who); /* Only roll these if it is the player (who) that gained the level */ @@ -1702,20 +1630,24 @@ sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name); else sprintf (buf, "You are now level %d.", op->level); + if (who) new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf); } + player_lvl_adj (who, op); /* To increase more levels */ } else if (op->level > 1 && op->stats.exp < level_exp (op->level, who->expmul)) { op->level--; who->update_stats (); + if (op->type != PLAYER) { sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name); new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf); } + player_lvl_adj (who, op); /* To decrease more levels */ } @@ -2036,6 +1968,7 @@ percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100; level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)]; + if (level_loss < 0) level_loss = 0; loss = check_exp_loss (op, MIN (level_loss, percentage_loss));