(svn r18008) -Codechange: Rename NUM_PRICES to PR_END, and use the Price enum some more.

This commit is contained in:
frosch 2009-11-08 12:23:02 +00:00
parent e781929d7f
commit 3f5e42b04a
6 changed files with 23 additions and 20 deletions

View File

@ -109,7 +109,7 @@ int _score_part[MAX_COMPANIES][SCORE_END];
Economy _economy; Economy _economy;
Prices _price; Prices _price;
Money _additional_cash_required; Money _additional_cash_required;
static byte _price_base_multiplier[NUM_PRICES]; static byte _price_base_multiplier[PR_END];
Money CalculateCompanyValue(const Company *c) Money CalculateCompanyValue(const Company *c)
{ {
@ -625,10 +625,8 @@ void RecomputePrices()
/* Setup maximum loan */ /* Setup maximum loan */
_economy.max_loan = (_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / 50000 * 50000; _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 */ /* 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; Money price = _price_base_specs[i].start_price;
/* Apply difficulty settings */ /* Apply difficulty settings */
@ -662,7 +660,7 @@ void RecomputePrices()
} }
/* Store value */ /* Store value */
((Money *)&_price)[i] = price; _price[i] = price;
} }
/* Setup cargo payment */ /* Setup cargo payment */
@ -730,10 +728,8 @@ static void HandleEconomyFluctuations()
*/ */
void ResetPriceBaseMultipliers() void ResetPriceBaseMultipliers()
{ {
uint i;
/* 8 means no multiplier. */ /* 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; _price_base_multiplier[i] = 8;
} }
@ -744,9 +740,9 @@ void ResetPriceBaseMultipliers()
* @param price Index of price base to change. * @param price Index of price base to change.
* @param factor Amount to change by. * @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); _price_base_multiplier[price] = min(factor, MAX_PRICE_MODIFIER);
} }
@ -800,7 +796,7 @@ void InitializeEconomy()
*/ */
Money GetPriceByIndex(Price index) Money GetPriceByIndex(Price index)
{ {
if (index >= NUM_PRICES) return 0; if (index >= PR_END) return 0;
return _price[index]; return _price[index];
} }

View File

@ -23,7 +23,7 @@
#include "station_type.h" #include "station_type.h"
void ResetPriceBaseMultipliers(); void ResetPriceBaseMultipliers();
void SetPriceBaseMultiplier(uint price, byte factor); void SetPriceBaseMultiplier(Price price, byte factor);
extern const ScoreInfo _score_info[]; extern const ScoreInfo _score_info[];
extern int _score_part[MAX_COMPANIES][SCORE_END]; extern int _score_part[MAX_COMPANIES][SCORE_END];

View File

@ -59,7 +59,12 @@ struct ScoreInfo {
int score; ///< How much score it will give 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 { enum Price {
PR_BEGIN = 0,
PR_STATION_VALUE = 0, PR_STATION_VALUE = 0,
PR_BUILD_RAIL, PR_BUILD_RAIL,
PR_BUILD_ROAD, PR_BUILD_ROAD,
@ -110,11 +115,12 @@ enum Price {
PR_RUNNING_SHIP, PR_RUNNING_SHIP,
PR_BUILD_INDUSTRY, PR_BUILD_INDUSTRY,
NUM_PRICES, PR_END,
INVALID_PRICE = 0xFF INVALID_PRICE = 0xFF
}; };
DECLARE_POSTFIX_INCREMENT(Price)
typedef Money Prices[NUM_PRICES]; typedef Money Prices[PR_END];
enum ExpensesType { enum ExpensesType {
EXPENSES_CONSTRUCTION = 0, EXPENSES_CONSTRUCTION = 0,

View File

@ -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 start = 0x4B34; ///< Position of first base price
static const uint32 size = 6; ///< Size of each base price record 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); grfmsg(1, "%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer);
return; return;
} }
@ -1668,8 +1668,8 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, by
byte factor = grf_load_byte(&buf); byte factor = grf_load_byte(&buf);
uint price = gvid + i; uint price = gvid + i;
if (price < NUM_PRICES) { if (price < PR_END) {
SetPriceBaseMultiplier(price, factor); SetPriceBaseMultiplier((Price)price, factor);
} else { } else {
grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price);
} }

View File

@ -18,9 +18,10 @@
/** Prices in pre 126 savegames */ /** Prices in pre 126 savegames */
static void Load_PRIC() 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; int vt = CheckSavegameVersion(65) ? SLE_FILE_I32 : SLE_FILE_I64;
SlArray(NULL, NUM_PRICES, vt | SLE_VAR_NULL); SlArray(NULL, 49, vt | SLE_VAR_NULL);
SlArray(NULL, NUM_PRICES, SLE_FILE_U16 | SLE_VAR_NULL); SlArray(NULL, 49, SLE_FILE_U16 | SLE_VAR_NULL);
} }
/** Cargo payment rates in pre 126 savegames */ /** Cargo payment rates in pre 126 savegames */

View File

@ -9,7 +9,7 @@
/** @file pricebase.h Price Bases */ /** @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_NONE }, ///< PR_STATION_VALUE
{ 100, PCAT_CONSTRUCTION}, ///< PR_BUILD_RAIL { 100, PCAT_CONSTRUCTION}, ///< PR_BUILD_RAIL
{ 95, PCAT_CONSTRUCTION}, ///< PR_BUILD_ROAD { 95, PCAT_CONSTRUCTION}, ///< PR_BUILD_ROAD