mirror of https://github.com/OpenTTD/OpenTTD
(svn r26448) -Fix [FS#5970]: Avoid division by 0 when scaling flow values.
parent
a9bdb92d19
commit
bef953a32c
|
@ -49,8 +49,10 @@ void FlowMapper::Run(LinkGraphJob &job) const
|
||||||
FlowStatMap &flows = node.Flows();
|
FlowStatMap &flows = node.Flows();
|
||||||
flows.FinalizeLocalConsumption(node.Station());
|
flows.FinalizeLocalConsumption(node.Station());
|
||||||
if (this->scale) {
|
if (this->scale) {
|
||||||
/* Scale by time the graph has been running without being compressed. */
|
/* Scale by time the graph has been running without being compressed. Add 1 to avoid
|
||||||
uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression();
|
* division by 0 if spawn date == last compression date. This matches
|
||||||
|
* LinkGraph::Monthly(). */
|
||||||
|
uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1;
|
||||||
for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) {
|
for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) {
|
||||||
i->second.ScaleToMonthly(runtime);
|
i->second.ScaleToMonthly(runtime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4314,9 +4314,11 @@ void FlowStat::ReleaseShare(StationID st)
|
||||||
/**
|
/**
|
||||||
* Scale all shares from link graph's runtime to monthly values.
|
* Scale all shares from link graph's runtime to monthly values.
|
||||||
* @param runtime Time the link graph has been running without compression.
|
* @param runtime Time the link graph has been running without compression.
|
||||||
|
* @pre runtime must be greater than 0 as we don't want infinite flow values.
|
||||||
*/
|
*/
|
||||||
void FlowStat::ScaleToMonthly(uint runtime)
|
void FlowStat::ScaleToMonthly(uint runtime)
|
||||||
{
|
{
|
||||||
|
assert(runtime > 0);
|
||||||
SharesMap new_shares;
|
SharesMap new_shares;
|
||||||
uint share = 0;
|
uint share = 0;
|
||||||
for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
|
for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
|
||||||
|
|
Loading…
Reference in New Issue