Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #289

Merged
merged 3 commits into from
Dec 31, 2023
Merged

Dev #289

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions BDArmory/Control/MissileFire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,14 +2055,14 @@ IEnumerator GuardMissileRoutine(Vessel targetVessel, MissileBase ml)
}
else
{
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {CurrentMissile.name} could not lock, attempting unguided fire.");
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {(CurrentMissile ? CurrentMissile.name : "null missile")} could not lock, attempting unguided fire.");
unguidedWeapon = true; //so let them be used as unguided ordinance
}
}
}
else //no radar, missiles now expensive unguided ordinance
{
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {CurrentMissile.name} has no radar, attempting unguided fire.");
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {(CurrentMissile ? CurrentMissile.name : "null missile")} has no radar, attempting unguided fire.");
unguidedWeapon = true; //so let them be used as unguided ordinance
}
break;
Expand Down Expand Up @@ -2475,7 +2475,7 @@ IEnumerator GuardMissileRoutine(Vessel targetVessel, MissileBase ml)
MissileLauncher mlauncher = ml as MissileLauncher;
if (mlauncher && mlauncher.multiLauncher && mlauncher.multiLauncher.overrideReferenceTransform)
{
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {CurrentMissile.name} launched from MML, aborting unguided launch.");
if (BDArmorySettings.DEBUG_MISSILES) Debug.Log($"[BDArmory.MissileFire]: {vessel.vesselName}'s {(CurrentMissile ? CurrentMissile.name : "null missile")} launched from MML, aborting unguided launch.");
}
else
{
Expand Down Expand Up @@ -6435,7 +6435,7 @@ public void SetTarget(TargetInfo target)
}
else
{
if (PreviousMissile != null && PreviousMissile.ActiveRadar && PreviousMissile.targetVessel != null && PreviousMissile.targetVessel.Vessel != null) //previous missile has gone active, don't need that lock anymore
if (PreviousMissile != null && PreviousMissile.ActiveRadar && PreviousMissile.targetVessel != null) //previous missile has gone active, don't need that lock anymore
{
vesselRadarData.UnlockSelectedTarget(PreviousMissile.targetVessel.Vessel);
}
Expand Down Expand Up @@ -6858,7 +6858,7 @@ public void SendTargetDataToMissile(MissileBase ml, bool clearHeat = true)
if (ml.targetVessel != null) Debug.Log($"[BDArmory.MissileData]: targetInfo sent for {ml.targetVessel.Vessel.GetName()}");
}
if (BDArmorySettings.DEBUG_MISSILES)
Debug.Log($"[BDArmory.MissileData]: firing missile at {(currentTarget != null ? currentTarget.Vessel.GetName() : "null target")}");
Debug.Log($"[BDArmory.MissileData]: firing missile at {(currentTarget != null && currentTarget.Vessel != null ? currentTarget.Vessel.GetName() : "null target")}");
}

