returns the quality of an item of food; the lower the better; fungi and ghouls will eat even tainted food */
| 992 | /* returns the quality of an item of food; the lower the better; |
| 993 | fungi and ghouls will eat even tainted food */ |
| 994 | int |
| 995 | dogfood(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; |
no test coverage detected