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

Function CheckAircraftOrderDistance

src/order_cmd.cpp:1463–1487  ·  view source on GitHub ↗

* Check if an aircraft has enough range for an order list. * @param v_new Aircraft to check. * @param v_order Vehicle currently holding the order list. * @param first First order in the source order list. * @return True if the aircraft has enough range for the orders, false otherwise. */

Source from the content-addressed store, hash-verified

1461 * @return True if the aircraft has enough range for the orders, false otherwise.
1462 */
1463static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order)
1464{
1465 if (v_new->acache.cached_max_range == 0) return true;
1466 if (v_order->GetNumOrders() == 0) return true;
1467
1468 const OrderList &orderlist = *v_order->orders;
1469 auto orders = orderlist.GetOrders();
1470
1471 /* Iterate over all orders to check the distance between all
1472 * 'goto' orders and their respective next order (of any type). */
1473 for (VehicleOrderID cur = 0; cur < orderlist.GetNumOrders(); ++cur) {
1474 switch (orders[cur].GetType()) {
1475 case OT_GOTO_STATION:
1476 case OT_GOTO_DEPOT:
1477 case OT_GOTO_WAYPOINT:
1478 /* If we don't have a next order, we've reached the end and must check the first order instead. */
1479 if (GetOrderDistance(cur, orderlist.GetNext(cur), v_order) > v_new->acache.cached_max_range_sqr) return false;
1480 break;
1481
1482 default: break;
1483 }
1484 }
1485
1486 return true;
1487}
1488
1489/**
1490 * Clone/share/copy an order-list of another vehicle.

Callers 1

CmdCloneOrderFunction · 0.85

Calls 5

GetOrderDistanceFunction · 0.85
GetOrdersMethod · 0.80
GetNextMethod · 0.80
GetNumOrdersMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected