Skip to content

Commit

Permalink
Merge pull request #762 from TheKurgan/master
Browse files Browse the repository at this point in the history
Reverted some of the changes to commit on Oct 27 2019 in order to fix…
  • Loading branch information
jrodrigv authored Apr 4, 2020
2 parents 521b7d3 + b97d9bb commit ff5624a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 112 deletions.
64 changes: 32 additions & 32 deletions BDArmory/Modules/BDModularGuidance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,40 +617,40 @@ private Vector3 CruiseGuidance()
return this._guidance.GetDirection(this,TargetPosition);
}

//private void CheckMiss(Vector3 targetPosition)
//{
// if (HasMissed) return;
// // if I'm to close to my vessel avoid explosion
// if ((vessel.CoM - SourceVessel.CoM).magnitude < 4 * DetonationDistance) return;
// // if I'm getting closer to my target avoid explosion
// if ((vessel.CoM - targetPosition).sqrMagnitude >
// (vessel.CoM + (vessel.Velocity() * Time.fixedDeltaTime) - (targetPosition + (TargetVelocity * Time.fixedDeltaTime))).sqrMagnitude) return;

// if (MissileState != MissileStates.PostThrust ) return;

// Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
// HasMissed = true;
// guidanceActive = false;
// TargetMf = null;
// isTimed = true;
// detonationTime = TimeIndex + 1.5f;
//}

//private void CheckMiss()
//{
// if (HasMissed) return;
private void CheckMiss(Vector3 targetPosition)
{
if (HasMissed) return;
// if I'm to close to my vessel avoid explosion
if ((vessel.CoM - SourceVessel.CoM).magnitude < 4 * DetonationDistance) return;
// if I'm getting closer to my target avoid explosion
if ((vessel.CoM - targetPosition).sqrMagnitude >
(vessel.CoM + (vessel.Velocity() * Time.fixedDeltaTime) - (targetPosition + (TargetVelocity * Time.fixedDeltaTime))).sqrMagnitude) return;

if (MissileState != MissileStates.PostThrust ) return;

Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
HasMissed = true;
guidanceActive = false;
TargetMf = null;
isTimed = true;
detonationTime = TimeIndex + 1.5f;
}

private void CheckMiss()
{
if (HasMissed) return;


// if (MissileState == MissileStates.PostThrust && (vessel.LandedOrSplashed || vessel.Velocity().magnitude < 10f))
// {
// Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
// HasMissed = true;
// guidanceActive = false;
// TargetMf = null;
// isTimed = true;
// detonationTime = TimeIndex + 1.5f;
// }
//}
if (MissileState == MissileStates.PostThrust && (vessel.LandedOrSplashed || vessel.Velocity().magnitude < 10f))
{
Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
HasMissed = true;
guidanceActive = false;
TargetMf = null;
isTimed = true;
detonationTime = TimeIndex + 1.5f;
}
}


public void GuidanceSteer(FlightCtrlState s)
Expand Down
35 changes: 0 additions & 35 deletions BDArmory/Modules/MissileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,41 +1013,6 @@ public void CheckDetonationState()
}
}

public void CheckMiss(Vector3 targetPosition)
{
if (HasMissed) return;
// if I'm to close to my vessel avoid explosion
if ((vessel.CoM - SourceVessel.CoM).magnitude < 4 * DetonationDistance) return;
// if I'm getting closer to my target avoid explosion
if ((vessel.CoM - targetPosition).sqrMagnitude >
(vessel.CoM + (vessel.Velocity() * Time.fixedDeltaTime) - (targetPosition + (TargetVelocity * Time.fixedDeltaTime))).sqrMagnitude) return;

if (MissileState != MissileStates.PostThrust) return;

Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
HasMissed = true;
guidanceActive = false;
TargetMf = null;
isTimed = true;
detonationTime = TimeIndex + 1.5f;
}

public void CheckMiss()
{
if (HasMissed) return;


if (MissileState == MissileStates.PostThrust && (vessel.LandedOrSplashed || vessel.Velocity().magnitude < 10f))
{
Debug.Log("[BDArmory]: Missile CheckMiss showed miss");
HasMissed = true;
guidanceActive = false;
TargetMf = null;
isTimed = true;
detonationTime = TimeIndex + 1.5f;
}
}

protected void SetInitialDetonationDistance()
{
if (this.DetonationDistance == -1)
Expand Down
93 changes: 48 additions & 45 deletions BDArmory/Modules/MissileLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,48 +872,48 @@ public override void OnFixedUpdate()
}
}

