コード例 #1
0
ファイル: KCT_LaunchPad.cs プロジェクト: ryanc55/RP-0
        public void SetActive()
        {
            try
            {
                KCTDebug.Log($"Switching to LaunchPad: {name} lvl: {level} destroyed? {IsDestroyed}");
                KCTGameStates.ActiveKSC.ActiveLaunchPadID = KCTGameStates.ActiveKSC.LaunchPads.IndexOf(this);

                //set the level to this level
                if (Utilities.CurrentGameIsCareer())
                {
                    foreach (Upgradeables.UpgradeableFacility facility in GetUpgradeableFacilityReferences())
                    {
                        KCTEvents.AllowedToUpgrade = true;
                        facility.SetLevel(level);
                    }
                }

                //set the destroyed state to this destroyed state
                UpdateLaunchpadDestructionState(false);
            }
            catch (Exception ex)
            {
                KCTDebug.LogError("Error while calling SetActive: " + ex);
            }
        }
コード例 #2
0
        private static Dictionary <Part, List <PartConfigValidationError> > GetConfigErrorsDict(BuildListVessel blv)
        {
            var dict = new Dictionary <Part, List <PartConfigValidationError> >();

            ShipConstruct sc = blv.GetShip();

            foreach (Part part in sc.parts)
            {
                foreach (PartModule pm in part.Modules)
                {
                    var types = new[] { typeof(string).MakeByRefType(), typeof(bool).MakeByRefType(), typeof(float).MakeByRefType() };
                    var mi    = pm.GetType().GetMethod("Validate", BindingFlags.Instance | BindingFlags.Public, null, types, null);
                    if (mi != null)
                    {
                        var  parameters = new object[] { null, null, null };
                        bool allSucceeded;
                        try
                        {
                            allSucceeded = (bool)mi.Invoke(pm, parameters);
                        }
                        catch (Exception ex)
                        {
                            KCTDebug.LogError($"Config validation failed for {part.name}");
                            Debug.LogException(ex);
                            allSucceeded  = false;
                            parameters[0] = "error occurred, check the logs";
                            parameters[1] = false;
                            parameters[2] = 0f;
                        }

                        if (!allSucceeded)
                        {
                            if (!dict.TryGetValue(part, out List <PartConfigValidationError> list))
                            {
                                list       = new List <PartConfigValidationError>(2);
                                dict[part] = list;
                            }

                            list.Add(new PartConfigValidationError
                            {
                                PM            = pm,
                                Error         = (string)parameters[0],
                                CanBeResolved = (bool)parameters[1],
                                CostToResolve = (float)parameters[2]
                            });
                        }
                    }
                }
            }

            return(dict);
        }
コード例 #3
0
        private static void AssignCrewToCurrentVessel()
        {
            if (!KCTGameStates.IsSimulatedFlight &&
                FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCTGameStates.LaunchedCrew.Count > 0)
            {
                KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;
                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                {
                    KCTDebug.Log($"Part being tested: {p.partInfo.title}");
                    if (p.CrewCapacity == 0 || !(KCTGameStates.LaunchedCrew.Find(part => part.PartID == p.craftID) is PartCrewAssignment cp))
                    {
                        continue;
                    }
                    List <CrewMemberAssignment> crewList = cp.CrewList;
                    KCTDebug.Log($"cP.crewList.Count: {cp.CrewList.Count}");
                    foreach (CrewMemberAssignment assign in crewList)
                    {
                        ProtoCrewMember crewMember = assign?.PCM;
                        if (crewMember == null)
                        {
                            continue;
                        }

                        // CrewRoster isn't reloaded from ConfigNode when starting flight. Can use the same instances as the previous scene.
                        try
                        {
                            if (crewMember is ProtoCrewMember && p.AddCrewmember(crewMember))
                            {
                                KCTDebug.Log($"Assigned {crewMember.name} to {p.partInfo.name}");
                                crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                crewMember.seat?.SpawnCrew();
                            }
                            else
                            {
                                KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}");
                                crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                            }
                        }
                        catch (Exception ex)
                        {
                            KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}: {ex}");
                            crewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                        }
                    }
                }
                KCTGameStates.LaunchedCrew.Clear();
            }
        }
