]> granicus.if.org Git - nethack/commitdiff
Make sure xstart and ystart are always zero when not in_mklev
authorcopperwater <aosdict@gmail.com>
Wed, 6 Apr 2022 12:00:34 +0000 (08:00 -0400)
committerPatR <rankin@nethack.org>
Fri, 8 Apr 2022 17:05:43 +0000 (10:05 -0700)
Running #wizloadlua to run Lua scripts that use coordinates in any way
would work differently if you were on certain levels for the first time
versus leaving and returning to them. This is because various bits of
level creation routines can leave xstart and ystart set to non-zero
values, which are then zeroed at some point when leaving and returning
to the level.

Since xstart and ystart are only relevant to level creation and lua
commands, this fixes the problem by zeroing them after leaving mklev
routines. (Saving them with the level doesn't work because xstart and
ystart are relative to the last used des.map, of which there could be
multiple, e.g. in Asmodeus's level or if two map-based themed rooms
happen to generate. I can envision a more complex solution in which
every des.map used in the level can be associated with an identifier,
whose xstart and ystart are saved for use by later post-level-creation
lua scripts, but currently I just want to make them consistent between
level visits.)

src/mklev.c

index a0582e8e5f4cfa6b66f9d888a8058b3f74769e53..5e78777e7eef41d4582f8104ac2a1be965fc0c4c 100644 (file)
@@ -1093,6 +1093,10 @@ level_finalize_topology(void)
     bound_digging();
     mineralize(-1, -1, -1, -1, FALSE);
     g.in_mklev = FALSE;
+    /* avoid coordinates in future lua-loads for this level being thrown off
+     * because xstart and ystart aren't saved with the level and will be 0 after
+     * leaving and returning */
+    g.xstart = g.ystart = 0;
     /* has_morgue gets cleared once morgue is entered; graveyard stays
        set (graveyard might already be set even when has_morgue is clear
        [see fixup_special()], so don't update it unconditionally) */