Skip to content

Commit

Permalink
Expose propellantStability directly without rounding
Browse files Browse the repository at this point in the history
Introduces GetPropellantProbability/GetUllageProbability to get
the rounded version that forces veryStable to 100% (couldn't think
of a better name, even though this isn't really the proper probability
since the exponent isn't applied).

This lets MJ 'see' values between 0.996 and 1.0

Didn't get this compiling yet because of all the RF deps and ROUtils in
particular so be a little careful before merging.

Signed-off-by: Lamont Granquist <[email protected]>
  • Loading branch information
lamont-granquist committed Nov 8, 2023
1 parent c672e1f commit d019015
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
20 changes: 10 additions & 10 deletions Source/Engines/ModuleEnginesRF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ModuleEnginesRF : ModuleEnginesSolver

protected Propellant curveProp;

[KSPField(guiName = "#RF_EngineRF_IgnitedFor", guiUnits = "s", guiFormat = "F3", groupName = groupName)] // Ignited for
[KSPField(guiName = "#RF_EngineRF_IgnitedFor", guiUnits = "s", guiFormat = "F3", groupName = groupName)] // Ignited for
public float curveTime = 0f;
#endregion

Expand Down Expand Up @@ -496,9 +496,9 @@ private void SetFields()
tags += pressureFed ? ", " : string.Empty;
tags += $"<color=yellow>{Localizer.GetStringByTag("#RF_EngineRF_Ullage")}</color>"; // Ullage
}
sISP = $"{atmosphereCurve.Evaluate(1):N0} (ASL) - {atmosphereCurve.Evaluate(0):N0} (Vac)"; //
sISP = $"{atmosphereCurve.Evaluate(1):N0} (ASL) - {atmosphereCurve.Evaluate(0):N0} (Vac)"; //
GetThrustData(out double thrustVac, out double thrustASL);
sThrust = $"{Utilities.FormatThrust(thrustASL)} (ASL) - {Utilities.FormatThrust(thrustVac)} (Vac)"; //
sThrust = $"{Utilities.FormatThrust(thrustASL)} (ASL) - {Utilities.FormatThrust(thrustVac)} (Vac)"; //
if (ignitions > 0)
sIgnitions = $"{ignitions:N0}";
else if (ignitions == -1)
Expand Down Expand Up @@ -685,7 +685,7 @@ public override void UpdateSolver(EngineThermodynamics ambientTherm, double alti
{
if (EngineIgnited && ignited && throttledUp && rfSolver.GetRunning())
{
double state = ullageSet.GetUllageStability();
double state = ullageSet.GetUllageProbability();
double testValue = Math.Pow(state, RFSettings.Instance.stabilityPower);
if (staticRandom.NextDouble() > testValue)
{
Expand Down Expand Up @@ -762,10 +762,10 @@ public void SetScale(double newScale)
#region Info
protected string ThrottleString()
{
if (throttleLocked) { return ", throttle locked"; } //
if (MinThrottle == 1f) { return ", unthrottleable"; } //
if (throttleLocked) { return ", throttle locked"; } //
if (MinThrottle == 1f) { return ", unthrottleable"; } //
if (MinThrottle < 0f || MinThrottle > 1f) { return string.Empty; }
return $", {MinThrottle:P0} min throttle"; //
return $", {MinThrottle:P0} min throttle"; //
}

protected void GetThrustData(out double thrustVac, out double thrustASL)
Expand Down Expand Up @@ -850,8 +850,8 @@ protected string GetThrustInfo()
output += $"{MinThrottle:P0} {Localizer.GetStringByTag("#RF_EngineRF_MinThrottle")}\n"; // min throttle
if (thrustASL != thrustVac)
{
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MAXThrustInVac")}: </b>{Utilities.FormatThrust(thrustVac)} (TWR {thrustVac / weight:0.0##})\n"; //Max. Thrust (Vac)
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MAXThrustInASL")}: </b>{Utilities.FormatThrust(thrustASL)} (TWR {thrustASL / weight:0.0##})\n"; //Max. Thrust (ASL)
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MAXThrustInVac")}: </b>{Utilities.FormatThrust(thrustVac)} (TWR {thrustVac / weight:0.0##})\n"; //Max. Thrust (Vac)
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MAXThrustInASL")}: </b>{Utilities.FormatThrust(thrustASL)} (TWR {thrustASL / weight:0.0##})\n"; //Max. Thrust (ASL)
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MINThrustInVac")}: </b>{Utilities.FormatThrust(thrustVac * MinThrottle)} (TWR {thrustVac * MinThrottle / weight:0.0##})\n"; // Min. Thrust (Vac)
output += $"<b>{Localizer.GetStringByTag("#RF_EngineRF_MINThrustInASL")}: </b>{Utilities.FormatThrust(thrustASL * MinThrottle)} (TWR {thrustASL * MinThrottle / weight:0.0##})\n"; // Min. Thrust (ASL)
}
Expand Down Expand Up @@ -887,7 +887,7 @@ public string GetUllageIgnition()
return output;
}


public override string GetInfo()
{
string output = $"{GetThrustInfo()}" +
Expand Down
3 changes: 2 additions & 1 deletion Source/Ullage/UllageSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void Update(Vector3 acc, Vector3 angVel, double timeDelta, double venting
angularVelocity = engine.transform.InverseTransformDirection(engine.part.rb.angularVelocity);
else
angularVelocity = engine.transform.InverseTransformDirection(angVel);

fuelRatio = 1d;
if(HighLogic.LoadedSceneIsFlight && engine.EngineIgnited)
{
Expand All @@ -139,6 +139,7 @@ public void Update(Vector3 acc, Vector3 angVel, double timeDelta, double venting
public void SetUllageStability(double newStability) => ullageSim.SetPropellantStability(newStability);
public string GetUllageState(out Color col) => ullageSim.GetPropellantStatus(out col);
public double GetUllageStability() => ullageSim.GetPropellantStability();
public double GetUllageProbability() => ullageSim.GetPropellantProbability();
public bool PressureOK() => !engine.pressureFed || tanksHighlyPressurized;
public bool EditorPressurized()
{
Expand Down
10 changes: 6 additions & 4 deletions Source/Ullage/UllageSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void Update(Vector3d localAcceleration, Vector3d rotation, double deltaTi

//if (ventingAcc != 0.0f) Debug.Log("BoilOffAcc: " + ventingAcc.ToString("F8"));
//else Debug.Log("BoilOffAcc: No boiloff.");

Vector3d localAccelerationAmount = localAcceleration * deltaTime;
Vector3d rotationAmount = rotation * deltaTime;

Expand Down Expand Up @@ -179,8 +179,6 @@ public void Update(Vector3d localAcceleration, Vector3d rotation, double deltaTi
//Debug.Log("Ullage: pHorizontal: " + pHorizontal.ToString("F3"));

propellantStability = Math.Max(0.0d, 1.0d - (pVertical * pHorizontal * (0.75d + Math.Sqrt(bLevel))));
if (propellantStability >= veryStable)
propellantStability = 1d;

//#if DEBUG
// if (propellantStability < 0.5d)
Expand All @@ -204,9 +202,13 @@ private void SetStateString()
propellantStatus = Localizer.GetStringByTag("#RF_UllageState_Unstable"); // "Unstable"
else
propellantStatus = Localizer.GetStringByTag("#RF_UllageState_VeryUnstable"); // "Very Unstable"
propellantStatus += $" ({propellantStability:P2})";
propellantStatus += $" ({GetPropellantProbability():P2})";
}
public double GetPropellantStability() => propellantStability;
public double GetPropellantProbability()
{
return propellantStability >= veryStable ? 1.0d : propellantStability;
}
public void SetPropellantStability(double newStab) => propellantStability = newStab;
public string GetPropellantStatus(out Color col)
{
Expand Down

0 comments on commit d019015

Please sign in to comment.