--- deliantra/server/common/living.C 2009/11/23 12:19:57 1.103 +++ deliantra/server/common/living.C 2012/01/03 11:25:31 1.126 @@ -1,9 +1,9 @@ /* * 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,2011,2012 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 Affero GNU General Public License as published by the @@ -141,7 +141,7 @@ Both come in handy at least in function add_exp() */ -#define MAX_EXPERIENCE levels[settings.max_level] +#define MAX_EXPERIENCE levels [settings.max_level] /* because exp_obj sum to make the total score, * we cannot allow that sum to exceed the maximum @@ -158,9 +158,7 @@ * -b.t. */ -#define MAX_EXP_IN_OBJ levels[settings.max_level]/(MAX_EXP_CAT - 1) - -extern sint64 *levels; +#define MAX_EXP_IN_OBJ MAX_EXP_IN_OBJ / (MAX_EXP_CAT - 1) #define MAX_SAVE_LEVEL 110 @@ -264,7 +262,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. */ @@ -417,9 +415,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 @@ -466,7 +461,7 @@ else { new_draw_info (NDI_UNIQUE, 0, op, "You are blinded."); - SET_FLAG (op, FLAG_BLIND); + op->set_flag (FLAG_BLIND); if (op->type == PLAYER) op->contr->do_los = 1; } @@ -478,7 +473,7 @@ else { new_draw_info (NDI_UNIQUE, 0, op, "Your vision returns."); - CLEAR_FLAG (op, FLAG_BLIND); + op->clr_flag (FLAG_BLIND); if (op->type == PLAYER) op->contr->do_los = 1; } @@ -526,29 +521,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 */ @@ -609,9 +608,9 @@ if (!tmp) { - tmp = arch_to_object (at); + tmp = at->instance (); tmp = insert_ob_in_ob (tmp, this); - SET_FLAG (tmp, FLAG_APPLIED); + tmp->set_flag (FLAG_APPLIED); } } @@ -639,9 +638,9 @@ if (!value) return; - tmp = arch_to_object (at); + tmp = at->instance (); tmp = insert_ob_in_ob (tmp, this); - SET_FLAG (tmp, FLAG_APPLIED); + tmp->set_flag (FLAG_APPLIED); } if (value) @@ -705,32 +704,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 () @@ -766,6 +739,8 @@ 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) { @@ -792,20 +767,20 @@ slaying = 0; - if (!QUERY_FLAG (this, FLAG_WIZ)) + if (!this->flag [FLAG_WIZ]) { - CLEAR_FLAG (this, FLAG_XRAYS); - CLEAR_FLAG (this, FLAG_MAKE_INVIS); + this->clr_flag (FLAG_XRAYS); + this->clr_flag (FLAG_MAKE_INVIS); } - CLEAR_FLAG (this, FLAG_LIFESAVE); - CLEAR_FLAG (this, FLAG_STEALTH); - CLEAR_FLAG (this, FLAG_BLIND); + this->clr_flag (FLAG_LIFESAVE); + this->clr_flag (FLAG_STEALTH); + this->clr_flag (FLAG_BLIND); - 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); + if (!arch->flag [FLAG_REFL_SPELL ]) this->clr_flag (FLAG_REFL_SPELL); + if (!arch->flag [FLAG_REFL_MISSILE]) this->clr_flag (FLAG_REFL_MISSILE); + if (!arch->flag [FLAG_UNDEAD ]) this->clr_flag (FLAG_UNDEAD); + if (!arch->flag [FLAG_SEE_IN_DARK ]) this->clr_flag (FLAG_SEE_IN_DARK); path_attuned = arch->path_attuned; path_repelled = arch->path_repelled; @@ -813,8 +788,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 */ @@ -823,11 +796,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; @@ -840,7 +813,7 @@ * basically, if a server updates its max level, these playes may find * that their protection from physical goes down */ - if (!QUERY_FLAG (this, FLAG_USE_ARMOUR) && type == PLAYER) + if (!this->flag [FLAG_USE_ARMOUR] && type == PLAYER) { ac = max (-10, arch->stats.ac - level / 3); prot[ATNR_PHYSICAL] += ((100 - prot[AT_PHYSICAL]) * (80 * level / settings.max_level)) / 100; @@ -851,6 +824,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,7 +835,7 @@ * 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) + if (tmp->flag [FLAG_APPLIED] && tmp->type == POTION) continue; glow_radius += tmp->glow_radius; @@ -897,21 +872,14 @@ */ if ((tmp->flag [FLAG_APPLIED] && tmp->type != CONTAINER - && tmp->type != CLOSE_CON) - || (tmp->type == SKILL - && tmp->subtype == SK_PRAYING)) + && tmp->type != CLOSE_CON + && tmp->type != SPELL) + || (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] += tmp->stats.stat (i); @@ -932,39 +900,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) @@ -979,12 +935,13 @@ flag |= tmp->flag & copy_flags; - if (QUERY_FLAG (tmp, FLAG_UNDEAD) && !QUERY_FLAG (arch, FLAG_UNDEAD)) - SET_FLAG (this, FLAG_UNDEAD); + if (tmp->flag [FLAG_UNDEAD] && !arch->flag [FLAG_UNDEAD]) + this->set_flag (FLAG_UNDEAD); - if (QUERY_FLAG (tmp, FLAG_MAKE_INVIS)) + //TODO: copy_flags? + if (tmp->flag [FLAG_MAKE_INVIS]) { - SET_FLAG (this, FLAG_MAKE_INVIS); + set_flag (FLAG_MAKE_INVIS); invisible = 1; } @@ -1001,20 +958,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 +973,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; + if (!this->flag [FLAG_READY_WEAPON]) + weapon_speed = max (0, WEAPON_SPEED (tmp)); weapon_weight = tmp->weight; stats.dam += 1 + chosen_skill->level * tmp->stats.dam / 9; @@ -1054,14 +998,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 +1025,31 @@ break; + case RANGED: 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; + wc -= tmp->stats.wc + tmp->magic; - 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; + 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; @@ -1145,14 +1088,14 @@ ac -= tmp->stats.ac + tmp->magic; if (ARMOUR_SPEED (tmp)) - max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f); + min_it (max_speed, ARMOUR_SPEED (tmp) / 10.f); break; } /* switch tmp->type */ } /* item is equipped */ } /* for loop of items */ - glow_radius = min (glow_radius, MAX_LIGHT_RADIUS); + 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. @@ -1168,7 +1111,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]; } @@ -1358,8 +1302,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); @@ -1404,6 +1347,10 @@ 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. */ @@ -1575,7 +1522,7 @@ /* clear the flag - exp goes into this bucket, but player * still doesn't know it. */ - CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL); + skill_obj->clr_flag (FLAG_CAN_USE_SKILL); skill_obj->stats.exp = 0; skill_obj->level = 1; op->insert (skill_obj); @@ -1608,7 +1555,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 */ @@ -1662,10 +1609,7 @@ sint64 level_exp (int level, double expmul) { - if (level > settings.max_level) - return (sint64) (expmul * levels[settings.max_level]); - - return (sint64) (expmul * levels[level]); + return expmul * level_to_min_exp (level); } /* @@ -1703,7 +1647,7 @@ * flag is what to do if the player doesn't have the skill: */ static void -add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) +add_player_exp (object *op, sint64 exp, shstr_tmp skill_name, int flag) { object *skill_obj; sint64 limit, exp_to_add; @@ -1743,7 +1687,7 @@ * than half what you need to gain for next level. */ exp_to_add = exp; - limit = (levels[op->level + 1] - levels[op->level]) / 2; + limit = (levels [op->level + 1] - levels [op->level]) / 2; if (exp_to_add > limit) exp_to_add = limit; @@ -1760,7 +1704,7 @@ if (skill_obj) { exp_to_add = exp; - limit = (levels[skill_obj->level + 1] - levels[skill_obj->level]) / 2; + limit = (levels [skill_obj->level + 1] - levels [skill_obj->level]) / 2; if (exp_to_add > limit) exp_to_add = limit; @@ -1827,7 +1771,7 @@ * a postive number. */ static void -subtract_player_exp (object *op, sint64 exp, const char *skill, int flag) +subtract_player_exp (object *op, sint64 exp, shstr_tmp skill, int flag) { float fraction = (float) exp / (float) op->stats.exp; object *tmp; @@ -1836,7 +1780,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 && tmp->skill == skill) { del_exp = check_exp_loss (tmp, exp); tmp->stats.exp -= del_exp; @@ -1847,7 +1791,7 @@ /* only want to process other skills if we are not trying * to match a specific skill. */ - del_exp = check_exp_loss (tmp, (sint64) (tmp->stats.exp * fraction)); + del_exp = check_exp_loss (tmp, tmp->stats.exp * fraction); tmp->stats.exp -= del_exp; player_lvl_adj (op, tmp); } @@ -1871,7 +1815,7 @@ * these last two values are only used for players. */ void -change_exp (object *op, sint64 exp, const char *skill_name, int flag) +change_exp (object *op, sint64 exp, shstr_tmp skill_name, int flag) { #ifdef EXP_DEBUG LOG (llevDebug, "change_exp() called for %s, exp = %" PRId64 "\n", query_name (op), exp); @@ -1898,7 +1842,7 @@ if (op->type != PLAYER) { /* Sanity check */ - if (!QUERY_FLAG (op, FLAG_ALIVE)) + if (!op->flag [FLAG_ALIVE]) return; /* reset exp to max allowed value. We subtract from @@ -1959,7 +1903,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)]; + level_loss = op->stats.exp - levels [max (0, op->level - settings.death_penalty_level)]; if (level_loss < 0) level_loss = 0;