From 9d7378ec57f41e0451d9c9353e72be8d2f96a1e8 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Tue, 29 Aug 2023 16:19:06 -0400 Subject: [PATCH] Fix: undoing monsters' permablindness by accident Monsters can become permanently blind (in very narrow circumstances -- I think limited only to a very short-range camera flash), in which case they have both mon->mblinded and mon->mcansee set to 0. Such permanently blinded monsters can counterintuitively regain their sight by being blinded a second time from a different source: for example, by being hit with a cream pie. That second blinding will increase mon->mblinded (which functions as a blindness timeout) by some amount, and when it runs out the monster will regain its sight. Try to make sure that doesn't happen by skipping any blinding attacks if the monster has already been permanently blinded. --- include/monst.h | 2 ++ src/mondata.c | 4 ++++ src/potion.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/monst.h b/include/monst.h index d04300171d..ecb1391aaf 100644 --- a/include/monst.h +++ b/include/monst.h @@ -248,6 +248,8 @@ struct monst { #define engulfing_u(mon) (u.uswallow && (u.ustuck == (mon))) #define helpless(mon) ((mon)->msleeping || !(mon)->mcanmove) +#define mon_perma_blind(mon) (!mon->mcansee && !mon->mblinded) + #define mon_offmap(mon) (((mon)->mstate & (MON_DETACH|MON_MIGRATING|MON_LIMBO|MON_OFFMAP)) != 0) /* Get the maximum difficulty monsters that can currently be generated, diff --git a/src/mondata.c b/src/mondata.c index 282da195a4..d66b54cca5 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -226,6 +226,10 @@ can_blnd( if (!haseyes(mdef->data)) return FALSE; + /* if monster has been permanently blinded, the deed is already done */ + if (!is_you && mon_perma_blind(mdef)) + return FALSE; + /* /corvus oculum corvi non eruit/ a saying expressed in Latin rather than a zoological observation: "a crow will not pluck out the eye of another crow" diff --git a/src/potion.c b/src/potion.c index a4701b1bf4..40df5d931d 100644 --- a/src/potion.c +++ b/src/potion.c @@ -1786,7 +1786,7 @@ potionhit(struct monst *mon, struct obj *obj, int how) mon_adjust_speed(mon, 1, obj); break; case POT_BLINDNESS: - if (haseyes(mon->data)) { + if (haseyes(mon->data) && !mon_perma_blind(mon)) { int btmp = 64 + rn2(32) + rn2(32) * !resist(mon, POTION_CLASS, 0, NOTELL);