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

Function drain_en

src/trap.c:5201–5244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5199}
5200
5201void
5202drain_en(int n, boolean max_already_drained)
5203{
5204 const char *mesg;
5205 char punct = max_already_drained ? '!' : '.';
5206
5207 /*
5208 * FIXME?
5209 * u.uenmax should probably have a higher minimum than 0;
5210 * perhaps u.ulevel or (u.ulevel + 1) / 2
5211 */
5212 if (u.uenmax < 1) {
5213 /* energy is completely gone */
5214 if (u.uen || u.uenmax) { /* paranoia */
5215 u.uen = u.uenmax = 0;
5216 disp.botl = TRUE;
5217 }
5218 mesg = "momentarily lethargic";
5219 } else {
5220 /* throttle further loss a bit when there's not much left to lose */
5221 if (n > (u.uen + u.uenmax) / 3)
5222 n = rnd(n);
5223
5224 mesg = "your magical energy drain away";
5225 if (n > u.uen)
5226 punct = '!';
5227
5228 u.uen -= n;
5229 if (u.uen < 0) {
5230 u.uenmax -= rnd(-u.uen);
5231 if (u.uenmax < 0)
5232 u.uenmax = 0;
5233 u.uen = 0;
5234 } else if (u.uen > u.uenmax) {
5235 /* uen might be greater than uenmax if caller reduced uenmax
5236 and then we throttled the loss being applied to current */
5237 u.uen = u.uenmax;
5238 }
5239 disp.botl = TRUE;
5240 }
5241 /* after manipulating u.uen,uenmax and setting context.botl, so
5242 that You_feel() -> pline() will update status before the message */
5243 You_feel("%s%c", mesg, punct);
5244}
5245
5246/* the #untrap command - disarm a trap */
5247int

Callers 3

mhitm_ad_drenFunction · 0.85
trapeffect_anti_magicFunction · 0.85
gulpmuFunction · 0.85

Calls 2

rndFunction · 0.85
You_feelFunction · 0.85

Tested by

no test coverage detected