]> granicus.if.org Git - nethack/commitdiff
Fix: antigravity trap doors
authorMichael Meyer <me@entrez.cc>
Wed, 21 Sep 2022 23:41:45 +0000 (19:41 -0400)
committerPasi Kallinen <paxed@alt.org>
Thu, 22 Sep 2022 08:36:47 +0000 (11:36 +0300)
Trap doors saved their destinations as an absolute level, rather than a
relative one, so if you loaded bones from a special level their
destinations would reflect the dungeon layout from the bones player's
game.  For example, die on the Oracle level, on dlvl5, with a trap door
that goes to dlvl6.  Another player gets those bones on their Oracle
level, which is dlvl8... the trap door would still go to dlvl6.  Pretty
amazing trap door -- something you might see in a funhouse!

Include relative rather than absolute destinations in save and bones
files, much like stairs do, to avoid this problem.

I bumped EDITLEVEL because although this won't break save files in an
obvious way, it will interpret the (absolute) destinations in existing
save and bones files as relative, leading to some crazy long falls. :)

include/patchlevel.h
src/restore.c
src/save.c

index 7f9f6fd333761a7b8e26660554a7bc1f81ddcd1d..2174c1ddfc72b234663dfc03773bc035769971a4 100644 (file)
@@ -17,7 +17,7 @@
  * Incrementing EDITLEVEL can be used to force invalidation of old bones
  * and save files.
  */
-#define EDITLEVEL 64
+#define EDITLEVEL 65
 
 /*
  * Development status possibilities.
index 1d1ed6cccb0abfbb8a5db299676c3c4484766bec..d864864b5b34b937891dd7ef0a37b29390726543 100644 (file)
@@ -1093,6 +1093,11 @@ getlev(NHFILE* nhfp, int pid, xint8 lev)
         if (nhfp->structlevel)
             mread(nhfp->fd, (genericptr_t)trap, sizeof(struct trap));
         if (trap->tx != 0) {
+            if (g.program_state.restoring != REST_GSTATE
+                && trap->dst.dnum == u.uz.dnum) {
+                /* convert relative destination to absolute */
+                trap->dst.dlevel += u.uz.dlevel;
+            }
             trap->ntrap = g.ftrap;
             g.ftrap = trap;
         } else
index 4d378438659ba39b307bdeebf8f5b7f51d934b0b..2f09079dbca8bdbb487cc1ed8e575cb8ff89b714 100644 (file)
@@ -985,11 +985,17 @@ savetrapchn(NHFILE* nhfp, register struct trap* trap)
     register struct trap *trap2;
 
     while (trap) {
+        boolean use_relative = (g.program_state.restoring != REST_GSTATE
+                                && trap->dst.dnum == u.uz.dnum);
         trap2 = trap->ntrap;
+        if (use_relative)
+            trap->dst.dlevel -= u.uz.dlevel; /* make it relative */
         if (perform_bwrite(nhfp)) {
             if (nhfp->structlevel)
                 bwrite(nhfp->fd, (genericptr_t) trap, sizeof *trap);
         }
+        if (use_relative)
+            trap->dst.dlevel += u.uz.dlevel; /* reset back to absolute */
         if (release_data(nhfp))
             dealloc_trap(trap);
         trap = trap2;