mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-18 01:42:38 +01:00
Codechange: make CompanyMask a BaseBitSet implementation
This commit is contained in:
@@ -656,12 +656,12 @@ void CalcEngineReliability(Engine *e, bool new_month)
|
||||
if (new_month && re->index > e->index && age != INT32_MAX) age++; /* parent variant's age has not yet updated. */
|
||||
|
||||
/* Check for early retirement */
|
||||
if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
|
||||
if (e->company_avail.Any() && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
|
||||
int retire_early = e->info.retire_early;
|
||||
uint retire_early_max_age = std::max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
|
||||
if (retire_early != 0 && age >= retire_early_max_age) {
|
||||
/* Early retirement is enabled and we're past the date... */
|
||||
e->company_avail = 0;
|
||||
e->company_avail = CompanyMask{};
|
||||
ClearLastVariant(e->index, e->type);
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
}
|
||||
@@ -680,7 +680,7 @@ void CalcEngineReliability(Engine *e, bool new_month)
|
||||
} else {
|
||||
/* time's up for this engine.
|
||||
* We will now completely retire this design */
|
||||
e->company_avail = 0;
|
||||
e->company_avail = CompanyMask{};
|
||||
e->reliability = e->reliability_final;
|
||||
/* Kick this engine out of the lists */
|
||||
ClearLastVariant(e->index, e->type);
|
||||
@@ -721,8 +721,8 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
|
||||
e->age = 0;
|
||||
e->flags = {};
|
||||
e->company_avail = 0;
|
||||
e->company_hidden = 0;
|
||||
e->company_avail = CompanyMask{};
|
||||
e->company_hidden = CompanyMask{};
|
||||
|
||||
/* Vehicles with the same base_intro date shall be introduced at the same time.
|
||||
* Make sure they use the same randomisation of the date. */
|
||||
@@ -788,7 +788,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
/* prevent certain engines from ever appearing. */
|
||||
if (!ei->climates.Test(_settings_game.game_creation.landscape)) {
|
||||
e->flags.Set(EngineFlag::Available);
|
||||
e->company_avail = 0;
|
||||
e->company_avail = CompanyMask{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,7 +833,7 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
|
||||
Engine *e = Engine::Get(eid);
|
||||
Company *c = Company::Get(company);
|
||||
|
||||
SetBit(e->company_avail, company);
|
||||
e->company_avail.Set(company);
|
||||
if (e->type == VEH_TRAIN) {
|
||||
c->avail_railtypes = GetCompanyRailTypes(c->index);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
@@ -861,7 +861,7 @@ static void DisableEngineForCompany(EngineID eid, CompanyID company)
|
||||
Engine *e = Engine::Get(eid);
|
||||
Company *c = Company::Get(company);
|
||||
|
||||
ClrBit(e->company_avail, company);
|
||||
e->company_avail.Reset(company);
|
||||
if (e->type == VEH_TRAIN) {
|
||||
c->avail_railtypes = GetCompanyRailTypes(c->index);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
@@ -921,7 +921,7 @@ static CompanyID GetPreviewCompany(Engine *e)
|
||||
|
||||
int32_t best_hist = -1;
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
|
||||
if (c->block_preview == 0 && !e->preview_asked.Test(c->index) &&
|
||||
c->old_economy[0].performance_history > best_hist) {
|
||||
|
||||
/* Check whether the company uses similar vehicles */
|
||||
@@ -976,7 +976,7 @@ static IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGameCalend
|
||||
CloseWindowById(WC_ENGINE_PREVIEW, i);
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
}
|
||||
} else if (CountBits(e->preview_asked) < MAX_COMPANIES) {
|
||||
} else if (CountBits(e->preview_asked.base()) < MAX_COMPANIES) {
|
||||
e->preview_company = GetPreviewCompany(e);
|
||||
|
||||
if (e->preview_company == INVALID_COMPANY) {
|
||||
@@ -984,7 +984,7 @@ static IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGameCalend
|
||||
continue;
|
||||
}
|
||||
|
||||
SetBit(e->preview_asked, e->preview_company);
|
||||
e->preview_asked.Set(e->preview_company);
|
||||
e->preview_wait = 20;
|
||||
/* AIs are intentionally not skipped for preview even if they cannot build a certain
|
||||
* vehicle type. This is done to not give poor performing human companies an "unfair"
|
||||
@@ -1005,7 +1005,7 @@ static IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGameCalend
|
||||
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
|
||||
{
|
||||
for (Engine *e : Engine::Iterate()) {
|
||||
SB(e->company_hidden, cid, 1, 0);
|
||||
e->company_hidden.Reset(cid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1023,7 +1023,7 @@ CommandCost CmdSetVehicleVisibility(DoCommandFlag flags, EngineID engine_id, boo
|
||||
if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
|
||||
|
||||
if ((flags & DC_EXEC) != 0) {
|
||||
AssignBit(e->company_hidden, _current_company, hide);
|
||||
e->company_hidden.Set(_current_company, hide);
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
}
|
||||
|
||||
@@ -1087,7 +1087,7 @@ static void NewVehicleAvailable(Engine *e)
|
||||
for (Company *c : Company::Iterate()) {
|
||||
uint block_preview = c->block_preview;
|
||||
|
||||
if (!HasBit(e->company_avail, c->index)) continue;
|
||||
if (!e->company_avail.Test(c->index)) continue;
|
||||
|
||||
/* We assume the user did NOT build it.. prove me wrong ;) */
|
||||
c->block_preview = 20;
|
||||
@@ -1178,7 +1178,7 @@ void CalendarEnginesMonthlyLoop()
|
||||
/* Show preview dialog to one of the companies. */
|
||||
e->flags.Set(EngineFlag::ExclusivePreview);
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
e->preview_asked = 0;
|
||||
e->preview_asked = CompanyMask{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1264,10 +1264,10 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
|
||||
/* check if it's available ... */
|
||||
if (company == OWNER_DEITY) {
|
||||
/* ... for any company (preview does not count) */
|
||||
if (!e->flags.Test(EngineFlag::Available) || e->company_avail == 0) return false;
|
||||
if (!e->flags.Test(EngineFlag::Available) || e->company_avail.None()) return false;
|
||||
} else {
|
||||
/* ... for this company */
|
||||
if (!HasBit(e->company_avail, company)) return false;
|
||||
if (!e->company_avail.Test(company)) return false;
|
||||
}
|
||||
|
||||
if (!e->IsEnabled()) return false;
|
||||
@@ -1329,7 +1329,7 @@ void CheckEngines()
|
||||
if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
|
||||
|
||||
/* We have an available engine... yay! */
|
||||
if (e->flags.Test(EngineFlag::Available) && e->company_avail != 0) return;
|
||||
if (e->flags.Test(EngineFlag::Available) && e->company_avail.Any()) return;
|
||||
|
||||
/* Okay, try to find the earliest date. */
|
||||
min_date = std::min(min_date, e->info.base_intro);
|
||||
|
||||
Reference in New Issue
Block a user