Esempio n. 1
0
        private static void UpdateBuildRates()
        {
            if (!_ratesUpdated)
            {
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    if (ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.VehicleAssemblyBuilding) >= 0)
                    {
                        _ratesUpdated = true;
                        KCTDebug.Log("Updating build rates");
                        foreach (KSCItem KSC in KCTGameStates.KSCs)
                        {
                            KSC?.RecalculateBuildRates();
                            KSC?.RecalculateUpgradedBuildRates();
                        }

                        KCTDebug.Log("Rates updated");

                        foreach (SpaceCenterFacility facility in Enum.GetValues(typeof(SpaceCenterFacility)))
                        {
                            KCTGameStates.BuildingMaxLevelCache[facility.ToString()] = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facility);
                            KCTDebug.Log($"Cached {facility} max at {KCTGameStates.BuildingMaxLevelCache[facility.ToString()]}");
                        }
                    }
                }
                else
                {
                    _ratesUpdated = true;
                }
            }
        }
Esempio n. 2
0
        private IEnumerator UpdateBuildRates()
        {
            do
            {
                yield return(new WaitForFixedUpdate());    // No way to know when KSP has finally initialized the ScenarioUpgradeableFacilities data
            } while (HighLogic.LoadedScene == GameScenes.SPACECENTER && ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.VehicleAssemblyBuilding) < 0);

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER &&
                ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.VehicleAssemblyBuilding) >= 0)
            {
                KCTDebug.Log("Updating build rates");
                foreach (KSCItem KSC in KCTGameStates.KSCs)
                {
                    KSC?.RecalculateBuildRates();
                    KSC?.RecalculateUpgradedBuildRates();
                }

                KCTDebug.Log("Rates updated");

                foreach (SpaceCenterFacility facility in Enum.GetValues(typeof(SpaceCenterFacility)))
                {
                    KCTGameStates.BuildingMaxLevelCache[facility.ToString()] = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facility);
                    KCTDebug.Log($"Cached {facility} max at {KCTGameStates.BuildingMaxLevelCache[facility.ToString()]}");
                }
            }
        }
Esempio n. 3
0
        public void FixedUpdate()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            double lastUT = KCT_GameStates.UT > 0 ? KCT_GameStates.UT : Planetarium.GetUniversalTime();

            KCT_GameStates.UT = Planetarium.GetUniversalTime();
            try
            {
                // No need to set this true or false every single fixed upate
                // Actually not needed anymore not that the ToolbarController is handling it
#if false
                if (KCT_GUI.clicked && KCT_GameStates.toolbarControl != null)
                {
                    KCT_GameStates.toolbarControl.SetTrue(false);
                }
                else
                {
                    KCT_GameStates.toolbarControl.SetFalse(false);
                }
#endif
                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                {
                    return;
                }

                if (!KCT_GameStates.erroredDuringOnLoad.AlertFired && KCT_GameStates.erroredDuringOnLoad.HasErrored())
                {
                    KCT_GameStates.erroredDuringOnLoad.FireAlert();
                }

                if (KCT_GameStates.UpdateLaunchpadDestructionState)
                {
                    KCTDebug.Log("Updating launchpad destruction state.");
                    KCT_GameStates.UpdateLaunchpadDestructionState = false;
                    KCT_GameStates.ActiveKSC.ActiveLPInstance.SetDestructibleStateFromNode();
                    if (KCT_GameStates.ActiveKSC.ActiveLPInstance.upgradeRepair)
                    {
                        //repair everything, then update the node
                        KCT_GameStates.ActiveKSC.ActiveLPInstance.RefreshDestructionNode();
                        KCT_GameStates.ActiveKSC.ActiveLPInstance.CompletelyRepairNode();
                        KCT_GameStates.ActiveKSC.ActiveLPInstance.SetDestructibleStateFromNode();
                    }
                }

                if (!ratesUpdated)
                {
                    if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                    {
                        if (ScenarioUpgradeableFacilities.GetFacilityLevelCount(SpaceCenterFacility.VehicleAssemblyBuilding) >= 0)
                        {
                            ratesUpdated = true;
                            KCTDebug.Log("Updating build rates");
                            foreach (KCT_KSC KSC in KCT_GameStates.KSCs)
                            {
                                KSC?.RecalculateBuildRates();
                                KSC?.RecalculateUpgradedBuildRates();
                            }

                            KCTDebug.Log("Rates updated");

                            foreach (SpaceCenterFacility facility in Enum.GetValues(typeof(SpaceCenterFacility)))
                            {
                                KCT_GameStates.BuildingMaxLevelCache[facility.ToString()] = ScenarioUpgradeableFacilities.GetFacilityLevelCount(facility);
                                KCTDebug.Log("Cached " + facility.ToString() + " max at " + KCT_GameStates.BuildingMaxLevelCache[facility.ToString()]);
                            }
                        }
                    }
                    else
                    {
                        ratesUpdated = true;
                    }
                }

                if (KCT_GameStates.ActiveKSC?.ActiveLPInstance != null && HighLogic.LoadedScene == GameScenes.SPACECENTER && KCT_Utilities.CurrentGameIsCareer())
                {
                    if (lvlCheckTimer++ > 30)
                    {
                        lvlCheckTimer = 0;
                        if (KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad) != KCT_GameStates.ActiveKSC.ActiveLPInstance.level)
                        {
                            KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID, false);
                            KCT_GameStates.UpdateLaunchpadDestructionState = true;
                        }
                    }
                }
                //Warp code
                if (!KCT_GUI.PrimarilyDisabled && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION))
                {
                    IKCTBuildItem ikctItem = KCT_Utilities.NextThingToFinish();
                    if (KCT_GameStates.targetedItem == null && ikctItem != null)
                    {
                        KCT_GameStates.targetedItem = ikctItem;
                    }
                    double remaining = ikctItem != null?ikctItem.GetTimeLeft() : -1;

                    double dT = TimeWarp.CurrentRate / (KCT_GameStates.UT - lastUT);
                    if (dT >= 20)
                    {
                        dT = 0.1;
                    }
                    //KCTDebug.Log("dt: " + dT);
                    int nBuffers = 1;
                    if (KCT_GameStates.canWarp && ikctItem != null && !ikctItem.IsComplete())
                    {
                        int warpRate = TimeWarp.CurrentRateIndex;
                        if (warpRate < KCT_GameStates.lastWarpRate) //if something else changes the warp rate then release control to them, such as Kerbal Alarm Clock
                        {
                            KCT_GameStates.canWarp      = false;
                            KCT_GameStates.lastWarpRate = 0;
                        }
                        else
                        {
                            if (ikctItem == KCT_GameStates.targetedItem && warpRate > 0 && TimeWarp.fetch.warpRates[warpRate] * dT * nBuffers > Math.Max(remaining, 0))
                            {
                                int newRate = warpRate;
                                //find the first rate that is lower than the current rate
                                while (newRate > 0)
                                {
                                    if (TimeWarp.fetch.warpRates[newRate] * dT * nBuffers < remaining)
                                    {
                                        break;
                                    }
                                    newRate--;
                                }
                                KCTDebug.Log("Warping down to " + newRate + " (delta: " + (TimeWarp.fetch.warpRates[newRate] * dT) + ")");
                                TimeWarp.SetRate(newRate, true); //hopefully a faster warp down than before
                                warpRate = newRate;
                            }
                            else if (warpRate == 0 && KCT_GameStates.warpInitiated)
                            {
                                KCT_GameStates.canWarp       = false;
                                KCT_GameStates.warpInitiated = false;
                                KCT_GameStates.targetedItem  = null;
                            }
                            KCT_GameStates.lastWarpRate = warpRate;
                        }
                    }
                    else if (ikctItem != null && ikctItem == KCT_GameStates.targetedItem && (KCT_GameStates.warpInitiated || KCT_GameStates.settings.ForceStopWarp) && TimeWarp.CurrentRateIndex > 0 && (remaining < 1) && (!ikctItem.IsComplete())) //Still warp down even if we don't control the clock
                    {
                        TimeWarp.SetRate(0, true);
                        KCT_GameStates.warpInitiated = false;
                        KCT_GameStates.targetedItem  = null;
                    }
                }

                if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
                {
                    KCT_Utilities.SetActiveKSCToRSS();
                }

                if (!KCT_GUI.PrimarilyDisabled && HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    if (KSP.UI.Screens.VesselSpawnDialog.Instance != null && KSP.UI.Screens.VesselSpawnDialog.Instance.Visible)
                    {
                        KSP.UI.Screens.VesselSpawnDialog.Instance.ButtonClose();
                        KCTDebug.Log("Attempting to close spawn dialog!");
                    }
                }

                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.ProgressBuildTime();
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Esempio n. 4
0
        public static void DelayedStart()
        {
            //    KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Keys);
            //  KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Values.ElementAt(0).facilityRefs[0].name);


            /* if (!updateChecked)
             * {
             *   if (KCT_GameStates.settings.CheckForUpdates && !KCT_GameStates.firstStart) //Check for updates
             *       KCT_UpdateChecker.CheckForUpdate(false, KCT_GameStates.settings.VersionSpecific);
             *   updateChecked = true;
             * }*/

            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }

            List <GameScenes> validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER
            };

            if (validScenes.Contains(HighLogic.LoadedScene))
            {
                //Check for simulation save and load it.
                string backupFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs";
                if (System.IO.File.Exists(backupFile))
                {
                    KCT_GameStates.LoadingSimulationSave = true;

                    /*  if (!KCT_GameStates.LoadingSimulationSave)
                     *    KCT_Utilities.LoadSimulationSave();
                     * else
                     *    System.IO.File.Delete(backupFile);*/
                }
            }

            if (HighLogic.LoadedSceneIsFlight && KCT_GameStates.flightSimulated)
            {
                KCTDebug.Log("Simulation started");
                KCT_GUI.hideAll();
                KCT_GUI.showSimulationWindow = !KCT_GameStates.settings.NoSimGUI;
                KCT_GUI.showTimeRemaining    = true;
                if (!KCT_GameStates.simulationInitialized)
                {
                    Planetarium.SetUniversalTime(KCT_GameStates.simulationUT);
                    KCT_GameStates.simulationInitialized = true;
                }
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsToChargeAtSimEnd != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsToChargeAtSimEnd, TransactionReasons.None);
                KCT_GameStates.FundsToChargeAtSimEnd = 0;
            }
            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsGivenForVessel != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsGivenForVessel, TransactionReasons.VesselRollout);
                KCT_GameStates.FundsGivenForVessel = 0;
            }
            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated)
            {
                List <VesselType> invalidTypes = new List <VesselType> {
                    VesselType.Debris, VesselType.SpaceObject, VesselType.Unknown
                };
                if (!invalidTypes.Contains(FlightGlobals.ActiveVessel.vesselType) && !KCT_GameStates.BodiesVisited.Contains(FlightGlobals.ActiveVessel.mainBody.bodyName))
                {
                    KCT_GameStates.BodiesVisited.Add(FlightGlobals.ActiveVessel.mainBody.bodyName);
                    var message = new ScreenMessage("[KCT] New simulation body unlocked: " + FlightGlobals.ActiveVessel.mainBody.bodyName, 4.0f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage(message, true);
                    KCTDebug.Log("Unlocked sim body: " + FlightGlobals.ActiveVessel.mainBody.bodyName);
                }
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                return;
            }

            //The following should only be executed when fully enabled for the save

            //check that all parts are valid in all ships. If not, warn the user and disable that vessel (once that code is written)
            if (!KCT_GameStates.vesselErrorAlerted)
            {
                List <KCT_BuildListVessel> erroredVessels = new List <KCT_BuildListVessel>();
                foreach (KCT_KSC KSC in KCT_GameStates.KSCs) //this is faster one subsequent scene changes
                {
                    foreach (KCT_BuildListVessel blv in KSC.VABList)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.VABWarehouse)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.SPHList)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                    foreach (KCT_BuildListVessel blv in KSC.SPHWarehouse)
                    {
                        if (!blv.allPartsValid)
                        {
                            //error!
                            KCTDebug.Log(blv.shipName + " contains invalid parts!");
                            erroredVessels.Add(blv);
                        }
                    }
                }
                if (erroredVessels.Count > 0)
                {
                    PopUpVesselError(erroredVessels);
                }
                KCT_GameStates.vesselErrorAlerted = true;
            }

            foreach (KCT_KSC KSC in KCT_GameStates.KSCs)
            {
                KSC.RecalculateBuildRates();
                KSC.RecalculateUpgradedBuildRates();
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.buildSimulatedVessel)
            {
                KCT_GameStates.buildSimulatedVessel = false;
                KCT_BuildListVessel toBuild = KCT_GameStates.launchedVessel.NewCopy(false);
                toBuild.buildPoints = KCT_Utilities.GetBuildTime(toBuild.ExtractedPartNodes, true, KCT_GUI.useInventory);
                KCT_Utilities.AddVesselToBuildList(toBuild, KCT_GUI.useInventory);
            }

            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated)
            {
                KCT_GUI.hideAll();
                if (FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH && KCT_GameStates.launchedVessel != null)
                {
                    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_Utilities.GetTotalVesselCost(FlightGlobals.ActiveVessel.protoVessel), TransactionReasons.VesselRollout);
                        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);
                    }
                }
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (KCT_GameStates.EditorShipEditingMode)
                {
                    KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName);
                    EditorLogic.fetch.shipNameField.Text = KCT_GameStates.editedVessel.shipName;
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    if (KCT_GameStates.settings.OverrideLaunchButton)
                    {
                        KCTDebug.Log("Taking control of launch button");
                        EditorLogic.fetch.launchBtn.methodToInvoke           = "ShowLaunchAlert";
                        EditorLogic.fetch.launchBtn.scriptWithMethodToInvoke = KerbalConstructionTime.instance;
                    }
                    else
                    {
                        InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTLaunchLock");
                    }
                    KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    if (ToolbarManager.ToolbarAvailable && KCT_GameStates.settings.PreferBlizzyToolbar)
                    {
                        if (KCT_GameStates.showWindows[0])
                        {
                            KCT_GUI.ClickOn();
                        }
                        else
                        {
                            if (KCT_Events.instance != null && KCT_Events.instance.KCTButtonStock != null)
                            {
                                //KCT_Events.instance.KCTButtonStock.SetTrue(true);
                                //KCT_GUI.clicked = true;
                                if (KCT_GameStates.showWindows[0])
                                {
                                    KCT_GUI.ClickOn();
                                }
                            }

                            /*  else
                             * {
                             *    KCT_GUI.showEditorGUI = KCT_GameStates.showWindows[0];
                             * }*/
                        }
                    }
                    KCT_GUI.ResetBLWindow();
                }
                else
                {
                    KCT_GUI.showBuildList         = false;
                    KCT_GameStates.showWindows[0] = false;
                }
                if (KCT_GameStates.firstStart)
                {
                    KCTDebug.Log("Showing first start.");
                    KCT_GUI.showFirstRun = true;

                    //initialize the proper launchpad
                    KCT_GameStates.ActiveKSC.ActiveLPInstance.level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad);
                }
                KCT_GameStates.firstStart = false;
                if (KCT_GameStates.LaunchFromTS)
                {
                    KCT_GameStates.launchedVessel.Launch();
                }

                KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID);


                foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
                {
                    //foreach (KCT_Recon_Rollout rr in ksc.Recon_Rollout)
                    for (int i = 0; i < ksc.Recon_Rollout.Count; i++)
                    {
                        KCT_Recon_Rollout rr = ksc.Recon_Rollout[i];
                        if (rr.RRType != KCT_Recon_Rollout.RolloutReconType.Reconditioning && KCT_Utilities.FindBLVesselByID(new Guid(rr.associatedID)) == null)
                        {
                            KCTDebug.Log("Invalid Recon_Rollout at " + ksc.KSCName + ". ID " + rr.associatedID + " not found.");
                            ksc.Recon_Rollout.Remove(rr);
                            i--;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public static void DelayedStart()
        {
            //    KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Keys);
            //  KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Values.ElementAt(0).facilityRefs[0].name);


            if (!updateChecked)
            {
                if (KCT_GameStates.settings.CheckForUpdates && !KCT_GameStates.firstStart) //Check for updates
                {
                    KCT_UpdateChecker.CheckForUpdate(false, KCT_GameStates.settings.VersionSpecific);
                }
                updateChecked = true;
            }

            if (!KCT_GameStates.settings.enabledForSave)
            {
                return;
            }

            List <GameScenes> validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER
            };

            if (validScenes.Contains(HighLogic.LoadedScene))
            {
                //Check for simulation save and load it.
                string backupFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs";
                if (System.IO.File.Exists(backupFile))
                {
                    KCT_GameStates.LoadingSimulationSave = true;

                    /*  if (!KCT_GameStates.LoadingSimulationSave)
                     *    KCT_Utilities.LoadSimulationSave();
                     * else
                     *    System.IO.File.Delete(backupFile);*/
                }
            }

            if (HighLogic.LoadedSceneIsFlight && KCT_GameStates.flightSimulated)
            {
                KCTDebug.Log("Simulation started");
                KCT_GUI.hideAll();
                KCT_GUI.showSimulationWindow = !KCT_GameStates.settings.NoSimGUI;
                KCT_GUI.showTimeRemaining    = true;
                Planetarium.SetUniversalTime(KCT_GameStates.simulationUT);
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsToChargeAtSimEnd != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsToChargeAtSimEnd, TransactionReasons.None);
                KCT_GameStates.FundsToChargeAtSimEnd = 0;
            }
            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsGivenForVessel != 0)
            {
                KCT_Utilities.SpendFunds(KCT_GameStates.FundsGivenForVessel, TransactionReasons.VesselRollout);
                KCT_GameStates.FundsGivenForVessel = 0;
            }
            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated)
            {
                List <VesselType> invalidTypes = new List <VesselType> {
                    VesselType.Debris, VesselType.SpaceObject, VesselType.Unknown
                };
                if (!invalidTypes.Contains(FlightGlobals.ActiveVessel.vesselType) && !KCT_GameStates.BodiesVisited.Contains(FlightGlobals.ActiveVessel.mainBody.bodyName))
                {
                    KCT_GameStates.BodiesVisited.Add(FlightGlobals.ActiveVessel.mainBody.bodyName);
                    var message = new ScreenMessage("[KCT] New simulation body unlocked: " + FlightGlobals.ActiveVessel.mainBody.bodyName, 4.0f, ScreenMessageStyle.UPPER_LEFT);
                    ScreenMessages.PostScreenMessage(message, true);
                    KCTDebug.Log("Unlocked sim body: " + FlightGlobals.ActiveVessel.mainBody.bodyName);
                }
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                return;
            }

            //The following should only be executed when fully enabled for the save

            foreach (KCT_KSC KSC in KCT_GameStates.KSCs)
            {
                KSC.RecalculateBuildRates();
                KSC.RecalculateUpgradedBuildRates();
            }

            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.buildSimulatedVessel)
            {
                KCT_GameStates.buildSimulatedVessel = false;
                KCT_BuildListVessel toBuild = KCT_GameStates.launchedVessel.NewCopy(false);
                toBuild.buildPoints = KCT_Utilities.GetBuildTime(toBuild.ExtractedPartNodes, true, KCT_GUI.useInventory);
                KCT_Utilities.AddVesselToBuildList(toBuild, KCT_GUI.useInventory);
            }

            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated)
            {
                KCT_GUI.hideAll();
                if (FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH && KCT_GameStates.launchedVessel != null)
                {
                    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_Utilities.GetTotalVesselCost(FlightGlobals.ActiveVessel.protoVessel), TransactionReasons.VesselRollout);
                        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);
                    }
                }
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (KCT_GameStates.EditorShipEditingMode)
                {
                    KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName);
                    EditorLogic.fetch.shipNameField.Text = KCT_GameStates.editedVessel.shipName;
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    if (KCT_GameStates.settings.OverrideLaunchButton)
                    {
                        KCTDebug.Log("Taking control of launch button");
                        EditorLogic.fetch.launchBtn.methodToInvoke           = "ShowLaunchAlert";
                        EditorLogic.fetch.launchBtn.scriptWithMethodToInvoke = KerbalConstructionTime.instance;
                    }
                    else
                    {
                        InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTLaunchLock");
                    }
                    KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                if (KCT_Utilities.CurrentGameHasScience() && KCT_GameStates.TotalUpgradePoints == 0)
                {
                    ConfigNode CN = new ConfigNode();
                    ResearchAndDevelopment.Instance.snapshot.Save(CN);
                    ConfigNode[] techNodes = CN.GetNodes("Tech");
                    KCTDebug.Log("technodes length: " + techNodes.Length);
                    KCT_GameStates.TotalUpgradePoints = techNodes.Length + 14;
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showBuildList = KCT_GameStates.showWindows[0];
                    KCT_GUI.ResetBLWindow();
                }
                else
                {
                    KCT_GUI.showBuildList         = false;
                    KCT_GameStates.showWindows[0] = false;
                }
                if (KCT_GameStates.firstStart)
                {
                    KCTDebug.Log("Showing first start.");
                    KCT_GUI.showFirstRun = true;
                }
                KCT_GameStates.firstStart = false;
                if (KCT_GameStates.LaunchFromTS)
                {
                    KCT_GameStates.launchedVessel.Launch();
                }
            }
        }