Ejemplo n.º 1
0
        internal List <Part> GetDockedVesselParts(ModuleDockingNode dockingNode)
        {
            List <Part> vesselpartList = new List <Part>();

            try
            {
                if (dockingNode != null)
                {
                    // The root part matters for the original vessel.  However, vessels that are split from the original vessel have their docking port as the root.
                    // So, if the root is the docking port, we want to grab the children from the docking port.  if the root is different than the port, we want to use
                    // the Root, as the docking port will not have a parent...
                    if (!vesselpartList.Contains(dockingNode.part))
                    {
                        vesselpartList.Add(dockingNode.part);
                    }
                    Part vesselRoot =
                        (from p in Vessel.parts where p.flightID == dockingNode.vesselInfo.rootPartUId select p).SingleOrDefault();
                    if (vesselRoot != null)
                    {
                        GetChildren(vesselRoot, ref vesselpartList);
                    }
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($"Error in GetSelectedVesselParts().\r\nError:  {ex}", SmUtils.LogType.Error, true);
                vesselpartList = new List <Part>();
            }
            return(vesselpartList);
        }
Ejemplo n.º 2
0
 internal void GetHatches()
 {
     _hatches.Clear();
     try
     {
         if (!SMSettings.EnableCls || !SMConditions.CanShowShipManifest())
         {
             return;
         }
         if (!SMAddon.GetClsAddon())
         {
             return;
         }
         SMAddon.UpdateClsSpaces();
         if (!SMAddon.GetClsVessel())
         {
             return;
         }
         List <ICLSPart> .Enumerator hParts = SMAddon.ClsAddon.Vessel.Parts.GetEnumerator();
         while (hParts.MoveNext())
         {
             if (hParts.Current == null)
             {
                 continue;
             }
             List <PartModule> .Enumerator hModules = hParts.Current.Part.Modules.GetEnumerator();
             while (hModules.MoveNext())
             {
                 if (hModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)hModules.Current;
                 if (pModule.moduleName != "ModuleDockingHatch")
                 {
                     continue;
                 }
                 ModHatch pHatch = new ModHatch
                 {
                     HatchModule = (PartModule)hModules.Current,
                     ClsPart     = hParts.Current
                 };
                 _hatches.Add(pHatch);
             }
             hModules.Dispose();
         }
         hParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetHatches().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 3
0
 internal void GetAntennas()
 {
     _antennas.Clear();
     try
     {
         // Added support for RemoteTech antennas
         List <Part> .Enumerator pParts = Vessel.Parts.GetEnumerator();
         while (pParts.MoveNext())
         {
             if (pParts.Current == null)
             {
                 continue;
             }
             if (!pParts.Current.Modules.Contains("ModuleDataTransmitter") && !pParts.Current.Modules.Contains("ModuleRTAntenna"))
             {
                 continue;
             }
             ModAntenna pAntenna = new ModAntenna {
                 SPart = pParts.Current
             };
             List <PartModule> .Enumerator pModules = pParts.Current.Modules.GetEnumerator();
             while (pModules.MoveNext())
             {
                 if (pModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)pModules.Current;
                 if (pModule is ModuleDataTransmitter || pModule.moduleName == "ModuleRTAntenna")
                 {
                     pAntenna.XmitterModule = pModule;
                 }
                 if (pModule is ModuleDeployableAntenna ||
                     pModule is ModuleAnimateGeneric && (pModule.Events["Toggle"].guiName == "Extend" || pModule.Events["Toggle"].guiName == "Retract"))
                 {
                     pAntenna.AnimateModule = pModule;
                 }
             }
             pModules.Dispose();
             if (pAntenna.AnimateModule != null)
             {
                 _antennas.Add(pAntenna);
             }
         }
         pParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetAntennas().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 4
0
        internal List <Part> GetSelectedVesselsParts(List <ModDockedVessel> modDockedVessels, List <string> selectedResources)
        {
            List <Part> resourcePartList = new List <Part>();

            if (modDockedVessels == null || modDockedVessels.Count <= 0 || selectedResources == null ||
                selectedResources.Count <= 0)
            {
                return(resourcePartList);
            }
            try
            {
                List <ModDockedVessel> .Enumerator dVessels = modDockedVessels.GetEnumerator();
                while (dVessels.MoveNext())
                {
                    if (dVessels.Current == null)
                    {
                        continue;
                    }
                    List <Part> .Enumerator mdvParts = dVessels.Current.VesselParts.GetEnumerator();
                    while (mdvParts.MoveNext())
                    {
                        if (mdvParts.Current == null)
                        {
                            continue;
                        }
                        if (selectedResources.Count > 1 && mdvParts.Current.Resources.Contains(selectedResources[0]) && mdvParts.Current.Resources.Contains(selectedResources[1]))
                        {
                            resourcePartList.Add(mdvParts.Current);
                        }
                        else if (mdvParts.Current.Resources.Contains(selectedResources[0]))
                        {
                            resourcePartList.Add(mdvParts.Current);
                        }
                    }
                    mdvParts.Dispose();
                }
                dVessels.Dispose();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($"Error in GetSelectedVesselParts().\r\nError:  {ex}", SmUtils.LogType.Error, true);
                resourcePartList = new List <Part>();
            }
            return(resourcePartList);
        }
Ejemplo n.º 5
0
 internal void GetSolarPanels()
 {
     _solarPanels.Clear();
     try
     {
         List <Part> .Enumerator pParts = Vessel.Parts.GetEnumerator();
         while (pParts.MoveNext())
         {
             if (pParts.Current == null)
             {
                 continue;
             }
             List <PartModule> .Enumerator pModules = pParts.Current.Modules.GetEnumerator();
             while (pModules.MoveNext())
             {
                 if (pModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)pModules.Current;
                 if (pModule.moduleName != "ModuleDeployableSolarPanel")
                 {
                     continue;
                 }
                 ModuleDeployableSolarPanel iModule = (ModuleDeployableSolarPanel)pModule;
                 if (!iModule.Events["Extend"].active && !iModule.Events["Retract"].active)
                 {
                     continue;
                 }
                 ModSolarPanel pPanel = new ModSolarPanel
                 {
                     PanelModule = pModule,
                     SPart       = pParts.Current
                 };
                 _solarPanels.Add(pPanel);
             }
             pModules.Dispose();
         }
         pParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetSolarPanels().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 6
0
 internal void GetLights()
 {
     _lights.Clear();
     try
     {
         List <Part> .Enumerator pParts = Vessel.Parts.GetEnumerator();
         while (pParts.MoveNext())
         {
             if (pParts.Current == null)
             {
                 continue;
             }
             if (!pParts.Current.FindModulesImplementing <ModuleLight>().Any())
             {
                 continue;
             }
             List <PartModule> .Enumerator pModules = pParts.Current.Modules.GetEnumerator();
             while (pModules.MoveNext())
             {
                 if (pModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)pModules.Current;
                 if (pModule.moduleName != "ModuleLight")
                 {
                     continue;
                 }
                 ModLight pLight = new ModLight
                 {
                     LightModule = pModule,
                     SPart       = pParts.Current
                 };
                 _lights.Add(pLight);
             }
             pModules.Dispose();
         }
         pParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetLights().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 7
0
 internal static void FillCrew(Part part)
 {
     //Utilities.LogMessage(string.Format("Entering Fill Crew with part {0}", part.partInfo.name), Utilities.LogType.Info, true);
     if (IsCrewFull(part))
     {
         return;
     }
     while (part.CrewCapacity > SmUtils.GetPartCrewCount(part))
     {
         ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
         part.AddCrewmember(kerbal);
         //Utilities.LogMessage(string.Format("Filling crew in part {0}", part.partInfo.name), Utilities.LogType.Info, true);
         if (kerbal.seat != null)
         {
             kerbal.seat.SpawnCrew();
         }
     }
     SMAddon.FireEventTriggers();
 }
Ejemplo n.º 8
0
 internal void GetSolarPanels()
 {
     _solarPanels.Clear();
     try
     {
         List <Part> .Enumerator pParts = Vessel.Parts.GetEnumerator();
         while (pParts.MoveNext())
         {
             if (pParts.Current == null)
             {
                 continue;
             }
             List <ModuleDeployableSolarPanel> .Enumerator pModules = pParts.Current.FindModulesImplementing <ModuleDeployableSolarPanel>().GetEnumerator();
             while (pModules.MoveNext())
             {
                 ModuleDeployableSolarPanel solarPanel = pModules.Current;
                 if (solarPanel == null)
                 {
                     continue;
                 }
                 if (!solarPanel.Events["Extend"].active && !solarPanel.Events["Retract"].active)
                 {
                     continue;
                 }
                 ModSolarPanel pPanel = new ModSolarPanel
                 {
                     PanelModule = solarPanel,
                     SPart       = pParts.Current
                 };
                 _solarPanels.Add(pPanel);
             }
             pModules.Dispose();
         }
         pParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetSolarPanels().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 9
0
 internal void GetHatches()
 {
     _hatches.Clear();
     try
     {
         List <ICLSPart> .Enumerator hParts = SMAddon.ClsAddon.Vessel.Parts.GetEnumerator();
         while (hParts.MoveNext())
         {
             if (hParts.Current == null)
             {
                 continue;
             }
             IEnumerator hModules = hParts.Current.Part.Modules.GetEnumerator();
             while (hModules.MoveNext())
             {
                 if (hModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)hModules.Current;
                 if (pModule.moduleName != "ModuleDockingHatch")
                 {
                     continue;
                 }
                 ModHatch pHatch = new ModHatch
                 {
                     HatchModule = (PartModule)hModules.Current,
                     ClsPart     = hParts.Current
                 };
                 _hatches.Add(pHatch);
             }
         }
         hParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetHatches().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 10
0
 internal void GetLabs()
 {
     _labs.Clear();
     try
     {
         List <Part> .Enumerator pParts = Vessel.Parts.GetEnumerator();
         while (pParts.MoveNext())
         {
             if (pParts.Current == null)
             {
                 continue;
             }
             if (!pParts.Current.Modules.Contains("ModuleScienceLab"))
             {
                 continue;
             }
             IEnumerator pModules = pParts.Current.Modules.GetEnumerator();
             while (pModules.MoveNext())
             {
                 if (pModules.Current == null)
                 {
                     continue;
                 }
                 PartModule pModule = (PartModule)pModules.Current;
                 if (pModule.moduleName != "ModuleScienceLab")
                 {
                     continue;
                 }
                 _labs.Add((ModuleScienceLab)pModule);
             }
         }
         pParts.Dispose();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage($"Error in GetLabs().\r\nError:  {ex}", SmUtils.LogType.Error, true);
     }
 }
Ejemplo n.º 11
0
        internal List <Part> GetDockedVesselParts(DockedVesselInfo vesselInfo)
        {
            List <Part> vesselpartList = new List <Part>();

            try
            {
                if (vesselInfo != null)
                {
                    Part vesselRoot =
                        (from p in Vessel.parts where p.flightID == vesselInfo.rootPartUId select p).SingleOrDefault();
                    if (vesselRoot != null)
                    {
                        //vesselpartList = (from p in Vessel.parts where p.launchID == vesselRoot.launchID select p).ToList();
                        GetChildren(vesselRoot, ref vesselpartList);
                    }
                }
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($"Error in GetSelectedVesselParts().\r\nError:  {ex}", SmUtils.LogType.Error, true);
                vesselpartList = new List <Part>();
            }
            return(vesselpartList);
        }
Ejemplo n.º 12
0
        internal List <Part> GetVesselsPartsByResource(List <ModDockedVessel> modDockedVessels, List <string> selectedResources)
        {
            List <Part> resourcePartList = new List <Part>();

            if (modDockedVessels == null || modDockedVessels.Count <= 0 ||
                selectedResources == null || selectedResources.Count <= 0)
            {
                return(resourcePartList);
            }
            try
            {
                List <ModDockedVessel> .Enumerator dVessel = modDockedVessels.GetEnumerator();
                while (dVessel.MoveNext())
                {
                    if (dVessel.Current == null)
                    {
                        continue;
                    }
                    List <Part> .Enumerator mdvPart = dVessel.Current.VesselParts.GetEnumerator();
                    while (mdvPart.MoveNext())
                    {
                        if (mdvPart.Current == null)
                        {
                            continue;
                        }
                        if (selectedResources.Contains(SMConditions.ResourceType.Crew.ToString()))
                        {
                            if (mdvPart.Current.CrewCapacity > 0)
                            {
                                resourcePartList.Add(mdvPart.Current);
                            }
                        }
                        if (selectedResources.Contains(SMConditions.ResourceType.Science.ToString()))
                        {
                            if (mdvPart.Current.FindModulesImplementing <ModuleScienceExperiment>().Any() ||
                                mdvPart.Current.FindModulesImplementing <ModuleScienceContainer>().Any() ||
                                mdvPart.Current.FindModulesImplementing <ModuleScienceConverter>().Any() ||
                                mdvPart.Current.FindModulesImplementing <ModuleScienceLab>().Any())
                            {
                                resourcePartList.Add(mdvPart.Current);
                            }
                        }
                        else
                        {
                            // resources
                            if (selectedResources.Count > 1 && mdvPart.Current.Resources.Contains(selectedResources[0]) &&
                                mdvPart.Current.Resources.Contains(selectedResources[1]))
                            {
                                resourcePartList.Add(mdvPart.Current);
                            }
                            else if (mdvPart.Current.Resources.Contains(selectedResources[0]))
                            {
                                resourcePartList.Add(mdvPart.Current);
                            }
                        }
                    }
                    mdvPart.Dispose();
                }
                dVessel.Dispose();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($"Error in GetSelectedVesselParts().\r\nError:  {ex}", SmUtils.LogType.Error, true);
                resourcePartList = new List <Part>();
            }
            return(resourcePartList);
        }