コード例 #4
0
        private void AddSimulationWatermark()
        {
            if (!KCTGameStates.Settings.ShowSimWatermark)
            {
                return;
            }

            var uiController = KSP.UI.UIMasterController.Instance;

            if (uiController == null)
            {
                KCTDebug.LogError("UIMasterController.Instance is null");
                return;
            }

            _simWatermark = new GameObject();
            _simWatermark.transform.SetParent(uiController.mainCanvas.transform, false);
            _simWatermark.name = "sim-watermark";

            var c = Color.gray;

            c.a = 0.65f;
            var text = _simWatermark.AddComponent <Text>();

            text.text      = "Simulation";
            text.font      = UISkinManager.defaultSkin.font;
            text.fontSize  = (int)(40 * uiController.uiScale);
            text.color     = c;
            text.alignment = TextAnchor.MiddleCenter;

            var rectTransform = text.GetComponent <RectTransform>();

            rectTransform.localPosition = Vector3.zero;
            rectTransform.localScale    = Vector3.one;
            rectTransform.anchorMin     = rectTransform.anchorMax = new Vector2(0.5f, 0.85f);
            rectTransform.sizeDelta     = new Vector2(190 * uiController.uiScale, 50 * uiController.uiScale);

            if (DateTime.Today.Month == 4 && DateTime.Today.Day == 1)
            {
                text.text = "Activate Windows";
                rectTransform.anchorMin = rectTransform.anchorMax = new Vector2(0.8f, 0.2f);
                rectTransform.sizeDelta = new Vector2(300 * uiController.uiScale, 50 * uiController.uiScale);
            }
        }
コード例 #5
0
        private static void AddPartToInventory(string partName, ModuleInventoryPart inv)
        {
            AvailablePart ap      = PartLoader.getPartInfoByName(partName);
            var           pp      = new ProtoPartSnapshot(ap.partPrefab, null);
            int           slotIdx = inv.FirstEmptySlot();

            if (slotIdx < 0)
            {
                KCTDebug.LogError($"Part {inv.part.name} does not have inventory space to add {partName}");
                return;
            }

            StoredPart storedPart = new StoredPart(partName, slotIdx)
            {
                snapshot      = pp,
                variantName   = pp.moduleVariantName,
                quantity      = 1,
                stackCapacity = pp.moduleCargoStackableQuantity
            };

            inv.storedParts.Add(storedPart.slotIndex, storedPart);
        }
