mirror of https://github.com/OpenTTD/OpenTTD
Fix: Company values do not properly account for shares (#9770)
Co-authored-by: Charles Pigott <charlespigott@googlemail.com>pull/9895/head
parent
fa562ba041
commit
6540948ace
|
@ -167,6 +167,7 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
|
||||||
};
|
};
|
||||||
|
|
||||||
Money CalculateCompanyValue(const Company *c, bool including_loan = true);
|
Money CalculateCompanyValue(const Company *c, bool including_loan = true);
|
||||||
|
Money CalculateCompanyValueExcludingShares(const Company *c, bool including_loan = true);
|
||||||
|
|
||||||
extern uint _next_competitor_start;
|
extern uint _next_competitor_start;
|
||||||
extern uint _cur_company_tick_index;
|
extern uint _cur_company_tick_index;
|
||||||
|
|
|
@ -103,7 +103,7 @@ static PriceMultipliers _price_base_multiplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the value of the company. That is the value of all
|
* Calculate the value of the company. That is the value of all
|
||||||
* assets (vehicles, stations, etc) and money minus the loan,
|
* assets (vehicles, stations, shares) and money minus the loan,
|
||||||
* except when including_loan is \c false which is useful when
|
* except when including_loan is \c false which is useful when
|
||||||
* we want to calculate the value for bankruptcy.
|
* we want to calculate the value for bankruptcy.
|
||||||
* @param c the company to get the value of.
|
* @param c the company to get the value of.
|
||||||
|
@ -111,6 +111,25 @@ static PriceMultipliers _price_base_multiplier;
|
||||||
* @return the value of the company.
|
* @return the value of the company.
|
||||||
*/
|
*/
|
||||||
Money CalculateCompanyValue(const Company *c, bool including_loan)
|
Money CalculateCompanyValue(const Company *c, bool including_loan)
|
||||||
|
{
|
||||||
|
Money owned_shares_value = 0;
|
||||||
|
|
||||||
|
for (const Company *co : Company::Iterate()) {
|
||||||
|
uint8 shares_owned = 0;
|
||||||
|
|
||||||
|
for (uint8 i = 0; i < 4; i++) {
|
||||||
|
if (co->share_owners[i] == c->index) {
|
||||||
|
shares_owned++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
owned_shares_value += (CalculateCompanyValueExcludingShares(co) / 4) * shares_owned;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::max<Money>(owned_shares_value + CalculateCompanyValueExcludingShares(c), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Money CalculateCompanyValueExcludingShares(const Company *c, bool including_loan)
|
||||||
{
|
{
|
||||||
Owner owner = c->index;
|
Owner owner = c->index;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue