From 33a5dbff37c889c9c72f0fbe0a85399638588329 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 20 Dec 2022 15:23:40 -0800 Subject: [PATCH] sleeping vs deafness Another one from entrez: falling asleep tried to make the hero Deaf, but was adding a negative value to the timeout. A negative value of bigger magnitude that the current timeout could produce weird values when making that be negative and then stuffing it into an unsigned field. This applies a fix to sleep-causes-deafness bug but also disables that, at least for the time being since nobody seemed to notice that it wasn't working. The fix might be noticeable so needs testing. This also adjusts You_hear() so that if Deaf and sleeping are both active, it will still yield "You dream that your hear ..." instead having Deaf override that. --- src/pline.c | 2 +- src/timeout.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pline.c b/src/pline.c index 2b68908b2..5eb9bb703 100644 --- a/src/pline.c +++ b/src/pline.c @@ -351,7 +351,7 @@ You_hear(const char *line, ...) va_list the_args; char *tmp; - if (Deaf || !flags.acoustics) + if ((Deaf && !Unaware) || !flags.acoustics) return; va_start(the_args, line); if (Underwater) diff --git a/src/timeout.c b/src/timeout.c index 4b642a4ae..705acf2da 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -851,14 +851,21 @@ fall_asleep(int how_long, boolean wakeup_msg) stop_occupation(); nomul(how_long); gm.multi_reason = "sleeping"; - /* generally don't notice sounds while sleeping */ +#if 0 /* this was broken; the fix for 'how_long' will result in changed + * behavior for sounds that don't go through You_hear() so needs + * testing */ + /* You_hear() produces "You dream that you hear ..." when sleeping; + other sound messages will either honor or ignore Deaf */ if (wakeup_msg && gm.multi == how_long) { /* caller can follow with a direct call to Hear_again() if there's a need to override this when wakeup_msg is true */ - incr_itimeout(&HDeaf, how_long); + /* 3.7: how_long is negative so wasn't actually incrementing the + deafness timeout when it used to be passed as-is */ + incr_itimeout(&HDeaf, abs(how_long)); gc.context.botl = TRUE; ga.afternmv = Hear_again; /* this won't give any messages */ } +#endif /* early wakeup from combat won't be possible until next monster turn */ u.usleep = gm.moves; gn.nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again;