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

Function critically_low_hp

src/pray.c:115–156  ·  view source on GitHub ↗

critically low hit points if hp <= 5 or hp <= maxhp/N for some N */

Source from the content-addressed store, hash-verified

113
114/* critically low hit points if hp <= 5 or hp <= maxhp/N for some N */
115boolean
116critically_low_hp(
117 boolean only_if_injured) /* determines whether maxhp <= 5 matters */
118{
119 int divisor, hplim,
120 curhp = Upolyd ? u.mh : u.uhp,
121 maxhp = Upolyd ? u.mhmax : u.uhpmax;
122
123 if (only_if_injured && !(curhp < maxhp))
124 return FALSE;
125 /* if maxhp is extremely high, use lower threshold for the division test
126 (golden glow cuts off at 11+5*lvl, nurse interaction at 25*lvl; this
127 ought to use monster hit dice--and a smaller multiplier--rather than
128 ulevel when polymorphed, but polyself doesn't maintain that) */
129 hplim = 15 * u.ulevel;
130 if (maxhp > hplim)
131 maxhp = hplim;
132 /* 7 used to be the unconditional divisor */
133 switch (xlev_to_rank(u.ulevel)) { /* maps 1..30 into 0..8 */
134 case 0:
135 case 1:
136 divisor = 5;
137 break; /* explvl 1 to 5 */
138 case 2:
139 case 3:
140 divisor = 6;
141 break; /* explvl 6 to 13 */
142 case 4:
143 case 5:
144 divisor = 7;
145 break; /* explvl 14 to 21 */
146 case 6:
147 case 7:
148 divisor = 8;
149 break; /* explvl 22 to 29 */
150 default:
151 divisor = 9;
152 break; /* explvl 30+ */
153 }
154 /* 5 is a magic number in TROUBLE_HIT handling below */
155 return (boolean) (curhp <= 5 || curhp * divisor <= maxhp);
156}
157
158/* return True if surrounded by impassible rock, regardless of the state
159 of your own location (for example, inside a doorless closet) */

Callers 4

tty_status_updateFunction · 0.85
curses_status_updateFunction · 0.85
in_troubleFunction · 0.85
get_hiliteFunction · 0.85

Calls 1

xlev_to_rankFunction · 0.85

Tested by

no test coverage detected