compute and comment on your (new?) hunger status */
| 3359 | |
| 3360 | /* compute and comment on your (new?) hunger status */ |
| 3361 | void |
| 3362 | newuhs(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; |
no test coverage detected