1
0
Fork 0

Codefix: Engine constructor's base parameter isn't an actual EngineID

pull/13377/head
Rubidium 2025-01-19 14:54:52 +01:00 committed by rubidium42
parent 40ab4e306b
commit e7e9a12817
3 changed files with 18 additions and 18 deletions

View File

@ -68,16 +68,16 @@ const uint8_t _engine_offsets[4] = {
static_assert(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info)); static_assert(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
Engine::Engine(VehicleType type, EngineID base) Engine::Engine(VehicleType type, uint16_t local_id)
{ {
this->type = type; this->type = type;
this->grf_prop.local_id = base; this->grf_prop.local_id = local_id;
this->list_position = base; this->list_position = local_id;
this->preview_company = INVALID_COMPANY; this->preview_company = INVALID_COMPANY;
this->display_last_variant = INVALID_ENGINE; this->display_last_variant = INVALID_ENGINE;
/* Check if this base engine is within the original engine data range */ /* Check if this base engine is within the original engine data range */
if (base >= _engine_counts[type]) { if (local_id >= _engine_counts[type]) {
/* 'power' defaults to zero, so we also have to default to 'wagon' */ /* 'power' defaults to zero, so we also have to default to 'wagon' */
if (type == VEH_TRAIN) this->u.rail.railveh_type = RAILVEH_WAGON; if (type == VEH_TRAIN) this->u.rail.railveh_type = RAILVEH_WAGON;
/* Set model life to maximum to make wagons available */ /* Set model life to maximum to make wagons available */
@ -104,16 +104,16 @@ Engine::Engine(VehicleType type, EngineID base)
} }
/* Copy the original engine info for this slot */ /* Copy the original engine info for this slot */
this->info = _orig_engine_info[_engine_offsets[type] + base]; this->info = _orig_engine_info[_engine_offsets[type] + local_id];
/* Copy the original engine data for this slot */ /* Copy the original engine data for this slot */
switch (type) { switch (type) {
default: NOT_REACHED(); default: NOT_REACHED();
case VEH_TRAIN: case VEH_TRAIN:
this->u.rail = _orig_rail_vehicle_info[base]; this->u.rail = _orig_rail_vehicle_info[local_id];
this->original_image_index = this->u.rail.image_index; this->original_image_index = this->u.rail.image_index;
this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base; this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + local_id;
/* Set the default model life of original wagons to "infinite" */ /* Set the default model life of original wagons to "infinite" */
if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = TimerGameCalendar::Year{0xFF}; if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = TimerGameCalendar::Year{0xFF};
@ -121,21 +121,21 @@ Engine::Engine(VehicleType type, EngineID base)
break; break;
case VEH_ROAD: case VEH_ROAD:
this->u.road = _orig_road_vehicle_info[base]; this->u.road = _orig_road_vehicle_info[local_id];
this->original_image_index = this->u.road.image_index; this->original_image_index = this->u.road.image_index;
this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base; this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + local_id;
break; break;
case VEH_SHIP: case VEH_SHIP:
this->u.ship = _orig_ship_vehicle_info[base]; this->u.ship = _orig_ship_vehicle_info[local_id];
this->original_image_index = this->u.ship.image_index; this->original_image_index = this->u.ship.image_index;
this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base; this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + local_id;
break; break;
case VEH_AIRCRAFT: case VEH_AIRCRAFT:
this->u.air = _orig_aircraft_vehicle_info[base]; this->u.air = _orig_aircraft_vehicle_info[local_id];
this->original_image_index = this->u.air.image_index; this->original_image_index = this->u.air.image_index;
this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base; this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + local_id;
break; break;
} }
} }

View File

@ -83,7 +83,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
std::vector<WagonOverride> overrides; std::vector<WagonOverride> overrides;
Engine() {} Engine() {}
Engine(VehicleType type, EngineID base); Engine(VehicleType type, uint16_t local_id);
bool IsEnabled() const; bool IsEnabled() const;
/** /**

View File

@ -381,10 +381,10 @@ static bool FixTTOEngines()
/* Load the default engine set. Many of them will be overridden later */ /* Load the default engine set. Many of them will be overridden later */
{ {
uint j = 0; uint j = 0;
for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i); for (uint16_t i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i);
for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i); for (uint16_t i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i);
for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i); for (uint16_t i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i);
for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i); for (uint16_t i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i);
} }
TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(TimerGameCalendar::Year{2050}, 0, 1)); TimerGameCalendar::Date aging_date = std::min(TimerGameCalendar::date + CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::ConvertYMDToDate(TimerGameCalendar::Year{2050}, 0, 1));