Skip to content

Commit

Permalink
Merge pull request #14 from StarCoreSE/revert-13-thetrackening
Browse files Browse the repository at this point in the history
Revert "turrets avoid shooting at things they can't hit"
  • Loading branch information
InvalidArgument3 authored Jul 6, 2024
2 parents f87da0a + 2dcf293 commit 1be2f67
Show file tree
Hide file tree
Showing 9 changed files with 847 additions and 56 deletions.
833 changes: 833 additions & 0 deletions CoreSystems.csproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public partial class Weapon : Part
internal string FriendlyNameNoAmmo = string.Empty;
internal string FriendlyNameNoTarget = string.Empty;
internal string FriendlyNameNoSubsystem = string.Empty;
internal string FriendlyNameImpossibleHit = string.Empty;

internal string AmmoName = "";
internal ProtoWeaponPartState PartState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ internal enum FriendlyNames
NoAmmo,
NoSubSystems,
NoTarget,
ImpossibleToHit,
}

internal string UpdateAndGetFriendlyName(FriendlyNames type)
Expand All @@ -493,7 +492,6 @@ internal string UpdateAndGetFriendlyName(FriendlyNames type)
FriendlyNameNoTarget = weaponName + Hud.NoTargetStr;
FriendlyNameNoAmmo = weaponName + Hud.NoAmmoStr;
FriendlyNameNoSubsystem = weaponName + Hud.NoSubSystemStr;
FriendlyNameImpossibleHit = weaponName + Hud.ImpossibleHitStr;
}

switch (type)
Expand All @@ -504,8 +502,6 @@ internal string UpdateAndGetFriendlyName(FriendlyNames type)
return FriendlyNameNoTarget;
case FriendlyNames.NoSubSystems:
return FriendlyNameNoSubsystem;
case FriendlyNames.ImpossibleToHit:
return FriendlyNameImpossibleHit;
default:
return FriendlyName;
}
Expand Down
17 changes: 2 additions & 15 deletions Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public static bool QuarticSolver(ref double timeToIntercept, Vector3D relativePo
return false;
}