#endregion Targeting
Expand Down
6 changes: 4 additions & 2 deletions BDArmory/Radar/VesselRadarData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public TargetSignatureData activeIRTarget(Vessel desiredTarget, MissileFire mf)
else
{
if (displayedTargets[i].targetData.Team == mf.Team) continue;
if (displayedTargets[i].targetData.signalStrength > targetMagnitude )
if (displayedTargets[i].targetData.signalStrength > targetMagnitude)
{
targetMagnitude = displayedTargets[i].targetData.signalStrength;
brightestTarget = i;
Expand Down Expand Up @@ -1023,6 +1023,7 @@ private void WindowRadar(int windowID)

for (int i = 0; i < rCount; i++)
{
if (availableRadars[i] == null || availableRadars[i].gameObject == null) continue;
bool canScan = availableRadars[i].canScan;
bool canTrackWhileScan = availableRadars[i].canTrackWhileScan;
bool islocked = availableRadars[i].locked;
Expand Down Expand Up @@ -1076,6 +1077,7 @@ private void WindowRadar(int windowID)
}
for (int i = 0; i < iCount; i++)
{
if (availableIRSTs[i] == null || availableIRSTs[i].gameObject == null) continue;
bool canScan = availableIRSTs[i].canScan;
float currentAngle = availableIRSTs[i].currentAngle;

Expand Down Expand Up @@ -2064,7 +2066,7 @@ private void DrawDisplayedContacts()
if (weaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.Missile || weaponManager.selectedWeapon.GetWeaponClass() == WeaponClasses.SLW)
{
MissileBase currMissile = weaponManager.CurrentMissile;
if (currMissile.TargetingMode == MissileBase.TargetingModes.Radar || currMissile.TargetingMode == MissileBase.TargetingModes.Heat)
if (currMissile && (currMissile.TargetingMode == MissileBase.TargetingModes.Radar || currMissile.TargetingMode == MissileBase.TargetingModes.Heat))
{
MissileLaunchParams dlz = MissileLaunchParams.GetDynamicLaunchParams(currMissile, lockedTarget.velocity, lockedTarget.predictedPosition);
float rangeToPixels = (1 / rIncrements[rangeIndex]) * RadarDisplayRect.height;
Expand Down
2 changes: 1 addition & 1 deletion BDArmory/UI/LoadedVesselSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ private void UpdateCamera()
var targetDirection = missile.TargetPosition - missile.transform.position;
var targetDistance = targetDirection.magnitude;
if (Vector3.Dot(targetDirection, missile.GetForwardTransform()) < 0.5f * targetDistance) continue; // Ignore off-target missiles.
if (missile.targetVessel != null && missile.targetVessel.Vessel != null && missile.targetVessel.Vessel.IsMissile()) continue; // Ignore missiles targeting missiles.
if (missile.targetVessel != null && missile.targetVessel.Vessel.IsMissile()) continue; // Ignore missiles targeting missiles.
if (Vector3.Dot(missile.TargetVelocity - missile.vessel.Velocity(), missile.GetForwardTransform()) > -1f) continue; // Ignore missiles that aren't gaining on their targets.
float missileScore = targetDistance < 1e3f ? 0.1f : 0.1f + (targetDistance - 1e3f) * (targetDistance - 1e3f) * 5e-8f; // Prioritise missiles that are within 1km from their targets and de-prioritise those more than 5km away.
if (missileScore < bestScore)
Expand Down
11 changes: 7 additions & 4 deletions BDArmory/Weapons/Missiles/MissileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ public float Throttle

public TargetInfo targetVessel
{
get { return _targetVessel; }
get
{
if (_targetVessel != null && _targetVessel.Vessel == null) _targetVessel = null; // The vessel could die before _targetVessel gets cleared otherwise.
return _targetVessel;
}
set
{
_targetVessel = value;
Expand Down Expand Up @@ -818,10 +822,9 @@ protected void UpdateRadarTarget()
{
TargetAcquired = false;

float angleToTarget = Vector3.Angle(radarTarget.predictedPosition - transform.position, GetForwardTransform());

if (radarTarget.exists)
{
float angleToTarget = Vector3.Angle(radarTarget.predictedPosition - transform.position, GetForwardTransform());
// locked-on before launch, passive radar guidance or waiting till in active radar range:
if (!ActiveRadar && ((radarTarget.predictedPosition - transform.position).sqrMagnitude > (activeRadarRange * activeRadarRange) || angleToTarget > maxOffBoresight * 0.75f))
{
Expand Down Expand Up @@ -1249,7 +1252,7 @@ public Vector3d UpdateInertialTarget()
}
else //clamp updates to radar/IRST track speed
{
float updateCount = TimeIndex / GpsUpdateMax;
float updateCount = TimeIndex / GpsUpdateMax;
if (updateCount > gpsUpdateCounter)
{
gpsUpdateCounter++;
Expand Down
9 changes: 5 additions & 4 deletions BDArmory/Weapons/Missiles/MissileLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,11 +1345,12 @@ public void MissileLaunch()
}
catch (Exception e)
{
Debug.LogError("[BDArmory.MissileLauncher]: DEBUG " + e.Message);
Debug.LogError("[BDArmory.MissileLauncher]: DEBUG " + e.Message + "\n" + e.StackTrace);
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null part?: " + (part == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG part: " + e2.Message); }
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null part.rb?: " + (part.rb == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG part.rb: " + e2.Message); }
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null BDATargetManager.FiredMissiles?: " + (BDATargetManager.FiredMissiles == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG BDATargetManager.FiredMissiles: " + e2.Message); }
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null vessel?: " + (vessel == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG vessel: " + e2.Message); }
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null targetVessel?: " + (targetVessel == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG targetVessel: " + e2.Message); }
try { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG null sfAudioSource?: " + (sfAudioSource == null)); } catch (Exception e2) { Debug.LogWarning("[BDArmory.MissileLauncher]: DEBUG sfAudioSource: " + e2.Message); }
throw; // Re-throw the exception so behaviour is unchanged so we see it.
}
Expand Down Expand Up @@ -2128,7 +2129,7 @@ void StartBoost()
if (string.IsNullOrEmpty(boostTransformName))
{
boostEmitters = pEmitters;
if (hasRCS && rcsTransforms!=null) boostEmitters.RemoveAll(pe => rcsTransforms.Contains(pe));
if (hasRCS && rcsTransforms != null) boostEmitters.RemoveAll(pe => rcsTransforms.Contains(pe));
if (hasRCS && forwardRCS && !boostEmitters.Contains(forwardRCS)) boostEmitters.Add(forwardRCS);
boostGaplessEmitters = gaplessEmitters;
}
Expand Down Expand Up @@ -2790,8 +2791,8 @@ void WarnTarget()

void SetupRCS()
{
rcsFiredTimes = [ 0, 0, 0, 0 ];
rcsTransforms = [ upRCS, leftRCS, rightRCS, downRCS ];
rcsFiredTimes = [0, 0, 0, 0];
rcsTransforms = [upRCS, leftRCS, rightRCS, downRCS];
}

void DoRCS()
Expand Down
15 changes: 9 additions & 6 deletions BDArmory/Weapons/Missiles/MultiMissileLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,17 @@ IEnumerator salvoFire(bool LaunchThenDestroy)
if (deployState != null)
{
yield return new WaitForSecondsFixed(0.5f); //wait for missile to clear bay
deployState.enabled = true;
deployState.speed = -deploySpeed / deployState.length;
yield return new WaitWhileFixed(() => deployState != null && deployState.normalizedTime > 0);
if (deployState != null)
{
deployState.normalizedTime = 0;
deployState.speed = 0;
deployState.enabled = false;
deployState.enabled = true;
deployState.speed = -deploySpeed / deployState.length;
yield return new WaitWhileFixed(() => deployState != null && deployState.normalizedTime > 0);
if (deployState != null)
{
deployState.normalizedTime = 0;
deployState.speed = 0;
deployState.enabled = false;
}
}
}
if (missileLauncher == null) yield break;
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

- Add tooltips to settings.
- Add thumbnails to the craft browser.
- Figure out how to add a 0 value to UI_FloatSemiLogRange sliders.
- Stability of the targeting cam when slewing with the mouse (jitter).

- Wiki entries
- Auto-Tuning

- Stability of the targeting cam when slewing with the mouse.
- Requests from discord:
- ? Add an action group trigger to the WM based on the current target being an enemy vessel within a custom distance. - Make it a collapsable section of custom triggers to include other conditions later.
- Artillery aiming support
Expand Down