mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: make VehicleType a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
b90aefbf49
commit
77403627a8
+68
-68
@@ -58,7 +58,7 @@ static TimerGameCalendar::Year _year_engine_aging_stops;
|
||||
uint8_t GetOriginalEngineCount(VehicleType type)
|
||||
{
|
||||
/** Number of engines of each vehicle type in original engine data */
|
||||
static constexpr uint8_t ENGINE_COUNTS[VEH_COMPANY_END] = {
|
||||
static constexpr VehicleTypeIndexArray<uint8_t> ENGINE_COUNTS = {
|
||||
lengthof(_orig_rail_vehicle_info),
|
||||
lengthof(_orig_road_vehicle_info),
|
||||
lengthof(_orig_ship_vehicle_info),
|
||||
@@ -77,7 +77,7 @@ uint8_t GetOriginalEngineCount(VehicleType type)
|
||||
uint8_t GetOriginalEngineOffset(VehicleType type)
|
||||
{
|
||||
/** Offset of the first engine of each vehicle type in original engine data */
|
||||
static constexpr uint8_t ENGINE_OFFSETS[VEH_COMPANY_END] = {
|
||||
static constexpr VehicleTypeIndexArray<uint8_t> ENGINE_OFFSETS = {
|
||||
0,
|
||||
lengthof(_orig_rail_vehicle_info),
|
||||
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
|
||||
@@ -95,7 +95,7 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
|
||||
this->type = type;
|
||||
|
||||
/* Called in the context of loading a savegame. The rest comes from the loader. */
|
||||
if (type == VEH_INVALID) return;
|
||||
if (type == VehicleType::Invalid) return;
|
||||
|
||||
this->grf_prop.local_id = local_id;
|
||||
this->list_position = local_id;
|
||||
@@ -106,17 +106,17 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
|
||||
if (local_id >= GetOriginalEngineCount(type)) {
|
||||
/* Initialise default type-specific information. */
|
||||
switch (type) {
|
||||
case VEH_TRAIN: this->vehicle_info.emplace<RailVehicleInfo>(); break;
|
||||
case VEH_ROAD: this->vehicle_info.emplace<RoadVehicleInfo>(); break;
|
||||
case VEH_SHIP: this->vehicle_info.emplace<ShipVehicleInfo>(); break;
|
||||
case VEH_AIRCRAFT: this->vehicle_info.emplace<AircraftVehicleInfo>(); break;
|
||||
case VehicleType::Train: this->vehicle_info.emplace<RailVehicleInfo>(); break;
|
||||
case VehicleType::Road: this->vehicle_info.emplace<RoadVehicleInfo>(); break;
|
||||
case VehicleType::Ship: this->vehicle_info.emplace<ShipVehicleInfo>(); break;
|
||||
case VehicleType::Aircraft: this->vehicle_info.emplace<AircraftVehicleInfo>(); break;
|
||||
default: break;
|
||||
}
|
||||
/* Set model life to maximum to make wagons available */
|
||||
this->info.base_life = TimerGameCalendar::Year{0xFF};
|
||||
/* Aircraft must have CT_INVALID as default, as there is no property */
|
||||
this->info.cargo_type = INVALID_CARGO;
|
||||
this->info.cargo_label = (type == VEH_AIRCRAFT) ? CT_INVALID : CT_PASSENGERS;
|
||||
this->info.cargo_label = (type == VehicleType::Aircraft) ? CT_INVALID : CT_PASSENGERS;
|
||||
/* Set cargo aging period to the default value. */
|
||||
this->info.cargo_age_period = Ticks::CARGO_AGING_TICKS;
|
||||
/* Not a variant */
|
||||
@@ -131,7 +131,7 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
|
||||
switch (type) {
|
||||
default: NOT_REACHED();
|
||||
|
||||
case VEH_TRAIN: {
|
||||
case VehicleType::Train: {
|
||||
RailVehicleInfo &rvi = this->vehicle_info.emplace<RailVehicleInfo>(_orig_rail_vehicle_info[local_id]);
|
||||
this->original_image_index = rvi.image_index;
|
||||
this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + local_id;
|
||||
@@ -142,21 +142,21 @@ Engine::Engine(EngineID index, VehicleType type, uint16_t local_id) : EnginePool
|
||||
break;
|
||||
}
|
||||
|
||||
case VEH_ROAD: {
|
||||
case VehicleType::Road: {
|
||||
RoadVehicleInfo &rvi = this->vehicle_info.emplace<RoadVehicleInfo>(_orig_road_vehicle_info[local_id]);
|
||||
this->original_image_index = rvi.image_index;
|
||||
this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + local_id;
|
||||
break;
|
||||
}
|
||||
|
||||
case VEH_SHIP: {
|
||||
case VehicleType::Ship: {
|
||||
ShipVehicleInfo &svi = this->vehicle_info.emplace<ShipVehicleInfo>(_orig_ship_vehicle_info[local_id]);
|
||||
this->original_image_index = svi.image_index;
|
||||
this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + local_id;
|
||||
break;
|
||||
}
|
||||
|
||||
case VEH_AIRCRAFT: {
|
||||
case VehicleType::Aircraft: {
|
||||
AircraftVehicleInfo &avi = this->vehicle_info.emplace<AircraftVehicleInfo>(_orig_aircraft_vehicle_info[local_id]);
|
||||
this->original_image_index = avi.image_index;
|
||||
this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + local_id;
|
||||
@@ -198,16 +198,16 @@ bool Engine::CanCarryCargo() const
|
||||
* Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
|
||||
*/
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
if (this->VehInfo<RailVehicleInfo>().capacity == 0) return false;
|
||||
break;
|
||||
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
if (this->VehInfo<RoadVehicleInfo>().capacity == 0) return false;
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Ship:
|
||||
case VehicleType::Aircraft:
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -234,7 +234,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
|
||||
CargoType default_cargo = this->GetDefaultCargoType();
|
||||
CargoType cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
|
||||
|
||||
if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CargoClass::Passengers)) {
|
||||
if (mail_capacity != nullptr && this->type == VehicleType::Aircraft && IsCargoInClass(cargo_type, CargoClass::Passengers)) {
|
||||
*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->VehInfo<AircraftVehicleInfo>().mail_capacity, v);
|
||||
}
|
||||
|
||||
@@ -249,22 +249,22 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
|
||||
uint capacity;
|
||||
uint extra_mail_cap = 0;
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->VehInfo<RailVehicleInfo>().capacity, v);
|
||||
|
||||
/* In purchase list add the capacity of the second head. Always use the plain property for this. */
|
||||
if (v == nullptr && this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD) capacity += this->VehInfo<RailVehicleInfo>().capacity;
|
||||
break;
|
||||
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->VehInfo<RoadVehicleInfo>().capacity, v);
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
case VehicleType::Ship:
|
||||
capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->VehInfo<ShipVehicleInfo>().capacity, v);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Aircraft:
|
||||
capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->VehInfo<AircraftVehicleInfo>().passenger_capacity, v);
|
||||
if (!IsCargoInClass(cargo_type, CargoClass::Passengers)) {
|
||||
extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->VehInfo<AircraftVehicleInfo>().mail_capacity, v);
|
||||
@@ -285,7 +285,7 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const
|
||||
}
|
||||
|
||||
/* Apply multipliers depending on cargo- and vehicletype. */
|
||||
if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) {
|
||||
if (new_multipliers || (this->type != VehicleType::Ship && default_cargo != cargo_type)) {
|
||||
uint16_t default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier;
|
||||
uint16_t cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier;
|
||||
capacity *= cargo_multiplier;
|
||||
@@ -308,24 +308,24 @@ Money Engine::GetRunningCost() const
|
||||
Price base_price;
|
||||
uint cost_factor;
|
||||
switch (this->type) {
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
base_price = this->VehInfo<RoadVehicleInfo>().running_cost_class;
|
||||
if (base_price == Price::Invalid) return 0;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->VehInfo<RoadVehicleInfo>().running_cost);
|
||||
break;
|
||||
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
base_price = this->VehInfo<RailVehicleInfo>().running_cost_class;
|
||||
if (base_price == Price::Invalid) return 0;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->VehInfo<RailVehicleInfo>().running_cost);
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
case VehicleType::Ship:
|
||||
base_price = Price::RunningShip;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->VehInfo<ShipVehicleInfo>().running_cost);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Aircraft:
|
||||
base_price = Price::RunningAircraft;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->VehInfo<AircraftVehicleInfo>().running_cost);
|
||||
break;
|
||||
@@ -345,12 +345,12 @@ Money Engine::GetCost() const
|
||||
Price base_price;
|
||||
uint cost_factor;
|
||||
switch (this->type) {
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
base_price = Price::BuildVehicleRoad;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->VehInfo<RoadVehicleInfo>().cost_factor);
|
||||
break;
|
||||
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
if (this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
|
||||
base_price = Price::BuildVehicleWagon;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo<RailVehicleInfo>().cost_factor);
|
||||
@@ -360,12 +360,12 @@ Money Engine::GetCost() const
|
||||
}
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
case VehicleType::Ship:
|
||||
base_price = Price::BuildVehicleShip;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->VehInfo<ShipVehicleInfo>().cost_factor);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Aircraft:
|
||||
base_price = Price::BuildVehicleAircraft;
|
||||
cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->VehInfo<AircraftVehicleInfo>().cost_factor);
|
||||
break;
|
||||
@@ -383,18 +383,18 @@ Money Engine::GetCost() const
|
||||
uint Engine::GetDisplayMaxSpeed() const
|
||||
{
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->VehInfo<RailVehicleInfo>().max_speed);
|
||||
|
||||
case VEH_ROAD: {
|
||||
case VehicleType::Road: {
|
||||
uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0);
|
||||
return (max_speed != 0) ? max_speed * 2 : this->VehInfo<RoadVehicleInfo>().max_speed / 2;
|
||||
}
|
||||
|
||||
case VEH_SHIP:
|
||||
case VehicleType::Ship:
|
||||
return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->VehInfo<ShipVehicleInfo>().max_speed) / 2;
|
||||
|
||||
case VEH_AIRCRAFT: {
|
||||
case VehicleType::Aircraft: {
|
||||
uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0);
|
||||
if (max_speed != 0) {
|
||||
return (max_speed * 128) / 10;
|
||||
@@ -416,9 +416,9 @@ uint Engine::GetPower() const
|
||||
{
|
||||
/* Only trains and road vehicles have 'power'. */
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->VehInfo<RailVehicleInfo>().power);
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->VehInfo<RoadVehicleInfo>().power) * 10;
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -434,9 +434,9 @@ uint Engine::GetDisplayWeight() const
|
||||
{
|
||||
/* Only trains and road vehicles have 'weight'. */
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->VehInfo<RailVehicleInfo>().weight) << (this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->VehInfo<RoadVehicleInfo>().weight) / 4;
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -452,9 +452,9 @@ uint Engine::GetDisplayMaxTractiveEffort() const
|
||||
{
|
||||
/* Only trains and road vehicles have 'tractive effort'. */
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
case VehicleType::Train:
|
||||
return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->VehInfo<RailVehicleInfo>().tractive_effort)) / 256;
|
||||
case VEH_ROAD:
|
||||
case VehicleType::Road:
|
||||
return (GROUND_ACCELERATION * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->VehInfo<RoadVehicleInfo>().tractive_effort)) / 256;
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -479,7 +479,7 @@ uint16_t Engine::GetRange() const
|
||||
{
|
||||
if (!_settings_game.vehicle.aircraft_range) return 0;
|
||||
switch (this->type) {
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Aircraft:
|
||||
return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->VehInfo<AircraftVehicleInfo>().max_range);
|
||||
|
||||
default: NOT_REACHED();
|
||||
@@ -493,7 +493,7 @@ uint16_t Engine::GetRange() const
|
||||
StringID Engine::GetAircraftTypeText() const
|
||||
{
|
||||
switch (this->type) {
|
||||
case VEH_AIRCRAFT:
|
||||
case VehicleType::Aircraft:
|
||||
switch (this->VehInfo<AircraftVehicleInfo>().subtype) {
|
||||
case AIR_HELI: return STR_LIVERY_HELICOPTER;
|
||||
case AIR_CTOL: return STR_LIVERY_SMALL_PLANE;
|
||||
@@ -535,7 +535,7 @@ bool Engine::IsVariantHidden(CompanyID c) const
|
||||
void EngineOverrideManager::ResetToDefaultMapping()
|
||||
{
|
||||
EngineID id = EngineID::Begin();
|
||||
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
|
||||
for (VehicleType type = VehicleType::Train; type <= VehicleType::Aircraft; type++) {
|
||||
auto &map = this->mappings[type];
|
||||
map.clear();
|
||||
for (uint internal_id = 0; internal_id < GetOriginalEngineCount(type); internal_id++, ++id) {
|
||||
@@ -629,7 +629,7 @@ void SetupEngines()
|
||||
CloseWindowByClass(WC_ENGINE_PREVIEW);
|
||||
_engine_pool.CleanPool();
|
||||
|
||||
for (VehicleType type = VEH_BEGIN; type != VEH_COMPANY_END; type++) {
|
||||
for (VehicleType type = VehicleType::Begin; type != VehicleType::CompanyEnd; type++) {
|
||||
const auto &mapping = _engine_mngr.mappings[type];
|
||||
|
||||
/* Verify that the engine override manager has at least been set up with the default engines. */
|
||||
@@ -651,7 +651,7 @@ void ShowEnginePreviewWindow(EngineID engine);
|
||||
static bool IsWagon(EngineID index)
|
||||
{
|
||||
const Engine *e = Engine::Get(index);
|
||||
return e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON;
|
||||
return e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -727,7 +727,7 @@ void SetYearEngineAgingStops()
|
||||
|
||||
/* Exclude certain engines */
|
||||
if (!ei->climates.Test(_settings_game.game_creation.landscape)) continue;
|
||||
if (e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
|
||||
if (e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
|
||||
|
||||
/* Base year ending date on half the model life */
|
||||
TimerGameCalendar::YearMonthDay ymd = TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength.base() * CalendarTime::DAYS_IN_LEAP_YEAR) / 2);
|
||||
@@ -757,7 +757,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
SaveRandomSeeds(&saved_seeds);
|
||||
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
|
||||
ei->base_intro.base() ^
|
||||
e->type ^
|
||||
to_underlying(e->type) ^
|
||||
e->GetGRFID());
|
||||
uint32_t r = Random();
|
||||
|
||||
@@ -784,7 +784,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym
|
||||
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
|
||||
(re->index.base() << 16) ^ (re->info.base_intro.base() << 12) ^ (re->info.decay_speed << 8) ^
|
||||
(re->info.lifelength.base() << 4) ^ re->info.retire_early ^
|
||||
e->type ^
|
||||
to_underlying(e->type) ^
|
||||
e->GetGRFID());
|
||||
|
||||
/* Base reliability defined as a percentage of UINT16_MAX. */
|
||||
@@ -861,9 +861,9 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
|
||||
Company *c = Company::Get(company);
|
||||
|
||||
e->company_avail.Set(company);
|
||||
if (e->type == VEH_TRAIN) {
|
||||
if (e->type == VehicleType::Train) {
|
||||
c->avail_railtypes = GetCompanyRailTypes(c->index);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
} else if (e->type == VehicleType::Road) {
|
||||
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
|
||||
}
|
||||
|
||||
@@ -872,9 +872,9 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
|
||||
|
||||
/* Update the toolbar. */
|
||||
InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
||||
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
if (e->type == VehicleType::Road) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VehicleType::Ship) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -889,9 +889,9 @@ static void DisableEngineForCompany(EngineID eid, CompanyID company)
|
||||
Company *c = Company::Get(company);
|
||||
|
||||
e->company_avail.Reset(company);
|
||||
if (e->type == VEH_TRAIN) {
|
||||
if (e->type == VehicleType::Train) {
|
||||
c->avail_railtypes = GetCompanyRailTypes(c->index);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
} else if (e->type == VehicleType::Road) {
|
||||
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
|
||||
}
|
||||
|
||||
@@ -944,7 +944,7 @@ static CompanyID GetPreviewCompany(Engine *e)
|
||||
CompanyID best_company = CompanyID::Invalid();
|
||||
|
||||
/* For trains the cargomask has no useful meaning, since you can attach other wagons */
|
||||
CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
|
||||
CargoTypes cargomask = e->type != VehicleType::Train ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES;
|
||||
|
||||
int32_t best_hist = -1;
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
@@ -976,10 +976,10 @@ static CompanyID GetPreviewCompany(Engine *e)
|
||||
static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
|
||||
{
|
||||
switch (type) {
|
||||
case VEH_TRAIN: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
|
||||
case VEH_ROAD: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
|
||||
case VEH_SHIP: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
|
||||
case VEH_AIRCRAFT: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
|
||||
case VehicleType::Train: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
|
||||
case VehicleType::Road: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
|
||||
case VehicleType::Ship: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
|
||||
case VehicleType::Aircraft: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -1132,12 +1132,12 @@ static void NewVehicleAvailable(Engine *e)
|
||||
/* Do not introduce new rail wagons */
|
||||
if (IsWagon(index)) return;
|
||||
|
||||
if (e->type == VEH_TRAIN) {
|
||||
if (e->type == VehicleType::Train) {
|
||||
/* maybe make another rail type available */
|
||||
assert(e->VehInfo<RailVehicleInfo>().railtypes != RailTypes{});
|
||||
RailTypes introduced = GetAllIntroducesRailTypes(e->VehInfo<RailVehicleInfo>().railtypes);
|
||||
for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | introduced, TimerGameCalendar::date);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
} else if (e->type == VehicleType::Road) {
|
||||
/* maybe make another road type available */
|
||||
assert(e->VehInfo<RoadVehicleInfo>().roadtype < ROADTYPE_END);
|
||||
for (Company *c : Company::Iterate()) c->avail_roadtypes = AddDateIntroducedRoadTypes(c->avail_roadtypes | GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->introduces_roadtypes, TimerGameCalendar::date);
|
||||
@@ -1155,9 +1155,9 @@ static void NewVehicleAvailable(Engine *e)
|
||||
}
|
||||
|
||||
/* Update the toolbar. */
|
||||
if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VEH_AIRCRAFT) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
if (e->type == VehicleType::Road) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD);
|
||||
if (e->type == VehicleType::Ship) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
|
||||
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_AIR);
|
||||
|
||||
/* Remove from preview windows */
|
||||
InvalidateWindowClassesData(WC_ENGINE_PREVIEW);
|
||||
@@ -1292,12 +1292,12 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
|
||||
|
||||
if (!e->IsEnabled()) return false;
|
||||
|
||||
if (type == VEH_TRAIN && company != OWNER_DEITY) {
|
||||
if (type == VehicleType::Train && company != OWNER_DEITY) {
|
||||
/* Check if the rail type is available to this company */
|
||||
const Company *c = Company::Get(company);
|
||||
if (!GetAllCompatibleRailTypes(e->VehInfo<RailVehicleInfo>().railtypes).Any(c->avail_railtypes)) return false;
|
||||
}
|
||||
if (type == VEH_ROAD && company != OWNER_DEITY) {
|
||||
if (type == VehicleType::Road && company != OWNER_DEITY) {
|
||||
/* Check if the road type is available to this company */
|
||||
const Company *c = Company::Get(company);
|
||||
if (!GetRoadTypeInfo(e->VehInfo<RoadVehicleInfo>().roadtype)->powered_roadtypes.Any(c->avail_roadtypes)) return false;
|
||||
@@ -1344,7 +1344,7 @@ void CheckEngines()
|
||||
if (!e->IsEnabled()) continue;
|
||||
|
||||
/* Don't consider train wagons, we need a powered engine available. */
|
||||
if (e->type == VEH_TRAIN && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
|
||||
if (e->type == VehicleType::Train && e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) continue;
|
||||
|
||||
/* We have an available engine... yay! */
|
||||
if (e->flags.Test(EngineFlag::Available) && e->company_avail.Any()) return;
|
||||
|
||||
Reference in New Issue
Block a user