Skip to content

Commit

Permalink
Change boolean-returning API to look more boolean
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Feb 29, 2024
1 parent b99cb00 commit 64c77bc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleStagingController.cs
Expand Up @@ -499,7 +499,7 @@ private bool HasActiveOrIdleEngineOrTankDescendant(Part p, List<int> tankResourc

if (!p.IsSepratron() && !IsBurnedOutSrbDecoupledInNextStage(p))
{
if ((p.State == PartStates.ACTIVE || p.State == PartStates.IDLE) && p.EngineHasFuel() && !p.UnrestartableDeadEngine())
if ((p.State == PartStates.ACTIVE || p.State == PartStates.IDLE) && p.EngineHasFuel() && !p.IsUnrestartableDeadEngine())
{
return true; // TODO: properly check if ModuleEngines is active
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class SimModuleEngines : SimPartModule
public double ModuleSpoolupTime;
public bool NoPropellants;
public bool IsModuleEnginesRf;
public bool UnrestartableDeadEngine;
public bool IsUnrestartableDeadEngine;

public readonly H1 ThrustCurve = H1.Get(true);
public readonly H1 ThrottleIspCurve = H1.Get(true);
Expand Down
2 changes: 1 addition & 1 deletion MechJebLib/FuelFlowSimulation/SimVessel.cs
Expand Up @@ -107,7 +107,7 @@ public void UpdateActiveEngines()
{
if (e.MassFlowRate <= 0) continue;

if (e.UnrestartableDeadEngine)
if (e.IsUnrestartableDeadEngine)
continue;

e.UpdateEngineStatus();
Expand Down
14 changes: 7 additions & 7 deletions MechJebLibBindings/FuelFlowSimulation/SimVesselUpdater.cs
Expand Up @@ -163,13 +163,13 @@ private void UpdateModuleEngines(SimPart part, SimModuleEngines engine, ModuleEn

// we need to check for launch clamps since non-airlightable engines have zero restarts but magically start
// when the vessel has a launch clamp
engine.UnrestartableDeadEngine = kspEngine.UnrestartableDeadEngine() && !_vessel.HasLaunchClamp;
engine.IsEnabled = kspEngine.isEnabled;
engine.IsOperational = kspEngine.isOperational;
engine.ThrottleLimiter = kspEngine.thrustPercentage;
engine.MultIsp = kspEngine.multIsp;
engine.NoPropellants = kspEngine is { flameout: true, statusL2: "No propellants" };
engine.ModuleResiduals = 0;
engine.IsUnrestartableDeadEngine = kspEngine.IsUnrestartableDeadEngine() && !_vessel.HasLaunchClamp;
engine.IsEnabled = kspEngine.isEnabled;
engine.IsOperational = kspEngine.isOperational;
engine.ThrottleLimiter = kspEngine.thrustPercentage;
engine.MultIsp = kspEngine.multIsp;
engine.NoPropellants = kspEngine is { flameout: true, statusL2: "No propellants" };
engine.ModuleResiduals = 0;

if (engine.IsModuleEnginesRf && _rfPredictedMaximumResiduals!.GetValue(kspEngine) is double doubleVal)
engine.ModuleResiduals = doubleVal;
Expand Down
9 changes: 3 additions & 6 deletions MechJebLibBindings/PartExtensions.cs
Expand Up @@ -21,15 +21,13 @@ static PartExtensions()

/// <summary>
/// Checks that all engine modules on the part are unrestartable and dead.
///
/// Note that the caller must ensure that the vessel does not have any launch clamps, which always allows the engine
/// to start.
///
/// When called on a part with no engine modules, this method returns false.
/// </summary>
/// <param name="p">the Part</param>
/// <returns>if the Part's engine modules are all unrestable dead engines</returns>
public static bool UnrestartableDeadEngine(this Part p)
public static bool IsUnrestartableDeadEngine(this Part p)
{
if (CheatOptions.InfinitePropellant)
return false;
Expand All @@ -43,7 +41,7 @@ public static bool UnrestartableDeadEngine(this Part p)

foreach (ModuleEngines e in enginelist)
{
if (!e.UnrestartableDeadEngine())
if (!e.IsUnrestartableDeadEngine())
return false;
}

Expand All @@ -52,13 +50,12 @@ public static bool UnrestartableDeadEngine(this Part p)

/// <summary>
/// Checks that the engine module is unrestartable and dead.
///
/// Note that the caller must ensure that the vessel does not have any launch clamps, which always allows the engine
/// to start.
/// </summary>
/// <param name="e">the ModulEngines</param>
/// <returns>if the engine module is an unrestartable dead engine</returns>
public static bool UnrestartableDeadEngine(this ModuleEngines e)
public static bool IsUnrestartableDeadEngine(this ModuleEngines e)
{
if (CheatOptions.InfinitePropellant)
return false;
Expand Down

0 comments on commit 64c77bc

Please sign in to comment.