From 742216540c3e27ef332e9ec23db5faa7be88cb11 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Sun, 12 Jul 2020 20:58:35 -0400 Subject: [PATCH] Check bones data directly for deja vu messages After modifications to amnesia, `deja vu' messages are now displayed upon entering a level containing bones of a previous character of the current player. This test is done simply by checking for a ghost on the level that shares a name with the current character. However, since ghosts generated in other circumstances (such as in the Valley of the Dead and other special levels) can have names pulled randomly from the high score list, etc, this message can be displayed on non-bones levels where a ghost has been generated with the character's name. Additionally, when a bones pile doesn't include a ghost (such as when the character in question was slimed, killed by a wraith, etc), the `deja vu' message will not be displayed when it should be. This is all described in in NetHack/NetHack#322. This commit changes the method of testing for `familiarity' by adding a function to iterate through any bones data for the current level, searching for a match to the hero's name. Should fix NetHack/NetHack#322. --- include/extern.h | 3 ++- src/bones.c | 23 ++++++++++++++++++++++- src/do.c | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/extern.h b/include/extern.h index 873b2e632..89f07f57a 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1594168620 2020/07/08 00:37:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.851 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.852 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -161,6 +161,7 @@ E void FDECL(drop_upon_death, (struct monst *, struct obj *, int, int)); E boolean NDECL(can_make_bones); E void FDECL(savebones, (int, time_t, struct obj *)); E int NDECL(getbones); +E boolean FDECL(bones_include_name, (const char *)); /* ### botl.c ### */ diff --git a/src/bones.c b/src/bones.c index 21fc01534..357271a71 100644 --- a/src/bones.c +++ b/src/bones.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 bones.c $NHDT-Date: 1593953344 2020/07/05 12:49:04 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.100 $ */ +/* NetHack 3.6 bones.c $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.102 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -658,4 +658,25 @@ getbones() return ok; } +/* check whether current level contains bones from a particular player */ +boolean +bones_include_name(name) +const char *name; +{ + struct cemetery *bp; + char buf[BUFSZ]; + + Strcpy(buf, name); + Strcat(buf, "-"); + int l = strlen(buf); + + if ((bp = g.level.bonesinfo)) { + do { + if (!strncmp(bp->who, buf, l)) + return TRUE; + } while ((bp = bp->next) != (struct cemetery *) 0); + } + return FALSE; +} + /*bones.c*/ diff --git a/src/do.c b/src/do.c index 8f13dd2ad..e9fb19c85 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do.c $NHDT-Date: 1593953347 2020/07/05 12:49:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.246 $ */ +/* NetHack 3.6 do.c $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.247 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1470,7 +1470,7 @@ boolean at_stairs, falling, portal; mklev(); new = TRUE; /* made the level */ - familiar = (find_ghost_with_name(g.plname) != (struct monst *) 0); + familiar = bones_include_name(g.plname); } else { /* returning to previously visited level; reload it */ nhfp = open_levelfile(new_ledger, whynot);