summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/debug.cc2
-rw-r--r--crawl-ref/source/dungeon.cc5
-rw-r--r--crawl-ref/source/luadgn.cc22
-rw-r--r--crawl-ref/source/maps.cc87
4 files changed, 74 insertions, 42 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index f25a886c18..7e70a2be39 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -4794,6 +4794,8 @@ static void _mapgen_report_available_random_vaults(FILE *outf)
mesclr();
mprf("Examining random maps at %s", i->describe().c_str());
mg_report_random_maps(outf, *i);
+ if (kbhit() && getch() == ESCAPE)
+ break;
fprintf(outf, "---------------------------------\n");
}
}
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 9f4160da0b..6ec32e4d3f 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -670,6 +670,7 @@ int process_disconnected_zones(int x1, int y1, int x2, int y2,
{
memset(travel_point_distance, 0, sizeof(travel_distance_grid_t));
int nzones = 0;
+ int ngood = 0;
for (int y = y1; y <= y2 ; ++y)
for (int x = x1; x <= x2; ++x)
{
@@ -691,7 +692,7 @@ int process_disconnected_zones(int x1, int y1, int x2, int y2,
// If we want only stairless zones, screen out zones that did
// have stairs.
if (choose_stairless && found_exit_stair)
- --nzones;
+ ++ngood;
else if (fill)
{
for (int fy = y1; fy <= y2 ; ++fy)
@@ -701,7 +702,7 @@ int process_disconnected_zones(int x1, int y1, int x2, int y2,
}
}
- return (nzones);
+ return (nzones - ngood);
}
static int _dgn_count_disconnected_zones(bool choose_stairless)
diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc
index 2d688d887c..4df7078a69 100644
--- a/crawl-ref/source/luadgn.cc
+++ b/crawl-ref/source/luadgn.cc
@@ -13,6 +13,7 @@
#include <cmath>
#include "branch.h"
+#include "chardump.h"
#include "clua.h"
#include "cloud.h"
#include "directn.h"
@@ -1727,10 +1728,11 @@ static dungeon_feature_type _get_lua_feature(lua_State *ls, int idx)
return feat;
}
-static void _clamp_to_bounds(int &x, int &y)
+static void _clamp_to_bounds(int &x, int &y, bool edge_ok = false)
{
- x = std::min(std::max(x, X_BOUND_1+1), X_BOUND_2-1);
- y = std::min(std::max(y, Y_BOUND_1+1), Y_BOUND_2-1);
+ const int edge_offset = edge_ok ? 0 : 1;
+ x = std::min(std::max(x, X_BOUND_1 + edge_offset), X_BOUND_2 - edge_offset);
+ y = std::min(std::max(y, Y_BOUND_1 + edge_offset), Y_BOUND_2 - edge_offset);
}
static int dgn_fill_area(lua_State *ls)
@@ -2017,8 +2019,8 @@ static int dgn_smear_feature(lua_State *ls)
int x2 = luaL_checkint(ls, 6);
int y2 = luaL_checkint(ls, 7);
- _clamp_to_bounds(x1, y1);
- _clamp_to_bounds(x2, y2);
+ _clamp_to_bounds(x1, y1, true);
+ _clamp_to_bounds(x2, y2, true);
smear_feature(iterations, boxy, feat, x1, y1, x2, y2);
@@ -2115,6 +2117,14 @@ static int dgn_fill_disconnected_zones(lua_State *ls)
return 0;
}
+static int dgn_debug_dump_map(lua_State *ls)
+{
+ const int pos = lua_isuserdata(ls, 1) ? 2 : 1;
+ if (lua_isstring(ls, pos))
+ dump_map(lua_tostring(ls, pos), true);
+ return (0);
+}
+
static const struct luaL_reg dgn_lib[] =
{
{ "default_depth", dgn_default_depth },
@@ -2201,6 +2211,8 @@ static const struct luaL_reg dgn_lib[] =
{ "join_the_dots", dgn_join_the_dots },
{ "fill_disconnected_zones", dgn_fill_disconnected_zones },
+ { "debug_dump_map", dgn_debug_dump_map },
+
{ NULL, NULL }
};
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index f2c5827afb..e0b0909c44 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -486,16 +486,29 @@ static std::string _vault_chance_tag(const map_def &map)
return ("");
}
-static int _random_map_by_selector(const map_selector &sel)
+typedef std::vector<unsigned> vault_indices;
+
+static vault_indices _eligible_maps_for_selector(const map_selector &sel)
{
- if (!sel.valid())
- return (-1);
+ vault_indices eligible;
+
+ if (sel.valid())
+ {
+ for (unsigned i = 0, size = vdefs.size(); i < size; ++i)
+ if (sel.accept(vdefs[i]))
+ eligible.push_back(i);
+ }
+
+ return (eligible);
+}
+static int _random_map_by_selector(const map_selector &sel);
+static int _random_map_in_list(const map_selector &sel,
+ const vault_indices &filtered)
+{
int mapindex = -1;
int rollsize = 0;
- typedef std::vector<unsigned> vault_indices;
-
// First build a list of vaults that could be used:
vault_indices eligible;
@@ -505,30 +518,30 @@ static int _random_map_by_selector(const map_selector &sel)
typedef std::set<std::string> tag_set;
tag_set chance_tags;
- for (unsigned i = 0, size = vdefs.size(); i < size; ++i)
- if (sel.accept(vdefs[i]))
+ for (unsigned f = 0, size = filtered.size(); f < size; ++f)
+ {
+ const int i = filtered[f];
+ if (!sel.ignore_chance && vdefs[i].chance > 0)
{
- if (!sel.ignore_chance && vdefs[i].chance > 0)
+ // There may be several alternatives for a portal
+ // vault that want to be governed by one common
+ // CHANCE. In this case each vault will use a
+ // CHANCE, and a common chance_xxx tag. Pick the
+ // first such vault for the chance roll. Note that
+ // at this point we ignore chance_priority.
+ const std::string tag = _vault_chance_tag(vdefs[i]);
+ if (chance_tags.find(tag) == chance_tags.end())
{
- // There may be several alternatives for a portal
- // vault that want to be governed by one common
- // CHANCE. In this case each vault will use a
- // CHANCE, and a common chance_xxx tag. Pick the
- // first such vault for the chance roll. Note that
- // at this point we ignore chance_priority.
- const std::string tag = _vault_chance_tag(vdefs[i]);
- if (chance_tags.find(tag) == chance_tags.end())
- {
- if (!tag.empty())
- chance_tags.insert(tag);
- chance.push_back(i);
- }
- }
- else
- {
- eligible.push_back(i);
+ if (!tag.empty())
+ chance_tags.insert(tag);
+ chance.push_back(i);
}
}
+ else
+ {
+ eligible.push_back(i);
+ }
+ }
// Sort chances by priority, high priority first.
std::sort(chance.begin(), chance.end(), _compare_vault_chance_priority);
@@ -580,6 +593,12 @@ static int _random_map_by_selector(const map_selector &sel)
return (mapindex);
}
+static int _random_map_by_selector(const map_selector &sel)
+{
+ const vault_indices filtered = _eligible_maps_for_selector(sel);
+ return _random_map_in_list(sel, filtered);
+}
+
// Returns a map for which PLACE: matches the given place.
int random_map_for_place(const level_id &place, bool want_minivault)
{
@@ -885,14 +904,6 @@ void run_map_preludes()
typedef std::pair<std::string, int> weighted_map_name;
typedef std::vector<weighted_map_name> weighted_map_names;
-static int _mg_random_vault_here(const level_id &place, bool mini)
-{
- no_messages mx;
- map_selector sel = map_selector::by_depth(place, mini);
- sel.preserve_dummy = true;
- return _random_map_by_selector(sel);
-}
-
static weighted_map_names mg_find_random_vaults(
const level_id &place, bool wantmini)
{
@@ -905,9 +916,15 @@ static weighted_map_names mg_find_random_vaults(
map_count_t map_counts;
+ map_selector sel = map_selector::by_depth(place, wantmini);
+ sel.preserve_dummy = true;
+
+ no_messages mx;
+ vault_indices filtered = _eligible_maps_for_selector(sel);
+
for (int i = 0; i < 10000; ++i)
{
- const int v = _mg_random_vault_here(place, wantmini);
+ const int v = _random_map_in_list(sel, filtered);
if (v == -1)
map_counts["(none)"]++;
else
@@ -943,7 +960,7 @@ static void mg_report_random_vaults(
for (int i = 0, size = wms.size(); i < size; ++i)
{
std::string curr =
- make_stringf("%s (%.4f%%)",
+ make_stringf("%s (%.2f%%)",
wms[i].first.c_str(),
100.0 * wms[i].second / weightsum);
if (i < size - 1)