From a30a45be4667cbd008cd8f1a0b07c69a851db211 Mon Sep 17 00:00:00 2001 From: copperwater Date: Tue, 22 Mar 2022 21:13:51 -0400 Subject: [PATCH] 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. --- src/nhlua.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/nhlua.c b/src/nhlua.c index ab5ccc694..dafee5753 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -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;