diff --git a/MechJeb2/MechJebModuleNodeExecutor.cs b/MechJeb2/MechJebModuleNodeExecutor.cs index 2531e6289..27019a89b 100644 --- a/MechJeb2/MechJebModuleNodeExecutor.cs +++ b/MechJeb2/MechJebModuleNodeExecutor.cs @@ -36,6 +36,10 @@ public string NextNodeCountdown() double dV = node.GetBurnVector(orbit).magnitude; double halfBurnTIme; double burnTIme = BurnTime(dV, out halfBurnTIme); + if (double.IsInfinity(halfBurnTIme)) + { + halfBurnTIme = 0.0; + } return GuiUtils.TimeToDHMS(node.UT - halfBurnTIme - vesselState.time); } @@ -124,8 +128,8 @@ public override void OnFixedUpdate() double burnTime = BurnTime(dVLeft, out halfBurnTime); double timeToNode = node.UT - vesselState.time; - - if (halfBurnTime > 0 && timeToNode < halfBurnTime) + //(!double.IsInfinity(num) && num > 0.0 && num2 < num) || num2 <= 0.0 + if ((!double.IsInfinity(halfBurnTime) && halfBurnTime > 0 && timeToNode < halfBurnTime) || timeToNode < 0) { burnTriggered = true; if (!MuUtils.PhysicsRunning()) core.warp.MinimumWarp(); @@ -223,7 +227,27 @@ private double BurnTime(double dv, out double halfBurnTime) // TODO: Be smarter about throttle limits on future stages. if (i == stats.vacStats.Length - 1) { - stageAvgAccel *= vesselState.throttleLimit; + if (this.core.thrust.limiter != MechJebModuleThrustController.LimitMode.UnstableIgnition) + { + stageAvgAccel *= (double)this.vesselState.throttleLimit; + } + else + { + double fLimitTemp = 1.0; + if (this.core.thrust.limitThrottle) + { + fLimitTemp = this.core.thrust.maxThrottle; + } + if (this.core.thrust.limitAcceleration) + { + fLimitTemp = Math.Min(fLimitTemp, this.core.thrust.maxAccelerationLimit); + } + if (this.core.thrust.limiterMinThrottle) + { + fLimitTemp = Math.Max(this.core.thrust.minThrottle, fLimitTemp); + } + stageAvgAccel *= fLimitTemp; + } } halfBurnTime += Math.Min(halfDvLeft, stageBurnDv) / stageAvgAccel; diff --git a/MechJeb2/MechJebModuleThrustController.cs b/MechJeb2/MechJebModuleThrustController.cs index acb6a995e..2bb9648af 100644 --- a/MechJeb2/MechJebModuleThrustController.cs +++ b/MechJeb2/MechJebModuleThrustController.cs @@ -113,6 +113,8 @@ public void LimitToPreventUnstableIgnitionInfoItem() [Persistent(pass = (int)Pass.Global)] public EditableDouble maxAcceleration = 40; + public double maxAccelerationLimit = 1; + [GeneralInfoItem("Limit acceleration", InfoItem.Category.Thrust)] public void LimitAccelerationInfoItem() { @@ -136,7 +138,7 @@ public void LimitThrottleInfoItem() { GUILayout.BeginHorizontal(); GUIStyle s = new GUIStyle(GUI.skin.toggle); - if (limiter == LimitMode.Throttle) s.onHover.textColor = s.onNormal.textColor = Color.green; + if (limiter == LimitMode.Throttle) s.onHover.textColor = s.onNormal.textColor = maxThrottle > 0d ? Color.green : Color.red; limitThrottle = GUILayout.Toggle(limitThrottle, "Limit throttle to", s, GUILayout.Width(110)); maxThrottle.text = GUILayout.TextField(maxThrottle.text, GUILayout.Width(30)); GUILayout.Label("%", GUILayout.ExpandWidth(false)); @@ -431,6 +433,8 @@ public override void Drive(FlightCtrlState s) float limit = AccelerationLimitedThrottle(); if(limit < throttleLimit) limiter = LimitMode.Acceleration; throttleLimit = Mathf.Min(throttleLimit, limit); + // to provide an externally facing value. (used when ignition is unstable so we can approximate throttle limit when ignition stablizes) + maxAccelerationLimit = throttleLimit; } if (electricThrottle && ElectricEngineRunning()) @@ -458,15 +462,16 @@ public override void Drive(FlightCtrlState s) // RealFuels ullage integration. Stock always has stableUllage. if (limitToPreventUnstableIgnition && !vesselState.stableUllage) { - if (( targetThrottle > 0.0F || s.mainThrottle > 0.0F ) && throttleLimit > 0.0F ) { + if (( targetThrottle > 0.0F || s.mainThrottle > 0.0F ) && throttleLimit > 0.0F ) + { // We want to fire the throttle, and nothing else is limiting us, but we have unstable ullage - limiter = LimitMode.UnstableIgnition; if (vessel.ActionGroups[KSPActionGroup.RCS] && s.Z == 0) { // RCS is on, so use it to ullage s.Z = -1.0F; } } - throttleLimit = 0.0F; + limiter = LimitMode.UnstableIgnition; + throttleLimit = 0.0F; } if (double.IsNaN(throttleLimit)) throttleLimit = 0;