]> granicus.if.org Git - nethack/commitdiff
Fix: using a selection in a lit des.region modified it
authorcopperwater <aosdict@gmail.com>
Sun, 26 Feb 2023 22:46:47 +0000 (17:46 -0500)
committerPasi Kallinen <paxed@alt.org>
Wed, 1 Mar 2023 15:32:15 +0000 (17:32 +0200)
The intuitive behavior when passing a selection to des.region, e.g.

    local foo = selection.area(07,02,10,24)
    des.region(foo, "lit")

is that foo will remain unmodified for further use. However, this wasn't
the case whenever making a lit region from it, because in order to light
walls adjacent to the lit area, the selection was having a grow
transformation applied as well. (This also seems like a problem - it
grows the selection even if what is being lit is not surrounded by
walls. I added a note in lua.adoc about this behavior.)

This fixes the selection mutation by cloning the passed-in selection and
growing the clone which leaves the original one unaffected.

This should not affect any special levels currently because the only
instance of des.region being used with a selection appears to be in
bigrm-2, which specifies *unlit* areas, which did not get grown.

doc/lua.adoc
src/sp_lev.c

index 67ed82c7ec6c5b636e247c83024faf3fbdf4a327..5f447fe78230c75e24ae359a9d6e9de418576f9e 100644 (file)
@@ -838,6 +838,11 @@ Example:
 
 Create a room region, which can be irregular; use the boundary <<_map_characters,map character>> to restrict the floodfilled area.
 
+If using the first form with a selection and "lit", the lit area will extend
+outward 1 space from the selection to attempt to accomodate adjacent walls,
+regardless of whether they are actually walls or not. If using "unlit", this
+will not happen.
+
 Example:
 
  des.region(selection, lit);
index eecbf43d6eb3246b524387117e1a9ee2d99a6634..e88fc0a9bd9c7e5e633e0f3267dda436ab108808 100644 (file)
@@ -6061,12 +6061,12 @@ lspo_region(lua_State *L)
     } else if (argc == 2) {
         /* region(selection, "lit"); */
         static const char *const lits[] = { "unlit", "lit", NULL };
-        struct selectionvar *sel = l_selection_check(L, 1);
+        struct selectionvar *orig = l_selection_check(L, 1),
+                            *sel = selection_clone(orig);
 
         rlit = luaL_checkoption(L, 2, "lit", lits);
 
         /*
-    TODO: adjust region size for wall, but only if lit
     TODO: lit=random
         */
         if (rlit)