From: Pasi Kallinen Date: Sat, 22 Feb 2020 16:35:33 +0000 (+0200) Subject: Change lua selection floodfill and add some tests X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc70132da83f07d3c56e6e268b0a0ee438fd3733;p=nethack Change lua selection floodfill and add some tests --- diff --git a/dat/Rog-strt.lua b/dat/Rog-strt.lua index 769cb517f..b7e97e63a 100644 --- a/dat/Rog-strt.lua +++ b/dat/Rog-strt.lua @@ -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. diff --git a/dat/astral.lua b/dat/astral.lua index 546022320..62ea0ec16 100644 --- a/dat/astral.lua +++ b/dat/astral.lua @@ -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 diff --git a/dat/minetn-1.lua b/dat/minetn-1.lua index f4c5c85bc..fd1257c0e 100644 --- a/dat/minetn-1.lua +++ b/dat/minetn-1.lua @@ -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 diff --git a/src/nhlsel.c b/src/nhlsel.c index 237b75b50..a0ba7e627 100644 --- a/src/nhlsel.c +++ b/src/nhlsel.c @@ -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; } diff --git a/test/test_sel.lua b/test/test_sel.lua index b29482253..387c11260 100644 --- a/test/test_sel.lua +++ b/test/test_sel.lua @@ -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();