From: copperwater Date: Wed, 6 Apr 2022 12:00:34 +0000 (-0400) Subject: Make sure xstart and ystart are always zero when not in_mklev X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99715e005fb45fe036041b7f7721068d421e0d1c;p=nethack Make sure xstart and ystart are always zero when not in_mklev 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.) --- diff --git a/src/mklev.c b/src/mklev.c index a0582e8e5..5e78777e7 100644 --- a/src/mklev.c +++ b/src/mklev.c @@ -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) */