From: nethack.rankin Date: Sat, 13 Jul 2002 12:19:09 +0000 (+0000) Subject: B04002 - blessed gain level vs XL 30 X-Git-Tag: MOVE2GIT~2649 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30f6fbb5fedb78f1ed1956ae5335b5791dd029c1;p=nethack B04002 - blessed gain level vs XL 30 Fix the problem [reported in the newsgroup and forwarded by ] of blessed potions of gain level having the possibility of reducing your experience points if you were already level 30. The random XP value that averages "half way to next level" could be less than your current experience if you had gotten to level 30 via such a blessed potion or had drunk at least one of same since reaching that level. This didn't really make any difference to game play since you weren't losing any levels, HP, mana, or score, but it was visible to users who enable the `showexp' option. --- diff --git a/doc/fixes34.1 b/doc/fixes34.1 index 68b8c24d1..9c88e1f20 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -155,6 +155,7 @@ steed movement would use your speed if walking step by step kicking a known, unseen monster would sometimes leave behind an extra I symbol applying a lance against a long worm could cause an impossible a knight applying a lance did not do a caitiff check +blessed gain level when already at level 30 won't reduce experience points Platform- and/or Interface-Specific Fixes diff --git a/include/extern.h b/include/extern.h index 335c4615e..1e290ae02 100644 --- a/include/extern.h +++ b/include/extern.h @@ -577,7 +577,7 @@ E void FDECL(more_experienced, (int,int)); E void FDECL(losexp, (const char *)); E void NDECL(newexplevel); E void FDECL(pluslvl, (BOOLEAN_P)); -E long NDECL(rndexp); +E long FDECL(rndexp, (BOOLEAN_P)); /* ### explode.c ### */ diff --git a/src/exper.c b/src/exper.c index 37771a8bb..932b2833a 100644 --- a/src/exper.c +++ b/src/exper.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)exper.c 3.4 2002/06/23 */ +/* SCCS Id: @(#)exper.c 3.4 2002/07/11 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -216,17 +216,32 @@ boolean incr; /* true iff via incremental experience growth */ flags.botl = 1; } +/* compute a random amount of experience points suitable for the hero's + experience level: base number of points needed to reach the current + level plus a random portion of what it takes to get to the next level */ long -rndexp() +rndexp(gaining) +boolean gaining; /* gaining XP via potion vs setting XP for polyself */ { - long minexp, maxexp, diff, factor; + long minexp, maxexp, diff, factor, result; minexp = (u.ulevel == 1) ? 0L : newuexp(u.ulevel - 1); maxexp = newuexp(u.ulevel); diff = maxexp - minexp, factor = 1L; + /* make sure that `diff' is an argument which rn2() can handle */ while (diff >= (long)LARGEST_INT) diff /= 2L, factor *= 2L; - return minexp + factor * (long)rn2((int)diff); + result = minexp + factor * (long)rn2((int)diff); + /* 3.4.1: if already at level 30, add to current experience + points rather than to threshold needed to reach the current + level; otherwise blessed potions of gain level can result + in lowering the experience points instead of raising them */ + if (u.ulevel == MAXULEV && gaining) { + result += (u.uexp - minexp); + /* avoid wrapping (over 400 blessed potions needed for that...) */ + if (result < u.uexp) result = u.uexp; + } + return result; } /*exper.c*/ diff --git a/src/polyself.c b/src/polyself.c index e080ba518..fb860ac75 100644 --- a/src/polyself.c +++ b/src/polyself.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)polyself.c 3.4 2002/06/23 */ +/* SCCS Id: @(#)polyself.c 3.4 2002/07/11 */ /* Copyright (C) 1987, 1988, 1989 by Ken Arromdee */ /* NetHack may be freely redistributed. See license for details. */ @@ -159,7 +159,7 @@ newman() reset_rndmonst(NON_PM); /* new monster generation criteria */ /* random experience points for the new experience level */ - u.uexp = rndexp(); + u.uexp = rndexp(FALSE); /* u.uhpmax * u.ulevel / oldlvl: proportionate hit points to new level * -10 and +10: don't apply proportionate HP to 10 of a starting diff --git a/src/potion.c b/src/potion.c index bbade3880..fe8726a09 100644 --- a/src/potion.c +++ b/src/potion.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)potion.c 3.4 2002/03/23 */ +/* SCCS Id: @(#)potion.c 3.4 2002/07/11 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -770,7 +770,7 @@ peffects(otmp) /* blessed potions place you at a random spot in the * middle of the new level instead of the low point */ - u.uexp = rndexp(); + u.uexp = rndexp(TRUE); break; case POT_HEALING: You_feel("better.");