示例#1
0
        public static void RampUpWarp()
        {
            //KCT_BuildListVessel ship = KCT_Utilities.NextShipToFinish();
            IKCTBuildItem ship = KCT_Utilities.NextThingToFinish();

            RampUpWarp(ship);
        }
示例#2
0
文件: GameStates.cs 项目: ntwest/KCT
        public static void reset()
        {
            const string logBlockName = nameof(GameStates) + "." + nameof(reset);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                firstStart         = false;
                vesselErrorAlerted = false;

                PurchasedUpgrades = new List <int>()
                {
                    0, 0
                };
                targetedItem = null;
                KCT_GUI.ResetFormulaRateHolders();

                InventorySaleUpgrades = 0;
                InventorySalesFigures = 0;

                ExperimentalParts.Clear();
                MiscellaneousTempUpgrades = 0;

                BuildingMaxLevelCache.Clear();

                lastUT = 0;
            }
        }
示例#3
0
        public static void Create(IKCTBuildItem warpTarget)
        {
            if (go is GameObject)
            {
                go.DestroyGameObject();
            }
            go = new GameObject("KCTWarpController");
            var controller = go.AddComponent <KCTWarpController>();

            controller.target = warpTarget;
            Debug.Log($"{ModTag} Created for warp target {warpTarget.GetItemName()}");
        }
示例#4
0
        public void Start()
        {
            lastUT = Planetarium.GetUniversalTime();
            if (target == null)
            {
                target = Utilities.GetNextThingToFinish();
            }

            // These KCTGameStates fields should fade out.
            desiredWarpRate = RampUpWarp(target);
            warping         = true;
        }
示例#5
0
        public static void RampUpWarp(IKCTBuildItem item)
        {
            int    lastRateIndex = TimeWarp.CurrentRateIndex;
            int    newRate       = TimeWarp.CurrentRateIndex + 1;
            double timeLeft      = item.GetTimeLeft();

            if (double.IsPositiveInfinity(timeLeft))
            {
                timeLeft = KCT_Utilities.NextThingToFinish().GetTimeLeft();
            }
            while ((timeLeft > 15 * TimeWarp.deltaTime) && (TimeWarp.CurrentRateIndex < KCT_GameStates.settings.MaxTimeWarp) && (lastRateIndex < newRate))
            {
                lastRateIndex = TimeWarp.CurrentRateIndex;
                TimeWarp.SetRate(lastRateIndex + 1, true);
                newRate = TimeWarp.CurrentRateIndex;
            }
        }
示例#6
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker           = new Dictionary <string, int>();
            PartInventory         = new Dictionary <string, int>();
            flightSimulated       = false;
            simulationInitialized = false;
            vesselDict            = new Dictionary <string, string>();
            BodiesVisited         = new List <string> {
                Planetarium.fetch.Home.name
            };
            simulationBody     = KCT_Utilities.GetBodyByName(BodiesVisited[0]);
            simulateInOrbit    = false;
            firstStart         = false;
            vesselErrorAlerted = false;

            /*  VABUpgrades = new List<int>() {0};
            *  SPHUpgrades = new List<int>() {0};
            *  RDUpgrades = new List<int>() {0, 0};*/
            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            // LaunchPadReconditioning = null;
            targetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            InventorySaleUpgrades = 0;
            InventorySalesFigures = 0;

            ExperimentalParts.Clear();
            MiscellaneousTempUpgrades = 0;


            lastUT = 0;
            //ActiveKSC = new KCT_KSC("Stock");
            //KSCs = new List<KCT_KSC>() {ActiveKSC};


            /* VABList = new List<KCT_BuildListVessel>();
             * VABWarehouse = new List<KCT_BuildListVessel>();
             * SPHList = new List<KCT_BuildListVessel>();
             * SPHWarehouse = new List<KCT_BuildListVessel>();
             * TechList = new List<KCT_TechItem>();*/
        }
示例#7
0
        private int RampUpWarp(IKCTBuildItem item)
        {
            int    newRate  = TimeWarp.CurrentRateIndex;
            double timeLeft = item.GetTimeLeft();

            if (double.IsPositiveInfinity(timeLeft))
            {
                timeLeft = Utilities.GetNextThingToFinish().GetTimeLeft();
            }
            while ((newRate + 1 < TimeWarp.fetch.warpRates.Length) &&
                   (timeLeft > TimeWarp.fetch.warpRates[newRate + 1] * Planetarium.fetch.fixedDeltaTime) &&
                   (newRate < KCTGameStates.Settings.MaxTimeWarp))
            {
                newRate++;
            }
            TimeWarp.SetRate(newRate, true);
            return(newRate);
        }
示例#8
0
        public static IKCTBuildItem NextThingToFinish()
        {
            IKCTBuildItem thing        = null;
            double        shortestTime = double.PositiveInfinity;

            foreach (IKCTBuildItem blv in KCT_GameStates.VABList)
            {
                double time = blv.GetTimeLeft();
                if (time < shortestTime)
                {
                    thing        = blv;
                    shortestTime = time;
                }
            }
            foreach (IKCTBuildItem blv in KCT_GameStates.SPHList)
            {
                double time = blv.GetTimeLeft();
                if (time < shortestTime)
                {
                    thing        = blv;
                    shortestTime = time;
                }
            }
            foreach (IKCTBuildItem blv in KCT_GameStates.TechList)
            {
                double time = blv.GetTimeLeft();
                if (time < shortestTime)
                {
                    thing        = blv;
                    shortestTime = time;
                }
            }
            if (KCT_GameStates.LaunchPadReconditioning != null)
            {
                IKCTBuildItem blv  = (IKCTBuildItem)KCT_GameStates.LaunchPadReconditioning;
                double        time = blv.GetTimeLeft();
                if (time < shortestTime)
                {
                    thing        = blv;
                    shortestTime = time;
                }
            }
            return(thing);
        }
示例#9
0
        public static void Reset()
        {
            IsFirstStart       = false;
            VesselErrorAlerted = false;

            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            TargetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            MiscellaneousTempUpgrades = 0;

            BuildingMaxLevelCache.Clear();

            LastUT = 0;

            InitAndClearTechList();
        }
示例#10
0
        public static void reset()
        {
            firstStart         = false;
            vesselErrorAlerted = false;

            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            targetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            InventorySaleUpgrades = 0;
            InventorySalesFigures = 0;

            ExperimentalParts.Clear();
            MiscellaneousTempUpgrades = 0;

            BuildingMaxLevelCache.Clear();

            lastUT = 0;
        }
示例#11
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker     = new Dictionary <string, int>();
            PartInventory   = new Dictionary <string, int>();
            flightSimulated = false;
            vesselDict      = new Dictionary <string, string>();
            simulationBody  = KCT_Utilities.GetBodyByName("Kerbin");
            simulateInOrbit = false;
            BodiesVisited   = new List <string> {
                "Kerbin"
            };
            TotalUpgradePoints = 0;

            /*  VABUpgrades = new List<int>() {0};
            *  SPHUpgrades = new List<int>() {0};
            *  RDUpgrades = new List<int>() {0, 0};*/
            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            // LaunchPadReconditioning = null;
            targetedItem           = null;
            KCT_GUI.fundsCost      = -13;
            KCT_GUI.sciCost        = -13;
            KCT_GUI.nodeRate       = -13;
            KCT_GUI.upNodeRate     = -13;
            KCT_GUI.researchRate   = -13;
            KCT_GUI.upResearchRate = -13;
            //ActiveKSC = new KCT_KSC("Stock");
            //KSCs = new List<KCT_KSC>() {ActiveKSC};


            /* VABList = new List<KCT_BuildListVessel>();
             * VABWarehouse = new List<KCT_BuildListVessel>();
             * SPHList = new List<KCT_BuildListVessel>();
             * SPHWarehouse = new List<KCT_BuildListVessel>();
             * TechList = new List<KCT_TechItem>();*/
        }
