1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-21 19:32:54 +01:00

Codechange: make CompanyMask a BaseBitSet implementation

This commit is contained in:
Rubidium
2025-02-08 10:08:36 +01:00
committed by rubidium42
parent e972033e11
commit ec492cb267
27 changed files with 116 additions and 99 deletions

View File

@@ -1549,25 +1549,25 @@ void NetworkUpdateClientInfo(ClientID client_id)
*/
static void NetworkAutoCleanCompanies()
{
CompanyMask has_clients = 0;
CompanyMask has_vehicles = 0;
CompanyMask has_clients{};
CompanyMask has_vehicles{};
if (!_settings_client.network.autoclean_companies) return;
/* Detect the active companies */
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
if (Company::IsValidID(ci->client_playas)) SetBit(has_clients, ci->client_playas);
if (Company::IsValidID(ci->client_playas)) has_clients.Set(ci->client_playas);
}
if (!_network_dedicated) {
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
assert(ci != nullptr);
if (Company::IsValidID(ci->client_playas)) SetBit(has_clients, ci->client_playas);
if (Company::IsValidID(ci->client_playas)) has_clients.Set(ci->client_playas);
}
if (_settings_client.network.autoclean_novehicles != 0) {
for (const Company *c : Company::Iterate()) {
if (std::any_of(std::begin(c->group_all), std::end(c->group_all), [](const GroupStatistics &gs) { return gs.num_vehicle != 0; })) SetBit(has_vehicles, c->index);
if (std::any_of(std::begin(c->group_all), std::end(c->group_all), [](const GroupStatistics &gs) { return gs.num_vehicle != 0; })) has_vehicles.Set(c->index);
}
}
@@ -1576,7 +1576,7 @@ static void NetworkAutoCleanCompanies()
/* Skip the non-active once */
if (c->is_ai) continue;
if (!HasBit(has_clients, c->index)) {
if (!has_clients.Test(c->index)) {
/* The company is empty for one month more */
if (c->months_empty != std::numeric_limits<decltype(c->months_empty)>::max()) c->months_empty++;
@@ -1587,7 +1587,7 @@ static void NetworkAutoCleanCompanies()
IConsolePrint(CC_INFO, "Auto-cleaned company #{}.", c->index + 1);
}
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
if (_settings_client.network.autoclean_novehicles != 0 && c->months_empty > _settings_client.network.autoclean_novehicles && !HasBit(has_vehicles, c->index)) {
if (_settings_client.network.autoclean_novehicles != 0 && c->months_empty > _settings_client.network.autoclean_novehicles && !has_vehicles.Test(c->index)) {
/* Shut the company down */
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID);
IConsolePrint(CC_INFO, "Auto-cleaned company #{} with no vehicles.", c->index + 1);