nh.getmap() returns information relative to the most recent des.map

There are many possible use cases for nh.getmap during level creation,
but it's rendered mostly unusable by virtue of always returning data
about the exact x,y coordinate in g.level.locations. (In particular,
it can't currently be used in themed rooms at all, because the themed
room could be anywhere on the level.) This is inconsistent with how most
other coordinate-based functions work following a des.map, which use
coordinates relative to the 0,0 point of the map.

This changes it so that during level creation only, if nh.getmap is used
following a des.map statement, it will look up the coordinates relative
to the origin of the map, consistent with the other functions.
This commit is contained in:
copperwater
2022-03-22 21:13:51 -04:00
committed by Pasi Kallinen
parent 93842fbb1b
commit a30a45be46

View File

@@ -487,6 +487,20 @@ nhl_getmap(lua_State *L)
nhl_error(L, "Incorrect arguments");
return 0;
}
if (g.in_mklev) {
/* xstart and ystart are set by the des.map() command to give
* coordinates relative to the 0,0 of that map. It can be quite useful
* to check what terrain is on a given space. But without compensating
* for the change in xstart and ystart here, this will lead to results
* like des.terrain(4,6,'L') and then nh.getmap(4,6) not being lava.
*
* Only valid during mklev, because xstart and ystart are not saved
* with the level and can change during the level creating process when
* additional des.map() are executed. They will not necessarily be the
* same later. */
x += g.xstart;
y += g.ystart;
}
x = (coordxy) lx;
y = (coordxy) ly;