Skip to content

Instantly share code, notes, and snippets.

@SamuXarick
Created January 3, 2024 20:03
Show Gist options
  • Save SamuXarick/509ce2e915c02f7052219b731b6eae2f to your computer and use it in GitHub Desktop.
Save SamuXarick/509ce2e915c02f7052219b731b6eae2f to your computer and use it in GitHub Desktop.
Problem: the list at line 36 is still the same list defined at line 19. Why?
/**
* Perform a (large) amount of savegame conversion *magic* in order to
* load older savegames and to fill the caches for various purposes.
* @return True iff conversion went without a problem.
*/
bool AfterLoadGame()
{
(...)
/* Wait counter and load/unload ticks got split. */
if (IsSavegameVersionBefore(SLV_136)) {
for (Company *c : Company::Iterate()) {
VehicleList &vehicle_list = c->group_all[VEH_AIRCRAFT].vehicle_list;
for (const Vehicle *v : vehicle_list) {
Aircraft *a = Aircraft::From(Vehicle::Get(v->index));
a->turn_counter = a->current_order.IsType(OT_LOADING) ? 0 : a->load_unload_ticks;
}
vehicle_list = c->group_all[VEH_TRAIN].vehicle_list;
for (const Vehicle *v : vehicle_list) {
Train *t = Train::From(Vehicle::Get(v->index));
t->wait_counter = t->current_order.IsType(OT_LOADING) ? 0 : t->load_unload_ticks;
}
}
}
(...)
/* In old versions it was possible to remove an airport while a plane was
* taking off or landing. This gives all kind of problems when building
* another airport in the same station so we don't allow that anymore.
* For old savegames with such aircraft we just throw them in the air and
* treat the aircraft like they were flying already. */
if (IsSavegameVersionBefore(SLV_146)) {
for (const Company *c : Company::Iterate()) {
const VehicleList &vehicle_list = c->group_all[VEH_AIRCRAFT].vehicle_list;
for (const Vehicle *vehicle : vehicle_list) {
Aircraft *v = Aircraft::From(Vehicle::Get(vehicle->index));
Station *st = GetTargetAirportIfValid(v);
if (st == nullptr && v->state != FLYING) {
v->state = FLYING;
UpdateAircraftCache(v);
AircraftNextAirportPos_and_Order(v);
/* get aircraft back on running altitude */
if ((v->vehstatus & VS_CRASHED) == 0) {
GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
}
}
}
}
}
(...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment