From 10c98f7e0ecc896af956a10ed392607a7864fef1 Mon Sep 17 00:00:00 2001 From: yexo Date: Tue, 21 Apr 2009 16:49:53 +0000 Subject: (svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station --- src/ai/api/ai_order.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/ai') 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; } -- cgit v1.2.3-54-g00ecf