Change lua selection floodfill and add some tests

This commit is contained in:
Pasi Kallinen
2020-02-22 18:35:33 +02:00
parent fe3dae85d5
commit dc70132da8
5 changed files with 27 additions and 16 deletions

View 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.

View 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

View 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

View 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;
}

View 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();