static */
| 471 | } |
| 472 | |
| 473 | /* static */ bool ScriptOrder::InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrder::ScriptOrderFlags order_flags) |
| 474 | { |
| 475 | /* IsValidVehicleOrder is not good enough because it does not allow appending. */ |
| 476 | if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); |
| 477 | |
| 478 | EnforceCompanyModeValid(false); |
| 479 | EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); |
| 480 | EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders()); |
| 481 | EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags)); |
| 482 | |
| 483 | Order order; |
| 484 | OrderType ot = (order_flags & OF_GOTO_NEAREST_DEPOT) ? OT_GOTO_DEPOT : ::GetOrderTypeByTile(destination); |
| 485 | switch (ot) { |
| 486 | case OT_GOTO_DEPOT: { |
| 487 | OrderDepotTypeFlags odtf = OrderDepotTypeFlag::PartOfOrders; |
| 488 | if ((order_flags & OF_SERVICE_IF_NEEDED) != 0) odtf.Set(OrderDepotTypeFlag::Service); |
| 489 | |
| 490 | OrderDepotActionFlags odaf{}; |
| 491 | if ((order_flags & OF_STOP_IN_DEPOT) != 0) odaf.Set(OrderDepotActionFlag::Halt); |
| 492 | if ((order_flags & OF_GOTO_NEAREST_DEPOT) != 0) odaf.Set(OrderDepotActionFlag::NearestDepot); |
| 493 | |
| 494 | OrderNonStopFlags onsf{}; |
| 495 | if ((order_flags & OF_NON_STOP_INTERMEDIATE) != 0) onsf.Set(OrderNonStopFlag::NoIntermediate); |
| 496 | if ((order_flags & OF_GOTO_NEAREST_DEPOT) != 0) { |
| 497 | order.MakeGoToDepot(DepotID::Invalid(), odtf, onsf, odaf); |
| 498 | } else { |
| 499 | /* Check explicitly if the order is to a station (for aircraft) or |
| 500 | * to a depot (other vehicle types). */ |
| 501 | if (::Vehicle::Get(vehicle_id)->type == VEH_AIRCRAFT) { |
| 502 | if (!::IsTileType(destination, MP_STATION)) return false; |
| 503 | order.MakeGoToDepot(::GetStationIndex(destination), odtf, onsf, odaf); |
| 504 | } else { |
| 505 | if (::IsTileType(destination, MP_STATION)) return false; |
| 506 | order.MakeGoToDepot(::GetDepotIndex(destination), odtf, onsf, odaf); |
| 507 | } |
| 508 | } |
| 509 | break; |
| 510 | } |
| 511 | |
| 512 | case OT_GOTO_STATION: |
| 513 | order.MakeGoToStation(::GetStationIndex(destination)); |
| 514 | order.SetLoadType(static_cast<OrderLoadType>(GB(order_flags, 5, 3))); |
| 515 | order.SetUnloadType(static_cast<OrderUnloadType>(GB(order_flags, 2, 3))); |
| 516 | order.SetStopLocation(OrderStopLocation::FarEnd); |
| 517 | break; |
| 518 | |
| 519 | case OT_GOTO_WAYPOINT: |
| 520 | order.MakeGoToWaypoint(::GetStationIndex(destination)); |
| 521 | break; |
| 522 | |
| 523 | default: |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | order.SetNonStopType(static_cast<OrderNonStopFlags>(GB(order_flags, 0, 2))); |
| 528 | |
| 529 | int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position); |
| 530 | return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id, order_pos, order); |
nothing calls this directly
no test coverage detected