MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / updateLoadCargoComponent

Method updateLoadCargoComponent

src/OpenLoco/src/Vehicles/VehicleHead.cpp:3327–3487  ·  view source on GitHub ↗

0x004BA19D

Source from the content-addressed store, hash-verified

3325
3326 // 0x004BA19D
3327 bool VehicleHead::updateLoadCargoComponent(VehicleCargo& cargo, VehicleBogie* bogie)
3328 {
3329 if (cargo.maxQty == 0)
3330 {
3331 return false;
3332 }
3333 if (stationId == StationId::null)
3334 {
3335 return false;
3336 }
3337
3338 uint8_t loadingModifier = getLoadingModifier(bogie);
3339
3340 auto* station = StationManager::get(stationId);
3341 auto orders = getCurrentOrders();
3342 if (cargo.qty == 0)
3343 {
3344 // bitmask of cargo to wait for
3345 uint32_t cargoToWaitFor = 0;
3346 for (auto& order : orders)
3347 {
3348 auto* waitFor = order.as<OrderWaitFor>();
3349 if (waitFor != nullptr)
3350 {
3351 cargoToWaitFor |= (1 << waitFor->getCargo());
3352 }
3353 if (order.hasFlags(OrderFlags::IsRoutable))
3354 {
3355 break;
3356 }
3357 }
3358 // bitmask of all cargo from orders
3359 uint32_t allPossibleCargoToWaitFor = 0;
3360 for (auto& order : orders)
3361 {
3362 auto* waitFor = order.as<OrderWaitFor>();
3363 if (waitFor != nullptr)
3364 {
3365 allPossibleCargoToWaitFor |= (1 << waitFor->getCargo());
3366 }
3367 }
3368 if (allPossibleCargoToWaitFor == 0)
3369 {
3370 allPossibleCargoToWaitFor = 0xFFFFFFFF;
3371 }
3372
3373 auto acceptedCargo = cargo.acceptedTypes;
3374 uint8_t chosenCargo = 0xFF;
3375 uint16_t highestQty = 0;
3376 for (; acceptedCargo != 0;)
3377 {
3378 auto possibleCargo = Numerics::bitScanForward(acceptedCargo);
3379 acceptedCargo &= ~(1 << possibleCargo);
3380
3381 if (!(allPossibleCargoToWaitFor & (1 << possibleCargo)))
3382 {
3383 continue;
3384 }

Callers

nothing calls this directly

Calls 9

bitScanForwardFunction · 0.85
distance2DFunction · 0.85
getCurrentDayFunction · 0.85
enumValueFunction · 0.85
getCargoMethod · 0.80
getFunction · 0.50
invalidateFunction · 0.50
hasFlagsMethod · 0.45

Tested by

no test coverage detected