Mercurial > hg > openttd
diff src/ai/api/ai_order.cpp @ 11721:c92611d86f13 draft
(svn r16109) -Fix [NoAI]: Make sure AIOrder::GetDestination always returns a tile belonging to the station
author | yexo <yexo@openttd.org> |
---|---|
date | Tue, 21 Apr 2009 16:49:53 +0000 (2009-04-21) |
parents | 4ffde677f62e |
children | 34e40a741e56 |
line wrap: on
line diff
--- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -124,11 +124,36 @@ } 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; }