public static Vector3D TrajectoryEstimation(Weapon weapon, Vector3D targetPos, Vector3D targetVel, Vector3D targetAcc, Vector3D shooterPos, out bool valid, bool basicPrediction = false, bool trackAngular = false)
internal static Vector3D TrajectoryEstimation(Weapon weapon, Vector3D targetPos, Vector3D targetVel, Vector3D targetAcc, Vector3D shooterPos, out bool valid, bool basicPrediction = false, bool trackAngular = false)
{
valid = false;
Vector3D aimPoint;
Expand All @@ -927,7 +927,7 @@ public static Vector3D TrajectoryEstimation(Weapon weapon, Vector3D targetPos, V
var shooterVel = ai != null ? (Vector3D)ai.TopEntityVel : Vector3D.Zero;
var projectileMaxSpeed = ammoDef.Const.DesiredProjectileSpeed * weapon.VelocityMult;
var updateGravity = ammoDef.Const.FeelsGravity && ai != null && ai.InPlanetGravity;
var useSimple = basicPrediction || ammoDef.Const.AmmoSkipAccel || targetAcc.LengthSquared() < 2.5;
var useSimple = basicPrediction || ammoDef.Const.AmmoSkipAccel || targetAcc.LengthSquared() < 2.5; //equal to approx 1.58 m/s

#region Must Have Updates
if (ai != null && comp.TopEntity != null && comp.TopEntity.PositionComp != null && ai.VelocityUpdateTick != session.Tick)
Expand Down Expand Up @@ -1007,19 +1007,6 @@ public static Vector3D TrajectoryEstimation(Weapon weapon, Vector3D targetPos, V
var usedTti = QuarticSolver(ref advTti, deltaPos, deltaVel, targetAcc, ammoDef.Const.DesiredProjectileSpeed * weapon.VelocityMult, ai?.QuadraticCoefficientsStorage) ? advTti : initialTti;
aimPoint = targetPos + (usedTti + (ammoDef.Const.AmmoSkipAccel ? 0 : (projAccelTime / usedTti))) * (targetVel - shooterVel);
}

// Check if the time-to-intercept is greater than half of the maximum travel time
double maxTravelTime = ammoDef.Const.MaxTrajectory / projectileMaxSpeed;
double closingSpeedPercentage = Vector3D.Dot(deltaVel, deltaPosNorm) / projectileMaxSpeed;
double interceptThreshold = maxTravelTime * 0.5 * (1 - closingSpeedPercentage);

if (initialTti > interceptThreshold)
{
valid = false;
weapon.Target.ImpossibleToHit = true; // Mark target as impossible to hit
return targetPos;
}

Vector3D gravityOffset = Vector3D.Zero;
if (updateGravity && !MyUtils.IsZero(weapon.GravityPoint))
{
Expand Down
1 change: 0 additions & 1 deletion Data/Scripts/CoreSystems/Support/MiscTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Target
internal TargetStates TargetState;
internal bool HasTarget;
internal bool IsAligned;
public bool ImpossibleToHit;
internal bool SoftProjetileReset;
internal bool TargetChanged;
internal bool ClientDirty;
Expand Down
27 changes: 11 additions & 16 deletions Data/Scripts/CoreSystems/Ui/Hud/HudDraw.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.Eventing.Reader;
using CoreSystems;
using CoreSystems;
using CoreSystems.Platform;
using CoreSystems.Support;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -233,7 +232,6 @@ private void BackgroundAdd(Vector2D currWeaponDisplayPos, double bgStartPosX)
public const string NoAmmoStr = ": No Ammo";
public const string NoTargetStr = ": No Target";
public const string NoSubSystemStr = ": No Subsystem";
public const string ImpossibleHitStr = ": No Angle";

private void WeaponsToAdd(bool reset, Vector2D currWeaponDisplayPos, double bgStartPosX)
{
Expand All @@ -250,36 +248,33 @@ private void WeaponsToAdd(bool reset, Vector2D currWeaponDisplayPos, double bgSt

var delayNoTarget = !weapon.System.WConst.GiveUpAfter || s.Tick - weapon.LastShootTick > weapon.System.WConst.DelayAfterBurst;
var notAnyBlock = comp.MasterOverrides.SubSystem != WeaponDefinition.TargetingDef.BlockTypes.Any;
var needsTarget = (!weapon.Target.HasTarget || Session.I.Tick - weapon.Target.ChangeTick <= 30) && comp.MasterOverrides.Grids && (comp.DetectOtherSignals && comp.MasterAi.DetectionInfo.OtherInRange || comp.MasterAi.DetectionInfo.PriorityInRange) && report && comp.Data.Repo.Values.Set.ReportTarget && delayNoTarget && comp.MasterAi.DetectionInfo.TargetInRange(weapon);
var needsTarget = (!weapon.Target.HasTarget || Session.I.Tick - weapon.Target.ChangeTick <= 30) && comp.MasterOverrides.Grids && (comp.DetectOtherSignals && comp.MasterAi.DetectionInfo.OtherInRange || comp.MasterAi.DetectionInfo.PriorityInRange) && report && comp.Data.Repo.Values.Set.ReportTarget && delayNoTarget && comp.MasterAi.DetectionInfo.TargetInRange(weapon);
var showReloadIcon = (weapon.Loading || weapon.Reload.WaitForClient || s.Tick - weapon.LastLoadedTick < 60);

string noTargetReason;
string noTagetReason;
var needNameUpdate = weapon.LastFriendlyNameTick == 0 || s.Tick - weapon.LastFriendlyNameTick > 600;
if (needsTarget)
{
if (weapon.OutOfAmmo && !showReloadIcon)
noTargetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoAmmo) : weapon.FriendlyNameNoAmmo;
noTagetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoAmmo) : weapon.FriendlyNameNoAmmo;

else if (comp.MasterOverrides.FocusSubSystem && !showReloadIcon && notAnyBlock && weapon.FoundTopMostTarget)
noTargetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoSubSystems) : weapon.FriendlyNameNoSubsystem;
noTagetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoSubSystems) : weapon.FriendlyNameNoSubsystem;

else if (weapon.Target.ImpossibleToHit)
noTargetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.ImpossibleToHit) : weapon.FriendlyNameImpossibleHit;

else
noTargetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoTarget) : weapon.FriendlyNameNoTarget;
else
noTagetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.NoTarget) : weapon.FriendlyNameNoTarget;
}
else
{
noTargetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.Normal) : weapon.FriendlyName;
noTagetReason = needNameUpdate ? weapon.UpdateAndGetFriendlyName(Weapon.FriendlyNames.Normal) : weapon.FriendlyName;
}

var textOffset = bgStartPosX - _bgWidth + _reloadWidth + _padding;
var hasHeat = weapon.HeatPerc > 0;

var textInfo = _textDrawPool.Count > 0 ? _textDrawPool.Dequeue() : new TextDrawRequest();

textInfo.Text = noTargetReason;
textInfo.Text = noTagetReason;
var color = new Vector4(1, 1, 1, 1);
textInfo.Color = color;
textInfo.Position.X = textOffset;
Expand All @@ -294,7 +289,7 @@ private void WeaponsToAdd(bool reset, Vector2D currWeaponDisplayPos, double bgSt

textInfo.Text = $"(x{stackedInfo.WeaponStack})";
textInfo.Color = new Vector4(0.5f, 0.5f, 1, 1);
textInfo.Position.X = textOffset + (noTargetReason.Length * ((_textSize * s.AspectRatioInv) * 0.6f) * ShadowSizeScaler);
textInfo.Position.X = textOffset + (noTagetReason.Length * ((_textSize * s.AspectRatioInv) * 0.6f) * ShadowSizeScaler);

textInfo.Position.Y = currWeaponDisplayPos.Y;
textInfo.FontSize = _sTextSize;
Expand Down
17 changes: 0 additions & 17 deletions Generic.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion Generic.sln → WeaponCore-StarCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generic", "Generic.csproj", "{771CFBEA-9E09-45B8-9360-35C01B0459B8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeaponCore-StarCore", "WeaponCore-StarCore.csproj", "{771CFBEA-9E09-45B8-9360-35C01B0459B8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 0 additions & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mal.Mdk2.ModAnalyzers" version="2.1.8" targetFramework="net48" developmentDependency="true" />
<package id="System.Xml.XmlSerializer" version="4.3.0" targetFramework="net461" />
</packages>

0 comments on commit 1be2f67

Please sign in to comment.