1
0
Fork 0

Compare commits

..

No commits in common. "5869f790d8e926e8b906de91a7aefec29763d579" and "82c87208146e11f26c2dbc1aa647bb38c7da7458" have entirely different histories.

4 changed files with 13 additions and 32 deletions

View File

@ -544,14 +544,13 @@ public:
} }
if (change_class) { if (change_class) {
/* If that fails, select the first available airport /* If that fails, select the first available airport
* from the first class where airports are available. */ * from a random class. */
for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) { for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
AirportClass *apclass = AirportClass::Get(j); AirportClass *apclass = AirportClass::Get(j);
for (uint i = 0; i < apclass->GetSpecCount(); i++) { for (uint i = 0; i < apclass->GetSpecCount(); i++) {
const AirportSpec *as = apclass->GetSpec(i); const AirportSpec *as = apclass->GetSpec(i);
if (as->IsAvailable()) { if (as->IsAvailable()) {
_selected_airport_class = j; _selected_airport_class = j;
this->vscroll->SetCount(apclass->GetSpecCount());
this->SelectOtherAirport(i); this->SelectOtherAirport(i);
return; return;
} }

View File

@ -1422,7 +1422,7 @@ struct BuildVehicleWindow : Window {
list.emplace_back(eid, e->info.variant_id, e->display_flags, 0); list.emplace_back(eid, e->info.variant_id, e->display_flags, 0);
if (rvi->railveh_type != RAILVEH_WAGON) num_engines++; if (rvi->railveh_type != RAILVEH_WAGON) num_engines++;
if (e->info.variant_id != INVALID_ENGINE) variants.push_back(e->info.variant_id); if (e->info.variant_id != eid && e->info.variant_id != INVALID_ENGINE) variants.push_back(e->info.variant_id);
if (eid == this->sel_engine) sel_id = eid; if (eid == this->sel_engine) sel_id = eid;
} }
@ -1654,14 +1654,13 @@ struct BuildVehicleWindow : Window {
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID); Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
} }
/* Update last used variant in hierarchy and refresh if necessary. */ /* Update last used variant and refresh if necessary. */
bool refresh = false; bool refresh = false;
EngineID parent = sel_eng; int recursion = 10; /* In case of infinite loop */
while (parent != INVALID_ENGINE) { for (Engine *e = Engine::Get(sel_eng); recursion > 0; e = Engine::Get(e->info.variant_id), --recursion) {
Engine *e = Engine::Get(parent);
refresh |= (e->display_last_variant != sel_eng); refresh |= (e->display_last_variant != sel_eng);
e->display_last_variant = sel_eng; e->display_last_variant = sel_eng;
parent = e->info.variant_id; if (e->info.variant_id == INVALID_ENGINE) break;
} }
if (refresh) { if (refresh) {
InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window

View File

@ -491,7 +491,7 @@ bool Engine::IsVariantHidden(CompanyID c) const
* the last display variant rather than the actual parent variant. */ * the last display variant rather than the actual parent variant. */
const Engine *re = this; const Engine *re = this;
const Engine *ve = re->GetDisplayVariant(); const Engine *ve = re->GetDisplayVariant();
while (!(ve->IsHidden(c)) && re->info.variant_id != INVALID_ENGINE) { while (!(ve->IsHidden(c)) && re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index) {
re = Engine::Get(re->info.variant_id); re = Engine::Get(re->info.variant_id);
ve = re->GetDisplayVariant(); ve = re->GetDisplayVariant();
} }
@ -607,7 +607,7 @@ void CalcEngineReliability(Engine *e, bool new_month)
{ {
/* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */ /* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */
Engine *re = e; Engine *re = e;
while (re->info.variant_id != INVALID_ENGINE && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) { while (re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
re = Engine::Get(re->info.variant_id); re = Engine::Get(re->info.variant_id);
} }
@ -706,7 +706,7 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
/* Get parent variant index for syncing reliability via random seed. */ /* Get parent variant index for syncing reliability via random seed. */
const Engine *re = e; const Engine *re = e;
while (re->info.variant_id != INVALID_ENGINE && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) { while (re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
re = Engine::Get(re->info.variant_id); re = Engine::Get(re->info.variant_id);
} }

View File

@ -9125,9 +9125,12 @@ static void FinaliseEngineArray()
} }
} }
/* Do final mapping on variant engine ID. */ /* Do final mapping on variant engine ID and set appropriate flags on variant engine */
if (e->info.variant_id != INVALID_ENGINE) { if (e->info.variant_id != INVALID_ENGINE) {
e->info.variant_id = GetNewEngineID(e->grf_prop.grffile, e->type, e->info.variant_id); e->info.variant_id = GetNewEngineID(e->grf_prop.grffile, e->type, e->info.variant_id);
if (e->info.variant_id != INVALID_ENGINE) {
Engine::Get(e->info.variant_id)->display_flags |= EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded;
}
} }
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
@ -9159,26 +9162,6 @@ static void FinaliseEngineArray()
} }
} }
} }
/* Check engine variants don't point back on themselves (either directly or via a loop) then set appropriate flags
* on variant engine. This is performed separately as all variant engines need to have been resolved. */
for (Engine *e : Engine::Iterate()) {
EngineID parent = e->info.variant_id;
while (parent != INVALID_ENGINE) {
parent = Engine::Get(parent)->info.variant_id;
if (parent != e->index) continue;
/* Engine looped back on itself, so clear the variant. */
e->info.variant_id = INVALID_ENGINE;
GrfMsg(1, "FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->index].internal_id, e->GetGRF()->filename);
break;
}
if (e->info.variant_id != INVALID_ENGINE) {
Engine::Get(e->info.variant_id)->display_flags |= EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded;
}
}
} }
/** Check for invalid cargoes */ /** Check for invalid cargoes */