public static ShipState GetState(ShipStateEnum shipState) { ShipManager shipMan = ShipManager.GetInstance(); ShipState pShipState = null; switch (shipState) { case ShipStateEnum.Ready: pShipState = shipMan.pReadyState; break; case ShipStateEnum.MissileFlying: pShipState = shipMan.pMissileFlyingState; break; case ShipStateEnum.End: pShipState = shipMan.pEndState; break; default: Debug.Assert(false); break; } return(pShipState); }
public void Update() { if (m_initialized && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false && (m_shipThrusters != null || m_shipWheels != null) && m_distanceToShip < m_definition.MaxUpdateRange_sq && m_groupData != null) { //calculate current ship state bool driving = ((DateTime.UtcNow - m_lastContactWithGround).TotalSeconds <= 0.2f); float shipSpeed = driving == false ? m_shipGrid.Physics.LinearVelocity.Length() : (m_shipGrid.Physics.LinearVelocity * m_groupData.WheelsSpeedCompensation).Length(); ShipStateEnum lastState = m_shipState; if (m_shipGrid.GridSystems.ResourceDistributor.ResourceState == MyResourceStateEnum.NoPower || m_isDebris || ((m_shipThrusters == null || m_shipThrusters.ThrustCount <= 0) && (m_shipWheels == null || m_shipWheels.WheelCount <= 0))) { m_shipState = ShipStateEnum.NoPower; } else { if (shipSpeed < m_definition.SpeedThreshold1) m_shipState = ShipStateEnum.Slow; else if (shipSpeed < m_definition.SpeedThreshold2) m_shipState = ShipStateEnum.Medium; else m_shipState = ShipStateEnum.Fast; } //in first person change bool orig = m_shouldPlay2D; if (m_shipGrid.GridSizeEnum == MyCubeSize.Large) m_shouldPlay2D = m_insideShip; else if (MySession.Static.ControlledEntity != null && MySession.Static.IsCameraUserControlledSpectator() == false && MySession.Static.ControlledEntity.Entity != null && MySession.Static.ControlledEntity.Entity.Parent == m_shipGrid) { m_shouldPlay2D = ((MySession.Static.ControlledEntity.Entity is MyCockpit) && (MySession.Static.ControlledEntity.Entity as MyCockpit).IsInFirstPersonView) || ((MySession.Static.ControlledEntity.Entity is MyRemoteControl) && MySession.Static.LocalCharacter != null && MySession.Static.LocalCharacter.IsUsing is MyCockpit && (MySession.Static.LocalCharacter.IsUsing as MyCockpit).Parent == m_shipGrid) || (MySession.Static.CameraController is MyCameraBlock && (MySession.Static.CameraController as MyCameraBlock).Parent == m_shipGrid); } else m_shouldPlay2D = false; m_shouldPlay2DChanged = (orig != m_shouldPlay2D); //thruster volume corrections for (int i = 0; i < m_thrusterVolumes.Length; i++) { if (m_thrusterVolumes[i] < m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Min(m_thrusterVolumes[i] + m_groupData.ThrusterCompositionChangeSpeed, m_thrusterVolumeTargets[i]); } else if (m_thrusterVolumes[i] > m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Max(m_thrusterVolumes[i] - m_groupData.ThrusterCompositionChangeSpeed, m_thrusterVolumeTargets[i]); } } if (driving) { m_wheelVolumeModifierEngine = Math.Min(m_wheelVolumeModifierEngine + 0.01f, 1f); m_wheelVolumeModifierWheels = Math.Min(m_wheelVolumeModifierWheels + 0.03f, 1f); } else { m_wheelVolumeModifierEngine = Math.Max(m_wheelVolumeModifierEngine - 0.005f, 0f); m_wheelVolumeModifierWheels = Math.Max(m_wheelVolumeModifierWheels - 0.03f, 0f); } //play sounds if there was change in state, ship type or thruster composition if (m_shipState != lastState || m_categoryChange || m_forceSoundCheck) { if (m_shipState == ShipStateEnum.NoPower) { if (m_shipState != lastState) { for (int i = 0; i < m_emitters.Length; i++) m_emitters[i].StopSound(false); m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = 1f; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesEnd); } } else { if (m_shipState == ShipStateEnum.Slow) PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopSlow); else if (m_shipState == ShipStateEnum.Medium) PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopMedium); else if (m_shipState == ShipStateEnum.Fast) PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopFast); PlayShipSound(ShipEmitters.ShipEngine, ShipSystemSoundsEnum.ShipEngine); PlayShipSound(ShipEmitters.ShipIdle, ShipSystemSoundsEnum.ShipIdle); if (m_thrusterVolumes[(int)ShipThrusters.Ion] > 0f) { PlayShipSound(ShipEmitters.IonThrusters, ShipSystemSoundsEnum.IonThrusters); PlayShipSound(ShipEmitters.IonThrustersIdle, ShipSystemSoundsEnum.IonThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Hydrogen] > 0f) { PlayShipSound(ShipEmitters.HydrogenThrusters, ShipSystemSoundsEnum.HydrogenThrusters); PlayShipSound(ShipEmitters.HydrogenThrustersIdle, ShipSystemSoundsEnum.HydrogenThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Atmospheric] > 0f) { if (m_shipState == ShipStateEnum.Slow) PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersSlow); else if (m_shipState == ShipStateEnum.Medium) PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersMedium); else if (m_shipState == ShipStateEnum.Fast) PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersFast); PlayShipSound(ShipEmitters.AtmosphericThrustersIdle, ShipSystemSoundsEnum.AtmoThrustersIdle); } if (m_shipWheels.WheelCount > 0) { PlayShipSound(ShipEmitters.WheelsMain, ShipSystemSoundsEnum.WheelsEngineRun); PlayShipSound(ShipEmitters.WheelsSecondary, ShipSystemSoundsEnum.WheelsSecondary); } if (lastState == ShipStateEnum.NoPower) { m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = 1f; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesStart); } } m_categoryChange = false; m_forceSoundCheck = false; } //there was change in camera - sound should change from 2d to 3d or vice versa if (m_shouldPlay2DChanged) { for (int i = 0; i < m_emitters.Length; i++) { m_emitters[i].Force2D = m_shouldPlay2D; m_emitters[i].Force3D = !m_shouldPlay2D; if (m_emitters[i].IsPlaying && m_emitters[i].Plays2D != m_shouldPlay2D && m_emitters[i].Loop) { m_emitters[i].StopSound(true); m_emitters[i].PlaySound(m_emitters[i].SoundPair, true, true, m_shouldPlay2D); } } m_shouldPlay2DChanged = false; } //update emitter volumes if (m_shipState != ShipStateEnum.NoPower) { if (m_shipEngineModifier < 1f) m_shipEngineModifier = Math.Min(1f, m_shipEngineModifier + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / m_groupData.EngineTimeToTurnOn); float shipSpeedRatio = Math.Min(shipSpeed / m_definition.FullSpeed, 1f); float shipSpeedVolume = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.EngineVolumes) * m_shipEngineModifier * m_singleSoundsModifier; float shipThrusterRatio; float shipThrusterIdleRatio = 1f; //main sound - engines if (m_emitters[(int)ShipEmitters.MainSound].IsPlaying) { m_emitters[(int)ShipEmitters.MainSound].VolumeMultiplier = shipSpeedVolume; float semitones = m_groupData.EnginePitchRangeInSemitones_h + m_groupData.EnginePitchRangeInSemitones * shipSpeedRatio; m_emitters[(int)ShipEmitters.MainSound].Sound.FrequencyRatio = MyAudio.Static.SemitonesToFrequencyRatio(semitones); } //thruster base volume ratio shipThrusterRatio = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.ThrusterVolumes); shipThrusterRatio = Math.Max(Math.Min(shipThrusterRatio, 1f) - m_wheelVolumeModifierEngine * m_groupData.WheelsLowerThrusterVolumeBy, 0f); shipThrusterIdleRatio = MyMath.Clamp(1.2f - shipThrusterRatio * 3f, 0f, 1f) * m_shipEngineModifier * m_singleSoundsModifier; shipThrusterRatio *= m_shipEngineModifier * m_singleSoundsModifier; //large ship special emitters m_emitters[(int)ShipEmitters.ShipEngine].VolumeMultiplier = Math.Max(0f, shipSpeedVolume - shipThrusterIdleRatio); m_emitters[(int)ShipEmitters.ShipIdle].VolumeMultiplier = shipThrusterIdleRatio * m_shipEngineModifier * m_singleSoundsModifier; //ion thruster run/idle sounds volumes + pitch float thrusterPitch = MyAudio.Static.SemitonesToFrequencyRatio(m_groupData.ThrusterPitchRangeInSemitones_h + m_groupData.ThrusterPitchRangeInSemitones * shipThrusterRatio); if (m_emitters[(int)ShipEmitters.IonThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.IonThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Ion]; m_emitters[(int)ShipEmitters.IonThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.IonThrustersIdle].IsPlaying) m_emitters[(int)ShipEmitters.IonThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Ion]; //hydrogen thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.HydrogenThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.HydrogenThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; m_emitters[(int)ShipEmitters.HydrogenThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].IsPlaying) m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; //atmospheric thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.AtmosphericThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.AtmosphericThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; m_emitters[(int)ShipEmitters.AtmosphericThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].IsPlaying) m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; //wheels volume + pitch if (m_emitters[(int)ShipEmitters.WheelsMain].IsPlaying) { m_emitters[(int)ShipEmitters.MainSound].VolumeMultiplier = Math.Max(shipSpeedVolume - m_wheelVolumeModifierEngine * m_groupData.WheelsLowerThrusterVolumeBy, 0f); m_emitters[(int)ShipEmitters.WheelsMain].VolumeMultiplier = shipThrusterRatio * m_wheelVolumeModifierEngine * m_singleSoundsModifier; m_emitters[(int)ShipEmitters.WheelsMain].Sound.FrequencyRatio = thrusterPitch; m_emitters[(int)ShipEmitters.WheelsSecondary].VolumeMultiplier = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.WheelsVolumes) * m_shipEngineModifier * m_wheelVolumeModifierWheels * m_singleSoundsModifier; } //speed up/down sounds float speedUpDownVolume = 0.5f + shipThrusterRatio / 2f; m_playingSpeedUpOrDown = m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying; //speed up if (m_speedChange >= 20 && m_timers[(int)ShipTimers.SpeedUp] <= 0f && m_wheelVolumeModifierEngine <= 0f) { m_timers[(int)ShipTimers.SpeedUp] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 1f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) FadeOutSound(duration: 1000); m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesSpeedUp, false, false); m_playingSpeedUpOrDown = true; } else if (m_speedChange <= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) FadeOutSound(duration: 1000); //speed down if (m_speedChange <= 10 && m_timers[(int)ShipTimers.SpeedDown] <= 0f && m_wheelVolumeModifierEngine <= 0f) { m_timers[(int)ShipTimers.SpeedDown] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 2f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) FadeOutSound(duration: 1000); m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesSpeedDown, false, false); m_playingSpeedUpOrDown = true; } else if (m_speedChange >= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) FadeOutSound(duration: 1000); //volume change for all sound if speed up/down is playing float singleSoundVolumeTarget = 1f; if (m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) singleSoundVolumeTarget = m_groupData.SpeedDownSoundChangeVolumeTo; if (m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) singleSoundVolumeTarget = m_groupData.SpeedUpSoundChangeVolumeTo; if (m_singleSoundsModifier < singleSoundVolumeTarget) m_singleSoundsModifier = Math.Min(m_singleSoundsModifier + m_groupData.SpeedUpDownChangeSpeed, singleSoundVolumeTarget); else if (m_singleSoundsModifier > singleSoundVolumeTarget) m_singleSoundsModifier = Math.Max(m_singleSoundsModifier - m_groupData.SpeedUpDownChangeSpeed, singleSoundVolumeTarget); //speed down volume if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && (m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown)) || m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp)))) m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; } else { if (m_shipEngineModifier > 0f) m_shipEngineModifier = Math.Max(0f, m_shipEngineModifier - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / m_groupData.EngineTimeToTurnOff); } if (m_shipThrusters != null && m_shipThrusters.ThrustCount <= 0) m_shipThrusters = null; //speed up / speed down variable if (Math.Abs(shipSpeed - m_lastFrameShipSpeed) > 0.01f && shipSpeed >= 3f) m_speedChange = (int)MyMath.Clamp(m_speedChange + (shipSpeed > m_lastFrameShipSpeed ? 1 : -1), 0, 30); else if (m_speedChange != 15) m_speedChange += m_speedChange > 15 ? -1 : 1; //speed up / speed down timers if (shipSpeed >= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedDown] > 0f) m_timers[(int)ShipTimers.SpeedDown] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; if (shipSpeed <= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedUp] > 0f) m_timers[(int)ShipTimers.SpeedUp] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; m_lastFrameShipSpeed = shipSpeed; } }
public void SetState(ShipStateEnum shipState) { this.state = ShipManager.GetState(shipState); }
void Start() { state = ShipStateEnum.IDLE; movePercent = 0.0f; }
public void Update() { if (m_initialized && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false && (m_shipThrusters != null || m_shipWheels != null) && m_distanceToShip < MAX_UPDATE_RANGE_SQ) { //calculate current ship state m_driving = m_shipWheels.HasWorkingWheels(true); float shipSpeedSquered = m_driving == false?m_shipGrid.Physics.LinearVelocity.LengthSquared() : (m_shipGrid.Physics.LinearVelocity * WHEELS_SPEED_COMPENSATION).LengthSquared(); ShipStateEnum lastState = m_shipState; if (m_shipGrid.GridSystems.ResourceDistributor.ResourceState == MyResourceStateEnum.NoPower || m_shipCategory == ShipTypeEnum.Debris || ((m_shipThrusters == null || m_shipThrusters.ThrustCount <= 0) && (m_shipWheels == null || m_shipWheels.WheelCount <= 0))) { m_shipState = ShipStateEnum.NoPower; } else { if (shipSpeedSquered < ENGINES_SPEED_THRESHOLD_1_SQ) { m_shipState = ShipStateEnum.Slow; } else if (shipSpeedSquered < ENGINES_SPEED_THRESHOLD_2_SQ) { m_shipState = ShipStateEnum.Medium; } else { m_shipState = ShipStateEnum.Fast; } } //in first person change bool orig = m_shouldPlay2D; if (m_shipGrid.GridSizeEnum == MyCubeSize.Large) { m_shouldPlay2D = m_insideShip; } else if (MySession.Static.ControlledEntity != null && MySession.Static.IsCameraUserControlledSpectator() == false && MySession.Static.ControlledEntity.Entity != null && MySession.Static.ControlledEntity.Entity.Parent == m_shipGrid) { m_shouldPlay2D = ((MySession.Static.ControlledEntity.Entity is MyCockpit) && (MySession.Static.ControlledEntity.Entity as MyCockpit).IsInFirstPersonView) || (MySession.Static.CameraController is MyCameraBlock && (MySession.Static.CameraController as MyCameraBlock).Parent == m_shipGrid); } else { m_shouldPlay2D = false; } m_shouldPlay2DChanged = (orig != m_shouldPlay2D); //thruster volume corrections for (int i = 0; i < m_thrusterVolumes.Length; i++) { if (m_thrusterVolumes[i] < m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Min(m_thrusterVolumes[i] + THRUSTER_COMPOSITION_CHANGE_SPEED, m_thrusterVolumeTargets[i]); } else if (m_thrusterVolumes[i] > m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Max(m_thrusterVolumes[i] - THRUSTER_COMPOSITION_CHANGE_SPEED, m_thrusterVolumeTargets[i]); } } if (m_driving) { m_wheelVolumeModifier = Math.Min(m_wheelVolumeModifier + 0.04f, 1f); } else { m_wheelVolumeModifier = Math.Max(m_wheelVolumeModifier - 0.005f, 0f); } //play sounds if there was change in state, ship type or thruster composition if (m_shipState != lastState || m_categoryChange || m_forceSoundCheck) { if (m_shipState == ShipStateEnum.NoPower) { if (m_shipState != lastState) { for (int i = 0; i < m_emitters.Length; i++) { m_emitters[i].StopSound(false); } PlayShipSound(ShipEmitters.SingleSounds, ShipSounds.EnginesEnd); } } else { if (m_shipState == ShipStateEnum.Slow) { PlayShipSound(ShipEmitters.MainSound, ShipSounds.MainLoopSlow); } else if (m_shipState == ShipStateEnum.Medium) { PlayShipSound(ShipEmitters.MainSound, ShipSounds.MainLoopMedium); } else if (m_shipState == ShipStateEnum.Fast) { PlayShipSound(ShipEmitters.MainSound, ShipSounds.MainLoopFast); } PlayShipSound(ShipEmitters.ShipEngine, ShipSounds.ShipEngine); if (m_shipGrid.GridSizeEnum == MyCubeSize.Large) { PlayShipSound(ShipEmitters.LargeShipIdle, ShipSounds.LargeShipIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Ion] > 0f) { PlayShipSound(ShipEmitters.IonThrusters, ShipSounds.IonThrusters); PlayShipSound(ShipEmitters.IonThrustersIdle, ShipSounds.IonThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Hydrogen] > 0f) { PlayShipSound(ShipEmitters.HydrogenThrusters, ShipSounds.HydrogenThrusters); PlayShipSound(ShipEmitters.HydrogenThrustersIdle, ShipSounds.HydrogenThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Atmospheric] > 0f) { if (m_shipState == ShipStateEnum.Slow) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSounds.AtmoThrustersSlow, useFadeOut: true); } else if (m_shipState == ShipStateEnum.Medium) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSounds.AtmoThrustersMedium, useFadeOut: true); } else if (m_shipState == ShipStateEnum.Fast) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSounds.AtmoThrustersFast, useFadeOut: true); } PlayShipSound(ShipEmitters.AtmosphericThrustersIdle, ShipSounds.AtmoThrustersIdle); } if (m_shipWheels.WheelCount > 0) { PlayShipSound(ShipEmitters.WheelsMain, ShipSounds.WheelsEngineRun); PlayShipSound(ShipEmitters.WheelsSecondary, ShipSounds.WheelsSecondary); } if (lastState == ShipStateEnum.NoPower) { PlayShipSound(ShipEmitters.SingleSounds, ShipSounds.EnginesStart); } } m_categoryChange = false; m_forceSoundCheck = false; } //there was change in camera - sound should change from 2d to 3d or vice versa if (m_shouldPlay2DChanged) { for (int i = 0; i < m_emitters.Length; i++) { m_emitters[i].Force2D = m_shouldPlay2D; m_emitters[i].Force3D = !m_shouldPlay2D; if (m_emitters[i].IsPlaying && m_emitters[i].Plays2D != m_shouldPlay2D && m_emitters[i].Loop) { m_emitters[i].StopSound(true); m_emitters[i].PlaySound(m_emitters[i].SoundPair, true, true, m_shouldPlay2D); } } m_shouldPlay2DChanged = false; } //update emitter volumes if (m_shipState != ShipStateEnum.NoPower) { if (m_shipEngineModifier < 1f) { m_shipEngineModifier = Math.Min(1f, m_shipEngineModifier + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / ENGINES_TIME_TURN_ON); } float shipSpeedRatio = Math.Min(shipSpeedSquered / FULL_SPEED_SQ, 1f); float shipSpeedVolume = (ENGINES_MIN_VOLUME + (1f - ENGINES_MIN_VOLUME) * shipSpeedRatio) * m_shipEngineModifier; float shipThrusterRatio; float shipThrusterIdleRatio = 1f; //main sound - engines if (m_emitters[(int)ShipEmitters.MainSound].IsPlaying) { m_emitters[(int)ShipEmitters.MainSound].VolumeMultiplier = shipSpeedVolume; float semitones = -ENGINES_PITCH_RANGE_HALF + ENGINES_PITCH_RANGE * shipSpeedRatio; m_emitters[(int)ShipEmitters.MainSound].Sound.FrequencyRatio = MyAudio.Static.SemitonesToFrequencyRatio(semitones); } //thruster base volume ratio if (shipSpeedSquered <= THRUSTER_RATIO_SPEED_THRESHOLD_1_SQ) { shipThrusterRatio = THRUSTER_RATIO_VOLUME_1 * shipSpeedSquered / THRUSTER_RATIO_SPEED_THRESHOLD_1_SQ; } else if (shipSpeedSquered <= THRUSTER_RATIO_SPEED_THRESHOLD_2_SQ) { shipThrusterRatio = THRUSTER_RATIO_VOLUME_1 + THRUSTER_RATIO_VOLUME_2_DIFF * (shipSpeedSquered - THRUSTER_RATIO_SPEED_THRESHOLD_1_SQ) / THRUSTER_RATIO_SPEED_THRESHOLD_2_DIFF; } else if (shipSpeedSquered <= THRUSTER_RATIO_SPEED_THRESHOLD_3_SQ) { shipThrusterRatio = THRUSTER_RATIO_VOLUME_2 + THRUSTER_RATIO_VOLUME_3_DIFF * (shipSpeedSquered - THRUSTER_RATIO_SPEED_THRESHOLD_2_SQ) / THRUSTER_RATIO_SPEED_THRESHOLD_3_DIFF; } else { shipThrusterRatio = THRUSTER_RATIO_VOLUME_3 + THRUSTER_RATIO_VOLUME_4_DIFF * (shipSpeedSquered - THRUSTER_RATIO_SPEED_THRESHOLD_3_SQ) / THRUSTER_RATIO_SPEED_THRESHOLD_4_DIFF; } shipThrusterRatio = Math.Max(Math.Min(shipThrusterRatio, 1f) - m_wheelVolumeModifier * WHEELS_LOWER_THRUSTERS_BY_RATIO, 0f); shipThrusterIdleRatio = MyMath.Clamp(1.2f - shipThrusterRatio * 3f, 0f, 1f); //large ship special emitters m_emitters[(int)ShipEmitters.ShipEngine].VolumeMultiplier = Math.Max(0f, shipSpeedVolume - shipThrusterIdleRatio); if (m_shipGrid.GridSizeEnum == MyCubeSize.Large) { m_emitters[(int)ShipEmitters.LargeShipIdle].VolumeMultiplier = shipThrusterIdleRatio * m_shipEngineModifier; } //ion thruster run/idle sounds volumes + pitch float thrusterPitch = MyAudio.Static.SemitonesToFrequencyRatio(-ENGINES_PITCH_RANGE_HALF + ENGINES_PITCH_RANGE * shipThrusterRatio); if (m_emitters[(int)ShipEmitters.IonThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.IonThrusters].VolumeMultiplier = shipThrusterRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Ion]; m_emitters[(int)ShipEmitters.IonThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.IonThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.IonThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Ion]; } //hydrogen thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.HydrogenThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.HydrogenThrusters].VolumeMultiplier = shipThrusterRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; m_emitters[(int)ShipEmitters.HydrogenThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; } //atmospheric thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.AtmosphericThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.AtmosphericThrusters].VolumeMultiplier = shipThrusterRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; m_emitters[(int)ShipEmitters.AtmosphericThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_shipEngineModifier * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; } //wheels volume + pitch if (m_emitters[(int)ShipEmitters.WheelsMain].IsPlaying) { m_emitters[(int)ShipEmitters.WheelsMain].VolumeMultiplier = shipThrusterRatio * m_shipEngineModifier * m_wheelVolumeModifier; m_emitters[(int)ShipEmitters.WheelsMain].Sound.FrequencyRatio = thrusterPitch; m_emitters[(int)ShipEmitters.WheelsSecondary].VolumeMultiplier = (WHEELS_GROUND_MIN_VOLUME + (1f - WHEELS_GROUND_MIN_VOLUME) * shipThrusterRatio) * m_shipEngineModifier * m_wheelVolumeModifier; } //speed up/down sounds if (m_speedChange >= 20 && m_timers[(int)ShipTimers.SpeedUp] <= 0f && m_wheelVolumeModifier <= 0f) { m_timers[(int)ShipTimers.SpeedUp] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 1f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSounds.EnginesSpeedDown))) { m_emitters[(int)ShipEmitters.SingleSounds].StopSound(false); } PlayShipSound(ShipEmitters.SingleSounds, ShipSounds.EnginesSpeedUp, false, false); } else if (m_speedChange <= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSounds.EnginesSpeedUp))) { m_emitters[(int)ShipEmitters.SingleSounds].StopSound(false); } if (m_speedChange <= 10 && m_timers[(int)ShipTimers.SpeedDown] <= 0f && m_wheelVolumeModifier <= 0f) { m_timers[(int)ShipTimers.SpeedDown] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 1f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSounds.EnginesSpeedUp))) { m_emitters[(int)ShipEmitters.SingleSounds].StopSound(false); } PlayShipSound(ShipEmitters.SingleSounds, ShipSounds.EnginesSpeedDown, false, false); } else if (m_speedChange >= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSounds.EnginesSpeedDown))) { m_emitters[(int)ShipEmitters.SingleSounds].StopSound(false); } } else { if (m_shipEngineModifier > 0f) { m_shipEngineModifier = Math.Max(0f, m_shipEngineModifier - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / ENGINES_TIME_TURN_OFF); } } if (m_shipThrusters != null && m_shipThrusters.ThrustCount <= 0) { m_shipThrusters = null; } //speed up / speed down variable if (Math.Abs(shipSpeedSquered - m_lastFrameShipSpeed) > 0.5f && shipSpeedSquered >= 9f) { m_speedChange = (int)MyMath.Clamp(m_speedChange + (shipSpeedSquered > m_lastFrameShipSpeed ? 1 : -1), 0, 30); } else if (m_speedChange != 15) { m_speedChange += m_speedChange > 15 ? -1 : 1; } //speed up / speed down timers if (shipSpeedSquered >= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedDown] > 0f) { m_timers[(int)ShipTimers.SpeedDown] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; } if (shipSpeedSquered <= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedUp] > 0f) { m_timers[(int)ShipTimers.SpeedUp] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; } m_lastFrameShipSpeed = shipSpeedSquered; } }
public void Update() { if (m_initialized && m_shipGrid.Physics != null && m_shipGrid.IsStatic == false && (m_shipThrusters != null || m_shipWheels != null) && m_distanceToShip < m_definition.MaxUpdateRange_sq && m_groupData != null) { //calculate current ship state bool driving = ((DateTime.UtcNow - m_lastContactWithGround).TotalSeconds <= 0.2f); float shipSpeed = driving == false?m_shipGrid.Physics.LinearVelocity.Length() : (m_shipGrid.Physics.LinearVelocity * m_groupData.WheelsSpeedCompensation).Length(); float originalSpeed = Math.Min(shipSpeed / m_definition.FullSpeed, 1f); if (!MySandboxGame.Config.ShipSoundsAreBasedOnSpeed) { shipSpeed = m_shipCurrentPower * m_definition.FullSpeed; } ShipStateEnum lastState = m_shipState; if (m_shipGrid.GridSystems.ResourceDistributor.ResourceState == MyResourceStateEnum.NoPower || m_isDebris || ((m_shipThrusters == null || m_shipThrusters.ThrustCount <= 0) && (m_shipWheels == null || m_shipWheels.WheelCount <= 0))) { m_shipState = ShipStateEnum.NoPower; } else { if (shipSpeed < m_definition.SpeedThreshold1) { m_shipState = ShipStateEnum.Slow; } else if (shipSpeed < m_definition.SpeedThreshold2) { m_shipState = ShipStateEnum.Medium; } else { m_shipState = ShipStateEnum.Fast; } } //alternate speed calculation (based on acceleration/decceleration) if (!MySandboxGame.Config.ShipSoundsAreBasedOnSpeed) { m_shipCurrentPowerTarget = 0f; if (driving) { if (m_shipWheels != null && m_shipWheels.WheelCount > 0) { if (m_shipWheels.AngularVelocity.LengthSquared() >= 1f) { m_shipCurrentPowerTarget = 1f;//accelerating/deccelerating } else if (m_shipGrid.Physics.LinearVelocity.LengthSquared() > 5f) { m_shipCurrentPowerTarget = 0.33f;//cruising } } } else { if (m_shipThrusters != null) { if (m_shipThrusters.FinalThrust.LengthSquared() >= 100f) { m_shipCurrentPowerTarget = 1f;//accelerating/deccelerating } else if (m_shipGrid.Physics.Gravity != Vector3.Zero && m_shipThrusters.DampenersEnabled && m_shipGrid.Physics.LinearVelocity.LengthSquared() < 4f) { m_shipCurrentPowerTarget = 0.33f;//hovering } else { m_shipCurrentPowerTarget = 0;//complete stop } } } if (m_shipCurrentPower < m_shipCurrentPowerTarget) { m_shipCurrentPower = Math.Min(m_shipCurrentPower + POWER_CHANGE_SPEED_UP, m_shipCurrentPowerTarget); } else if (m_shipCurrentPower > m_shipCurrentPowerTarget) { m_shipCurrentPower = Math.Max(m_shipCurrentPower - POWER_CHANGE_SPEED_DOWN, m_shipCurrentPowerTarget); } } //in first person change bool orig = m_shouldPlay2D; if (m_shipGrid.GridSizeEnum == MyCubeSize.Large) { m_shouldPlay2D = m_insideShip; } else if (MySession.Static.ControlledEntity != null && MySession.Static.IsCameraUserControlledSpectator() == false && MySession.Static.ControlledEntity.Entity != null && MySession.Static.ControlledEntity.Entity.Parent == m_shipGrid) { m_shouldPlay2D = ((MySession.Static.ControlledEntity.Entity is MyCockpit) && (MySession.Static.ControlledEntity.Entity as MyCockpit).IsInFirstPersonView) || ((MySession.Static.ControlledEntity.Entity is MyRemoteControl) && MySession.Static.LocalCharacter != null && MySession.Static.LocalCharacter.IsUsing is MyCockpit && (MySession.Static.LocalCharacter.IsUsing as MyCockpit).Parent == m_shipGrid) || (MySession.Static.CameraController is MyCameraBlock && (MySession.Static.CameraController as MyCameraBlock).Parent == m_shipGrid); } else { m_shouldPlay2D = false; } m_shouldPlay2DChanged = (orig != m_shouldPlay2D); //thruster volume corrections for (int i = 0; i < m_thrusterVolumes.Length; i++) { if (m_thrusterVolumes[i] < m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Min(m_thrusterVolumes[i] + m_groupData.ThrusterCompositionChangeSpeed, m_thrusterVolumeTargets[i]); } else if (m_thrusterVolumes[i] > m_thrusterVolumeTargets[i]) { m_thrusterVolumes[i] = Math.Max(m_thrusterVolumes[i] - m_groupData.ThrusterCompositionChangeSpeed, m_thrusterVolumeTargets[i]); } } if (driving) { m_wheelVolumeModifierEngine = Math.Min(m_wheelVolumeModifierEngine + 0.01f, 1f); m_wheelVolumeModifierWheels = Math.Min(m_wheelVolumeModifierWheels + 0.03f, 1f); } else { m_wheelVolumeModifierEngine = Math.Max(m_wheelVolumeModifierEngine - 0.005f, 0f); m_wheelVolumeModifierWheels = Math.Max(m_wheelVolumeModifierWheels - 0.03f, 0f); } //play sounds if there was change in state, ship type or thruster composition if (m_shipState != lastState || m_categoryChange || m_forceSoundCheck) { if (m_shipState == ShipStateEnum.NoPower) { if (m_shipState != lastState) { for (int i = 0; i < m_emitters.Length; i++) { m_emitters[i].StopSound(false); } m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = 1f; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesEnd); } } else { if (m_shipState == ShipStateEnum.Slow) { PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopSlow); } else if (m_shipState == ShipStateEnum.Medium) { PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopMedium); } else if (m_shipState == ShipStateEnum.Fast) { PlayShipSound(ShipEmitters.MainSound, ShipSystemSoundsEnum.MainLoopFast); } PlayShipSound(ShipEmitters.ShipEngine, ShipSystemSoundsEnum.ShipEngine); PlayShipSound(ShipEmitters.ShipIdle, ShipSystemSoundsEnum.ShipIdle); if (m_thrusterVolumes[(int)ShipThrusters.Ion] > 0f) { PlayShipSound(ShipEmitters.IonThrusters, ShipSystemSoundsEnum.IonThrusters); PlayShipSound(ShipEmitters.IonThrustersIdle, ShipSystemSoundsEnum.IonThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Hydrogen] > 0f) { PlayShipSound(ShipEmitters.HydrogenThrusters, ShipSystemSoundsEnum.HydrogenThrusters); PlayShipSound(ShipEmitters.HydrogenThrustersIdle, ShipSystemSoundsEnum.HydrogenThrustersIdle); } if (m_thrusterVolumes[(int)ShipThrusters.Atmospheric] > 0f) { if (m_shipState == ShipStateEnum.Slow) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersSlow); } else if (m_shipState == ShipStateEnum.Medium) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersMedium); } else if (m_shipState == ShipStateEnum.Fast) { PlayShipSound(ShipEmitters.AtmosphericThrusters, ShipSystemSoundsEnum.AtmoThrustersFast); } PlayShipSound(ShipEmitters.AtmosphericThrustersIdle, ShipSystemSoundsEnum.AtmoThrustersIdle); } if (m_shipWheels.WheelCount > 0) { PlayShipSound(ShipEmitters.WheelsMain, ShipSystemSoundsEnum.WheelsEngineRun); PlayShipSound(ShipEmitters.WheelsSecondary, ShipSystemSoundsEnum.WheelsSecondary); } if (lastState == ShipStateEnum.NoPower) { m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = 1f; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesStart); } } m_categoryChange = false; m_forceSoundCheck = false; } //there was change in camera - sound should change from 2d to 3d or vice versa if (m_shouldPlay2DChanged) { for (int i = 0; i < m_emitters.Length; i++) { m_emitters[i].Force2D = m_shouldPlay2D; m_emitters[i].Force3D = !m_shouldPlay2D; if (m_emitters[i].IsPlaying && m_emitters[i].Plays2D != m_shouldPlay2D && m_emitters[i].Loop) { m_emitters[i].StopSound(true); m_emitters[i].PlaySound(m_emitters[i].SoundPair, true, true, m_shouldPlay2D); } } m_shouldPlay2DChanged = false; } //update emitter volumes if (m_shipState != ShipStateEnum.NoPower) { if (m_shipEngineModifier < 1f) { m_shipEngineModifier = Math.Min(1f, m_shipEngineModifier + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / m_groupData.EngineTimeToTurnOn); } float shipSpeedRatio = Math.Min(shipSpeed / m_definition.FullSpeed, 1f); float shipSpeedVolume = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.EngineVolumes) * m_shipEngineModifier * m_singleSoundsModifier; float shipThrusterRatio; float shipThrusterIdleRatio = 1f; //main sound - engines if (m_emitters[(int)ShipEmitters.MainSound].IsPlaying) { m_emitters[(int)ShipEmitters.MainSound].VolumeMultiplier = shipSpeedVolume; float semitones = m_groupData.EnginePitchRangeInSemitones_h + m_groupData.EnginePitchRangeInSemitones * shipSpeedRatio; m_emitters[(int)ShipEmitters.MainSound].Sound.FrequencyRatio = MyAudio.Static.SemitonesToFrequencyRatio(semitones); } //thruster base volume ratio shipThrusterRatio = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.ThrusterVolumes); shipThrusterRatio = Math.Max(Math.Min(shipThrusterRatio, 1f) - m_wheelVolumeModifierEngine * m_groupData.WheelsLowerThrusterVolumeBy, 0f); shipThrusterIdleRatio = MyMath.Clamp(1.2f - shipThrusterRatio * 3f, 0f, 1f) * m_shipEngineModifier * m_singleSoundsModifier; shipThrusterRatio *= m_shipEngineModifier * m_singleSoundsModifier; //large ship special emitters m_emitters[(int)ShipEmitters.ShipEngine].VolumeMultiplier = MySandboxGame.Config.ShipSoundsAreBasedOnSpeed ? Math.Max(0f, shipSpeedVolume - shipThrusterIdleRatio) : originalSpeed; m_emitters[(int)ShipEmitters.ShipIdle].VolumeMultiplier = (MySandboxGame.Config.ShipSoundsAreBasedOnSpeed ? shipThrusterIdleRatio : MyMath.Clamp(1.2f - originalSpeed * 3f, 0f, 1f)) * m_shipEngineModifier * m_singleSoundsModifier; //ion thruster run/idle sounds volumes + pitch float thrusterPitch = MyAudio.Static.SemitonesToFrequencyRatio(m_groupData.ThrusterPitchRangeInSemitones_h + m_groupData.ThrusterPitchRangeInSemitones * shipThrusterRatio); if (m_emitters[(int)ShipEmitters.IonThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.IonThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Ion]; m_emitters[(int)ShipEmitters.IonThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.IonThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.IonThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Ion]; } //hydrogen thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.HydrogenThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.HydrogenThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; m_emitters[(int)ShipEmitters.HydrogenThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.HydrogenThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Hydrogen]; } //atmospheric thruster run/idle sounds volumes + pitch if (m_emitters[(int)ShipEmitters.AtmosphericThrusters].IsPlaying) { m_emitters[(int)ShipEmitters.AtmosphericThrusters].VolumeMultiplier = shipThrusterRatio * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; m_emitters[(int)ShipEmitters.AtmosphericThrusters].Sound.FrequencyRatio = thrusterPitch; } if (m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].IsPlaying) { m_emitters[(int)ShipEmitters.AtmosphericThrustersIdle].VolumeMultiplier = shipThrusterIdleRatio * m_thrusterVolumes[(int)ShipThrusters.Atmospheric]; } //wheels volume + pitch if (m_emitters[(int)ShipEmitters.WheelsMain].IsPlaying) { m_emitters[(int)ShipEmitters.MainSound].VolumeMultiplier = Math.Max(shipSpeedVolume - m_wheelVolumeModifierEngine * m_groupData.WheelsLowerThrusterVolumeBy, 0f); m_emitters[(int)ShipEmitters.WheelsMain].VolumeMultiplier = shipThrusterRatio * m_wheelVolumeModifierEngine * m_singleSoundsModifier; m_emitters[(int)ShipEmitters.WheelsMain].Sound.FrequencyRatio = thrusterPitch; m_emitters[(int)ShipEmitters.WheelsSecondary].VolumeMultiplier = CalculateVolumeFromSpeed(shipSpeedRatio, ref m_groupData.WheelsVolumes) * m_shipEngineModifier * m_wheelVolumeModifierWheels * m_singleSoundsModifier; } //speed up/down sounds float speedUpDownVolume = 0.5f + shipThrusterRatio / 2f; m_playingSpeedUpOrDown = m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying; //speed up if (m_speedChange >= 20 && m_timers[(int)ShipTimers.SpeedUp] <= 0f && m_wheelVolumeModifierEngine <= 0f) { m_timers[(int)ShipTimers.SpeedUp] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 1f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) { FadeOutSound(duration: 1000); } m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesSpeedUp, false, false); m_playingSpeedUpOrDown = true; } else if (m_speedChange <= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) { FadeOutSound(duration: 1000); } //speed down if (m_speedChange <= 10 && m_timers[(int)ShipTimers.SpeedDown] <= 0f && m_wheelVolumeModifierEngine <= 0f) { m_timers[(int)ShipTimers.SpeedDown] = (m_shipGrid.GridSizeEnum == MyCubeSize.Large ? 8f : 2f); if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) { FadeOutSound(duration: 1000); } m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; PlayShipSound(ShipEmitters.SingleSounds, ShipSystemSoundsEnum.EnginesSpeedDown, false, false); m_playingSpeedUpOrDown = true; } else if (m_speedChange >= 15 && m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) { FadeOutSound(duration: 1000); } //volume change for all sound if speed up/down is playing float singleSoundVolumeTarget = 1f; if (m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown))) { singleSoundVolumeTarget = m_groupData.SpeedDownSoundChangeVolumeTo; } if (m_playingSpeedUpOrDown && m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp))) { singleSoundVolumeTarget = m_groupData.SpeedUpSoundChangeVolumeTo; } if (m_singleSoundsModifier < singleSoundVolumeTarget) { m_singleSoundsModifier = Math.Min(m_singleSoundsModifier + m_groupData.SpeedUpDownChangeSpeed, singleSoundVolumeTarget); } else if (m_singleSoundsModifier > singleSoundVolumeTarget) { m_singleSoundsModifier = Math.Max(m_singleSoundsModifier - m_groupData.SpeedUpDownChangeSpeed, singleSoundVolumeTarget); } //speed down volume if (m_emitters[(int)ShipEmitters.SingleSounds].IsPlaying && (m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedDown)) || m_emitters[(int)ShipEmitters.SingleSounds].SoundPair.Equals(GetShipSound(ShipSystemSoundsEnum.EnginesSpeedUp)))) { m_emitters[(int)ShipEmitters.SingleSounds].VolumeMultiplier = speedUpDownVolume; } } else { if (m_shipEngineModifier > 0f) { m_shipEngineModifier = Math.Max(0f, m_shipEngineModifier - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / m_groupData.EngineTimeToTurnOff); } } if (m_shipThrusters != null && m_shipThrusters.ThrustCount <= 0) { m_shipThrusters = null; } //speed up / speed down variable if (Math.Abs(shipSpeed - m_lastFrameShipSpeed) > 0.01f && shipSpeed >= 3f) { m_speedChange = (int)MyMath.Clamp(m_speedChange + (shipSpeed > m_lastFrameShipSpeed ? 1 : -1), 0, 30); } else if (m_speedChange != 15) { m_speedChange += m_speedChange > 15 ? -1 : 1; } //speed up / speed down timers if (shipSpeed >= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedDown] > 0f) { m_timers[(int)ShipTimers.SpeedDown] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; } if (shipSpeed <= m_lastFrameShipSpeed && m_timers[(int)ShipTimers.SpeedUp] > 0f) { m_timers[(int)ShipTimers.SpeedUp] -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; } m_lastFrameShipSpeed = shipSpeed; } }