diff --git a/src/core/base_bitset_type.hpp b/src/core/base_bitset_type.hpp index c88bc4b9a8..1505d578da 100644 --- a/src/core/base_bitset_type.hpp +++ b/src/core/base_bitset_type.hpp @@ -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(this->data).begin(); } auto end() const { return SetBitIterator(this->data).end(); } diff --git a/src/economy.cpp b/src/economy.cpp index babfe3801f..9d428bc07c 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -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; } diff --git a/src/engine.cpp b/src/engine.cpp index 37566df260..627c7b9db4 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -976,7 +976,7 @@ static const IntervalTimer _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()) {