public MechJebModuleScriptActionAscent(MechJebModuleScript scriptModule, MechJebCore core) : base(scriptModule, core, NAME)
 {
     this.autopilot    = core.GetComputerModule <MechJebModuleAscentAutopilot>();
     this.ascentModule = core.GetComputerModule <MechJebModuleAscentGuidance>();
     this.mainBody     = core.target.mainBody;
     this.targetOrbit  = core.target.TargetOrbit;
     actionTypes.Add("Ascent Guidance");
     actionTypes.Add("Launching to Rendezvous");
     this.readModuleConfiguration();
 }
Exemple #2
0
 public MechJebModuleScriptActionDockingAutopilot(MechJebModuleScript scriptModule, MechJebCore core) : base(scriptModule, core, NAME)
 {
     this.autopilot             = core.GetComputerModule <MechJebModuleDockingAutopilot>();;
     this.moduleGuidance        = core.GetComputerModule <MechJebModuleDockingGuidance>();;
     this.speedLimit            = autopilot.speedLimit;
     this.rol                   = autopilot.rol;
     this.forceRol              = autopilot.forceRol;
     this.overridenSafeDistance = autopilot.overridenSafeDistance;
     this.overrideSafeDistance  = autopilot.overrideSafeDistance;
     this.overrideTargetSize    = autopilot.overrideTargetSize;
     this.overridenTargetSize   = autopilot.overridenTargetSize;
     this.safeDistance          = autopilot.safeDistance;
     this.targetSize            = autopilot.targetSize;
     this.drawBoundingBox       = autopilot.drawBoundingBox;
 }
		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 MechJebModuleScriptActionSmartASS(MechJebModuleScript scriptModule, MechJebCore core, MechJebModuleScriptActionsList actionsList) : base(scriptModule, core, actionsList, NAME)
        {
            this.smartAss = core.GetComputerModule <MechJebModuleSmartASS>();
            int modeIdx = 0;

            foreach (MechJebModuleSmartASS.Target target in Enum.GetValues(typeof(MechJebModuleSmartASS.Target)))
            {
                if (TargetIsMode[(int)target] && target != MechJebModuleSmartASS.Target.AUTO)
                {
                    isTargetMode.Add(true);
                    modeModes.Add((MechJebModuleSmartASS.Mode) 0);
                    targetModes.Add(target);
                    modeStrings.Add(TargetTexts[(int)target]);
                    targetModeSelectorIdxs[(int)target] = modeIdx++;
                }
            }

            foreach (MechJebModuleSmartASS.Mode mode in Enum.GetValues(typeof(MechJebModuleSmartASS.Mode)))
            {
                if (mode != MechJebModuleSmartASS.Mode.AUTO)
                {
                    modeModes.Add(mode);
                    isTargetMode.Add(false);
                    targetModes.Add((MechJebModuleSmartASS.Target) 0);
                    modeStrings.Add(ModeTexts[(int)mode]);
                    modeModeSelectorIdxs[(int)mode] = modeIdx++;
                    targets[(int)mode]       = new List <MechJebModuleSmartASS.Target>();
                    targetStrings[(int)mode] = new List <String>();
                }
            }

            foreach (MechJebModuleSmartASS.Target target in Enum.GetValues(typeof(MechJebModuleSmartASS.Target)))
            {
                if (!TargetIsMode[(int)target])
                {
                    MechJebModuleSmartASS.Mode mode = Target2Mode[(int)target];
                    targetSelectorIdxs[(int)target] = targets[(int)mode].Count;
                    targets[(int)mode].Add(target);
                    targetStrings[(int)mode].Add(TargetTexts[(int)target]);
                }
            }
        }
 public MechJebModuleScriptCondition(MechJebModuleScript scriptModule, MechJebCore core, MechJebModuleScriptAction action)
 {
     this.scriptModule = scriptModule;
     this.core         = core;
     this.action       = action;
     moduleInfoItems   = core.GetComputerModule <MechJebModuleInfoItems>();
     conditionsList    = new List <String>();
     modifiersList     = new List <String>();
     conditionsList.Add("Altitude");
     conditionsList.Add("Speed");
     conditionsList.Add("Distance to target");
     conditionsList.Add("Target Apoapsis");
     conditionsList.Add("Target Periapsis");
     conditionsList.Add("Target Time to closest approach");
     conditionsList.Add("Target Distance to closest approach");
     conditionsList.Add("Target Relative velocity");
     conditionsList.Add("Target inclination");
     conditionsList.Add("Target orbit period");
     conditionsList.Add("Target orbit speed");
     conditionsList.Add("Target time to Ap");
     conditionsList.Add("Target time to Pe");
     conditionsList.Add("Target LAN");
     conditionsList.Add("Target AoP");
     conditionsList.Add("Target eccentricity");
     conditionsList.Add("Target SMA");
     conditionsList.Add("Periapsis in Target SOI");
     conditionsList.Add("Phase angle to target");
     conditionsList.Add("Target planet phase angle");
     conditionsList.Add("Relative inclination");
     conditionsList.Add("Time to AN");
     conditionsList.Add("Time to DN");
     conditionsList.Add("Time to equatorial AN");
     conditionsList.Add("Time to equatorial DN");
     conditionsList.Add("Circular orbit speed");
     conditionsList.Add("Apoapsis");
     conditionsList.Add("Periapsis");
     modifiersList.Add("Smaller than");
     modifiersList.Add("Equal to");
     modifiersList.Add("Greater than");
     modifiersList.Add("Between");
 }
 /* Note to self:
 foreach (ThatEnumType item in (ThatEnumType[]) Enum.GetValues(typeof(ThatEnumType)))
 can save a lot of time here.
 */
 private void UpdateJebReferences()
 {
     activeJeb = vessel.GetMasterMechJeb();
     // Node executor is activeJeb.node
     activeSmartass = activeJeb != null ? activeJeb.GetComputerModule<MechJebModuleSmartASS>() : null;
 }
