--- deliantra/server/common/living.C 2008/05/06 16:32:34 1.86 +++ deliantra/server/common/living.C 2010/03/28 16:41:45 1.112 @@ -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 @@ -596,7 +594,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 +606,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 +624,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 +636,7 @@ if (!value) return; - tmp = arch_to_object (at); + tmp = at->instance (); tmp = insert_ob_in_ob (tmp, this); SET_FLAG (tmp, FLAG_APPLIED); } @@ -765,9 +763,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,7 +812,7 @@ glow_radius = arch->glow_radius; move_type = arch->move_type; - chosen_skill = 0; + object *chosen_skill = 0; /* initializing resistances from the values in player/monster's * archetype clone @@ -860,10 +862,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,8 +897,7 @@ 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) { @@ -913,13 +911,14 @@ 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]) { contr->digestion += tmp->stats.food; contr->gen_hp += tmp->stats.hp; - contr->gen_sp += tmp->stats.sp; + if (tmp->type != BOW) // ugly exception for bows + contr->gen_sp += tmp->stats.sp; contr->gen_grace += tmp->stats.grace; contr->gen_sp_armour += tmp->gen_sp_armour; } @@ -931,39 +930,36 @@ } /* Update slots used for items */ - if (QUERY_FLAG (tmp, FLAG_APPLIED)) + if (tmp->flag [FLAG_APPLIED]) 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++) + { + /* Potential for cursed potions, in which case we just can use + * a straight MAX, as potion_resist is initialised to zero. + // TODO: this is askign for a magic marker optimisation + */ + if (potion_resist[i]) + max_it (potion_resist[i], tmp->resist[i]); + else + 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) @@ -1000,15 +996,6 @@ 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: @@ -1053,14 +1040,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: @@ -1079,10 +1067,20 @@ break; + case WAND: + case ROD: + case HORN: + case SKILL_TOOL: + if (type != PLAYER) + chosen_skill = find_skill_by_name (this, tmp->skill); + break; + case BOW: case WEAPON: if (type != PLAYER || current_weapon == tmp) { + chosen_skill = find_skill_by_name (this, tmp->skill); + wc -= tmp->stats.wc + tmp->magic; if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) @@ -1138,10 +1136,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); @@ -1151,6 +1149,11 @@ } /* item is equipped */ } /* for loop of items */ + if (type != PLAYER) + this->chosen_skill = chosen_skill; + + glow_radius = min (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. */ @@ -1173,18 +1176,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. @@ -1329,9 +1330,6 @@ if (settings.search_items && contr->search_str[0]) speed -= 1; - - if (attacktype == 0) - attacktype = arch->attacktype; } /* End if player */ if (added_speed >= 0) @@ -1360,8 +1358,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); @@ -1406,20 +1403,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 @@ -1443,11 +1457,6 @@ * set the new dragon name after gaining levels or * changing ability focus (later this can be extended to * eventually change the player's face and animation) - * - * Note that the title is written to 'own_title' in the - * player struct. This should be changed to 'ext_title' - * as soon as clients support this! - * Please, anyone, write support for 'ext_title'. */ void set_dragon_name (object *pl, const object *abil, const object *skin) @@ -1475,29 +1484,17 @@ if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level) atnr = abil->stats.exp; - level = (int) (level / 25.); - /* now set the new title */ - if (pl->contr) + if (level < 25) sprintf (pl->contr->title, "%s hatchling", attacks[atnr]); + else if (level < 50) sprintf (pl->contr->title, "%s wyrm" , attacks[atnr]); + else if (level < 75) sprintf (pl->contr->title, "%s wyvern" , attacks[atnr]); + else if (level < 100) sprintf (pl->contr->title, "%s dragon" , attacks[atnr]); + else { - if (level == 0) - sprintf (pl->contr->title, "%s hatchling", attacks[atnr]); - else if (level == 1) - sprintf (pl->contr->title, "%s wyrm", attacks[atnr]); - else if (level == 2) - sprintf (pl->contr->title, "%s wyvern", attacks[atnr]); - else if (level == 3) - sprintf (pl->contr->title, "%s dragon", attacks[atnr]); - else - { - /* special titles for extra high resistance! */ - if (skin->resist[atnr] > 80) - sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]); - else if (skin->resist[atnr] > 50) - sprintf (pl->contr->title, "ancient %s dragon", attacks[atnr]); - else - sprintf (pl->contr->title, "big %s dragon", attacks[atnr]); - } + /* special titles for extra high resistance! */ + if (skin->resist[atnr] > 80) sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]); + else if (skin->resist[atnr] > 50) sprintf (pl->contr->title, "ancient %s dragon" , attacks[atnr]); + else sprintf (pl->contr->title, "big %s dragon" , attacks[atnr]); } strcpy (pl->contr->own_title, ""); @@ -1508,7 +1505,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 */ @@ -1574,7 +1571,7 @@ skill_obj = get_archetype_by_skill_name (skill_name, SKILL); if (!skill_obj) { - LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name); + LOG (llevError, "give_skill_by_name: couldn't find skill %s\n", skill_name); return NULL; } @@ -1584,14 +1581,10 @@ CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL); skill_obj->stats.exp = 0; skill_obj->level = 1; - insert_ob_in_ob (skill_obj, op); + op->insert (skill_obj); if (player *pl = op->contr) - { - 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 - } + pl->link_skills (); return skill_obj; } @@ -1618,7 +1611,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 */ @@ -1661,12 +1654,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 } /* @@ -1720,7 +1708,7 @@ static void add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) { - object *skill_obj = NULL; + object *skill_obj; sint64 limit, exp_to_add; int i; @@ -1733,29 +1721,22 @@ * chosen_skill. This means we don't need to search through * the players inventory. */ + skill_obj = 0; + if (skill_name) { - if (op->chosen_skill && op->chosen_skill->type == SKILL && !strcmp (skill_name, op->chosen_skill->skill)) - skill_obj = op->chosen_skill; - else + skill_obj = op->contr->find_skill (skill_name); + + /* Player doesn't have the skill. Check to see what to do, and give + * it to the player if necessary + */ + if (!skill_obj) { - for (i = 0; i < NUM_SKILLS; i++) - if (op->contr->last_skill_ob[i] && !strcmp (op->contr->last_skill_ob[i]->skill, skill_name)) - { - skill_obj = op->contr->last_skill_ob[i]; - break; - } + if (flag == SK_EXP_NONE) + return; - /* Player doesn't have the skill. Check to see what to do, and give - * it to the player if necessary - */ - if (!skill_obj) - { - if (flag == SK_EXP_NONE) - return; - else if (flag == SK_EXP_ADD_SKILL) - give_skill_by_name (op, skill_name); - } + if (flag == SK_EXP_ADD_SKILL) + skill_obj = give_skill_by_name (op, skill_name); } } @@ -1798,28 +1779,32 @@ } /* This function checks to make sure that object 'op' can - * lost 'exp' experience. It returns the amount of exp + * lose 'exp' experience. It returns the amount of exp * object 'op' can in fact lose - it basically makes * adjustments based on permanent exp and the like. * This function should always be used for losing experience - * 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; if (exp > op->stats.exp) exp = op->stats.exp; + if (settings.permanent_exp_ratio) { del_exp = (sint64) ((op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO); + if (del_exp < 0) del_exp = 0; + if (exp > del_exp) exp = del_exp; } + return exp; } @@ -1829,10 +1814,9 @@ if (exp < 0) return check_exp_loss (op, exp); else - return MIN (exp, (sint64) MAX_EXPERIENCE - op->stats.exp); + return min (exp, (sint64)MAX_EXPERIENCE - op->stats.exp); } - /* Subtracts experience from player. * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we * only subtract from the matching skill. Otherwise, @@ -1855,7 +1839,7 @@ for (tmp = op->inv; tmp; tmp = tmp->below) if (tmp->type == SKILL && tmp->stats.exp) { - if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (tmp->skill, skill)) + if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (&tmp->skill, skill)) { del_exp = check_exp_loss (tmp, exp); tmp->stats.exp -= del_exp; @@ -1953,17 +1937,15 @@ void apply_death_exp_penalty (object *op) { - object *tmp; sint64 loss; sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */ sint64 level_loss; /* defined by the setting 'death_penalty_levels */ - for (tmp = op->inv; tmp; tmp = tmp->below) + for (object *tmp = op->inv; tmp; tmp = tmp->below) 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 @@ -1973,18 +1955,19 @@ if (level_loss < 0) level_loss = 0; - loss = check_exp_loss (tmp, MIN (level_loss, percentage_loss)); + loss = check_exp_loss (tmp, min (level_loss, percentage_loss)); tmp->stats.exp -= loss; player_lvl_adj (op, tmp); } percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100; - level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)]; + 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)); + + loss = check_exp_loss (op, min (level_loss, percentage_loss)); op->stats.exp -= loss; player_lvl_adj (op, NULL);