//private void CheckMiss()
//{
// float sqrDist = (float) ((TargetPosition + (TargetVelocity * Time.fixedDeltaTime)) - (vessel.CoM + (vessel.Velocity() * Time.fixedDeltaTime))).sqrMagnitude;
// if (sqrDist < 160000 || MissileState == MissileStates.PostThrust)
// {
// checkMiss = true;
// }
// if (maxAltitude != 0f)
// {
// if (vessel.altitude >= maxAltitude) checkMiss = true;
// }

// //kill guidance if missileBase has missed
// if (!HasMissed && checkMiss)
// {
// bool noProgress = MissileState == MissileStates.PostThrust && (Vector3.Dot(vessel.Velocity() - TargetVelocity, TargetPosition - vessel.transform.position) < 0);
// if (Vector3.Dot(TargetPosition - transform.position, transform.forward) < 0 || noProgress)
// {
// Debug.Log("[BDArmory]: Missile has missed!");

// if (vessel.altitude >= maxAltitude && maxAltitude != 0f)
// Debug.Log("[BDArmory]: CheckMiss trigged by MaxAltitude");

// HasMissed = true;
// guidanceActive = false;

// TargetMf = null;

// MissileLauncher launcher = this as MissileLauncher;
// if (launcher != null)
// {
// if (launcher.hasRCS) launcher.KillRCS();
// }

// if (sqrDist < Mathf.Pow(GetBlastRadius() * 0.5f, 2)) part.Destroy();

// isTimed = true;
// detonationTime = TimeIndex + 1.5f;
// return;
// }
// }
//}
private void CheckMiss()
{
float sqrDist = (float) ((TargetPosition + (TargetVelocity * Time.fixedDeltaTime)) - (vessel.CoM + (vessel.Velocity() * Time.fixedDeltaTime))).sqrMagnitude;
if (sqrDist < 160000 || MissileState == MissileStates.PostThrust)
{
checkMiss = true;
}
if (maxAltitude != 0f)
{
if (vessel.altitude >= maxAltitude) checkMiss = true;
}

//kill guidance if missileBase has missed
if (!HasMissed && checkMiss)
{
bool noProgress = MissileState == MissileStates.PostThrust && (Vector3.Dot(vessel.Velocity() - TargetVelocity, TargetPosition - vessel.transform.position) < 0);
if (Vector3.Dot(TargetPosition - transform.position, transform.forward) < 0 || noProgress)
{
Debug.Log("[BDArmory]: Missile has missed!");

if (vessel.altitude >= maxAltitude && maxAltitude != 0f)
Debug.Log("[BDArmory]: CheckMiss trigged by MaxAltitude");

HasMissed = true;
guidanceActive = false;

TargetMf = null;

MissileLauncher launcher = this as MissileLauncher;
if (launcher != null)
{
if (launcher.hasRCS) launcher.KillRCS();
}

if (sqrDist < Mathf.Pow(GetBlastRadius() * 0.5f, 2)) part.Destroy();

isTimed = true;
detonationTime = TimeIndex + 1.5f;
return;
}
}
}


void UpdateGuidance()
Expand Down Expand Up @@ -1046,10 +1046,10 @@ void UpdateGuidance()
SLWGuidance();
}

CheckMiss(TargetPosition);
}
else
{
CheckMiss();
TargetMf = null;
if (aero)
{
Expand All @@ -1067,8 +1067,6 @@ void UpdateGuidance()
KillRCS();
}
}

CheckMiss();
}

// feature_engagementenvelope: terminal guidance mode for cruise missiles
Expand Down Expand Up @@ -1602,6 +1600,7 @@ void CruiseGuidance()
vesselReferenceTransform.rotation = Quaternion.LookRotation(-rotationTransform.up, rotationTransform.forward);
}
DoAero(cruiseTarget);
CheckMiss();
}

void AAMGuidance()
Expand Down Expand Up @@ -1632,6 +1631,7 @@ void AAMGuidance()
if (TimeIndex > dropTime + 0.25f)
{
DoAero(aamTarget);
CheckMiss();
}

}
Expand All @@ -1650,6 +1650,7 @@ void AGMGuidance()
Debug.Log("[BDArmory]: AGM Missile guidance failed - target out of view");
guidanceActive = false;
}
CheckMiss();
}
else
{
Expand Down Expand Up @@ -1697,6 +1698,8 @@ void SLWGuidance()

if (SLWTarget.y > 0f) SLWTarget.y = getSWLWOffset;

CheckMiss();

}

void DoAero(Vector3 targetPosition)
Expand Down

0 comments on commit ff5624a

Please sign in to comment.