From: copperwater Date: Sun, 26 Feb 2023 22:46:47 +0000 (-0500) Subject: Fix: using a selection in a lit des.region modified it X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69d37be878c77033f4f0e8fc7567edf3d9cef2f1;p=nethack Fix: using a selection in a lit des.region modified it 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. --- diff --git a/doc/lua.adoc b/doc/lua.adoc index 67ed82c7e..5f447fe78 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -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); diff --git a/src/sp_lev.c b/src/sp_lev.c index eecbf43d6..e88fc0a9b 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -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)