summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-09-26 11:04:30 +0000
committerfrosch <frosch@openttd.org>2010-09-26 11:04:30 +0000
commitb65f463e33af617bd0399e41e3618f2ef8b1f896 (patch)
tree2c0831f548b25fda6473a30d93135d2d828150d2 /src
parent717fcd09c65a5e26116059d30bcd9e1b6e924c66 (diff)
downloadopenttd-b65f463e33af617bd0399e41e3618f2ef8b1f896.tar.xz
(svn r20850) -Codechange: Add IndustrySpec::UsesSmoothEconomy() to deduplicate code.
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp15
-rw-r--r--src/industrytype.h6
2 files changed, 15 insertions, 6 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 68cc9d758..da79956f8 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1572,9 +1572,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
i->production_rate[1] = indspec->production_rate[1];
/* don't use smooth economy for industries using production related callbacks */
- if (_settings_game.economy.smooth_economy &&
- !(HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
- !(HasBit(indspec->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_CHANGE))) { // production change callbacks
+ if (indspec->UsesSmoothEconomy()) {
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8, 255);
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8, 255);
}
@@ -2232,9 +2230,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
bool suppress_message = false;
bool recalculate_multipliers = false; ///< reinitialize production_rate to match prod_level
/* don't use smooth economy for industries using production related callbacks */
- bool smooth_economy = _settings_game.economy.smooth_economy &&
- !(HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
- !(HasBit(indspec->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_CHANGE)); // production change callbacks
+ bool smooth_economy = indspec->UsesSmoothEconomy();
byte div = 0;
byte mul = 0;
int8 increment = 0;
@@ -2515,6 +2511,13 @@ Money IndustrySpec::GetRemovalCost() const
return (_price[PR_CLEAR_INDUSTRY] * this->removal_cost_multiplier) >> 8;
}
+bool IndustrySpec::UsesSmoothEconomy() const
+{
+ return _settings_game.economy.smooth_economy &&
+ !(HasBit(this->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
+ !(HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE)); // production change callbacks
+}
+
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
{
if (AutoslopeEnabled()) {
diff --git a/src/industrytype.h b/src/industrytype.h
index c534fa60a..c037ab61e 100644
--- a/src/industrytype.h
+++ b/src/industrytype.h
@@ -153,6 +153,12 @@ struct IndustrySpec {
* @return the cost (inflation corrected etc)
*/
Money GetRemovalCost() const;
+
+ /**
+ * Determines whether this industrytype uses smooth economy or whether it uses standard/newgrf production changes.
+ * @return true if smooth economy is used.
+ */
+ bool UsesSmoothEconomy() const;
};
/**