示例#12
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker     = new Dictionary <string, int>();
            PartInventory   = new Dictionary <string, int>();
            flightSimulated = false;
            vesselDict      = new Dictionary <string, string>();
            simulationBody  = KCT_Utilities.GetBodyByName("Kerbin");
            simulateInOrbit = false;
            BodiesVisited   = new List <string> {
                "Kerbin"
            };
            TotalUpgradePoints = 0;
            VABUpgrades        = new List <int>()
            {
                0
            };
            SPHUpgrades = new List <int>()
            {
                0
            };
            RDUpgrades = new List <int>()
            {
                0, 0
            };
            PurchasedUpgrades = new List <int>()
            {
                0, 0
            };
            LaunchPadReconditioning = null;
            targetedItem            = null;

            VABList      = new List <KCT_BuildListVessel>();
            VABWarehouse = new List <KCT_BuildListVessel>();
            SPHList      = new List <KCT_BuildListVessel>();
            SPHWarehouse = new List <KCT_BuildListVessel>();
            TechList     = new List <KCT_TechItem>();
        }
示例#13
0
 public static void RampUpWarp(IKCTBuildItem item)
 {
     int newRate = TimeWarp.CurrentRateIndex;
     double timeLeft = item.GetTimeLeft();
     if (double.IsPositiveInfinity(timeLeft))
         timeLeft = KCT_Utilities.NextThingToFinish().GetTimeLeft();
     while ((newRate + 1 < TimeWarp.fetch.warpRates.Length) && (timeLeft > TimeWarp.fetch.warpRates[newRate + 1]*Planetarium.fetch.fixedDeltaTime) && (newRate < KCT_GameStates.settings.MaxTimeWarp))
     {
         newRate++;
     }
     TimeWarp.SetRate(newRate, true);
       //  Debug.Log("Fixed Delta Time: " + Planetarium.fetch.fixedDeltaTime);
 }
示例#14
0
        public static void ProgressBuildTime()
        {
            UT = Planetarium.GetUniversalTime();
            double UTDiff = UT - lastUT;

            if (UTDiff > 0 && UTDiff < (TimeWarp.fetch.warpRates[TimeWarp.fetch.warpRates.Length - 1] * 2) && lastUT > 0)
            {
                double buildRate = 0;
                if (KCT_GameStates.VABList.Count > 0)
                {
                    for (int i = 0; i < KCT_GameStates.VABList.Count; i++)
                    {
                        buildRate = GetBuildRate(i, KCT_BuildListVessel.ListType.VAB);
                        KCT_GameStates.VABList[i].AddProgress(buildRate * (UT - lastUT));
                        if (((IKCTBuildItem)KCT_GameStates.VABList[i]).IsComplete())
                        {
                            MoveVesselToWarehouse(0, i);
                        }
                    }
                }
                if (KCT_GameStates.SPHList.Count > 0)
                {
                    for (int i = 0; i < KCT_GameStates.SPHList.Count; i++)
                    {
                        buildRate = GetBuildRate(i, KCT_BuildListVessel.ListType.SPH);
                        KCT_GameStates.SPHList[i].AddProgress(buildRate * (UT - lastUT));
                        if (((IKCTBuildItem)KCT_GameStates.SPHList[i]).IsComplete())
                        {
                            MoveVesselToWarehouse(1, i);
                        }
                    }
                }

                for (int i = 0; i < KCT_GameStates.TechList.Count; i++)
                {
                    KCT_TechItem tech = KCT_GameStates.TechList[i];
                    buildRate      = tech.BuildRate;
                    tech.progress += (buildRate * (UT - lastUT));
                    if (tech.isComplete || KCT_GameStates.settings.InstantTechUnlock)
                    {
                        if (KCT_GameStates.settings.ForceStopWarp && TimeWarp.CurrentRate > 1f)
                        {
                            TimeWarp.SetRate(0, true);
                        }
                        if (tech.protoNode == null)
                        {
                            continue;
                        }
                        tech.EnableTech();
                        KCT_GameStates.TechList.Remove(tech);
                    }
                }

                if (KCT_GameStates.LaunchPadReconditioning != null)
                {
                    IKCTBuildItem item = (IKCTBuildItem)KCT_GameStates.LaunchPadReconditioning;
                    KCT_GameStates.LaunchPadReconditioning.progress += (item.GetBuildRate() * (UT - lastUT));
                    if (item.IsComplete() || !KCT_GameStates.settings.Reconditioning)
                    {
                        KCT_GameStates.LaunchPadReconditioning = null;
                    }
                }
            }
            lastUT = UT;
        }
示例#15
0
        private static void ProcessWarp(double lastUT)
        {
            Profiler.BeginSample("KCT ProcessWarp");
            IKCTBuildItem iKctItem = Utilities.GetNextThingToFinish();

            if (KCTGameStates.TargetedItem == null && iKctItem != null)
            {
                KCTGameStates.TargetedItem = iKctItem;
            }
            double remaining = iKctItem != null?iKctItem.GetTimeLeft() : -1;

            double dT = TimeWarp.CurrentRate / (KCTGameStates.UT - lastUT);

            if (dT >= 20)
            {
                dT = 0.1;
            }
            int nBuffers = 1;

            if (KCTGameStates.CanWarp && iKctItem != null && !iKctItem.IsComplete())
            {
                int warpRate = TimeWarp.CurrentRateIndex;
                if (warpRate < KCTGameStates.LastWarpRate) //if something else changes the warp rate then release control to them, such as Kerbal Alarm Clock
                {
                    KCTGameStates.CanWarp      = false;
                    KCTGameStates.LastWarpRate = 0;
                }
                else
                {
                    if (iKctItem == KCTGameStates.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 && KCTGameStates.WarpInitiated)
                    {
                        KCTGameStates.CanWarp       = false;
                        KCTGameStates.WarpInitiated = false;
                        KCTGameStates.TargetedItem  = null;
                    }
                    KCTGameStates.LastWarpRate = warpRate;
                }
            }
            else if (iKctItem != null && iKctItem == KCTGameStates.TargetedItem &&
                     (KCTGameStates.WarpInitiated || KCTGameStates.Settings.ForceStopWarp) &&
                     TimeWarp.CurrentRateIndex > 0 && (remaining < 1) && (!iKctItem.IsComplete())) //Still warp down even if we don't control the clock
            {
                TimeWarp.SetRate(0, true);
                KCTGameStates.WarpInitiated = false;
                KCTGameStates.TargetedItem  = null;
            }
            Profiler.EndSample();
        }
