summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_dgnbld.cc
diff options
context:
space:
mode:
authorJude Brown <bookofjude@users.sourceforge.net>2010-01-12 12:09:46 +1000
committerJude Brown <bookofjude@users.sourceforge.net>2010-01-12 13:35:39 +1000
commitacabbaacbc91db8c6b711b85e1f68694b42ed829 (patch)
tree63053744baefd88d2d5b2d7d002234f6571f20c3 /crawl-ref/source/l_dgnbld.cc
parentaf50b39780da6717f5f9a597a66c0c97e01329e5 (diff)
downloadcrawl-ref-acabbaacbc91db8c6b711b85e1f68694b42ed829.tar.gz
crawl-ref-acabbaacbc91db8c6b711b85e1f68694b42ed829.zip
Some new Lua wrappers for dungeon building and ranges.
Introduces util.range(start, stop), returning an array consisting of the numeric values between start and stop inclusive. Also introduces "is_valid_coord" Lua wrapper, which does the same work as _valid_coord but does not generate an error message for invalid coordinates, "find_in_area" (a straight translation of the function in dungeon.cc), and "is_passable_coord" which checks the glyph at that location against traversable_glyphs.
Diffstat (limited to 'crawl-ref/source/l_dgnbld.cc')
-rw-r--r--crawl-ref/source/l_dgnbld.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/crawl-ref/source/l_dgnbld.cc b/crawl-ref/source/l_dgnbld.cc
index 354ba4dad7..218facc9bf 100644
--- a/crawl-ref/source/l_dgnbld.cc
+++ b/crawl-ref/source/l_dgnbld.cc
@@ -190,6 +190,29 @@ LUAFN(dgn_count_neighbors)
PLUARET(number, lines.count_feature_in_box(tl, br, feat));
}
+LUAFN(dgn_is_valid_coord)
+{
+ LINES(ls, 1, lines);
+
+ TABLE_INT(ls, x, -1);
+ TABLE_INT(ls, y, -1);
+
+ if (x < 0 || x >= lines.width())
+ {
+ lua_pushboolean(ls, false);
+ return (1);
+ }
+
+ if (y < 0 || y >= lines.height())
+ {
+ lua_pushboolean(ls, false);
+ return (1);
+ }
+
+ lua_pushboolean(ls, true);
+ return (1);
+}
+
LUAFN(dgn_extend_map)
{
LINES(ls, 1, lines);
@@ -263,6 +286,53 @@ LUAFN(dgn_fill_disconnected)
return (0);
}
+LUAFN(dgn_is_passable_coord)
+{
+ LINES(ls, 1, lines);
+
+ TABLE_INT(ls, x, -1);
+ TABLE_INT(ls, y, -1);
+ TABLE_STR(ls, passable, traversable_glyphs);
+
+ if (!_valid_coord(ls, lines, x, y))
+ return (0);
+
+ if (strchr(passable, lines(x, y)))
+ lua_pushboolean(ls, true);
+ else
+ lua_pushboolean(ls, false);
+
+ return (1);
+}
+
+LUAFN(dgn_find_in_area)
+{
+ LINES(ls, 1, lines);
+
+ TABLE_INT(ls, x1, -1);
+ TABLE_INT(ls, y1, -1);
+ TABLE_INT(ls, x2, -1);
+ TABLE_INT(ls, y2, -1);
+
+ if (!_coords(ls, lines, x1, y1, x2, y2))
+ return (0);
+
+ TABLE_CHAR(ls, find, 'x');
+
+ int x, y;
+
+ for (x = x1; x <= x2; x++)
+ for (y = y1; y <= y2; y++)
+ if (lines(x, y) == find)
+ {
+ lua_pushboolean(ls, true);
+ return (1);
+ }
+
+ lua_pushboolean(ls, false);
+ return (1);
+}
+
LUAFN(dgn_height)
{
LINES(ls, 1, lines);
@@ -690,9 +760,12 @@ const struct luaL_reg dgn_build_dlib[] =
{ "count_feature_in_box", &dgn_count_feature_in_box },
{ "count_antifeature_in_box", &dgn_count_antifeature_in_box },
{ "count_neighbors", &dgn_count_neighbors },
+ { "is_valid_coord", &dgn_is_valid_coord },
+ { "is_passable_coord", &dgn_is_passable_coord },
{ "extend_map", &dgn_extend_map },
{ "fill_area", &dgn_fill_area },
{ "fill_disconnected", &dgn_fill_disconnected },
+ { "find_in_area", &dgn_find_in_area },
{ "height", dgn_height },
{ "join_the_dots", &dgn_join_the_dots },
{ "make_circle", &dgn_make_circle },