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

Method tryCreateInitialMovementSound

src/OpenLoco/src/Vehicles/VehicleHead.cpp:2646–2679  ·  view source on GitHub ↗

0x004B980A

Source from the content-addressed store, hash-verified

2644
2645 // 0x004B980A
2646 void VehicleHead::tryCreateInitialMovementSound(const Status initialStatus)
2647 {
2648 if (status != Status::travelling)
2649 {
2650 return;
2651 }
2652
2653 if (initialStatus != Status::stopped && initialStatus != Status::waitingAtSignal)
2654 {
2655 return;
2656 }
2657
2658 Vehicle train(head);
2659 const auto* vehObj = train.cars.firstCar.body->getObject();
2660 if (vehObj != nullptr && vehObj->numStartSounds != 0)
2661 {
2662 auto numSounds = vehObj->numStartSounds & NumStartSounds::kMask;
2663 if (vehObj->numStartSounds & NumStartSounds::kHasCrossingWhistle)
2664 {
2665 // remove the crossing whistle from available sounds to play
2666 numSounds = std::max(numSounds - 1, 1);
2667 }
2668 auto randSoundIndex = gPrng1().randNext(numSounds - 1);
2669 auto randSoundId = Audio::makeObjectSoundId(vehObj->startSounds[randSoundIndex]);
2670 Vehicle2* veh2 = train.veh2;
2671 auto tileHeight = TileManager::getHeight(veh2->position);
2672 auto volume = 0;
2673 if (veh2->position.z < tileHeight.landHeight)
2674 {
2675 volume = -1500;
2676 }
2677 Audio::playSound(randSoundId, Audio::ChannelId::vehicles, veh2->position + World::Pos3{ 0, 0, 22 }, volume, 22050);
2678 }
2679 }
2680
2681 // 0x004B996F
2682 void VehicleHead::setStationVisitedTypes()

Callers

nothing calls this directly

Calls 5

makeObjectSoundIdFunction · 0.85
getHeightFunction · 0.85
playSoundFunction · 0.85
getObjectMethod · 0.45
randNextMethod · 0.45

Tested by

no test coverage detected