示例#16
0
        public void FixedUpdate()
        {
            #if DEBUG
            if (!updateChecked && KCT_GameStates.settings.CheckForDebugUpdates && !KCT_GameStates.firstStart)
            {
                KCT_UpdateChecker.CheckForUpdate(false, false);
                updateChecked = true;
            }
            #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.LoadingSimulationSave)
            {
                KCT_Utilities.LoadSimulationSave(true);
            }

            if (KCT_GameStates.UpdateLaunchpadDestructionState)
            {
                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();
                }
            }
            double lastUT = KCT_GameStates.UT > 0 ? KCT_GameStates.UT : Planetarium.GetUniversalTime();
            KCT_GameStates.UT = Planetarium.GetUniversalTime();
            try
            {
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER && KCT_Utilities.CurrentGameIsCareer() && KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad) != KCT_GameStates.ActiveKSC.ActiveLPInstance.level)
                {
                    failedLvlChecks++;
                    if (failedLvlChecks > 10)
                    {
                        KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID, false);
                        KCT_GameStates.UpdateLaunchpadDestructionState = true;
                        failedLvlChecks = 0;
                    }
                }
                //Warp code
                if (!KCT_GUI.PrimarilyDisabled && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION && !KCT_GameStates.flightSimulated))
                {
                    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 (SOIAlert())
                        {
                            TimeWarp.SetRate(0, true);
                            KCT_GameStates.canWarp       = false;
                            KCT_GameStates.warpInitiated = false;
                        }
                        else 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))
                            {
                                //double timeDelta = TimeWarp.CurrentRate * dT * nBuffers - ikctItem.GetTimeLeft();
                                //   KCTDebug.Log("Current delta: " + (TimeWarp.fetch.warpRates[warpRate] * dT) + " Remaining: " + remaining);
                                //KCTDebug.Log("dt: " + dT);
                                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.FLIGHT && KCT_GameStates.flightSimulated) //Simulated flights
                {
                    if (FlightGlobals.ActiveVessel.loaded && !FlightGlobals.ActiveVessel.packed && !moved)
                    {
                        //moved = true;
                        int secondsForMove = KCT_GameStates.DelayMoveSeconds;
                        if (KCT_GameStates.simulateInOrbit && loadDeferTime == DateTime.MaxValue)
                        {
                            loadDeferTime = DateTime.Now;
                        }
                        else if (KCT_GameStates.simulateInOrbit && (DateTime.Now.CompareTo(loadDeferTime.AddSeconds(secondsForMove)) > 0))
                        {
                            KCTDebug.Log("Moving vessel to orbit. " + KCT_GameStates.simulationBody.bodyName + ":" + KCT_GameStates.simOrbitAltitude + ":" + KCT_GameStates.simInclination);
                            KCT_OrbitAdjuster.PutInOrbitAround(KCT_GameStates.simulationBody, KCT_GameStates.simOrbitAltitude, KCT_GameStates.simInclination);
                            moved         = true;
                            loadDeferTime = DateTime.MaxValue;
                        }
                        else if (!KCT_GameStates.simulateInOrbit)
                        {
                            moved = true;
                        }

                        if (KCT_GameStates.simulateInOrbit && loadDeferTime != DateTime.MaxValue && lastSeconds != (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).Seconds)
                        {
                            double remaining = (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).TotalSeconds;
                            ScreenMessages.PostScreenMessage("[KCT] Moving vessel in " + Math.Round(remaining) + " seconds", (float)(remaining - Math.Floor(remaining)), ScreenMessageStyle.UPPER_CENTER);
                            lastSeconds = (int)remaining;
                        }
                    }
                    if (KCT_GameStates.simulationEndTime > 0 && KCT_GameStates.UT >= KCT_GameStates.simulationEndTime)
                    {
                        TimeWarp.SetRate(0, true);
                        FlightDriver.SetPause(true);
                        KCT_GUI.showSimulationCompleteFlight = true;
                    }
                    if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH && KCT_GameStates.simulationEndTime == 0 && KCT_GameStates.simulationTimeLimit > 0)
                    {
                        KCT_GameStates.simulationEndTime = Planetarium.GetUniversalTime() + KCT_GameStates.simulationTimeLimit; //Just in case the event doesn't fire
                    }
                }

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

                if (!KCT_GUI.PrimarilyDisabled && HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    if (VesselSpawnDialog.Instance.Visible)
                    {
                        POINTER_INFO ptr = new POINTER_INFO();
                        ptr.evt = POINTER_INFO.INPUT_EVENT.TAP;
                        VesselSpawnDialog.Instance.ButtonClose(ref ptr);
                        KCTDebug.Log("Attempting to close spawn dialog!");
                    }
                }

                /* if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.recoveredVessel != null)
                 * {
                 *   InputLockManager.SetControlLock(ControlTypes.All, "KCTPopupLock");
                 *   DialogOption[] options = new DialogOption[3];
                 *   options[0] = new DialogOption("VAB Storage", RecoverToVAB);
                 *   options[1] = new DialogOption("SPH Storage", RecoverToSPH);
                 *   options[2] = new DialogOption("The Scrapyard", RecoverToScrapyard);
                 *   MultiOptionDialog diag = new MultiOptionDialog("Send recovered vessel to", windowTitle: "Vessel Recovery", options: options);
                 *   PopupDialog.SpawnPopupDialog(diag, false, HighLogic.Skin);
                 * }*/

                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.ProgressBuildTime();
                }
            }
            catch (IndexOutOfRangeException e)
            {
                print(e.Message);
                print(e.StackTrace);
            }
        }
