Skip to content

Commit

Permalink
Fix the FFS root part
Browse files Browse the repository at this point in the history
Need to pick the part with a null parent, not part[0]

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Sep 30, 2023
1 parent da367eb commit 9335acd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions MechJeb2/MechJebLib/Simulations/DecouplingAnalyzer.cs
Expand Up @@ -26,12 +26,18 @@ public static void Analyze(SimVessel v)
CalculateDecoupledInStageRecursively(v, rootPart, null, -1);
}

private static SimPart FindRootPart(IReadOnlyList<SimPart> parts)
{
for (int i = 0; i < parts.Count; i++)
if (parts[i].IsRoot)
return parts[i];
return parts[0];
}

// BUG: This should at least be fixed to not pick the payload fairings if they are left in stage 0
// BUG: Does this even do anything? What part has a inverseStage of -1?
// BUG: Even if we change this to p.InverseStage <= 0 below what happens with the last decoupler when
// it should detatch the payload and so the part decoupled from it should be the root, not the part itself?
private static SimPart FindRootPart(IReadOnlyList<SimPart> parts) => parts[0];

/*
SimPart? rootPart = null;
Expand Down
1 change: 1 addition & 0 deletions MechJeb2/MechJebLib/Simulations/SimPart.cs
Expand Up @@ -38,6 +38,7 @@ public class SimPart
public double DisabledResourcesMass;
public double EngineResiduals;

public bool IsRoot;
public bool IsLaunchClamp;
public bool IsEngine;
public bool IsSepratron => IsEngine && IsThrottleLocked && ActivatesEvenIfDisconnected && InverseStage == DecoupledInStage;
Expand Down
1 change: 1 addition & 0 deletions MechJeb2/MechJebLib/Simulations/SimVesselBuilder.cs
Expand Up @@ -138,6 +138,7 @@ private SimPart BuildPart(Part kspPart)
part.Mass = kspPart.mass;
part.Name = kspPart.name;
part.DryMass = kspPart.prefabMass;
part.IsRoot = kspPart.parent is null;
part.ModulesStagedMass = GetModuleMass(kspPart, kspPart.prefabMass, ModifierStagingSituation.STAGED);
part.ModulesUnstagedMass = GetModuleMass(kspPart, kspPart.prefabMass, ModifierStagingSituation.UNSTAGED);
part.DecoupledInStage = int.MinValue;
Expand Down

0 comments on commit 9335acd

Please sign in to comment.