From 95857f2026be27808b27a5aa1d86ba50aa31d81f Mon Sep 17 00:00:00 2001 From: peter1138 Date: Wed, 12 Oct 2005 07:27:56 +0000 Subject: (svn r3032) -NewGRF, Feature: Add support for changing base prices. --- economy.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'economy.c') diff --git a/economy.c b/economy.c index 8ec569d00..fd19a592c 100644 --- a/economy.c +++ b/economy.c @@ -768,6 +768,33 @@ static const int32 _price_base[NUM_PRICES] = { 1000000, // build_industry }; +static byte price_base_multiplier[NUM_PRICES]; + +/** + * Reset changes to the price base multipliers. + */ +void ResetPriceBaseMultipliers(void) +{ + int i; + + // 8 means no multiplier. + for (i = 0; i < NUM_PRICES; i++) + price_base_multiplier[i] = 8; +} + +/** + * 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) + * @param price Index of price base to change. + * @param factor Amount to change by. + */ +void SetPriceBaseMultiplier(int price, byte factor) +{ + if (price < NUM_PRICES) + price_base_multiplier[price] = factor; +} + void StartupEconomy(void) { int i; @@ -784,6 +811,11 @@ void StartupEconomy(void) price = price * 9 >> 3; } } + if (price_base_multiplier[i] > 8) { + price <<= price_base_multiplier[i] - 8; + } else { + price >>= 8 - price_base_multiplier[i]; + } ((int32*)&_price)[i] = price; _price_frac[i] = 0; } -- cgit v1.2.3-54-g00ecf