summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-08-02 20:06:34 -0400
committerJesse Luehrs <doy@tozt.net>2014-08-02 20:10:40 -0400
commit4e1b44a4905cccd1a8509a91f9d10d7a06f956e7 (patch)
tree62b76b8e00325f1f7a96c646f10b5a5fe62919e6
parent756871af9b64cee576375e9ed5f73cf3cfa1b453 (diff)
downloadcrawl-ref-4e1b44a4905cccd1a8509a91f9d10d7a06f956e7.tar.gz
crawl-ref-4e1b44a4905cccd1a8509a91f9d10d7a06f956e7.zip
allow iterating over branches in a non-enum order (8742)
This allows us to have a consistent and logical ordering of branches without requiring the branch enum itself to be reordered (which could have save compatibility implications). The new ordering of branches just moves Depths to the place in the ordering that it already is planned to go on the next major save compat bump, but other changes are possible, if desired. All places in the code that iterate over branches have been updated to use the new iterator except for code dealing with save files, which still uses enum order, so that we can change the display ordering without affecting saves.
-rw-r--r--crawl-ref/source/abyss.cc8
-rw-r--r--crawl-ref/source/branch.cc94
-rw-r--r--crawl-ref/source/branch.h15
-rw-r--r--crawl-ref/source/command.cc9
-rw-r--r--crawl-ref/source/dbg-maps.cc20
-rw-r--r--crawl-ref/source/dbg-scan.cc8
-rw-r--r--crawl-ref/source/describe.cc12
-rw-r--r--crawl-ref/source/dgn-overview.cc71
-rw-r--r--crawl-ref/source/dungeon.cc56
-rw-r--r--crawl-ref/source/godabil.cc18
-rw-r--r--crawl-ref/source/l_you.cc12
-rw-r--r--crawl-ref/source/maps.cc4
-rw-r--r--crawl-ref/source/mon-pick.cc20
-rw-r--r--crawl-ref/source/mon-place.cc10
-rw-r--r--crawl-ref/source/ng-init.cc19
-rw-r--r--crawl-ref/source/place-info.cc4
-rw-r--r--crawl-ref/source/place.cc8
-rw-r--r--crawl-ref/source/player.cc14
-rw-r--r--crawl-ref/source/religion.cc4
-rw-r--r--crawl-ref/source/stairs.cc6
-rw-r--r--crawl-ref/source/travel.cc12
-rw-r--r--crawl-ref/source/wiz-dgn.cc12
22 files changed, 269 insertions, 167 deletions
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc
index e4b7dfc866..2d96fc22e0 100644
--- a/crawl-ref/source/abyss.cc
+++ b/crawl-ref/source/abyss.cc
@@ -969,13 +969,13 @@ static bool _in_wastes(const coord_def &p)
static level_id _get_random_level()
{
vector<level_id> levels;
- for (int i = BRANCH_DUNGEON; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (i == BRANCH_ABYSS || i == BRANCH_SHOALS)
+ if (it->id == BRANCH_ABYSS || it->id == BRANCH_SHOALS)
continue;
- for (int j = 1; j <= brdepth[i]; ++j)
+ for (int j = 1; j <= brdepth[it->id]; ++j)
{
- const level_id id(static_cast<branch_type>(i), j);
+ const level_id id(it->id, j);
if (is_existing_level(id))
levels.push_back(id);
}
diff --git a/crawl-ref/source/branch.cc b/crawl-ref/source/branch.cc
index d4477564a5..61bde7c82f 100644
--- a/crawl-ref/source/branch.cc
+++ b/crawl-ref/source/branch.cc
@@ -11,6 +11,87 @@ FixedVector<int, NUM_BRANCHES> brdepth;
FixedVector<int, NUM_BRANCHES> branch_bribe;
branch_type root_branch;
+branch_iterator::branch_iterator() :
+ i(BRANCH_DUNGEON)
+{
+}
+
+branch_iterator::operator bool() const
+{
+ return i < NUM_BRANCHES;
+}
+
+const Branch* branch_iterator::operator*() const
+{
+ static const branch_type branch_order[] = {
+ BRANCH_DUNGEON,
+ BRANCH_TEMPLE,
+ BRANCH_ORC,
+ BRANCH_ELF,
+#if TAG_MAJOR_VERSION == 34
+ BRANCH_DWARF,
+#endif
+ BRANCH_LAIR,
+ BRANCH_SWAMP,
+ BRANCH_SHOALS,
+ BRANCH_SNAKE,
+ BRANCH_SPIDER,
+ BRANCH_SLIME,
+ BRANCH_VAULTS,
+#if TAG_MAJOR_VERSION == 34
+ BRANCH_BLADE,
+#endif
+ BRANCH_CRYPT,
+ BRANCH_TOMB,
+ BRANCH_DEPTHS,
+ BRANCH_VESTIBULE,
+ BRANCH_DIS,
+ BRANCH_GEHENNA,
+ BRANCH_COCYTUS,
+ BRANCH_TARTARUS,
+ BRANCH_ZOT,
+#if TAG_MAJOR_VERSION == 34
+ BRANCH_FOREST,
+#endif
+ BRANCH_ABYSS,
+ BRANCH_PANDEMONIUM,
+ BRANCH_ZIGGURAT,
+ BRANCH_LABYRINTH,
+ BRANCH_BAZAAR,
+ BRANCH_TROVE,
+ BRANCH_SEWER,
+ BRANCH_OSSUARY,
+ BRANCH_BAILEY,
+ BRANCH_ICE_CAVE,
+ BRANCH_VOLCANO,
+ BRANCH_WIZLAB
+ };
+ COMPILE_CHECK(ARRAYSZ(branch_order) == NUM_BRANCHES);
+
+ if (i < NUM_BRANCHES)
+ return &branches[branch_order[i]];
+ else
+ return nullptr;
+}
+
+const Branch* branch_iterator::operator->() const
+{
+ return **this;
+}
+
+branch_iterator& branch_iterator::operator++()
+{
+ i++;
+ return *this;
+}
+
+branch_iterator branch_iterator::operator++(int)
+{
+ branch_iterator copy = *this;
+ ++(*this);
+ return copy;
+}
+
const Branch& your_branch()
{
return branches[you.where_are_you];
@@ -44,10 +125,15 @@ bool is_random_subbranch(branch_type branch)
|| branch == BRANCH_CRYPT;
}
+bool is_connected_branch(const Branch *branch)
+{
+ return !(branch->branch_flags & BFLAG_NO_XLEV_TRAVEL);
+}
+
bool is_connected_branch(branch_type branch)
{
ASSERT_RANGE(branch, 0, NUM_BRANCHES);
- return !(branches[branch].branch_flags & BFLAG_NO_XLEV_TRAVEL);
+ return is_connected_branch(&branches[branch]);
}
bool is_connected_branch(level_id place)
@@ -57,9 +143,9 @@ bool is_connected_branch(level_id place)
branch_type str_to_branch(const string &branch, branch_type err)
{
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (branches[i].abbrevname && branches[i].abbrevname == branch)
- return static_cast<branch_type>(i);
+ for (branch_iterator it; it; ++it)
+ if (it->abbrevname && it->abbrevname == branch)
+ return it->id;
return err;
}
diff --git a/crawl-ref/source/branch.h b/crawl-ref/source/branch.h
index 2c692ff43e..a77b092d92 100644
--- a/crawl-ref/source/branch.h
+++ b/crawl-ref/source/branch.h
@@ -44,6 +44,20 @@ struct Branch
int ambient_noise; // affects noise loudness and player stealth
};
+class branch_iterator {
+public:
+ branch_iterator();
+
+ operator bool() const;
+ const Branch* operator*() const;
+ const Branch* operator->() const;
+ branch_iterator& operator++();
+ branch_iterator operator++(int);
+
+protected:
+ int i;
+};
+
extern const Branch branches[NUM_BRANCHES];
extern FixedVector<level_id, NUM_BRANCHES> brentry;
extern FixedVector<int, NUM_BRANCHES> brdepth;
@@ -55,6 +69,7 @@ const Branch& your_branch();
bool at_branch_bottom();
bool is_hell_subbranch(branch_type branch);
bool is_random_subbranch(branch_type branch);
+bool is_connected_branch(const Branch *branch);
bool is_connected_branch(branch_type branch);
bool is_connected_branch(level_id place);
level_id current_level_parent();
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 590b17f9c6..11ee53a9f0 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -879,16 +879,13 @@ static vector<string> _get_branch_keys()
{
vector<string> names;
- for (int i = BRANCH_DUNGEON; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- branch_type which_branch = static_cast<branch_type>(i);
- const Branch &branch = branches[which_branch];
-
// Skip unimplemented branches
- if (branch_is_unfinished(which_branch))
+ if (branch_is_unfinished(it->id))
continue;
- names.push_back(branch.shortname);
+ names.push_back(it->shortname);
}
return names;
}
diff --git a/crawl-ref/source/dbg-maps.cc b/crawl-ref/source/dbg-maps.cc
index 44caa43edf..4f12c867c8 100644
--- a/crawl-ref/source/dbg-maps.cc
+++ b/crawl-ref/source/dbg-maps.cc
@@ -183,21 +183,20 @@ static void _dungeon_places()
{
generated_levels.clear();
branch_count = 0;
- for (int br = BRANCH_DUNGEON; br < NUM_BRANCHES; ++br)
+ for (branch_iterator it; it; ++it)
{
- if (brdepth[br] == -1)
+ if (brdepth[it->id] == -1)
continue;
#if TAG_MAJOR_VERSION == 34
// Don't want to include Forest since it doesn't generate
- if (br == BRANCH_FOREST)
+ if (it->id == BRANCH_FOREST)
continue;
#endif
bool new_branch = true;
- const branch_type branch = static_cast<branch_type>(br);
- for (int depth = 1; depth <= brdepth[br]; ++depth)
+ for (int depth = 1; depth <= brdepth[it->id]; ++depth)
{
- level_id l(branch, depth);
+ level_id l(it->id, depth);
if (SysEnv.map_gen_range.get() && !SysEnv.map_gen_range->is_usable_in(l))
continue;
generated_levels.push_back(l);
@@ -325,15 +324,14 @@ static void _write_map_stats()
}
vector<level_id> mapless;
- for (int i = BRANCH_DUNGEON; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (brdepth[i] == -1)
+ if (brdepth[it->id] == -1)
continue;
- const branch_type br = static_cast<branch_type>(i);
- for (int dep = 1; dep <= brdepth[i]; ++dep)
+ for (int dep = 1; dep <= brdepth[it->id]; ++dep)
{
- const level_id lid(br, dep);
+ const level_id lid(it->id, dep);
if (SysEnv.map_gen_range.get()
&& !SysEnv.map_gen_range->is_usable_in(lid))
{
diff --git a/crawl-ref/source/dbg-scan.cc b/crawl-ref/source/dbg-scan.cc
index 84c9358316..62c18f99e1 100644
--- a/crawl-ref/source/dbg-scan.cc
+++ b/crawl-ref/source/dbg-scan.cc
@@ -1928,19 +1928,19 @@ void objstat_generate_stats()
run_map_local_preludes();
// Populate a vector of the levels ids we've made
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (brdepth[i] == -1)
+ if (brdepth[it->id] == -1)
continue;
- const branch_type br = static_cast<branch_type>(i);
+ const branch_type br = it->id;
#if TAG_MAJOR_VERSION == 34
// Don't want to include Forest since it doesn't generate
if (br == BRANCH_FOREST)
continue;
#endif
vector<level_id> levels;
- for (int dep = 1; dep <= brdepth[i]; ++dep)
+ for (int dep = 1; dep <= brdepth[br]; ++dep)
{
const level_id lid(br, dep);
if (SysEnv.map_gen_range.get()
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 16b8679a68..e7799c92c6 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -2115,12 +2115,12 @@ void get_feature_desc(const coord_def &pos, describe_info &inf)
// Display branch descriptions on the entries to those branches.
if (feat_is_stair(feat))
{
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (branches[i].entry_stairs == feat)
+ if (it->entry_stairs == feat)
{
long_desc += "\n";
- long_desc += getLongDescription(branches[i].shortname);
+ long_desc += getLongDescription(it->shortname);
break;
}
}
@@ -4452,9 +4452,9 @@ static string _describe_branch_bribability()
string ret = "You can bribe the following branches:\n";
vector<branch_type> targets;
size_t width = 0;
- for (unsigned int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- const branch_type br = static_cast<branch_type>(i);
+ const branch_type br = it->id;
if (!gozag_branch_bribable(br))
continue;
@@ -4464,7 +4464,7 @@ static string _describe_branch_bribability()
continue;
targets.push_back(br);
- width = max(width, strlen(branches[i].longname));
+ width = max(width, strlen(it->longname));
}
for (unsigned int i = 0; i < targets.size(); i++)
diff --git a/crawl-ref/source/dgn-overview.cc b/crawl-ref/source/dgn-overview.cc
index 216f78ad17..faecab20e0 100644
--- a/crawl-ref/source/dgn-overview.cc
+++ b/crawl-ref/source/dgn-overview.cc
@@ -182,8 +182,7 @@ static string _portals_description_string()
{
string disp;
level_id last_id;
- for (branch_type cur_portal = BRANCH_DUNGEON; cur_portal < NUM_BRANCHES;
- cur_portal = static_cast<branch_type>(cur_portal + 1))
+ for (branch_iterator it; it; ++it)
{
last_id.depth = 10000;
portal_map_type::const_iterator ci_portals;
@@ -194,7 +193,7 @@ static string _portals_description_string()
// one line per region should be enough, they're all of
// the form D:XX, except for labyrinth portals, of which
// you would need 11 (at least) to have a problem.
- if (ci_portals->second == cur_portal)
+ if (ci_portals->second == it->id)
{
if (last_id.depth == 10000)
disp += coloured_branch(ci_portals->second)+ ":";
@@ -253,9 +252,9 @@ static string _get_seen_branches(bool display)
}
disp += "\n";
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- const branch_type branch = branches[i].id;
+ const branch_type branch = it->id;
if (branch == BRANCH_ZIGGURAT)
continue;
@@ -267,16 +266,16 @@ static string _get_seen_branches(bool display)
lid = find_deepest_explored(lid);
string entry_desc;
- for (set<level_id>::iterator it = stair_level[branch].begin();
- it != stair_level[branch].end(); ++it)
+ for (set<level_id>::iterator lit = stair_level[branch].begin();
+ lit != stair_level[branch].end(); ++lit)
{
- entry_desc += " " + it->describe(false, true);
+ entry_desc += " " + lit->describe(false, true);
}
// "D" is a little too short here.
const char *brname = (branch == BRANCH_DUNGEON
- ? branches[branch].shortname
- : branches[branch].abbrevname);
+ ? it->shortname
+ : it->abbrevname);
snprintf(buffer, sizeof buffer,
"<yellow>%*s</yellow> <darkgrey>(%d/%d)</darkgrey>%s",
@@ -306,36 +305,42 @@ static string _get_unseen_branches()
/* see if we need to hide lair branches that don't exist */
int seen_lair_branches = 0;
int seen_vaults_branches = 0;
- for (int i = BRANCH_FIRST_NON_DUNGEON; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- const branch_type branch = branches[i].id;
+ if (it->id < BRANCH_FIRST_NON_DUNGEON)
+ continue;
+
+ const branch_type branch = it->id;
if (!is_random_subbranch(branch))
continue;
if (stair_level.count(branch))
{
- if (parent_branch((branch_type)i) == BRANCH_LAIR)
+ if (parent_branch(branch) == BRANCH_LAIR)
seen_lair_branches++;
- else if (parent_branch((branch_type)i) == BRANCH_VAULTS)
+ else if (parent_branch(branch) == BRANCH_VAULTS)
seen_vaults_branches++;
}
}
- for (int i = BRANCH_FIRST_NON_DUNGEON; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- const branch_type branch = branches[i].id;
+ if (it->id < BRANCH_FIRST_NON_DUNGEON)
+ continue;
+
+ const branch_type branch = it->id;
if (is_random_subbranch(branch)
- && ((parent_branch((branch_type)i) == BRANCH_LAIR
+ && ((parent_branch(branch) == BRANCH_LAIR
&& seen_lair_branches >= 2)
- || (parent_branch((branch_type)i) == BRANCH_VAULTS)
+ || (parent_branch(branch) == BRANCH_VAULTS)
&& seen_vaults_branches >= 1))
{
continue;
}
- if (i == BRANCH_VESTIBULE || !is_connected_branch(branch))
+ if (branch == BRANCH_VESTIBULE || !is_connected_branch(branch))
continue;
if (branch_is_unfinished(branch))
@@ -343,30 +348,30 @@ static string _get_unseen_branches()
if (!stair_level.count(branch))
{
- const branch_type parent = branches[branch].parent_branch;
+ const branch_type parent = it->parent_branch;
// Root branches.
if (parent == NUM_BRANCHES)
continue;
level_id lid(parent, 0);
lid = find_deepest_explored(lid);
- if (lid.depth >= branches[branch].mindepth)
+ if (lid.depth >= it->mindepth)
{
- if (branches[branch].mindepth != branches[branch].maxdepth)
+ if (it->mindepth != it->maxdepth)
{
snprintf(buffer, sizeof buffer,
"<darkgrey>%6s: %s:%d-%d</darkgrey>",
- branches[branch].abbrevname,
+ it->abbrevname,
branches[parent].abbrevname,
- branches[branch].mindepth,
- branches[branch].maxdepth);
+ it->mindepth,
+ it->maxdepth);
}
else
{
snprintf(buffer, sizeof buffer,
"<darkgrey>%6s: %s:%d</darkgrey>",
- branches[branch].abbrevname,
+ it->abbrevname,
branches[parent].abbrevname,
- branches[branch].mindepth);
+ it->mindepth);
}
disp += buffer;
@@ -579,10 +584,10 @@ static string _get_notes()
{
string disp;
- for (int br = 0 ; br < NUM_BRANCHES; ++br)
- for (int d = 1; d <= brdepth[br]; ++d)
+ for (branch_iterator it; it; ++it)
+ for (int d = 1; d <= brdepth[it->id]; ++d)
{
- level_id i(static_cast<branch_type>(br), d);
+ level_id i(it->id, d);
if (!get_level_annotation(i).empty())
disp += _get_coloured_level_annotation(i) + "\n";
}
@@ -625,10 +630,10 @@ static bool _unnotice_stair(const level_pos &pos)
if (!feat_is_branch_stairs(feat))
return false;
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (branches[i].entry_stairs == feat)
+ for (branch_iterator it; it; ++it)
+ if (it->entry_stairs == feat)
{
- const branch_type br = static_cast<branch_type>(i);
+ const branch_type br = it->id;
if (stair_level.count(br))
{
stair_level[br].erase(level_id::current());
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 786e45e3f9..46b3e0ca0a 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -3628,15 +3628,15 @@ static void _place_branch_entrances(bool use_vaults)
// entrances (or mimics thereof) could be placed here.
bool branch_entrance_placed[NUM_BRANCHES];
bool could_be_placed = false;
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- branch_entrance_placed[i] = false;
+ branch_entrance_placed[it->id] = false;
if (!could_be_placed
- && !branch_is_unfinished(branches[i].id)
- && !is_hell_subbranch(branches[i].id)
- && ((you.depth >= branches[i].mindepth
- && you.depth <= branches[i].maxdepth)
- || level_id::current() == brentry[i]))
+ && !branch_is_unfinished(it->id)
+ && !is_hell_subbranch(it->id)
+ && ((you.depth >= it->mindepth
+ && you.depth <= it->maxdepth)
+ || level_id::current() == brentry[it->id]))
{
could_be_placed = true;
}
@@ -3651,45 +3651,43 @@ static void _place_branch_entrances(bool use_vaults)
if (!feat_is_branch_stairs(grd(*ri)))
continue;
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (branches[i].entry_stairs == grd(*ri)
+ for (branch_iterator it; it; ++it)
+ if (it->entry_stairs == grd(*ri)
&& !feature_mimic_at(*ri))
{
- branch_entrance_placed[i] = true;
+ branch_entrance_placed[it->id] = true;
break;
}
}
// Place actual branch entrances.
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
// Vestibule and hells are placed by other means.
// Likewise, if we already have an entrance, keep going.
- if (i >= BRANCH_VESTIBULE && i <= BRANCH_LAST_HELL
- || branch_entrance_placed[i])
+ if (it->id >= BRANCH_VESTIBULE && it->id <= BRANCH_LAST_HELL
+ || branch_entrance_placed[it->id])
{
continue;
}
- const Branch *b = &branches[i];
-
- const bool mimic = !branch_is_unfinished(b->id)
- && !is_hell_subbranch(b->id)
- && you.depth >= b->mindepth
- && you.depth <= b->maxdepth
+ const bool mimic = !branch_is_unfinished(it->id)
+ && !is_hell_subbranch(it->id)
+ && you.depth >= it->mindepth
+ && you.depth <= it->maxdepth
&& one_chance_in(FEATURE_MIMIC_CHANCE);
- if (b->entry_stairs != NUM_FEATURES
- && player_in_branch(parent_branch((branch_type)i))
- && (level_id::current() == brentry[i] || mimic))
+ if (it->entry_stairs != NUM_FEATURES
+ && player_in_branch(parent_branch(it->id))
+ && (level_id::current() == brentry[it->id] || mimic))
{
// Placing a stair.
- dprf("Placing stair to %s", b->shortname);
+ dprf("Placing stair to %s", it->shortname);
// Attempt to place an entry vault if allowed
if (use_vaults)
{
- string entry_tag = string(b->abbrevname);
+ string entry_tag = string(it->abbrevname);
entry_tag += "_entry";
lowercase(entry_tag);
@@ -3703,12 +3701,12 @@ static void _place_branch_entrances(bool use_vaults)
const coord_def portal_pos = find_portal_place(NULL, false);
if (!portal_pos.origin())
{
- env.grid(portal_pos) = b->entry_stairs;
+ env.grid(portal_pos) = it->entry_stairs;
env.level_map_mask(portal_pos) |= MMT_VAULT;
continue;
}
- const coord_def stair_pos = _place_specific_feature(b->entry_stairs);
+ const coord_def stair_pos = _place_specific_feature(it->entry_stairs);
// Don't allow subsequent vaults to overwrite the branch stair
env.level_map_mask(stair_pos) |= MMT_VAULT;
}
@@ -6439,10 +6437,10 @@ FixedVector<vector<StairConnectivity>, NUM_BRANCHES> connectivity;
void init_level_connectivity()
{
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- int depth = brdepth[i] > 0 ? brdepth[i] : 0;
- connectivity[i].resize(depth);
+ int depth = brdepth[it->id] > 0 ? brdepth[it->id] : 0;
+ connectivity[it->id].resize(depth);
}
}
diff --git a/crawl-ref/source/godabil.cc b/crawl-ref/source/godabil.cc
index 5b08f9954c..9810dc8b5f 100644
--- a/crawl-ref/source/godabil.cc
+++ b/crawl-ref/source/godabil.cc
@@ -4491,11 +4491,11 @@ bool gozag_check_bribe_branch(bool quiet)
branch_type branch2 = NUM_BRANCHES;
if (feat_is_branch_stairs(grd(you.pos())))
{
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (branches[i].entry_stairs == grd(you.pos())
- && gozag_branch_bribable(static_cast<branch_type>(i)))
+ for (branch_iterator it; it; ++it)
+ if (it->entry_stairs == grd(you.pos())
+ && gozag_branch_bribable(it->id))
{
- branch2 = static_cast<branch_type>(i);
+ branch2 = it->id;
break;
}
}
@@ -4529,16 +4529,16 @@ bool gozag_bribe_branch()
branch_type branch = you.where_are_you;
if (feat_is_branch_stairs(grd(you.pos())))
{
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (branches[i].entry_stairs == grd(you.pos())
- && gozag_branch_bribable(static_cast<branch_type>(i)))
+ for (branch_iterator it; it; ++it)
+ if (it->entry_stairs == grd(you.pos())
+ && gozag_branch_bribable(it->id))
{
string prompt =
make_stringf("Do you want to bribe the denizens of %s?",
- branches[i].longname);
+ it->longname);
if (yesno(prompt.c_str(), true, 'n'))
{
- branch = static_cast<branch_type>(i);
+ branch = it->id;
prompted = true;
}
break;
diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc
index f287c5f087..54b2f54a43 100644
--- a/crawl-ref/source/l_you.cc
+++ b/crawl-ref/source/l_you.cc
@@ -626,21 +626,21 @@ LUAFN(you_in_branch)
int br = NUM_BRANCHES;
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- if (strcasecmp(name, branches[i].shortname) == 0
- || strcasecmp(name, branches[i].longname) == 0
- || strcasecmp(name, branches[i].abbrevname) == 0)
+ if (strcasecmp(name, it->shortname) == 0
+ || strcasecmp(name, it->longname) == 0
+ || strcasecmp(name, it->abbrevname) == 0)
{
if (br != NUM_BRANCHES)
{
string err = make_stringf(
"'%s' matches both branch '%s' and '%s'",
name, branches[br].abbrevname,
- branches[i].abbrevname);
+ it->abbrevname);
return luaL_argerror(ls, 1, err.c_str());
}
- br = i;
+ br = it->id;
}
}
diff --git a/crawl-ref/source/maps.cc b/crawl-ref/source/maps.cc
index 04ea95a1f1..00616613b3 100644
--- a/crawl-ref/source/maps.cc
+++ b/crawl-ref/source/maps.cc
@@ -1488,8 +1488,8 @@ void read_maps()
{
unwind_var<FixedVector<int, NUM_BRANCHES> > depths(brdepth);
// let the sanity check place maps
- for (int i = 0; i < NUM_BRANCHES; i++)
- brdepth[i] = branches[i].numlevels;
+ for (branch_iterator it; it; ++it)
+ brdepth[it->id] = it->numlevels;
dlua.execfile("dlua/sanity.lua", true, true);
}
}
diff --git a/crawl-ref/source/mon-pick.cc b/crawl-ref/source/mon-pick.cc
index f645be6100..4e74424ba5 100644
--- a/crawl-ref/source/mon-pick.cc
+++ b/crawl-ref/source/mon-pick.cc
@@ -169,13 +169,13 @@ monster_type pick_monster_all_branches(int absdepth0, monster_picker &picker,
memset(rarities, 0, sizeof(rarities));
int nvalid = 0;
- for (int br = 0; br < NUM_BRANCHES; br++)
+ for (branch_iterator it; it; ++it)
{
- int depth = absdepth0 - absdungeon_depth((branch_type)br, 0);
- if (depth < 1 || depth > branch_ood_cap((branch_type)br))
+ int depth = absdepth0 - absdungeon_depth(it->id, 0);
+ if (depth < 1 || depth > branch_ood_cap(it->id))
continue;
- for (const pop_entry *pop = population[br].pop; pop->value; pop++)
+ for (const pop_entry *pop = population[it->id].pop; pop->value; pop++)
{
if (depth < pop->minr || depth > pop->maxr)
continue;
@@ -254,9 +254,9 @@ void debug_monpick()
string fails;
// Tests for the legacy interface; shouldn't ever happen.
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- branch_type br = (branch_type)i;
+ branch_type br = it->id;
for (monster_type m = MONS_0; m < NUM_MONSTERS; ++m)
{
@@ -266,22 +266,22 @@ void debug_monpick()
if (lev < DEPTH_NOWHERE && !rare)
{
fails += make_stringf("%s: no rarity for %s\n",
- branches[i].abbrevname,
+ it->abbrevname,
mons_class_name(m));
}
if (rare && lev >= DEPTH_NOWHERE)
{
fails += make_stringf("%s: no depth for %s\n",
- branches[i].abbrevname,
+ it->abbrevname,
mons_class_name(m));
}
}
}
// Legacy tests end.
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- branch_type br = (branch_type)i;
+ branch_type br = it->id;
for (int d = 1; d <= branch_ood_cap(br); d++)
{
diff --git a/crawl-ref/source/mon-place.cc b/crawl-ref/source/mon-place.cc
index 5acede199e..d94a0a5776 100644
--- a/crawl-ref/source/mon-place.cc
+++ b/crawl-ref/source/mon-place.cc
@@ -538,16 +538,16 @@ static bool _find_mon_place_near_stairs(coord_def& pos,
}
// Is it a branch stair?
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (branches[i].entry_stairs == feat)
+ if (it->entry_stairs == feat)
{
- place = static_cast<branch_type>(i);
+ place = it->id;
break;
}
- else if (branches[i].exit_stairs == feat)
+ else if (it->exit_stairs == feat)
{
- place = brentry[i];
+ place = brentry[it->id];
// This can happen on D:1 and in wizmode with random spawns on the
// first floor of a branch that didn't generate naturally.
if (!place.is_valid())
diff --git a/crawl-ref/source/ng-init.cc b/crawl-ref/source/ng-init.cc
index 81a6e2eb32..ce89607477 100644
--- a/crawl-ref/source/ng-init.cc
+++ b/crawl-ref/source/ng-init.cc
@@ -60,8 +60,8 @@ void initialise_branch_depths()
// XXX: Should this go elsewhere?
branch_bribe.init(0);
- for (int br = 0; br < NUM_BRANCHES; ++br)
- brentry[br].clear();
+ for (branch_iterator it; it; ++it)
+ brentry[it->id].clear();
if (crawl_state.game_is_sprint())
{
@@ -83,10 +83,15 @@ void initialise_branch_depths()
{
const Branch *b = &branches[branch];
ASSERT(b->id == branch);
- if (!branch_is_unfinished(b->id) && b->parent_branch != NUM_BRANCHES)
+ }
+
+ for (branch_iterator it; it; ++it)
+ {
+ if (!branch_is_unfinished(it->id) && it->parent_branch != NUM_BRANCHES)
{
- brentry[branch] = level_id(b->parent_branch,
- random_range(b->mindepth, b->maxdepth));
+ brentry[it->id] = level_id(it->parent_branch,
+ random_range(it->mindepth,
+ it->maxdepth));
}
}
@@ -104,8 +109,8 @@ void initialise_branch_depths()
brentry[disabled_branch[i]].clear();
}
- for (int i = 0; i < NUM_BRANCHES; i++)
- brdepth[i] = branches[i].numlevels;
+ for (branch_iterator it; it; ++it)
+ brdepth[it->id] = it->numlevels;
}
#define MAX_OVERFLOW_LEVEL 9
diff --git a/crawl-ref/source/place-info.cc b/crawl-ref/source/place-info.cc
index 963aab2f02..e6ba233dad 100644
--- a/crawl-ref/source/place-info.cc
+++ b/crawl-ref/source/place-info.cc
@@ -128,6 +128,6 @@ PlaceInfo& player::get_place_info(branch_type branch) const
void player::clear_place_info()
{
global_info = PlaceInfo();
- for (unsigned int i = 0; i < NUM_BRANCHES; ++i)
- branch_info[i] = PlaceInfo();
+ for (branch_iterator it; it; ++it)
+ branch_info[it->id] = PlaceInfo();
}
diff --git a/crawl-ref/source/place.cc b/crawl-ref/source/place.cc
index 1e90bbe721..7c5791a1f1 100644
--- a/crawl-ref/source/place.cc
+++ b/crawl-ref/source/place.cc
@@ -109,12 +109,10 @@ bool branch_allows_followers(branch_type branch)
vector<level_id> all_dungeon_ids()
{
vector<level_id> out;
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- const Branch &branch = branches[i];
-
- for (int depth = 1; depth <= brdepth[i]; depth++)
- out.push_back(level_id(branch.id, depth));
+ for (int depth = 1; depth <= brdepth[it->id]; depth++)
+ out.push_back(level_id(it->id, depth));
}
return out;
}
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 78d61a056f..e9954202dd 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -5892,10 +5892,10 @@ void player::init()
constricting = 0;
// Protected fields:
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- branch_info[i].branch = (branch_type)i;
- branch_info[i].assert_validity();
+ branch_info[it->id].branch = it->id;
+ branch_info[it->id].assert_validity();
}
}
@@ -7869,14 +7869,14 @@ vector<PlaceInfo> player::get_all_place_info(bool visited_only,
{
vector<PlaceInfo> list;
- for (int i = 0; i < NUM_BRANCHES; i++)
+ for (branch_iterator it; it; ++it)
{
- if (visited_only && branch_info[i].num_visits == 0
- || dungeon_only && !is_connected_branch((branch_type)i))
+ if (visited_only && branch_info[it->id].num_visits == 0
+ || dungeon_only && !is_connected_branch(*it))
{
continue;
}
- list.push_back(branch_info[i]);
+ list.push_back(branch_info[it->id]);
}
return list;
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 7bad2fc919..91fddcdc73 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -2930,8 +2930,8 @@ void excommunication(god_type new_god)
you.attribute[ATTR_GOZAG_SHOPS_CURRENT] = 0;
}
invalidate_agrid(true); // gold auras
- for (int i = 0; i < NUM_BRANCHES; i++)
- branch_bribe[i] = 0;
+ for (branch_iterator it; it; ++it)
+ branch_bribe[it->id] = 0;
add_daction(DACT_BRIBE_TIMEOUT);
add_daction(DACT_REMOVE_GOZAG_SHOPS);
_set_penance(old_god, 25);
diff --git a/crawl-ref/source/stairs.cc b/crawl-ref/source/stairs.cc
index 0428290852..cb5f1c62d4 100644
--- a/crawl-ref/source/stairs.cc
+++ b/crawl-ref/source/stairs.cc
@@ -617,10 +617,10 @@ level_id stair_destination(dungeon_feature_type feat, const string &dst,
}
// Try to find a branch stair.
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (branches[i].entry_stairs == feat)
- return level_id(branches[i].id);
+ if (it->entry_stairs == feat)
+ return level_id(it->id);
}
return level_id();
diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc
index 41518104b8..5a53ebf797 100644
--- a/crawl-ref/source/travel.cc
+++ b/crawl-ref/source/travel.cc
@@ -2112,9 +2112,9 @@ static vector<branch_type> _get_branches(bool (*selector)(const Branch &))
{
vector<branch_type> result;
- for (int i = 0; i < NUM_BRANCHES; ++i)
- if (selector(branches[i]))
- result.push_back(branches[i].id);
+ for (branch_iterator it; it; ++it)
+ if (selector(**it))
+ result.push_back(it->id);
return result;
}
@@ -3132,11 +3132,11 @@ level_id level_id::get_next_level_id(const coord_def &pos)
return stair_destination(pos);
#endif
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (gridc == branches[i].entry_stairs)
+ if (gridc == it->entry_stairs)
{
- id.branch = static_cast<branch_type>(i);
+ id.branch = it->id;
id.depth = 1;
break;
}
diff --git a/crawl-ref/source/wiz-dgn.cc b/crawl-ref/source/wiz-dgn.cc
index fa1197b832..74aeedf985 100644
--- a/crawl-ref/source/wiz-dgn.cc
+++ b/crawl-ref/source/wiz-dgn.cc
@@ -292,19 +292,19 @@ bool wizard_create_feature(const coord_def& pos)
void wizard_list_branches()
{
- for (int i = 0; i < NUM_BRANCHES; ++i)
+ for (branch_iterator it; it; ++it)
{
- if (parent_branch((branch_type)i) == NUM_BRANCHES)
+ if (parent_branch(it->id) == NUM_BRANCHES)
continue;
- else if (brentry[i].is_valid())
+ else if (brentry[it->id].is_valid())
{
mprf(MSGCH_DIAGNOSTICS, "Branch %d (%s) is on %s",
- i, branches[i].longname, brentry[i].describe().c_str());
+ it->id, it->longname, brentry[it->id].describe().c_str());
}
- else if (is_random_subbranch((branch_type)i))
+ else if (is_random_subbranch(it->id))
{
mprf(MSGCH_DIAGNOSTICS, "Branch %d (%s) was not generated "
- "this game", i, branches[i].longname);
+ "this game", it->id, it->longname);
}
}