private BoosterGuidanceCore CheckCore(Vessel vessel) { if (core == null) { core = BoosterGuidanceCore.GetBoosterGuidanceCore(vessel); if (core != null) { UpdateFromCore(); Targets.SetVisibility(showTargets, showTargets && core.Enabled() && (FlightGlobals.ActiveVessel == core.vessel)); } else { return(core); } } else { if (core.vessel != vessel) { Debug.Log("[BoosterGuidance] core.vessel!=vessel vessel=" + vessel + " map=" + MapView.MapIsEnabled); // Get new BoosterGuidanceCore as vessel changed core = BoosterGuidanceCore.GetBoosterGuidanceCore(vessel); UpdateFromCore(); } } if (core == null) { Debug.Log("[BoosterGuidance] Vessel " + vessel.name + " has no BoosterGuidanceCore"); } return(core); }
void EnableGuidance(BLControllerPhase phase) { BoosterGuidanceCore core = BoosterGuidanceCore.GetBoosterGuidanceCore(FlightGlobals.ActiveVessel); KSPActionParam param = new KSPActionParam(KSPActionGroup.None, KSPActionType.Activate); core.useFAR = hasFAR; Debug.Log("[BoosterGuidance] Vessel=" + FlightGlobals.ActiveVessel.name + " useFAR=" + core.useFAR); core.EnableGuidance(param); core.SetPhase(phase); }
public void CopyToOtherCore(BoosterGuidanceCore other) { other.deployLandingGear = deployLandingGear; other.deployLandingGearHeight = deployLandingGearHeight; other.landingBurnEngines = landingBurnEngines; other.landingBurnMaxAoA = landingBurnMaxAoA; other.landingBurnSteerKp = landingBurnSteerKp; other.aeroDescentMaxAoA = aeroDescentMaxAoA; other.aeroDescentSteerKp = aeroDescentSteerKp; other.reentryBurnAlt = reentryBurnAlt; other.reentryBurnMaxAoA = reentryBurnMaxAoA; other.reentryBurnSteerKp = reentryBurnSteerKp; other.reentryBurnTargetSpeed = reentryBurnTargetSpeed; other.tgtAlt = tgtAlt; other.tgtLatitude = tgtLatitude; other.tgtLongitude = tgtLongitude; other.touchdownMargin = touchdownMargin; other.touchdownSpeed = touchdownSpeed; other.igniteDelay = igniteDelay; other.phase = phase; }
void DisableGuidance() { BoosterGuidanceCore core = BoosterGuidanceCore.GetBoosterGuidanceCore(FlightGlobals.ActiveVessel); core.DisableGuidance(); }
bool MainTab(int windowID) { bool targetChanged = false; BoosterGuidanceCore core = CheckCore(FlightGlobals.ActiveVessel); BLControllerPhase phase = core.Phase(); // Target: // Draw any Controls inside the window here GUILayout.Label(Localizer.Format("#BoosterGuidance_Target"));//Target coordinates: GUILayout.BeginHorizontal(); double step = 1.0 / (60 * 60); // move by 1 arc second tgtLatitude.DrawEditGUI(EditableAngle.Direction.NS); if (GUILayout.Button("▲")) { tgtLatitude += step; targetChanged = true; } if (GUILayout.Button("▼")) { tgtLatitude -= step; targetChanged = true; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); tgtLongitude.DrawEditGUI(EditableAngle.Direction.EW); if (GUILayout.Button("◄")) { tgtLongitude -= step; targetChanged = true; } if (GUILayout.Button("►")) { tgtLongitude += step; targetChanged = true; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#BoosterGuidance_PickTarget"))) { PickTarget(); } if (GUILayout.Button("Set Here")) { SetTargetHere(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); showTargets = GUILayout.Toggle(showTargets, Localizer.Format("#BoosterGuidance_ShowTargets")); bool prevLogging = core.logging; // TODO string filename = FlightGlobals.ActiveVessel.name; filename = filename.Replace(" ", "_"); filename = filename.Replace("(", ""); filename = filename.Replace(")", ""); core.logFilename = filename; core.logging = GUILayout.Toggle(core.logging, Localizer.Format("#BoosterGuidance_Logging")); if (core.Enabled()) { if ((!prevLogging) && (core.logging)) // logging switched on { core.StartLogging(); } if ((prevLogging) && (!core.logging)) // logging switched off { core.StopLogging(); } } GUILayout.EndHorizontal(); // Info box GUILayout.BeginHorizontal(); GUILayout.Label(core.Info()); GUILayout.EndHorizontal(); // Boostback SetEnabledColors((phase == BLControllerPhase.BoostBack) || (phase == BLControllerPhase.Unset)); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(Localizer.Format("#BoosterGuidance_Boostback"), "Enable thrust towards target when out of atmosphere"))) { EnableGuidance(BLControllerPhase.BoostBack); } GUILayout.EndHorizontal(); // Coasting SetEnabledColors((phase == BLControllerPhase.Coasting) || (phase == BLControllerPhase.Unset)); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(Localizer.Format("#BoosterGuidance_Coasting"), "Turn to retrograde attitude and wait for Aero Descent phase"))) { EnableGuidance(BLControllerPhase.Coasting); } GUILayout.EndHorizontal(); // Re-Entry Burn SetEnabledColors((phase == BLControllerPhase.ReentryBurn) || (phase == BLControllerPhase.Unset)); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(Localizer.Format("#BoosterGuidance_ReentryBurn"), "Ignite engine on re-entry to reduce overheating"))) { EnableGuidance(BLControllerPhase.ReentryBurn); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#BoosterGuidance_EnableAltitude"), reentryBurnAlt, "m", 65); core.reentryBurnAlt = reentryBurnAlt; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#BoosterGuidance_TargetSpeed"), reentryBurnTargetSpeed, "m/s", 40); core.reentryBurnTargetSpeed = reentryBurnTargetSpeed; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Steer", GUILayout.Width(40)); core.reentryBurnSteerKp = Mathf.Clamp(core.reentryBurnSteerKp, 0, maxReentryGain); core.reentryBurnSteerKp = GUILayout.HorizontalSlider(core.reentryBurnSteerKp, 0, maxReentryGain); GUILayout.Label(((int)(core.reentryBurnMaxAoA)).ToString() + "°(max)", GUILayout.Width(60)); GUILayout.EndHorizontal(); // Aero Descent SetEnabledColors((phase == BLControllerPhase.AeroDescent) || (phase == BLControllerPhase.Unset)); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(Localizer.Format("#BoosterGuidance_AeroDescent"), "No thrust aerodynamic descent, steering with gridfins within atmosphere"))) { EnableGuidance(BLControllerPhase.AeroDescent); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Steer", GUILayout.Width(40)); core.aeroDescentSteerKp = Mathf.Clamp(core.aeroDescentSteerKp, 0, maxAeroDescentGain); core.aeroDescentSteerKp = GUILayout.HorizontalSlider(core.aeroDescentSteerKp, 0, maxAeroDescentGain); // max turn 2 degrees for 100m error GUILayout.Label(((int)core.aeroDescentMaxAoA).ToString() + "°(max)", GUILayout.Width(60)); GUILayout.EndHorizontal(); // Landing Burn SetEnabledColors((phase == BLControllerPhase.LandingBurn) || (phase == BLControllerPhase.Unset)); GUILayout.BeginHorizontal(); if (GUILayout.Button(Localizer.Format("#BoosterGuidance_LandingBurn"))) { EnableGuidance(BLControllerPhase.LandingBurn); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#BoosterGuidance_EnableAltitude")); String text = "n/a"; if (core.Enabled()) { if (core.LandingBurnHeight() > 0) { text = ((int)(core.LandingBurnHeight() + tgtAlt)).ToString() + "m"; } else { if (core.LandingBurnHeight() < 0) { text = Localizer.Format("#BoosterGuidance_TooHeavy"); } } } GUILayout.Label(text, GUILayout.Width(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#BoosterGuidance_Engines")); if (numLandingBurnEngines == Localizer.Format("#BoosterGuidance_Current")) { GUILayout.Label(numLandingBurnEngines); } else { GUILayout.Label(numLandingBurnEngines); } if (numLandingBurnEngines == "current") // Save active engines { if (GUILayout.Button(Localizer.Format("#BoosterGuidance_Set"))) // Set to currently active engines { numLandingBurnEngines = core.SetLandingBurnEngines(); } } else { if (GUILayout.Button(Localizer.Format("#BoosterGuidance_Unset"))) // Set to currently active engines { numLandingBurnEngines = core.UnsetLandingBurnEngines(); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Steer", GUILayout.Width(40)); core.landingBurnSteerKp = Mathf.Clamp(core.landingBurnSteerKp, 0, maxLandingBurnGain); core.landingBurnSteerKp = GUILayout.HorizontalSlider(core.landingBurnSteerKp, 0, maxLandingBurnGain); string max = Localizer.Format("#BoosterGuidance_Max"); GUILayout.Label(((int)(core.landingBurnMaxAoA)).ToString() + "°(" + max + ")", GUILayout.Width(60)); GUILayout.EndHorizontal(); // Activate guidance SetEnabledColors(true); // back to normal GUILayout.BeginHorizontal(); if (!core.Enabled()) { if (GUILayout.Button(Localizer.Format("#BoosterGuidance_EnableGuidance"))) { core.EnableGuidance(); } } else { if (GUILayout.Button(Localizer.Format("#BoosterGuidance_DisableGuidance"))) { core.DisableGuidance(); } } GUILayout.EndHorizontal(); GUI.DragWindow(); return((GUI.changed) || targetChanged); }
void WindowFunction(int windowID) { BoosterGuidanceCore core = CheckCore(FlightGlobals.ActiveVessel); if (core == null) { GUILayout.BeginHorizontal(); GUILayout.Label("No BoosterGuidance Core"); GUILayout.EndHorizontal(); return; } OnUpdate(); SetEnabledColors(true); // Close button if (GUI.Button(new Rect(windowRect.width - 18, 2, 16, 16), "")) { Hide(); return; } // Check for target being set if (core.vessel.targetObject != lastVesselTarget) { if (core.vessel.targetObject != null) { Vessel target = core.vessel.targetObject.GetVessel(); tgtLatitude = target.latitude; tgtLongitude = target.longitude; tgtAlt = (int)target.altitude; UpdateCore(); string msg = String.Format(Localizer.Format("#BoosterGuidance_TargetSetToX"), target.name); GuiUtils.ScreenMessage(msg); } lastVesselTarget = core.vessel.targetObject; } // Check for navigation target NavWaypoint nav = NavWaypoint.fetch; if (nav.IsActive) { // Does current nav position differ from last one used? A hack because // a can't see a way to check if the nav waypoint has changed // Doing it this way means lat and lon in window can be edited without them // getting locked to the nav waypoint if ((lastNavLat != nav.Latitude) || (lastNavLon != nav.Longitude)) { Coordinates pos = new Coordinates(nav.Latitude, nav.Longitude); Debug.Log("[BoosterGuidance] Target set to nav location " + pos.ToStringDMS()); tgtLatitude = nav.Latitude; tgtLongitude = nav.Longitude; lastNavLat = nav.Latitude; lastNavLon = nav.Longitude; // This is VERY unreliable //tgtAlt = (int)nav.Altitude; tgtAlt = (int)FlightGlobals.ActiveVessel.mainBody.TerrainAltitude(tgtLatitude, tgtLongitude); core.SetTarget(tgtLatitude, tgtLongitude, tgtAlt); string msg = String.Format(Localizer.Format("#BoosterGuidance_TargetSetToX"), pos.ToStringDMS()); GuiUtils.ScreenMessage(msg); UpdateCore(); } } else { lastNavLat = 0; lastNavLon = 0; } // Check for unloaded vessels foreach (var controller in BoosterGuidanceCore.controllers) { if (!controller.vessel.loaded) { GuiUtils.ScreenMessage("Guidance disabled for " + controller.vessel.name + " as out of physics range"); DisableGuidance(); } } tab = GUILayout.Toolbar(tab, new string[] { Localizer.Format("#BoosterGuidance_Main"), Localizer.Format("Advanced") }); bool changed = false; switch (tab) { case 0: changed = MainTab(windowID); break; case 1: changed = AdvancedTab(windowID); break; } if (changed) { UpdateCore(); } }