MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetOrderDestination

Method GetOrderDestination

src/script/api/script_order.cpp:241–299  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

239}
240
241/* static */ TileIndex ScriptOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position)
242{
243 if (!IsValidVehicleOrder(vehicle_id, order_position)) return INVALID_TILE;
244
245 const Order *order = ::ResolveOrder(vehicle_id, order_position);
246 if (order == nullptr || order->GetType() == OT_CONDITIONAL) return INVALID_TILE;
247 const Vehicle *v = ::Vehicle::Get(vehicle_id);
248
249 switch (order->GetType()) {
250 case OT_GOTO_DEPOT: {
251 /* We don't know where the nearest depot is... (yet) */
252 if (order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) return INVALID_TILE;
253
254 if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination().ToDepotID())->xy;
255 /* Aircraft's hangars are referenced by StationID, not DepotID */
256 const Station *st = ::Station::Get(order->GetDestination().ToStationID());
257 if (!st->airport.HasHangar()) return INVALID_TILE;
258 return st->airport.GetHangarTile(0);
259 }
260
261 case OT_GOTO_STATION: {
262 const Station *st = ::Station::Get(order->GetDestination().ToStationID());
263 if (st->train_station.tile != INVALID_TILE) {
264 for (TileIndex t : st->train_station) {
265 if (st->TileBelongsToRailStation(t)) return t;
266 }
267 } else if (st->ship_station.tile != INVALID_TILE) {
268 for (TileIndex t : st->ship_station) {
269 if (IsTileType(t, MP_STATION) && (IsDock(t) || IsOilRig(t)) && GetStationIndex(t) == st->index) return t;
270 }
271 } else if (st->bus_stops != nullptr) {
272 return st->bus_stops->xy;
273 } else if (st->truck_stops != nullptr) {
274 return st->truck_stops->xy;
275 } else if (st->airport.tile != INVALID_TILE) {
276 for (TileIndex tile : st->airport) {
277 if (st->TileBelongsToAirport(tile) && !::IsHangar(tile)) return tile;
278 }
279 }
280 return INVALID_TILE;
281 }
282
283 case OT_GOTO_WAYPOINT: {
284 const Waypoint *wp = ::Waypoint::Get(order->GetDestination().ToStationID());
285 if (wp->train_station.tile != INVALID_TILE) {
286 for (TileIndex t : wp->train_station) {
287 if (wp->TileBelongsToRailStation(t)) return t;
288 }
289 } else if (wp->road_waypoint_area.tile != INVALID_TILE) {
290 for (TileIndex t : wp->road_waypoint_area) {
291 if (::IsRoadWaypointTile(t) && ::GetStationIndex(t) == wp->index) return t;
292 }
293 }
294 /* If the waypoint has no rail or road waypoint tiles, it must have a buoy */
295 return wp->xy;
296 }
297 default: return INVALID_TILE;
298 }

Callers

nothing calls this directly

Calls 15

ResolveOrderFunction · 0.85
IsTileTypeFunction · 0.85
IsDockFunction · 0.85
IsOilRigFunction · 0.85
GetStationIndexFunction · 0.85
IsHangarFunction · 0.85
IsRoadWaypointTileFunction · 0.85
TestMethod · 0.80
GetDepotActionTypeMethod · 0.80
ToDepotIDMethod · 0.80
GetDestinationMethod · 0.80
HasHangarMethod · 0.80

Tested by

no test coverage detected