public override void Init(MyComponentDefinitionBase definition) { base.Init(definition); var craftDefinition = definition as MyCraftingComponentBasicDefinition; System.Diagnostics.Debug.Assert(craftDefinition != null, "Trying to initialize crafting component from wrong definition type?"); if (craftDefinition != null) { ActionSound = new MySoundPair(craftDefinition.ActionSound); m_craftingSpeedMultiplier = craftDefinition.CraftingSpeedMultiplier; foreach (var blueprintClass in craftDefinition.AvailableBlueprintClasses) { var classDefinition = MyDefinitionManager.Static.GetBlueprintClass(blueprintClass); System.Diagnostics.Debug.Assert(classDefinition != null, blueprintClass + " blueprint class definition was not found."); if (classDefinition != null) { m_blueprintClasses.Add(classDefinition); } } } }
public MyWeaponAmmoData(int rateOfFire, string soundName, int shotsInBurst) { this.RateOfFire = rateOfFire; this.ShotsInBurst = shotsInBurst; this.ShootSound = new MySoundPair(soundName); this.ShootIntervalInMiliseconds = (int)(1000 / (RateOfFire * oneSixtieth)); }
public ImpactSounds(float mass, string soundCue, float minVelocity, float maxVolumeVelocity) { this.Mass = mass; this.SoundCue = new MySoundPair(soundCue); this.minVelocity = minVelocity; this.maxVolumeVelocity = maxVolumeVelocity; }
private bool m_willStartSound; // will start sound in updateaftersimulation #endregion Fields #region Constructors public MySoundBlock() : base() { #if XB1 // XB1_SYNC_NOREFLECTION m_soundRadius = SyncType.CreateAndAddProp<float>(); m_volume = SyncType.CreateAndAddProp<float>(); m_cueId = SyncType.CreateAndAddProp<MyCueId>(); m_loopPeriod = SyncType.CreateAndAddProp<float>(); #endif // XB1 CreateTerminalControls(); m_soundPair = new MySoundPair(); m_soundEmitterIndex = 0; m_soundEmitters = new MyEntity3DSoundEmitter[EMITTERS_NUMBER]; for (int i = 0; i < EMITTERS_NUMBER; i++) { m_soundEmitters[i] = new MyEntity3DSoundEmitter(this); m_soundEmitters[i].Force3D = true; } m_volume.ValueChanged += (x) => VolumeChanged(); m_soundRadius.ValueChanged += (x) => RadiusChanged(); m_cueId.ValueChanged += (x) => SelectionChanged(); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_WeaponDefinition; MyDebug.AssertDebug(ob != null); this.WeaponAmmoDatas = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length]; this.NoAmmoSound = new MySoundPair(ob.NoAmmoSoundName); this.ReloadSound = new MySoundPair(ob.ReloadSoundName); this.DeviateShotAngle = MathHelper.ToRadians(ob.DeviateShotAngle); this.ReleaseTimeAfterFire = ob.ReleaseTimeAfterFire; this.MuzzleFlashLifeSpan = ob.MuzzleFlashLifeSpan; this.AmmoMagazinesId = new MyDefinitionId[ob.AmmoMagazines.Length]; for (int i = 0; i < this.AmmoMagazinesId.Length; i++) { var ammoMagazine = ob.AmmoMagazines[i]; this.AmmoMagazinesId[i] = new MyDefinitionId(ammoMagazine.Type, ammoMagazine.Subtype); var ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]); MyAmmoType ammoType = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType; string errorMessage = null; switch (ammoType) { case MyAmmoType.HighSpeed: MyDebug.AssertDebug(ob.ProjectileAmmoData != null, "No weapon ammo data specified for projectile ammo"); if (ob.ProjectileAmmoData != null) { this.WeaponAmmoDatas[(int)MyAmmoType.HighSpeed] = new MyWeaponAmmoData(ob.ProjectileAmmoData); } else { errorMessage = string.Format(ErrorMessageTemplate, "projectile", "Projectile"); } break; case MyAmmoType.Missile: MyDebug.AssertDebug(ob.MissileAmmoData != null, "No weapon ammo data specified for missile ammo"); if (ob.MissileAmmoData != null) { this.WeaponAmmoDatas[(int)MyAmmoType.Missile] = new MyWeaponAmmoData(ob.MissileAmmoData); } else { errorMessage = string.Format(ErrorMessageTemplate, "missile", "Missile"); } break; default: throw new NotImplementedException(); } if (!string.IsNullOrEmpty(errorMessage)) { MyDefinitionErrors.Add(Context, errorMessage, TErrorSeverity.Critical); } } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var chamberDef = builder as MyObjectBuilder_CryoChamberDefinition; OverlayTexture = chamberDef.OverlayTexture; IdlePowerConsumption = chamberDef.IdlePowerConsumption; OutsideSound = new MySoundPair(chamberDef.OutsideSound); InsideSound = new MySoundPair(chamberDef.InsideSound); }
public MaterialProperties(MySoundPair soundCue, string particleEffectName, ContactPropertyParticleProperties effectProperties) { Sound = soundCue; ParticleEffectProperties = effectProperties; if (particleEffectName != null) MyParticlesLibrary.GetParticleEffectsID( particleEffectName, out ParticleEffectID); else ParticleEffectID = -1; }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var obProjector = builder as MyObjectBuilder_ProjectorDefinition; MyDebug.AssertDebug(obProjector != null, "Initializing camera definition using wrong object builder.!"); ResourceSinkGroup = MyStringHash.GetOrCompute(obProjector.ResourceSinkGroup); RequiredPowerInput = obProjector.RequiredPowerInput; IdleSound = new MySoundPair(obProjector.IdleSound); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_ShipSoundsDefinition; MyDebug.AssertDebug(ob != null); this.MinWeight = ob.MinWeight; this.AllowSmallGrid = ob.AllowSmallGrid; this.AllowLargeGrid = ob.AllowLargeGrid; this.EnginePitchRangeInSemitones = ob.EnginePitchRangeInSemitones; this.EnginePitchRangeInSemitones_h = ob.EnginePitchRangeInSemitones * -0.5f; this.EngineTimeToTurnOn = ob.EngineTimeToTurnOn; this.EngineTimeToTurnOff = ob.EngineTimeToTurnOff; this.WheelsLowerThrusterVolumeBy = ob.WheelsLowerThrusterVolumeBy; this.WheelsFullSpeed = ob.WheelsFullSpeed; this.ThrusterCompositionMinVolume = ob.ThrusterCompositionMinVolume; this.ThrusterCompositionMinVolume_c = ob.ThrusterCompositionMinVolume / (1f - ob.ThrusterCompositionMinVolume); this.ThrusterCompositionChangeSpeed = ob.ThrusterCompositionChangeSpeed; this.SpeedDownSoundChangeVolumeTo = ob.SpeedDownSoundChangeVolumeTo; this.SpeedUpSoundChangeVolumeTo = ob.SpeedUpSoundChangeVolumeTo; this.SpeedUpDownChangeSpeed = ob.SpeedUpDownChangeSpeed * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS; foreach (var sound in ob.Sounds) { if(sound.SoundName.Length == 0) continue; MySoundPair soundPair = new MySoundPair(sound.SoundName); if (soundPair != MySoundPair.Empty) this.Sounds.Add(sound.SoundType, soundPair); } List<MyTuple<float, float>> thrusterVolumesTemp = new List<MyTuple<float,float>>(); foreach (var thrusterVolume in ob.ThrusterVolumes) { thrusterVolumesTemp.Add(new MyTuple<float, float>(Math.Max(0f, thrusterVolume.Speed), Math.Max(0f, thrusterVolume.Volume))); } this.ThrusterVolumes = thrusterVolumesTemp.OrderBy(o => o.Item1).ToList(); List<MyTuple<float, float>> engineVolumesTemp = new List<MyTuple<float, float>>(); foreach (var engineVolume in ob.EngineVolumes) { engineVolumesTemp.Add(new MyTuple<float, float>(Math.Max(0f, engineVolume.Speed), Math.Max(0f, engineVolume.Volume))); } this.EngineVolumes = engineVolumesTemp.OrderBy(o => o.Item1).ToList(); List<MyTuple<float, float>> wheelsVolumesTemp = new List<MyTuple<float, float>>(); foreach (var wheelsVolume in ob.WheelsVolumes) { wheelsVolumesTemp.Add(new MyTuple<float, float>(Math.Max(0f, wheelsVolume.Speed), Math.Max(0f, wheelsVolume.Volume))); } this.WheelsVolumes = wheelsVolumesTemp.OrderBy(o => o.Item1).ToList(); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var obDefinition = builder as MyObjectBuilder_OxygenGeneratorDefinition; this.IceToOxygenRatio = obDefinition.IceToOxygenRatio; this.OxygenProductionPerSecond = obDefinition.OxygenProductionPerSecond; this.GenerateSound = new MySoundPair(obDefinition.GenerateSound); this.IdleSound = new MySoundPair(obDefinition.IdleSound); }
public EffectSoundEmitter(uint id, Vector3 position, MySoundPair sound) { ParticleSoundId = id; Updated = true; Emitter = new MyEntity3DSoundEmitter(null); Emitter.SetPosition(position); Emitter.PlaySound(sound); if (Emitter.Sound != null) OriginalVolume = Emitter.Sound.Volume; else OriginalVolume = 1f; Emitter.Update(); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { var ob = (MyObjectBuilder_RopeDefinition)builder; this.EnableRayCastRelease = ob.EnableRayCastRelease; this.IsDefaultCreativeRope = ob.IsDefaultCreativeRope; this.ColorMetalTexture = ob.ColorMetalTexture; this.NormalGlossTexture = ob.NormalGlossTexture; this.AddMapsTexture = ob.AddMapsTexture; if (!string.IsNullOrEmpty(ob.AttachSound)) this.AttachSound = new MySoundPair(ob.AttachSound); if (!string.IsNullOrEmpty(ob.DetachSound)) this.DetachSound = new MySoundPair(ob.DetachSound); if (!string.IsNullOrEmpty(ob.WindingSound)) this.WindingSound = new MySoundPair(ob.WindingSound); base.Init(builder); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var airVent = builder as MyObjectBuilder_AirVentDefinition; MyDebug.AssertDebug(airVent != null, "Initializing air vent definition using wrong object builder."); StandbyPowerConsumption = airVent.StandbyPowerConsumption; OperationalPowerConsumption = airVent.OperationalPowerConsumption; VentilationCapacityPerSecond = airVent.VentilationCapacityPerSecond; PressurizeSound = new MySoundPair(airVent.PressurizeSound); DepressurizeSound = new MySoundPair(airVent.DepressurizeSound); IdleSound = new MySoundPair(airVent.IdleSound); }
public CollisionProperty(string soundCue, string particleEffectName, List<AlternativeImpactSounds> impactsounds) { Sound = new MySoundPair(soundCue); ParticleEffect = particleEffectName; if (impactsounds == null || impactsounds.Count == 0) ImpactSoundCues = null; else { ImpactSoundCues = new List<ImpactSounds>(); foreach (var impactSound in impactsounds) { ImpactSoundCues.Add(new ImpactSounds(impactSound.mass, impactSound.soundCue, impactSound.minVelocity, impactSound.maxVolumeVelocity)); } } }
private MyCueId SelectCue(MySoundPair sound) { if (MySession.Static != null && MySession.Static.Settings.RealisticSound && MyFakes.ENABLE_NEW_SOUNDS) { if (IsInOxygen()) { return(sound.Arcade); } else { return(sound.Realistic); } } else { return(sound.Arcade); } }
public void PlaySingleSound(MySoundPair soundId, /*bool loop = false,*/ bool stopPrevious = false, bool skipIntro = false) { var cueId = soundId.Arcade; if (EmitterMethods[MethodsEnum.CueType].Count > 0) { var select = (Func <MySoundPair, MyCueId>)EmitterMethods[MethodsEnum.CueType][0]; cueId = select(soundId); } if (m_cueEnum == cueId) { return; } else { PlaySound(cueId, stopPrevious, skipIntro); } }
public void PlaySingleSound(MySoundPair soundId, /*bool loop = false,*/ bool stopPrevious = false, bool skipIntro = false, bool skipToEnd = false) { m_closeSoundSoundPair = soundId; m_soundPair = soundId; var cueId = m_useRealisticByDefault ? soundId.Realistic : soundId.Arcade; if (EmitterMethods[MethodsEnum.CueType].Count > 0) { var select = (Func <MySoundPair, MyCueId>)EmitterMethods[MethodsEnum.CueType][0]; cueId = select(soundId); } if (m_cueEnum.Equals(cueId)) { return; } else { PlaySoundWithDistance(cueId, stopPrevious, skipIntro, skipToEnd: skipToEnd); } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var obDefinition = builder as MyObjectBuilder_OxygenGeneratorDefinition; IceConsumptionPerSecond = obDefinition.IceConsumptionPerSecond; GenerateSound = new MySoundPair(obDefinition.GenerateSound); IdleSound = new MySoundPair(obDefinition.IdleSound); ResourceSourceGroup = MyStringHash.GetOrCompute(obDefinition.ResourceSourceGroup); ProducedGases = null; if (obDefinition.ProducedGases != null) { ProducedGases = new List<MyGasGeneratorResourceInfo>(obDefinition.ProducedGases.Count); foreach(var producedGasInfo in obDefinition.ProducedGases) ProducedGases.Add(producedGasInfo); } }
private MyCueId SelectCue(MySoundPair sound) { if (m_useRealisticByDefault) { if (IsThereAir()) { m_realistic = false; return(sound.Arcade); } else { m_realistic = true; return(sound.Realistic); } } else { m_realistic = false; return(sound.Arcade); } }
public EffectSoundEmitter(uint id, Vector3 position, MySoundPair sound) { ParticleSoundId = id; Updated = true; MyEntity entity = null; if (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound)//snap emitter to closest block - used for realistic sounds { List<MyEntity> m_detectedObjects = new List<MyEntity>(); BoundingSphereD effectSphere = new BoundingSphereD(MySession.Static.LocalCharacter != null ? MySession.Static.LocalCharacter.PositionComp.GetPosition() : MySector.MainCamera.Position, 2f); MyGamePruningStructure.GetAllEntitiesInSphere(ref effectSphere, m_detectedObjects); float distBest = float.MaxValue; float dist; for (int i = 0; i < m_detectedObjects.Count; i++) { MyCubeBlock block = m_detectedObjects[i] as MyCubeBlock; if (block != null) { dist = Vector3.DistanceSquared(MySession.Static.LocalCharacter.PositionComp.GetPosition(), block.PositionComp.GetPosition()); if (dist < distBest) { dist = distBest; entity = block; } } } m_detectedObjects.Clear(); } Emitter = new MyEntity3DSoundEmitter(entity); Emitter.SetPosition(position); if (sound == null) sound = MySoundPair.Empty; Emitter.PlaySound(sound); if (Emitter.Sound != null) OriginalVolume = Emitter.Sound.Volume; else OriginalVolume = 1f; Emitter.Update(); SoundPair = sound; }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var materialBuilder = builder as MyObjectBuilder_PhysicalMaterialDefinition; if (materialBuilder != null) { //MyDebug.AssertDebug(materialBuilder != null, "Initializing physical material definition using wrong object builder."); Density = materialBuilder.Density; HorisontalTransmissionMultiplier = materialBuilder.HorisontalTransmissionMultiplier; HorisontalFragility = materialBuilder.HorisontalFragility; SupportMultiplier = materialBuilder.SupportMultiplier; CollisionMultiplier = materialBuilder.CollisionMultiplier; DamageDecal = materialBuilder.DamageDecal; } var soundBuilder = builder as MyObjectBuilder_MaterialSoundsDefinition; if(soundBuilder != null) { InheritSoundsFrom = MyStringHash.GetOrCompute(soundBuilder.InheritFrom); foreach(var sound in soundBuilder.ContactSounds) { var type = MyStringId.GetOrCompute(sound.Type); if (!CollisionSounds.ContainsKey(type)) CollisionSounds[type] = new Dictionary<MyStringHash, MySoundPair>(MyStringHash.Comparer); var material = MyStringHash.GetOrCompute(sound.Material); Debug.Assert(!CollisionSounds[type].ContainsKey(material), "Overwriting material sound!"); CollisionSounds[type][material] = new MySoundPair(sound.Cue); } foreach(var sound in soundBuilder.GeneralSounds) { GeneralSounds[MyStringId.GetOrCompute(sound.Type)] = new MySoundPair(sound.Cue); } } }
private MyCueId SelectCue(MySoundPair sound) { int isPressurized; if (!this.m_useRealisticByDefault) { this.m_realistic = false; return(sound.Arcade); } if (this.m_lastSoundData == null) { this.m_lastSoundData = MyAudio.Static.GetCue(sound.Realistic); } if ((this.m_lastSoundData != null) && this.m_lastSoundData.AlwaysUseOneMode) { this.m_realistic = true; return(sound.Realistic); } MyCockpit cockpit = (MySession.Static.LocalCharacter != null) ? (MySession.Static.LocalCharacter.Parent as MyCockpit) : null; if ((cockpit == null) || (cockpit.CubeGrid.GridSizeEnum != MyCubeSize.Large)) { isPressurized = 0; } else { isPressurized = (int)cockpit.BlockDefinition.IsPressurized; } bool flag = (bool)isPressurized; if (this.IsThereAir() | flag) { this.m_realistic = false; return(sound.Arcade); } this.m_realistic = true; return(sound.Realistic); }
private void PlaySound(string soundName) { MyPhysicalMaterialDefinition def; if(MyDefinitionManager.Static.TryGetDefinition<MyPhysicalMaterialDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalMaterialDefinition),m_physItemDef.PhysicalMaterial), out def)) { MySoundPair sound; if (def.GeneralSounds.TryGetValue(MyStringId.GetOrCompute(soundName), out sound) && !sound.SoundId.IsNull) { m_soundEmitter.PlaySound(sound); } else { MySoundPair soundPair; if (!m_toolSounds.TryGetValue(soundName, out soundPair)) { soundPair = new MySoundPair(soundName); m_toolSounds.Add(soundName, soundPair); } m_soundEmitter.PlaySound(soundPair); } } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { if (objectBuilder.SubtypeName != null && objectBuilder.SubtypeName.Length > 0) m_physicalItemId = new MyDefinitionId(typeof(MyObjectBuilder_PhysicalGunObject), objectBuilder.SubtypeName + "Item"); PhysicalObject = (MyObjectBuilder_PhysicalGunObject)MyObjectBuilderSerializer.CreateNewObject(m_physicalItemId); base.Init(objectBuilder, m_physicalItemId); var definition = MyDefinitionManager.Static.GetPhysicalItemDefinition(m_physicalItemId); Init(null, definition.Model, null, null, null); Render.CastShadows = true; Render.NeedsResolveCastShadow = false; PhysicalObject.GunEntity = (MyObjectBuilder_EntityBase)objectBuilder.Clone(); PhysicalObject.GunEntity.EntityId = this.EntityId; foreach (ToolSound toolSound in m_handItemDef.ToolSounds) { if (toolSound.type == null || toolSound.subtype == null || toolSound.sound == null) continue; if (toolSound.type.Equals("Main")) { if(toolSound.subtype.Equals("Idle")) weldSoundIdle = new MySoundPair(toolSound.sound); if (toolSound.subtype.Equals("Weld")) weldSoundWeld = new MySoundPair(toolSound.sound); } } }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { base.Init(builder, cubeGrid); //m_subpartsSize = 0.5f * (0.5f * SlimBlock.CubeGrid.GridSize - 0.3f); var doorDefinition = BlockDefinition as MyDoorDefinition; MyStringHash resourceSinkGroup; if (doorDefinition != null) { MaxOpen = doorDefinition.MaxOpen; m_openSound = new MySoundPair(doorDefinition.OpenSound); m_closeSound = new MySoundPair(doorDefinition.CloseSound); resourceSinkGroup = MyStringHash.GetOrCompute(doorDefinition.ResourceSinkGroup); } else { MaxOpen = 1.2f; m_openSound = new MySoundPair("BlockDoorSmallOpen"); m_closeSound = new MySoundPair("BlockDoorSmallClose"); resourceSinkGroup = MyStringHash.GetOrCompute("Doors"); } var ob = (MyObjectBuilder_Door)builder; m_open = ob.State; m_currOpening = ob.Opening; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( resourceSinkGroup, MyEnergyConstants.MAX_REQUIRED_POWER_DOOR, () => (Enabled && IsFunctional) ? sinkComp.MaxRequiredInput : 0f); sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged; sinkComp.Update(); ResourceSink = sinkComp; if (!Enabled || !ResourceSink.IsPowered) UpdateSlidingDoorsPosition(true); OnStateChange(); if (m_open) { // required when reinitializing a door after the armor beneath it is destroyed if (Open && (m_currOpening == MaxOpen)) UpdateSlidingDoorsPosition(true); } SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
public void FindAndPlayStateSound() { if (m_character.Breath != null) m_character.Breath.Update(); var cueEnum = SelectSound(); UpdateBreath(); if (m_movementEmitter != null && CharacterSounds[(int)CharacterSoundsEnum.MOVEMENT_SOUND] != MySoundPair.Empty) { if (m_isWalking && !m_movementEmitter.IsPlaying) m_movementEmitter.PlaySound(CharacterSounds[(int)CharacterSoundsEnum.MOVEMENT_SOUND]); if (!m_isWalking && m_movementEmitter.IsPlaying) m_movementEmitter.StopSound(false); } var primaryEmitter = m_soundEmitters[(int)MySoundEmitterEnum.PrimaryState]; var walkEmitter = m_soundEmitters[(int)MySoundEmitterEnum.WalkState]; bool sameSoundAlreadyPlaying = (cueEnum.Equals(primaryEmitter.SoundPair) && primaryEmitter.IsPlaying); if (primaryEmitter.Sound != null) { if (primaryEmitter.LastSoundData != null) { float scaledVolume = primaryEmitter.LastSoundData.Volume * MathHelper.Clamp(m_character.Physics.LinearVelocity.Length() / 7.5f, 0.6f, 1); primaryEmitter.Sound.SetVolume(scaledVolume); } } if (!sameSoundAlreadyPlaying && (m_isWalking == false || m_character.Definition.LoopingFootsteps)) { if (cueEnum != EmptySoundPair && cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND]) { if (m_jetpackSustainTimer >= JETPACK_TIME_BETWEEN_SOUNDS) { if (primaryEmitter.Loop) primaryEmitter.StopSound(true); primaryEmitter.PlaySound(cueEnum, false, false); } } else if (primaryEmitter.SoundId.IsNull == false && primaryEmitter.SoundId == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND].SoundId) { if (m_jetpackSustainTimer <= 0f || cueEnum != CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND]) { primaryEmitter.StopSound(false); primaryEmitter.PlaySound(CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND], false, true); } } else if (cueEnum == EmptySoundPair) { foreach (var soundEmitter in m_soundEmitters) { if (soundEmitter.Loop) soundEmitter.StopSound(false); } } else if (cueEnum == m_lastPrimarySound && (cueEnum == CharacterSounds[(int)CharacterSoundsEnum.CROUCH_DOWN_SOUND] || cueEnum == CharacterSounds[(int)CharacterSoundsEnum.CROUCH_UP_SOUND])) { //do nothing } else { if (primaryEmitter.Loop) primaryEmitter.StopSound(false); primaryEmitter.PlaySound(cueEnum, true, false); } } else if (!m_character.Definition.LoopingFootsteps&& walkEmitter != null && cueEnum != null) { IKFeetStepSounds(walkEmitter, cueEnum); } m_lastPrimarySound = cueEnum; }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { base.Init(builder, cubeGrid); //m_subpartsSize = 0.5f * (0.5f * SlimBlock.CubeGrid.GridSize - 0.3f); if (BlockDefinition is MyDoorDefinition) { var doorDefinition = (MyDoorDefinition)BlockDefinition; MaxOpen = doorDefinition.MaxOpen; m_openSound = new MySoundPair(doorDefinition.OpenSound); m_closeSound = new MySoundPair(doorDefinition.CloseSound); } else { MaxOpen = 1.2f; m_openSound = new MySoundPair("BlockDoorSmallOpen"); m_closeSound = new MySoundPair("BlockDoorSmallClose"); } var ob = (MyObjectBuilder_Door)builder; m_open = ob.State; m_currOpening = ob.Opening; PowerReceiver = new MyPowerReceiver(MyConsumerGroupEnum.Doors, false, MyEnergyConstants.MAX_REQUIRED_POWER_DOOR, () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f); PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged; PowerReceiver.Update(); if (!Enabled || !PowerReceiver.IsPowered) UpdateSlidingDoorsPosition(true); OnStateChange(); if (m_open) { // required when reinitializing a door after the armor beneath it is destroyed if (Open && (m_currOpening == MaxOpen)) UpdateSlidingDoorsPosition(true); } SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
static MyTrees() { m_soundTreeBreak = new MySoundPair("ImpTreeBreak"); }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { var doorDefinition = BlockDefinition as MyDoorDefinition; MyStringHash resourceSinkGroup; if (doorDefinition != null) { MaxOpen = doorDefinition.MaxOpen; m_openSound = new MySoundPair(doorDefinition.OpenSound); m_closeSound = new MySoundPair(doorDefinition.CloseSound); resourceSinkGroup = MyStringHash.GetOrCompute(doorDefinition.ResourceSinkGroup); } else { MaxOpen = 1.2f; m_openSound = new MySoundPair("BlockDoorSmallOpen"); m_closeSound = new MySoundPair("BlockDoorSmallClose"); resourceSinkGroup = MyStringHash.GetOrCompute("Doors"); } var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( resourceSinkGroup, MyEnergyConstants.MAX_REQUIRED_POWER_DOOR, () => (Enabled && IsFunctional) ? sinkComp.MaxRequiredInput : 0f); sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged; ResourceSink = sinkComp; base.Init(builder, cubeGrid); //m_subpartsSize = 0.5f * (0.5f * SlimBlock.CubeGrid.GridSize - 0.3f); var ob = (MyObjectBuilder_Door)builder; m_open.Value = ob.State; if (ob.Opening == -1) { m_currOpening = IsFunctional ? 0 : MaxOpen; m_open.Value = !IsFunctional; } else { m_currOpening = ob.Opening; } if (!Enabled || !ResourceSink.IsPowered) { UpdateSlidingDoorsPosition(true); } OnStateChange(); if (m_open) { // required when reinitializing a door after the armor beneath it is destroyed if (Open && (m_currOpening == MaxOpen)) { UpdateSlidingDoorsPosition(true); } } sinkComp.Update(); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); if (BlockDefinition is MyMedicalRoomDefinition) { var def = (MyMedicalRoomDefinition)BlockDefinition; m_idleSound = new MySoundPair(def.IdleSound); m_progressSound = new MySoundPair(def.ProgressSound); } else { m_idleSound = new MySoundPair("BlockMedical"); m_progressSound = new MySoundPair("BlockMedicalProgress"); } m_rechargeSocket = new MyRechargeSocket(); NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; SteamUserId = (objectBuilder as MyObjectBuilder_MedicalRoom).SteamUserId; if (SteamUserId != 0) //backward compatibility { MyPlayer controller = Sync.Players.TryGetPlayerById(new MyPlayer.PlayerId(SteamUserId)); if (controller != null) { IDModule.Owner = controller.Identity.IdentityId; IDModule.ShareMode = MyOwnershipShareModeEnum.Faction; } } SteamUserId = 0; m_takeSpawneeOwnership = (objectBuilder as MyObjectBuilder_MedicalRoom).TakeOwnership; m_setFactionToSpawnee = (objectBuilder as MyObjectBuilder_MedicalRoom).SetFaction; SyncObject = new SyncClass(this); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; InitializeConveyorEndpoint(); PowerReceiver = new MyPowerReceiver( group: MyConsumerGroupEnum.Utility, isAdaptible: false, maxRequiredInput: MyEnergyConstants.MAX_REQUIRED_POWER_MEDICAL_ROOM, requiredInputFunc: () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f); PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged; PowerReceiver.Update(); AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this)); if (this.CubeGrid.CreatePhysics) Components.Add<MyRespawnComponent>(new MyRespawnComponent()); }
private MyCueId CheckDistanceSounds(MyCueId soundId) { if (soundId.IsNull == false) { if (m_lastSoundData != null && m_lastSoundData.DistantSounds != null && m_lastSoundData.DistantSounds.Count > 0) { float distanceToSoundSquered = Vector3.DistanceSquared(MySector.MainCamera.Position, this.SourcePosition); int bestSoundIndex = -1; m_usesDistanceSounds = true; m_secondaryEnabled = false; float dist, crossfadeDist; for (int i = 0; i < m_lastSoundData.DistantSounds.Count; i++) { dist = m_lastSoundData.DistantSounds[i].distance * m_lastSoundData.DistantSounds[i].distance; if (distanceToSoundSquered > dist) { bestSoundIndex = i; } else { crossfadeDist = m_lastSoundData.DistantSounds[i].distanceCrossfade >= 0f ? m_lastSoundData.DistantSounds[i].distanceCrossfade * m_lastSoundData.DistantSounds[i].distanceCrossfade : float.MaxValue; if (distanceToSoundSquered > crossfadeDist) { m_secondaryVolumeRatio = (distanceToSoundSquered - crossfadeDist) / (dist - crossfadeDist); m_secondaryEnabled = true; MySoundPair secondarySoundPair = new MySoundPair(m_lastSoundData.DistantSounds[i].sound); if (secondarySoundPair != MySoundPair.Empty) { m_secondaryCueEnum = SelectCue(secondarySoundPair); } else { m_secondaryCueEnum = new MyCueId(MyStringHash.GetOrCompute(m_lastSoundData.DistantSounds[bestSoundIndex].sound)); } } else { break; } } } if (bestSoundIndex >= 0) { MySoundPair soundPair = new MySoundPair(m_lastSoundData.DistantSounds[bestSoundIndex].sound); if (soundPair != MySoundPair.Empty) { m_soundPair = soundPair; soundId = SelectCue(m_soundPair); } else { soundId = new MyCueId(MyStringHash.GetOrCompute(m_lastSoundData.DistantSounds[bestSoundIndex].sound)); } } else { m_soundPair = m_closeSoundSoundPair; } } else { m_usesDistanceSounds = false; } } if (m_secondaryEnabled == false) { m_secondaryCueEnum = myEmptyCueId; } return(soundId); }
private void SetFallSound() { m_fallSound = new MySoundPair(m_fallSoundString.Value); }
private MyCueId CheckDistanceSounds(MyCueId soundId) { if (!soundId.IsNull) { using (this.m_lastSoundDataLock.AcquireExclusiveUsing()) { int num2; if (((this.m_lastSoundData != null) && (this.m_lastSoundData.DistantSounds != null)) && (this.m_lastSoundData.DistantSounds.Count > 0)) { float num = this.SourcePosition.LengthSquared(); num2 = -1; this.m_usesDistanceSounds = true; this.m_secondaryEnabled = false; for (int i = 0; i < this.m_lastSoundData.DistantSounds.Count; i++) { float num3 = this.m_lastSoundData.DistantSounds[i].Distance * this.m_lastSoundData.DistantSounds[i].Distance; if (num > num3) { num2 = i; } else { float num4 = (this.m_lastSoundData.DistantSounds[i].DistanceCrossfade >= 0f) ? (this.m_lastSoundData.DistantSounds[i].DistanceCrossfade * this.m_lastSoundData.DistantSounds[i].DistanceCrossfade) : float.MaxValue; if (num <= num4) { break; } this.m_secondaryVolumeRatio = (num - num4) / (num3 - num4); this.m_secondaryEnabled = true; MySoundPair objA = new MySoundPair(this.m_lastSoundData.DistantSounds[i].Sound, true); if (!ReferenceEquals(objA, MySoundPair.Empty)) { this.m_secondaryCueEnum = this.SelectCue(objA); } else if (num2 >= 0) { this.m_secondaryCueEnum = new MyCueId(MyStringHash.GetOrCompute(this.m_lastSoundData.DistantSounds[num2].Sound)); } else { this.m_secondaryEnabled = false; } } } } else { this.m_usesDistanceSounds = false; goto TR_0002; } if (num2 < 0) { this.m_soundPair = this.m_closeSoundSoundPair; } else { MySoundPair objA = new MySoundPair(this.m_lastSoundData.DistantSounds[num2].Sound, true); if (ReferenceEquals(objA, MySoundPair.Empty)) { soundId = new MyCueId(MyStringHash.GetOrCompute(this.m_lastSoundData.DistantSounds[num2].Sound)); } else { this.m_soundPair = objA; soundId = this.SelectCue(this.m_soundPair); } } } } TR_0002: if (!this.m_secondaryEnabled) { this.m_secondaryCueEnum = this.myEmptyCueId; } return(soundId); }
private void StartLoopSound(MySoundPair cueEnum) { if (m_soundEmitter.Loop) m_soundEmitter.PlaySingleSound(cueEnum, true, true); else m_soundEmitter.PlaySound(cueEnum); }
public MyEntity3DSoundEmitter(VRage.Game.Entity.MyEntity entity, bool useStaticList = false, float dopplerScaler = 1f) { int num1; int num2; this.m_cueEnum = new MyCueId(MyStringHash.NullOrEmpty); this.myEmptyCueId = new MyCueId(MyStringHash.NullOrEmpty); this.m_soundPair = MySoundPair.Empty; this.m_secondaryCueEnum = new MyCueId(MyStringHash.NullOrEmpty); this.m_secondaryBaseVolume = 1f; this.m_baseVolume = 1f; this.m_soundsQueue = new List <MyCueId>(); this.m_closeSoundCueId = new MyCueId(MyStringHash.NullOrEmpty); this.m_closeSoundSoundPair = MySoundPair.Empty; this.m_volumeMultiplier = 1f; this.m_lastSoundDataLock = new FastResourceLock(); this.m_activeEffect = MyStringHash.NullOrEmpty; this.m_lastPlayedWaveNumber = -1; this.EmitterMethods = new Dictionary <int, ConcurrentCachingList <Delegate> >(); this.CanPlayLoopSounds = true; this.m_entity = entity; this.DopplerScaler = dopplerScaler; foreach (object obj2 in Enum.GetValues(typeof(MethodsEnum))) { this.EmitterMethods.Add((int)obj2, new ConcurrentCachingList <Delegate>()); } this.EmitterMethods[1].Add(new Func <bool>(this.IsControlledEntity)); if (((MySession.Static != null) && MySession.Static.Settings.RealisticSound) && MyFakes.ENABLE_NEW_SOUNDS) { this.EmitterMethods[0].Add(new Func <bool>(this.IsInAtmosphere)); this.EmitterMethods[0].Add(new Func <bool>(this.IsCurrentWeapon)); this.EmitterMethods[0].Add(new Func <bool>(this.IsOnSameGrid)); this.EmitterMethods[0].Add(new Func <bool>(this.IsControlledEntity)); this.EmitterMethods[1].Add(new Func <bool>(this.IsCurrentWeapon)); this.EmitterMethods[2].Add(new Func <MySoundPair, MyCueId>(this.SelectCue)); this.EmitterMethods[3].Add(new Func <MyStringHash>(this.SelectEffect)); } this.UpdateEmitterMethods(); if ((MySession.Static == null) || !MySession.Static.Settings.RealisticSound) { num1 = 0; } else { num1 = (int)MyFakes.ENABLE_NEW_SOUNDS; } this.m_useRealisticByDefault = (bool)num1; if ((MySession.Static == null) || !MySession.Static.Settings.RealisticSound) { num2 = 0; } else { num2 = (int)MyFakes.ENABLE_NEW_SOUNDS; } if ((((num2 & useStaticList) != 0) && (entity != null)) && MyFakes.ENABLE_NEW_SOUNDS_QUICK_UPDATE) { List <MyEntity3DSoundEmitter> entityEmitters = m_entityEmitters; lock (entityEmitters) { m_entityEmitters.Add(this); } } }
private void StartSound(MySoundPair cueEnum) { m_gunBase.StartShootSound(m_soundEmitter); }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { MyStringHash orCompute; this.m_physicsInitiated = false; MyDoorDefinition blockDefinition = base.BlockDefinition as MyDoorDefinition; if (blockDefinition != null) { this.MaxOpen = blockDefinition.MaxOpen; this.m_openSound = new MySoundPair(blockDefinition.OpenSound, true); this.m_closeSound = new MySoundPair(blockDefinition.CloseSound, true); orCompute = MyStringHash.GetOrCompute(blockDefinition.ResourceSinkGroup); this.m_openingSpeed = blockDefinition.OpeningSpeed; } else { this.MaxOpen = 1.2f; this.m_openSound = new MySoundPair("BlockDoorSmallOpen", true); this.m_closeSound = new MySoundPair("BlockDoorSmallClose", true); orCompute = MyStringHash.GetOrCompute("Doors"); this.m_openingSpeed = 1f; } MyResourceSinkComponent sinkComp = new MyResourceSinkComponent(1); sinkComp.Init(orCompute, 3E-05f, delegate { if (!this.Enabled || !this.IsFunctional) { return(0f); } return(sinkComp.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId)); }); sinkComp.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged); base.ResourceSink = sinkComp; base.Init(builder, cubeGrid); base.NeedsWorldMatrix = false; MyObjectBuilder_Door door = (MyObjectBuilder_Door)builder; base.m_open.SetLocalValue(door.State); if (door.Opening != -1f) { this.m_currOpening = MathHelper.Clamp(door.Opening, 0f, this.MaxOpen); } else { this.m_currOpening = base.IsFunctional ? 0f : this.MaxOpen; base.m_open.SetLocalValue(!base.IsFunctional); } if (!base.Enabled || !base.ResourceSink.IsPoweredByType(MyResourceDistributorComponent.ElectricityId)) { this.UpdateSlidingDoorsPosition(); } this.OnStateChange(); if (((base.m_open != null) && base.Open) && (this.m_currOpening == this.MaxOpen)) { this.UpdateSlidingDoorsPosition(); } sinkComp.Update(); base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged); if (!Sync.IsServer) { base.NeedsWorldMatrix = true; } }
public void PlayActionSound(MySoundPair actionSound) { m_lastActionSound = actionSound; m_soundEmitters[(int)MySoundEmitterEnum.Action].PlaySound(m_lastActionSound); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { var medicalRoomDefinition = BlockDefinition as MyMedicalRoomDefinition; MyStringHash resourceSinkGroup; if (medicalRoomDefinition != null) { m_idleSound = new MySoundPair(medicalRoomDefinition.IdleSound); m_progressSound = new MySoundPair(medicalRoomDefinition.ProgressSound); resourceSinkGroup = MyStringHash.GetOrCompute(medicalRoomDefinition.ResourceSinkGroup); } else { m_idleSound = new MySoundPair("BlockMedical"); m_progressSound = new MySoundPair("BlockMedicalProgress"); resourceSinkGroup = MyStringHash.GetOrCompute("Utility"); } SinkComp = new MyResourceSinkComponent(); SinkComp.Init( resourceSinkGroup, MyEnergyConstants.MAX_REQUIRED_POWER_MEDICAL_ROOM, () => (Enabled && IsFunctional) ? SinkComp.MaxRequiredInput : 0f); SinkComp.IsPoweredChanged += Receiver_IsPoweredChanged; base.Init(objectBuilder, cubeGrid); m_rechargeSocket = new MyRechargeSocket(); NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SteamUserId = (objectBuilder as MyObjectBuilder_MedicalRoom).SteamUserId; if (SteamUserId != 0) //backward compatibility { MyPlayer controller = Sync.Players.GetPlayerById(new MyPlayer.PlayerId(SteamUserId)); if (controller != null) { IDModule.Owner = controller.Identity.IdentityId; IDModule.ShareMode = MyOwnershipShareModeEnum.Faction; } } SteamUserId = 0; m_takeSpawneeOwnership = (objectBuilder as MyObjectBuilder_MedicalRoom).TakeOwnership; m_setFactionToSpawnee = (objectBuilder as MyObjectBuilder_MedicalRoom).SetFaction; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; InitializeConveyorEndpoint(); SinkComp.Update(); AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(SinkComp, this)); if (this.CubeGrid.CreatePhysics) Components.Add<MyRespawnComponent>(new MyRespawnComponent()); m_healingAllowed = medicalRoomDefinition.HealingAllowed; m_refuelAllowed = medicalRoomDefinition.RefuelAllowed; m_suitChangeAllowed = medicalRoomDefinition.SuitChangeAllowed; m_customWardrobesEnabled = medicalRoomDefinition.CustomWardrobesEnabled; m_forceSuitChangeOnRespawn = medicalRoomDefinition.ForceSuitChangeOnRespawn; m_customWardrobeNames = medicalRoomDefinition.CustomWardrobeNames; m_respawnSuitName = medicalRoomDefinition.RespawnSuitName; m_spawnWithoutOxygenEnabled = medicalRoomDefinition.SpawnWithoutOxygenEnabled; RespawnAllowed = medicalRoomDefinition.RespawnAllowed; }
private void IKFeetStepSounds(MyEntity3DSoundEmitter walkEmitter, MySoundPair cueEnum) { var movementState = m_character.GetCurrentMovementState(); if (movementState.GetMode() == MyCharacterMovement.Flying) return; if (movementState.GetSpeed() != m_lastUpdateMovementState.GetSpeed()) { walkEmitter.StopSound(true); m_lastStepTime = 0; } int usedMinimumDelay = int.MaxValue; if (movementState.GetDirection() != MyCharacterMovement.NoDirection) { switch (movementState.GetSpeed()) { case MyCharacterMovement.NormalSpeed: usedMinimumDelay = m_stepMinimumDelayWalk; break; case MyCharacterMovement.Fast: usedMinimumDelay = m_stepMinimumDelayRun; break; case MyCharacterMovement.VeryFast: usedMinimumDelay = m_stepMinimumDelaySprint; break; } } bool minimumDelayExceeded = false; minimumDelayExceeded = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastStepTime) >= usedMinimumDelay; //MyRenderProxy.DebugDrawAABB(m_character.PositionComp.WorldAABB, Color.White); if (minimumDelayExceeded) { int leftAnkleBoneIndex, rightAnkleBoneIndex; MyCharacterBone leftAnkleBone = m_character.AnimationController != null ? m_character.AnimationController.FindBone(m_character.Definition.LeftAnkleBoneName, out leftAnkleBoneIndex) : null; MyCharacterBone rightAnkleBone = m_character.AnimationController != null ? m_character.AnimationController.FindBone(m_character.Definition.RightAnkleBoneName, out rightAnkleBoneIndex) : null; Vector3 posLeftFoot = leftAnkleBone != null ? leftAnkleBone.AbsoluteTransform.Translation : m_character.PositionComp.LocalAABB.Center; Vector3 posRightFoot = rightAnkleBone != null ? rightAnkleBone.AbsoluteTransform.Translation : m_character.PositionComp.LocalAABB.Center; float ankleHeight; MyFeetIKSettings settingsIK; if (m_character.Definition.FeetIKSettings != null && m_character.Definition.FeetIKSettings.TryGetValue(MyCharacterMovementEnum.Standing, out settingsIK)) { ankleHeight = settingsIK.FootSize.Y; } else { ankleHeight = DEFAULT_ANKLE_HEIGHT; } float charSpeed = 0f; if (m_character.AnimationController != null) m_character.AnimationController.Variables.GetValue(MyAnimationVariableStorageHints.StrIdSpeed, out charSpeed); if (posLeftFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y || posRightFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y) { if(charSpeed > 0.05f) walkEmitter.PlaySound(cueEnum); m_lastStepTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; } } m_lastUpdateMovementState = movementState; }
private void StartIdleSound(MySoundPair cuePair) { if (m_soundEmitter.IsPlaying && m_soundEmitter.SoundId != cuePair.SoundId && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastContactTime < 100) return; StartLoopSound(cuePair); }
private void StartSound(MySoundPair cuePair) { if ((m_soundEmitter.Sound != null) && (m_soundEmitter.Sound.IsPlaying) && (m_soundEmitter.SoundId == cuePair.SoundId)) return; m_soundEmitter.StopSound(true); m_soundEmitter.PlaySingleSound(cuePair, true); }
private void SetFallSound() { m_fallSound = new MySoundPair(m_fallSoundString.Value); NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; }