MCPcopy Index your code
hub / github.com/NetHack/NetHack / food_detect

Function food_detect

src/detect.c:478–594  ·  view source on GitHub ↗

returns 1 if nothing was detected, 0 if something was detected */

Source from the content-addressed store, hash-verified

476
477/* returns 1 if nothing was detected, 0 if something was detected */
478int
479food_detect(struct obj *sobj)
480{
481 struct obj *obj;
482 struct monst *mtmp;
483 int ct = 0, ctu = 0;
484 boolean confused = (Confusion || (sobj && sobj->cursed)), stale;
485 char oclass = confused ? POTION_CLASS : FOOD_CLASS;
486 const char *what = confused ? something : "food";
487
488 stale = clear_stale_map(oclass, 0);
489 if (u.usteed) /* some situations leave steed with stale coordinates */
490 u.usteed->mx = u.ux, u.usteed->my = u.uy;
491
492 for (obj = fobj; obj; obj = obj->nobj)
493 if (o_in(obj, oclass)) {
494 if (u_at(obj->ox, obj->oy))
495 ctu++;
496 else
497 ct++;
498 }
499 for (mtmp = fmon; mtmp && (!ct || !ctu); mtmp = mtmp->nmon) {
500 if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx))
501 continue;
502 for (obj = mtmp->minvent; obj; obj = obj->nobj)
503 if (o_in(obj, oclass)) {
504 if (u_at(mtmp->mx, mtmp->my))
505 ctu++; /* steed or an engulfer with inventory */
506 else
507 ct++;
508 break;
509 }
510 }
511
512 if (!ct && !ctu) {
513 gk.known = stale && !confused;
514 if (stale) {
515 docrt();
516 You("sense a lack of %s nearby.", what);
517 if (sobj && sobj->blessed) {
518 if (!u.uedibility)
519 Your("%s starts to tingle.", body_part(NOSE));
520 u.uedibility = 1;
521 }
522 } else if (sobj) {
523 char buf[BUFSZ];
524
525 Sprintf(buf, "Your %s twitches%s.", body_part(NOSE),
526 (sobj->blessed && !u.uedibility)
527 ? " then starts to tingle"
528 : "");
529 if (sobj->blessed && !u.uedibility) {
530 boolean savebeginner = flags.beginner;
531
532 flags.beginner = FALSE; /* prevent non-delivery of message */
533 strange_feeling(sobj, buf);
534 flags.beginner = savebeginner;
535 u.uedibility = 1;

Callers 1

seffect_food_detectionFunction · 0.85

Calls 14

clear_stale_mapFunction · 0.85
o_inFunction · 0.85
docrtFunction · 0.85
YouFunction · 0.85
YourFunction · 0.85
body_partFunction · 0.85
strange_feelingFunction · 0.85
clsFunction · 0.85
unconstrain_mapFunction · 0.85
map_objectFunction · 0.85
newsymFunction · 0.85
exerciseFunction · 0.85

Tested by

no test coverage detected