--- deliantra/server/common/living.C 2007/07/21 14:37:25 1.71
+++ deliantra/server/common/living.C 2012/01/27 22:00:39 1.127
@@ -1,28 +1,28 @@
/*
- * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * 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
+ * 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
*
- * 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 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
+ * The authors can be reached via e-mail to
*/
#include
-#include
/* Handy little macro that adds exp and keeps it within bounds. Since
* we are now using 64 bit values, I'm not all concerned about overflow issues
@@ -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. */
@@ -282,21 +280,24 @@
int
change_abil (object *op, object *tmp)
{
- int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, success = 0;
+ int flag = tmp->flag [FLAG_APPLIED] ? 1 : -1;
+ int success = 0;
char message[MAX_BUF];
int potion_max = 0;
- /* remember what object was like before it was changed. note that
- * refop is a local copy of op only to be used for detecting changes
- * found by update_stats. refop is not a real object
- */
- object_copy refop = *op;
+ // keep some stats for comparison purposes
+ object::flags_t prev_flag = op->flag;
+ MoveType prev_move_type = op->move_type;
+ sint16 prev_resist [NROFATTACKS]; // clumsy
+ assert (sizeof (prev_resist) == sizeof (op->resist));
+ memcpy (prev_resist, op->resist, sizeof (prev_resist));
if (op->type == PLAYER)
{
if (tmp->type == POTION)
{
potion_max = 1;
+
for (int j = 0; j < NUM_STATS; j++)
{
int ostat = op->contr->orig_stats.stat (j);
@@ -305,8 +306,7 @@
/* nstat is what the stat will be after use of the potion */
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
+ /* Do some bounds checking. There is the potential for potions
* that adjust that stat by more than one point, so we need
* to allow for that.
*/
@@ -368,19 +368,19 @@
DIFF_MSG (flag, "Your hands begin to glow red.", "Your hands stop glowing red.");
}
- if (QUERY_FLAG (op, FLAG_LIFESAVE) != QUERY_FLAG (&refop, FLAG_LIFESAVE))
+ if (op->flag [FLAG_LIFESAVE] != prev_flag [FLAG_LIFESAVE])
{
success = 1;
DIFF_MSG (flag, "You feel very protected.", "You don't feel protected anymore.");
}
- if (QUERY_FLAG (op, FLAG_REFL_MISSILE) != QUERY_FLAG (&refop, FLAG_REFL_MISSILE))
+ if (op->flag [FLAG_REFL_MISSILE] != prev_flag [FLAG_REFL_MISSILE])
{
success = 1;
DIFF_MSG (flag, "A magic force shimmers around you.", "The magic force fades away.");
}
- if (QUERY_FLAG (op, FLAG_REFL_SPELL) != QUERY_FLAG (&refop, FLAG_REFL_SPELL))
+ if (op->flag [FLAG_REFL_SPELL] != prev_flag [FLAG_REFL_SPELL])
{
success = 1;
DIFF_MSG (flag, "You feel more safe now, somehow.", "Suddenly you feel less safe, somehow.");
@@ -392,7 +392,7 @@
* can be misleading (a little higher could be miscontrued from
* from fly high)
*/
- if (tmp->move_type && op->move_type != refop.move_type)
+ if (tmp->move_type && op->move_type != prev_move_type)
{
success = 1;
@@ -401,7 +401,7 @@
*/
if (tmp->move_type & MOVE_FLY_LOW && !(op->move_type & MOVE_FLY_HIGH))
{
- DIFF_MSG (flag, "You start to float in the air!.", "You float down to the ground.");
+ DIFF_MSG (flag, "You start to float in the air!", "You float down to the ground.");
}
if (tmp->move_type & MOVE_FLY_HIGH)
@@ -415,16 +415,13 @@
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
* originally undead may change their status
*/
- if (!QUERY_FLAG (op->arch, FLAG_UNDEAD))
- if (QUERY_FLAG (op, FLAG_UNDEAD) != QUERY_FLAG (&refop, FLAG_UNDEAD))
+ if (!op->arch->flag [FLAG_UNDEAD])
+ if (op->flag [FLAG_UNDEAD] != prev_flag [FLAG_UNDEAD])
{
success = 1;
if (flag > 0)
@@ -439,13 +436,13 @@
}
}
- if (QUERY_FLAG (op, FLAG_STEALTH) != QUERY_FLAG (&refop, FLAG_STEALTH))
+ if (op->flag [FLAG_STEALTH] != prev_flag [FLAG_STEALTH])
{
success = 1;
DIFF_MSG (flag, "You walk more quietly.", "You walk more noisily.");
}
- if (QUERY_FLAG (op, FLAG_MAKE_INVIS) != QUERY_FLAG (&refop, FLAG_MAKE_INVIS))
+ if (op->flag [FLAG_MAKE_INVIS] != prev_flag [FLAG_MAKE_INVIS])
{
success = 1;
DIFF_MSG (flag, "You become transparent.", "You can see yourself.");
@@ -454,36 +451,36 @@
/* blinded you can tell if more blinded since blinded player has minimal
* vision
*/
- if (QUERY_FLAG (tmp, FLAG_BLIND))
+ if (tmp->flag [FLAG_BLIND])
{
success = 1;
if (flag > 0)
{
- if (QUERY_FLAG (op, FLAG_WIZ))
+ if (op->flag [FLAG_WIZ])
new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self is blinded.");
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;
}
}
else
{
- if (QUERY_FLAG (op, FLAG_WIZ))
+ if (op->flag [FLAG_WIZ])
new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self can now see again.");
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;
}
}
}
- if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) != QUERY_FLAG (&refop, FLAG_SEE_IN_DARK))
+ if (op->flag [FLAG_SEE_IN_DARK] != prev_flag [FLAG_SEE_IN_DARK])
{
success = 1;
if (op->type == PLAYER)
@@ -491,12 +488,12 @@
DIFF_MSG (flag, "Your vision is better in the dark.", "You see less well in the dark.");
}
- if (QUERY_FLAG (op, FLAG_XRAYS) != QUERY_FLAG (&refop, FLAG_XRAYS))
+ if (op->flag [FLAG_XRAYS] != prev_flag [FLAG_XRAYS])
{
success = 1;
if (flag > 0)
{
- if (QUERY_FLAG (op, FLAG_WIZ))
+ if (op->flag [FLAG_WIZ])
new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a little clearer.");
else
{
@@ -507,7 +504,7 @@
}
else
{
- if (QUERY_FLAG (op, FLAG_WIZ))
+ if (op->flag [FLAG_WIZ])
new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a bit out of focus.");
else
{
@@ -524,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 */
@@ -555,29 +556,26 @@
if (i == ATNR_PHYSICAL)
continue; /* Don't display about armour */
- if (op->resist[i] != refop.resist[i])
+ if (op->resist [i] != prev_resist [i])
{
success = 1;
- if (op->resist[i] > refop.resist[i])
- sprintf (message, "Your resistance to %s rises to %d%%.", change_resist_msg[i], op->resist[i]);
+
+ if (op->resist [i] > prev_resist [i])
+ sprintf (message, "Your resistance to %s rises to %d%%.", change_resist_msg [i], op->resist [i]);
else
- sprintf (message, "Your resistance to %s drops to %d%%.", change_resist_msg[i], op->resist[i]);
+ sprintf (message, "Your resistance to %s drops to %d%%.", change_resist_msg [i], op->resist [i]);
new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, op, message);
}
}
if (!potion_max)
- {
- for (int j = 0; j < NUM_STATS; j++)
+ for (int j = 0; j < NUM_STATS; j++)
+ if (int i = tmp->stats.stat (j))
{
- if (int i = tmp->stats.stat (j))
- {
- success = 1;
- DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]);
- }
+ success = 1;
+ DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]);
}
- }
return success;
}
@@ -598,7 +596,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");
@@ -610,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);
}
}
@@ -628,7 +626,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
@@ -640,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)
@@ -706,6 +704,20 @@
}
}
+static struct copy_flags : object::flags_t
+{
+ copy_flags ()
+ {
+ set (FLAG_LIFESAVE);
+ set (FLAG_REFL_SPELL);
+ set (FLAG_REFL_MISSILE);
+ set (FLAG_STEALTH);
+ set (FLAG_XRAYS);
+ set (FLAG_BLIND);
+ set (FLAG_SEE_IN_DARK);
+ }
+} copy_flags;
+
/*
* Updates all abilities given by applied objects in the inventory
* of the given object. Note: This function works for both monsters
@@ -719,19 +731,23 @@
void
object::update_stats ()
{
- int i, j;
- float f, max = 9, added_speed = 0, bonus_speed = 0, sp_tmp, speed_reduce_from_disease = 1;
+ float max_speed = 9, added_speed = 0, bonus_speed = 0, speed_reduce_from_disease = 1;
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, *tmp;
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)
{
- for (i = 0; i < NUM_STATS; i++)
- stats.stat (i) = contr->orig_stats.stat (i);
+ contr->delayed_update = false;
+
+ for (int i = 0; i < NUM_STATS; i++)
+ stat_sum [i] = contr->orig_stats.stat (i);
if (settings.spell_encumbrance == TRUE)
contr->encumbrance = 0;
@@ -751,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;
@@ -772,21 +788,19 @@
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->resist, sizeof (resist));
- for (i = 0; i < NROFATTACKS; i++)
+ 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;
@@ -799,9 +813,9 @@
* 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);
+ ac = max (-10, arch->stats.ac - level / 3);
prot[ATNR_PHYSICAL] += ((100 - prot[AT_PHYSICAL]) * (80 * level / settings.max_level)) / 100;
}
else
@@ -810,7 +824,7 @@
stats.luck = arch->stats.luck;
speed = arch->speed;
- sint16 digestion = 0; // a local var to add digestion
+ 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.
@@ -821,14 +835,10 @@
* 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;
- /* 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;
+ glow_radius += tmp->glow_radius;
/* For some things, we don't care what is equipped */
if (tmp->type == SKILL)
@@ -851,7 +861,7 @@
}
}
- /* Container objects are not meant to adjust a players, but other applied
+ /* Container objects are not meant to adjust players, but other applied
* objects need to make adjustments.
* This block should handle all player specific changes
* The check for Praying is a bit of a hack - god given bonuses are put
@@ -862,40 +872,23 @@
*/
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 (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
- * 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)
+ for (int i = 0; i < NUM_STATS; i++)
+ stat_sum [i] += tmp->stats.stat (i);
+
+ if (digest_types [tmp->type])
{
- digestion += tmp->stats.food;
+ 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;
}
@@ -907,43 +900,27 @@
}
/* Update slots used for items */
- if (QUERY_FLAG (tmp, FLAG_APPLIED))
- for (i = 0; i < NUM_BODY_LOCATIONS; i++)
+ 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 = tmp->last_sp / 100.f;
+ min_it (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f);
- if (speed_reduce_from_disease == 0)
- speed_reduce_from_disease = 1;
- }
-
- /* Pos. and neg. protections are counted seperate (-> pro/vuln).
+ /* 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 (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)
@@ -956,20 +933,15 @@
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);
- if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE)) SET_FLAG (this, FLAG_REFL_MISSILE);
- if (QUERY_FLAG (tmp, FLAG_STEALTH )) SET_FLAG (this, FLAG_STEALTH);
- if (QUERY_FLAG (tmp, FLAG_XRAYS )) SET_FLAG (this, FLAG_XRAYS);
- 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);
+ 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;
}
@@ -986,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)
@@ -1011,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;
@@ -1039,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:
@@ -1065,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;
-
- slaying = tmp->slaying;
+ if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0)
+ ac -= tmp->stats.ac + tmp->magic;
- /* 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;
@@ -1124,21 +1082,20 @@
}
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) && ARMOUR_SPEED (tmp) / 10.f < max)
- max = ARMOUR_SPEED (tmp) / 10.f;
+ if (ARMOUR_SPEED (tmp))
+ min_it (max_speed, ARMOUR_SPEED (tmp) / 10.f);
break;
} /* switch tmp->type */
} /* item is equipped */
} /* for loop of items */
- // now clamp digestion to our limits
- contr->digestion = clamp (digestion, MIN_DIGESTION, MAX_DIGESTION);
+ 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.
@@ -1150,45 +1107,48 @@
* If there is a cursed (and no uncursed) potion in effect, we take
* 'total resistance = vulnerability from cursed potion'.
*/
- for (i = 0; i < NROFATTACKS; i++)
+ for (int i = 0; i < NROFATTACKS; i++)
{
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];
}
- /* Figure out the players sp/mana/hp totals. */
if (type == PLAYER)
{
- int pl_level;
+ // clamp various player stats
+ for (int i = 0; i < NUM_STATS; ++i)
+ stats.stat (i) = stat_sum [i];
+
+ check_stat_bounds (&stats);
- check_stat_bounds (&(stats));
- pl_level = level;
+ contr->digestion = clamp (contr->digestion, MIN_DIGESTION, MAX_DIGESTION);
+
+ /* Figure out the players sp/mana/hp totals. */
+ int pl_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.
*/
- for (i = 1, stats.maxhp = 0; i <= pl_level && i <= 10; i++)
+ stats.maxhp = 0;
+ for (int i = 1; i <= min (10, pl_level); i++)
{
- j = contr->levhp[i] + con_bonus[stats.Con] / 2;
+ int j = contr->levhp[i] + con_bonus[stats.Con] / 2;
if (i % 2 && con_bonus[stats.Con] % 2)
- {
- if (con_bonus[stats.Con] > 0)
- j++;
- else
- j--;
- }
+ if (con_bonus[stats.Con] > 0)
+ j++;
+ else
+ j--;
stats.maxhp += j > 1 ? j : 1; /* always get at least 1 hp/level */
}
- for (i = 11; i <= level; i++)
- stats.maxhp += 2;
+ stats.maxhp += 2 * max (0, level - 10);
if (stats.hp > stats.maxhp)
stats.hp = stats.maxhp;
@@ -1211,9 +1171,9 @@
stats.maxsp = 1;
else
{
- sp_tmp = 0.f;
+ float sp_tmp = 0.f;
- for (i = 1; i <= mana_obj->level && i <= 10; i++)
+ for (int i = 1; i <= min (10, mana_obj->level); i++)
{
float stmp;
@@ -1223,21 +1183,14 @@
else
stmp = contr->levsp[i] + (2.f * sp_bonus[stats.Pow] + sp_bonus[stats.Int]) / 12.f;
- if (stmp < 1.f)
- stmp = 1.f;
-
- sp_tmp += stmp;
+ sp_tmp += max (1.f, stmp);
}
- stats.maxsp = (sint16)sp_tmp;
-
- for (i = 11; i <= mana_obj->level; i++)
- stats.maxsp += 2;
+ stats.maxsp = int (sp_tmp) + 2 * max (0, mana_obj->level - 10);
}
/* Characters can get their sp supercharged via rune of transferrance */
- if (stats.sp > stats.maxsp * 2)
- stats.sp = stats.maxsp * 2;
+ stats.sp = min (stats.sp, stats.maxsp * 2);
/* set maxgrace, notice 3-4 lines below it depends on both Wis and Pow */
if (!grace_obj || !grace_obj->level || type != PLAYER)
@@ -1252,8 +1205,9 @@
* 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.f;
- for (i = 1, stats.maxgrace = 0; i <= grace_obj->level && i <= 10; i++)
+ float sp_tmp = 0.f;
+
+ for (int i = 1; i <= min (10, grace_obj->level); i++)
{
float grace_tmp = 0.f;
@@ -1263,17 +1217,11 @@
else
grace_tmp = contr->levgrace[i] + (grace_bonus[stats.Pow] + 2.f * grace_bonus[stats.Wis]) / 12.f;
- if (grace_tmp < 1.f)
- grace_tmp = 1.f;
-
- sp_tmp += grace_tmp;
+ sp_tmp += max (1.f, grace_tmp);
}
- stats.maxgrace = (sint16)sp_tmp;
-
- /* two grace points per level after 11 */
- for (i = 11; i <= grace_obj->level; i++)
- stats.maxgrace += 2;
+ /* two grace points per level after 10 */
+ stats.maxgrace = int (sp_tmp) + 2 * max (0, grace_obj->level - 10);
}
/* No limit on grace vs maxgrace */
@@ -1303,7 +1251,7 @@
{
wc -= wc_obj->level + thaco_bonus[stats.Str];
- for (i = 1; i < wc_obj->level; i++)
+ for (int i = 1; i < wc_obj->level; i++)
{
/* additional wc every 6 levels */
if (!(i % 6))
@@ -1326,9 +1274,6 @@
if (settings.search_items && contr->search_str[0])
speed -= 1;
-
- if (attacktype == 0)
- attacktype = arch->attacktype;
} /* End if player */
if (added_speed >= 0)
@@ -1337,8 +1282,7 @@
speed /= 1.f - added_speed;
/* Max is determined by armour */
- if (speed > max)
- speed = max;
+ speed = min (speed, max_speed);
if (type == PLAYER)
{
@@ -1347,20 +1291,21 @@
* weight limit, then player suffers a speed reduction based on how
* much above he is, and what is max carry is
*/
- f = (carrying / 1000) - max_carry[stats.Str];
- if (f > 0)
+ float f = (carrying / 1000) - max_carry[stats.Str];
+ if (f > 0.f)
speed = speed / (1.f + f / max_carry[stats.Str]);
}
speed += bonus_speed / 10.f; /* Not affected by limits */
+ speed *= speed_reduce_from_disease;
/* 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.
+ * 25 ticks or so. This amounts to once every 3 seconds of realtime.
*/
- speed = speed * speed_reduce_from_disease;
+ max_it (speed, is_player () ? MIN_PLAYER_SPEED : MIN_ACTIVE_SPEED);
- if (speed < 0.01f && type == PLAYER)
- speed = 0.01f;
+ if (speed != old_speed)
+ set_speed (speed);
if (type == PLAYER)
{
@@ -1402,23 +1347,37 @@
else if (move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH))
move_type &= ~MOVE_WALK;
- if (speed != old_speed)
- set_speed (speed);
+ // 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
@@ -1442,11 +1401,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)
@@ -1474,29 +1428,17 @@
if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level)
atnr = abil->stats.exp;
- level = (int) (level / 5.);
-
/* now set the new title */
- if (pl->contr != NULL)
+ 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, "");
@@ -1507,7 +1449,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 */
@@ -1573,24 +1515,20 @@
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;
}
/* 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;
- 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;
}
@@ -1606,15 +1544,18 @@
player_lvl_adj (object *who, object *op)
{
char buf[MAX_BUF];
+ bool changed = false;
if (!op) /* when rolling stats */
op = who;
- if (op->level < settings.max_level && op->stats.exp >= level_exp (op->level + 1, who->expmul))
+ while (op->level < settings.max_level && op->stats.exp >= level_exp (op->level + 1, who->expmul))
{
+ changed = true;
+
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 */
@@ -1625,37 +1566,39 @@
who->contr->levgrace[who->level] = die_roll (2, 2, who, PREFER_HIGH) - 1;
}
- who->update_stats ();
if (op->level > 1)
{
if (op->type != PLAYER)
- sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name);
+ {
+ who->contr->play_sound (sound_find ("skill_up"));
+ 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);
+ {
+ who->contr->play_sound (sound_find ("level_up"));
+ 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))
+
+ while (op->level > 1 && op->stats.exp < level_exp (op->level, who->expmul))
{
+ changed = true;
+
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 */
}
- /* check if the spell data has changed */
- esrv_update_stats (who->contr);
- esrv_update_spells (who->contr);
+ if (changed)
+ who->update_stats (); // should cause esrv_update_stats and esrv_update_spells
}
/*
@@ -1666,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);
}
/*
@@ -1707,11 +1647,10 @@
* 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 = NULL;
+ object *skill_obj;
sint64 limit, exp_to_add;
- int i;
/* prevents some forms of abuse. */
if (op->contr->braced)
@@ -1722,29 +1661,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);
}
}
@@ -1754,7 +1686,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;
@@ -1771,7 +1703,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;
@@ -1787,28 +1719,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;
}
@@ -1818,10 +1754,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,
@@ -1835,7 +1770,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;
@@ -1844,7 +1779,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;
@@ -1855,7 +1790,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);
}
@@ -1879,7 +1814,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);
@@ -1906,7 +1841,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
@@ -1942,17 +1877,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
@@ -1962,18 +1895,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);