* end of no 'g.'
*/
+/* Does typ match with levl[][].typ, considering special types
+ MATCH_WALL and MAX_TYPE (aka transparency)? */
+boolean
+match_maptyps(typ, levltyp)
+xchar typ, levltyp;
+{
+ if ((typ == MATCH_WALL) && !IS_STWALL(levltyp))
+ return FALSE;
+ if ((typ < MAX_TYPE) && (typ != levltyp))
+ return FALSE;
+ return TRUE;
+}
+
struct mapfragment *
mapfrag_fromstr(str)
char *str;
for (ry = -(mf->hei / 2); ry <= (mf->hei / 2); ry++) {
schar mapc = mapfrag_get(mf, rx + (mf->wid / 2) , ry + (mf->hei / 2));
schar levc = isok(x+rx, y+ry) ? levl[x+rx][y+ry].typ : STONE;
- if ((mapc < MAX_TYPE) && (mapc != levc))
+ if (!match_maptyps(mapc, levc))
return FALSE;
}
return TRUE;
for (x = 0; x < ret->wid; x++)
for (y = 0; y < ret->hei; y++)
- if (selection_getpoint(x, y, ov) && (levl[x][y].typ == typ)) {
+ if (selection_getpoint(x, y, ov) && match_maptyps(typ, levl[x][y].typ)) {
switch (lit) {
default:
case -2:
free(tmpstr);
if ((err = mapfrag_error(mf)) != NULL) {
- mapfrag_free(&mf);
nhl_error(L, err);
/*NOTREACHED*/
}
sel_has_n_points(selb, 2, __func__);
sel_pt_ne(selb, 5,5, 1, __func__);
sel_pt_ne(selb, 15,10, 1, __func__);
+
+ des.reset_level();
+ des.level_init({ style = "solidfill", fg = " " });
+ des.replace_terrain({ selection=sela, fromterrain=" ", toterrain="-", chance=50 });
+ des.replace_terrain({ selection=sela, fromterrain=" ", toterrain="|", chance=50 });
+
+ -- test filtering by "w" (match any solid wall)
+ local seld = sela:filter_mapchar("w");
+ sel_has_n_points(seld, 1659, __func__);
end -- test_sel_filter_mapchar
function test_sel_flood()
end -- test_sel_flood
function test_sel_match()
- local sel = selection.match([[...]]);
+ local __func__ = "test_sel_match";
+ des.reset_level();
+ des.level_init({ style = "solidfill", fg = " " });
+
+ -- test horizontal map fragment
+ des.terrain(5,5, ".");
+ des.terrain(6,5, ".");
+ des.terrain(7,5, ".");
+ local sela = selection.match([[...]]);
+ sel_has_n_points(sela, 1, __func__);
+ sel_pt_ne(sela, 6,5, 1, __func__);
+
+ -- test vertical map fragment
+ local mapfragv = " \n.\n ";
+ local selb = selection.match(mapfragv);
+ 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__);
+
+ -- test matching with "w" to match any wall
+ des.terrain(5,4, "-");
+ des.terrain(6,6, "|");
+ local mapfragv = "w\n.\nw";
+ local selc = selection.match(mapfragv);
+ sel_has_n_points(selc, 3, __func__);
+ sel_pt_ne(selc, 5,5, 1, __func__);
+ sel_pt_ne(selc, 6,5, 1, __func__);
+ sel_pt_ne(selc, 7,5, 1, __func__);
+
+ -- test a 3x3 map fragment
+ local mapfrag = "www\n...\nwww";
+ local seld = selection.match(mapfrag);
+ sel_has_n_points(seld, 1, __func__);
+ sel_pt_ne(seld, 6,5, 1, __func__);
end -- test_sel_match
test_selection_params();