Skip to content

Commit

Permalink
Improve sim starting parameter validation.
Browse files Browse the repository at this point in the history
Also prevent UT changing from clashing with Principia.
  • Loading branch information
siimav committed Mar 26, 2021
1 parent 4dbcaf7 commit b127626
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Source/KerbalConstructionTime/GUI/GUI_Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static partial class KCT_GUI
{
private static Rect _simulationWindowPosition = new Rect((Screen.width - 250) / 2, (Screen.height - 250) / 2, 250, 1);
private static Rect _simulationConfigPosition = new Rect((Screen.width / 2) - 150, (Screen.height / 4), 300, 1);
private static Vector2 _bodyChooserScrollPos;

private static string _sOrbitAlt = "", _sOrbitInc = "", _UTString = "", _sDelay = "0";
private static bool _fromCurrentUT = true;
Expand Down Expand Up @@ -172,6 +173,13 @@ private static void StartSim(SimulationParams simParams)
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;

Expand All @@ -188,12 +196,31 @@ private static void StartSim(SimulationParams simParams)
simParams.SimInclination %= 360;
}

double currentUT = HighLogic.CurrentGame.flightState.universalTime;
double currentUT = Utilities.GetUT();
simParams.DelayMoveSeconds = 0;
if (_fromCurrentUT)
simParams.SimulationUT = currentUT + MagiCore.Utilities.ParseTimeString(_UTString, false);
{
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 < 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)
Expand Down

0 comments on commit b127626

Please sign in to comment.