private void HandleHoverSounds() { if (!TimeCircuits.IsFlying) { return; } // Play acceleration sound if (IsBoosting) { if (_engineAccell2Sound.IsAnyInstancePlaying) { if (_engineAccell2Sound.Last?.PlayPosition >= 7000) { _engineAccell2Sound.Play(); } } else { _engineAccell2Sound.Play(); } } else { _engineAccell2Sound.Stop(); } // Play deceleration sound if (Game.IsControlPressed(Control.VehicleBrake) && Speed > 15 && Utils.EntitySpeedVector(Vehicle).Y > 0) { if (!_engineDecellSound.IsAnyInstancePlaying || _engineDecellSound.Last?.PlayPosition > 1000) { _engineDecellSound.Play(); } } else { _engineDecellSound.Stop(); } }
private void HandleRegularSounds() { if (TimeCircuits.IsFlying) { return; } // Play Idle sound if (IsIdle) { if (!_engineIdleSound.IsAnyInstancePlaying) { _engineIdleSound.Play(); } } else { _engineIdleSound.Stop(); } // Play revving sound if (IsRevving) { if (!_engineRevvingSound.IsAnyInstancePlaying || _engineRevvingSound.Last?.PlayPosition > 1000 && !_isRevPlayed) { _engineRevvingSound.Play(); _isRevPlayed = true; } } else { _isRevPlayed = false; } // Play deceleration sound if (IsBreaking && Speed > 30 && !Utils.IsAnyTireBurst(Vehicle) && !Game.IsControlPressed(Control.VehicleAccelerate) && !Vehicle.IsInWater) { if (!_engineDecellSound.IsAnyInstancePlaying || _engineDecellSound.Last?.PlayPosition > 1000) { _engineDecellSound.Play(); } } else { _engineDecellSound.Stop(); } // Play reverse sound if (IsReversing && WheelSpeed < -3 && _possibleFastAccel && !Utils.IsAnyTireBurst(Vehicle) && !Vehicle.IsInWater) { if (!_engineReverseSound.IsAnyInstancePlaying) { _engineReverseSound.Play(); } } else { _engineReverseSound.Stop(); } }
public override void Process() { if (_engineSounds.Any(x => x == null)) { return; } if (Vehicle.IsVisible == false || !Vehicle.IsEngineRunning || !ModSettings.PlayEngineSounds) { Stop(); return; } // Update wheel positions _wheelPos = new List <Vector3> { Vehicle.Bones["wheel_lf"].Position, Vehicle.Bones["wheel_rf"].Position, Vehicle.Bones["wheel_rr"].Position, Vehicle.Bones["wheel_lr"].Position }; // Slower interval works more correct on high speed _checkInterval = Speed > 5 ? 250 : 25; // Acceleration prediction, cuz if angle is too high e.g. > 6 car wont drive fast, // or if its not all wheels / on dirt PredictAccleration(); // Get speed of rear wheel because delorean is rear wheel drive so // we can accurately detect acceleration GetAccelerationSound(); // Parse some engine info CheckIdle(); CheckRevving(); CheckDecelerration(); CheckNeutral(); CheckReverse(); // Parse engine information just before check CheckGear(); if (Game.GameTime > _check - 5) { CheckAcceleration(); Acceleration = VehicleAcceleration() * 100; } // Simulate Doppler Effect _engineSounds.ForEach(x => x.Velocity = Vehicle.Velocity); // Play neutral sound if (Speed > 35) { if (!_engineNeutralSound.IsAnyInstancePlaying) { _engineNeutralSound.Play(); } } else { _engineNeutralSound.Stop(); } HandleRegularSounds(); HandleHoverSounds(); // We don't process acceleration each tick // because we won't get accurate results if (Game.GameTime < _check) { return; } HandleAccelerationSound(); // Show engine information on screen Debug(-1); // Re-check acceleration and reset timer if (Game.GameTime <= _check) { return; } _prevAccel = Utils.Magnitude(Vehicle.Velocity); // Next time check _check = Game.GameTime + _checkInterval; }