mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
Codechange: Use EnumBitSet for EngineFlags.
This commit is contained in:
parent
6c4ddb242a
commit
f8b1e3033f
@ -355,7 +355,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
|
||||
u->random_bits = Random();
|
||||
|
||||
v->vehicle_flags = 0;
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
@ -720,7 +720,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
const EngineInfo *ei = &e->info;
|
||||
|
||||
e->age = 0;
|
||||
e->flags = 0;
|
||||
e->flags = {};
|
||||
e->company_avail = 0;
|
||||
e->company_hidden = 0;
|
||||
|
||||
@ -745,7 +745,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
if (intro_ymd.day > 1) intro_months++; // Engines are introduced at the first month start at/after intro date.
|
||||
e->age = aging_months - intro_months;
|
||||
e->company_avail = MAX_UVALUE(CompanyMask);
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->flags.Set(EngineFlag::Available);
|
||||
}
|
||||
|
||||
/* Get parent variant index for syncing reliability via random seed. */
|
||||
@ -787,7 +787,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
|
||||
/* prevent certain engines from ever appearing. */
|
||||
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) {
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->flags.Set(EngineFlag::Available);
|
||||
e->company_avail = 0;
|
||||
}
|
||||
}
|
||||
@ -970,7 +970,7 @@ static IntervalTimer<TimerGameCalendar> _calendar_engines_daily({TimerGameCalend
|
||||
|
||||
for (Engine *e : Engine::Iterate()) {
|
||||
EngineID i = e->index;
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) {
|
||||
if (e->preview_company != INVALID_COMPANY) {
|
||||
if (!--e->preview_wait) {
|
||||
CloseWindowById(WC_ENGINE_PREVIEW, i);
|
||||
@ -1040,7 +1040,7 @@ CommandCost CmdSetVehicleVisibility(DoCommandFlag flags, EngineID engine_id, boo
|
||||
CommandCost CmdWantEnginePreview(DoCommandFlag flags, EngineID engine_id)
|
||||
{
|
||||
Engine *e = Engine::GetIfValid(engine_id);
|
||||
if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
|
||||
if (e == nullptr || !e->flags.Test(EngineFlag::ExclusivePreview) || e->preview_company != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) AcceptEnginePreview(engine_id, _current_company);
|
||||
|
||||
@ -1083,7 +1083,7 @@ static void NewVehicleAvailable(Engine *e)
|
||||
|
||||
/* In case the company didn't build the vehicle during the intro period,
|
||||
* prevent that company from getting future intro periods for a while. */
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
uint block_preview = c->block_preview;
|
||||
|
||||
@ -1105,7 +1105,7 @@ static void NewVehicleAvailable(Engine *e)
|
||||
}
|
||||
}
|
||||
|
||||
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
|
||||
e->flags.Reset(EngineFlag::ExclusivePreview).Set(EngineFlag::Available);
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
|
||||
/* Now available for all companies */
|
||||
@ -1150,7 +1150,7 @@ void CalendarEnginesMonthlyLoop()
|
||||
bool refresh = false;
|
||||
for (Engine *e : Engine::Iterate()) {
|
||||
/* Age the vehicle */
|
||||
if ((e->flags & ENGINE_AVAILABLE) && e->age != INT32_MAX) {
|
||||
if (e->flags.Test(EngineFlag::Available) && e->age != INT32_MAX) {
|
||||
e->age++;
|
||||
CalcEngineReliability(e, true);
|
||||
refresh = true;
|
||||
@ -1159,10 +1159,10 @@ void CalendarEnginesMonthlyLoop()
|
||||
/* Do not introduce invalid engines */
|
||||
if (!e->IsEnabled()) continue;
|
||||
|
||||
if (!(e->flags & ENGINE_AVAILABLE) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) {
|
||||
if (!e->flags.Test(EngineFlag::Available) && TimerGameCalendar::date >= (e->intro_date + CalendarTime::DAYS_IN_YEAR)) {
|
||||
/* Introduce it to all companies */
|
||||
NewVehicleAvailable(e);
|
||||
} else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && TimerGameCalendar::date >= e->intro_date) {
|
||||
} else if (!e->flags.Any({EngineFlag::Available, EngineFlag::ExclusivePreview}) && TimerGameCalendar::date >= e->intro_date) {
|
||||
/* Introduction date has passed...
|
||||
* Check if it is allowed to build this vehicle type at all
|
||||
* based on the current game settings. If not, it does not
|
||||
@ -1176,7 +1176,7 @@ void CalendarEnginesMonthlyLoop()
|
||||
if (e->info.extra_flags.Test(ExtraEngineFlag::NoPreview)) continue;
|
||||
|
||||
/* Show preview dialog to one of the companies. */
|
||||
e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
|
||||
e->flags.Set(EngineFlag::ExclusivePreview);
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
e->preview_asked = 0;
|
||||
}
|
||||
@ -1264,7 +1264,7 @@ 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 & ENGINE_AVAILABLE) || e->company_avail == 0) return false;
|
||||
if (!e->flags.Test(EngineFlag::Available) || e->company_avail == 0) return false;
|
||||
} else {
|
||||
/* ... for this company */
|
||||
if (!HasBit(e->company_avail, company)) 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 & ENGINE_AVAILABLE) != 0 && e->company_avail != 0) return;
|
||||
if (e->flags.Test(EngineFlag::Available) && e->company_avail != 0) return;
|
||||
|
||||
/* Okay, try to find the earliest date. */
|
||||
min_date = std::min(min_date, e->info.base_intro);
|
||||
|
@ -53,7 +53,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
|
||||
uint16_t duration_phase_1; ///< First reliability phase in months, increasing reliability from #reliability_start to #reliability_max.
|
||||
uint16_t duration_phase_2; ///< Second reliability phase in months, keeping #reliability_max.
|
||||
uint16_t duration_phase_3; ///< Third reliability phase in months, decaying to #reliability_final.
|
||||
uint8_t flags; ///< Flags of the engine. @see EngineFlags
|
||||
EngineFlags flags; ///< Flags of the engine. @see EngineFlags
|
||||
|
||||
CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company.
|
||||
uint8_t preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company.
|
||||
|
@ -187,10 +187,11 @@ struct EngineInfo {
|
||||
/**
|
||||
* Engine.flags is a bitmask, with the following values.
|
||||
*/
|
||||
enum EngineFlags : uint8_t {
|
||||
ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone.
|
||||
ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
|
||||
enum class EngineFlag : uint8_t {
|
||||
Available = 1, ///< This vehicle is available to everyone.
|
||||
ExclusivePreview = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
|
||||
};
|
||||
using EngineFlags = EnumBitSet<EngineFlag, uint8_t>;
|
||||
|
||||
/**
|
||||
* Contexts an engine name can be shown in.
|
||||
|
@ -557,7 +557,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
||||
return (cs->classes << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type];
|
||||
}
|
||||
|
||||
case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
|
||||
case 0x48: return v->GetEngine()->flags.base(); // Vehicle Type Info
|
||||
case 0x49: return v->build_year.base();
|
||||
|
||||
case 0x4A:
|
||||
@ -957,7 +957,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
|
||||
return 0x000000FF;
|
||||
}
|
||||
}
|
||||
case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
|
||||
case 0x48: return Engine::Get(this->self_type)->flags.base(); // Vehicle Type Info
|
||||
case 0x49: return TimerGameCalendar::year.base(); // 'Long' format build year
|
||||
case 0x4B: return TimerGameCalendar::date.base(); // Long date of last service
|
||||
case 0x92: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service
|
||||
|
@ -312,7 +312,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin
|
||||
v->compatible_roadtypes = rti->powered_roadtypes;
|
||||
v->gcache.cached_veh_length = VEHICLE_LENGTH;
|
||||
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
AddArticulatedParts(v);
|
||||
|
@ -107,7 +107,7 @@ struct ENGNChunkHandler : ChunkHandler {
|
||||
if (IsSavegameVersionBefore(SLV_179)) {
|
||||
/* preview_company_rank was replaced with preview_company and preview_asked.
|
||||
* Just cancel any previews. */
|
||||
e->flags &= ~4; // ENGINE_OFFER_WINDOW_OPEN
|
||||
e->flags.Reset(EngineFlag{4}); // ENGINE_OFFER_WINDOW_OPEN
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
e->preview_asked = MAX_UVALUE(CompanyMask);
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ static bool FixTTOEngines()
|
||||
|
||||
/* Make sure for example monorail and maglev are available when they should be */
|
||||
if (TimerGameCalendar::date >= e->intro_date && HasBit(e->info.climates, 0)) {
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->flags.Set(EngineFlag::Available);
|
||||
e->company_avail = MAX_UVALUE(CompanyMask);
|
||||
e->age = TimerGameCalendar::date > e->intro_date ? (TimerGameCalendar::date - e->intro_date).base() / 30 : 0;
|
||||
}
|
||||
@ -432,7 +432,7 @@ static bool FixTTOEngines()
|
||||
for (uint j = 0; j < lengthof(tto_to_ttd); j++) {
|
||||
if (tto_to_ttd[j] == i && _old_engines[j].company_avail != 0) {
|
||||
e->company_avail = MAX_UVALUE(CompanyMask);
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->flags.Set(EngineFlag::Available);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, V
|
||||
v->acceleration = svi->acceleration;
|
||||
v->UpdateCache();
|
||||
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->InvalidateNewGRFCacheOfChain();
|
||||
|
@ -796,7 +796,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engin
|
||||
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
|
||||
v->random_bits = Random();
|
||||
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
|
||||
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);
|
||||
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
|
Loading…
Reference in New Issue
Block a user