summaryrefslogtreecommitdiff
path: root/src/station_cmd.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-12-20 14:57:44 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-12-20 14:57:44 +0000
commitec492bfb7700b719e41553417cbe77c5d10549ae (patch)
tree3e32848d29e0a9326bb9ff373a2248fe7239ca68 /src/station_cmd.cpp
parent4818b72c759f3845a28b94d3f1fad9541d4e8304 (diff)
downloadopenttd-ec492bfb7700b719e41553417cbe77c5d10549ae.tar.xz
(svn r26166) -Fix: Scale flows only after mapping to avoid rounding errors.
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 6b158aaf1..6ef602b83 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -4290,6 +4290,22 @@ void FlowStat::ReleaseShare(StationID st)
}
/**
+ * Scale all shares from link graph's runtime to monthly values.
+ * @param runtime Time the link graph has been running without compression.
+ */
+void FlowStat::ScaleToMonthly(uint runtime)
+{
+ SharesMap new_shares;
+ uint share = 0;
+ for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
+ share = max(share + 1, i->first * 30 / runtime);
+ new_shares[share] = i->second;
+ if (this->unrestricted == i->first) this->unrestricted = share;
+ }
+ this->shares.swap(new_shares);
+}
+
+/**
* Add some flow from "origin", going via "via".
* @param origin Origin of the flow.
* @param via Next hop.