MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetLoadAmount

Function GetLoadAmount

src/economy.cpp:1298–1331  ·  view source on GitHub ↗

* Gets the amount of cargo the given vehicle can load in the current tick. * This is only about loading speed. The free capacity is ignored. * @param v Vehicle to be queried. * @return Amount of cargo the vehicle can load at once. */

Source from the content-addressed store, hash-verified

1296 * @return Amount of cargo the vehicle can load at once.
1297 */
1298static uint GetLoadAmount(Vehicle *v)
1299{
1300 const Engine *e = v->GetEngine();
1301 uint load_amount = e->info.load_amount;
1302
1303 /* The default loadamount for mail is 1/4 of the load amount for passengers */
1304 bool air_mail = v->type == VEH_AIRCRAFT && !Aircraft::From(v)->IsNormalAircraft();
1305 if (air_mail) load_amount = CeilDiv(load_amount, 4);
1306
1307 if (_settings_game.order.gradual_loading) {
1308 uint16_t cb_load_amount = CALLBACK_FAILED;
1309 if (e->GetGRF() != nullptr && e->GetGRF()->grf_version >= 8) {
1310 /* Use callback 36 */
1311 cb_load_amount = GetVehicleProperty(v, PROP_VEHICLE_LOAD_AMOUNT, CALLBACK_FAILED);
1312 } else if (e->info.callback_mask.Test(VehicleCallbackMask::LoadAmount)) {
1313 /* Use callback 12 */
1314 cb_load_amount = GetVehicleCallback(CBID_VEHICLE_LOAD_AMOUNT, 0, 0, v->engine_type, v);
1315 }
1316 if (cb_load_amount != CALLBACK_FAILED) {
1317 if (e->GetGRF()->grf_version < 8) cb_load_amount = GB(cb_load_amount, 0, 8);
1318 if (cb_load_amount >= 0x100) {
1319 ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_LOAD_AMOUNT, cb_load_amount);
1320 } else if (cb_load_amount != 0) {
1321 load_amount = cb_load_amount;
1322 }
1323 }
1324 }
1325
1326 /* Scale load amount the same as capacity */
1327 if (e->info.misc_flags.Test(EngineMiscFlag::NoDefaultCargoMultiplier) && !air_mail) load_amount = CeilDiv(load_amount * CargoSpec::Get(v->cargo_type)->multiplier, 0x100);
1328
1329 /* Zero load amount breaks a lot of things. */
1330 return std::max(1u, load_amount);
1331}
1332
1333/**
1334 * Iterate the articulated parts of a vehicle, also considering the special cases of "normal"

Callers 1

LoadUnloadVehicleFunction · 0.85

Calls 10

CeilDivFunction · 0.85
GetVehiclePropertyFunction · 0.85
GetVehicleCallbackFunction · 0.85
GBFunction · 0.85
IsNormalAircraftMethod · 0.80
TestMethod · 0.80
GetEngineMethod · 0.45
GetGRFMethod · 0.45
GetGRFIDMethod · 0.45

Tested by

no test coverage detected