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

Function dogfood

src/dog.c:994–1134  ·  view source on GitHub ↗

returns the quality of an item of food; the lower the better; fungi and ghouls will eat even tainted food */

Source from the content-addressed store, hash-verified

992/* returns the quality of an item of food; the lower the better;
993 fungi and ghouls will eat even tainted food */
994int
995dogfood(struct monst *mon, struct obj *obj)
996{
997 struct permonst *mptr = mon->data, *fptr;
998 boolean carni = carnivorous(mptr), herbi = herbivorous(mptr),
999 starving, mblind;
1000 int fx;
1001
1002 if (obj->opoisoned && !resists_poison(mon))
1003 return POISON;
1004 if (is_quest_artifact(obj) || obj_resists(obj, 0, 95))
1005 return obj->cursed ? TABU : APPORT;
1006
1007 switch (obj->oclass) {
1008 case FOOD_CLASS:
1009 fx = (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG)
1010 /* corpsenm might be NON_PM (special tin, unhatchable egg) */
1011 ? obj->corpsenm
1012 : NON_PM;
1013 /* mons[NUMMONS] is a valid array entry, though not a valid monster;
1014 * predicate tests against it will fail */
1015 fptr = &mons[(ismnum(fx)) ? fx : NUMMONS];
1016
1017 if (obj->otyp == CORPSE && is_rider(fptr))
1018 return TABU;
1019 if ((obj->otyp == CORPSE || obj->otyp == EGG)
1020 && flesh_petrifies(fptr) /* c*ckatrice or Medusa */
1021 && !resists_ston(mon))
1022 return POISON;
1023 if (obj->otyp == LUMP_OF_ROYAL_JELLY
1024 && mon->data == &mons[PM_KILLER_BEE]) {
1025 struct monst *mtmp = find_pmmonst(PM_QUEEN_BEE);
1026
1027 /* if there's a queen bee on the level, don't eat royal jelly;
1028 if there isn't, do eat it and grow into a queen */
1029 return !mtmp ? DOGFOOD : TABU;
1030 }
1031 if (!carni && !herbi)
1032 return obj->cursed ? UNDEF : APPORT;
1033
1034 /* a starving pet will eat almost anything */
1035 starving = (mon->mtame && !mon->isminion
1036 && EDOG(mon)->mhpmax_penalty);
1037 /* even carnivores will eat carrots if they're temporarily blind */
1038 mblind = (!mon->mcansee && haseyes(mon->data));
1039
1040 /* ghouls prefer old corpses and unhatchable eggs, yum!
1041 they'll eat fresh non-veggy corpses and hatchable eggs
1042 when starving; they never eat stone-to-flesh'd meat */
1043 if (mptr == &mons[PM_GHOUL]) {
1044 if (obj->otyp == CORPSE)
1045 return (peek_at_iced_corpse_age(obj) + 50L <= svm.moves
1046 && !(fx == PM_LIZARD || fx == PM_LICHEN)) ? DOGFOOD
1047 : (starving && !vegan(fptr)) ? ACCFOOD
1048 : POISON;
1049 if (obj->otyp == EGG)
1050 return stale_egg(obj) ? CADAVER : starving ? ACCFOOD : POISON;
1051 return TABU;

Callers 7

thitmonstFunction · 0.85
dog_eatFunction · 0.85
dog_inventFunction · 0.85
dog_goalFunction · 0.85
dog_moveFunction · 0.85
tamedogFunction · 0.85
mon_would_consume_itemFunction · 0.85

Calls 6

is_quest_artifactFunction · 0.85
obj_resistsFunction · 0.85
find_pmmonstFunction · 0.85
peek_at_iced_corpse_ageFunction · 0.85
same_raceFunction · 0.85
mon_hates_silverFunction · 0.85

Tested by

no test coverage detected