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

Method updateCargoSprite

src/OpenLoco/src/Vehicles/VehicleBody.cpp:1390–1416  ·  view source on GitHub ↗

0x004AC039 Note: Vanilla often called this from bogies which would just return immediately

Source from the content-addressed store, hash-verified

1388 // Note: Vanilla often called this from bogies which would
1389 // just return immediately
1390 void VehicleBody::updateCargoSprite()
1391 {
1392 if (objectSpriteType == 0xFF)
1393 {
1394 return;
1395 }
1396 if (primaryCargo.maxQty == 0)
1397 {
1398 return;
1399 }
1400
1401 const auto* vehicleObj = getObject();
1402 auto& bodySprite = vehicleObj->bodySprites[objectSpriteType];
1403
1404 auto percentageFull = std::min((primaryCargo.qty * 256) / primaryCargo.maxQty, 255);
1405 auto spriteIndex = (percentageFull * bodySprite.numCargoLoadFrames) / 256;
1406 if (spriteIndex != 0)
1407 {
1408 spriteIndex += vehicleObj->cargoTypeSpriteOffsets[primaryCargo.type];
1409 }
1410 spriteIndex *= bodySprite.numAnimationFrames;
1411 if (spriteIndex != cargoFrame)
1412 {
1413 cargoFrame = spriteIndex;
1414 invalidateSprite();
1415 }
1416 }
1417
1418 // 0x0042F6B6
1419 // TODO: move this?

Callers 3

updateUnloadCargoMethod · 0.80
updateLoadCargoMethod · 0.80
removeAllCargoFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected