diff --git a/Data/Scripts/CoreSystems/Ai/AiFields.cs b/Data/Scripts/CoreSystems/Ai/AiFields.cs index 17d203da..230bf5a9 100644 --- a/Data/Scripts/CoreSystems/Ai/AiFields.cs +++ b/Data/Scripts/CoreSystems/Ai/AiFields.cs @@ -69,7 +69,7 @@ public partial class Ai internal readonly List SupportComps = new List(32); internal readonly List ControlComps = new List(32); internal readonly List PhantomComps = new List(32); - internal readonly List DeadProjectiles = new List(); + internal readonly HashSet DeadProjectiles = new HashSet(); internal readonly List TargetAisTmp = new List(); internal readonly List NearByShieldsTmp = new List(); internal readonly List NearByFriendlyShields = new List(); diff --git a/Data/Scripts/CoreSystems/Projectiles/Projectile.cs b/Data/Scripts/CoreSystems/Projectiles/Projectile.cs index d31957e0..1c2c9d09 100644 --- a/Data/Scripts/CoreSystems/Projectiles/Projectile.cs +++ b/Data/Scripts/CoreSystems/Projectiles/Projectile.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using CoreSystems.Platform; @@ -237,7 +237,7 @@ internal void Start() { Vector3D targetDir; Vector3D targetPos; - if (TrajectoryEstimation(Info.AmmoDef, w, ref Position, out targetDir, out targetPos)) + if (TrajectoryEstimation(Info.AmmoDef, ref Position, out targetDir, out targetPos, false)) TargetPosition = targetPos; TargetPosition -= (Direction * variance); @@ -3078,7 +3078,7 @@ internal void ForceNewTarget() Info.Storage.PickTarget = false; } - internal bool TrajectoryEstimation(WeaponDefinition.AmmoDef ammoDef, Weapon weapon, ref Vector3D shooterPos, out Vector3D targetDirection, out Vector3D estimatedPosition) + internal bool TrajectoryEstimation(WeaponDefinition.AmmoDef ammoDef, ref Vector3D shooterPos, out Vector3D targetDirection, out Vector3D estimatedPosition, bool isTimedSpawn) { var aConst = Info.AmmoDef.Const; var eTarget = Info.Target.TargetObject as MyEntity; @@ -3108,7 +3108,11 @@ internal bool TrajectoryEstimation(WeaponDefinition.AmmoDef ammoDef, Weapon weap } var targetVel = eTarget != null ? eTarget.GetTopMostParent().Physics.LinearVelocity : (Vector3)pTarget.Velocity; - var shooterVel = !Info.AmmoDef.Const.FragDropVelocity ? Velocity : Vector3D.Zero; + Vector3D shooterVel = Vector3D.Zero; + if (isTimedSpawn) + shooterVel = !Info.AmmoDef.Const.FragDropVelocity ? Velocity : Vector3D.Zero; + else + shooterVel = Info.ShooterVel; var projectileMaxSpeed = ammoDef.Const.DesiredProjectileSpeed * (weapon == null ? 1 : weapon.VelocityMult); Vector3D deltaPos = targetPos - shooterPos; @@ -3143,9 +3147,8 @@ internal bool TrajectoryEstimation(WeaponDefinition.AmmoDef ammoDef, Weapon weap if (timeToIntercept < 0) { - if (aConst.FragPointType == PointTypes.Lead) + if (aConst.TimedFragments && aConst.FragPointType == PointTypes.Lead) { - estimatedPosition = targetPos + timeToIntercept * (targetVel - shooterVel); targetDirection = Vector3D.Normalize(estimatedPosition - shooterPos); return true; @@ -3155,7 +3158,6 @@ internal bool TrajectoryEstimation(WeaponDefinition.AmmoDef ammoDef, Weapon weap targetDirection = Direction; return false; } - estimatedPosition = targetPos + timeToIntercept * (targetVel - shooterVel); targetDirection = Vector3D.Normalize(estimatedPosition - shooterPos); return true; @@ -3589,7 +3591,7 @@ internal void SpawnShrapnel(bool timedSpawn = true) // inception begins } Vector3D estimatedTargetPos; - if (!TrajectoryEstimation(fragAmmoDef, null, ref newOrigin, out pointDir, out estimatedTargetPos)) + if (!TrajectoryEstimation(fragAmmoDef, ref newOrigin, out pointDir, out estimatedTargetPos, true)) continue; } diff --git a/Data/Scripts/CoreSystems/Projectiles/ProjectileGen.cs b/Data/Scripts/CoreSystems/Projectiles/ProjectileGen.cs index 892b907f..f0ea8fa2 100644 --- a/Data/Scripts/CoreSystems/Projectiles/ProjectileGen.cs +++ b/Data/Scripts/CoreSystems/Projectiles/ProjectileGen.cs @@ -225,10 +225,7 @@ private void SpawnFragments() if (dumbAdd || validAi) { targetAi.DeadProjectiles.Remove(p); - if (targetAi.LiveProjectile.ContainsKey(p)) - targetAi.LiveProjectile[p] = condition1 || condition2; - else - targetAi.LiveProjectile.Add(p, (condition1 || condition2)); + targetAi.LiveProjectile[p] = condition1 || condition2; targetAi.LiveProjectileTick = Session.I.Tick; targetAi.NewProjectileTick = Session.I.Tick; p.Watchers.Add(targetAi); diff --git a/Data/Scripts/CoreSystems/Session/SessionUpdate.cs b/Data/Scripts/CoreSystems/Session/SessionUpdate.cs index 831d0092..381a9171 100644 --- a/Data/Scripts/CoreSystems/Session/SessionUpdate.cs +++ b/Data/Scripts/CoreSystems/Session/SessionUpdate.cs @@ -46,8 +46,10 @@ private void AiLoop() if (!ai.ScanInProgress && Tick - ai.TargetsUpdatedTick > 100 && DbTask.IsComplete) ai.RequestDbUpdate(); - if (ai.DeadProjectiles.Count > 0) { - for (int i = 0; i < ai.DeadProjectiles.Count; i++) ai.LiveProjectile.Remove(ai.DeadProjectiles[i]); + if (ai.DeadProjectiles.Count > 0) + { + foreach (var dead in ai.DeadProjectiles) + ai.LiveProjectile.Remove(dead); ai.DeadProjectiles.Clear(); ai.LiveProjectileTick = Tick; }