示例#17
0
        public static void DrawBuildListWindow(int windowID)
        {
            if (buildListWindowPosition.xMax > Screen.width)
            {
                buildListWindowPosition.x = Screen.width - buildListWindowPosition.width;
            }

            //GUI.skin = HighLogic.Skin;
            GUIStyle redText = new GUIStyle(GUI.skin.label);

            redText.normal.textColor = Color.red;
            GUIStyle yellowText = new GUIStyle(GUI.skin.label);

            yellowText.normal.textColor = Color.yellow;
            GUIStyle greenText = new GUIStyle(GUI.skin.label);

            greenText.normal.textColor = Color.green;

            int width1 = 120;
            int width2 = 100;
            int butW   = 20;

            GUILayout.BeginVertical();
            //GUILayout.Label("Current KSC: " + KCT_GameStates.ActiveKSC.KSCName);
            //List next vessel to finish
            GUILayout.BeginHorizontal();
            GUILayout.Label("Next:", windowSkin.label);
            IKCTBuildItem buildItem = KCT_Utilities.NextThingToFinish();

            if (buildItem != null)
            {
                //KCT_BuildListVessel ship = (KCT_BuildListVessel)buildItem;
                GUILayout.Label(buildItem.GetItemName());
                if (buildItem.GetListType() == KCT_BuildListVessel.ListType.VAB || buildItem.GetListType() == KCT_BuildListVessel.ListType.Reconditioning)
                {
                    GUILayout.Label("VAB", windowSkin.label);
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(buildItem.GetTimeLeft()));
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.SPH)
                {
                    GUILayout.Label("SPH", windowSkin.label);
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(buildItem.GetTimeLeft()));
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.TechNode)
                {
                    GUILayout.Label("Tech", windowSkin.label);
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(buildItem.GetTimeLeft()));
                }
                else if (buildItem.GetListType() == KCT_BuildListVessel.ListType.KSC)
                {
                    GUILayout.Label("KSC", windowSkin.label);
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(buildItem.GetTimeLeft()));
                }

                if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex == 0 && GUILayout.Button("Warp to" + System.Environment.NewLine + "Complete"))
                {
                    KCT_GameStates.targetedItem = buildItem;
                    KCT_GameStates.canWarp      = true;
                    KCT_Utilities.RampUpWarp();
                    KCT_GameStates.warpInitiated = true;
                }
                else if (!HighLogic.LoadedSceneIsEditor && TimeWarp.CurrentRateIndex > 0 && GUILayout.Button("Stop" + System.Environment.NewLine + "Warp"))
                {
                    KCT_GameStates.canWarp = false;
                    TimeWarp.SetRate(0, true);
                    KCT_GameStates.lastWarpRate = 0;
                }

                if (KCT_GameStates.settings.AutoKACAlarams && KACWrapper.APIReady)
                {
                    double UT = Planetarium.GetUniversalTime();
                    if (!KCT_Utilities.ApproximatelyEqual(KCT_GameStates.KACAlarmUT - UT, buildItem.GetTimeLeft()))
                    {
                        KCTDebug.Log("KAC Alarm being created!");
                        KCT_GameStates.KACAlarmUT = (buildItem.GetTimeLeft() + UT);
                        KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => a.ID == KCT_GameStates.KACAlarmId);
                        if (alarm == null)
                        {
                            alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => (a.Name.StartsWith("KCT: ")));
                        }
                        if (alarm != null)
                        {
                            KCTDebug.Log("Removing existing alarm");
                            KACWrapper.KAC.DeleteAlarm(alarm.ID);
                        }
                        KCT_GameStates.KACAlarmId = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, "KCT: " + buildItem.GetItemName() + " Complete", KCT_GameStates.KACAlarmUT);
                        KCTDebug.Log("Alarm created with ID: " + KCT_GameStates.KACAlarmId);
                    }
                }
            }
            else
            {
                GUILayout.Label("No Active Projects");
            }
            GUILayout.EndHorizontal();

            //Buttons for VAB/SPH lists
            List <string> buttonList = new List <string> {
                "VAB", "SPH", "KSC"
            };

            if (KCT_Utilities.CurrentGameHasScience() && !KCT_GameStates.settings.InstantTechUnlock)
            {
                buttonList.Add("Tech");
            }
            GUILayout.BeginHorizontal();
            //if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { buttonList.Add("Upgrades"); buttonList.Add("Settings"); }
            int lastSelected = listWindow;

            listWindow = GUILayout.Toolbar(listWindow, buttonList.ToArray());

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Upgrades"))
            {
                showUpgradeWindow = true;
                showBuildList     = false;
                showBLPlus        = false;
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && GUILayout.Button("Settings"))
            {
                showBuildList = false;
                showBLPlus    = false;
                ShowSettings();
            }
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                buildListWindowPosition.height = 1;
                showBLPlus = false;
                if (lastSelected == listWindow)
                {
                    listWindow = -1;
                }
            }
            //Content of lists
            if (listWindow == 0) //VAB Build List
            {
                List <KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.VABList;
                GUILayout.BeginHorizontal();
                //  GUILayout.Space((butW + 4) * 3);
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width2));
                //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10));
                GUILayout.EndHorizontal();
                if (KCT_Utilities.ReconditioningActive(null))
                {
                    GUILayout.BeginHorizontal();
                    IKCTBuildItem item = (IKCTBuildItem)KCT_GameStates.ActiveKSC.GetReconditioning();
                    GUILayout.Label(item.GetItemName());
                    GUILayout.Label(KCT_GameStates.ActiveKSC.GetReconditioning().ProgressPercent().ToString() + "%", GUILayout.Width(width1 / 2));
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(item.GetTimeLeft()), GUILayout.Width(width2));
                    //GUILayout.Label(Math.Round(KCT_GameStates.ActiveKSC.GetReconditioning().BP, 2).ToString(), GUILayout.Width(width1 / 2 + 10));
                    if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width((butW + 4) * 2)))
                    {
                        KCT_GameStates.targetedItem = item;
                        KCT_GameStates.canWarp      = true;
                        KCT_Utilities.RampUpWarp(item);
                        KCT_GameStates.warpInitiated = true;
                    }
                    //GUILayout.Space((butW + 4) * 3);
                    GUILayout.EndHorizontal();
                }

                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                {
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels under construction! Go to the VAB to build more.");
                    }
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        GUILayout.BeginHorizontal();
                        //GUILayout.Label(b.shipName, GUILayout.Width(width1));

                        if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW)))
                        {
                            if (IDSelected == b.id)
                            {
                                showBLPlus = !showBLPlus;
                            }
                            else
                            {
                                showBLPlus = true;
                            }
                            IDSelected = b.id;
                        }
                        else if (HighLogic.LoadedSceneIsEditor)
                        {
                            //GUILayout.Space(butW);
                            if (GUILayout.Button("X", GUILayout.Width(butW)))
                            {
                                InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock");
                                IDSelected = b.id;
                                DialogOption[] options = new DialogOption[2];
                                options[0] = new DialogOption("Yes", ScrapVessel);
                                options[1] = new DialogOption("No", DummyVoid);
                                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", windowTitle: "Scrap Vessel", options: options);
                                PopupDialog.SpawnPopupDialog(diag, false, windowSkin);
                            }
                        }

                        if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Insert(0, b);
                            }
                            else
                            {
                                buildList.Insert(i - 1, b);
                            }
                        }
                        else if (i == 0)
                        {
                            //      GUILayout.Space(butW + 4);
                        }
                        if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Add(b);
                            }
                            else
                            {
                                buildList.Insert(i + 1, b);
                            }
                        }
                        else if (i >= buildList.Count - 1)
                        {
                            //      GUILayout.Space(butW + 4);
                        }


                        GUILayout.Label(b.shipName);
                        GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2));
                        if (b.buildRate > 0)
                        {
                            GUILayout.Label(KCT_Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2));
                        }
                        else
                        {
                            GUILayout.Label("Est: " + KCT_Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.VAB, null)), GUILayout.Width(width2));
                        }
                        // GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10));
                        GUILayout.EndHorizontal();
                    }

                    //ADD Storage here!
                    buildList = KCT_GameStates.ActiveKSC.VABWarehouse;
                    GUILayout.Label("__________________________________________________");
                    GUILayout.Label("VAB Storage");
                    if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel"))
                    {
                        KCT_GameStates.recoveredVessel            = new KCT_BuildListVessel(FlightGlobals.ActiveVessel);
                        KCT_GameStates.recoveredVessel.type       = KCT_BuildListVessel.ListType.VAB;
                        KCT_GameStates.recoveredVessel.launchSite = "LaunchPad";
                        // HighLogic.LoadScene(GameScenes.SPACECENTER);
                        //ShipConstruction.RecoverVesselFromFlight(FlightGlobals.ActiveVessel.protoVessel, HighLogic.CurrentGame.flightState);
                        GameEvents.OnVesselRecoveryRequested.Fire(FlightGlobals.ActiveVessel);
                    }
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete.");
                    }
                    KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollout);
                    //KCT_Recon_Rollout rollback = KCT_GameStates.ActiveKSC.GetReconRollout(KCT_Recon_Rollout.RolloutReconType.Rollback);
                    bool rolloutEnabled = KCT_GameStates.settings.Reconditioning && KCT_GameStates.timeSettings.RolloutReconSplit > 0;
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b           = buildList[i];
                        KCT_Recon_Rollout   rollback    = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Rollback);
                        KCT_Recon_Rollout   recovery    = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery);
                        GUIStyle            textColor   = new GUIStyle(GUI.skin.label);
                        GUIStyle            buttonColor = new GUIStyle(GUI.skin.button);
                        string status = "In Storage";
                        if (rollout != null && rollout.associatedID == b.id.ToString())
                        {
                            status    = "Rolling Out";
                            textColor = yellowText;
                            if (rollout.AsBuildItem().IsComplete())
                            {
                                status    = "On the Pad";
                                textColor = greenText;
                            }
                        }
                        else if (rollback != null)
                        {
                            status    = "Rolling Back";
                            textColor = yellowText;
                        }
                        else if (recovery != null)
                        {
                            status    = "Recovering";
                            textColor = redText;
                        }

                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && status == "In Storage")
                        {
                            if (GUILayout.Button("*", GUILayout.Width(butW)))
                            {
                                if (IDSelected == b.id)
                                {
                                    showBLPlus = !showBLPlus;
                                }
                                else
                                {
                                    showBLPlus = true;
                                }
                                IDSelected = b.id;
                            }
                        }
                        else
                        {
                            GUILayout.Space(butW + 4);
                        }

                        GUILayout.Label(b.shipName, textColor);
                        GUILayout.Label(status + "   ", textColor, GUILayout.ExpandWidth(false));
                        if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && (rollout == null || b.id.ToString() != rollout.associatedID) && rollback == null && GUILayout.Button("Rollout", GUILayout.ExpandWidth(false)))
                        {
                            if (rollout != null)
                            {
                                rollout.SwapRolloutType();
                            }
                            KCT_GameStates.ActiveKSC.Recon_Rollout.Add(new KCT_Recon_Rollout(b, KCT_Recon_Rollout.RolloutReconType.Rollout, b.id.ToString()));
                        }
                        else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollout != null && b.id.ToString() == rollout.associatedID && !rollout.AsBuildItem().IsComplete() && rollback == null &&
                                 GUILayout.Button(KCT_Utilities.GetColonFormattedTime(rollout.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false)))
                        {
                            rollout.SwapRolloutType();
                        }
                        else if (rolloutEnabled && !HighLogic.LoadedSceneIsEditor && recovery == null && rollback != null && b.id.ToString() == rollback.associatedID && !rollback.AsBuildItem().IsComplete())
                        {
                            if (rollout == null)
                            {
                                if (GUILayout.Button(KCT_Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false)))
                                {
                                    rollback.SwapRolloutType();
                                }
                            }
                            else
                            {
                                GUILayout.Label(KCT_Utilities.GetColonFormattedTime(rollback.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                            }
                        }
                        else if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && (!rolloutEnabled || (rollout != null && b.id.ToString() == rollout.associatedID && rollout.AsBuildItem().IsComplete())))
                        {
                            if (rolloutEnabled && GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button("Roll Back", GUILayout.ExpandWidth(false)))
                            {
                                rollout.SwapRolloutType();
                            }
                            else if (!GameSettings.MODIFIER_KEY.GetKey() && GUILayout.Button("Launch", GUILayout.ExpandWidth(false)))
                            {
                                bool operational = KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.VAB);//new PreFlightTests.FacilityOperational("LaunchPad", "building").Test();
                                if (!operational)
                                {
                                    ScreenMessages.PostScreenMessage("You must repair the launchpad prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                                }
                                else if (KCT_Utilities.ReconditioningActive(null))
                                {
                                    //can't launch now
                                    ScreenMessage message = new ScreenMessage("[KCT] Cannot launch while LaunchPad is being reconditioned. It will be finished in "
                                                                              + KCT_Utilities.GetFormattedTime(((IKCTBuildItem)KCT_GameStates.ActiveKSC.GetReconditioning()).GetTimeLeft()), 4.0f, ScreenMessageStyle.UPPER_CENTER);
                                    ScreenMessages.PostScreenMessage(message, true);
                                }
                                else
                                {
                                    /*if (rollout != null)
                                     *  KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);*/
                                    KCT_GameStates.launchedVessel = b;
                                    if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, "LaunchPad").Count == 0)//  ShipConstruction.CheckLaunchSiteClear(HighLogic.CurrentGame.flightState, "LaunchPad", false))
                                    {
                                        showBLPlus = false;
                                        // buildList.RemoveAt(i);
                                        if (!IsCrewable(b.ExtractedParts))
                                        {
                                            b.Launch();
                                        }
                                        else
                                        {
                                            showBuildList = false;
                                            centralWindowPosition.height = 1;
                                            KCT_GameStates.launchedCrew.Clear();
                                            parts       = KCT_GameStates.launchedVessel.ExtractedParts;
                                            pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts();
                                            KCT_GameStates.launchedCrew = new List <CrewedPart>();
                                            foreach (PseudoPart pp in pseudoParts)
                                            {
                                                KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List <ProtoCrewMember>()));
                                            }
                                            CrewFirstAvailable();
                                            showShipRoster = true;
                                        }
                                    }
                                    else
                                    {
                                        showBuildList   = false;
                                        showClearLaunch = true;
                                    }
                                }
                            }
                        }
                        else if (!HighLogic.LoadedSceneIsEditor && recovery != null)
                        {
                            GUILayout.Label(KCT_Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndScrollView();
            }
            else if (listWindow == 1) //SPH Build List
            {
                List <KCT_BuildListVessel> buildList = KCT_GameStates.ActiveKSC.SPHList;
                GUILayout.BeginHorizontal();
                //  GUILayout.Space((butW + 4) * 3);
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width2));
                //GUILayout.Label("BP:", GUILayout.Width(width1 / 2 + 10));
                GUILayout.EndHorizontal();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                {
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels under construction! Go to the SPH to build more.");
                    }
                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b = buildList[i];
                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("*", GUILayout.Width(butW)))
                        {
                            if (IDSelected == b.id)
                            {
                                showBLPlus = !showBLPlus;
                            }
                            else
                            {
                                showBLPlus = true;
                            }
                            IDSelected = b.id;
                        }
                        else if (HighLogic.LoadedSceneIsEditor)
                        {
                            //GUILayout.Space(butW);
                            if (GUILayout.Button("X", GUILayout.Width(butW)))
                            {
                                InputLockManager.SetControlLock(ControlTypes.EDITOR_SOFT_LOCK, "KCTPopupLock");
                                IDSelected = b.id;
                                DialogOption[] options = new DialogOption[2];
                                options[0] = new DialogOption("Yes", ScrapVessel);
                                options[1] = new DialogOption("No", DummyVoid);
                                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap " + b.shipName + "?", windowTitle: "Scrap Vessel", options: options);
                                PopupDialog.SpawnPopupDialog(diag, false, windowSkin);
                            }
                        }

                        if (i > 0 && GUILayout.Button("^", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Insert(0, b);
                            }
                            else
                            {
                                buildList.Insert(i - 1, b);
                            }
                        }
                        else if (i == 0)
                        {
                            //          GUILayout.Space(butW + 4);
                        }
                        if (i < buildList.Count - 1 && GUILayout.Button("v", GUILayout.Width(butW)))
                        {
                            buildList.RemoveAt(i);
                            if (GameSettings.MODIFIER_KEY.GetKey())
                            {
                                buildList.Add(b);
                            }
                            else
                            {
                                buildList.Insert(i + 1, b);
                            }
                        }
                        else if (i >= buildList.Count - 1)
                        {
                            //         GUILayout.Space(butW + 4);
                        }

                        GUILayout.Label(b.shipName);
                        GUILayout.Label(Math.Round(b.ProgressPercent(), 2).ToString() + "%", GUILayout.Width(width1 / 2));
                        if (b.buildRate > 0)
                        {
                            GUILayout.Label(KCT_Utilities.GetColonFormattedTime(b.timeLeft), GUILayout.Width(width2));
                        }
                        else
                        {
                            GUILayout.Label("Est: " + KCT_Utilities.GetColonFormattedTime((b.buildPoints - b.progress) / KCT_Utilities.GetBuildRate(0, KCT_BuildListVessel.ListType.SPH, null)), GUILayout.Width(width2));
                        }
                        //GUILayout.Label(Math.Round(b.buildPoints, 2).ToString(), GUILayout.Width(width1 / 2 + 10));
                        GUILayout.EndHorizontal();
                    }

                    buildList = KCT_GameStates.ActiveKSC.SPHWarehouse;
                    GUILayout.Label("__________________________________________________");
                    GUILayout.Label("SPH Storage");
                    if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.IsRecoverable && FlightGlobals.ActiveVessel.IsClearToSave() == ClearToSaveStatus.CLEAR && GUILayout.Button("Recover Active Vessel"))
                    {
                        KCT_GameStates.recoveredVessel            = new KCT_BuildListVessel(FlightGlobals.ActiveVessel);
                        KCT_GameStates.recoveredVessel.type       = KCT_BuildListVessel.ListType.SPH;
                        KCT_GameStates.recoveredVessel.launchSite = "Runway";
                        //ShipConstruction.RecoverVesselFromFlight(FlightGlobals.ActiveVessel.protoVessel, HighLogic.CurrentGame.flightState);
                        GameEvents.OnVesselRecoveryRequested.Fire(FlightGlobals.ActiveVessel);
                    }

                    for (int i = 0; i < buildList.Count; i++)
                    {
                        KCT_BuildListVessel b      = buildList[i];
                        string            status   = "";
                        KCT_Recon_Rollout recovery = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == b.id.ToString() && r.RRType == KCT_Recon_Rollout.RolloutReconType.Recovery);
                        if (recovery != null)
                        {
                            status = "Recovering";
                        }

                        GUILayout.BeginHorizontal();
                        if (!HighLogic.LoadedSceneIsEditor && status == "")
                        {
                            if (GUILayout.Button("*", GUILayout.Width(butW)))
                            {
                                if (IDSelected == b.id)
                                {
                                    showBLPlus = !showBLPlus;
                                }
                                else
                                {
                                    showBLPlus = true;
                                }
                                IDSelected = b.id;
                            }
                        }
                        else
                        {
                            GUILayout.Space(butW + 4);
                        }

                        GUILayout.Label(b.shipName);
                        GUILayout.Label(status + "   ", GUILayout.ExpandWidth(false));
                        //ScenarioDestructibles.protoDestructibles["KSCRunway"].
                        if (HighLogic.LoadedScene != GameScenes.TRACKSTATION && recovery == null && GUILayout.Button("Launch", GUILayout.ExpandWidth(false)))
                        {
                            bool operational = KCT_Utilities.LaunchFacilityIntact(KCT_BuildListVessel.ListType.SPH);//new PreFlightTests.FacilityOperational("Runway", "building").Test();
                            if (!operational)
                            {
                                ScreenMessages.PostScreenMessage("You must repair the runway prior to launch!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                            }
                            else
                            {
                                showBLPlus = false;
                                KCT_GameStates.launchedVessel = b;
                                if (ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, "Runway").Count == 0)
                                {
                                    if (!IsCrewable(b.ExtractedParts))
                                    {
                                        b.Launch();
                                    }
                                    else
                                    {
                                        showBuildList = false;
                                        centralWindowPosition.height = 1;
                                        KCT_GameStates.launchedCrew.Clear();
                                        parts       = KCT_GameStates.launchedVessel.ExtractedParts;
                                        pseudoParts = KCT_GameStates.launchedVessel.GetPseudoParts();
                                        KCT_GameStates.launchedCrew = new List <CrewedPart>();
                                        foreach (PseudoPart pp in pseudoParts)
                                        {
                                            KCT_GameStates.launchedCrew.Add(new CrewedPart(pp.uid, new List <ProtoCrewMember>()));
                                        }
                                        CrewFirstAvailable();
                                        showShipRoster = true;
                                    }
                                }
                                else
                                {
                                    showBuildList   = false;
                                    showClearLaunch = true;
                                }
                            }
                        }
                        else if (recovery != null)
                        {
                            GUILayout.Label(KCT_Utilities.GetColonFormattedTime(recovery.AsBuildItem().GetTimeLeft()), GUILayout.ExpandWidth(false));
                        }
                        GUILayout.EndHorizontal();
                    }
                    if (buildList.Count == 0)
                    {
                        GUILayout.Label("No vessels in storage!\nThey will be stored here when they are complete.");
                    }
                }
                GUILayout.EndScrollView();
            }
            else if (listWindow == 2) //KSC things
            {
                List <KCT_UpgradingBuilding> KSCList = KCT_GameStates.ActiveKSC.KSCTech;
                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width1));
                GUILayout.Space(70);
                GUILayout.EndHorizontal();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                if (KSCList.Count == 0)
                {
                    GUILayout.Label("No upgrade projects are currently underway.");
                }
                foreach (KCT_UpgradingBuilding KCTTech in KSCList)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(KCTTech.AsIKCTBuildItem().GetItemName());
                    GUILayout.Label(Math.Round(100 * KCTTech.progress / KCTTech.BP, 2) + " %", GUILayout.Width(width1 / 2));
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(KCTTech.AsIKCTBuildItem().GetTimeLeft()), GUILayout.Width(width1));
                    if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width(70)))
                    {
                        KCT_GameStates.targetedItem = KCTTech;
                        KCT_GameStates.canWarp      = true;
                        KCT_Utilities.RampUpWarp(KCTTech);
                        KCT_GameStates.warpInitiated = true;
                    }
                    else if (HighLogic.LoadedSceneIsEditor)
                    {
                        GUILayout.Space(70);
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
            }
            else if (listWindow == 3) //Tech nodes
            {
                List <KCT_TechItem> techList = KCT_GameStates.TechList;
                //GUILayout.Label("Tech Node Research");
                GUILayout.BeginHorizontal();
                GUILayout.Label("Node Name:");
                GUILayout.Label("Progress:", GUILayout.Width(width1 / 2));
                GUILayout.Label("Time Left:", GUILayout.Width(width1));
                GUILayout.Space(70);
                GUILayout.EndHorizontal();
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(250));
                if (techList.Count == 0)
                {
                    GUILayout.Label("No tech nodes are being researched!\nBegin research by unlocking tech in the R&D building.");
                }
                for (int i = 0; i < techList.Count; i++)
                {
                    KCT_TechItem t = techList[i];
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(t.techName);
                    GUILayout.Label(Math.Round(100 * t.progress / t.scienceCost, 2) + " %", GUILayout.Width(width1 / 2));
                    GUILayout.Label(KCT_Utilities.GetColonFormattedTime(t.TimeLeft), GUILayout.Width(width1));
                    if (!HighLogic.LoadedSceneIsEditor && GUILayout.Button("Warp To", GUILayout.Width(70)))
                    {
                        KCT_GameStates.targetedItem = t;
                        KCT_GameStates.canWarp      = true;
                        KCT_Utilities.RampUpWarp(t);
                        KCT_GameStates.warpInitiated = true;
                    }
                    else if (HighLogic.LoadedSceneIsEditor)
                    {
                        GUILayout.Space(70);
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
            }

            if (KCT_UpdateChecker.UpdateFound)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Current Version: " + KCT_UpdateChecker.CurrentVersion);
                GUILayout.Label("Latest: " + KCT_UpdateChecker.WebVersion);
                GUILayout.EndHorizontal();
            }

            if (KCT_SpecialSurpriseInside.instance.activated)
            {
                GUILayout.BeginHorizontal();
                //jeb coin img, jeb coin amt, store button, daily challenge, SRB races
                GUILayout.Label(KCT_SpecialSurpriseInside.instance.jebCoinTex, GUILayout.ExpandWidth(false));
                if (GUILayout.Button(" Jeb Coins: " + KCT_SpecialSurpriseInside.instance.TotalJebCoins, GUILayout.ExpandWidth(false)))
                {
                    KCT_SpecialSurpriseInside.instance.JebCoinStore();
                }
                GUILayout.Label("");
                if (GUILayout.Button("Daily Challenge", GUILayout.ExpandWidth(false)))
                {
                    KCT_SpecialSurpriseInside.instance.DailyChallengePopup();
                }
                GUILayout.Label("");
                if (GUILayout.Button("Race SRBs", GUILayout.ExpandWidth(false)))
                {
                    KCT_SpecialSurpriseInside.instance.showRace = true;
                    showBuildList = false;
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
示例#18
0
        public void FixedUpdate()
        {
            if (!KCT_GameStates.settings.enabledForSave)
            {
                return;
            }

            KCT_GameStates.UT = Planetarium.GetUniversalTime();
            try
            {
                if (!KCT_GUI.PrimarilyDisabled && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION && !KCT_GameStates.flightSimulated))
                {
                    IKCTBuildItem ikctItem = KCT_Utilities.NextThingToFinish();
                    if (KCT_GameStates.targetedItem == null && ikctItem != null)
                    {
                        KCT_GameStates.targetedItem = ikctItem;
                    }
                    if (KCT_GameStates.canWarp && ikctItem != null && !ikctItem.IsComplete())
                    {
                        int warpRate = TimeWarp.CurrentRateIndex;
                        if (SOIAlert())
                        {
                            TimeWarp.SetRate(0, true);
                            KCT_GameStates.canWarp       = false;
                            KCT_GameStates.warpInitiated = false;
                        }
                        else 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 && (10 * TimeWarp.deltaTime) > Math.Max((ikctItem.GetTimeLeft()), 0) && TimeWarp.CurrentRate > 1.0f)
                            {
                                TimeWarp.SetRate(--warpRate, true);
                            }
                            else if (warpRate == 0 && KCT_GameStates.warpInitiated)
                            {
                                KCT_GameStates.canWarp       = false;
                                KCT_GameStates.warpInitiated = false;
                            }
                            KCT_GameStates.lastWarpRate = warpRate;
                        }
                    }
                    else if (ikctItem != null && ikctItem == KCT_GameStates.targetedItem && (KCT_GameStates.warpInitiated || KCT_GameStates.settings.ForceStopWarp) && TimeWarp.CurrentRate != 0 && (ikctItem.GetTimeLeft()) < (TimeWarp.deltaTime * 2) && (!ikctItem.IsComplete())) //Still warp down even if we don't control the clock
                    {
                        TimeWarp.SetRate(0, false);
                        KCT_GameStates.warpInitiated = false;
                    }
                    else if (ikctItem != null && (KCT_GameStates.settings.ForceStopWarp) && TimeWarp.CurrentRate != 0 && (!ikctItem.IsComplete()))
                    {
                        if ((10 * TimeWarp.deltaTime) > Math.Max((ikctItem.GetTimeLeft()), 0) && TimeWarp.CurrentRate > 1.0f)
                        {
                            TimeWarp.SetRate(TimeWarp.CurrentRateIndex - 1, true);
                        }
                    }
                }

                if (HighLogic.LoadedScene == GameScenes.FLIGHT && KCT_GameStates.flightSimulated) //Simulated flights
                {
                    if (FlightGlobals.ActiveVessel.loaded && !FlightGlobals.ActiveVessel.packed && !moved)
                    {
                        //moved = true;
                        int secondsForMove = 3;
                        if (KCT_GameStates.simulateInOrbit && loadDeferTime == DateTime.MaxValue)
                        {
                            loadDeferTime = DateTime.Now;
                        }
                        else if (KCT_GameStates.simulateInOrbit && (!KCT_GameStates.delayMove || DateTime.Now.CompareTo(loadDeferTime.AddSeconds(secondsForMove)) > 0))
                        {
                            KCTDebug.Log("Moving vessel to orbit. " + KCT_GameStates.simulationBody.bodyName + ":" + KCT_GameStates.simOrbitAltitude + ":" + KCT_GameStates.simInclination);
                            KCT_OrbitAdjuster.PutInOrbitAround(KCT_GameStates.simulationBody, KCT_GameStates.simOrbitAltitude, KCT_GameStates.simInclination);
                            moved         = true;
                            loadDeferTime = DateTime.MaxValue;
                        }
                        else if (!KCT_GameStates.simulateInOrbit)
                        {
                            moved = true;
                        }

                        if (KCT_GameStates.simulateInOrbit && loadDeferTime != DateTime.MaxValue && lastSeconds != (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).Seconds)
                        {
                            double remaining = (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).TotalSeconds;
                            ScreenMessages.PostScreenMessage("[KCT] Moving vessel in " + Math.Round(remaining) + " seconds", (float)(remaining - Math.Floor(remaining)), ScreenMessageStyle.UPPER_CENTER);
                            lastSeconds = (int)remaining;
                        }
                    }
                    if (KCT_GameStates.simulationEndTime > 0 && KCT_GameStates.UT >= KCT_GameStates.simulationEndTime)
                    {
                        FlightDriver.SetPause(true);
                        KCT_GUI.showSimulationCompleteFlight = true;
                    }
                    if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH && KCT_GameStates.simulationEndTime == 0 && KCT_GameStates.simulationTimeLimit > 0)
                    {
                        KCT_GameStates.simulationEndTime = Planetarium.GetUniversalTime() + KCT_GameStates.simulationTimeLimit; //Just in case the event doesn't fire
                    }
                }

                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.ProgressBuildTime();
                }
            }
            catch (IndexOutOfRangeException e)
            {
                print(e.Message);
                print(e.StackTrace);
            }
        }
