summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-04 14:32:30 +0000
committerrubidium <rubidium@openttd.org>2009-01-04 14:32:30 +0000
commit2283b8038f288d24ca719e482be256229430f53d (patch)
tree292bf3e68143902349c6838a65a40a5ff0b13aa7 /src
parent8c33893ffd5cfcaf3d3a8b0cc24cb1f2be7738ef (diff)
downloadopenttd-2283b8038f288d24ca719e482be256229430f53d.tar.xz
(svn r14825) -Fix: pay the correct amount of interest instead of a few percent too little a year
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index a6fbb55f2..3c220d329 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -639,12 +639,23 @@ static void AddInflation(bool check_year = true)
static void CompaniesPayInterest()
{
const Company *c;
- int interest = _economy.interest_rate * 54;
FOR_ALL_COMPANIES(c) {
_current_company = c->index;
- SubtractMoneyFromCompany(CommandCost(EXPENSES_LOAN_INT, (Money)BigMulSU(c->current_loan, interest, 16)));
+ /* Over a year the paid interest should be "loan * interest percentage",
+ * but... as that number is likely not dividable by 12 (pay each month),
+ * one needs to account for that in the monthly fee calculations.
+ * To easily calculate what one should pay "this" month, you calculate
+ * what (total) should have been paid up to this month and you substract
+ * whatever has been paid in the previous months. This will mean one month
+ * it'll be a bit more and the other it'll be a bit less than the average
+ * monthly fee, but on average it will be exact. */
+ Money yearly_fee = c->current_loan * _economy.interest_rate / 100;
+ Money up_to_previous_month = yearly_fee * _cur_month / 12;
+ Money up_to_this_month = yearly_fee * (_cur_month + 1) / 12;
+
+ SubtractMoneyFromCompany(CommandCost(EXPENSES_LOAN_INT, up_to_this_month - up_to_previous_month));
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, _price.station_value >> 2));
}