function hell_tweaks(protected_area)
local liquid = "L";
local ground = ".";
+ local n_prot = protected_area:numpoints();
local prot = protected_area:negate();
-- random pools
-- river
if (percent(50)) then
- local floor = selection.match(ground);
- local a = selection.rndcoord(floor);
- local b = selection.rndcoord(floor);
- local lavariver = selection.randline(selection.new(), a.x, a.y, b.x, b.y, 10);
-
- if (percent(50)) then
- lavariver = selection.grow(lavariver, "north");
- end
- if (percent(50)) then
- lavariver = selection.grow(lavariver, "west");
- end
- if (percent(25)) then
- local riverbanks = selection.grow(lavariver);
+ local allrivers = selection.new();
+ local reqpts = ((nhc.COLNO * nhc.ROWNO) - n_prot) / 12; -- # of lava pools required
+ local rpts = 0;
+ local rivertries = 0;
+
+ repeat
+ local floor = selection.match(ground);
+ local a = selection.rndcoord(floor);
+ local b = selection.rndcoord(floor);
+ local lavariver = selection.randline(selection.new(), a.x, a.y, b.x, b.y, 10);
+
+ if (percent(50)) then
+ lavariver = selection.grow(lavariver, "north");
+ end
+ if (percent(50)) then
+ lavariver = selection.grow(lavariver, "west");
+ end
+ allrivers = allrivers | lavariver;
+ allrivers = allrivers & prot;
+
+ rpts = allrivers:numpoints();
+ rivertries = rivertries + 1;
+ until ((rpts > reqpts) or (rivertries > 7));
+
+ if (percent(60)) then
+ local prc = 10 * math.random(1, 6);
+ local riverbanks = selection.grow(allrivers);
riverbanks = riverbanks & prot;
- des.terrain(selection.percentage(riverbanks, 50), ground);
+ des.terrain(selection.percentage(riverbanks, prc), ground);
end
- lavariver = lavariver & prot;
- des.terrain(lavariver, liquid);
+
+ des.terrain(allrivers, liquid);
end
-- replacing some walls with boulders
local s = selection.negate();
+=== numpoints
+
+Return the number of points in the selection.
+
+Example:
+
+ local n = sel:numpoints();
+
+
=== percentage
Each selected location has a percentage chance of being selected in the new selection.
/* lua_CFunction prototypes */
static int l_selection_new(lua_State *);
static int l_selection_clone(lua_State *);
+static int l_selection_numpoints(lua_State *);
static int l_selection_getpoint(lua_State *);
static int l_selection_setpoint(lua_State *);
static int l_selection_filter_percent(lua_State *);
return 1;
}
+/* local numpoints = selection.numpoints(sel); */
+static int
+l_selection_numpoints(lua_State *L)
+{
+ struct selectionvar *sel = l_selection_check(L, 1);
+ coordxy x, y;
+ int ret = 0;
+ NhRect rect;
+
+ selection_getbounds(sel, &rect);
+
+ for (x = rect.lx; x <= rect.hx; x++)
+ for (y = rect.ly; y <= rect.hy; y++)
+ if (selection_getpoint(x, y, sel))
+ ret++;
+
+ lua_settop(L, 0);
+ lua_pushinteger(L, ret);
+ return 1;
+}
+
/* local value = selection.get(sel, x, y); */
static int
l_selection_getpoint(lua_State *L)
{ "clone", l_selection_clone },
{ "get", l_selection_getpoint },
{ "set", l_selection_setpoint },
+ { "numpoints", l_selection_numpoints },
{ "negate", l_selection_not },
{ "percentage", l_selection_filter_percent },
{ "rndcoord", l_selection_rndcoord },
sel_are_equal(sela, selb, __func__);
end
+function test_sel_numpoints()
+ local __func__ = "test_sel_numpoints";
+ des.reset_level();
+ des.level_init({ style = "solidfill", fg = " " });
+
+ local sela = selection.new();
+ local npts = sela:numpoints();
+ if (npts ~= 0) then
+ error(string.format("numpoints reported %i, should have been 0", npts));
+ end
+
+ des.terrain(5,5, ".");
+
+ local selb = selection.match(".");
+ local npts = selb:numpoints();
+ if (npts ~= 1) then
+ error(string.format("numpoints reported %i, should have been 1", npts));
+ end
+
+ des.terrain(6,5, ".");
+
+ local selc = selection.match(".");
+ local npts = selc:numpoints();
+ if (npts ~= 2) then
+ error(string.format("numpoints reported %i, should have been 2", npts));
+ end
+end
+
nh.debug_flags({mongen = false, hunger = false, overwrite_stairs = true });
test_selection_params();
test_sel_negate();
test_sel_iterate();
test_sel_bounds();
test_sel_map();
+test_sel_numpoints();