/// <summary> /// Updates resource. /// </summary> public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); bool decoyLiving = true; if (m_elapsedMiliseconds > TimeToActivate) { decoyLiving = UpdateParticles(); this.Physics.LinearVelocity = Vector3.Zero; if (this.Visible) { this.Visible = false; m_flareLoop = MyAudio.AddCue2dOr3d(this, MySoundCuesEnum.SfxFlareLoop01, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); } } if (!decoyLiving) { MarkForClose(); } else { // Aggro near bots MyDangerZones.Instance.NotifyArea(GetPosition(), 300, OwnerEntity); if (m_flareLoop != null && m_flareLoop.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_flareLoop, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); } } }
void UpdateMovingCue() { if ((m_movingCue != null) && (m_movingCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(m_movingCue, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, this.Physics.LinearVelocity); } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); if (m_smokeCue != null && m_smokeCue.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_smokeCue, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); } }
public override void OnWorldPositionChanged(object source) { base.OnWorldPositionChanged(source); if (chatterCue.HasValue && chatterCue.Value.IsPlaying) { MyAudio.UpdateCuePosition(chatterCue, this.GetPosition(), this.GetForward(), this.GetUp(), Vector3.Zero); } }
public override void UpdateBeforeSimulation() { //We dont want to update every frame because of this //Visible = IsDummyVisible(); base.UpdateBeforeSimulation(); if ((DummyFlags & MyDummyPointFlags.PARTICLE) != 0 && ParticleEffect == null && //MyGuiScreenGamePlay.Static.IsGameActive() && (PersistentFlags & MyPersistentEntityFlags.Enabled) > 0) { StartEffect(); } if (ParticleEffect != null && //((MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) || (DummyFlags & MyDummyPointFlags.PARTICLE) == 0) { StopEffect(); } if (m_cue != null && m_cue.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_cue, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero); } if (DoesParticleEffectNeedDetector()) { RefreshParticleSound(); if (m_smallShipDetector == null) { RefreshParticleEffect(); } foreach (var detectedEntityPair in m_smallShipDetector.GetDetectedEntities()) { var detectedSmallShip = (MySmallShip)detectedEntityPair.Key; float distance = Vector3.Distance(detectedSmallShip.GetPosition(), this.GetPosition()); float influenceStrength = MathHelper.Clamp((m_smallShipDetector.Radius - distance) / m_smallShipDetector.Radius, 0f, 1f); if (m_effectHelper.DamageStrength.HasValue) { DamageShip(detectedSmallShip, influenceStrength); } if (m_effectHelper.DirectionalPushStrength.HasValue) { PushShip(detectedSmallShip, distance, influenceStrength); } } } }
void OwnerPositionChanged(object sender, EventArgs eventArgs) { if (m_loopSound != null && m_loopSound.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_loopSound, m_kinematicPartOwner.WorldMatrix.Translation, Vector3.Forward, Vector3.Forward, Vector3.Zero); } if (m_loopDamagedSound != null && m_loopDamagedSound.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_loopDamagedSound, m_kinematicPartOwner.WorldMatrix.Translation, Vector3.Forward, Vector3.Forward, Vector3.Zero); } }
public override void OnWorldPositionChanged(object source) { base.OnWorldPositionChanged(source); if (ParticleEffect != null) { ParticleEffect.WorldMatrix = this.WorldMatrix; } if (m_cue != null && m_cue.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_cue, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero); } }
private void UpdateSoundPositions() { if (m_loopSound != null && m_loopSound.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_loopSound, m_ownerKinematic.WorldMatrix.Translation, m_ownerKinematic.WorldMatrix.Forward, m_ownerKinematic.WorldMatrix.Up, new Vector3(0, 0, 0)); } if (m_startSound != null && m_startSound.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_startSound, m_ownerKinematic.WorldMatrix.Translation, m_ownerKinematic.WorldMatrix.Forward, m_ownerKinematic.WorldMatrix.Up, new Vector3(0, 0, 0)); } if (m_endSound != null && m_endSound.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_endSound, m_ownerKinematic.WorldMatrix.Translation, m_ownerKinematic.WorldMatrix.Forward, m_ownerKinematic.WorldMatrix.Up, new Vector3(0, 0, 0)); } }
protected void PlayKinematicLoopingSound() { if (m_kinematicPartOwner.HealthRatio > MyPrefabConstants.DAMAGED_HEALTH || !HasSoundForDamagedState) { PlayLoopSound(ref m_loopSound, m_loopSoundCue); StopKinematicSounds(m_loopSound); MyAudio.UpdateCuePosition(m_loopSound, this.GetPosition(), Vector3.Forward, Vector3.Up, Vector3.Zero); } else { PlayLoopSound(ref m_loopDamagedSound, m_loopDamagedSoundCue); StopKinematicSounds(m_loopDamagedSound); MyAudio.UpdateCuePosition(m_loopSound, this.GetPosition(), Vector3.Forward, Vector3.Up, Vector3.Zero); } }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); if (Parent == null) { return; } if (m_cue == null || !m_cue.Value.IsPlaying) { return; } MyAudio.UpdateCuePosition(m_cue, Vector3.Transform(m_pointLocalMatrix.Translation, base.WorldMatrix), WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); }
protected override void UpdatePrefabAfterSimulation() { base.UpdatePrefabAfterSimulation(); /* * if (m_cue != null && m_cue.Value.IsPlaying) * { * MyAudio.CalculateOcclusion(m_cue.Value, m_cue.Value.Center); * } */ PlaySound(); if (m_cue != null && m_cue.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_cue, Vector3.Transform(m_pointLocalMatrix.Translation, base.WorldMatrix), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // HACK: Multiplayer if (IsDummy && CurrentState == MyDrillStateEnum.Drilling) { Shot(null); } switch (CurrentState) { case MyDrillStateEnum.InsideShip: // If drill isnt active we stop sound that might not be stopped before StopDustEffect(); StopIdleCue(); return; case MyDrillStateEnum.Deactivated: PullDrillBack(); return; case MyDrillStateEnum.Activated: EjectDrill(); break; case MyDrillStateEnum.Drilling: Drill(); break; } if ((m_drillCue != null) && m_drillCue.Value.IsPlaying) { MyAudio.UpdateCuePosition(m_drillCue, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, this.Parent.Physics.LinearVelocity); } if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeStarted) > 100) { CurrentState = MyDrillStateEnum.Activated; StopDrillingCue(); StopDustEffect(); //StopMovingCue(); } }
/// <summary> /// Called when [world position changed]. /// </summary> /// <param name="source">The source object that caused this event.</param> public override void OnWorldPositionChanged(object source) { base.OnWorldPositionChanged(source); if (Physics != null && m_thrusterCue != null) { // Update thruster cue/sound MyAudio.UpdateCuePosition(m_thrusterCue, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); } // Update light position if (m_light != null) { m_light.SetPosition(GetPosition()); m_light.Color = MyMissileHelperUtil.GetMissileLightColor(); m_light.Range = MyMissileConstants.MISSILE_LIGHT_RANGE; } }
public override void UpdateBeforeSimulation() { if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_startTime + m_maxTime) { MarkForClose(); return; } if (m_trailEffect != null) { m_trailEffect.WorldMatrix = Matrix.CreateWorld(this.WorldVolume.Center, m_trailEffect.WorldMatrix.Forward, m_trailEffect.WorldMatrix.Up); } if (m_burningCue != null) { MyAudio.UpdateCuePosition(m_burningCue, this.GetPosition(), this.GetForward(), Vector3.Up, Vector3.Zero); } base.UpdateBeforeSimulation(); }
/// <summary> /// Initialize flares to fire /// </summary> private void FireFlares() { m_flareDeploy = MyAudio.AddCue2dOr3d(this, MySoundCuesEnum.SfxFlareDeploy, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics.LinearVelocity); MyAudio.UpdateCuePosition(m_flareDeploy, GetPosition(), GetForward(), GetUp(), Physics.LinearVelocity); foreach (FlareParticle particle in m_particles) { particle.Position = WorldMatrix.Translation; Matrix rot = Matrix.CreateFromAxisAngle(WorldMatrix.Forward, MyMwcUtils.GetRandomFloat(0.0f, MathHelper.TwoPi)); particle.Dir = Vector3.TransformNormal(MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Up, 0.2f), rot); particle.FlyTime = MyMwcUtils.GetRandomFloat(500, 8000); particle.Life = MyMwcUtils.GetRandomFloat(8000, MyDecoyFlareConstants.MAX_LIVING_TIME); var effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.UniversalLauncher_DecoyFlare); effect.UserBirthMultiplier = 0.3f; particle.ParticleEffect = effect; } m_startParticleTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_flaresFired = true; }
public static void Update() { // Update only if sun wind is active if (IsActive == false) { return; } float darkeningPhase; float dt; int relTime = GetDarkeningPhase(out darkeningPhase, out dt); if (relTime > MaxTimeMs) { Clear(); return; } MyAudio.UpdateCuePosition(ambientSound, MyCamera.Position + MyCamera.ForwardVector * -MaxSoundDistance * (1 - darkeningPhase), MyCamera.ForwardVector, MyCamera.UpVector, Vector3.Zero); MyAudio.UpdateCueVolume(ambientSound, darkeningPhase * MaxAmbientVolume); // update smoke foreach (SmokeParticle part in smokeParticles) { Vector3 toCamera = (MyCamera.Position - part.Pos); toCamera.Normalize(); float alpha = darkeningPhase * MaxSmokeAlpha; part.Color = new Vector4(alpha, alpha, alpha, alpha); //part.Color.W = darkeningPhase; part.Pos += part.Velocity * dt + toCamera * CenterBias * dt; part.Angle += part.AngularVelocity * dt; } // remove old ice and sparks m_iceList.Clear(); foreach (IceParticle particle in iceParticles) { if (particle.StartTime + 4000 < relTime) { m_iceList.Add(particle); } } foreach (IceParticle ice in m_iceList) { ice.AsteroidEntity.MarkForClose(); Debug.Assert(ice.TrailEffect != null, "ice.TrailEffect != null"); ice.TrailEffect.Stop(); ice.TrailEffect = null; StopCue(ice.Sound); iceParticles.Remove(ice); } int c = 0; while (c < storms.Count) { ElectricStorm storm = storms[c]; if (storm.StartTime + 1500 < relTime) { storms.RemoveAt(c); continue; } c++; } // if its dark add new sparks and ice balls if (darkeningPhase >= 1) { if (storms.Count < MaxSparkCount && MyMwcUtils.GetRandomInt(SparkEveryMs) < dt * 1000.0f) { var storm = new ElectricStorm { Position = MyCamera.Position + MyCamera.ForwardVector * 250 + MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector) * MyMwcUtils.GetRandomFloat(0, 300), StartTime = relTime, Effect = MyParticlesManager.CreateParticleEffect( (int)MyParticleEffectsIDEnum.Damage_Sparks), }; storm.Effect.WorldMatrix = Matrix.CreateTranslation(storm.Position); storm.Effect.AutoDelete = true; storm.Effect.UserScale = 2; storm.Sound = MyAudio.AddCue2D(MySoundCuesEnum.SfxSpark); storms.Add(storm); } if (iceParticles.Count < MaxIceCount && MyMwcUtils.GetRandomInt(IceEveryMs) < dt * 1000.0f) { Vector3 dir = MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector); Vector3 pos = MyCamera.Position + MyCamera.ForwardVector * 250 + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 200) + dir * MyMwcUtils.GetRandomFloat(0, 500); MyMwcObjectBuilder_StaticAsteroid rockModel = MySectorGenerator.GenerateStaticAsteroid(MyMwcUtils.GetRandomFloat(0.1f, 2f), MyStaticAsteroidTypeSetEnum.A, MyMwcVoxelMaterialsEnum.Ice_01, pos, random, asteroidTypes); Matrix matrix = Matrix.CreateFromAxisAngle(MyMwcUtils.GetRandomVector3Normalized(), MyMwcUtils.GetRandomFloat(0, MathHelper.Pi)); matrix.Translation = pos; MyEntity asteroid = MyEntities.CreateFromObjectBuilderAndAdd(null, rockModel, matrix); asteroid.Physics.Enabled = false; asteroid.CastShadows = false; MyParticleEffect effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot); Vector3 velocity = -dir *MyMwcUtils.GetRandomInt(150, 400); iceParticles.Add(new IceParticle { StartTime = relTime, Position = pos, Direction = -dir, AsteroidEntity = asteroid, TrailEffect = effect, RotAxis = MyMwcUtils.GetRandomVector3Normalized(), RotAngle = MyMwcUtils.GetRandomRadian(), AngularVelocity = MyMwcUtils.GetRandomFloat(0.2f, 10f), Velocity = velocity, Sound = MyAudio.AddCue3D(MySoundCuesEnum.WepSniperHighFire2d, pos, dir, dir * -dir, velocity) }); } } // update ice parts foreach (IceParticle particle in iceParticles) { particle.RotAngle += particle.AngularVelocity * dt; particle.Position += particle.Velocity * dt; Matrix matrix = Matrix.CreateFromAxisAngle(particle.RotAxis, particle.RotAngle); matrix.Translation = particle.Position; particle.AsteroidEntity.SetWorldMatrix(matrix); Matrix trans = Matrix.CreateTranslation(-particle.Direction * 10); particle.TrailEffect.WorldMatrix = matrix * trans; MyAudio.UpdateCuePosition(particle.Sound, particle.Position, particle.Direction, particle.Direction * -particle.Direction, particle.Velocity); } lastUpdateMs = MyMinerGame.TotalGamePlayTimeInMilliseconds; }
/// <summary> /// Updates resource. /// </summary> public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); if ((!GetParentMinerShip().Config.Engine.On || GetParentMinerShip().Fuel <= 0) && (CurrentState == MyHarvestingDeviceEnum.InVoxel || CurrentState == MyHarvestingDeviceEnum.FindingVoxel)) { StartFastReturningBack(); } if (CurrentState == MyHarvestingDeviceEnum.InsideShip) { // Do nothing return; } if (CurrentState == MyHarvestingDeviceEnum.FindingVoxel) { // Head in local space m_headPositionLocal += this.LocalMatrix.Forward * MyHarvestingTubeConstants.EJECTION_SPEED_IN_METERS_PER_SECOND; } else if (CurrentState == MyHarvestingDeviceEnum.ReturningBack) { // Head in local space m_headPositionLocal -= this.LocalMatrix.Forward * MyHarvestingTubeConstants.EJECTION_SPEED_IN_METERS_PER_SECOND; } else if (CurrentState == MyHarvestingDeviceEnum.FastReturningBack) { // Head in local space m_headPositionLocal -= this.LocalMatrix.Forward * MyHarvestingTubeConstants.FAST_PULL_BACK_IN_METERS_PER_SECOND; } // Transform head position into world space Matrix worldMatrix = Parent.WorldMatrix; m_harvestingOreHead.LocalMatrix = Matrix.CreateWorld(m_headPositionLocal, m_harvestingOreHead.LocalMatrix.Forward, m_harvestingOreHead.LocalMatrix.Up); m_headPositionTransformed = m_harvestingOreHead.WorldMatrix.Translation; // Distance must carry sign (plus/minus) because when we need to know if head is behind it's starting point when pulling back // IMPORTANT: Forward is in -Z direction, so that's why I subtract position from head and not oppositely float distance = this.LocalMatrix.Translation.Z - m_headPositionLocal.Z; if (CurrentState == MyHarvestingDeviceEnum.ReturningBack || CurrentState == MyHarvestingDeviceEnum.FastReturningBack) { if (distance <= MyHarvestingTubeConstants.DISTANCE_TO_PLUG_IN_THE_TUBE) { StartInsideShip(); } } else { if (distance >= MyHarvestingTubeConstants.MAX_DISTANCE_OF_HARVESTING_DEVICE) { StartReturningBack(); } } // Sphere for head of harvester BoundingSphere headSphere = new BoundingSphere(m_headPositionTransformed, m_harvestingOreHead.ModelLod0.BoundingSphere.Radius); if (CurrentState == MyHarvestingDeviceEnum.FindingVoxel) { // Check if head doesn't collide with anything MyEntity sphereResult = MyEntities.GetIntersectionWithSphere(ref headSphere, m_parentMinerShip, null); if (sphereResult != null) { if (sphereResult is MyVoxelMap) { StartInVoxel((MyVoxelMap)sphereResult); } else { // Intersection between sphere and anything else but voxels, so we start pulling back quickly StartFastReturningBack(); } } } // If we are connected to voxel check permanently if the voxel is still there if ((CurrentState == MyHarvestingDeviceEnum.InVoxel) && (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeCheckedForVoxelPresence) > MyHarvestingTubeConstants.INTERVAL_TO_CHECK_FOR_VOXEL_CONNECTION_IN_MILISECONDS) { m_lastTimeCheckedForVoxelPresence = MyMinerGame.TotalGamePlayTimeInMilliseconds; // Check if head doesn't collide with anything MyEntity sphereResult = MyEntities.GetIntersectionWithSphere(ref headSphere, m_parentMinerShip, null); if (!(sphereResult is MyVoxelMap)) { StartFastReturningBack(); } } // If we are connected to voxel we can harvest it if (CurrentState == MyHarvestingDeviceEnum.InVoxel) { m_actualVoxelContent -= m_harvestingSpeed; if (m_actualVoxelContent <= 0) { StartReleaseVoxel(); } } if ((WorldMatrix.Translation - m_headPositionTransformed).Length() > MyMwcMathConstants.EPSILON) { // Check if tube doesn't colide with something MyLine tubeLine = new MyLine(WorldMatrix.Translation, m_headPositionTransformed, true); MyIntersectionResultLineTriangleEx?tubeIntersection = MyEntities.GetIntersectionWithLine(ref tubeLine, this, m_parentMinerShip); // We colide with something and we need fast return back if (tubeIntersection != null) { StartFastReturningBack(); } } if (CurrentState == MyHarvestingDeviceEnum.InVoxel) { m_parentMinerShip.IncreaseHeadShake(MyHarvestingTubeConstants.SHAKE_DURING_IN_VOXELS); } else if ((CurrentState == MyHarvestingDeviceEnum.FastReturningBack) || (CurrentState == MyHarvestingDeviceEnum.FindingVoxel) || (CurrentState == MyHarvestingDeviceEnum.ReturningBack)) { m_parentMinerShip.IncreaseHeadShake(MyHarvestingTubeConstants.SHAKE_DURING_EJECTION); } if (m_light != null) { m_light.SetPosition(m_headPositionTransformed - WorldMatrix.Forward); } if ((m_tubeMovingCue != null) && (m_tubeMovingCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(m_tubeMovingCue, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } if ((m_grindingCue != null) && (m_grindingCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(m_grindingCue, m_headPositionTransformed, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } m_harvestingOreHead.SetData(ref m_worldMatrixForRenderingFromCockpitView); }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // Cannon is rotating while shoting. After that, it will slow-down. float normalizedRotationSpeed = 1.0f - MathHelper.Clamp((float)(MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) / m_rotationTimeout, 0, 1); normalizedRotationSpeed = MathHelper.SmoothStep(0, 1, normalizedRotationSpeed); m_rotationAngle -= normalizedRotationSpeed * MyAutocanonConstants.ROTATION_SPEED_PER_SECOND * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; Matrix worldMatrix = this.WorldMatrix; m_positionMuzzleInWorldSpace = GetMuzzlePosition(m_barrel.GetMuzzlePosition()); m_barrel.SetData(ref m_worldMatrixForRenderingFromCockpitView, m_rotationAngle); // Handle 'motor loop and motor end' cues if ((m_cannonMotorEndPlayed == false) && ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) > MyAutocanonConstants.SHOT_INTERVAL_IN_MILISECONDS)) { // Stop 'shooting loop' cue if (MyMinerGame.TotalGamePlayTimeInMilliseconds > m_lastTimeShoot + MyAutocanonConstants.MIN_TIME_RELEASE_INTERVAL_IN_MILISECONDS) { MySoundCue?autocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK_LOOP); if ((autocanonAttackLoopCue != null) && (autocanonAttackLoopCue.Value.IsPlaying == true)) { autocanonAttackLoopCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate); } autocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK); if ((autocanonAttackLoopCue != null) && (autocanonAttackLoopCue.Value.IsPlaying == true)) { autocanonAttackLoopCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate); } // Start 'release' cue MySoundCue?autocanonReleaseCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_RELEASE); if ((autocanonReleaseCue == null) || (autocanonReleaseCue.Value.IsPlaying == false)) { GetParentMinerShip().UnifiedWeaponCueSet( AUTOCANON_RELEASE, MyAudio.AddCue2dOr3d(GetParentMinerShip(), AUTOCANON_RELEASE, Parent.GetPosition(), Parent.WorldMatrix.Forward, Parent.WorldMatrix.Up, Parent.Physics.LinearVelocity)); } m_cannonMotorEndPlayed = true; } } // Update sound position MySoundCue?updateAutocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK_LOOP); if ((updateAutocanonAttackLoopCue != null) && (updateAutocanonAttackLoopCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonAttackLoopCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } updateAutocanonAttackLoopCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_ATTACK); if ((updateAutocanonAttackLoopCue != null) && (updateAutocanonAttackLoopCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonAttackLoopCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } // Update sound position MySoundCue?updateAutocanonReleaseCue = GetParentMinerShip().UnifiedWeaponCueGet(AUTOCANON_RELEASE); if ((updateAutocanonReleaseCue != null) && (updateAutocanonReleaseCue.Value.IsPlaying == true)) { MyAudio.UpdateCuePosition(updateAutocanonReleaseCue, m_positionMuzzleInWorldSpace, WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity); } // If gun fires too much, we start generating smokes at the muzzle if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_smokeLastTime) >= (MyAutocanonConstants.SMOKES_INTERVAL_IN_MILISECONDS)) { m_smokeLastTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; SmokesToGenerateDecrease(); if (m_smokesToGenerate > 0 && m_smokeEffect == null) { if (MyCamera.GetDistanceWithFOV(GetPosition()) < 150) { m_smokeEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Autocannon); m_smokeEffect.WorldMatrix = WorldMatrix; m_smokeEffect.OnDelete += new EventHandler(m_smokeEffect_OnDelete); } } } if (m_smokeEffect != null) { float smokeOffset = 0.2f; if ((MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.CameraAttachedTo == MinerWars.AppCode.Game.GUI.MyCameraAttachedToEnum.PlayerMinerShip) && (Parent == MySession.PlayerShip)) { smokeOffset = 0.0f; } m_smokeEffect.WorldMatrix = Matrix.CreateTranslation(m_positionMuzzleInWorldSpace + worldMatrix.Forward * smokeOffset); m_smokeEffect.UserBirthMultiplier = m_smokesToGenerate; } }
public static void Update() { // Update only if sun wind is active if (IsActive == false) { return; } //? float dT = ((float)MyMinerGame.TotalGamePlayTimeInMilliseconds - (float)m_timeLastUpdate) / 1000.0f; m_timeLastUpdate = MyMinerGame.TotalGamePlayTimeInMilliseconds; if ((MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) || MyMinerGame.IsPaused()) { return; } m_deltaTime += dT; float traveledDistance = m_speed * m_deltaTime; // If sun wind finished its way, we will turn it off if (traveledDistance >= MySunWindConstants.SUN_WIND_LENGTH_TOTAL) { IsActive = false; StopCue(); return; } Vector3 campos = MyCamera.Position; // This is plane that goes through sun wind, it's in its middle m_planeMiddle = new MyPlane(m_initialSunWindPosition + m_directionFromSunNormalized * traveledDistance, m_directionFromSunNormalized); m_distanceToSunWind = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeMiddle); // We make sure that sound moves always on line that goes through camera. So it's not in the middle of sun wind, more like middle where is camera. // Reason is that I want the sound always go through camera. m_positionOnCameraLine = MyCamera.Position - m_directionFromSunNormalized * m_distanceToSunWind; Vector3 positionFront = m_positionOnCameraLine + m_directionFromSunNormalized * 5000; Vector3 positionBack = m_positionOnCameraLine + m_directionFromSunNormalized * -5000; m_planeFront = new MyPlane(ref positionFront, ref m_directionFromSunNormalized); m_planeBack = new MyPlane(ref positionBack, ref m_directionFromSunNormalized); float distanceToFrontPlane = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeFront); float distanceToBackPlane = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeBack); Vector3 positionOfSound; if ((distanceToFrontPlane <= 0) && (distanceToBackPlane >= 0)) { positionOfSound = MyCamera.Position; } else if (distanceToFrontPlane > 0) { positionOfSound = positionFront; } else { positionOfSound = positionBack; } // Update position of sound. It works like this: we hear coming sound, then we are in the sound and then we hear it coming out. MyAudio.UpdateCuePosition(m_burningCue, positionOfSound, m_directionFromSunNormalized, -m_downVector, m_directionFromSunNormalized * m_speed); //MySounds.UpdateCuePosition(m_burningCue, positionOfSound, m_directionFromSunNormalized, Vector3.Up, Vector3.Zero); //MyLogManager.WriteLine("positionOfSound: " + MyUtils.GetFormatedVector3(positionOfSound, 3)); //MyLogManager.WriteLine("m_directionFromSunNormalized: " + MyUtils.GetFormatedVector3(m_directionFromSunNormalized, 3)); //MyLogManager.WriteLine("m_downVector: " + MyUtils.GetFormatedVector3(m_downVector, 3)); Position = positionOfSound; // Shake player's head float distanceToSound; Vector3.Distance(ref positionOfSound, ref campos, out distanceToSound); float shake = 1 - MathHelper.Clamp(distanceToSound / 1000, 0, 1); if (MySession.PlayerShip != null) { MySession.PlayerShip.IncreaseHeadShake( MathHelper.Lerp(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_DURING_SUN_WIND_MIN, MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_DURING_SUN_WIND_MAX, shake)); } for (int i = 0; i < m_sunwindEntities.Count;) { if (m_sunwindEntities[i].Closed) { m_sunwindEntities.RemoveAtFast(i); } else { i++; } } // Apply force to all objects that aren't static and are hit by sun wind (ignoring voxels and large ships) MyEntities.ApplySunWindForce(m_sunwindEntities, ref m_planeFront, ref m_planeBack, DoNotIgnoreTheseTypes, ref m_directionFromSunNormalized); // Start small billboards if (m_distanceToSunWind <= MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_DISTANCE) { Debug.Assert(m_computedMaxDistances == MySunWindConstants.SMALL_BILLBOARDS_SIZE.X * MySunWindConstants.SMALL_BILLBOARDS_SIZE.Y, "Not all small billboard MaxDistances are computed!"); m_smallBillboardsStarted = true; } ComputeMaxDistances(); }
public override void UpdateBeforeSimulation() { try { MyRender.GetRenderProfiler().StartProfilingBlock("MyCannonShot.UpdateBeforeSimulation"); if (this.WorldMatrix.Translation != m_previousPosition) { MyLine line = new MyLine(this.WorldMatrix.Translation, m_previousPosition); MyDangerZones.Instance.Notify(line, OwnerEntity); } // Kill this missile if (m_isExploded && !m_wasPenetration) { // Create explosion MyExplosion newExplosion = MyExplosions.AddExplosion(); if (newExplosion != null) { float radius = MyMwcUtils.GetRandomFloat(m_ammoProperties.ExplosionRadius - 2, m_ammoProperties.ExplosionRadius + 2); BoundingSphere explosionSphere = new BoundingSphere((m_collisionPoint.HasValue ? m_collisionPoint.Value : GetPosition()), radius); MyExplosionInfo info = new MyExplosionInfo(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, explosionSphere, m_explosionType, true) { GroupMask = Physics.GroupMask, CascadeLevel = CascadedExplosionLevel, HitEntity = m_collidedEntity, OwnerEntity = this.OwnerEntity, Direction = WorldMatrix.Forward, ParticleScale = 1.5f, VoxelExplosionCenter = explosionSphere.Center + radius * WorldMatrix.Forward * 0.6f, }; info.CreateParticleEffect = !m_hasExplosion; newExplosion.Start(ref info); } if (m_collidedEntity != null && !m_collidedEntity.IsExploded()) { m_collidedEntity.Physics.AddForce( MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, WorldMatrix.Forward * MyMissileConstants.HIT_STRENGTH_IMPULSE, GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 2, MyMissileConstants.HIT_STRENGTH_IMPULSE * MyMwcUtils.GetRandomVector3Normalized()); } MarkForClose(); return; } base.UpdateBeforeSimulation(); // Chech timeout and max distance if ((m_elapsedMiliseconds > MyCannonConstants.SHOT_TIMEOUT) || (Vector3.Distance(this.WorldMatrix.Translation, m_origin) >= m_ammoProperties.MaxTrajectory)) { MarkForClose(); return; } Matrix orientation = GetWorldRotation(); // Update thruster cue/sound MyAudio.UpdateCuePosition(m_thrusterCue, this.WorldMatrix.Translation, orientation.Forward, orientation.Up, this.Physics.LinearVelocity); Vector3 pos = this.WorldMatrix.Translation; if (m_penetratedVoxelMap == null) { if (m_smokeEffect != null) { m_smokeEffect.WorldMatrix = WorldMatrix; } } /* * if (m_wasPenetration) * { * // Create explosion * MyExplosion newExplosion = MyExplosions.AddExplosion(); * if (newExplosion != null) * { * float radius = MyMwcUtils.GetRandomFloat(1, 2); * float particleScale = 2.2f; // must be large enough to cover the hole * newExplosion.StartWithPositionOffset(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, m_explosionType, m_penetrationOrigin - WorldMatrix.Forward * 2, radius, MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadedExplosionLevel, particleScale: particleScale, hitEntity: m_collidedEntity, ownerEntity: m_ownerEntity); * } * m_wasPenetration = false; * m_hasExplosion = true; * } */ if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive) { // Look for small ships in shots's proximity BoundingSphere boundingSphere = new BoundingSphere(GetPosition(), MyCannonShotConstants.PROXIMITY_DETECTION_RADIUS); BoundingBox boundingBox = new BoundingBox(); BoundingBox.CreateFromSphere(ref boundingSphere, out boundingBox); var elements = MyEntities.GetElementsInBox(ref boundingBox); for (int i = 0; i < elements.Count; i++) { var rigidBody = (MyPhysicsBody)elements[i].GetRigidBody().m_UserData; var entity = rigidBody.Entity; if (!(entity is MinerWars.AppCode.Game.Entities.MySmallShip)) { continue; } if (entity == OwnerEntity) { continue; } if (entity == this) { continue; } Explode(entity); break; } elements.Clear(); } /* * if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster) * { * m_cuttingSphere.Center = GetPosition(); * * // We found voxel so lets make tunel into it * MyPhysObjectBase collisionResult = MyEntities.GetIntersectionWithSphere(ref m_cuttingSphere, this, (MySmallShip)Parent); * if (collisionResult is MyVoxelMap) * { * MyVoxelMap voxelMap = collisionResult as MyVoxelMap; * if (m_penetratedVoxelMap == null) * { * m_penetratedVoxelMap = voxelMap; * m_penetrationOrigin = GetPosition(); * } * * Game.Voxels.MyVoxelGenerator.CutOutSphereFast(voxelMap, m_cuttingSphere); * } * } */ /* * if (m_usedAmmo.AmmoType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster) * { * if (m_penetratedVoxelMap != null) * { * //MyCannonShotConstants.BUSTER_PENETRATION_LENGTH * float busterPenetrationLength = m_ammoProperties.ExplosionRadius * 0.75f; * if (Vector3.Distance(m_penetrationOrigin, GetPosition()) >= busterPenetrationLength) * { * m_collisionPoint = GetPosition(); //We want to explode inside voxel, not on collision point * Explode(m_penetratedVoxelMap); * } * } * } */ } finally { MyRender.GetRenderProfiler().EndProfilingBlock(); } }