コード例 #6
0
        public void Start()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Start called");

            // Subscribe to events from KSP and other mods
            if (!KCT_Events.instance.subscribedToEvents)
            {
                KCT_Events.instance.SubscribeToEvents();
            }

            KCT_GameStates.settings.Save(); //Save the settings file, with defaults if it doesn't exist
            KCT_PresetManager.Instance.SaveActiveToSaveData();

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);

                KCT_GUI.buildRateForDisplay = null;
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                if (InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
                {
                    InputLockManager.RemoveControlLock("KCTLaunchLock");
                }
            }

            KACWrapper.InitKACWrapper();

            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCT_GameStates.UT = Planetarium.GetUniversalTime();

            KCT_GUI.guiDataSaver.Load();

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:

                //if (HighLogic.LoadedSceneIsEditor)
            {
                KCT_GUI.hideAll();
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showEditorGUI = KCT_GameStates.showWindows[1];
                    if (KCT_GUI.showEditorGUI)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
            }
            break;

            case GameScenes.SPACECENTER:
                //else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                bool shouldStart = KCT_GUI.showFirstRun;
                KCT_GUI.hideAll();
                if (!shouldStart)
                {
                    KCT_GUI.showBuildList = KCT_GameStates.showWindows[0];
                    if (KCT_GUI.showBuildList)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
                KCT_GUI.showFirstRun = shouldStart;
            }
            break;

            case GameScenes.FLIGHT:
                if (/*HighLogic.LoadedSceneIsFlight && */ FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH &&
                    FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCT_GameStates.launchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        //KCTDebug.Log("craft: " + p.craftID);
                        KCTDebug.LogError("Part being tested: " + p.partInfo.title);
                        {
                            CrewedPart cP = KCT_GameStates.launchedCrew.Find(part => part.partID == p.craftID);
                            if (cP == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cP.crewList;
                            KCTDebug.LogError("cP.crewList.Count: " + cP.crewList.Count);
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name + ". Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log("Assigning " + finalCrewMember.name + " to " + p.partInfo.name);
                                        if (p.AddCrewmember(finalCrewMember))    //p.AddCrewmemberAt(finalCrewMember, crewList.IndexOf(crewMember)))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCT_GameStates.launchedCrew.Clear();
                }
                //if (HighLogic.LoadedSceneIsFlight)
                {
                    KCT_GUI.hideAll();
                    if (KCT_GameStates.launchedVessel != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                    {
                        KCT_GameStates.launchedVessel.KSC = null;     //it's invalid now
                        KCTDebug.Log("Attempting to remove launched vessel from build list");
                        bool removed = KCT_GameStates.launchedVessel.RemoveFromBuildList();
                        if (removed)     //Only do these when the vessel is first removed from the list
                        {
                            //Add the cost of the ship to the funds so it can be removed again by KSP
                            KCT_Utilities.AddFunds(KCT_GameStates.launchedVessel.cost, TransactionReasons.VesselRollout);
                            FlightGlobals.ActiveVessel.vesselName = KCT_GameStates.launchedVessel.shipName;
                        }

                        KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (rollout != null)
                        {
                            KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                        }

                        KCT_AirlaunchPrep alPrep = KCT_GameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (alPrep != null)
                        {
                            KCT_GameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                        }

                        AirlaunchParams alParams = KCT_GameStates.AirlaunchParams;
                        if (alParams != null && alParams.KCTVesselId == KCT_GameStates.launchedVessel.id &&
                            (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                        {
                            if (!alParams.KSPVesselId.HasValue)
                            {
                                alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                            }
                            StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                        }
                    }
                }
                break;
            }

            ratesUpdated = false;
            KCTDebug.Log("Start finished");

            wfsOne  = new WaitForSeconds(1f);
            wfsTwo  = new WaitForSeconds(2f);
            wfsHalf = new WaitForSeconds(0.5f);

            DelayedStart();

            UpdateTechlistIconColor();
            StartCoroutine(HandleEditorButton_Coroutine());
        }
コード例 #7
0
        public void Start()
        {
            KCTDebug.Log("Start called");
            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            // Subscribe to events from KSP and other mods
            if (!KCTEvents.Instance.SubscribedToEvents)
            {
                KCTEvents.Instance.SubscribeToEvents();
            }

            if (KCTGameStates.IsFirstStart)
            {
                PresetManager.Instance.SaveActiveToSaveData();
            }

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);

                KCT_GUI.BuildRateForDisplay = null;
                if (!KCT_GUI.IsPrimarilyDisabled)
                {
                    Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }

            if (KCT_GUI.IsPrimarilyDisabled &&
                InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
            {
                InputLockManager.RemoveControlLock("KCTLaunchLock");
            }

            KACWrapper.InitKACWrapper();

            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCTGameStates.UT = Utilities.GetUT();

            KCT_GUI.GuiDataSaver.Load();
            KCT_GUI.GUIStates.HideAllNonMainWindows();

            if (!HighLogic.LoadedSceneIsFlight)
            {
                bool b = KCTGameStates.SimulationParams.BuildSimulatedVessel;
                KCTGameStates.SimulationParams.Reset();
                if (b && KCTGameStates.LaunchedVessel != null)
                {
                    Utilities.AddVesselToBuildList(KCTGameStates.LaunchedVessel);
                }
            }

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:
                KCT_GUI.HideAll();
                if (!KCT_GUI.IsPrimarilyDisabled)
                {
                    KCT_GUI.GUIStates.ShowEditorGUI = KCTGameStates.ShowWindows[1];
                    if (KCTGameStates.EditorShipEditingMode)
                    {
                        KCT_GUI.EnsureEditModeIsVisible();
                    }
                    else if (KCT_GUI.GUIStates.ShowEditorGUI)
                    {
                        KCT_GUI.ToggleVisibility(true);
                    }
                    else
                    {
                        KCT_GUI.ToggleVisibility(false);
                    }
                }
                break;

            case GameScenes.SPACECENTER:
                bool shouldStart = KCT_GUI.GUIStates.ShowFirstRun;
                KCT_GUI.HideAll();
                KCTGameStates.ClearVesselEditMode();
                if (!shouldStart)
                {
                    KCT_GUI.GUIStates.ShowBuildList = KCTGameStates.ShowWindows[0];
                    if (KCT_GUI.GUIStates.ShowBuildList)
                    {
                        KCT_GUI.ToggleVisibility(true);
                    }
                    else
                    {
                        KCT_GUI.ToggleVisibility(false);
                    }
                }
                KCT_GUI.GUIStates.ShowFirstRun = shouldStart;
                break;

            case GameScenes.TRACKSTATION:
                KCTGameStates.ClearVesselEditMode();
                break;

            case GameScenes.FLIGHT:
                if (!KCTGameStates.IsSimulatedFlight &&
                    FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH &&
                    FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCTGameStates.LaunchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        KCTDebug.Log("Part being tested: " + p.partInfo.title);
                        {
                            CrewedPart cp = KCTGameStates.LaunchedCrew.Find(part => part.PartID == p.craftID);
                            if (cp == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cp.CrewList;
                            KCTDebug.Log("cP.crewList.Count: " + cp.CrewList.Count);
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}. Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log($"Assigning {finalCrewMember.name } to {p.partInfo.name}");
                                        if (p.AddCrewmember(finalCrewMember))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}");
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}: {ex}");
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCTGameStates.LaunchedCrew.Clear();
                }

                KCT_GUI.HideAll();
                if (!KCTGameStates.IsSimulatedFlight && KCTGameStates.LaunchedVessel != null && FlightGlobals.ActiveVessel?.situation == Vessel.Situations.PRELAUNCH)
                {
                    KCTGameStates.LaunchedVessel.KSC = null;     //it's invalid now
                    KCTDebug.Log("Attempting to remove launched vessel from build list");
                    bool removed = KCTGameStates.LaunchedVessel.RemoveFromBuildList();
                    if (removed)     //Only do these when the vessel is first removed from the list
                    {
                        //Add the cost of the ship to the funds so it can be removed again by KSP
                        Utilities.AddFunds(KCTGameStates.LaunchedVessel.Cost, TransactionReasons.VesselRollout);
                        FlightGlobals.ActiveVessel.vesselName = KCTGameStates.LaunchedVessel.ShipName;
                    }

                    ReconRollout rollout = KCTGameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString());
                    if (rollout != null)
                    {
                        KCTGameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                    }

                    AirlaunchPrep alPrep = KCTGameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString());
                    if (alPrep != null)
                    {
                        KCTGameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                    }

                    AirlaunchParams alParams = KCTGameStates.AirlaunchParams;
                    if (alParams != null && alParams.KCTVesselId == KCTGameStates.LaunchedVessel.Id &&
                        (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                    {
                        if (!alParams.KSPVesselId.HasValue)
                        {
                            alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                        }
                        StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                    }
                }
                break;
            }

            _ratesUpdated = false;
            KCTDebug.Log("Start finished");

            _wfsOne  = new WaitForSeconds(1f);
            _wfsTwo  = new WaitForSeconds(2f);
            _wfsHalf = new WaitForSeconds(0.5f);

            DelayedStart();

            UpdateTechlistIconColor();
            StartCoroutine(HandleEditorButton_Coroutine());
        }
コード例 #8
0
        private void ProcessFlightStart()
        {
            if (FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH)
            {
                return;
            }

            var dataModule = (KCTVesselTracker)FlightGlobals.ActiveVessel.vesselModules.Find(vm => vm is KCTVesselTracker);

            if (dataModule != null)
            {
                if (string.IsNullOrWhiteSpace(dataModule.Data.LaunchID))
                {
                    dataModule.Data.LaunchID = Guid.NewGuid().ToString("N");
                    KCTDebug.Log($"Assigned LaunchID: {dataModule.Data.LaunchID}");
                }

                if (KCTGameStates.LaunchedVessel != null)
                {
                    dataModule.Data.FacilityBuiltIn = KCTGameStates.LaunchedVessel.FacilityBuiltIn;
                    dataModule.Data.VesselID        = KCTGameStates.LaunchedVessel.KCTPersistentID;
                }
            }

            if (KCT_GUI.IsPrimarilyDisabled)
            {
                return;
            }

            if (!KCTGameStates.IsSimulatedFlight &&
                FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCTGameStates.LaunchedCrew.Count > 0)
            {
                KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;
                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                {
                    KCTDebug.Log("Part being tested: " + p.partInfo.title);
                    if (!(KCTGameStates.LaunchedCrew.Find(part => part.PartID == p.craftID) is CrewedPart cp))
                    {
                        continue;
                    }
                    List <ProtoCrewMember> crewList = cp.CrewList;
                    KCTDebug.Log("cP.crewList.Count: " + cp.CrewList.Count);
                    foreach (ProtoCrewMember crewMember in crewList)
                    {
                        if (crewMember != null)     // Can this list can have null ProtoCrewMembers?
                        {
                            ProtoCrewMember finalCrewMember = crewMember;
                            if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                            {
                                finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                            }
                            else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                            {
                                finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                            }
                            try
                            {
                                if (finalCrewMember is ProtoCrewMember && p.AddCrewmember(finalCrewMember))
                                {
                                    KCTDebug.Log($"Assigned {finalCrewMember.name } to {p.partInfo.name}");
                                    finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                    finalCrewMember.seat?.SpawnCrew();
                                }
                                else
                                {
                                    KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}");
                                    finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                }
                            }
                            catch (Exception ex)
                            {
                                KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}: {ex}");
                                finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                            }
                        }
                    }
                }
                KCTGameStates.LaunchedCrew.Clear();
            }

            if (KCTGameStates.LaunchedVessel != null && !KCTGameStates.IsSimulatedFlight)
            {
                KCTGameStates.LaunchedVessel.KSC = null;                //it's invalid now
                KCTDebug.Log("Attempting to remove launched vessel from build list");
                if (KCTGameStates.LaunchedVessel.RemoveFromBuildList()) //Only do these when the vessel is first removed from the list
                {
                    //Add the cost of the ship to the funds so it can be removed again by KSP
                    Utilities.AddFunds(KCTGameStates.LaunchedVessel.Cost, TransactionReasons.VesselRollout);
                    FlightGlobals.ActiveVessel.vesselName = KCTGameStates.LaunchedVessel.ShipName;
                }

                if (KCTGameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString()) is ReconRollout rollout)
                {
                    KCTGameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                }

                if (KCTGameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString()) is AirlaunchPrep alPrep)
                {
                    KCTGameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                }

                if (KCTGameStates.AirlaunchParams is AirlaunchParams alParams && alParams.KCTVesselId == KCTGameStates.LaunchedVessel.Id &&
                    (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                {
                    if (!alParams.KSPVesselId.HasValue)
                    {
                        alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                    }
                    StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                }
            }
        }