--- deliantra/server/common/living.C 2008/12/18 19:56:09 1.93 +++ deliantra/server/common/living.C 2010/04/06 21:11:48 1.117 @@ -1,22 +1,23 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * - * Deliantra 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 3 of the License, or - * (at your option) any later version. + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 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. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . * * The authors can be reached via e-mail to */ @@ -263,7 +264,7 @@ * function since some of the values passed to new_draw_info are hardcoded. */ #define DIFF_MSG(flag, msg1, msg2) \ - new_draw_info(NDI_UNIQUE, 0, op, (flag>0)?msg1:msg2); + new_draw_info (NDI_UNIQUE, 0, op, (flag > 0) ? msg1 : msg2); /* return 1 if we sucessfully changed a stat, 0 if nothing was changed. */ @@ -416,9 +417,6 @@ if (tmp->move_type & MOVE_SWIM) DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming"); - - /* Changing move status may mean you are affected by things you weren't before */ - check_move_on (op, op); } /* becoming UNDEAD... a special treatment for this flag. Only those not @@ -525,29 +523,33 @@ DIFF_MSG (flag * tmp->stats.luck, "You feel more lucky.", "You feel less lucky."); } - if (tmp->stats.hp && op->type == PLAYER) + if (digest_types [tmp->type]) { - success = 1; - DIFF_MSG (flag * tmp->stats.hp, "You feel much more healthy!", "You feel much less healthy!"); - } + if (tmp->stats.hp && op->type == PLAYER) + { + success = 1; + DIFF_MSG (flag * tmp->stats.hp, "You feel much more healthy!", "You feel much less healthy!"); + } - if (tmp->stats.sp && op->type == PLAYER && tmp->type != SKILL) - { - success = 1; - DIFF_MSG (flag * tmp->stats.sp, "You feel one with the powers of magic!", "You suddenly feel very mundane."); - } + if (tmp->stats.sp && op->type == PLAYER + && tmp->type != SKILL && tmp->type != BOW) + { + success = 1; + DIFF_MSG (flag * tmp->stats.sp, "You feel one with the powers of magic!", "You suddenly feel very mundane."); + } - /* for the future when artifacts set this -b.t. */ - if (tmp->stats.grace && op->type == PLAYER) - { - success = 1; - DIFF_MSG (flag * tmp->stats.grace, "You feel closer to your god!", "You suddenly feel less holy."); - } + /* for the future when artifacts set this -b.t. */ + if (tmp->stats.grace && op->type == PLAYER) + { + success = 1; + DIFF_MSG (flag * tmp->stats.grace, "You feel closer to your god!", "You suddenly feel less holy."); + } - if (tmp->stats.food && op->type == PLAYER) - { - success = 1; - DIFF_MSG (flag * tmp->stats.food, "You feel your digestion slowing down.", "You feel your digestion speeding up."); + if (tmp->stats.food && op->type == PLAYER) + { + success = 1; + DIFF_MSG (flag * tmp->stats.food, "You feel your digestion slowing down.", "You feel your digestion speeding up."); + } } /* Messages for changed resistance */ @@ -596,7 +598,7 @@ object *tmp; archetype *at; - at = archetype::find (ARCH_DEPLETION); + at = archetype::find (shstr_depletion); if (!at) { LOG (llevError, "Couldn't find archetype depletion.\n"); @@ -608,7 +610,7 @@ if (!tmp) { - tmp = arch_to_object (at); + tmp = at->instance (); tmp = insert_ob_in_ob (tmp, this); SET_FLAG (tmp, FLAG_APPLIED); } @@ -626,7 +628,7 @@ void object::change_luck (int value) { - archetype *at = archetype::find ("luck"); + archetype *at = archetype::find (shstr_luck); if (!at) LOG (llevError, "Couldn't find archetype luck.\n"); else @@ -638,7 +640,7 @@ if (!value) return; - tmp = arch_to_object (at); + tmp = at->instance (); tmp = insert_ob_in_ob (tmp, this); SET_FLAG (tmp, FLAG_APPLIED); } @@ -704,32 +706,6 @@ } } -/* 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. - */ -static struct digest_types : std::bitset -{ - digest_types () - { - set (WEAPON); - set (BOW); - set (ARMOUR); - set (HELMET); - set (SHIELD); - set (RING); - set (BOOTS); - set (GLOVES); - set (AMULET); - set (GIRDLE); - set (BRACERS); - set (CLOAK); - set (DISEASE); - set (FORCE); - set (SKILL); - } -} digest_types; - static struct copy_flags : object::flags_t { copy_flags () @@ -765,9 +741,13 @@ float old_speed = speed; int stat_sum [NUM_STATS]; + MoveType move_type; // we use change_move_type to change it, so use a local copy + /* First task is to clear all the values back to their original values */ if (type == PLAYER) { + contr->delayed_update = false; + for (int i = 0; i < NUM_STATS; i++) stat_sum [i] = contr->orig_stats.stat (i); @@ -810,8 +790,6 @@ glow_radius = arch->glow_radius; move_type = arch->move_type; - chosen_skill = 0; - /* initializing resistances from the values in player/monster's * archetype clone */ @@ -820,11 +798,11 @@ for (int i = 0; i < NROFATTACKS; i++) { if (resist[i] > 0) - prot[i] = resist[i], vuln[i] = 0; + prot[i] = resist[i], vuln[i] = 0; else - vuln[i] = -(resist[i]), prot[i] = 0; + vuln[i] = -resist[i], prot[i] = 0; - potion_resist[i] = 0; + potion_resist[i] = -1000; } wc = arch->stats.wc; @@ -848,6 +826,8 @@ stats.luck = arch->stats.luck; speed = arch->speed; + chosen_skill = 0; + /* OK - we've reset most all the objects attributes to sane values. * now go through and make adjustments for what the player has equipped. */ @@ -860,10 +840,7 @@ 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. - */ - glow_radius = max (glow_radius, tmp->glow_radius); + glow_radius += tmp->glow_radius; /* For some things, we don't care what is equipped */ if (tmp->type == SKILL) @@ -898,22 +875,14 @@ if ((tmp->flag [FLAG_APPLIED] && tmp->type != CONTAINER && tmp->type != CLOSE_CON) - || (tmp->type == SKILL - && tmp->subtype == SK_PRAYING)) + || (tmp->type == SKILL && tmp->subtype == SK_PRAYING)) { if (type == PLAYER) { contr->item_power += tmp->item_power; - if (tmp == contr->combat_ob || tmp == contr->ranged_ob) - if (tmp != current_weapon - && (tmp->type != SKILL || tmp->subtype != SK_PRAYING) - && !tmp->flag [FLAG_CURSED] - && !tmp->flag [FLAG_DAMNED]) - continue; - for (int i = 0; i < NUM_STATS; i++) - stat_sum [i] = stat_sum [i] + tmp->stats.stat (i); + stat_sum [i] += tmp->stats.stat (i); if (digest_types [tmp->type]) { @@ -932,39 +901,27 @@ } /* Update slots used for items */ - if (QUERY_FLAG (tmp, FLAG_APPLIED)) + if (tmp->flag [FLAG_APPLIED]) // exclude praying... for (int i = 0; i < NUM_BODY_LOCATIONS; i++) slot[i].used += tmp->slot[i].info; if (tmp->type == SYMPTOM) - speed_reduce_from_disease = - min (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f); + min_it (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f); /* Pos. and neg. protections are counted separate (-> pro/vuln). * (Negative protections are calculated exactly like positive.) * Resistance from potions are treated special as well. If there's * more than one potion-effect, the bigger prot.-value is taken. */ - if (tmp->type != POTION) - { - 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. - */ - if (tmp->type == POTION_EFFECT) - { - if (potion_resist[i]) - potion_resist[i] = max (potion_resist[i], tmp->resist[i]); - else - potion_resist[i] = tmp->resist[i]; - } - else if (tmp->resist[i] > 0) - prot[i] += ((100 - prot[i]) * tmp->resist[i]) / 100; - else if (tmp->resist[i] < 0) - vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100; - } - } + if (tmp->type == POTION_EFFECT) + for (int i = 0; i < NROFATTACKS; i++) + max_it (potion_resist[i], tmp->resist[i]); + else if (tmp->type != POTION) + for (int i = 0; i < NROFATTACKS; i++) + if (tmp->resist[i] > 0) + prot[i] += ((100 - prot[i]) * tmp->resist[i]) / 100; + else if (tmp->resist[i] < 0) + vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100; /* There may be other things that should not adjust the attacktype */ if (tmp->type != SYMPTOM) @@ -982,6 +939,7 @@ if (QUERY_FLAG (tmp, FLAG_UNDEAD) && !QUERY_FLAG (arch, FLAG_UNDEAD)) SET_FLAG (this, FLAG_UNDEAD); + //TODO: copy_flags? if (QUERY_FLAG (tmp, FLAG_MAKE_INVIS)) { SET_FLAG (this, FLAG_MAKE_INVIS); @@ -1001,20 +959,10 @@ 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: { - if (!QUERY_FLAG (tmp, FLAG_APPLIED) || skill_flags [tmp->subtype] & SF_APPLY) + // some skills will end up here without counting as "applied" + if (!tmp->flag [FLAG_APPLIED] || skill_flags [tmp->subtype] & SF_AUTARK) break; if (chosen_skill) @@ -1026,16 +974,13 @@ update_stats (); return; } - else - chosen_skill = tmp; + + chosen_skill = tmp; if (tmp->stats.dam > 0) { /* skill is a 'weapon' */ if (!QUERY_FLAG (this, FLAG_READY_WEAPON)) - weapon_speed = WEAPON_SPEED (tmp); - - if (weapon_speed < 0) - weapon_speed = 0; + weapon_speed = max (0, WEAPON_SPEED (tmp)); weapon_weight = tmp->weight; stats.dam += 1 + chosen_skill->level * tmp->stats.dam / 9; @@ -1054,14 +999,15 @@ ac -= tmp->stats.ac + tmp->magic; if (settings.spell_encumbrance == TRUE && type == PLAYER) - contr->encumbrance += (int) 3 *tmp->weight / 1000; + contr->encumbrance += 3 * tmp->weight / 1000; } break; case SHIELD: if (settings.spell_encumbrance == TRUE && type == PLAYER) - contr->encumbrance += (int) tmp->weight / 2000; + contr->encumbrance += tmp->weight / 2000; + //FALLTHROUGH case RING: case AMULET: case GIRDLE: @@ -1080,33 +1026,35 @@ break; + case WAND: + case ROD: + case HORN: + break; + case BOW: case WEAPON: - 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; - - stats.dam += tmp->stats.dam + tmp->magic; - weapon_weight = tmp->weight; - weapon_speed = (WEAPON_SPEED (tmp) * 2 - tmp->magic) / 2; + wc -= tmp->stats.wc + tmp->magic; - if (weapon_speed < 0) - weapon_speed = 0; + if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) + ac -= tmp->stats.ac + tmp->magic; - 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; - } + 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; @@ -1139,10 +1087,10 @@ } if (tmp->stats.wc) - wc -= (tmp->stats.wc + tmp->magic); + wc -= tmp->stats.wc + tmp->magic; if (tmp->stats.ac) - ac -= (tmp->stats.ac + tmp->magic); + ac -= tmp->stats.ac + tmp->magic; if (ARMOUR_SPEED (tmp)) max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f); @@ -1152,6 +1100,8 @@ } /* item is equipped */ } /* for loop of items */ + min_it (glow_radius, MAX_LIGHT_RADIUS); + /* We've gone through all the objects the player has equipped. For many things, we * have generated intermediate values which we now need to assign. */ @@ -1166,7 +1116,8 @@ { resist[i] = prot[i] - vuln[i]; - if (potion_resist[i] && ((potion_resist[i] > resist[i]) || (potion_resist[i] < 0))) + if (potion_resist[i] != -1000 + && (potion_resist[i] < 0 || potion_resist[i] > resist[i])) resist[i] = potion_resist[i]; } @@ -1174,18 +1125,16 @@ { // clamp various player stats for (int i = 0; i < NUM_STATS; ++i) - stats.stat (i) = clamp (stat_sum [i], MIN_STAT, MAX_STAT); + stats.stat (i) = stat_sum [i]; + + check_stat_bounds (&stats); contr->digestion = clamp (contr->digestion, MIN_DIGESTION, MAX_DIGESTION); /* Figure out the players sp/mana/hp totals. */ int pl_level; - check_stat_bounds (&(stats)); - pl_level = level; - - if (pl_level < 1) - pl_level = 1; /* safety, we should always get 1 levels worth of hp! */ + pl_level = max (1, level); /* safety, we should always get 1 levels worth of hp! */ /* 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. @@ -1330,9 +1279,6 @@ if (settings.search_items && contr->search_str[0]) speed -= 1; - - if (attacktype == 0) - attacktype = arch->attacktype; } /* End if player */ if (added_speed >= 0) @@ -1361,8 +1307,7 @@ /* Put a lower limit on speed. Note with this speed, you move once every * 25 ticks or so. This amounts to once every 3 seconds of realtime. */ - if (speed < 0.04f && type == PLAYER) - speed = 0.04f; + max_it (speed, is_player () ? MIN_PLAYER_SPEED : MIN_ACTIVE_SPEED); if (speed != old_speed) set_speed (speed); @@ -1407,20 +1352,37 @@ else if (move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) move_type &= ~MOVE_WALK; + // now apply the new move_type + if (this->move_type != move_type) + change_move_type (move_type); + /* It is quite possible that a player's spell costing might have changed, * so we will check that now. */ - if (type == PLAYER) - { - esrv_update_stats (contr); - esrv_update_spells (contr); - } + if (is_player ()) + contr->update_spells (); // update the mapspace, if we are on a map if (!flag [FLAG_REMOVED] && map) map->at (x, y).flags_ = 0; } +void +object::set_glow_radius (sint8 rad) +{ + glow_radius = rad; + + if (is_on_map ()) + update_all_los (map, x, y); + else if (object *env = outer_env ()) + { + env->update_stats (); + + if (env->is_on_map ()) + update_all_los (env->map, env->x, env->y); + } +} + /* * Returns true if the given player is a legal class. * The function to add and remove class-bonuses to the stats doesn't @@ -1492,7 +1454,7 @@ * an overall level. Here, the dragon might gain new abilities * or change the ability-focus. */ -void +static void dragon_level_gain (object *who) { object *abil = NULL; /* pointer to dragon ability force */ @@ -1598,7 +1560,7 @@ op->level++; - if (op && op == who && op->stats.exp > 1 && is_dragon_pl (who)) + if (op && op == who && op->stats.exp > 1 && who->is_dragon ()) dragon_level_gain (who); /* Only roll these if it is the player (who) that gained the level */ @@ -1641,12 +1603,7 @@ } if (changed) - { - who->update_stats (); - esrv_update_stats (who->contr); - /* check if the spell data has changed */ - esrv_update_spells (who->contr); - } + who->update_stats (); // should cause esrv_update_stats and esrv_update_spells } /* @@ -1778,7 +1735,7 @@ * the 'exp' value passed should be positive - this is the * amount that should get subtract from the player. */ -sint64 +static sint64 check_exp_loss (const object *op, sint64 exp) { sint64 del_exp; @@ -1937,7 +1894,7 @@ if (tmp->type == SKILL && tmp->stats.exp) { percentage_loss = tmp->stats.exp * settings.death_penalty_ratio / 100; - level_loss = tmp->stats.exp - levels[MAX (0, tmp->level - settings.death_penalty_level)]; + level_loss = tmp->stats.exp - levels [max (0, tmp->level - settings.death_penalty_level)]; /* With the revised exp system, you can get cases where * losing several levels would still require that you have more