Skip to content

Commit

Permalink
Merge pull request #732 from SuicidalInsanity/patch-11
Browse files Browse the repository at this point in the history
Torpedo fix for #710
  • Loading branch information
jrodrigv authored Oct 22, 2019
2 parents 896474c + 47d0644 commit 6b16550
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions BDArmory/Modules/MissileLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,15 @@ void UpdateVolume()
void Update()
{
CheckDetonationState();
if (HighLogic.LoadedSceneIsFlight)
{
if (weaponClass == WeaponClasses.SLW && FlightGlobals.getAltitudeAtPos(part.transform.position) > 0) //#710
{
float a = (float)FlightGlobals.getGeeForceAtPosition(part.transform.position).magnitude;
float d = FlightGlobals.getAltitudeAtPos(part.transform.position);
dropTime = ((float)Math.Sqrt(a * (a + (8 * d))) - a) / (2 * a) - (Time.fixedDeltaTime * 1.5f); //quadratic equation for accel to find time from known force and vel
}// adjusts droptime to delay the MissileRoutine IEnum so torps won't start boosting until splashdown
}
}

void OnDestroy()
Expand Down Expand Up @@ -1170,7 +1179,7 @@ private void UpdateTerminalGuidance()
void UpdateThrustForces()
{
if (MissileState == MissileStates.PostThrust) return;

if (weaponClass == WeaponClasses.SLW && FlightGlobals.getAltitudeAtPos(part.transform.position) > 0) return; //#710, no torp thrust out of water
if (currentThrust * Throttle > 0)
{
debugString.Append("Missile thrust=" + currentThrust * Throttle);
Expand Down Expand Up @@ -1243,7 +1252,7 @@ IEnumerator BoostRoutine()
while (gpe.MoveNext())
{
if (gpe.Current == null) continue;
if (!vessel.InVacuum() && Throttle > 0)
if ((!vessel.InVacuum() && Throttle > 0) && weaponClass != WeaponClasses.SLW || (weaponClass == WeaponClasses.SLW && FlightGlobals.getAltitudeAtPos(part.transform.position) < 0 )) //#710
{
gpe.Current.emit = true;
gpe.Current.pEmitter.worldVelocity = 2 * ParticleTurbulence.flareTurbulence;
Expand Down Expand Up @@ -1383,17 +1392,31 @@ IEnumerator CruiseRoutine()
}

emitter.Current.maxSize = Mathf.Clamp01(Throttle / Mathf.Clamp((float)vessel.atmDensity, 0.2f, 1f));
emitter.Current.emit = true;
if (weaponClass != WeaponClasses.SLW || (weaponClass == WeaponClasses.SLW && FlightGlobals.getAltitudeAtPos(part.transform.position) < 0)) //#710
{
emitter.Current.emit = true;
}
else
{
emitter.Current.emit = false; // #710, shut down thrust FX for torps out of water
}
}
emitter.Dispose();

List<BDAGaplessParticleEmitter>.Enumerator gpe = gaplessEmitters.GetEnumerator();
while (gpe.MoveNext())
{
if (gpe.Current == null) continue;
gpe.Current.pEmitter.maxSize = Mathf.Clamp01(Throttle / Mathf.Clamp((float)vessel.atmDensity, 0.2f, 1f));
gpe.Current.emit = true;
gpe.Current.pEmitter.worldVelocity = 2 * ParticleTurbulence.flareTurbulence;
if (weaponClass != WeaponClasses.SLW || (weaponClass == WeaponClasses.SLW && FlightGlobals.getAltitudeAtPos(part.transform.position) < 0)) //#710
{
gpe.Current.pEmitter.maxSize = Mathf.Clamp01(Throttle / Mathf.Clamp((float)vessel.atmDensity, 0.2f, 1f));
gpe.Current.emit = true;
gpe.Current.pEmitter.worldVelocity = 2 * ParticleTurbulence.flareTurbulence;
}
else
{
gpe.Current.emit = false;
}
}
gpe.Dispose();

Expand Down

0 comments on commit 6b16550

Please sign in to comment.