mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add Count() method to BaseBitSet.
parent
ecc3438519
commit
66c16a1d1f
|
@ -230,6 +230,15 @@ public:
|
||||||
return (this->base() & Tmask) == this->base();
|
return (this->base() & Tmask) == this->base();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count the number of set bits.
|
||||||
|
* @return The number of bits set to true.
|
||||||
|
*/
|
||||||
|
inline uint Count() const
|
||||||
|
{
|
||||||
|
return CountBits(this->base());
|
||||||
|
}
|
||||||
|
|
||||||
auto begin() const { return SetBitIterator<Tvalue_type>(this->data).begin(); }
|
auto begin() const { return SetBitIterator<Tvalue_type>(this->data).begin(); }
|
||||||
auto end() const { return SetBitIterator<Tvalue_type>(this->data).end(); }
|
auto end() const { return SetBitIterator<Tvalue_type>(this->data).end(); }
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ static Money CalculateCompanyAssetValue(const Company *c)
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
|
|
||||||
for (const Station *st : Station::Iterate()) {
|
for (const Station *st : Station::Iterate()) {
|
||||||
if (st->owner == owner) num += CountBits(st->facilities.base());
|
if (st->owner == owner) num += st->facilities.Count();
|
||||||
}
|
}
|
||||||
|
|
||||||
Money value = num * _price[PR_STATION_VALUE] * 25;
|
Money value = num * _price[PR_STATION_VALUE] * 25;
|
||||||
|
@ -240,7 +240,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
for (const Station *st : Station::Iterate()) {
|
for (const Station *st : Station::Iterate()) {
|
||||||
/* Only count stations that are actually serviced */
|
/* Only count stations that are actually serviced */
|
||||||
if (st->owner == owner && (st->time_since_load <= 20 || st->time_since_unload <= 20)) num += CountBits(st->facilities.base());
|
if (st->owner == owner && (st->time_since_load <= 20 || st->time_since_unload <= 20)) num += st->facilities.Count();
|
||||||
}
|
}
|
||||||
_score_part[owner][SCORE_STATIONS] = num;
|
_score_part[owner][SCORE_STATIONS] = num;
|
||||||
}
|
}
|
||||||
|
|
|
@ -976,7 +976,7 @@ static const IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGame
|
||||||
CloseWindowById(WC_ENGINE_PREVIEW, i);
|
CloseWindowById(WC_ENGINE_PREVIEW, i);
|
||||||
e->preview_company = CompanyID::Invalid();
|
e->preview_company = CompanyID::Invalid();
|
||||||
}
|
}
|
||||||
} else if (CountBits(e->preview_asked.base()) < MAX_COMPANIES) {
|
} else if (e->preview_asked.Count() < MAX_COMPANIES) {
|
||||||
e->preview_company = GetPreviewCompany(e);
|
e->preview_company = GetPreviewCompany(e);
|
||||||
|
|
||||||
if (e->preview_company == CompanyID::Invalid()) {
|
if (e->preview_company == CompanyID::Invalid()) {
|
||||||
|
|
Loading…
Reference in New Issue