mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Improve performance when calculating company value (#9901)
parent
8c4a70e05e
commit
b7abaa55a3
|
@ -101,6 +101,8 @@ Economy _economy;
|
||||||
Prices _price;
|
Prices _price;
|
||||||
static PriceMultipliers _price_base_multiplier;
|
static PriceMultipliers _price_base_multiplier;
|
||||||
|
|
||||||
|
extern int GetAmountOwnedBy(const Company *c, Owner owner);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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, shares) and money minus the loan,
|
* assets (vehicles, stations, shares) and money minus the loan,
|
||||||
|
@ -115,18 +117,12 @@ Money CalculateCompanyValue(const Company *c, bool including_loan)
|
||||||
Money owned_shares_value = 0;
|
Money owned_shares_value = 0;
|
||||||
|
|
||||||
for (const Company *co : Company::Iterate()) {
|
for (const Company *co : Company::Iterate()) {
|
||||||
uint8 shares_owned = 0;
|
int shares_owned = GetAmountOwnedBy(co, c->index);
|
||||||
|
|
||||||
for (uint8 i = 0; i < 4; i++) {
|
if (shares_owned > 0) owned_shares_value += (CalculateCompanyValueExcludingShares(co) / 4) * shares_owned;
|
||||||
if (co->share_owners[i] == c->index) {
|
|
||||||
shares_owned++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
owned_shares_value += (CalculateCompanyValueExcludingShares(co) / 4) * shares_owned;
|
return owned_shares_value + CalculateCompanyValueExcludingShares(c);
|
||||||
}
|
|
||||||
|
|
||||||
return std::max<Money>(owned_shares_value + CalculateCompanyValueExcludingShares(c), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Money CalculateCompanyValueExcludingShares(const Company *c, bool including_loan)
|
Money CalculateCompanyValueExcludingShares(const Company *c, bool including_loan)
|
||||||
|
@ -2018,8 +2014,6 @@ static void DoAcquireCompany(Company *c)
|
||||||
delete c;
|
delete c;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int GetAmountOwnedBy(const Company *c, Owner owner);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquire shares in an opposing company.
|
* Acquire shares in an opposing company.
|
||||||
* @param flags type of operation
|
* @param flags type of operation
|
||||||
|
|
Loading…
Reference in New Issue