mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r25892) -Fix: off-by-one error in GetVia prevented certain flows from getting picked
This commit is contained in:
parent
54db96be43
commit
9337c561b0
|
@ -96,7 +96,7 @@ public:
|
||||||
inline StationID GetVia() const
|
inline StationID GetVia() const
|
||||||
{
|
{
|
||||||
assert(!this->shares.empty());
|
assert(!this->shares.empty());
|
||||||
return this->shares.upper_bound(RandomRange((--this->shares.end())->first - 1))->second;
|
return this->shares.upper_bound(RandomRange((--this->shares.end())->first))->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
StationID GetVia(StationID excluded, StationID excluded2 = INVALID_STATION) const;
|
StationID GetVia(StationID excluded, StationID excluded2 = INVALID_STATION) const;
|
||||||
|
|
|
@ -4065,7 +4065,7 @@ uint FlowStat::GetShare(StationID st) const
|
||||||
StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||||
{
|
{
|
||||||
assert(!this->shares.empty());
|
assert(!this->shares.empty());
|
||||||
uint max = (--this->shares.end())->first - 1;
|
uint max = (--this->shares.end())->first;
|
||||||
SharesMap::const_iterator it = this->shares.upper_bound(RandomRange(max));
|
SharesMap::const_iterator it = this->shares.upper_bound(RandomRange(max));
|
||||||
assert(it != this->shares.end());
|
assert(it != this->shares.end());
|
||||||
if (it->second != excluded && it->second != excluded2) return it->second;
|
if (it->second != excluded && it->second != excluded2) return it->second;
|
||||||
|
@ -4076,7 +4076,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||||
uint end = it->first;
|
uint end = it->first;
|
||||||
uint begin = (it == this->shares.begin() ? 0 : (--it)->first);
|
uint begin = (it == this->shares.begin() ? 0 : (--it)->first);
|
||||||
uint interval = end - begin;
|
uint interval = end - begin;
|
||||||
if (interval > max) return INVALID_STATION; // Only one station in the map.
|
if (interval >= max) return INVALID_STATION; // Only one station in the map.
|
||||||
uint new_max = max - interval;
|
uint new_max = max - interval;
|
||||||
uint rand = RandomRange(new_max);
|
uint rand = RandomRange(new_max);
|
||||||
SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) :
|
SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) :
|
||||||
|
@ -4090,7 +4090,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||||
uint end2 = it2->first;
|
uint end2 = it2->first;
|
||||||
uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first);
|
uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first);
|
||||||
uint interval2 = end2 - begin2;
|
uint interval2 = end2 - begin2;
|
||||||
if (interval2 > new_max) return INVALID_STATION; // Only the two excluded stations in the map.
|
if (interval2 >= new_max) return INVALID_STATION; // Only the two excluded stations in the map.
|
||||||
new_max -= interval2;
|
new_max -= interval2;
|
||||||
if (begin > begin2) {
|
if (begin > begin2) {
|
||||||
Swap(begin, begin2);
|
Swap(begin, begin2);
|
||||||
|
|
Loading…
Reference in New Issue