summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-01-24 11:05:26 +0000
committerrubidium <rubidium@openttd.org>2010-01-24 11:05:26 +0000
commit3d0b3818ddd1c9f825b81596e89a1b1a6baeb975 (patch)
treed43d57e5de1072570ba2de8fd796354e827a6742
parentb2f9b0ac43a7cf1d6bea1328f3c129912f998492 (diff)
downloadopenttd-3d0b3818ddd1c9f825b81596e89a1b1a6baeb975.tar.xz
(svn r18908) -Fix [FS#3561]: on bankruptcy the company value did include the loan and as such the value at which you bought the company was too low
-rw-r--r--src/company_base.h2
-rw-r--r--src/economy.cpp15
2 files changed, 13 insertions, 4 deletions
diff --git a/src/company_base.h b/src/company_base.h
index e43186d85..16fc622c1 100644
--- a/src/company_base.h
+++ b/src/company_base.h
@@ -107,7 +107,7 @@ struct Company : CompanyPool::PoolItem<&_company_pool> {
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
-Money CalculateCompanyValue(const Company *c);
+Money CalculateCompanyValue(const Company *c, bool including_loan = true);
extern uint _next_competitor_start;
extern uint _cur_company_tick_index;
diff --git a/src/economy.cpp b/src/economy.cpp
index 0f814e0cf..8711011cd 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -110,7 +110,16 @@ Prices _price;
Money _additional_cash_required;
static PriceMultipliers _price_base_multiplier;
-Money CalculateCompanyValue(const Company *c)
+/**
+ * Calculate the value of the company. That is the value of all
+ * assets (vehicles, stations, etc) and money minus the loan,
+ * except when including_loan is \c false which is useful when
+ * we want to calculate the value for bankruptcy.
+ * @param c the company to get the value of.
+ * @param including_loan include the loan in the company value.
+ * @return the value of the company.
+ */
+Money CalculateCompanyValue(const Company *c, bool including_loan)
{
Owner owner = c->index;
Money value = 0;
@@ -137,7 +146,7 @@ Money CalculateCompanyValue(const Company *c)
}
/* Add real money value */
- value -= c->current_loan;
+ if (including_loan) value -= c->current_loan;
value += c->money;
return max(value, (Money)1);
@@ -507,7 +516,7 @@ static void CompanyCheckBankrupt(Company *c)
case 3: {
/* Check if the company has any value.. if not, declare it bankrupt
* right now */
- Money val = CalculateCompanyValue(c);
+ Money val = CalculateCompanyValue(c, false);
if (val > 0) {
c->bankrupt_value = val;
c->bankrupt_asked = 1 << c->index; // Don't ask the owner