mirror of https://github.com/OpenTTD/OpenTTD
(svn r3032) -NewGRF, Feature: Add support for changing base prices.
parent
d678a12445
commit
c78e87d4da
32
economy.c
32
economy.c
|
@ -768,6 +768,33 @@ static const int32 _price_base[NUM_PRICES] = {
|
||||||
1000000, // build_industry
|
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)
|
void StartupEconomy(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -784,6 +811,11 @@ void StartupEconomy(void)
|
||||||
price = price * 9 >> 3;
|
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;
|
((int32*)&_price)[i] = price;
|
||||||
_price_frac[i] = 0;
|
_price_frac[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#ifndef ECONOMY_H
|
#ifndef ECONOMY_H
|
||||||
#define ECONOMY_H
|
#define ECONOMY_H
|
||||||
|
|
||||||
|
void ResetPriceBaseMultipliers(void);
|
||||||
|
void SetPriceBaseMultiplier(int price, byte factor);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Maximum possible loan
|
// Maximum possible loan
|
||||||
int32 max_loan;
|
int32 max_loan;
|
||||||
|
|
27
newgrf.c
27
newgrf.c
|
@ -16,6 +16,7 @@
|
||||||
#include "newgrf.h"
|
#include "newgrf.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
#include "bridge.h"
|
#include "bridge.h"
|
||||||
|
#include "economy.h"
|
||||||
|
|
||||||
/* TTDPatch extended GRF format codec
|
/* TTDPatch extended GRF format codec
|
||||||
* (c) Petr Baudis 2004 (GPL'd)
|
* (c) Petr Baudis 2004 (GPL'd)
|
||||||
|
@ -51,6 +52,7 @@ typedef enum grfspec_feature {
|
||||||
GSF_CANAL,
|
GSF_CANAL,
|
||||||
GSF_BRIDGE,
|
GSF_BRIDGE,
|
||||||
GSF_TOWNHOUSE,
|
GSF_TOWNHOUSE,
|
||||||
|
GSF_GLOBALVAR,
|
||||||
} grfspec_feature;
|
} grfspec_feature;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1058,6 +1060,27 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len)
|
||||||
|
{
|
||||||
|
byte *buf = *bufp;
|
||||||
|
int i;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
switch (prop) {
|
||||||
|
case 0x08: { /* Cost base factor */
|
||||||
|
FOR_EACH_OBJECT {
|
||||||
|
byte factor = grf_load_byte(&buf);
|
||||||
|
|
||||||
|
SetPriceBaseMultiplier(gvid + i, factor);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
*bufp = buf;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Action 0x00 */
|
/* Action 0x00 */
|
||||||
static void VehicleChangeInfo(byte *buf, int len)
|
static void VehicleChangeInfo(byte *buf, int len)
|
||||||
{
|
{
|
||||||
|
@ -1086,6 +1109,7 @@ static void VehicleChangeInfo(byte *buf, int len)
|
||||||
/* GSF_CANAL */ NULL,
|
/* GSF_CANAL */ NULL,
|
||||||
/* GSF_BRIDGE */ BridgeChangeInfo,
|
/* GSF_BRIDGE */ BridgeChangeInfo,
|
||||||
/* GSF_TOWNHOUSE */NULL,
|
/* GSF_TOWNHOUSE */NULL,
|
||||||
|
/* GSF_GLOBALVAR */GlobalVarChangeInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8 feature;
|
uint8 feature;
|
||||||
|
@ -2354,6 +2378,9 @@ static void ResetNewGRFData(void)
|
||||||
// Unload sprite group data
|
// Unload sprite group data
|
||||||
UnloadWagonOverrides();
|
UnloadWagonOverrides();
|
||||||
UnloadCustomEngineSprites();
|
UnloadCustomEngineSprites();
|
||||||
|
|
||||||
|
// Reset price base data
|
||||||
|
ResetPriceBaseMultipliers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitNewGRFFile(const char* filename, int sprite_offset)
|
static void InitNewGRFFile(const char* filename, int sprite_offset)
|
||||||
|
|
Loading…
Reference in New Issue