void Start() { instance = this; Log("Starting"); try { mucore.init(); vesselState = new VesselState(); attitude = new AttitudeController(this); stage = new StageController(this); attitude.OnStart(); stagestats = new StageStats(stage); stagestats.editorBody = getVessel.mainBody; stagestats.OnModuleEnabled(); stagestats.OnFixedUpdate(); stagestats.RequestUpdate(this); stagestats.OnFixedUpdate(); CreateButtonIcon(); LaunchName = new string(getVessel.vesselName.ToCharArray()); LaunchBody = getVessel.mainBody; launchdb = new LaunchDB(this); launchdb.Load(); mainWindow = new Window.MainWindow(this, 6378070); flightMapWindow = new Window.FlightMapWindow(this, 548302); statsWindow = new Window.StatsWindow(this, 6378070 + 4); double h = 80f; if (FlightGlobals.ActiveVessel.mainBody.atmosphere) { h = Math.Max(h, FlightGlobals.ActiveVessel.mainBody.atmosphereDepth + 10000f); DestinationHeight = new EditableValue(h, locked: true) / 1000; } delayUT = double.NaN; GameEvents.onShowUI.Add(ShowGUI); GameEvents.onHideUI.Add(HideGUI); LoadKeybind(); } catch (Exception ex) { Log(ex.ToString()); } }
public void CalculateSettings(Vessel vessel, bool UseBest = false) { float baseFactor = Mathf.Round((float)vessel.mainBody.GeeASL * 100.0f) / 10.0f; Log("Base turn speed factor {0:0.00}", baseFactor); // reset the settings to defaults if (GameSettings.MODIFIER_KEY.GetKey()) { launchdb.Clear(); TurnAngle = 10; StartSpeed = baseFactor * 10.0; DestinationHeight = (vessel.StableOrbitHeight() + 10000) / 1000; GravityTurner.Log("Reset results"); return; } Log("Min orbit height: {0}", vessel.StableOrbitHeight()); stagestats.ForceSimunlation(); double TWR = 0; for (int i = stagestats.atmoStats.Length - 1; i >= 0; i--) { double stagetwr = stagestats.atmoStats[i].StartTWR(vessel.mainBody.GeeASL); if (stagetwr > 0) { if (vessel.StageHasSolidEngine(i)) { TWR = (stagetwr + stagestats.atmoStats[i].MaxTWR(vessel.mainBody.GeeASL)) / 2.3; } else { TWR = stagetwr; } break; } } if (TWR > 1.2) { Log("First guess for TWR > 1.2 {0:0.00}", TWR); TWR -= 1.2; if (!TurnAngle.locked) { TurnAngle = Mathf.Clamp((float)(10 + TWR * 5), 10, 80); } if (!StartSpeed.locked) { StartSpeed = Mathf.Clamp((float)(baseFactor * 10 - TWR * baseFactor * 3), baseFactor, baseFactor * 10); if (StartSpeed < 10) { StartSpeed = 10; } } } double guessTurn, guessSpeed; if (UseBest && launchdb.BestSettings(out guessTurn, out guessSpeed)) { Log("UseBest && launchdb.BestSettings"); if (!StartSpeed.locked) { StartSpeed = guessSpeed; } if (!TurnAngle.locked) { TurnAngle = guessTurn; } } else if (launchdb.GuessSettings(out guessTurn, out guessSpeed)) { Log("GuessSettings"); if (!StartSpeed.locked) { StartSpeed = guessSpeed; } if (!TurnAngle.locked) { TurnAngle = guessTurn; } } if (!APTimeStart.locked) { APTimeStart = 50; } if (!APTimeFinish.locked) { APTimeFinish = 50; } if (!Sensitivity.locked) { Sensitivity = 0.3; } if (!DestinationHeight.locked) { DestinationHeight = vessel.StableOrbitHeight() + 10000; DestinationHeight /= 1000; } if (!Roll.locked) { Roll = 0; } if (!Inclination.locked) { Inclination = 0; } if (!PressureCutoff.locked) { PressureCutoff = 1200; } SaveParameters(); }