diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-05-05 07:31:02 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-05-05 07:31:02 +0000 |
commit | 05982cef94ba574904072aada7d1cfadca06f5e0 (patch) | |
tree | c4b2f88561b646dcb2cdf313674f52557228c0bf /crawl-ref/source/travel.cc | |
parent | e95171de09bcfcc415b2c4fda74d66bcde537b2c (diff) | |
download | crawl-ref-05982cef94ba574904072aada7d1cfadca06f5e0.tar.gz crawl-ref-05982cef94ba574904072aada7d1cfadca06f5e0.zip |
Travel cache was not handling stair distances correctly, fixed.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1409 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/travel.cc')
-rw-r--r-- | crawl-ref/source/travel.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index da371a7b8d..ef84c2dc5a 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -2233,7 +2233,6 @@ static int find_transtravel_stair( const level_id &cur, for (int i = 0, count = stairs.size(); i < count; ++i) { stair_info &si = stairs[i]; - int deltadist = li.distance_between(this_stair, &si); if (!this_stair) { @@ -2246,7 +2245,8 @@ static int find_transtravel_stair( const level_id &cur, // deltadist == 0 is legal (if this_stair is NULL), since the player // may be standing on the stairs. If two stairs are disconnected, // deltadist has to be negative. - if (deltadist < 0) continue; + if (deltadist < 0) + continue; int dist2stair = distance + deltadist; if (si.distance == -1 || si.distance > dist2stair) @@ -2295,7 +2295,8 @@ static int find_transtravel_stair( const level_id &cur, } // If we don't know where these stairs go, we can't take them. - if (!dest.is_valid()) continue; + if (!dest.is_valid()) + continue; // We need to get the stairs at the new location and set the // distance on them as well. @@ -2764,13 +2765,12 @@ void LevelInfo::correct_stair_list(const std::vector<coord_def> &s) stair_distances.clear(); // First we kill any stairs in 'stairs' that aren't there in 's'. - for (std::vector<stair_info>::iterator i = stairs.begin(); - i != stairs.end(); ++i) + for (int i = ((int) stairs.size()) - 1; i >= 0; --i) { bool found = false; for (int j = s.size() - 1; j >= 0; --j) { - if (s[j] == i->position) + if (s[j] == stairs[i].position) { found = true; break; @@ -2778,7 +2778,7 @@ void LevelInfo::correct_stair_list(const std::vector<coord_def> &s) } if (!found) - stairs.erase(i--); + stairs.erase(stairs.begin() + i); } // For each stair in 's', make sure we have a corresponding stair @@ -2813,7 +2813,9 @@ void LevelInfo::correct_stair_list(const std::vector<coord_def> &s) } } - stair_distances.reserve( stairs.size() * stairs.size() ); + const int nstairs = stairs.size(); + stair_distances.reserve( nstairs * nstairs ); + stair_distances.resize( nstairs * nstairs, 0 ); } int LevelInfo::distance_between(const stair_info *s1, const stair_info *s2) @@ -2825,7 +2827,7 @@ int LevelInfo::distance_between(const stair_info *s1, const stair_info *s2) int i1 = get_stair_index(s1->position), i2 = get_stair_index(s2->position); if (i1 == -1 || i2 == -1) return 0; - + return stair_distances[ i1 * stairs.size() + i2 ]; } @@ -2883,9 +2885,10 @@ void LevelInfo::save(FILE *file) const if (stair_count) { // Save stair distances as short ints. - for (int i = stair_count * stair_count - 1; i >= 0; --i) + const int sz = stair_distances.size(); + for (int i = 0, n = stair_count * stair_count; i < n; ++i) { - if (i >= (int) stair_distances.size()) + if (i >= sz) writeShort(file, -1); else writeShort(file, stair_distances[i]); |