Skip to content

Commit

Permalink
Fix residuals calcs again
Browse files Browse the repository at this point in the history
Biggest problem seems to be the inverted boolean check, no idea how that
was working.  Also fixed it to correctly check subclassing, which
didn't seem to be the current issue but probably is one.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Aug 10, 2023
1 parent 85d48d4 commit 7f3cd29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
13 changes: 7 additions & 6 deletions MechJeb2/MechJebLib/Simulations/SimVesselBuilder.cs
Expand Up @@ -38,20 +38,21 @@ private IShipconstruct _kspVessel
set => _manager._kspVessel = value;
}

private readonly SimVesselManager _manager;
private readonly SimVesselManager _manager;
private static readonly Type? _rfType;

static SimVesselBuilder()
{
_crewMassDelegate = Versioning.version_major == 1 && Versioning.version_minor < 11 ? (CrewMass)CrewMassOld : CrewMassNew;

if (!ReflectionUtils.isAssemblyLoaded("RealFuels"))
if (ReflectionUtils.isAssemblyLoaded("RealFuels"))
{
_rfSpoolUpTime = ReflectionUtils.getFieldByReflection("RealFuels", "RealFuels.ModuleEnginesRF", "effectiveSpoolUpTime");
if (_rfSpoolUpTime == null)
{
Debug.Log(
"MechJeb BUG: RealFuels loaded, but RealFuels.ModuleEnginesRF has no effectiveSpoolUpTime field, disabling spoolup");
}

_rfType = Type.GetType("RealFuels.ModuleEnginesRF, RealFuels");
}
}

Expand Down Expand Up @@ -256,9 +257,9 @@ private SimModuleEngines BuildModuleEngines(SimPart part, ModuleEngines kspEngin

if (ReflectionUtils.isAssemblyLoaded("RealFuels"))
{
engine.isModuleEnginesRF = Type.GetType("RealFuels.ModuleEnginesRF, RealFuels") == engine.GetType();
engine.isModuleEnginesRF = _rfType!.IsInstanceOfType(kspEngine);

if(engine.isModuleEnginesRF && _rfSpoolUpTime!.GetValue(kspEngine) is float floatVal)
if (engine.isModuleEnginesRF && _rfSpoolUpTime!.GetValue(kspEngine) is float floatVal)
engine.ModuleSpoolupTime = floatVal;
}

Expand Down
20 changes: 7 additions & 13 deletions MechJeb2/MechJebLib/Simulations/SimVesselUpdater.cs
Expand Up @@ -29,26 +29,20 @@ public class SimVesselUpdater
static SimVesselUpdater()
{
if (ReflectionUtils.isAssemblyLoaded("ProceduralFairings"))

{
_pfDecoupled =
ReflectionUtils.getFieldByReflection("ProceduralFairings", "ProceduralFairings.ProceduralFairingDecoupler", "decoupled");
_pfDecoupled = ReflectionUtils.getFieldByReflection("ProceduralFairings", "ProceduralFairings.ProceduralFairingDecoupler",
"decoupled");
if (_pfDecoupled == null)
{
Debug.Log(
"MechJeb BUG: ProceduralFairings loaded, but ProceduralFairings.ProceduralFairingDecoupler has no decoupled field");
}
Debug.Log("MechJeb BUG: ProceduralFairings loaded, but ProceduralFairings.ProceduralFairingDecoupler has no decoupled field");
}

if (ReflectionUtils.isAssemblyLoaded("RealFuels"))
{
_rfPredictedMaximumResiduals =
ReflectionUtils.getFieldByReflection("RealFuels", "RealFuels.ModuleEnginesRF", "predictedMaximumResiduals");
if (_rfPredictedMaximumResiduals == null)
{
Debug.Log(
"MechJeb BUG: RealFuels loaded, but RealFuels.ModuleEnginesRF has no predictedMaximumResiduals field, disabling residuals");
}
}
}

Expand Down Expand Up @@ -231,10 +225,10 @@ private static void UpdateModuleRCS(SimModuleRCS rcs, ModuleRCS? kspModuleRCS)
return;
}

rcs.IsEnabled = kspModuleRCS.isEnabled;
rcs.Isp = kspModuleRCS.atmosphereCurve.Evaluate(0) * kspModuleRCS.ispMult;
rcs.Thrust = kspModuleRCS.flowMult * kspModuleRCS.maxFuelFlow * rcs.Isp * rcs.G;
rcs.RcsEnabled = kspModuleRCS.rcsEnabled;
rcs.IsEnabled = kspModuleRCS.isEnabled;
rcs.Isp = kspModuleRCS.atmosphereCurve.Evaluate(0) * kspModuleRCS.ispMult;
rcs.Thrust = kspModuleRCS.flowMult * kspModuleRCS.maxFuelFlow * rcs.Isp * rcs.G;
rcs.RcsEnabled = kspModuleRCS.rcsEnabled;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 7f3cd29

Please sign in to comment.