summaryrefslogtreecommitdiff
path: root/src/economy.cpp
diff options
context:
space:
mode:
authortron <tron@openttd.org>2007-02-23 08:03:30 +0000
committertron <tron@openttd.org>2007-02-23 08:03:30 +0000
commit9cbc49b65be204765e9c4ccb494fb466072b6c14 (patch)
treefe2813897e6077aeba83d429ae7c2ac459f65fbd /src/economy.cpp
parent8ace4dd25c4face9d552a24babffede708e8628d (diff)
downloadopenttd-9cbc49b65be204765e9c4ccb494fb466072b6c14.tar.xz
(svn r8855) -Fix
Change some shift and cast mumbo jumbo for inflation calculation to something remotly comprehensible and explain what the magic number "54" means
Diffstat (limited to 'src/economy.cpp')
-rw-r--r--src/economy.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index c77146419..7575f6e9b 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -613,18 +613,21 @@ static void PlayersGenStatistics(void)
static void AddSingleInflation(int32 *value, uint16 *frac, int32 amt)
{
- int64 tmp = (int64)*value * amt;
- int32 low;
- *frac = (uint16)(low = (uint16)tmp + *frac);
- *value += (int32)(tmp >> 16) + (low >> 16);
+ int64 tmp = (int64)*value * amt + *frac;
+ *frac = GB(tmp, 0, 16);
+ *value += tmp >> 16;
}
static void AddInflation(void)
{
- int i;
+ /* Approximation for (100 + infl_amount)% ** (1 / 12) - 100%
+ * scaled by 65536
+ * 12 -> months per year
+ * This is only a good approxiamtion for small values
+ */
int32 inf = _economy.infl_amount * 54;
- for (i = 0; i != NUM_PRICES; i++) {
+ for (uint i = 0; i != NUM_PRICES; i++) {
AddSingleInflation((int32*)&_price + i, _price_frac + i, inf);
}
@@ -634,7 +637,7 @@ static void AddInflation(void)
_economy.max_loan += 50000;
inf = _economy.infl_amount_pr * 54;
- for (i = 0; i != NUM_CARGO; i++) {
+ for (uint i = 0; i != NUM_CARGO; i++) {
AddSingleInflation(
(int32*)_cargo_payment_rates + i,
_cargo_payment_rates_frac + i,