* 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. */
| 1461 | * @return True if the aircraft has enough range for the orders, false otherwise. |
| 1462 | */ |
| 1463 | static 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. |
no test coverage detected