示例#19
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker = new Dictionary<string, int>();
            PartInventory = new Dictionary<string, int>();
            flightSimulated = false;
            simulationInitialized = false;
            vesselDict = new Dictionary<string, string>();
            simulationBody = KCT_Utilities.GetBodyByName(BodiesVisited[0]);
            simulateInOrbit = false;
            BodiesVisited = new List<string> { KCT_Utilities.GetBodyByName("Earth") != null ? "Earth" : "Kerbin" };
            TotalUpgradePoints = 0;
              /*  VABUpgrades = new List<int>() {0};
            SPHUpgrades = new List<int>() {0};
            RDUpgrades = new List<int>() {0, 0};*/
            PurchasedUpgrades = new List<int>() { 0, 0 };
               // LaunchPadReconditioning = null;
            targetedItem = null;
            KCT_GUI.fundsCost = -13;
            KCT_GUI.sciCost = -13;
            KCT_GUI.nodeRate = -13;
            KCT_GUI.upNodeRate = -13;
            KCT_GUI.researchRate = -13;
            KCT_GUI.upResearchRate = -13;
            //ActiveKSC = new KCT_KSC("Stock");
            //KSCs = new List<KCT_KSC>() {ActiveKSC};

               /* VABList = new List<KCT_BuildListVessel>();
            VABWarehouse = new List<KCT_BuildListVessel>();
            SPHList = new List<KCT_BuildListVessel>();
            SPHWarehouse = new List<KCT_BuildListVessel>();
            TechList = new List<KCT_TechItem>();*/
        }
