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

Function newuhs

src/eat.c:3361–3513  ·  view source on GitHub ↗

compute and comment on your (new?) hunger status */

Source from the content-addressed store, hash-verified

3359
3360/* compute and comment on your (new?) hunger status */
3361void
3362newuhs(boolean incr)
3363{
3364 unsigned newhs;
3365 static unsigned save_hs;
3366 static boolean saved_hs = FALSE;
3367 int h = u.uhunger;
3368
3369 newhs = (h > 1000)
3370 ? SATIATED
3371 : (h > 150) ? NOT_HUNGRY
3372 : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING;
3373
3374 /* While you're eating, you may pass from WEAK to HUNGRY to NOT_HUNGRY.
3375 * This should not produce the message "you only feel hungry now";
3376 * that message should only appear if HUNGRY is an endpoint. Therefore
3377 * we check to see if we're in the middle of eating. If so, we save
3378 * the first hunger status, and at the end of eating we decide what
3379 * message to print based on the _entire_ meal, not on each little bit.
3380 */
3381 /* It is normally possible to check if you are in the middle of a meal
3382 * by checking occupation == eatfood, but there is one special case:
3383 * start_eating() can call bite() for your first bite before it
3384 * sets the occupation.
3385 * Anyone who wants to get that case to work _without_ an ugly static
3386 * force_save_hs variable, feel free.
3387 */
3388 /* Note: If you become a certain hunger status in the middle of the
3389 * meal, and still have that same status at the end of the meal,
3390 * this will incorrectly print the associated message at the end of
3391 * the meal instead of the middle. Such a case is currently
3392 * impossible, but could become possible if a message for SATIATED
3393 * were added or if HUNGRY and WEAK were separated by a big enough
3394 * gap to fit two bites.
3395 */
3396 if (go.occupation == eatfood || gf.force_save_hs) {
3397 if (!saved_hs) {
3398 save_hs = u.uhs;
3399 saved_hs = TRUE;
3400 }
3401 u.uhs = newhs;
3402 return;
3403 } else {
3404 if (saved_hs) {
3405 u.uhs = save_hs;
3406 saved_hs = FALSE;
3407 }
3408 }
3409
3410 if (newhs == FAINTING) {
3411 /* u,uhunger is likely to be negative at this point */
3412 int uhunger_div_by_10 = sgn(u.uhunger) * ((abs(u.uhunger) + 5) / 10);
3413
3414 if (is_fainted())
3415 newhs = FAINTED;
3416 if (u.uhs <= WEAK || rn2(20 - uhunger_div_by_10) >= 19) {
3417 if (!is_fainted() && gm.multi >= 0 /* %% */) {
3418 int duration = 10 - uhunger_div_by_10;

Callers 12

peffect_waterFunction · 0.85
peffect_boozeFunction · 0.85
peffect_see_invisibleFunction · 0.85
gulpumFunction · 0.85
newmanFunction · 0.85
do_reset_eatFunction · 0.85
done_eatingFunction · 0.85
gethungryFunction · 0.85
morehungryFunction · 0.85
lesshungryFunction · 0.85
cant_finish_mealFunction · 0.85
drinkfountainFunction · 0.85

Calls 12

sgnFunction · 0.85
is_faintedFunction · 0.85
rn2Function · 0.85
stop_occupationFunction · 0.85
YouFunction · 0.85
incr_itimeoutFunction · 0.85
nomulFunction · 0.85
selftouchFunction · 0.85
botFunction · 0.85
doneFunction · 0.85
end_runningFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected