summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-10-04 19:23:50 +0000
committerfrosch <frosch@openttd.org>2010-10-04 19:23:50 +0000
commit7f060bdaf5ae6ad0ae0b354eb04ad63a8b34ffa6 (patch)
tree0eb1ccdfd1b4460b81c0f2d44629943484908341 /src/industry_cmd.cpp
parenta0a51c2ac13f90179a7fe476dc4e67dc27040816 (diff)
downloadopenttd-7f060bdaf5ae6ad0ae0b354eb04ad63a8b34ffa6.tar.xz
(svn r20896) -Codechange: Split recompution of productionrates for non-smooth economy to separate function.
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index da79956f8..8e86295d0 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2030,6 +2030,20 @@ static void UpdateIndustryStatistics(Industry *i)
}
}
+/**
+ * Recompute #production_rate for current #prod_level.
+ * This function is only valid when not using smooth economy.
+ */
+void Industry::RecomputeProductionMultipliers()
+{
+ const IndustrySpec *indspec = GetIndustrySpec(this->type);
+ assert(!indspec->UsesSmoothEconomy());
+
+ /* Rates are rounded up, so e.g. oilrig always produces some passengers */
+ this->production_rate[0] = min(CeilDiv(indspec->production_rate[0] * this->prod_level, PRODLEVEL_DEFAULT), 0xFF);
+ this->production_rate[1] = min(CeilDiv(indspec->production_rate[1] * this->prod_level, PRODLEVEL_DEFAULT), 0xFF);
+}
+
/** Simple helper that will collect data for the generation of industries */
struct ProbabilityHelper {
uint16 prob; ///< probability
@@ -2371,11 +2385,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
/* Recalculate production_rate
* For non-smooth economy these should always be synchronized with prod_level */
- if (recalculate_multipliers) {
- /* Rates are rounded up, so e.g. oilrig always produces some passengers */
- i->production_rate[0] = min(CeilDiv(indspec->production_rate[0] * i->prod_level, PRODLEVEL_DEFAULT), 0xFF);
- i->production_rate[1] = min(CeilDiv(indspec->production_rate[1] * i->prod_level, PRODLEVEL_DEFAULT), 0xFF);
- }
+ if (recalculate_multipliers) i->RecomputeProductionMultipliers();
/* Close if needed and allowed */
if (closeit && !CheckIndustryCloseDownProtection(i->type)) {