Skip to content

Commit

Permalink
Change: Redeploy aircraft from old savegames for the new aircraft con…
Browse files Browse the repository at this point in the history
…troller.
  • Loading branch information
J0anJosep committed May 5, 2024
1 parent b6cdbd0 commit 49e9d57
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/saveload/afterload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "../timer/timer_game_economy.h"
#include "../timer/timer_game_tick.h"
#include "../air.h"
#include "../air_map.h"

#include "saveload_internal.h"

Expand Down Expand Up @@ -3387,9 +3388,57 @@ bool AfterLoadGame()
/* Delete already crashed zeppelins. */
DeleteCrashedZeppelins();

/* We have to destroy all aircraft to completely restart from scratch. */
/* We have to redeploy aircraft. */
for (Aircraft *v : Aircraft::Iterate()) {
if ((v->vehstatus & VS_CRASHED) == 0) v->Crash();
if (!v->IsPrimaryVehicle()) continue;

Aircraft *u = v->Next(); // shadow
assert(u != nullptr);
v->flags = 0;

/* Assign dest_tile. */
v->dest_tile = 0;

int z = v->z_pos;
if ((v->vehstatus & VS_HIDDEN) != 0) {
assert(IsHangarTile(v->tile));
/* Keep aircraft in hangars. */
v->state = AS_HANGAR;
v->dest_tile = v->tile;
v->direction = u->direction = DiagDirToDir(GetHangarDirection(v->tile));
v->trackdir = u->trackdir = DiagDirToDiagTrackdir(GetHangarDirection(v->tile));
v->next_trackdir = INVALID_TRACKDIR;
v->wait_counter = 0;
v->x_pos = (v->x_pos & ~0xF) + 8;
v->y_pos = (v->y_pos & ~0xF) + 8;
v->current_order.Free();
ProcessOrders(v);
} else {
if (v->current_order.IsType(OT_LOADING)) {
ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
v->LeaveStation();
}
v->current_order.Free();
v->state = AS_FLYING;
v->next_trackdir = INVALID_TRACKDIR;
v->UpdateNextTile(INVALID_TILE);
v->trackdir = v->Next()->trackdir = TRACKDIR_X_NE;
v->direction = u->direction = DIR_NE;
v->x_pos = (v->x_pos & ~0xF) + 8;
v->y_pos = (v->y_pos & ~0xF) + 8;
v->tile = TileVirtXY(v->x_pos, v->y_pos);
GetAircraftFlightLevelBounds(v, nullptr, &z);
ProcessOrders(v);
TileIndex next_tile = FindClosestLandingTile(v);
AssignLandingTile(v, next_tile);
if (v->GetNextTile() != INVALID_TILE &&
IsBuiltInHeliportTile(v->GetNextTile()) &&
v->tile == TileAddXY(v->GetNextTile(), 2, 0)) {
v->tile = next_tile;
}
}

SetAircraftPosition(v, v->x_pos, v->y_pos, z);
}

InitializeAirportGui();
Expand Down

0 comments on commit 49e9d57

Please sign in to comment.