public static void DelayedStart() { // KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Keys); // KCTDebug.Log(ScenarioUpgradeableFacilities.protoUpgradeables.Values.ElementAt(0).facilityRefs[0].name); if (!updateChecked) { if (KCT_GameStates.settings.CheckForUpdates && !KCT_GameStates.firstStart) //Check for updates { KCT_UpdateChecker.CheckForUpdate(false, KCT_GameStates.settings.VersionSpecific); } updateChecked = true; } if (!KCT_GameStates.settings.enabledForSave) { return; } List <GameScenes> validScenes = new List <GameScenes> { GameScenes.SPACECENTER }; if (validScenes.Contains(HighLogic.LoadedScene)) { //Check for simulation save and load it. string backupFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs"; if (System.IO.File.Exists(backupFile)) { KCT_GameStates.LoadingSimulationSave = true; /* if (!KCT_GameStates.LoadingSimulationSave) * KCT_Utilities.LoadSimulationSave(); * else * System.IO.File.Delete(backupFile);*/ } } if (HighLogic.LoadedSceneIsFlight && KCT_GameStates.flightSimulated) { KCTDebug.Log("Simulation started"); KCT_GUI.hideAll(); KCT_GUI.showSimulationWindow = !KCT_GameStates.settings.NoSimGUI; KCT_GUI.showTimeRemaining = true; Planetarium.SetUniversalTime(KCT_GameStates.simulationUT); } if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsToChargeAtSimEnd != 0) { KCT_Utilities.SpendFunds(KCT_GameStates.FundsToChargeAtSimEnd, TransactionReasons.None); KCT_GameStates.FundsToChargeAtSimEnd = 0; } if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.FundsGivenForVessel != 0) { KCT_Utilities.SpendFunds(KCT_GameStates.FundsGivenForVessel, TransactionReasons.VesselRollout); KCT_GameStates.FundsGivenForVessel = 0; } if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated) { List <VesselType> invalidTypes = new List <VesselType> { VesselType.Debris, VesselType.SpaceObject, VesselType.Unknown }; if (!invalidTypes.Contains(FlightGlobals.ActiveVessel.vesselType) && !KCT_GameStates.BodiesVisited.Contains(FlightGlobals.ActiveVessel.mainBody.bodyName)) { KCT_GameStates.BodiesVisited.Add(FlightGlobals.ActiveVessel.mainBody.bodyName); var message = new ScreenMessage("[KCT] New simulation body unlocked: " + FlightGlobals.ActiveVessel.mainBody.bodyName, 4.0f, ScreenMessageStyle.UPPER_LEFT); ScreenMessages.PostScreenMessage(message, true); KCTDebug.Log("Unlocked sim body: " + FlightGlobals.ActiveVessel.mainBody.bodyName); } } if (KCT_GUI.PrimarilyDisabled) { return; } //The following should only be executed when fully enabled for the save foreach (KCT_KSC KSC in KCT_GameStates.KSCs) { KSC.RecalculateBuildRates(); KSC.RecalculateUpgradedBuildRates(); } if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.buildSimulatedVessel) { KCT_GameStates.buildSimulatedVessel = false; KCT_BuildListVessel toBuild = KCT_GameStates.launchedVessel.NewCopy(false); toBuild.buildPoints = KCT_Utilities.GetBuildTime(toBuild.ExtractedPartNodes, true, KCT_GUI.useInventory); KCT_Utilities.AddVesselToBuildList(toBuild, KCT_GUI.useInventory); } if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated) { KCT_GUI.hideAll(); if (FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH && KCT_GameStates.launchedVessel != null) { bool removed = KCT_GameStates.launchedVessel.RemoveFromBuildList(); if (removed) //Only do these when the vessel is first removed from the list { //Add the cost of the ship to the funds so it can be removed again by KSP //KCT_Utilities.AddFunds(KCT_Utilities.GetTotalVesselCost(FlightGlobals.ActiveVessel.protoVessel), TransactionReasons.VesselRollout); KCT_Utilities.AddFunds(KCT_GameStates.launchedVessel.cost, TransactionReasons.VesselRollout); FlightGlobals.ActiveVessel.vesselName = KCT_GameStates.launchedVessel.shipName; } KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString()); if (rollout != null) { KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout); } } } if (HighLogic.LoadedSceneIsEditor) { if (KCT_GameStates.EditorShipEditingMode) { KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName); EditorLogic.fetch.shipNameField.Text = KCT_GameStates.editedVessel.shipName; } if (!KCT_GUI.PrimarilyDisabled) { if (KCT_GameStates.settings.OverrideLaunchButton) { KCTDebug.Log("Taking control of launch button"); EditorLogic.fetch.launchBtn.methodToInvoke = "ShowLaunchAlert"; EditorLogic.fetch.launchBtn.scriptWithMethodToInvoke = KerbalConstructionTime.instance; } else { InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTLaunchLock"); } KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship); } } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { if (KCT_Utilities.CurrentGameHasScience() && KCT_GameStates.TotalUpgradePoints == 0) { ConfigNode CN = new ConfigNode(); ResearchAndDevelopment.Instance.snapshot.Save(CN); ConfigNode[] techNodes = CN.GetNodes("Tech"); KCTDebug.Log("technodes length: " + techNodes.Length); KCT_GameStates.TotalUpgradePoints = techNodes.Length + 14; } if (!KCT_GUI.PrimarilyDisabled) { KCT_GUI.showBuildList = KCT_GameStates.showWindows[0]; KCT_GUI.ResetBLWindow(); } else { KCT_GUI.showBuildList = false; KCT_GameStates.showWindows[0] = false; } if (KCT_GameStates.firstStart) { KCTDebug.Log("Showing first start."); KCT_GUI.showFirstRun = true; } KCT_GameStates.firstStart = false; if (KCT_GameStates.LaunchFromTS) { KCT_GameStates.launchedVessel.Launch(); } } }
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); } }
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); } 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 (!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); } }