MCPcopy Index your code
hub / github.com/NetHack/NetHack / rndexp

Function rndexp

src/exper.c:377–400  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

375 experience level: base number of points needed to reach the current
376 level plus a random portion of what it takes to get to the next level */
377long
378rndexp(boolean gaining) /* gaining XP via potion vs setting XP for polyself */
379{
380 long minexp, maxexp, diff, factor, result;
381
382 minexp = (u.ulevel == 1) ? 0L : newuexp(u.ulevel - 1);
383 maxexp = newuexp(u.ulevel);
384 diff = maxexp - minexp, factor = 1L;
385 /* make sure that `diff' is an argument which rn2() can handle */
386 while (diff >= (long) LARGEST_INT)
387 diff /= 2L, factor *= 2L;
388 result = minexp + factor * (long) rn2((int) diff);
389 /* 3.4.1: if already at level 30, add to current experience
390 points rather than to threshold needed to reach the current
391 level; otherwise blessed potions of gain level can result
392 in lowering the experience points instead of raising them */
393 if (u.ulevel == MAXULEV && gaining) {
394 result += (u.uexp - minexp);
395 /* avoid wrapping (over 400 blessed potions needed for that...) */
396 if (result < u.uexp)
397 result = u.uexp;
398 }
399 return result;
400}
401
402/*exper.c*/

Callers 2

peffect_gain_levelFunction · 0.85
newmanFunction · 0.85

Calls 2

newuexpFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected