diff options
author | frosch <frosch@openttd.org> | 2009-11-08 12:23:02 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-11-08 12:23:02 +0000 |
commit | 3f5e42b04a552b6c1bf06b2bbd36e8bf9c7376bb (patch) | |
tree | c5c07837a657cef27ac79e3caa35248c665a2d1d | |
parent | e781929d7f7d472bd400cc0d00407c97f469f841 (diff) | |
download | openttd-3f5e42b04a552b6c1bf06b2bbd36e8bf9c7376bb.tar.xz |
(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.
-rw-r--r-- | src/economy.cpp | 18 | ||||
-rw-r--r-- | src/economy_func.h | 2 | ||||
-rw-r--r-- | src/economy_type.h | 10 | ||||
-rw-r--r-- | src/newgrf.cpp | 6 | ||||
-rw-r--r-- | src/saveload/economy_sl.cpp | 5 | ||||
-rw-r--r-- | src/table/pricebase.h | 2 |
6 files changed, 23 insertions, 20 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index 2e70af61f..57d052bea 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[NUM_PRICES]; +static byte _price_base_multiplier[PR_END]; Money CalculateCompanyValue(const Company *c) { @@ -625,10 +625,8 @@ void RecomputePrices() /* Setup maximum loan */ _economy.max_loan = (_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000; - assert_compile(sizeof(_price) == NUM_PRICES * sizeof(Money)); - /* Setup price bases */ - for (uint i = 0; i < NUM_PRICES; i++) { + for (Price i = PR_BEGIN; i < PR_END; i++) { Money price = _price_base_specs[i].start_price; /* Apply difficulty settings */ @@ -662,7 +660,7 @@ void RecomputePrices() } /* Store value */ - ((Money *)&_price)[i] = price; + _price[i] = price; } /* Setup cargo payment */ @@ -730,10 +728,8 @@ static void HandleEconomyFluctuations() */ void ResetPriceBaseMultipliers() { - uint i; - /* 8 means no multiplier. */ - for (i = 0; i < NUM_PRICES; i++) + for (Price i = PR_BEGIN; i < PR_END; i++) _price_base_multiplier[i] = 8; } @@ -744,9 +740,9 @@ void ResetPriceBaseMultipliers() * @param price Index of price base to change. * @param factor Amount to change by. */ -void SetPriceBaseMultiplier(uint price, byte factor) +void SetPriceBaseMultiplier(Price price, byte factor) { - assert(price < NUM_PRICES); + assert(price < PR_END); _price_base_multiplier[price] = min(factor, MAX_PRICE_MODIFIER); } @@ -800,7 +796,7 @@ void InitializeEconomy() */ Money GetPriceByIndex(Price index) { - if (index >= NUM_PRICES) return 0; + if (index >= PR_END) return 0; return _price[index]; } diff --git a/src/economy_func.h b/src/economy_func.h index 3ad447aa6..9a84635c0 100644 --- a/src/economy_func.h +++ b/src/economy_func.h @@ -23,7 +23,7 @@ #include "station_type.h" void ResetPriceBaseMultipliers(); -void SetPriceBaseMultiplier(uint price, byte factor); +void SetPriceBaseMultiplier(Price price, byte 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 0f5a88ceb..4d726ed5d 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -59,7 +59,12 @@ struct ScoreInfo { int score; ///< How much score it will give }; +/** + * Enumeration of all base prices for use with #Prices. + * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them. + */ enum Price { + PR_BEGIN = 0, PR_STATION_VALUE = 0, PR_BUILD_RAIL, PR_BUILD_ROAD, @@ -110,11 +115,12 @@ enum Price { PR_RUNNING_SHIP, PR_BUILD_INDUSTRY, - NUM_PRICES, + PR_END, INVALID_PRICE = 0xFF }; +DECLARE_POSTFIX_INCREMENT(Price) -typedef Money Prices[NUM_PRICES]; +typedef Money Prices[PR_END]; enum ExpensesType { EXPENSES_CONSTRUCTION = 0, diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 21412ef95..fc38c2b9b 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -435,7 +435,7 @@ static void ConvertTTDBasePrice(uint32 base_pointer, const char *error_location, static const uint32 start = 0x4B34; ///< Position of first base price static const uint32 size = 6; ///< Size of each base price record - if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= NUM_PRICES) { + if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) { grfmsg(1, "%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer); return; } @@ -1668,8 +1668,8 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, by byte factor = grf_load_byte(&buf); uint price = gvid + i; - if (price < NUM_PRICES) { - SetPriceBaseMultiplier(price, factor); + if (price < PR_END) { + SetPriceBaseMultiplier((Price)price, factor); } else { grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); } diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index fccbb4bf3..cce2d7f2f 100644 --- a/src/saveload/economy_sl.cpp +++ b/src/saveload/economy_sl.cpp @@ -18,9 +18,10 @@ /** Prices in pre 126 savegames */ static void Load_PRIC() { + /* Old games store 49 base prices, very old games store them as int32 */ int vt = CheckSavegameVersion(65) ? SLE_FILE_I32 : SLE_FILE_I64; - SlArray(NULL, NUM_PRICES, vt | SLE_VAR_NULL); - SlArray(NULL, NUM_PRICES, SLE_FILE_U16 | SLE_VAR_NULL); + SlArray(NULL, 49, vt | SLE_VAR_NULL); + SlArray(NULL, 49, SLE_FILE_U16 | SLE_VAR_NULL); } /** Cargo payment rates in pre 126 savegames */ diff --git a/src/table/pricebase.h b/src/table/pricebase.h index d42d2da1f..1eeba1231 100644 --- a/src/table/pricebase.h +++ b/src/table/pricebase.h @@ -9,7 +9,7 @@ /** @file pricebase.h Price Bases */ -static const PriceBaseSpec _price_base_specs[NUM_PRICES] = { +static const PriceBaseSpec _price_base_specs[PR_END] = { { 100, PCAT_NONE }, ///< PR_STATION_VALUE { 100, PCAT_CONSTRUCTION}, ///< PR_BUILD_RAIL { 95, PCAT_CONSTRUCTION}, ///< PR_BUILD_ROAD |