summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-04-21 16:49:53 +0000
committeryexo <yexo@openttd.org>2009-04-21 16:49:53 +0000
commit10c98f7e0ecc896af956a10ed392607a7864fef1 (patch)
treef1a5f86d68f6099cc62953f21de8c478698ce767 /src/ai
parent63db874050c4a6c03bb15e773946c465d5027bf2 (diff)
downloadopenttd-10c98f7e0ecc896af956a10ed392607a7864fef1.tar.xz
(svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_order.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index eb48dae39..51ca973ca 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -124,11 +124,36 @@ static OrderType GetOrderTypeByTile(TileIndex t)
}
switch (order->GetType()) {
- case OT_GOTO_DEPOT:
+ case OT_GOTO_DEPOT: {
if (v->type != VEH_AIRCRAFT) return ::GetDepot(order->GetDestination())->xy;
- /* FALL THROUGH: aircraft's hangars are referenced by StationID, not DepotID */
+ /* Aircraft's hangars are referenced by StationID, not DepotID */
+ const Station *st = ::GetStation(order->GetDestination());
+ const AirportFTAClass *airport = st->Airport();
+ if (airport == NULL || airport->nof_depots == 0) return INVALID_TILE;
+ return st->airport_tile + ::ToTileIndexDiff(st->Airport()->airport_depots[0]);
+ }
- case OT_GOTO_STATION: return ::GetStation(order->GetDestination())->xy;
+ case OT_GOTO_STATION: {
+ const Station *st = ::GetStation(order->GetDestination());
+ if (st->train_tile != INVALID_TILE) {
+ for (uint i = 0; i < st->trainst_w; i++) {
+ TileIndex t = st->train_tile + TileDiffXY(i, 0);
+ if (st->TileBelongsToRailStation(t)) return t;
+ }
+ } else if (st->dock_tile != INVALID_TILE) {
+ return st->dock_tile;
+ } else if (st->bus_stops != NULL) {
+ return st->bus_stops->xy;
+ } else if (st->truck_stops != NULL) {
+ return st->truck_stops->xy;
+ } else if (st->airport_tile != INVALID_TILE) {
+ const AirportFTAClass *fta = st->Airport();
+ BEGIN_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile) {
+ if (!::IsHangar(tile)) return tile;
+ } END_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile)
+ }
+ return INVALID_TILE;
+ }
case OT_GOTO_WAYPOINT: return ::GetWaypoint(order->GetDestination())->xy;
default: return INVALID_TILE;
}