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

Function floorfood

src/eat.c:3578–3731  ·  view source on GitHub ↗

Returns an object representing food. * Object may be either on floor or in inventory. */

Source from the content-addressed store, hash-verified

3576 * Object may be either on floor or in inventory.
3577 */
3578struct obj *
3579floorfood(
3580 const char *verb,
3581 int corpsecheck) /* 0, no check, 1, corpses, 2, tinnable corpses */
3582{
3583 struct obj *otmp;
3584 char qbuf[QBUFSZ];
3585 char c;
3586 struct permonst *uptr = gy.youmonst.data;
3587 boolean feeding = !strcmp(verb, "eat"), /* corpsecheck==0 */
3588 offering = !strcmp(verb, "sacrifice"); /* corpsecheck==1 */
3589
3590 getobj_else = 0; /* haven't asked about floor food; is used to vary
3591 * "you don't have anything [else] to eat" when
3592 * floor food has been declined and inventory lacks
3593 * any suitable items */
3594 /* if we can't touch floor objects then use invent food only;
3595 same when 'm' prefix is used--for #eat, it means "skip floor food" */
3596 if (iflags.menu_requested
3597 || !can_reach_floor(TRUE) || (feeding && u.usteed)
3598 || (is_pool_or_lava(u.ux, u.uy)
3599 && (Wwalking || is_clinger(uptr) || (Flying && !Breathless))))
3600 goto skipfloor;
3601
3602 if (feeding && metallivorous(uptr)) {
3603 struct obj *gold;
3604 struct trap *ttmp = t_at(u.ux, u.uy);
3605
3606 if (ttmp && ttmp->tseen && ttmp->ttyp == BEAR_TRAP) {
3607 boolean u_in_beartrap = (u.utrap && u.utraptype == TT_BEARTRAP);
3608
3609 /* If not already stuck in the trap, perhaps there should
3610 be a chance to becoming trapped? Probably not, because
3611 then the trap would just get eaten on the _next_ turn... */
3612 Sprintf(qbuf, "There is a bear trap here (%s); eat it?",
3613 u_in_beartrap ? "holding you" : "armed");
3614 if ((c = yn_function(qbuf, ynqchars, 'n', TRUE)) == 'y') {
3615 struct obj *beartrap;
3616
3617 deltrap(ttmp);
3618 if (u_in_beartrap)
3619 reset_utrap(TRUE);
3620 beartrap = mksobj(BEARTRAP, TRUE, FALSE);
3621 Sprintf(qbuf,"You only manage to %s the bear trap.",
3622 u_in_beartrap ? "free yourself from" : "disarm");
3623 if (check_capacity(qbuf) && beartrap) {
3624 obj_extract_self(beartrap);
3625 dropy(beartrap); /* put it on the floor */
3626 return (struct obj *) 0;
3627 }
3628 return beartrap;
3629 } else if (c == 'q') {
3630 return (struct obj *) 0;
3631 }
3632 ++getobj_else;
3633 }
3634 if (levl[u.ux][u.uy].typ == IRONBARS) {
3635 /* already verified that hero is metallivorous above */

Callers 3

dosacrificeFunction · 0.85
doeatFunction · 0.85
use_tinning_kitFunction · 0.85

Calls 15

can_reach_floorFunction · 0.85
is_pool_or_lavaFunction · 0.85
t_atFunction · 0.85
yn_functionFunction · 0.85
deltrapFunction · 0.85
reset_utrapFunction · 0.85
mksobjFunction · 0.85
check_capacityFunction · 0.85
obj_extract_selfFunction · 0.85
dropyFunction · 0.85
on_levelFunction · 0.85
g_atFunction · 0.85

Tested by

no test coverage detected