Fixed editor overlay loading and added heading/pitch/roll rate readouts.
[VesselSimulator.git] / KerbalEngineer / VesselSimulator / EngineSim.cs
blob:a/KerbalEngineer/VesselSimulator/EngineSim.cs -> blob:b/KerbalEngineer/VesselSimulator/EngineSim.cs
--- a/KerbalEngineer/VesselSimulator/EngineSim.cs
+++ b/KerbalEngineer/VesselSimulator/EngineSim.cs
@@ -267,46 +267,36 @@
                         break;
 
                     case ResourceFlowMode.STAGE_PRIORITY_FLOW:
-                    {
-                        Dictionary<int, HashSet<PartSim>> stagePartSets = new Dictionary<int, HashSet<PartSim>>();
-                        int maxStage = -1;
-                        foreach (PartSim aPartSim in allParts)
-                        {
-                            if (aPartSim.resources[type] > SimManager.RESOURCE_MIN)
-                            {
-                                //int stage = aPartSim.decoupledInStage;            // Use the number of the stage the tank is decoupled in
-                                int stage = aPartSim.DecouplerCount(); // Use the count of decouplers between tank and root
-                                if (stage > maxStage)
-                                {
-                                    maxStage = stage;
-                                }
-                                if (stagePartSets.ContainsKey(stage))
-                                {
-                                    sourcePartSet = stagePartSets[stage];
-                                }
-                                else
-                                {
-                                    sourcePartSet = new HashSet<PartSim>();
-                                    stagePartSets.Add(stage, sourcePartSet);
-                                }
-
-                                sourcePartSet.Add(aPartSim);
-                            }
-                        }
-
-                        while (maxStage >= 0)
-                        {
-                            if (stagePartSets.ContainsKey(maxStage))
-                            {
-                                if (stagePartSets[maxStage].Count() > 0)
-                                {
-                                    sourcePartSet = stagePartSets[maxStage];
-                                    break;
-                                }
-                            }
-                            maxStage--;
-                        }
-                    }
+                        var stagePartSets = new Dictionary<int, HashSet<PartSim>>();
+                        var maxStage = -1;
+
+                        Logger.Log(type);
+                        foreach (var aPartSim in allParts)
+                        {
+                            if (aPartSim.resources[type] <= SimManager.RESOURCE_MIN) continue;
+
+                            var stage = aPartSim.DecouplerCount();
+                            if (stage > maxStage)
+                            {
+                                maxStage = stage;
+                            }
+
+                            if (!stagePartSets.TryGetValue(stage, out sourcePartSet))
+                            {
+                                sourcePartSet = new HashSet<PartSim>();
+                                stagePartSets.Add(stage, sourcePartSet);
+                            }
+                            sourcePartSet.Add(aPartSim);
+                        }
+
+                        for (var i = 0; i <= maxStage; i++)
+                        {
+                            HashSet<PartSim> stagePartSet;
+                            if (stagePartSets.TryGetValue(i, out stagePartSet) && stagePartSet.Count > 0)
+                            {
+                                sourcePartSet = stagePartSet;
+                            }
+                        }
                         break;
 
                     case ResourceFlowMode.STACK_PRIORITY_SEARCH: