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