MCPcopy Create free account
hub / github.com/NetHack/NetHack / regen_hp

Function regen_hp

src/allmain.c:624–679  ·  view source on GitHub ↗

maybe recover some lost health (or lose some when an eel out of water) */

Source from the content-addressed store, hash-verified

622
623/* maybe recover some lost health (or lose some when an eel out of water) */
624staticfn void
625regen_hp(int wtcap)
626{
627 int heal = 0;
628 boolean reached_full = FALSE,
629 encumbrance_ok = (wtcap < MOD_ENCUMBER || !u.umoved);
630
631 if (Upolyd) {
632 if (u.mh < 1) { /* shouldn't happen... */
633 rehumanize();
634 } else if (gy.youmonst.data->mlet == S_EEL
635 && !is_pool(u.ux, u.uy) && !Is_waterlevel(&u.uz)
636 && !Breathless) {
637 /* eel out of water loses hp, similar to monster eels;
638 as hp gets lower, rate of further loss slows down */
639 if (u.mh > 1 && !Regeneration && rn2(u.mh) > rn2(8)
640 && (!Half_physical_damage || !(svm.moves % 2L)))
641 heal = -1;
642 } else if (u.mh < u.mhmax) {
643 if (U_CAN_REGEN() || (encumbrance_ok && !(svm.moves % 20L)))
644 heal = 1;
645 }
646 if (heal) {
647 disp.botl = TRUE;
648 u.mh += heal;
649 reached_full = (u.mh == u.mhmax);
650 }
651
652 /* !Upolyd */
653 } else {
654 /* [when this code was in-line within moveloop(), there was
655 no !Upolyd check here, so poly'd hero recovered lost u.uhp
656 once u.mh reached u.mhmax; that may have been convenient
657 for the player, but it didn't make sense for gameplay...] */
658 if (u.uhp < u.uhpmax && (encumbrance_ok || U_CAN_REGEN())) {
659 heal = (u.ulevel + (int)ACURR(A_CON)) > rn2(100);
660
661 if (U_CAN_REGEN())
662 heal += 1;
663 if (Sleepy && u.usleep)
664 heal++;
665
666 if (heal) {
667 disp.botl = TRUE;
668 u.uhp += heal;
669 if (u.uhp > u.uhpmax)
670 u.uhp = u.uhpmax;
671 /* stop voluntary multi-turn activity if now fully healed */
672 reached_full = (u.uhp == u.uhpmax);
673 }
674 }
675 }
676
677 if (reached_full)
678 interrupt_multi("You are in full health.");
679}
680
681#undef U_CAN_REGEN

Callers 1

allmain.cFile · 0.85

Calls 4

rehumanizeFunction · 0.85
is_poolFunction · 0.85
rn2Function · 0.85
interrupt_multiFunction · 0.85

Tested by

no test coverage detected