summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_dgnbld.cc
diff options
context:
space:
mode:
authorinfiniplex <infiniplex@hotmail.com>2013-04-28 15:30:39 -0600
committerPete Hurst <pete@streamuniverse.tv>2013-04-30 06:32:09 +0100
commitf10432ccc7b5552fff438090be9839c35268de3e (patch)
tree22c75a26e7f181128668d6168d712c25579f2b3e /crawl-ref/source/l_dgnbld.cc
parentc7ca69ad772d0bdc60fe9216316ea37a796c9245 (diff)
downloadcrawl-ref-f10432ccc7b5552fff438090be9839c35268de3e.tar.gz
crawl-ref-f10432ccc7b5552fff438090be9839c35268de3e.zip
Converted layout_des door-adding function to C++
Diffstat (limited to 'crawl-ref/source/l_dgnbld.cc')
-rw-r--r--crawl-ref/source/l_dgnbld.cc165
1 files changed, 165 insertions, 0 deletions
diff --git a/crawl-ref/source/l_dgnbld.cc b/crawl-ref/source/l_dgnbld.cc
index e2912afd87..96013d05d5 100644
--- a/crawl-ref/source/l_dgnbld.cc
+++ b/crawl-ref/source/l_dgnbld.cc
@@ -343,6 +343,102 @@ static vector<char> _pool_fill_glyphs_from_table(lua_State *ls,
return fill_glyphs;
}
+// These functions check for irregularities before the first
+// corner along a wall in the indicated direction.
+static bool _wall_is_empty_x_minus(map_lines &lines,
+ int x, int y,
+ const char* wall, const char* floor)
+{
+ for(int x1 = x; x1 >= 0; x1--)
+ {
+ if(!lines.in_bounds(coord_def(x1, y + 1))
+ || !strchr(floor, lines(x1, y + 1)))
+ {
+ return true;
+ }
+ if(!lines.in_bounds(coord_def(x1, y - 1))
+ || !strchr(floor, lines(x1, y - 1)))
+ {
+ return true;
+ }
+
+ if(!strchr(wall, lines(x1, y)))
+ return false;
+ }
+
+ // hit the edge of the map, so this is good
+ return true;
+}
+
+static bool _wall_is_empty_x_plus(map_lines &lines,
+ int x, int y,
+ const char* wall, const char* floor)
+{
+ for(int x1 = x; x1 < lines.width(); x1++)
+ {
+ if(!lines.in_bounds(coord_def(x1, y + 1))
+ || !strchr(floor, lines(x1, y + 1)))
+ {
+ return true;
+ }
+ if(!lines.in_bounds(coord_def(x1, y - 1))
+ || !strchr(floor, lines(x1, y - 1)))
+ {
+ return true;
+ }
+
+ if(!strchr(wall, lines(x1, y)))
+ return false;
+ }
+ return true;
+}
+
+static bool _wall_is_empty_y_minus(map_lines &lines,
+ int x, int y,
+ const char* wall, const char* floor)
+{
+ for(int y1 = y; y1 >= 0; y1--)
+ {
+ if(!lines.in_bounds(coord_def(x + 1, y1))
+ || !strchr(floor, lines(x + 1, y1)))
+ {
+ return true;
+ }
+ if(!lines.in_bounds(coord_def(x - 1, y1))
+ || !strchr(floor, lines(x - 1, y1)))
+ {
+ return true;
+ }
+
+ if(!strchr(wall, lines(x, y1)))
+ return false;
+ }
+ return true;
+}
+
+static bool _wall_is_empty_y_plus(map_lines &lines,
+ int x, int y,
+ const char* wall, const char* floor)
+{
+ for(int y1 = y; y1 < lines.height(); y1++)
+ {
+ if(!lines.in_bounds(coord_def(x + 1, y1))
+ || !strchr(floor, lines(x + 1, y1)))
+ {
+ return true;
+ }
+ if(!lines.in_bounds(coord_def(x - 1, y1))
+ || !strchr(floor, lines(x - 1, y1)))
+ {
+ return true;
+ }
+
+ if(!strchr(wall, lines(x, y1)))
+ return false;
+ }
+ return true;
+}
+
LUAFN(dgn_count_feature_in_box)
{
@@ -994,6 +1090,74 @@ LUAFN(dgn_connect_adjacent_rooms)
return 0;
}
+LUAFN(dgn_connect_adjacent_rooms2)
+{
+ LINES(ls, 1, lines);
+
+ TABLE_STR(ls, wall, "x");
+ TABLE_STR(ls, floor, ".");
+ TABLE_CHAR(ls, replace, '.');
+ TABLE_INT(ls, max, 1);
+ TABLE_INT(ls, min, max);
+
+ int x1, y1, x2, y2;
+ if (!_coords(ls, lines, x1, y1, x2, y2))
+ return 0;
+
+ // we never go right up to the border to avoid looking off the map edge
+ if(x1 < 1)
+ x1 = 1;
+ if(x2 >= lines.width() - 1)
+ x2 = lines.width() - 2;
+ if(y1 < 1)
+ y1 = 1;
+ if(y2 >= lines.height() - 1)
+ y2 = lines.height() - 2;
+
+ if (min < 0)
+ return luaL_error(ls, "Invalid min connections: %i", min);
+ if (max < min)
+ {
+ return luaL_error(ls, "Invalid max connections: %i (min is %i)",
+ max, min);
+ }
+
+ int count = min + random2(max - min + 1);
+ for (random_rectangle_iterator ri(coord_def(x1, y1),
+ coord_def(x2, y2)); ri; ++ri)
+ {
+ if(count <= 0)
+ {
+ // stop when have checked enough spots
+ return 0;
+ }
+
+ int x = ri->x;
+ int y = ri->y;
+
+ if (strchr(wall, lines(*ri)))
+ {
+ if ( strchr(floor, lines(x, y - 1))
+ && strchr(floor, lines(x, y + 1))
+ && _wall_is_empty_x_plus (lines, x, y, wall, floor)
+ && _wall_is_empty_x_minus(lines, x, y, wall, floor))
+ {
+ lines(*ri) = replace;
+ }
+ else if ( strchr(floor, lines(x - 1, y))
+ && strchr(floor, lines(x + 1, y))
+ && _wall_is_empty_y_plus (lines, x, y, wall, floor)
+ && _wall_is_empty_y_minus(lines, x, y, wall, floor))
+ {
+ lines(*ri) = replace;
+ }
+ }
+ count--;
+ }
+
+ return 0;
+}
+
LUAFN(dgn_replace_area)
{
LINES(ls, 1, lines);
@@ -1570,6 +1734,7 @@ const struct luaL_reg dgn_build_dlib[] =
{ "remove_isolated_glyphs", &dgn_remove_isolated_glyphs },
{ "widen_paths", &dgn_widen_paths },
{ "connect_adjacent_rooms", &dgn_connect_adjacent_rooms },
+ { "connect_adjacent_rooms2", &dgn_connect_adjacent_rooms2 },
{ "replace_area", &dgn_replace_area },
{ "replace_first", &dgn_replace_first },
{ "replace_random", &dgn_replace_random },