From f8ec9dc32e50490b247d9995dc9882bf253f40c2 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 21 Sep 2022 19:41:45 -0400 Subject: [PATCH] Fix: antigravity trap doors 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 | 2 +- src/restore.c | 5 +++++ src/save.c | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/patchlevel.h b/include/patchlevel.h index 7f9f6fd33..2174c1ddf 100644 --- a/include/patchlevel.h +++ b/include/patchlevel.h @@ -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. diff --git a/src/restore.c b/src/restore.c index 1d1ed6ccc..d864864b5 100644 --- a/src/restore.c +++ b/src/restore.c @@ -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 diff --git a/src/save.c b/src/save.c index 4d3784386..2f09079db 100644 --- a/src/save.c +++ b/src/save.c @@ -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;