public void BreakShipIntoStages() { stages.Clear(); //loop through the part tree and try to break it into stages List <Part> parts = EditorLogic.fetch.ship.parts; EditorStatItem current = new EditorStatItem(); int stageNum = 0; StageParts stage = new StageParts(); List <Part> RemainingDecouplers = null; // = new List<Part>() { parts[0] }; foreach (var p in parts) { if (p.parent == null) { RemainingDecouplers = new List <Part>() { p }; break; } } if (RemainingDecouplers == null) { Log.Error("No parent part found"); return; } while (RemainingDecouplers.Count > 0) { //determine stages from the decouplers Part parent = RemainingDecouplers[0]; RemainingDecouplers.RemoveAt(0); stage = DetermineStage(parent); current = new EditorStatItem { stageNumber = stageNum++, parts = stage.parts }; RemainingDecouplers.AddRange(stage.decouplers); //compute properties double dryMass = 0; double wetMass = 0; stage.parts.ForEach(p => { dryMass += p.mass; wetMass += p.mass + p.GetResourceMass(); }); current.dryMass = dryMass; current.mass = wetMass; current.chuteArea = StageRecovery.GetChuteArea(stage.parts); stages.Add(current); } ConsolidateStages(); Log.Info("[SR] Found " + stages.Count + " stages!"); }
public void BreakShipIntoStages() { //loop through the part tree and try to break it into stages List <Part> parts = EditorLogic.fetch.ship.parts; EditorStatItem current = new EditorStatItem(); int stageNum = 0; StageParts stage = new StageParts(); List <Part> RemainingDecouplers = null; // = new List<Part>() { parts[0] }; for (int i = 0; i < parts.Count; i++) { Part p = parts[i]; if (p.parent == null) { RemainingDecouplers = new List <Part>() { p }; break; } } if (RemainingDecouplers == null) { stages.Clear(); Log.Error("No parent part found"); return; } var stageList = new List <EditorStatItem>(); while (RemainingDecouplers.Count > 0) { //determine stages from the decouplers Part parent = RemainingDecouplers[0]; RemainingDecouplers.RemoveAt(0); stage = DetermineStage(parent); current = new EditorStatItem { stageNumber = stageNum++, parts = stage.parts }; #if DEBUG Log.Info("Parent part: " + parent.partInfo.title); foreach (var d in stage.decouplers) { Log.Info("Child decouplers: " + d.partInfo.title); } #endif RemainingDecouplers.AddRange(stage.decouplers); //compute properties double dryMass = 0; double wetMass = 0; stage.parts.ForEach(p => { dryMass += p.mass; wetMass += p.mass + p.GetResourceMass(); }); current.dryMass = dryMass; current.mass = wetMass; current.chuteArea = StageRecovery.GetChuteArea(stage.parts); stageList.Add(current); } ConsolidateStages(ref stageList); stages.Clear(); // wait until we have a full stages collection before we clear it stages.AddRange(stageList); Log.Info("[SR] Found " + stages.Count + " stages!"); }