diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-08-02 20:06:34 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-08-02 20:10:40 -0400 |
commit | 4e1b44a4905cccd1a8509a91f9d10d7a06f956e7 (patch) | |
tree | 62b76b8e00325f1f7a96c646f10b5a5fe62919e6 /crawl-ref/source/dungeon.cc | |
parent | 756871af9b64cee576375e9ed5f73cf3cfa1b453 (diff) | |
download | crawl-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/dungeon.cc')
-rw-r--r-- | crawl-ref/source/dungeon.cc | 56 |
1 files changed, 27 insertions, 29 deletions
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); } } |