fix #H5853 - carrots don't cure blind pets

Report was for a blinded horse which ate a carrot but remained blind.
This fixes that, and also lets blinded carnivorous pets eat carrots.
Gelatinous cubes now handle carrots too, but since they lack eyses
there won't be any noticeable effect for them.
This commit is contained in:
PatR
2017-08-14 16:30:23 -07:00
parent fd74f2e149
commit 5e54397609
5 changed files with 45 additions and 35 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 extern.h $NHDT-Date: 1501725402 2017/08/03 01:56:42 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.598 $ */ /* NetHack 3.6 extern.h $NHDT-Date: 1502753404 2017/08/14 23:30:04 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.600 $ */
/* Copyright (c) Steve Creps, 1988. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1563,6 +1563,7 @@ E int FDECL(rnd_misc_item, (struct monst *));
E boolean FDECL(searches_for_item, (struct monst *, struct obj *)); E boolean FDECL(searches_for_item, (struct monst *, struct obj *));
E boolean FDECL(mon_reflects, (struct monst *, const char *)); E boolean FDECL(mon_reflects, (struct monst *, const char *));
E boolean FDECL(ureflects, (const char *, const char *)); E boolean FDECL(ureflects, (const char *, const char *));
E void FDECL(mcureblindness, (struct monst *, BOOLEAN_P));
E boolean FDECL(munstone, (struct monst *, BOOLEAN_P)); E boolean FDECL(munstone, (struct monst *, BOOLEAN_P));
E boolean FDECL(munslime, (struct monst *, BOOLEAN_P)); E boolean FDECL(munslime, (struct monst *, BOOLEAN_P));
+9 -5
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 dog.c $NHDT-Date: 1446808440 2015/11/06 11:14:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ /* NetHack 3.6 dog.c $NHDT-Date: 1502753406 2017/08/14 23:30:06 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.60 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -736,7 +736,8 @@ struct monst *mon;
register struct obj *obj; register struct obj *obj;
{ {
struct permonst *mptr = mon->data, *fptr = 0; struct permonst *mptr = mon->data, *fptr = 0;
boolean carni = carnivorous(mptr), herbi = herbivorous(mptr), starving; boolean carni = carnivorous(mptr), herbi = herbivorous(mptr),
starving, mblind;
if (is_quest_artifact(obj) || obj_resists(obj, 0, 95)) if (is_quest_artifact(obj) || obj_resists(obj, 0, 95))
return obj->cursed ? TABU : APPORT; return obj->cursed ? TABU : APPORT;
@@ -755,8 +756,10 @@ register struct obj *obj;
return obj->cursed ? UNDEF : APPORT; return obj->cursed ? UNDEF : APPORT;
/* a starving pet will eat almost anything */ /* a starving pet will eat almost anything */
starving = starving = (mon->mtame && !mon->isminion
(mon->mtame && !mon->isminion && EDOG(mon)->mhpmax_penalty); && EDOG(mon)->mhpmax_penalty);
/* even carnivores will eat carrots if they're temporarily blind */
mblind = (!mon->mcansee && haseyes(mon->data));
/* ghouls prefer old corpses and unhatchable eggs, yum! /* ghouls prefer old corpses and unhatchable eggs, yum!
they'll eat fresh non-veggy corpses and hatchable eggs they'll eat fresh non-veggy corpses and hatchable eggs
@@ -813,8 +816,9 @@ register struct obj *obj;
case TIN: case TIN:
return metallivorous(mptr) ? ACCFOOD : MANFOOD; return metallivorous(mptr) ? ACCFOOD : MANFOOD;
case APPLE: case APPLE:
case CARROT:
return herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD; return herbi ? DOGFOOD : starving ? ACCFOOD : MANFOOD;
case CARROT:
return (herbi || mblind) ? DOGFOOD : starving ? ACCFOOD : MANFOOD;
case BANANA: case BANANA:
return (mptr->mlet == S_YETI && herbi) return (mptr->mlet == S_YETI && herbi)
? DOGFOOD /* for monkey and ape (tameable), sasquatch */ ? DOGFOOD /* for monkey and ape (tameable), sasquatch */
+5 -2
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 dogmove.c $NHDT-Date: 1463704424 2016/05/20 00:33:44 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.60 $ */ /* NetHack 3.6 dogmove.c $NHDT-Date: 1502753407 2017/08/14 23:30:07 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.63 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -209,7 +209,7 @@ int x, y; /* dog's starting location, might be different from current */
boolean devour; boolean devour;
{ {
register struct edog *edog = EDOG(mtmp); register struct edog *edog = EDOG(mtmp);
boolean poly, grow, heal, slimer, deadmimic; boolean poly, grow, heal, eyes, slimer, deadmimic;
int nutrit; int nutrit;
long oprice; long oprice;
char objnambuf[BUFSZ]; char objnambuf[BUFSZ];
@@ -226,6 +226,7 @@ boolean devour;
poly = polyfodder(obj); poly = polyfodder(obj);
grow = mlevelgain(obj); grow = mlevelgain(obj);
heal = mhealup(obj); heal = mhealup(obj);
eyes = (obj->otyp == CARROT);
if (devour) { if (devour) {
if (mtmp->meating > 1) if (mtmp->meating > 1)
@@ -343,6 +344,8 @@ boolean devour;
} }
if (heal) if (heal)
mtmp->mhp = mtmp->mhpmax; mtmp->mhp = mtmp->mhpmax;
if ((eyes || heal) && !mtmp->mcansee)
mcureblindness(mtmp, canseemon(mtmp));
if (deadmimic) if (deadmimic)
quickmimic(mtmp); quickmimic(mtmp);
return 1; return 1;
+6 -3
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mon.c $NHDT-Date: 1496531114 2017/06/03 23:05:14 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.240 $ */ /* NetHack 3.6 mon.c $NHDT-Date: 1502753408 2017/08/14 23:30:08 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.242 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -886,9 +886,9 @@ int
meatobj(mtmp) /* for gelatinous cubes */ meatobj(mtmp) /* for gelatinous cubes */
struct monst *mtmp; struct monst *mtmp;
{ {
register struct obj *otmp, *otmp2; struct obj *otmp, *otmp2;
struct permonst *ptr, *original_ptr = mtmp->data; struct permonst *ptr, *original_ptr = mtmp->data;
int poly, grow, heal, count = 0, ecount = 0; int poly, grow, heal, eyes, count = 0, ecount = 0;
char buf[BUFSZ]; char buf[BUFSZ];
buf[0] = '\0'; buf[0] = '\0';
@@ -986,6 +986,7 @@ struct monst *mtmp;
poly = polyfodder(otmp); poly = polyfodder(otmp);
grow = mlevelgain(otmp); grow = mlevelgain(otmp);
heal = mhealup(otmp); heal = mhealup(otmp);
eyes = (otmp->otyp == CARROT);
delobj(otmp); /* munch */ delobj(otmp); /* munch */
ptr = mtmp->data; ptr = mtmp->data;
if (poly) { if (poly) {
@@ -996,6 +997,8 @@ struct monst *mtmp;
} else if (heal) { } else if (heal) {
mtmp->mhp = mtmp->mhpmax; mtmp->mhp = mtmp->mhpmax;
} }
if ((eyes || heal) && !mtmp->mcansee)
mcureblindness(mtmp, canseemon(mtmp));
/* in case it polymorphed or died */ /* in case it polymorphed or died */
if (ptr != original_ptr) if (ptr != original_ptr)
return !ptr ? 2 : 1; return !ptr ? 2 : 1;
+23 -24
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 muse.c $NHDT-Date: 1469840918 2016/07/30 01:08:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.78 $ */ /* NetHack 3.6 muse.c $NHDT-Date: 1502753408 2017/08/14 23:30:08 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.79 $ */
/* Copyright (C) 1990 by Ken Arromdee */ /* Copyright (C) 1990 by Ken Arromdee */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -603,7 +603,7 @@ struct monst *mtmp;
int i, fleetim, how = 0; int i, fleetim, how = 0;
struct obj *otmp = m.defensive; struct obj *otmp = m.defensive;
boolean vis, vismon, oseen; boolean vis, vismon, oseen;
const char *Mnam, *mcsa = "%s can see again."; const char *Mnam;
if ((i = precheck(mtmp, otmp)) != 0) if ((i = precheck(mtmp, otmp)) != 0)
return i; return i;
@@ -628,10 +628,7 @@ struct monst *mtmp;
pline_The("tip of %s's horn glows!", mon_nam(mtmp)); pline_The("tip of %s's horn glows!", mon_nam(mtmp));
} }
if (!mtmp->mcansee) { if (!mtmp->mcansee) {
mtmp->mcansee = 1; mcureblindness(mtmp, vismon);
mtmp->mblinded = 0;
if (vismon)
pline(mcsa, Monnam(mtmp));
} else if (mtmp->mconf || mtmp->mstun) { } else if (mtmp->mconf || mtmp->mstun) {
mtmp->mconf = mtmp->mstun = 0; mtmp->mconf = mtmp->mstun = 0;
if (vismon) if (vismon)
@@ -939,12 +936,8 @@ struct monst *mtmp;
mtmp->mhp += i; mtmp->mhp += i;
if (mtmp->mhp > mtmp->mhpmax) if (mtmp->mhp > mtmp->mhpmax)
mtmp->mhp = ++mtmp->mhpmax; mtmp->mhp = ++mtmp->mhpmax;
if (!otmp->cursed && !mtmp->mcansee) { if (!otmp->cursed && !mtmp->mcansee)
mtmp->mcansee = 1; mcureblindness(mtmp, vismon);
mtmp->mblinded = 0;
if (vismon)
pline(mcsa, Monnam(mtmp));
}
if (vismon) if (vismon)
pline("%s looks better.", Monnam(mtmp)); pline("%s looks better.", Monnam(mtmp));
if (oseen) if (oseen)
@@ -957,12 +950,8 @@ struct monst *mtmp;
mtmp->mhp += i; mtmp->mhp += i;
if (mtmp->mhp > mtmp->mhpmax) if (mtmp->mhp > mtmp->mhpmax)
mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2)); mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 5 : 2));
if (!mtmp->mcansee) { if (!mtmp->mcansee)
mtmp->mcansee = 1; mcureblindness(mtmp, vismon);
mtmp->mblinded = 0;
if (vismon)
pline(mcsa, Monnam(mtmp));
}
if (vismon) if (vismon)
pline("%s looks much better.", Monnam(mtmp)); pline("%s looks much better.", Monnam(mtmp));
if (oseen) if (oseen)
@@ -974,12 +963,8 @@ struct monst *mtmp;
if (otmp->otyp == POT_SICKNESS) if (otmp->otyp == POT_SICKNESS)
unbless(otmp); /* Pestilence */ unbless(otmp); /* Pestilence */
mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4)); mtmp->mhp = (mtmp->mhpmax += (otmp->blessed ? 8 : 4));
if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS) { if (!mtmp->mcansee && otmp->otyp != POT_SICKNESS)
mtmp->mcansee = 1; mcureblindness(mtmp, vismon);
mtmp->mblinded = 0;
if (vismon)
pline(mcsa, Monnam(mtmp));
}
if (vismon) if (vismon)
pline("%s looks completely healed.", Monnam(mtmp)); pline("%s looks completely healed.", Monnam(mtmp));
if (oseen) if (oseen)
@@ -2175,6 +2160,20 @@ const char *fmt, *str;
return FALSE; return FALSE;
} }
/* cure mon's blindness (use_defensive, dog_eat, meatobj) */
void
mcureblindness(mon, verbos)
struct monst *mon;
boolean verbos;
{
if (!mon->mcansee) {
mon->mcansee = 1;
mon->mblinded = 0;
if (verbos && haseyes(mon->data))
pline("%s can see again.", Monnam(mon));
}
}
/* TRUE if the monster ate something */ /* TRUE if the monster ate something */
boolean boolean
munstone(mon, by_you) munstone(mon, by_you)