| 37 | } |
| 38 | |
| 39 | static uint32_t cloneVehicle(EntityId head, uint8_t flags) |
| 40 | { |
| 41 | Vehicles::Vehicle existingTrain(head); |
| 42 | Vehicles::VehicleHead* newHead = nullptr; |
| 43 | |
| 44 | // Get total cost for a new vehicle |
| 45 | if (!(flags & Flags::apply)) |
| 46 | { |
| 47 | uint32_t totalCost = 0; |
| 48 | for (auto& car : existingTrain.cars) |
| 49 | { |
| 50 | VehicleCreateArgs args{}; |
| 51 | args.vehicleId = EntityId::null; |
| 52 | args.vehicleType = car.front->objectId; |
| 53 | |
| 54 | const auto cost = doCommand(args, 0); |
| 55 | if (cost == kFailure) |
| 56 | { |
| 57 | totalCost = kFailure; |
| 58 | break; |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | totalCost += cost; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (totalCost == kFailure) |
| 67 | { |
| 68 | return kFailure; |
| 69 | } |
| 70 | return totalCost; |
| 71 | } |
| 72 | |
| 73 | uint16_t cargoType = 0; |
| 74 | uint32_t totalCost = 0; |
| 75 | for (auto& car : existingTrain.cars) |
| 76 | { |
| 77 | uint32_t cost = 0; |
| 78 | if (newHead == nullptr) |
| 79 | { |
| 80 | VehicleCreateArgs args{}; |
| 81 | args.vehicleId = EntityId::null; |
| 82 | args.vehicleType = car.front->objectId; |
| 83 | |
| 84 | cost = doCommand(args, Flags::apply); |
| 85 | cargoType = car.body->primaryCargo.type; |
| 86 | |
| 87 | auto* newVeh = EntityManager::get<Vehicles::VehicleBase>(getLegacyReturnState().lastCreatedVehicleId); |
| 88 | if (newVeh == nullptr) |
| 89 | { |
| 90 | return kFailure; |
| 91 | } |
| 92 | newHead = EntityManager::get<Vehicles::VehicleHead>(newVeh->getHead()); |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | VehicleCreateArgs args{}; |
nothing calls this directly
no test coverage detected