summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/aircraft_cmd.cpp13
-rw-r--r--src/airport.cpp36
-rw-r--r--src/airport.h2
3 files changed, 49 insertions, 2 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index f2d2f8f09..6ca9f1ddd 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -855,8 +855,17 @@ static bool AircraftController(Aircraft *v)
const Station *st = Station::GetIfValid(v->targetairport);
/* INVALID_TILE if there is no station */
TileIndex tile = INVALID_TILE;
+ Direction rotation = DIR_N;
+ uint size_x = 1, size_y = 1;
if (st != NULL) {
- tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
+ if (st->airport.tile != INVALID_TILE) {
+ tile = st->airport.tile;
+ rotation = st->airport.rotation;
+ size_x = st->airport.w;
+ size_y = st->airport.h;
+ } else {
+ tile = st->xy;
+ }
}
/* DUMMY if there is no station or no airport */
const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
@@ -878,7 +887,7 @@ static bool AircraftController(Aircraft *v)
}
/* get airport moving data */
- const AirportMovingData amd = *afc->MovingData(v->pos);
+ const AirportMovingData amd = RotateAirportMovingData(afc->MovingData(v->pos), rotation, size_x, size_y);
int x = TileX(tile) * TILE_SIZE;
int y = TileY(tile) * TILE_SIZE;
diff --git a/src/airport.cpp b/src/airport.cpp
index 24b1bad11..6be9c0039 100644
--- a/src/airport.cpp
+++ b/src/airport.cpp
@@ -151,6 +151,42 @@ static byte AirportTestFTA(uint nofelements, const AirportFTA *layout, const byt
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report);
#endif
+/**
+ * Rotate the airport moving data to another rotation.
+ * @param orig Pointer to the moving data to rotate.
+ * @param rotation How to rotate the moving data.
+ * @return The rotated moving data.
+ */
+AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y)
+{
+ AirportMovingData amd;
+ amd.flag = orig->flag;
+ amd.direction = ChangeDir(orig->direction, (DirDiff)rotation);
+ switch (rotation) {
+ case DIR_N:
+ amd.x = orig->x;
+ amd.y = orig->y;
+ break;
+
+ case DIR_E:
+ amd.x = orig->y;
+ amd.y = num_tiles_y * TILE_SIZE - orig->x - 1;
+ break;
+
+ case DIR_S:
+ amd.x = num_tiles_x * TILE_SIZE - orig->x - 1;
+ amd.y = num_tiles_y * TILE_SIZE - orig->y - 1;
+ break;
+
+ case DIR_W:
+ amd.x = num_tiles_x * TILE_SIZE - orig->y - 1;
+ amd.y = orig->x;
+ break;
+
+ default: NOT_REACHED();
+ }
+ return amd;
+}
AirportFTAClass::AirportFTAClass(
const AirportMovingData *moving_data_,
diff --git a/src/airport.h b/src/airport.h
index 288a79a05..e91bdb1bd 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -136,6 +136,8 @@ struct AirportMovingData {
DirectionByte direction; ///< Direction to turn the aircraft after reaching this position.
};
+AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y);
+
struct AirportFTAbuildup;
/** Finite sTate mAchine --> FTA */