summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ng-init.cc
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 /crawl-ref/source/ng-init.cc
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.
Diffstat (limited to 'crawl-ref/source/ng-init.cc')
-rw-r--r--crawl-ref/source/ng-init.cc19
1 files changed, 12 insertions, 7 deletions
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