示例#20
0
 public static void RampUpWarp(IKCTBuildItem item)
 {
     int lastRateIndex = TimeWarp.CurrentRateIndex;
     int newRate = TimeWarp.CurrentRateIndex + 1;
     double timeLeft = item.GetTimeLeft();
     if (double.IsPositiveInfinity(timeLeft))
         timeLeft = KCT_Utilities.NextThingToFinish().GetTimeLeft();
     while ((timeLeft > 15 * TimeWarp.deltaTime) && (TimeWarp.CurrentRateIndex < KCT_GameStates.settings.MaxTimeWarp) && (lastRateIndex < newRate))
     {
         lastRateIndex = TimeWarp.CurrentRateIndex;
         TimeWarp.SetRate(lastRateIndex + 1, true);
         newRate = TimeWarp.CurrentRateIndex;
     }
 }
示例#21
0
        public void FixedUpdate()
        {
            if (!KCT_GameStates.settings.enabledForSave)
            {
                return;
            }

            if (!KCT_GameStates.erroredDuringOnLoad.AlertFired && KCT_GameStates.erroredDuringOnLoad.HasErrored())
            {
                KCT_GameStates.erroredDuringOnLoad.FireAlert();
            }
            if (KCT_GameStates.LoadingSimulationSave)
            {
                KCT_Utilities.LoadSimulationSave(true);
            }

            if (KCT_SpecialSurpriseInside.instance.activated)
            {
                if (HighLogic.LoadedSceneIsFlight)
                {
                    KCT_SpecialSurpriseInside.instance.CheckShipForChallengeComplete();
                }

                if (!KCT_SpecialSurpriseInside.instance.disableBlocks && UnityEngine.Random.Range(0, 1000) == 0)
                {
                    KCT_SpecialSurpriseInside.instance.showAd = true;
                }
            }


            KCT_GameStates.UT = Planetarium.GetUniversalTime();
            try
            {
                if (!KCT_GUI.PrimarilyDisabled && (HighLogic.LoadedScene == GameScenes.FLIGHT || HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION && !KCT_GameStates.flightSimulated))
                {
                    IKCTBuildItem ikctItem = KCT_Utilities.NextThingToFinish();
                    if (KCT_GameStates.targetedItem == null && ikctItem != null)
                    {
                        KCT_GameStates.targetedItem = ikctItem;
                    }
                    if (KCT_GameStates.canWarp && ikctItem != null && !ikctItem.IsComplete())
                    {
                        int warpRate = TimeWarp.CurrentRateIndex;
                        if (SOIAlert())
                        {
                            TimeWarp.SetRate(0, true);
                            KCT_GameStates.canWarp       = false;
                            KCT_GameStates.warpInitiated = false;
                        }
                        else 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 && (10 * TimeWarp.deltaTime) > Math.Max((ikctItem.GetTimeLeft()), 0) && TimeWarp.CurrentRate > 1.0f)
                            {
                                TimeWarp.SetRate(--warpRate, true);
                            }
                            else if (warpRate == 0 && KCT_GameStates.warpInitiated)
                            {
                                KCT_GameStates.canWarp       = false;
                                KCT_GameStates.warpInitiated = false;
                            }
                            KCT_GameStates.lastWarpRate = warpRate;
                        }
                    }
                    else if (ikctItem != null && ikctItem == KCT_GameStates.targetedItem && (KCT_GameStates.warpInitiated || KCT_GameStates.settings.ForceStopWarp) && TimeWarp.CurrentRate != 0 && (ikctItem.GetTimeLeft()) < (TimeWarp.deltaTime * 2) && (!ikctItem.IsComplete())) //Still warp down even if we don't control the clock
                    {
                        TimeWarp.SetRate(0, false);
                        KCT_GameStates.warpInitiated = false;
                    }
                    else if (ikctItem != null && (KCT_GameStates.settings.ForceStopWarp) && TimeWarp.CurrentRate != 0 && (!ikctItem.IsComplete()))
                    {
                        if ((10 * TimeWarp.deltaTime) > Math.Max((ikctItem.GetTimeLeft()), 0) && TimeWarp.CurrentRate > 1.0f)
                        {
                            TimeWarp.SetRate(TimeWarp.CurrentRateIndex - 1, true);
                        }
                    }
                }

                if (HighLogic.LoadedScene == GameScenes.FLIGHT && KCT_GameStates.flightSimulated) //Simulated flights
                {
                    if (FlightGlobals.ActiveVessel.loaded && !FlightGlobals.ActiveVessel.packed && !moved)
                    {
                        //moved = true;
                        int secondsForMove = 3;
                        if (KCT_GameStates.simulateInOrbit && loadDeferTime == DateTime.MaxValue)
                        {
                            loadDeferTime = DateTime.Now;
                        }
                        else if (KCT_GameStates.simulateInOrbit && (!KCT_GameStates.delayMove || DateTime.Now.CompareTo(loadDeferTime.AddSeconds(secondsForMove)) > 0))
                        {
                            KCTDebug.Log("Moving vessel to orbit. " + KCT_GameStates.simulationBody.bodyName + ":" + KCT_GameStates.simOrbitAltitude + ":" + KCT_GameStates.simInclination);
                            KCT_OrbitAdjuster.PutInOrbitAround(KCT_GameStates.simulationBody, KCT_GameStates.simOrbitAltitude, KCT_GameStates.simInclination);
                            moved         = true;
                            loadDeferTime = DateTime.MaxValue;
                        }
                        else if (!KCT_GameStates.simulateInOrbit)
                        {
                            moved = true;
                        }

                        if (KCT_GameStates.simulateInOrbit && loadDeferTime != DateTime.MaxValue && lastSeconds != (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).Seconds)
                        {
                            double remaining = (loadDeferTime.AddSeconds(secondsForMove) - DateTime.Now).TotalSeconds;
                            ScreenMessages.PostScreenMessage("[KCT] Moving vessel in " + Math.Round(remaining) + " seconds", (float)(remaining - Math.Floor(remaining)), ScreenMessageStyle.UPPER_CENTER);
                            lastSeconds = (int)remaining;
                        }
                    }
                    if (KCT_GameStates.simulationEndTime > 0 && KCT_GameStates.UT >= KCT_GameStates.simulationEndTime)
                    {
                        FlightDriver.SetPause(true);
                        KCT_GUI.showSimulationCompleteFlight = true;
                    }
                    if (FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH && KCT_GameStates.simulationEndTime == 0 && KCT_GameStates.simulationTimeLimit > 0)
                    {
                        KCT_GameStates.simulationEndTime = Planetarium.GetUniversalTime() + KCT_GameStates.simulationTimeLimit; //Just in case the event doesn't fire
                    }
                }

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

                /* if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.recoveredVessel != null)
                 * {
                 *   InputLockManager.SetControlLock(ControlTypes.All, "KCTPopupLock");
                 *   DialogOption[] options = new DialogOption[3];
                 *   options[0] = new DialogOption("VAB Storage", RecoverToVAB);
                 *   options[1] = new DialogOption("SPH Storage", RecoverToSPH);
                 *   options[2] = new DialogOption("The Scrapyard", RecoverToScrapyard);
                 *   MultiOptionDialog diag = new MultiOptionDialog("Send recovered vessel to", windowTitle: "Vessel Recovery", options: options);
                 *   PopupDialog.SpawnPopupDialog(diag, false, HighLogic.Skin);
                 * }*/

                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.ProgressBuildTime();
                }
            }
            catch (IndexOutOfRangeException e)
            {
                print(e.Message);
                print(e.StackTrace);
            }
        }
