summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/dat/clua/dungeon.lua11
-rw-r--r--crawl-ref/source/dungeon.h37
-rw-r--r--crawl-ref/source/luadgn.cc42
-rw-r--r--crawl-ref/source/mapdef.cc2
-rw-r--r--crawl-ref/source/spells2.cc2
5 files changed, 79 insertions, 15 deletions
diff --git a/crawl-ref/source/dat/clua/dungeon.lua b/crawl-ref/source/dat/clua/dungeon.lua
index d26bba984b..281e181931 100644
--- a/crawl-ref/source/dat/clua/dungeon.lua
+++ b/crawl-ref/source/dat/clua/dungeon.lua
@@ -77,6 +77,15 @@ function dgn.places_connected(map, map_glyph, test_connect, ...)
return test_connect(map, unpack(points))
end
+function dgn.any_glyph_connected(map, ...)
+ return dgn.places_connected(map, dgn.gly_points,
+ dgn.any_point_connected, ...)
+end
+
+function dgn.has_exit_from_glyph(map, glyph)
+ return dgn.places_connected(map, dgn.gly_point, dgn.has_exit_from, glyph)
+end
+
function dgn.glyphs_connected(map, ...)
return dgn.places_connected(map, dgn.gly_point, dgn.points_connected, ...)
end
@@ -101,4 +110,4 @@ end
function dgn.orig_gly_points(map, glyph)
return dgn.orig_fn(map, dgn.gly_points, glyph)
-end \ No newline at end of file
+end
diff --git a/crawl-ref/source/dungeon.h b/crawl-ref/source/dungeon.h
index 04f013b655..1ba0aaf3df 100644
--- a/crawl-ref/source/dungeon.h
+++ b/crawl-ref/source/dungeon.h
@@ -111,13 +111,15 @@ public:
void add_point(const coord_def &pos);
coord_def find_first_from(const coord_def &c, const dgn_region_list &vlts);
bool points_connected_from(const coord_def &start);
+ bool any_point_connected_from(const coord_def &start);
+ bool has_exit_from(const coord_def &start);
bool did_leave_vault() const { return left_vault; }
protected:
bool path_flood(const coord_def &c, const coord_def &dc);
protected:
- bool point_hunt;
+ bool point_hunt, want_exit;
bool needed_features[NUM_FEATURES];
std::vector<coord_def> needed_points;
bool left_vault;
@@ -129,8 +131,8 @@ protected:
template <typename fgrd, typename bound_check>
flood_find<fgrd, bound_check>::flood_find(const fgrd &f, const bound_check &bc)
- : travel_pathfind(), point_hunt(false), needed_features(),
- needed_points(), left_vault(true), vaults(),
+ : travel_pathfind(), point_hunt(false), want_exit(false),
+ needed_features(), needed_points(), left_vault(true), vaults(),
fgrid(f), bcheck(bc)
{
memset(needed_features, false, sizeof needed_features);
@@ -172,12 +174,41 @@ bool flood_find<fgrd, bound_check>::points_connected_from(
}
template <typename fgrd, typename bound_check>
+bool flood_find<fgrd, bound_check>::any_point_connected_from(
+ const coord_def &sp)
+{
+ if (needed_points.empty())
+ return (true);
+ set_floodseed(sp);
+ const size_t sz = needed_points.size();
+ pathfind(RMODE_EXPLORE);
+ return (needed_points.size() < sz);
+}
+
+template <typename fgrd, typename bound_check>
+bool flood_find<fgrd, bound_check>::has_exit_from(
+ const coord_def &sp)
+{
+ want_exit = true;
+ set_floodseed(sp);
+ return (pathfind(RMODE_EXPLORE) == coord_def(-1, -1));
+}
+
+template <typename fgrd, typename bound_check>
bool flood_find<fgrd, bound_check>::path_flood(
const coord_def &c,
const coord_def &dc)
{
if (!bcheck(dc))
+ {
+ if (want_exit)
+ {
+ greedy_dist = 100;
+ greedy_place = coord_def(-1, -1);
+ return (true);
+ }
return (false);
+ }
if (!needed_points.empty())
{
diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc
index ba8fb5fa98..65bc150799 100644
--- a/crawl-ref/source/luadgn.cc
+++ b/crawl-ref/source/luadgn.cc
@@ -647,19 +647,24 @@ static int dgn_grid(lua_State *ls)
PLUARET(number, grd[x][y]);
}
-static int dgn_points_connected(lua_State *ls)
+typedef
+flood_find<map_def::map_feature_finder, map_def::map_bounds_check>
+map_flood_finder;
+
+static int dgn_map_pathfind(lua_State *ls, int minargs,
+ bool (map_flood_finder::*f)(const coord_def &))
{
MAP(ls, 1, map);
const int nargs = lua_gettop(ls);
- if (nargs < 5)
- return luaL_error(ls,
- "Not enough points to test connectedness "
- "(need at least two)");
+ if (nargs < minargs)
+ return luaL_error
+ (ls,
+ make_stringf("Not enough points to test connectedness "
+ "(need at least %d)", minargs / 2).c_str());
map_def::map_feature_finder feat_finder(*map);
map_def::map_bounds_check bounds_checker(*map);
- flood_find<map_def::map_feature_finder, map_def::map_bounds_check>
- finder(feat_finder, bounds_checker);
+ map_flood_finder finder(feat_finder, bounds_checker);
for (int i = 4; i < nargs; i += 2)
{
@@ -669,8 +674,22 @@ static int dgn_points_connected(lua_State *ls)
}
const coord_def pos(luaL_checkint(ls, 2), luaL_checkint(ls, 3));
- const bool connected = finder.points_connected_from(pos);
- PLUARET(boolean, connected);
+ PLUARET(boolean, (finder.*f)(pos));
+}
+
+static int dgn_points_connected(lua_State *ls)
+{
+ return dgn_map_pathfind(ls, 5, &map_flood_finder::points_connected_from);
+}
+
+static int dgn_any_point_connected(lua_State *ls)
+{
+ return dgn_map_pathfind(ls, 5, &map_flood_finder::any_point_connected_from);
+}
+
+static int dgn_has_exit_from(lua_State *ls)
+{
+ return dgn_map_pathfind(ls, 3, &map_flood_finder::has_exit_from);
}
static void dlua_push_coord(lua_State *ls, const coord_def &c)
@@ -734,6 +753,8 @@ static const struct luaL_reg dgn_lib[] =
{ "kmons", dgn_kmons },
{ "grid", dgn_grid },
{ "points_connected", dgn_points_connected },
+ { "any_point_connected", dgn_any_point_connected },
+ { "has_exit_from", dgn_has_exit_from },
{ "gly_point", dgn_gly_point },
{ "gly_points", dgn_gly_points },
{ "original_map", dgn_original_map },
@@ -757,6 +778,9 @@ void init_dungeon_lua()
// Add additional function to the Crawl module.
luaL_openlib(dlua, "crawl", crawl_lib, 0);
dlua.execfile("clua/dungeon.lua", true, true);
+ if (!dlua.error.empty())
+ end(1, false, "Lua error: %s", dlua.error.c_str());
+ lua_getglobal(dlua, "dgn_run_map");
luaopen_debug(dlua);
luaL_newmetatable(dlua, MAP_METATABLE);
lua_settop(dlua, 1);
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc
index 857e93af08..49450734fc 100644
--- a/crawl-ref/source/mapdef.cc
+++ b/crawl-ref/source/mapdef.cc
@@ -1075,7 +1075,7 @@ std::string map_def::validate_map_def()
std::string err = run_lua(true);
if (!err.empty())
return (err);
-
+
if (orient == MAP_FLOAT || is_minivault())
{
if (map.width() > GXM - MAPGEN_BORDER * 2
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index 6846b37892..3a1b4a09c8 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -1312,7 +1312,7 @@ void summon_animals(int pow)
int power_left = pow + 1;
const bool varied = coinflip();
- monster_type mon_chosen;
+ monster_type mon_chosen = MONS_PROGRAM_BUG;
while ( power_left >= 0 && num_so_far < 8 )
{