Beispiel #1
0
 static public void UpdateChildren(Part p, string recoveryOwner, bool entireVessel = false)
 {
     foreach (Part child in p.children)
     {
         if (!idUtil.IsDecoupler(child))
         {
             ControllingRecoveryModule crm = child.FindModuleImplementing <ControllingRecoveryModule>();
             if (crm == null)
             {
                 Log.Info("Missing module ControllingRecoveryModule");
             }
             crm.RecoveryOwner = recoveryOwner;
             UpdateChildren(child, recoveryOwner, entireVessel);
         }
         else
         {
             if (entireVessel)
             {
                 // get child, and call using child and it's recoveryOwner
                 RecoveryIDModule ridm = child.FindModuleImplementing <RecoveryIDModule>();
                 UpdateChildren(child, ridm.RecoveryOwner, true);
             }
         }
     }
 }
Beispiel #2
0
 void onVesselLoaded(Vessel v)
 {
     Log.dbg("onVesselLoaded");
     if (v == null || v.rootPart == null)
     {
         return;
     }
     if (!registeredMods.Contains("StageRecovery"))
     {
         return;
     }
     if (!idUtil.IsDecoupler(v.rootPart))
     {
         ControllingRecoveryModule m = v.rootPart.FindModuleImplementing <ControllingRecoveryModule>();
         if (m != null)
         {
             idUtil.UpdateChildren(v.rootPart, m.RecoveryOwner, true);
         }
     }
     else
     {
         RecoveryIDModule m = v.rootPart.FindModuleImplementing <RecoveryIDModule>();
         if (m != null)
         {
             idUtil.UpdateChildren(v.rootPart, m.RecoveryOwner, true);
         }
     }
 }
Beispiel #3
0
 void UpdateChildren(Part p)
 {
     foreach (Part child in p.children)
     {
         if (!idUtil.IsDecoupler(child))
         {
             ControllingRecoveryModule crm = child.FindModuleImplementing <ControllingRecoveryModule>();
             if (crm == null)
             {
                 Log.Info("Missing module ControllingRecoveryModule");
             }
             crm.RecoveryOwner = RecoveryOwner;
             UpdateChildren(child);
         }
     }
 }
Beispiel #4
0
        void onEditorPartPlaced(Part p)
        {
            if (p == null)
            {
                Log.Info("RecoveryController.onEditorPartPlaced, part is null");
                return;
            }
            Log.Info("RecoveryController.onEditorPartPlaced, part: " + p.partInfo.name);
            if (p.parent == null)
            {
                // First part placed, set to auto
                Log.Info("Initial part placement");
                if (!idUtil.IsDecoupler(p))
                {
                    p.FindModuleImplementing <ControllingRecoveryModule>().RecoveryOwner = AUTO;
                }
                else
                {
                    p.FindModuleImplementing <RecoveryIDModule>().RecoveryOwner = AUTO;
                }

                return;
            }
            if (!idUtil.IsDecoupler(p))
            {
                string roParent;

                ControllingRecoveryModule m = p.FindModuleImplementing <ControllingRecoveryModule>();
                if (!idUtil.IsDecoupler(p.parent))
                {
                    roParent = p.parent.FindModuleImplementing <ControllingRecoveryModule>().RecoveryOwner;
                }
                else
                {
                    roParent = p.parent.FindModuleImplementing <RecoveryIDModule>().RecoveryOwner;
                }

                m.RecoveryOwner = roParent;
            }
            else
            {
                Log.Info("Decoupler placed");
                // Always set decoupler to auto when placed
                p.FindModuleImplementing <RecoveryIDModule>().RecoveryOwner = AUTO;
            }
        }
Beispiel #5
0
 void onVesselWasModified(Vessel v)
 {
     Log.dbg("onVesselWasModified");
     if (!idUtil.IsDecoupler(v.rootPart))
     {
         ControllingRecoveryModule m = v.rootPart.FindModuleImplementing <ControllingRecoveryModule>();
         if (m != null)
         {
             idUtil.UpdateChildren(v.rootPart, m.RecoveryOwner, true);
         }
     }
     else
     {
         RecoveryIDModule m = v.rootPart.FindModuleImplementing <RecoveryIDModule>();
         idUtil.UpdateChildren(v.rootPart, v.rootPart.FindModuleImplementing <RecoveryIDModule>().RecoveryOwner, true);
     }
 }
Beispiel #6
0
        public string ControllingMod(Vessel v)
        {
            if (v.name.StartsWith("Ast."))
            {
                Log.Info("Vessel: Asteroid");
                return("");
            }

            Log.Info("ControllingMod, vessel: " + v.name);
            if (!v.loaded)
            {
                Log.Info("Vessel is unloaded");
                foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                {
                    Log.Info("ProtoPartsnapshot, currentStage: " + v.currentStage.ToString() + "  stageIndex: " + p.stageIndex.ToString() + "  inverseStageIndex: " + p.inverseStageIndex.ToString());
                    if (p.inverseStageIndex >= v.currentStage - 1)
                    {
                        if (idUtil.IsDecoupler(p))
                        {
                            ProtoPartModuleSnapshot m = p.modules.FirstOrDefault(mod => mod.moduleName == "RecoveryIDModule");

                            // FindModuleImplementing<RecoveryIDModule>();
                            if (m != null /*&& m.moduleRef != null */)
                            {
                                Log.Info("Part: " + p.partInfo.name + ", decoupler, Returning: " + m.moduleValues.GetValue("recoveryOwner"));
                                return(m.moduleValues.GetValue("recoveryOwner"));
                                //return ((RecoveryIDModule)m.moduleRef).RecoveryOwner;
                            }
                        }
                        else
                        {
                            if (p.modules.Count > 0)
                            {
                                {
                                    ProtoPartModuleSnapshot m = p.modules.FirstOrDefault(mod => mod.moduleName == "ControllingRecoveryModule");
                                    if (m != null /* && m.moduleRef != null */)
                                    {
                                        Log.Info("Part: " + p.partInfo.name + ", part,  Returning: " + m.moduleValues.GetValue("recoveryOwner"));
                                        return(m.moduleValues.GetValue("recoveryOwner"));
                                        //return ((RecoveryIDModule)m.moduleRef).RecoveryOwner;
                                    }
                                }
                            }
                            else
                            {
                                Log.Info("ControllingRecoveryModule not found");
                                return("ControllingRecoveryModule not found");
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Part p in v.Parts)
                {
                    if (p.inverseStage >= v.currentStage - 1)
                    {
                        if (idUtil.IsDecoupler(p))
                        {
                            RecoveryIDModule m = p.FindModuleImplementing <RecoveryIDModule>();
                            if (m != null)
                            {
                                Log.Info("Part: " + p.partInfo.name + ", Returning: " + m.RecoveryOwner);
                                return(m.RecoveryOwner);
                            }
                        }
                        else
                        {
                            ControllingRecoveryModule m = p.FindModuleImplementing <ControllingRecoveryModule>();
                            if (m != null)
                            {
                                Log.Info("Part: " + p.partInfo.name + ", Returning: " + m.RecoveryOwner);
                                return(m.RecoveryOwner);
                            }
                        }
                    }
                }
            }
            Log.Info("returning null");
            return(null);
        }