From 742216540c3e27ef332e9ec23db5faa7be88cb11 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Sun, 12 Jul 2020 20:58:35 -0400 Subject: [PATCH 1/5] 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); From 64c26771f34d1146e1ff07190963456d16806b80 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Mon, 13 Jul 2020 06:18:00 -0400 Subject: [PATCH 2/5] Remove find_ghost_with_name(mon.c) --- include/extern.h | 3 +-- src/mon.c | 18 +----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/include/extern.h b/include/extern.h index 89f07f57a..b1b5901ae 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.852 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1594635320 2020/07/13 10:15:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.853 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1514,7 +1514,6 @@ E void NDECL(kill_genocided_monsters); E void FDECL(golemeffects, (struct monst *, int, int)); E boolean FDECL(angry_guards, (BOOLEAN_P)); E void NDECL(pacify_guards); -E struct monst *FDECL(find_ghost_with_name, (char *)); E void FDECL(decide_to_shapeshift, (struct monst *, int)); E boolean FDECL(vamp_stone, (struct monst *)); diff --git a/src/mon.c b/src/mon.c index 96b12736a..0c1604f3b 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mon.c $NHDT-Date: 1593306909 2020/06/28 01:15:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.338 $ */ +/* NetHack 3.6 mon.c $NHDT-Date: 1594635320 2020/07/13 10:15:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.339 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4322,22 +4322,6 @@ pacify_guards() } } -struct monst * -find_ghost_with_name(str) -char *str; -{ - struct monst *mtmp; - - for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { - if (DEADMONSTER(mtmp) - || mtmp->data != &mons[PM_GHOST] || !has_mname(mtmp)) - continue; - if (!strcmpi(MNAME(mtmp), str)) - return mtmp; - } - return (struct monst *) 0; -} - void mimic_hit_msg(mtmp, otyp) struct monst *mtmp; From 5a2c94f8e331622ebbdf4e50fab802fe2b7457da Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Mon, 13 Jul 2020 11:16:18 -0400 Subject: [PATCH 3/5] Rollback changes to NHDT-Date --- include/extern.h | 2 +- src/bones.c | 2 +- src/do.c | 2 +- src/mon.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/extern.h b/include/extern.h index b1b5901ae..663d42f65 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 extern.h $NHDT-Date: 1594635320 2020/07/13 10:15:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.853 $ */ +/* NetHack 3.6 extern.h $NHDT-Date: 1594168620 2020/07/08 00:37:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.851 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ diff --git a/src/bones.c b/src/bones.c index 357271a71..cb3c9e0a6 100644 --- a/src/bones.c +++ b/src/bones.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 bones.c $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.102 $ */ +/* NetHack 3.6 bones.c $NHDT-Date: 1593953344 2020/07/05 12:49:04 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.100 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985,1993. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ diff --git a/src/do.c b/src/do.c index e9fb19c85..c1601bbdd 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 do.c $NHDT-Date: 1594601903 2020/07/13 00:58:23 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.247 $ */ +/* NetHack 3.6 do.c $NHDT-Date: 1593953347 2020/07/05 12:49:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.246 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ diff --git a/src/mon.c b/src/mon.c index 0c1604f3b..0096f00dd 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mon.c $NHDT-Date: 1594635320 2020/07/13 10:15:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.339 $ */ +/* NetHack 3.6 mon.c $NHDT-Date: 1593306909 2020/06/28 01:15:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.338 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ From 61cc0e3d5182e723c7ce8acf2a27190579ceb311 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 22 Jul 2020 09:25:05 -0400 Subject: [PATCH 4/5] Formatting --- src/bones.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bones.c b/src/bones.c index cb3c9e0a6..c8ba12a14 100644 --- a/src/bones.c +++ b/src/bones.c @@ -664,15 +664,18 @@ bones_include_name(name) const char *name; { struct cemetery *bp; + int len; char buf[BUFSZ]; + /* prepare buffer by appending terminal hyphen to name, to avoid partial + * matches producing false positives */ Strcpy(buf, name); Strcat(buf, "-"); - int l = strlen(buf); + len = strlen(buf); if ((bp = g.level.bonesinfo)) { do { - if (!strncmp(bp->who, buf, l)) + if (!strncmp(bp->who, buf, len)) return TRUE; } while ((bp = bp->next) != (struct cemetery *) 0); } From 6ae78183464970ae754fcce0fe42053a724b2015 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 30 Dec 2020 22:42:48 -0500 Subject: [PATCH 5/5] Refactor bones search loop Using a for loop instead of an if and a do/while makes the code much more clear and concise, so that it's easier to understand what the function does at a glance. The actual approach to iterating through the current level's bones files and searching for a match is more or less unchanged. --- src/bones.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bones.c b/src/bones.c index e0b81ed3d..d497343f4 100644 --- a/src/bones.c +++ b/src/bones.c @@ -671,12 +671,11 @@ const char *name; Strcat(buf, "-"); len = strlen(buf); - if ((bp = g.level.bonesinfo)) { - do { - if (!strncmp(bp->who, buf, len)) - return TRUE; - } while ((bp = bp->next) != (struct cemetery *) 0); + for (bp = g.level.bonesinfo; bp; bp = bp->next) { + if (!strncmp(bp->who, buf, len)) + return TRUE; } + return FALSE; }