1
0
Fork 0

Codechange: Add Count() method to BaseBitSet.

pull/14266/head
Peter Nelson 2025-05-13 20:09:26 +01:00 committed by Peter Nelson
parent ecc3438519
commit 66c16a1d1f
3 changed files with 12 additions and 3 deletions

View File

@ -230,6 +230,15 @@ public:
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 end() const { return SetBitIterator<Tvalue_type>(this->data).end(); }

View File

@ -119,7 +119,7 @@ static Money CalculateCompanyAssetValue(const Company *c)
uint num = 0;
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;
@ -240,7 +240,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
uint num = 0;
for (const Station *st : Station::Iterate()) {
/* 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;
}

View File

@ -976,7 +976,7 @@ static const IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGame
CloseWindowById(WC_ENGINE_PREVIEW, i);
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);
if (e->preview_company == CompanyID::Invalid()) {