private static IEnumerator SetSimOrbit(SimulationParams simParams) { yield return(new WaitForEndOfFrame()); KCTDebug.Log($"Moving vessel to orbit. {simParams.SimulationBody.bodyName}:{simParams.SimOrbitAltitude}:{simParams.SimInclination}"); HyperEdit_Utilities.PutInOrbitAround(simParams.SimulationBody, simParams.SimOrbitAltitude, simParams.SimInclination); }
private void ProcessSimulation() { HighLogic.CurrentGame.Parameters.Flight.CanAutoSave = false; SimulationParams simParams = KCTGameStates.SimulationParams; if (FlightGlobals.ActiveVessel.loaded && !FlightGlobals.ActiveVessel.packed && !simParams.IsVesselMoved) { if (simParams.DisableFailures) { Utilities.ToggleFailures(!simParams.DisableFailures); } if (!simParams.SimulateInOrbit || !FlightDriver.CanRevertToPrelaunch) { // Either the player does not want to start in orbit or they saved and then loaded back into that save simParams.IsVesselMoved = true; return; } int secondsForMove = simParams.DelayMoveSeconds; if (_simMoveDeferTime == DateTime.MaxValue) { _simMoveDeferTime = DateTime.Now; } else if (DateTime.Now.CompareTo(_simMoveDeferTime.AddSeconds(secondsForMove)) > 0) { KCTDebug.Log($"Moving vessel to orbit. {simParams.SimulationBody.bodyName}:{simParams.SimOrbitAltitude}:{simParams.SimInclination}"); HyperEdit_Utilities.PutInOrbitAround(simParams.SimulationBody, simParams.SimOrbitAltitude, simParams.SimInclination); simParams.IsVesselMoved = true; _simMoveDeferTime = DateTime.MaxValue; } if (_simMoveDeferTime != DateTime.MaxValue && _simMoveSecondsRemain != (_simMoveDeferTime.AddSeconds(secondsForMove) - DateTime.Now).Seconds) { double remaining = (_simMoveDeferTime.AddSeconds(secondsForMove) - DateTime.Now).TotalSeconds; ScreenMessages.PostScreenMessage($"Moving vessel in {Math.Round(remaining)} seconds", (float)(remaining - Math.Floor(remaining)), ScreenMessageStyle.UPPER_CENTER); _simMoveSecondsRemain = (int)remaining; } } }
public static void DrawSimulationConfigure(int windowID) { SimulationParams simParams = KCTGameStates.SimulationParams; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Body: "); if (simParams == null) { simParams = KCTGameStates.SimulationParams = new SimulationParams(); } if (simParams.SimulationBody == null) { simParams.SimulationBody = Planetarium.fetch.Home; } GUILayout.Label(simParams.SimulationBody.bodyName); if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) { GUIStates.ShowSimConfig = false; GUIStates.ShowSimBodyChooser = true; _centralWindowPosition.height = 1; _simulationConfigPosition.height = 1; } GUILayout.EndHorizontal(); if (simParams.SimulationBody == Planetarium.fetch.Home) { bool changed = simParams.SimulateInOrbit; simParams.SimulateInOrbit = GUILayout.Toggle(simParams.SimulateInOrbit, " Start in orbit?"); if (simParams.SimulateInOrbit != changed) { _simulationConfigPosition.height = 1; } } if (simParams.SimulationBody != Planetarium.fetch.Home || simParams.SimulateInOrbit) { GUILayout.BeginHorizontal(); GUILayout.Label("Orbit Altitude (km): "); _sOrbitAlt = GUILayout.TextField(_sOrbitAlt, GUILayout.Width(100)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Min: " + simParams.SimulationBody.atmosphereDepth / 1000); GUILayout.Label("Max: " + Math.Floor(simParams.SimulationBody.sphereOfInfluence) / 1000); GUILayout.EndHorizontal(); if (!simParams.SimulateInOrbit) { simParams.SimulateInOrbit = true; } } if (simParams.SimulateInOrbit) { GUILayout.BeginHorizontal(); GUILayout.Label("Delay: (s)"); _sDelay = GUILayout.TextField(_sDelay, 3, GUILayout.Width(40)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Inclination: "); _sOrbitInc = GUILayout.TextField(_sOrbitInc, GUILayout.Width(50)); GUILayout.EndHorizontal(); } GUILayout.Space(4); GUILayout.BeginHorizontal(); GUILayout.Label("Time: "); _UTString = GUILayout.TextField(_UTString, GUILayout.Width(100)); _fromCurrentUT = GUILayout.Toggle(_fromCurrentUT, " From Now"); GUILayout.EndHorizontal(); GUILayout.Label("Accepts values with format \"1y 2d 3h 4s\""); GUILayout.Space(4); if (Utilities.IsTestFlightInstalled || Utilities.IsTestLiteInstalled) { simParams.DisableFailures = !GUILayout.Toggle(!simParams.DisableFailures, " Enable Part Failures"); GUILayout.Space(4); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Simulate")) { StartSim(simParams); } if (GUILayout.Button("Cancel")) { GUIStates.ShowSimConfig = false; _centralWindowPosition.height = 1; _unlockEditor = true; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); CheckEditorLock(); CenterWindow(ref _simulationConfigPosition); }
private static void StartSim(SimulationParams simParams) { if (KCTGameStates.IsSimulatedFlight) { string msg = "Current save already appears to be a simulation. Starting a simulation inside a simulation isn't allowed."; PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "simErrorPopup", "KCT Simulation error", msg, "Understood", false, HighLogic.UISkin); return; } if (EditorLogic.fetch.ship.Count == 0) { var message = new ScreenMessage("Can't simulate without a vessel", 6f, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(message); return; } if (simParams.SimulationBody != Planetarium.fetch.Home) { simParams.SimulateInOrbit = true; } if (simParams.SimulateInOrbit) { if (!double.TryParse(_sOrbitAlt, out simParams.SimOrbitAltitude)) { simParams.SimOrbitAltitude = simParams.SimulationBody.atmosphere ? simParams.SimulationBody.atmosphereDepth + 20000 : 20000; } else { simParams.SimOrbitAltitude = Math.Min(Math.Max(1000 * simParams.SimOrbitAltitude, simParams.SimulationBody.atmosphereDepth), simParams.SimulationBody.sphereOfInfluence); } if (!double.TryParse(_sOrbitInc, out simParams.SimInclination)) { simParams.SimInclination = 0; } else { simParams.SimInclination %= 360; } } double currentUT = Utilities.GetUT(); simParams.DelayMoveSeconds = 0; if (_fromCurrentUT) { double utOffset = MagiCore.Utilities.ParseTimeString(_UTString, false); simParams.SimulationUT = utOffset != 0 ? currentUT + utOffset : 0; } else { simParams.SimulationUT = MagiCore.Utilities.ParseTimeString(_UTString, true); } if (simParams.SimulationUT < 0) { var message = new ScreenMessage("Cannot set time further back than the game start", 6f, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(message); return; } if (Utilities.IsPrincipiaInstalled && simParams.SimulationUT != 0 && simParams.SimulationUT < currentUT + 0.5) { var message = new ScreenMessage("Going backwards in time isn't allowed with Principia", 6f, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage(message); return; } int.TryParse(_sDelay, out simParams.DelayMoveSeconds); if (simParams.SimulationUT < 0) { simParams.SimulationUT = currentUT; } //_unlockEditor = true; GUIStates.ShowSimConfig = false; _centralWindowPosition.height = 1; string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft"; Utilities.MakeSimulationSave(); Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship); double effCost = Utilities.GetEffectiveCost(EditorLogic.fetch.ship.Parts); double bp = Utilities.GetBuildTime(effCost); KCTGameStates.LaunchedVessel = new BuildListVessel(EditorLogic.fetch.ship, EditorLogic.fetch.launchSiteName, effCost, bp, EditorLogic.FlagURL); VesselCrewManifest manifest = KSP.UI.CrewAssignmentDialog.Instance.GetManifest(); if (manifest == null) { manifest = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(EditorLogic.fetch.ship.SaveShip(), null, true); } EditorLogic.fetch.ship.SaveShip().Save(tempFile); KCTGameStates.IsSimulatedFlight = true; FlightDriver.StartWithNewLaunch(tempFile, EditorLogic.FlagURL, EditorLogic.fetch.launchSiteName, manifest); }