]> granicus.if.org Git - nethack/commitdiff
Change lua selection floodfill and add some tests
authorPasi Kallinen <paxed@alt.org>
Sat, 22 Feb 2020 16:35:33 +0000 (18:35 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 22 Feb 2020 16:35:41 +0000 (18:35 +0200)
dat/Rog-strt.lua
dat/astral.lua
dat/minetn-1.lua
src/nhlsel.c
test/test_sel.lua

index 769cb517fe37d35a9f2e3a94e99a4b93a5a718b1..b7e97e63a7d676c8f39240876c190c239350896d 100644 (file)
@@ -40,8 +40,7 @@ des.map([[
 -- Dungeon Description
 --REGION:(00,00,75,20),lit,"ordinary"
 
-local streets = selection.floodfill(selection.new(), 0,12)
-
+local streets = selection.floodfill(0,12)
 
 -- The down stairs is at one of the 4 "exits".  The others are mimics,
 -- mimicing stairwells.
index 546022320cfc356caeac9cbe66821af3b1548121..62ea0ec160e8c8eaba9a46b24f2334c894c64500 100644 (file)
@@ -39,7 +39,7 @@ for i=1,2 do
    -- 3.6.[01]: 75% chance that both sides opened up, 25% that neither did;
    -- 3.6.2: 60% twice == 36% chance that both sides open up, 24% left side
    -- only, 24% right side only, 16% that neither side opens up
-   local hall = selection.new()
+   local hall;
    if math.random(0, 99) < 60 then
      if i == 1 then
         des.terrain(selection.area(17,14, 30,18),".")
@@ -47,14 +47,14 @@ for i=1,2 do
         -- temporarily close off the area to be filled so that it doesn't cover
         -- the entire entry area
         des.terrain(33,18, "|")
-        hall:floodfill(30,16)
+        hall = selection.floodfill(30,16)
         -- re-connect the opened wing with the rest of the map
         des.terrain(33,18, ".")
      else
         des.terrain(selection.area(44,14, 57,18),".")
         des.wallify()
         des.terrain(41,18, "|")
-        hall:floodfill(44,16)
+        hall = selection.floodfill(44,16)
         des.terrain(41,18, ".")
      end
      -- extra monsters; was [6 + 3d4] when both wings were opened up at once
index f4c5c85bc4c1d13d23e8c17df7eefe9c5e862bb0..fd1257c0e4e79a12ed4bcebeacd78a75ab9f2c7c 100644 (file)
@@ -115,8 +115,8 @@ des.object({ id = "magic missile", coord = place[5], buc="uncursed", spe=0 })
 
 -- the Orcish Army
 
-local inside = selection.floodfill(selection.new(), 18,8)
-local near_temple = selection.area(selection.new(), 17,8, 23,14) & inside
+local inside = selection.floodfill(18,8)
+local near_temple = selection.area(17,8, 23,14) & inside
 
 for i=1,5 + math.random(1 - 1,1*10) do
    if math.random(0, 99) < 50 then
index 237b75b501d18f9d4673b0289c9ee66c99187b12..a0ba7e6271223282c0fdf80ac5dad883f74dea81 100644 (file)
@@ -568,7 +568,6 @@ lua_State *L;
 }
 
 
-/* local s = selection.floodfill(sel, x, y); */
 /* local s = selection.floodfill(x,y); */
 static int
 l_selection_flood(L)
@@ -578,11 +577,7 @@ lua_State *L;
     struct selectionvar *sel = (struct selectionvar *) 0;
     schar x, y;
 
-    if (argc == 3) {
-        sel = l_selection_check(L, 1);
-        x = (schar) luaL_checkinteger(L, 2);
-        y = (schar) luaL_checkinteger(L, 3);
-    } else if (argc == 2) {
+    if (argc == 2) {
         x = (schar) luaL_checkinteger(L, 1);
         y = (schar) luaL_checkinteger(L, 2);
         lua_pop(L, 2);
@@ -600,7 +595,6 @@ lua_State *L;
         set_floodfillchk_match_under(levl[x][y].typ);
         selection_floodfill(sel, x, y, FALSE);
     }
-    lua_settop(L, 1);
     return 1;
 }
 
index b29482253e57571efa51ab53fa8473d44e41c48f..387c112605d839d8f2811e966122b5c13236f75e 100644 (file)
@@ -70,7 +70,6 @@ function test_selection_params()
    sel:area(1,2, 7,8);
    sel:grow();
    sel:filter_mapchar(' ');
-   sel:floodfill(1,1);
    sel:circle(40, 10, 9);
    sel:circle(40, 10, 9, 1);
    sel:ellipse(40, 10, 20, 8);
@@ -89,7 +88,6 @@ function test_selection_params()
    selection.area(sel, 1,2, 7,8);
    selection.grow(sel);
    selection.filter_mapchar(sel, ' ');
-   selection.floodfill(sel, 1,1);
    selection.circle(sel, 40, 10, 9);
    selection.circle(sel, 40, 10, 9, 1);
    selection.ellipse(sel, 40, 10, 20, 8);
@@ -338,6 +336,25 @@ function test_sel_filter_mapchar()
    sel_pt_ne(selb, 15,10, 1, __func__);
 end -- test_sel_filter_mapchar
 
+function test_sel_flood()
+   local __func__ = "test_sel_flood";
+   local sela = selection.new();
+   local sela_clone = sela:clone();
+
+   des.terrain(selection.negate(), ".");
+   des.terrain(5,5, "L");
+   des.terrain(6,5, "L");
+   des.terrain(7,5, "L");
+   des.terrain(8,6, "L");
+
+   local selb = selection.floodfill(6,5);
+   sel_has_n_points(selb, 3, __func__);
+   sel_pt_ne(selb, 5,5, 1, __func__);
+   sel_pt_ne(selb, 6,5, 1, __func__);
+   sel_pt_ne(selb, 7,5, 1, __func__);
+
+end -- test_sel_flood
+
 test_selection_params();
 test_sel_negate();
 test_sel_logical_and();
@@ -350,3 +367,4 @@ test_sel_fillrect();
 test_sel_randline();
 test_sel_grow();
 test_sel_filter_mapchar();
+test_sel_flood();