0x0042F6DB
| 16 | { |
| 17 | // 0x0042F6DB |
| 18 | static uint32_t vehicleRefit(const VehicleRefitArgs& args, const uint8_t flags) |
| 19 | { |
| 20 | setExpenditureType(ExpenditureType::TrainRunningCosts); |
| 21 | |
| 22 | try |
| 23 | { |
| 24 | Vehicles::Vehicle train(args.head); |
| 25 | auto& head = train.head; |
| 26 | |
| 27 | if (!head->canBeModified()) |
| 28 | { |
| 29 | return kFailure; |
| 30 | } |
| 31 | |
| 32 | if (!sub_431E6A(head->owner)) |
| 33 | { |
| 34 | return kFailure; |
| 35 | } |
| 36 | |
| 37 | if (train.cars.empty()) |
| 38 | { |
| 39 | setErrorText(StringIds::empty); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | auto car = train.cars.firstCar; |
| 44 | auto* vehObj = ObjectManager::get<VehicleObject>(car.body->objectId); |
| 45 | |
| 46 | if (!vehObj->hasFlags(VehicleObjectFlags::refittable)) |
| 47 | { |
| 48 | setErrorText(StringIds::empty); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | if (!(flags & Flags::apply)) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | uint16_t maxPrimaryCargo = vehObj->maxCargo[0]; |
| 58 | auto cargoTypes = vehObj->compatibleCargoCategories[0]; |
| 59 | auto primaryCargoId = Numerics::bitScanForward(cargoTypes); |
| 60 | uint16_t maxCargoUnits = Vehicles::getNumUnitsForCargo(maxPrimaryCargo, primaryCargoId, args.cargoType); |
| 61 | |
| 62 | car.body->primaryCargo.type = args.cargoType; |
| 63 | car.body->primaryCargo.maxQty = std::min<uint8_t>(maxCargoUnits, 0xFF); |
| 64 | car.body->primaryCargo.qty = 0; |
| 65 | |
| 66 | auto primaryCargoObj = ObjectManager::get<CargoObject>(args.cargoType); |
| 67 | auto acceptedTypes = 0; |
| 68 | for (uint16_t cargoId = 0; cargoId < ObjectManager::getMaxObjects(ObjectType::cargo); cargoId++) |
| 69 | { |
| 70 | auto cargoObject = ObjectManager::get<CargoObject>(cargoId); |
| 71 | if (cargoObject == nullptr) |
| 72 | { |
| 73 | continue; |
| 74 | } |
| 75 |
nothing calls this directly
no test coverage detected