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

Function newman

src/polyself.c:335–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335staticfn void
336newman(void)
337{
338 const char *newform;
339 int i, oldlvl, newlvl, oldgend, newgend, hpmax, enmax;
340
341 oldlvl = u.ulevel;
342 newlvl = oldlvl + rn1(5, -2); /* new = old + {-2,-1,0,+1,+2} */
343 if (newlvl > 127 || newlvl < 1) { /* level went below 0? */
344 goto dead; /* old level is still intact (in case of lifesaving) */
345 }
346 if (newlvl > MAXULEV)
347 newlvl = MAXULEV;
348 /* If your level goes down, your peak level goes down by
349 the same amount so that you can't simply use blessed
350 full healing to undo the decrease. But if your level
351 goes up, your peak level does *not* undergo the same
352 adjustment; you might end up losing out on the chance
353 to regain some levels previously lost to other causes. */
354 if (newlvl < oldlvl)
355 u.ulevelmax -= (oldlvl - newlvl);
356 if (u.ulevelmax < newlvl)
357 u.ulevelmax = newlvl;
358 u.ulevel = newlvl;
359
360 oldgend = poly_gender();
361 if (gs.sex_change_ok && !rn2(10))
362 change_sex();
363
364 adjabil(oldlvl, (int) u.ulevel);
365
366 /* random experience points for the new experience level */
367 u.uexp = rndexp(FALSE);
368
369 /* set up new attribute points (particularly Con) */
370 redist_attr();
371
372 /*
373 * New hit points:
374 * remove "level gain"-based HP from any extra HP accumulated
375 * (the "extra" might actually be negative);
376 * modify the extra, retaining {80%, 90%, 100%, or 110%};
377 * add in newly generated set of level-gain HP.
378 *
379 * (This used to calculate new HP in direct proportion to old HP,
380 * but that was subject to abuse: accumulate a large amount of
381 * extra HP, drain level down to 1, then polyself to level 2 or 3
382 * [lifesaving capability needed to handle level 0 and -1 cases]
383 * and the extra got multiplied by 2 or 3. Repeat the level
384 * drain and polyself steps until out of lifesaving capability.)
385 */
386 hpmax = u.uhpmax;
387 for (i = 0; i < oldlvl; i++)
388 hpmax -= (int) u.uhpinc[i];
389 /* hpmax * rn1(4,8) / 10; 0.95*hpmax on average */
390 hpmax = rounddiv((long) hpmax * (long) rn1(4, 8), 10);
391 for (i = 0; (u.ulevel = i) < newlvl; i++)
392 hpmax += newhp();

Callers 1

polyselfFunction · 0.85

Calls 15

poly_genderFunction · 0.85
rn2Function · 0.85
change_sexFunction · 0.85
adjabilFunction · 0.85
rndexpFunction · 0.85
redist_attrFunction · 0.85
rounddivFunction · 0.85
newhpFunction · 0.85
setuhpmaxFunction · 0.85
newpwFunction · 0.85
make_sickFunction · 0.85
make_stonedFunction · 0.85

Tested by

no test coverage detected