/// <summary> /// The MechJeb landing prediction simulator runs on a separate thread, /// and it may be costly for lower-end computers to leave it running /// all the time. This button allows the player to indicate whether /// it needs to be running, or not. /// </summary> /// <param name="state">Enable/disable</param> public void ButtonEnableLandingPrediction(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } var predictor = activeJeb.GetComputerModule <MechJebModuleLandingPredictions>(); if (predictor != null) { var landingGuidanceAP = activeJeb.GetComputerModule <MechJebModuleLandingGuidance>(); if (landingGuidanceAP != null) { if (state) { predictor.users.Add(landingGuidanceAP); } else { predictor.users.Remove(landingGuidanceAP); } } } }
public void ButtonAscentGuidance(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } MechJebModuleAscentAutopilot ap = activeJeb.GetComputerModule <MechJebModuleAscentAutopilot>(); if (ap == null) { return; } var agPilot = activeJeb.GetComputerModule <MechJebModuleAscentGuidance>(); if (agPilot != null) { if (ap.enabled) { ap.users.Remove(agPilot); } else { ap.users.Add(agPilot); } } }
public object ProcessVariable(string variable) { activeJeb = vessel.GetMasterMechJeb(); switch (variable) { case "MECHJEBAVAILABLE": if (activeJeb != null) { return(1); } return(-1); case "DELTAV": if (activeJeb != null) { MechJebModuleStageStats stats = activeJeb.GetComputerModule <MechJebModuleStageStats>(); stats.RequestUpdate(this); return(stats.vacStats.Sum(s => s.deltaV)); } return(null); case "DELTAVSTAGE": if (activeJeb != null) { MechJebModuleStageStats stats = activeJeb.GetComputerModule <MechJebModuleStageStats>(); stats.RequestUpdate(this); return(stats.vacStats[stats.vacStats.Length - 1].deltaV); } return(null); case "PREDICTEDLANDINGERROR": // If there's a failure at any step, exit with a -1. // The landing prediction system can be costly, and it // expects someone to be registered with it for it to run. // So, we'll have a MechJebRPM button to enable landing // predictions. And maybe add it in to the MJ menu. if (activeJeb != null && activeJeb.target.PositionTargetExists == true) { var predictor = activeJeb.GetComputerModule <MechJebModuleLandingPredictions>(); if (predictor != null && predictor.enabled) { ReentrySimulation.Result result = predictor.GetResult(); if (result != null && result.outcome == ReentrySimulation.Outcome.LANDED) { // We're going to hit something! double error = Vector3d.Distance(vessel.mainBody.GetRelSurfacePosition(result.endPosition.latitude, result.endPosition.longitude, 0), vessel.mainBody.GetRelSurfacePosition(activeJeb.target.targetLatitude, activeJeb.target.targetLongitude, 0)); return(error); } } } return(-1); } return(null); }
public static IList <IList <double> > DVStats() { IList <IList <double> > stats = new List <IList <double> >(); MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleStageStats activestats = activejeb.GetComputerModule("MechJebModuleStageStats") as MechJebModuleStageStats; if (activestats != null) { activestats.RequestUpdate(activejeb); int len = activestats.atmoStats.Length; for (int i = 0; i < len; i++) { IList <double> stage = new List <double>(); stage.Add(activestats.atmoStats[i].deltaV); stage.Add(activestats.vacStats[i].deltaV); stage.Add(activestats.atmoStats[i].StartTWR(1)); stage.Add(activestats.vacStats[i].StartTWR(1)); stage.Add(activestats.atmoStats[i].deltaTime); stats.Add(stage); } } } return(stats); }
public void ButtonNodeExecute(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } MechJebModuleManeuverPlanner mp = activeJeb.GetComputerModule <MechJebModuleManeuverPlanner>(); if (mp == null) { return; } if (state) { if (!activeJeb.node.enabled) { activeJeb.node.ExecuteOneNode(mp); } } else { activeJeb.node.Abort(); } }
public static void AscentNow(double Alt, float Inc) { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleAscentAutopilot activeasc = activejeb.GetComputerModule("MechJebModuleAscentAutopilot") as MechJebModuleAscentAutopilot; MechJebModuleAscentGuidance activegui = activejeb.GetComputerModule("MechJebModuleAscentGuidance") as MechJebModuleAscentGuidance; if (activeasc != null) { activegui.desiredInclination = Inc; activeasc.desiredOrbitAltitude.val = Alt; activeasc.desiredInclination = Inc; activeasc.enabled = true; } } }
public bool ButtonNodeExecuteState() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } MechJebModuleManeuverPlanner mp = activeJeb.GetComputerModule <MechJebModuleManeuverPlanner>(); return(mp != null && activeJeb.node.enabled); }
/// <summary> /// Returns whether the landing prediction simulator is currently /// running. /// </summary> /// <returns></returns> public bool ButtonEnableLandingPredictionState() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } var predictor = activeJeb.GetComputerModule <MechJebModuleLandingPredictions>(); return(predictor != null && predictor.enabled); }
/// <summary> /// Indicates whether the Rendezvous Autopilot is engaged. /// </summary> /// <returns></returns> public bool ButtonRendezvousAutopilotState() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } var autopilot = activeJeb.GetComputerModule <MechJebModuleRendezvousAutopilot>(); return(autopilot != null && autopilot.enabled); }
/// <summary> /// Returns true when Force Roll is on, and the roll is set to 0. /// </summary> /// <returns></returns> public bool ButtonForceRoll0State() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } MechJebModuleSmartASS activeSmartass = activeJeb.GetComputerModule <MechJebModuleSmartASS>(); return(activeSmartass != null && activeSmartass.forceRol && (double)activeSmartass.rol == 0.0); }
public static void SAForcerollClear() { MechJebCore activejeb = krpcmj.GetJeb(); if (activejeb != null) { MechJebModuleSmartASS activeass = activejeb.GetComputerModule("MechJebModuleSmartASS") as MechJebModuleSmartASS; if (activeass != null) { activeass.forceRol = false; } } }
public static void TranslatronCancel() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleTranslatron activetrans = activejeb.GetComputerModule("MechJebModuleTranslatron") as MechJebModuleTranslatron; if (activetrans != null) { activetrans.SetMode(MechJebModuleThrustController.TMode.OFF); } } }
public static void AbortExecution() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleNodeExecutor activenode = activejeb.GetComputerModule("MechJebModuleNodeExecutor") as MechJebModuleNodeExecutor; if (activenode != null) { activenode.Abort(); } } }
public static void ExecuteAllNodes() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleNodeExecutor activenode = activejeb.GetComputerModule("MechJebModuleNodeExecutor") as MechJebModuleNodeExecutor; if (activenode != null) { activenode.ExecuteAllNodes(activejeb); } } }
public static void WarptoApa() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleLandingAutopilot activelnd = activejeb.GetComputerModule("MechJebModuleLandingAutopilot") as MechJebModuleLandingAutopilot; if (activelnd != null) { activelnd.LandUntargeted(activejeb); } } }
/// <summary> /// Enables / disables landing guidance. When a target is selected and /// this mode is enabled, the ship goes into "Land at Target" mode. If /// a target is not selected, it becomes "Land Somewhere". /// </summary> /// <param name="state"></param> public void ButtonLandingGuidance(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } var autopilot = activeJeb.GetComputerModule <MechJebModuleLandingAutopilot>(); if (autopilot == null) { return; } if (state != autopilot.enabled) { if (state) { var landingGuidanceAP = activeJeb.GetComputerModule <MechJebModuleLandingGuidance>(); if (landingGuidanceAP != null) { if (activeJeb.target.PositionTargetExists) { autopilot.LandAtPositionTarget(landingGuidanceAP); } else { autopilot.LandUntargeted(landingGuidanceAP); } } } else { autopilot.StopLanding(); } } }
public static void LandTarget() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleLandingAutopilot activelnd = activejeb.GetComputerModule("MechJebModuleLandingAutopilot") as MechJebModuleLandingAutopilot; if (activelnd != null) { activelnd.LandAtPositionTarget(activejeb); } } }
public static void SAForceroll(float rol) { MechJebCore activejeb = krpcmj.GetJeb(); if (activejeb != null) { MechJebModuleSmartASS activeass = activejeb.GetComputerModule("MechJebModuleSmartASS") as MechJebModuleSmartASS; if (activeass != null) { activeass.rol = rol; activeass.forceRol = true; } } }
public static void AscentIntoPlane() { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleAscentAutopilot activeasc = activejeb.GetComputerModule("MechJebModuleAscentAutopilot") as MechJebModuleAscentAutopilot; if (activeasc != null) { activeasc.StartCountdown(activeasc.vesselState.time + LaunchTiming.TimeToPlane(activeasc.launchLANDifference, activeasc.vessel.mainBody, activeasc.vesselState.latitude, activeasc.vesselState.longitude, activeasc.core.target.TargetOrbit)); activeasc.enabled = true; } } }
StringValue LaunchWithMechJeb(ScalarValue alt) { MechJebCore activejeb = utils.GetJeb(); MechJebModuleAscentAutopilot activeasc = activejeb?.GetComputerModule("MechJebModuleAscentAutopilot") as MechJebModuleAscentAutopilot; if (activeasc != null) { activeasc.desiredOrbitAltitude.val = alt; activeasc.enabled = true; return(""); } return("error: no Mechjeb found in this vessel"); }
/// <summary> /// Returns true when Force Roll is on, and the roll is set to -90. /// </summary> /// <returns></returns> public bool ButtonForceRoll270State() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } // MOARdV TODO: normalize values before testing. MechJebModuleSmartASS activeSmartass = activeJeb.GetComputerModule <MechJebModuleSmartASS>(); return(activeSmartass != null && activeSmartass.forceRol && (double)activeSmartass.rol == -90.0); }
private static bool ReturnTargetState(MechJebModuleSmartASS.Target action, Vessel ourVessel) { MechJebCore activeJeb = ourVessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } MechJebModuleSmartASS activeSmartass = activeJeb.GetComputerModule <MechJebModuleSmartASS>(); if (activeSmartass == null) { return(false); } return(action == activeSmartass.target); }
public static void AscentRdzv(KRPC.SpaceCenter.Services.Vessel Targ) { MechJebCore activejeb = GetJeb(); if (activejeb != null) { MechJebModuleAscentAutopilot activeasc = activejeb.GetComputerModule("MechJebModuleAscentAutopilot") as MechJebModuleAscentAutopilot; if (activeasc != null) { activeasc.core.target.Set(Targ.InternalVessel); activeasc.core.vessel.targetObject = Targ.InternalVessel; activeasc.StartCountdown(activeasc.vesselState.time + LaunchTiming.TimeToPhaseAngle(activeasc.launchPhaseAngle, activeasc.vessel.mainBody, activeasc.vessel.longitude, activeasc.core.target.TargetOrbit)); activeasc.enabled = true; } } }
// and these are the two functions that actually do the work. private static void EnactTargetAction(MechJebModuleSmartASS.Target action, Vessel ourVessel) { MechJebCore activeJeb = ourVessel.GetMasterMechJeb(); if (activeJeb == null) { return; } MechJebModuleSmartASS activeSmartass = activeJeb.GetComputerModule <MechJebModuleSmartASS>(); if (activeSmartass == null) { return; } activeSmartass.target = action; activeSmartass.Engage(); }
/// <summary> /// Toggles SmartASS Force Roll mode. /// </summary> /// <param name="state"></param> public void ButtonForceRoll(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } MechJebModuleSmartASS activeSmartass = activeJeb.GetComputerModule <MechJebModuleSmartASS>(); if (activeSmartass != null) { activeSmartass.forceRol = state; activeSmartass.Engage(); } }
public bool ButtonAscentGuidanceState() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } MechJebModuleAscentAutopilot ap = activeJeb.GetComputerModule <MechJebModuleAscentAutopilot>(); if (ap == null) { return(false); } return(ap.enabled); }
public static void SASurface(float hdg, float pit, float rol) { MechJebCore activejeb = krpcmj.GetJeb(); if (activejeb != null) { MechJebModuleSmartASS activeass = activejeb.GetComputerModule("MechJebModuleSmartASS") as MechJebModuleSmartASS; if (activeass != null) { activeass.mode = MechJebModuleSmartASS.Mode.SURFACE; activeass.srfHdg = hdg; activeass.srfPit = pit; activeass.srfRol = rol; activeass.target = MechJebModuleSmartASS.Target.SURFACE; activeass.Engage(); } } }
/// <summary> /// Returns the current state of the landing guidance feature /// </summary> /// <returns>true if on, false if not</returns> public bool ButtonLandingGuidanceState() { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return(false); } var autopilot = activeJeb.GetComputerModule <MechJebModuleLandingAutopilot>(); if (autopilot == null) { return(false); } return(autopilot.enabled); }
/// <summary> /// Engages / disengages Rendezvous Autopilot /// </summary> /// <param name="state"></param> public void ButtonRendezvousAutopilot(bool state) { MechJebCore activeJeb = vessel.GetMasterMechJeb(); if (activeJeb == null) { return; } var autopilot = activeJeb.GetComputerModule <MechJebModuleRendezvousAutopilot>(); if (autopilot != null && activeJeb.target.NormalTargetExists && activeJeb.target.TargetOrbit.referenceBody == vessel.orbit.referenceBody) { /* * var autopilotController = activeJeb.GetComputerModule<MechJebModuleRendezvousAutopilotWindow>(); * if (autopilotController != null && autopilot.enabled != state) { * if (state) { * autopilot.users.Add(autopilotController); * } else { * autopilot.users.Remove(autopilotController); * } * } */ } }
//--- ROOT MENU methods private void UpdateRootMenu() { activeMenu.menuTitle = "== Root Menu: " + GetActiveMode(); targetMenuItem.isDisabled = (FlightGlobals.fetch.VesselTarget == null); nodeMenuItem.isDisabled = (vessel.patchedConicSolver.maneuverNodes.Count == 0); // Analysis disable once RedundantCast forceRollMenuItem.labelText = String.Format("Force Roll: {0:+0;-0;0}", (activeSmartass != null) ? (double)activeSmartass.rol : 0.0); // MOARdV: // This is a little messy, since SmartASS can be updated // asynchronously from our perspective. It is complicated // because some Target values do not have corresponding // modes (OFF, for instance). I am sure there's a cleaner way to // manage this, but I want to get basic functionality first, and // pretty code later. Currently, I put the OFF, KILL ROT, and NODE // buttons on the root menu, just like they're on the top-level // of the SmartASS window in MJ. // It is also fragile because I am using hard-coded numbers here // and I have to hope that no one rearranges the root menu. This // will be addressed in a future iteration of the code. if (activeSmartass != null) { if (activeSmartass.target == MechJebModuleSmartASS.Target.OFF) { activeMenu.SetSelected(0, true); } else if (activeSmartass.target == MechJebModuleSmartASS.Target.KILLROT) { activeMenu.SetSelected(1, true); } else if (activeSmartass.target == MechJebModuleSmartASS.Target.NODE) { activeMenu.SetSelected(2, true); } else if (MechJebModuleSmartASS.Target2Mode[(int)activeSmartass.target] == MechJebModuleSmartASS.Mode.ORBITAL) { activeMenu.SetSelected(3, true); } else if (MechJebModuleSmartASS.Target2Mode[(int)activeSmartass.target] == MechJebModuleSmartASS.Mode.TARGET) { activeMenu.SetSelected(4, true); } // 5 is Force Roll. State is controlled below, and is independent // of the rest of these // 6 is Execute Next Node. else if (MechJebModuleSmartASS.Target2Mode[(int)activeSmartass.target] == MechJebModuleSmartASS.Mode.SURFACE) { activeMenu.SetSelected(7, true); } else if (MechJebModuleSmartASS.Target2Mode[(int)activeSmartass.target] == MechJebModuleSmartASS.Mode.ADVANCED) { activeMenu.SetSelected(8, true); } forceRollMenuItem.isSelected = activeSmartass.forceRol; } else { activeMenu.SetSelected(0, true); forceRollMenuItem.isSelected = false; } TextMenu.Item item; item = activeMenu.Find(x => x.id == (int)MJMenu.ExecuteNodeMenu); if (item != null) { var mp = activeJeb.GetComputerModule <MechJebModuleManeuverPlanner>(); if (mp != null) { item.isSelected = false; item.labelText = (activeJeb.node.enabled) ? "Abort Node Execution" : "Execute Next Node"; item.isDisabled = (vessel.patchedConicSolver.maneuverNodes.Count == 0); } else { item.isSelected = false; item.labelText = "Execute Next Node"; item.isDisabled = true; } } item = activeMenu.Find(x => x.id == (int)MJMenu.AscentGuidanceMenu); if (item != null) { var ascentAP = activeJeb.GetComputerModule <MechJebModuleAscentAutopilot>(); if (ascentAP == null) { item.isSelected = false; item.isDisabled = true; } else { item.isSelected = ascentAP.enabled; item.isDisabled = false; } } item = activeMenu.Find(x => x.id == (int)MJMenu.LandingGuidanceMenu); if (item != null) { var landingAP = activeJeb.GetComputerModule <MechJebModuleLandingAutopilot>(); if (landingAP == null) { item.isSelected = false; item.isDisabled = true; } else { item.labelText = (activeJeb.target.PositionTargetExists) ? "Land at Target" : "Land Somewhere"; item.isSelected = landingAP.enabled; item.isDisabled = false; } } item = activeMenu.Find(x => x.id == (int)MJMenu.DockingGuidanceMenu); if (item != null) { var dockingAP = activeJeb.GetComputerModule <MechJebModuleDockingAutopilot>(); if (dockingAP == null) { item.isSelected = false; item.isDisabled = true; } else { item.isSelected = dockingAP.enabled; item.isDisabled = !(activeJeb.target.Target is ModuleDockingNode); } } //item = activeMenu.Find(x => x.id == (int)MJMenu.SpacePlaneMenu); //if (item != null) { // var headingAP = activeJeb.GetComputerModule<MechJebModuleSpaceplaneAutopilot>(); // if (headingAP == null) { // item.isSelected = false; // item.isDisabled = true; // } else { // item.isSelected = (headingAP.enabled && headingAP.mode == MechJebModuleSpaceplaneAutopilot.Mode.HOLD); // item.isDisabled = (headingAP.mode == MechJebModuleSpaceplaneAutopilot.Mode.AUTOLAND); // } //} item = activeMenu.Find(x => x.id == (int)MJMenu.CircularizeMenu); if (item != null) { item.isDisabled = vessel.LandedOrSplashed; } }