Skip to content

Commit

Permalink
this is like. so much more elegant and functional.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Apr 3, 2018
1 parent 6377ca2 commit 832d38f
Showing 1 changed file with 14 additions and 44 deletions.
58 changes: 14 additions & 44 deletions KerbalEngineer/VesselSimulator/PartSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,31 +836,25 @@ private int DecoupledInStage(Part thePart) {
if (original.parent == null)
return stage; //root part is always present. Fixes phantom stage if root is stageable.

List<Part> chain = new List<Part>(); //prolly dont need a list, just the previous part but whatever.

while (thePart != null) {

chain.Add(thePart);

if (thePart.inverseStage > stage) {

ModuleDecouple mdec = thePart.GetModule<ModuleDecouple>();
ModuleDockingNode mdock = thePart.GetModule<ModuleDockingNode>();
ModuleAnchoredDecoupler manch = thePart.GetModule<ModuleAnchoredDecoupler>();

if (mdec != null) {
ModuleDynamicNodes mdyn = thePart.GetModule<ModuleDynamicNodes>();
if (mdyn != null) { //engine plate
if (original == thePart) { //checking self, make sure not upside down
if (thePart.parent != null && mdec.ExplosiveNode != null && mdec.ExplosiveNode.attachedPart == thePart.parent) //leaves with stage
stage = thePart.inverseStage;
} else if (original.parent != null && original.parent == thePart) { //plate direct child.
if (mdec.ExplosiveNode != null && mdec.ExplosiveNode.attachedPart == original)
stage = thePart.inverseStage; //goodbye!
} else stage = thePart.inverseStage; //decouple.
} else {//regular decoupler
if (original == thePart) { //checking self
if (mdec.isOmniDecoupler || (thePart.parent != null && mdec.ExplosiveNode != null && mdec.ExplosiveNode.attachedPart == thePart.parent)) //leaves with stage
stage = thePart.inverseStage;
} else if (original.parent != null && original.parent == thePart) {
//decoupler direct child (i.e surface attached to round pods)
if (mdec.isOmniDecoupler || (mdec.ExplosiveNode != null && (mdec.ExplosiveNode.attachedPart == original || mdec.ExplosiveNode.attachedPart == thePart.parent))) //leaves with stage
AttachNode att = thePart.FindAttachNode(mdec.explosiveNodeID);
if (mdec.isOmniDecoupler)
stage = thePart.inverseStage;
else {
if (att != null) {
if ((thePart.parent != null && att.attachedPart == thePart.parent) || chain.Contains(att.attachedPart))
stage = thePart.inverseStage;
} else stage = thePart.inverseStage;
}
Expand All @@ -869,17 +863,10 @@ private int DecoupledInStage(Part thePart) {
if (manch != null) //radial decouplers (ALSO REENTRY PODS BECAUSE REASONS!)
{
AttachNode att = thePart.FindAttachNode(manch.explosiveNodeID); // these stupid fuckers don't initialize in the Editor scene.
if (original == thePart) { //checking self.
if (att != null) { //pod?
if ((thePart.parent != null && att.attachedPart == thePart.parent)) //upside down pod?
stage = thePart.inverseStage;//upside down pod!
} else {
stage = thePart.inverseStage; //radials, always leaves because they're super hard to put on backwards. Like pants.
}
} else if (att != null && original.parent != null && original.parent == thePart) { //pod direct children.
if (att.attachedPart == original || att.attachedPart == thePart.parent)
stage = thePart.inverseStage; //this child has be voted off the island.
} else stage = thePart.inverseStage;
if (att != null) {
if ((thePart.parent != null && att.attachedPart == thePart.parent) || chain.Contains(att.attachedPart))
stage = thePart.inverseStage;
} else stage = thePart.inverseStage; //radial decouplers it seems the attach node ('surface') comes back null.
}

if (mdock != null) //docking port
Expand All @@ -897,23 +884,6 @@ private int DecoupledInStage(Part thePart) {
return stage;
}

private bool IsActiveDecoupler(Part thePart) {
return thePart.FindModulesImplementing<ModuleDecouple>().Any(mod => !mod.isDecoupled) ||
thePart.FindModulesImplementing<ModuleAnchoredDecoupler>().Any(mod => !mod.isDecoupled);
}

private bool IsDecoupler(Part thePart) {
PartExtensions.ProtoModuleDecoupler protoDecoupler = thePart.GetProtoModuleDecoupler();
if (protoDecoupler != null && protoDecoupler.IsStageEnabled)
return true;

ModuleDockingNode modDock = thePart.GetModule<ModuleDockingNode>();
if (modDock != null && modDock.IsStageable())
return true;

return false;
}

private static bool IsEnginePlate(Part thePart) {
ModuleDecouple mdec = thePart.GetModule<ModuleDecouple>();
if (mdec != null && mdec.IsStageable()) {
Expand Down

0 comments on commit 832d38f

Please sign in to comment.