示例#22
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);
            }
        }
示例#23
0
        public static void reset()
        {
            //firstStart = true;
            PartTracker = new Dictionary<string, int>();
            PartInventory = new Dictionary<string, int>();
            flightSimulated = false;
            simulationInitialized = false;
            vesselDict = new Dictionary<string, string>();
            BodiesVisited = new List<string> { Planetarium.fetch.Home.name };
            simulationBody = KCT_Utilities.GetBodyByName(BodiesVisited[0]);
            simulateInOrbit = false;
            firstStart = false;
            vesselErrorAlerted = false;

              /*  VABUpgrades = new List<int>() {0};
            SPHUpgrades = new List<int>() {0};
            RDUpgrades = new List<int>() {0, 0};*/
            PurchasedUpgrades = new List<int>() { 0, 0 };
               // LaunchPadReconditioning = null;
            targetedItem = null;
            KCT_GUI.ResetFormulaRateHolders();

            InventorySaleUpgrades = 0;
            InventorySalesFigures = 0;

            ExperimentalParts.Clear();
            MiscellaneousTempUpgrades = 0;

            lastUT = 0;
            //ActiveKSC = new KCT_KSC("Stock");
            //KSCs = new List<KCT_KSC>() {ActiveKSC};

               /* VABList = new List<KCT_BuildListVessel>();
            VABWarehouse = new List<KCT_BuildListVessel>();
            SPHList = new List<KCT_BuildListVessel>();
            SPHWarehouse = new List<KCT_BuildListVessel>();
            TechList = new List<KCT_TechItem>();*/
        }