summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-11-08 18:04:53 +0000
committerfrosch <frosch@openttd.org>2009-11-08 18:04:53 +0000
commitf48f73f060b388ab51fec8112170cfa8d4b8ca17 (patch)
tree69fd79a57fa4ce4a62462c8be34c2b380230bc1b
parent5d3fa809317a84528af338cac7d7903250eb959b (diff)
downloadopenttd-f48f73f060b388ab51fec8112170cfa8d4b8ca17.tar.xz
(svn r18016) -Codechange: Move the arbitrary basecost multiplier offset (8) to newgrf loading and make the internal state zero-based instead.
-rw-r--r--src/economy.cpp16
-rw-r--r--src/economy_func.h2
-rw-r--r--src/economy_type.h7
-rw-r--r--src/newgrf.cpp4
4 files changed, 15 insertions, 14 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 57d052bea..1d934bd7c 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -109,7 +109,7 @@ int _score_part[MAX_COMPANIES][SCORE_END];
Economy _economy;
Prices _price;
Money _additional_cash_required;
-static byte _price_base_multiplier[PR_END];
+static int8 _price_base_multiplier[PR_END];
Money CalculateCompanyValue(const Company *c)
{
@@ -652,7 +652,7 @@ void RecomputePrices()
price = (int64)price * _economy.inflation_prices;
/* Apply newgrf modifiers, and remove fractional part of inflation */
- int shift = _price_base_multiplier[i] - 8 - 16;
+ int shift = _price_base_multiplier[i] - 16;
if (shift >= 0) {
price <<= shift;
} else {
@@ -728,22 +728,20 @@ static void HandleEconomyFluctuations()
*/
void ResetPriceBaseMultipliers()
{
- /* 8 means no multiplier. */
- for (Price i = PR_BEGIN; i < PR_END; i++)
- _price_base_multiplier[i] = 8;
+ memset(_price_base_multiplier, 0, sizeof(_price_base_multiplier));
}
/**
* Change a price base by the given factor.
- * The price base is altered by factors of two, with an offset of 8.
- * NewBaseCost = OldBaseCost * 2^(n-8)
+ * The price base is altered by factors of two.
+ * NewBaseCost = OldBaseCost * 2^n
* @param price Index of price base to change.
* @param factor Amount to change by.
*/
-void SetPriceBaseMultiplier(Price price, byte factor)
+void SetPriceBaseMultiplier(Price price, int factor)
{
assert(price < PR_END);
- _price_base_multiplier[price] = min(factor, MAX_PRICE_MODIFIER);
+ _price_base_multiplier[price] = Clamp(factor, MIN_PRICE_MODIFIER, MAX_PRICE_MODIFIER);
}
/**
diff --git a/src/economy_func.h b/src/economy_func.h
index 9a84635c0..38505d450 100644
--- a/src/economy_func.h
+++ b/src/economy_func.h
@@ -23,7 +23,7 @@
#include "station_type.h"
void ResetPriceBaseMultipliers();
-void SetPriceBaseMultiplier(Price price, byte factor);
+void SetPriceBaseMultiplier(Price price, int factor);
extern const ScoreInfo _score_info[];
extern int _score_part[MAX_COMPANIES][SCORE_END];
diff --git a/src/economy_type.h b/src/economy_type.h
index 4d726ed5d..ccaf9de4a 100644
--- a/src/economy_type.h
+++ b/src/economy_type.h
@@ -171,11 +171,14 @@ static const int LOAN_INTERVAL = 10000;
static const uint64 MAX_INFLATION = (1ull << (63 - 32)) - 1;
/**
- * Maximum NewGRF price modifier including the shift offset of 8 bits.
+ * Maximum NewGRF price modifiers.
* Increasing base prices by factor 65536 should be enough.
* @see MAX_INFLATION
*/
-static const int MAX_PRICE_MODIFIER = 16 + 8;
+enum {
+ MIN_PRICE_MODIFIER = -8,
+ MAX_PRICE_MODIFIER = 16,
+};
struct CargoPayment;
typedef uint32 CargoPaymentID;
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 69a187fd6..caa30ebb4 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -1665,11 +1665,11 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, by
for (int i = 0; i < numinfo; i++) {
switch (prop) {
case 0x08: { // Cost base factor
- byte factor = grf_load_byte(&buf);
+ int factor = grf_load_byte(&buf);
uint price = gvid + i;
if (price < PR_END) {
- SetPriceBaseMultiplier((Price)price, factor);
+ SetPriceBaseMultiplier((Price)price, factor - 8);
} else {
grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price);
}