summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-06-10 21:53:11 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-06-10 21:53:11 +0000
commit1c995a3faa44057dcefa7869d2fa41650090a8c6 (patch)
tree774b374f4f92c790e2b71750b3e98281efbbe083 /src/station_cmd.cpp
parent06d95e9123eaccfe1aacace5c157248e5ec9231a (diff)
downloadopenttd-1c995a3faa44057dcefa7869d2fa41650090a8c6.tar.xz
(svn r25391) -Fix: make ChangeShare really aware of INT_MIN
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index ae2ba9588..44cf45f5a 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -4101,27 +4101,33 @@ void FlowStat::ChangeShare(StationID st, int flow)
* be empty. In that case the whole flow stat must be deleted then. */
assert(!this->shares.empty());
- int32 added_shares = 0;
- uint32 last_share = 0;
+ uint removed_shares = 0;
+ uint added_shares = 0;
+ uint last_share = 0;
SharesMap new_shares;
for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
if (it->second == st) {
- uint share = it->first - last_share;
- int change = flow - added_shares;
- uint new_share = (change < 0 && (uint)(-change) > share) ? 0 : share + change;
- added_shares -= share;
- added_shares += new_share;
- if (new_share > 0) {
- new_shares[it->first + added_shares] = it->second;
+ if (flow < 0) {
+ uint share = it->first - last_share;
+ if (flow == INT_MIN || (uint)(-flow) >= share) {
+ removed_shares += share;
+ if (flow != INT_MIN) flow += share;
+ last_share = it->first;
+ continue; // remove the whole share
+ }
+ removed_shares += (uint)(-flow);
+ } else {
+ added_shares += (uint)(flow);
}
- } else {
- new_shares[it->first + added_shares] = it->second;
+
+ /* If we don't continue above the whole flow has been added or
+ * removed. */
+ flow = 0;
}
+ new_shares[it->first + added_shares - removed_shares] = it->second;
last_share = it->first;
}
- if (flow > added_shares) {
- new_shares[last_share + flow - added_shares] = st;
- }
+ if (flow > 0) new_shares[last_share + (uint)flow] = st;
this->shares.swap(new_shares);
}