Skip to content

Commit

Permalink
Merge pull request #18 from InvalidArgument3/fix-shitty-continuous-be…
Browse files Browse the repository at this point in the history
…am-power-calc

update to latest WC
  • Loading branch information
InvalidArgument3 authored Jul 20, 2024
2 parents 922a52e + d55883c commit f413f2c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Data/Scripts/CoreSystems/Ai/AiFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public partial class Ai
internal readonly List<SupportSys.SupportComponent> SupportComps = new List<SupportSys.SupportComponent>(32);
internal readonly List<ControlSys.ControlComponent> ControlComps = new List<ControlSys.ControlComponent>(32);
internal readonly List<WeaponComponent> PhantomComps = new List<WeaponComponent>(32);
internal readonly List<Projectile> DeadProjectiles = new List<Projectile>();
internal readonly HashSet<Projectile> DeadProjectiles = new HashSet<Projectile>();
internal readonly List<Ai> TargetAisTmp = new List<Ai>();
internal readonly List<Shields> NearByShieldsTmp = new List<Shields>();
internal readonly List<MyEntity> NearByFriendlyShields = new List<MyEntity>();
Expand Down
18 changes: 10 additions & 8 deletions Data/Scripts/CoreSystems/Projectiles/Projectile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using CoreSystems.Platform;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 1 addition & 4 deletions Data/Scripts/CoreSystems/Projectiles/ProjectileGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions Data/Scripts/CoreSystems/Session/SessionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f413f2c

Please sign in to comment.