Exemple #7
0
        public void actionsAddWindowGui(int windowID)
        {
            GUIStyle s = new GUIStyle(GUI.skin.label);

            s.normal.textColor = Color.blue;
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(Localizer.Format("#MechJeb_ScriptMod_label4"), s, GUILayout.ExpandWidth(false));            //"Add action"
            selectedGroupIndex = GuiUtils.ComboBox.Box(selectedGroupIndex, actionGroups, actionGroups);
            if (selectedGroupIndex != old_selectedGroupIndex)
            {
                selectedActionIndex    = 0;             //Reset action index
                old_selectedGroupIndex = selectedGroupIndex;
            }
            if (selectedGroupIndex == 10 && depth >= 4)             //Block more than 4 depth
            {
                GUIStyle s2 = new GUIStyle(GUI.skin.label);
                s2.normal.textColor = Color.red;
                GUILayout.Label(Localizer.Format("#MechJeb_ScriptMod_label5"), s2, GUILayout.ExpandWidth(false));                //"Program depth is limited to 4"
            }
            else
            {
                selectedActionIndex = GuiUtils.ComboBox.Box(selectedActionIndex, actionNames[selectedGroupIndex], actionNames);
                if (actionNames[selectedGroupIndex][selectedActionIndex].CompareTo("MODULE Ascent Autopilot") == 0 || actionNames[selectedGroupIndex][selectedActionIndex].CompareTo("MODULE Landing") == 0)
                {
                    if (GUILayout.Button(GameDatabase.Instance.GetTexture("MechJeb2/Icons/view", true), GUILayout.ExpandWidth(false)))
                    {
                        if (actionNames[selectedGroupIndex][selectedActionIndex].CompareTo("MODULE Ascent Autopilot") == 0)
                        {
                            //Open the ascent module GUI
                            core.GetComputerModule <MechJebModuleAscentGuidance>().enabled = true;
                        }
                        if (actionNames[selectedGroupIndex][selectedActionIndex].CompareTo("MODULE Landing") == 0)
                        {
                            //Open the DockingGuidance module GUI
                            core.GetComputerModule <MechJebModuleLandingGuidance>().enabled = true;
                        }
                    }
                }

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    String actionName = actionNames[selectedGroupIndex][selectedActionIndex];
                    if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions1_1")) == 0)                    //"Timer"
                    {
                        this.addAction(new MechJebModuleScriptActionTimer(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions2_1")) == 0)                    //"Decouple"
                    {
                        this.addAction(new MechJebModuleScriptActionUndock(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions2_2")) == 0)                    //"Dock Shield"
                    {
                        this.addAction(new MechJebModuleScriptActionDockingShield(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions7_1")) == 0)                    //"Staging"
                    {
                        this.addAction(new MechJebModuleScriptActionStaging(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions3_1")) == 0)                    //"Target Dock"
                    {
                        this.addAction(new MechJebModuleScriptActionTargetDock(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions3_2")) == 0)                    //"Target Body"
                    {
                        this.addAction(new MechJebModuleScriptActionTarget(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions4_1")) == 0)                    //"Control From"
                    {
                        this.addAction(new MechJebModuleScriptActionControlFrom(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions1_2")) == 0)                    //"Pause"
                    {
                        this.addAction(new MechJebModuleScriptActionPause(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions5_1")) == 0)                    //"Crew Transfer"
                    {
                        this.addAction(new MechJebModuleScriptActionCrewTransfer(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions10_1")) == 0)                    //"Quicksave"
                    {
                        this.addAction(new MechJebModuleScriptActionQuicksave(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions4_2")) == 0)                    //"RCS"
                    {
                        this.addAction(new MechJebModuleScriptActionRCS(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions4_4")) == 0)                    //"Switch Vessel"
                    {
                        this.addAction(new MechJebModuleScriptActionActiveVessel(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions7_2")) == 0)                    //"Activate Engine"
                    {
                        this.addAction(new MechJebModuleScriptActionActivateEngine(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions4_3")) == 0)                    //"SAS"
                    {
                        this.addAction(new MechJebModuleScriptActionSAS(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions6_2")) == 0)                    //"Execute node"
                    {
                        this.addAction(new MechJebModuleScriptActionExecuteNode(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions6_1")) == 0)                    //"Maneuver"
                    {
                        this.addAction(new MechJebModuleScriptActionManoeuver(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions8_1")) == 0)                    //"Node tolerance"
                    {
                        this.addAction(new MechJebModuleScriptActionTolerance(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions1_4")) == 0)                    //"Warp"
                    {
                        this.addAction(new MechJebModuleScriptActionWarp(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions1_3")) == 0)                    //"Wait for"
                    {
                        this.addAction(new MechJebModuleScriptActionWaitFor(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions11_1")) == 0)                    //"PROGRAM - Repeat"
                    {
                        if (this.checkMaxDepth())
                        {
                            this.addAction(new MechJebModuleScriptActionFor(scriptModule, core, this));
                        }
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions11_2")) == 0)                    //"PROGRAM - If"
                    {
                        if (this.checkMaxDepth())
                        {
                            this.addAction(new MechJebModuleScriptActionIf(scriptModule, core, this));
                        }
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions11_3")) == 0)                    //"PROGRAM - While"
                    {
                        if (this.checkMaxDepth())
                        {
                            this.addAction(new MechJebModuleScriptActionWhile(scriptModule, core, this));
                        }
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions11_4")) == 0)                    //"PROGRAM - Parallel"
                    {
                        if (this.checkMaxDepth())
                        {
                            this.addAction(new MechJebModuleScriptActionParallel(scriptModule, core, this));
                        }
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions10_3")) == 0)                    //"Action Group"
                    {
                        this.addAction(new MechJebModuleScriptActionActionGroup(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions10_2")) == 0)                    //"Load Script"
                    {
                        this.addAction(new MechJebModuleScriptActionLoadScript(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_1")) == 0)//"MODULE Smart A.S.S."
                    {
                        this.addAction(new MechJebModuleScriptActionSmartASS(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_2")) == 0)                    //"MODULE Ascent Autopilot"
                    {
                        this.addAction(new MechJebModuleScriptActionAscent(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_3")) == 0)                    //"MODULE Docking Autopilot"
                    {
                        this.addAction(new MechJebModuleScriptActionDockingAutopilot(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_4")) == 0)                    //"MODULE Landing"
                    {
                        this.addAction(new MechJebModuleScriptActionLanding(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_5")) == 0)                    //"MODULE Rendezvous"
                    {
                        this.addAction(new MechJebModuleScriptActionRendezvous(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo(Localizer.Format("#MechJeb_ScriptMod_actions9_6")) == 0)                    //"MODULE Rendezvous Autopilot"
                    {
                        this.addAction(new MechJebModuleScriptActionRendezvousAP(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo("[IR Sequencer] Sequence") == 0)                    //
                    {
                        this.addAction(new MechJebModuleScriptActionIRSequencer(scriptModule, core, this));
                    }
                    else if (actionName.CompareTo("[kOS] Command") == 0)                    //
                    {
                        this.addAction(new MechJebModuleScriptActionKos(scriptModule, core, this));
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
Exemple #8
0
 public MechJebModuleScriptActionRendezvousAP(MechJebModuleScript scriptModule, MechJebCore core) : base(scriptModule, core, NAME)
 {
     this.autopilot = core.GetComputerModule <MechJebModuleRendezvousAutopilot>();
     this.module    = core.GetComputerModule <MechJebModuleRendezvousAutopilotWindow>();
     this.readModuleConfiguration();
 }
Exemple #9
0
		protected override void LateUpdate()
		{
			if (shutdown)
				return;

			if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ready)
				return;

			if (SCANcontroller.controller == null)
			{
				way = null;
				return;
			}

			if (!SCANcontroller.controller.mechJebTargetSelection)
			{
				way = null;
				return;
			}

			v = FlightGlobals.ActiveVessel;

			if (v == null)
			{
				SCANcontroller.controller.MechJebLoaded = false;
				way = null;
				return;
			}

			if (v.mainBody != SCANcontroller.controller.LandingTargetBody)
				SCANcontroller.controller.LandingTargetBody = v.mainBody;

			data = SCANUtil.getData(v.mainBody);

			if (data == null)
			{
				SCANcontroller.controller.MechJebLoaded = false;
				way = null;
				return;
			}

			if (v.FindPartModulesImplementing<MechJebCore>().Count <= 0)
			{
				SCANcontroller.controller.MechJebLoaded = false;
				way = null;
				return;
			}

			core = v.GetMasterMechJeb();

			if (core == null)
			{
				SCANcontroller.controller.MechJebLoaded = false;
				way = null;
				return;
			}

			if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
			{
				if (guidanceModule == null)
					guidanceModule = (DisplayModule)core.GetComputerModule("MechJebModuleLandingGuidance");

				if (guidanceModule == null)
				{
					SCANcontroller.controller.MechJebLoaded = false;
					way = null;
					return;
				}

				if (!guidanceModule.unlockChecked)
					return;

				if (guidanceModule.hidden)
				{
					SCANcontroller.controller.MechJebLoaded = false;
					shutdown = true;
					way = null;
					return;
				}
			}

			target = core.target;

			if (target == null)
			{
				SCANcontroller.controller.MechJebLoaded = false;
				way = null;
				return;
			}

			if (!SCANcontroller.controller.MechJebLoaded)
			{
				SCANcontroller.controller.MechJebLoaded = true;
				RenderingManager.AddToPostDrawQueue(1, drawTarget);
			}

			if (SCANcontroller.controller.LandingTarget != null)
			{
				way = SCANcontroller.controller.LandingTarget;
			}

			if (SCANcontroller.controller.TargetSelecting)
			{
				way = null;
				selectingTarget = true;
				if (SCANcontroller.controller.TargetSelectingActive)
					selectingInMap = true;
				else
					selectingInMap = false;
				coords = SCANcontroller.controller.LandingTargetCoords;
				return;
			}
			else if (selectingTarget)
			{
				selectingTarget = false;
				if (selectingInMap)
				{
					selectingInMap = false;
					coords = SCANcontroller.controller.LandingTargetCoords;
					way = new SCANwaypoint(coords.y, coords.x, siteName);
					target.SetPositionTarget(SCANcontroller.controller.LandingTargetBody, way.Latitude, way.Longitude);
				}
			}

			selectingInMap = false;
			selectingTarget = false;

			if (target.Target == null)
			{
				way = null;
				return;
			}

			if (target.targetBody != v.mainBody)
			{
				way = null;
				return;
			}

			if (!(target.Target is PositionTarget))
			{
				way = null;
				return;
			}

			coords.x = target.targetLongitude;
			coords.y = target.targetLatitude;

			if (way != null)
			{
				if (!SCANUtil.ApproxEq(coords.x, way.Longitude) || !SCANUtil.ApproxEq(coords.y, way.Latitude))
				{
					way = new SCANwaypoint(coords.y, coords.x, siteName);
					SCANcontroller.controller.LandingTarget = way;
					data.addToWaypoints();
				}
			}
			else
			{
				way = new SCANwaypoint(coords.y, coords.x, siteName);
				SCANcontroller.controller.LandingTarget = way;
				data.addToWaypoints();
			}
		}
 public MechJebModuleScriptActionLanding(MechJebModuleScript scriptModule, MechJebCore core, MechJebModuleScriptActionsList actionsList) : base(scriptModule, core, actionsList, NAME)
 {
     module           = core.GetComputerModule <MechJebModuleLandingGuidance>();
     module_autopilot = core.GetComputerModule <MechJebModuleLandingAutopilot>();
     this.readModuleConfiguration();
 }