Ejemplo n.º 1
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            if (!target.NormalTargetExists)
            {
                throw new OperationException("must select a target to match planes with.");
            }
            else if (o.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new OperationException("can only match planes with an object in the same sphere of influence.");
            }
            else if (timeSelector.timeReference == TimeReference.REL_ASCENDING)
            {
                if (!o.AscendingNodeExists(target.TargetOrbit))
                {
                    throw new OperationException("ascending node with target doesn't exist.");
                }
            }
            else
            {
                if (!o.DescendingNodeExists(target.TargetOrbit))
                {
                    throw new OperationException("descending node with target doesn't exist.");
                }
            }

            Vector3d dV = (timeSelector.timeReference == TimeReference.REL_ASCENDING) ?
                OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesAscending(o, target.TargetOrbit, UT, out UT):
                OrbitalManeuverCalculator.DeltaVAndTimeToMatchPlanesDescending(o, target.TargetOrbit, UT, out UT);

            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 2
0
        void LoadComputerModules()
        {
            if (moduleRegistry == null)
            {
                moduleRegistry = (from ass in AppDomain.CurrentDomain.GetAssemblies() from t in ass.GetTypes() where t.IsSubclassOf(typeof(ComputerModule)) select t).ToList();
            }

            Version v = Assembly.GetAssembly(typeof(MechJebCore)).GetName().Version;

            version = v.Major.ToString() + "." + v.Minor.ToString() + "." + v.Build.ToString();

            foreach (Type t in moduleRegistry)
            {
                if ((t != typeof(ComputerModule)) && (t != typeof(DisplayModule) && (t != typeof(MechJebModuleCustomInfoWindow))) &&
                    !blacklist.Contains(t.Name) && (GetComputerModule(t.Name) == null))
                {
                    AddComputerModule((ComputerModule)(t.GetConstructor(new Type[] { typeof(MechJebCore) }).Invoke(new object[] { this })));
                }
            }

            attitude = GetComputerModule <MechJebModuleAttitudeController>();
            staging  = GetComputerModule <MechJebModuleStagingController>();
            thrust   = GetComputerModule <MechJebModuleThrustController>();
            target   = GetComputerModule <MechJebModuleTargetController>();
            warp     = GetComputerModule <MechJebModuleWarpController>();
            rcs      = GetComputerModule <MechJebModuleRCSController>();
            rcsbal   = GetComputerModule <MechJebModuleRCSBalancer>();
            rover    = GetComputerModule <MechJebModuleRoverController>();
            node     = GetComputerModule <MechJebModuleNodeExecutor>();
        }
Ejemplo n.º 3
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            if (!target.NormalTargetExists)
            {
                throw new Exception("must select a target for the Hohmann transfer.");
            }
            else if (o.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new Exception("target for Hohmann transfer must be in the same sphere of influence.");
            }
            else if (o.eccentricity > 1)
            {
                throw new Exception("starting orbit for Hohmann transfer must not be hyperbolic.");
            }
            else if (target.TargetOrbit.eccentricity > 1)
            {
                throw new Exception("target orbit for Hohmann transfer must not be hyperbolic.");
            }
            else if (o.RelativeInclination(target.TargetOrbit) > 30 && o.RelativeInclination(target.TargetOrbit) < 150)
            {
                errorMessage = "Warning: target's orbital plane is at a " + o.RelativeInclination(target.TargetOrbit).ToString("F0") + "º angle to starting orbit's plane (recommend at most 30º). Planned transfer may not intercept target properly.";
            }
            else if (o.eccentricity > 0.2)
            {
                errorMessage = "Warning: Recommend starting Hohmann transfers from a near-circular orbit (eccentricity < 0.2). Planned transfer is starting from an orbit with eccentricity " + o.eccentricity.ToString("F2") + " and so may not intercept target properly.";
            }

            Vector3d dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, target.TargetOrbit, UT, out UT);

            return(new ManeuverParameters(dV, UT));
        }
Ejemplo n.º 4
0
        void ComputeStuff(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            errorMessage = CheckPreconditions(o, target);
            if (errorMessage == null)
            {
                errorMessage = "";
            }
            else
            {
                return;
            }

            if (worker != null)
            {
                worker.stop = true;
            }
            plot = null;

            switch (selectionMode)
            {
            case Mode.LimitedTime:
                worker = new TransferCalculator(o, target.TargetOrbit, universalTime, maxArrivalTime, minSamplingStep, includeCaptureBurn);
                break;

            case Mode.Porkchop:
                worker = new AllGraphTransferCalculator(o, target.TargetOrbit, minDepartureTime, maxDepartureTime, minTransferTime, maxTransferTime, windowWidth, porkchop_Height, includeCaptureBurn);
                break;
            }
        }
Ejemplo n.º 5
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
            var dV = OrbitalManeuverCalculator.DeltaVToShiftNodeLongitude(o, UT, target.targetLongitude);

            return new ManeuverParameters(dV, UT);
        }
		public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
		{
			// Check preconditions
			string message = CheckPreconditions(o, target);
			if (message != null)
				throw new OperationException(message);

			// Check if computation is finished
			if (worker != null && !worker.Finished)
				throw new OperationException("Computation not finished");
			if (worker == null)
			{
				ComputeStuff(o, UT, target);
				throw new OperationException("Started computation");
			}

			if (worker.result == null)
			{
				throw new OperationException("Computation failed");
			}
			if (selectionMode == Mode.Porkchop)
			{
				if (plot == null || plot.selectedPoint == null)
					throw new OperationException("Invalid point selected.");
				return TransferCalculator.OptimizeEjection(
					worker.computed[plot.selectedPoint[0], plot.selectedPoint[1]],
					o, worker.destinationOrbit,
					worker.DateFromIndex(plot.selectedPoint[0]) + worker.DurationFromIndex(plot.selectedPoint[1]),
					UT);
			}

			return worker.OptimizedResult;
		}
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            if (!target.NormalTargetExists)
                throw new OperationException("must select a target for the course correction.");

            Orbit correctionPatch = o;
            while (correctionPatch != null)
            {
                if (correctionPatch.referenceBody == target.TargetOrbit.referenceBody)
                {
                    o = correctionPatch;
                    UT = correctionPatch.StartUT;
                    break;
                }
                correctionPatch = target.core.vessel.GetNextPatch(correctionPatch);
            }

            if (correctionPatch == null || correctionPatch.referenceBody != target.TargetOrbit.referenceBody)
                throw new OperationException("target for course correction must be in the same sphere of influence");

            if (o.NextClosestApproachTime(target.TargetOrbit, UT) < UT + 1 ||
                    o.NextClosestApproachDistance(target.TargetOrbit, UT) > target.TargetOrbit.semiMajorAxis * 0.2)
            {
                errorMessage = "Warning: orbit before course correction doesn't seem to approach target very closely. Planned course correction may be extreme. Recommend plotting an approximate intercept orbit and then plotting a course correction.";
            }

            CelestialBody targetBody = target.Target as CelestialBody;
            Vector3d dV = targetBody != null ?
                OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, targetBody, targetBody.Radius + courseCorrectFinalPeA, out UT):
                OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, interceptDistance, out UT);


            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 8
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            if (!target.NormalTargetExists)
            {
                throw new OperationException("must select a target for the Hohmann transfer.");
            }
            else if (o.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new OperationException("target for Hohmann transfer must be in the same sphere of influence.");
            }
            else if (o.eccentricity > 1)
            {
                throw new OperationException("starting orbit for Hohmann transfer must not be hyperbolic.");
            }
            else if (target.TargetOrbit.eccentricity > 1)
            {
                throw new OperationException("target orbit for Hohmann transfer must not be hyperbolic.");
            }
            else if (o.RelativeInclination(target.TargetOrbit) > 30 && o.RelativeInclination(target.TargetOrbit) < 150)
            {
                errorMessage = "Warning: target's orbital plane is at a " + o.RelativeInclination(target.TargetOrbit).ToString("F0") + "º angle to starting orbit's plane (recommend at most 30º). Planned transfer may not intercept target properly.";
            }
            else if (o.eccentricity > 0.2)
            {
                errorMessage = "Warning: Recommend starting Hohmann transfers from a near-circular orbit (eccentricity < 0.2). Planned transfer is starting from an orbit with eccentricity " + o.eccentricity.ToString("F2") + " and so may not intercept target properly.";
            }

            Vector3d dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, target.TargetOrbit, UT, out UT);

            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 9
0
        void ComputeStuff(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            errorMessage = "";
            try
            {
                CheckPreconditions(o, target);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return;
            }

            if (worker != null)
            {
                worker.stop = true;
            }
            plot = null;

            switch (selectionMode)
            {
            case Mode.LimitedTime:
                // We could end up asking for parameters in the past, take a safe 10 min margin
                worker = new TransferCalculator(o, target.TargetOrbit, SafeDepartureTime(o, universalTime), maxArrivalTime, minSamplingStep);
                break;

            case Mode.Porkchop:
                worker = new AllGraphTransferCalculator(o, target.TargetOrbit, minDepartureTime, maxDepartureTime, minTransferTime, maxTransferTime, windowWidth, porkchop_Height);
                break;
            }
        }
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
            var dV = OrbitalManeuverCalculator.DeltaVToResonantOrbit(o, UT, (double)resonanceNumerator.val / resonanceDenominator.val);

            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 11
0
 public TargetInfo(MechJebModuleTargetController target)
 {
     this.mainBody    = target.mainBody;
     this.target      = target;
     targetAlt        = mainBody.TerrainAltitude(target.targetLatitude, target.targetLongitude, !mainBody.ocean);
     this.vesselState = target.vesselState;
 }
Ejemplo n.º 12
0
        private string CheckPreconditions(Orbit o, MechJebModuleTargetController target)
        {
            if (o.eccentricity >= 1 || o.ApR >= o.referenceBody.sphereOfInfluence)
            {
                return("initial orbit must not be hyperbolic");
            }

            if (!target.NormalTargetExists)
            {
                return("must select a target for the interplanetary transfer.");
            }

            if (o.referenceBody.referenceBody == null)
            {
                return("doesn't make sense to plot an interplanetary transfer from an orbit around " + o.referenceBody.theName + ".");
            }

            if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
            {
                if (o.referenceBody == target.TargetOrbit.referenceBody)
                {
                    return("use regular Hohmann transfer function to intercept another body orbiting " + o.referenceBody.theName + ".");
                }
                return("an interplanetary transfer from within " + o.referenceBody.theName + "'s sphere of influence must target a body that orbits " + o.referenceBody.theName + "'s parent, " + o.referenceBody.referenceBody.theName + ".");
            }
            return(null);
        }
		public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			_draggable = true;
			if (worker != null && !target.NormalTargetExists && Event.current.type == EventType.Layout)
			{
				worker.stop = true;
				worker = null;
				plot = null;
			}

			selectionMode = (Mode) GuiUtils.ComboBox.Box((int) selectionMode, modeNames, this);
			if (Event.current.type == EventType.Repaint)
				windowWidth = (int)GUILayoutUtility.GetLastRect().width;

			switch (selectionMode)
			{
			case Mode.LimitedTime:
				GuiUtils.SimpleTextBox("Max arrival time", maxArrivalTime);
				if (worker != null && !worker.Finished)
					GuiUtils.SimpleLabel("Computing: " + worker.Progress + "%");
				break;
			case Mode.Porkchop:
				DoPorkchopGui(o, universalTime, target);
				break;
			}

			if (worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
				ComputeTimes(o, target.TargetOrbit, universalTime);

			if (GUI.changed || worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
				ComputeStuff(o, universalTime, target);
		}
Ejemplo n.º 14
0
        void LoadComputerModules()
        {
            if (moduleRegistry == null)
            {
                moduleRegistry = new List <Type>();
                foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        foreach (var module in (from t in ass.GetTypes() where t.IsSubclassOf(typeof(ComputerModule)) select t).ToList())
                        {
                            moduleRegistry.Add(module);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("MechJeb moduleRegistry creation threw an exception in LoadComputerModules loading " + ass.FullName + ": " + e);
                    }
                }
            }

            Assembly        assembly        = Assembly.GetAssembly(typeof(MechJebCore));
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

            if (fileVersionInfo.FilePrivatePart == 0)
            {
                version = fileVersionInfo.FileMajorPart + "." + fileVersionInfo.FileMinorPart + "." + fileVersionInfo.FileBuildPart;
            }
            else
            {
                version = "Dev #" + fileVersionInfo.FilePrivatePart;
            }

            try
            {
                foreach (Type t in moduleRegistry)
                {
                    if ((t != typeof(ComputerModule)) && (t != typeof(DisplayModule) && (t != typeof(MechJebModuleCustomInfoWindow))) &&
                        !blacklist.Contains(t.Name) && (GetComputerModule(t.Name) == null))
                    {
                        AddComputerModule((ComputerModule)(t.GetConstructor(new Type[] { typeof(MechJebCore) }).Invoke(new object[] { this })));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("MechJeb moduleRegistry loading threw an exception in LoadComputerModules: " + e);
            }

            attitude = GetComputerModule <MechJebModuleAttitudeController>();
            staging  = GetComputerModule <MechJebModuleStagingController>();
            thrust   = GetComputerModule <MechJebModuleThrustController>();
            target   = GetComputerModule <MechJebModuleTargetController>();
            warp     = GetComputerModule <MechJebModuleWarpController>();
            rcs      = GetComputerModule <MechJebModuleRCSController>();
            rcsbal   = GetComputerModule <MechJebModuleRCSBalancer>();
            rover    = GetComputerModule <MechJebModuleRoverController>();
            node     = GetComputerModule <MechJebModuleNodeExecutor>();
        }
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     if (target.Target is CelestialBody)
         GuiUtils.SimpleTextBox("Approximate final periapsis", courseCorrectFinalPeA, "km");
     else
         GuiUtils.SimpleTextBox("Closest approach distance", interceptDistance, "m");
     GUILayout.Label("Schedule the burn to minimize the required ΔV.");
 }
Ejemplo n.º 16
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     intercept_only = GUILayout.Toggle(intercept_only, Localizer.Format("#MechJeb_Hohm_intercept_only")); //intercept only, no capture burn (impact/flyby)
     simpleTransfer = GUILayout.Toggle(simpleTransfer, Localizer.Format("#MechJeb_Hohm_simpleTransfer")); //simple coplanar Hohmann transfer
     GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_Hohm_Label1"), periodOffset);                      //fractional target period offset
     if (!simpleTransfer)
     {
         timeSelector.DoChooseTimeGUI();
     }
 }
Ejemplo n.º 17
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     intercept_only = GUILayout.Toggle(intercept_only, "intercept only, no capture burn (impact/flyby)");
     simpleTransfer = GUILayout.Toggle(simpleTransfer, "simple coplanar Hohmann transfer");
     GuiUtils.SimpleTextBox("fractional target period offset:", periodOffset);
     if (!simpleTransfer)
     {
         timeSelector.DoChooseTimeGUI();
     }
 }
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GUILayout.Label("Change your orbital period to " + resonanceNumerator.val + "/" + resonanceDenominator.val + " of your current orbital period");
     GUILayout.BeginHorizontal();
     GUILayout.Label("New orbital period ratio :", GUILayout.ExpandWidth(true));
     resonanceNumerator.text = GUILayout.TextField(resonanceNumerator.text, GUILayout.Width(30));
     GUILayout.Label("/", GUILayout.ExpandWidth(false));
     resonanceDenominator.text = GUILayout.TextField(resonanceDenominator.text, GUILayout.Width(30));
     GUILayout.EndHorizontal();
     timeSelector.DoChooseTimeGUI();
 }
Ejemplo n.º 19
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            if (o.inclination < 10)
                errorMessage = "Warning: orbital plane has a low inclination of " + o.inclination + "º (recommend > 10º) and so maneuver may not be accurate";

            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            var dV = OrbitalManeuverCalculator.DeltaVToShiftLAN(o, UT, target.targetLongitude);

            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 20
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GUILayout.Label("Change your orbital period to " + resonanceNumerator.val + "/" + resonanceDenominator.val + " of your current orbital period");
     GUILayout.BeginHorizontal();
     GUILayout.Label("New orbital period ratio :", GUILayout.ExpandWidth(true));
     resonanceNumerator.text = GUILayout.TextField(resonanceNumerator.text, GUILayout.Width(30));
     GUILayout.Label("/", GUILayout.ExpandWidth(false));
     resonanceDenominator.text = GUILayout.TextField(resonanceDenominator.text, GUILayout.Width(30));
     GUILayout.EndHorizontal();
     timeSelector.DoChooseTimeGUI();
 }
Ejemplo n.º 21
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
            if (o.referenceBody.Radius + newApA < o.Radius(UT))
            {
                string burnAltitude = MuUtils.ToSI(o.Radius(UT) - o.referenceBody.Radius) + "m";
                throw new OperationException("new apoapsis cannot be lower than the altitude of the burn (" + burnAltitude + ")");
            }

            return new ManeuverParameters(OrbitalManeuverCalculator.DeltaVToChangeApoapsis(o, UT, newApA + o.referenceBody.Radius), UT);
        }
Ejemplo n.º 22
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     if (target.Target is CelestialBody)
     {
         GuiUtils.SimpleTextBox("Approximate final periapsis", courseCorrectFinalPeA, "km");
     }
     else
     {
         GuiUtils.SimpleTextBox("Closest approach distance", interceptDistance, "m");
     }
     GUILayout.Label("Schedule the burn to minimize the required ΔV.");
 }
Ejemplo n.º 23
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     if (target.Target is CelestialBody)
     {
         GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_approach_label1"), courseCorrectFinalPeA, "km");//Approximate final periapsis
     }
     else
     {
         GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_approach_label2"), interceptDistance, "m"); //Closest approach distance
     }
     GUILayout.Label(Localizer.Format("#MechJeb_approach_label3"));                                    //Schedule the burn to minimize the required ΔV.
 }
Ejemplo n.º 24
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            if (!target.NormalTargetExists)
                throw new OperationException("must select a target to intercept.");
            if (o.referenceBody != target.TargetOrbit.referenceBody)
                throw new OperationException("target must be in the same sphere of influence.");

            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            var dV = OrbitalManeuverCalculator.DeltaVToInterceptAtTime(o, UT, target.TargetOrbit, UT + interceptInterval);
            return new ManeuverParameters(dV, UT);
        }
        public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            GUILayout.Label("Schedule the burn:");
            waitForPhaseAngle = GUILayout.Toggle(waitForPhaseAngle, "at the next transfer window.");
            waitForPhaseAngle = !GUILayout.Toggle(!waitForPhaseAngle, "as soon as possible");

            if (!waitForPhaseAngle)
            {
                GUIStyle s = new GUIStyle(GUI.skin.label) {normal = {textColor = Color.yellow}};
                GUILayout.Label("Using this mode voids your warranty", s);
            }
        }
Ejemplo n.º 26
0
 public ManeuverParameters MakeNode(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     errorMessage = "";
     try
     {
         return(MakeNodeImpl(o, universalTime, target));
     }
     catch (Exception e)
     {
         errorMessage = e.Message;
         return(null);
     }
 }
Ejemplo n.º 27
0
        public override List <ManeuverParameters> MakeNodesImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            // Check preconditions
            string message = CheckPreconditions(o, target);

            if (message != null)
            {
                throw new OperationException(message);
            }

            // Check if computation is finished
            if (worker != null && !worker.Finished)
            {
                throw new OperationException(Localizer.Format("#MechJeb_adv_Exception1"));//Computation not finished
            }
            if (worker == null)
            {
                ComputeStuff(o, UT, target);
                throw new OperationException(Localizer.Format("#MechJeb_adv_Exception2"));//Started computation
            }

            List <ManeuverParameters> NodeList = new List <ManeuverParameters>();

            if (worker.arrivalDate < 0)
            {
                throw new OperationException(Localizer.Format("#MechJeb_adv_Exception3"));//Computation failed
            }
            if (selectionMode == Mode.Porkchop)
            {
                if (plot == null || plot.selectedPoint == null)
                {
                    throw new OperationException(Localizer.Format("#MechJeb_adv_Exception4"));//Invalid point selected.
                }
                NodeList.Add(worker.OptimizeEjection(
                                 worker.DateFromIndex(plot.selectedPoint[0]),
                                 o, worker.destinationOrbit, target.Target as CelestialBody,
                                 worker.DateFromIndex(plot.selectedPoint[0]) + worker.DurationFromIndex(plot.selectedPoint[1]),
                                 UT)
                             );
                return(NodeList);
            }

            NodeList.Add(worker.OptimizeEjection(
                             worker.DateFromIndex(worker.bestDate),
                             o, worker.destinationOrbit, target.Target as CelestialBody,
                             worker.DateFromIndex(worker.bestDate) + worker.DurationFromIndex(worker.bestDuration),
                             UT)
                         );
            return(NodeList);
        }
        public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            GUILayout.Label(Localizer.Format("#MechJeb_transfer_Label1"));                                           //Schedule the burn:
            waitForPhaseAngle = GUILayout.Toggle(waitForPhaseAngle, Localizer.Format("#MechJeb_transfer_Label2"));   //at the next transfer window.
            waitForPhaseAngle = !GUILayout.Toggle(!waitForPhaseAngle, Localizer.Format("#MechJeb_transfer_Label3")); //as soon as possible

            if (!waitForPhaseAngle)
            {
                GUIStyle s = new GUIStyle(GUI.skin.label)
                {
                    normal = { textColor = Color.yellow }
                };
                GUILayout.Label(Localizer.Format("#MechJeb_transfer_Label4"), s);//Using this mode voids your warranty
            }
        }
Ejemplo n.º 29
0
        public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            GUILayout.Label("Schedule the burn:");
            waitForPhaseAngle = GUILayout.Toggle(waitForPhaseAngle, "at the next transfer window.");
            waitForPhaseAngle = !GUILayout.Toggle(!waitForPhaseAngle, "as soon as possible");

            if (!waitForPhaseAngle)
            {
                GUIStyle s = new GUIStyle(GUI.skin.label)
                {
                    normal = { textColor = Color.yellow }
                };
                GUILayout.Label("Using this mode voids your warranty", s);
            }
        }
Ejemplo n.º 30
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            if (2*newSMA > o.Radius(UT) + o.referenceBody.sphereOfInfluence)
            {
                errorMessage = "Warning: new Semi-Major Axis is very large, and may result in a hyberbolic orbit";
            }

            if(o.Radius(UT) > 2*newSMA)
            {
                throw new OperationException("cannot make Semi-Major Axis less than twice the burn altitude plus the radius of " + o.referenceBody.theName + "(" + MuUtils.ToSI(o.referenceBody.Radius, 3) + "m)");
            }

            return new ManeuverParameters(OrbitalManeuverCalculator.DeltaVForSemiMajorAxis (o, UT, newSMA), UT);
        }
Ejemplo n.º 31
0
        void LoadComputerModules()
        {
            if (moduleRegistry == null)
            {
                moduleRegistry = new List <Type>();
                foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        moduleRegistry.AddRange((from t in ass.GetTypes() where t.IsSubclassOf(typeof(ComputerModule)) select t).ToList());
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("MechJeb moduleRegistry creation threw an exception in LoadComputerModules loading " + ass.FullName + ": " + e);
                    }
                }
            }

            System.Version v = Assembly.GetAssembly(typeof(MechJebCore)).GetName().Version;
            version = v.Major.ToString() + "." + v.Minor.ToString() + "." + v.Build.ToString();

            try
            {
                foreach (Type t in moduleRegistry)
                {
                    if ((t != typeof(ComputerModule)) && (t != typeof(DisplayModule) && (t != typeof(MechJebModuleCustomInfoWindow))) &&
                        !blacklist.Contains(t.Name) && (GetComputerModule(t.Name) == null))
                    {
                        AddComputerModule((ComputerModule)(t.GetConstructor(new Type[] { typeof(MechJebCore) }).Invoke(new object[] { this })));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("MechJeb moduleRegistry loading threw an exception in LoadComputerModules: " + e);
            }

            attitude = GetComputerModule <MechJebModuleAttitudeController>();
            staging  = GetComputerModule <MechJebModuleStagingController>();
            thrust   = GetComputerModule <MechJebModuleThrustController>();
            target   = GetComputerModule <MechJebModuleTargetController>();
            warp     = GetComputerModule <MechJebModuleWarpController>();
            rcs      = GetComputerModule <MechJebModuleRCSController>();
            rcsbal   = GetComputerModule <MechJebModuleRCSBalancer>();
            rover    = GetComputerModule <MechJebModuleRoverController>();
            node     = GetComputerModule <MechJebModuleNodeExecutor>();
        }
Ejemplo n.º 32
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            if (o.eccentricity > 0.2)
            {
                errorMessage = "Warning: Recommend starting moon returns from a near-circular orbit (eccentricity < 0.2). Planned return is starting from an orbit with eccentricity " + o.eccentricity.ToString("F2") + " and so may not be accurate.";
            }

            if (o.referenceBody.referenceBody == null)
            {
                throw new OperationException(o.referenceBody.theName + " is not orbiting another body you could return to.");
            }

            double UT;
            Vector3d dV = OrbitalManeuverCalculator.DeltaVAndTimeForMoonReturnEjection(o, universalTime, o.referenceBody.referenceBody.Radius + moonReturnAltitude, out UT);

            return new ManeuverParameters(dV, UT);
        }
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            // Check preconditions
            string message = CheckPreconditions(o, target);

            if (message != null)
            {
                throw new OperationException(message);
            }

            // Check if computation is finished
            if (worker != null && !worker.Finished)
            {
                throw new OperationException("Computation not finished");
            }
            if (worker == null)
            {
                ComputeStuff(o, UT, target);
                throw new OperationException("Started computation");
            }

            if (worker.arrivalDate < 0)
            {
                throw new OperationException("Computation failed");
            }
            if (selectionMode == Mode.Porkchop)
            {
                if (plot == null || plot.selectedPoint == null)
                {
                    throw new OperationException("Invalid point selected.");
                }
                return(worker.OptimizeEjection(
                           worker.DateFromIndex(plot.selectedPoint[0]),
                           o, worker.destinationOrbit, target.Target as CelestialBody,
                           worker.DateFromIndex(plot.selectedPoint[0]) + worker.DurationFromIndex(plot.selectedPoint[1]),
                           UT));
            }

            return(worker.OptimizeEjection(
                       worker.DateFromIndex(worker.bestDate),
                       o, worker.destinationOrbit, target.Target as CelestialBody,
                       worker.DateFromIndex(worker.bestDate) + worker.DurationFromIndex(worker.bestDuration),
                       UT));
        }
        public override List <ManeuverParameters> MakeNodesImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            // Check preconditions
            if (!target.NormalTargetExists)
            {
                throw new OperationException(Localizer.Format("#MechJeb_transfer_Exception1"));//"must select a target for the interplanetary transfer."
            }
            if (o.referenceBody.referenceBody == null)
            {
                throw new OperationException(Localizer.Format("#MechJeb_transfer_Exception2", o.referenceBody.displayName));//doesn't make sense to plot an interplanetary transfer from an orbit around <<1>>
            }
            if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
            {
                if (o.referenceBody == target.TargetOrbit.referenceBody)
                {
                    throw new OperationException(Localizer.Format("#MechJeb_transfer_Exception3", o.referenceBody.displayName));                                                                     //use regular Hohmann transfer function to intercept another body orbiting <<1>>
                }
                throw new OperationException(Localizer.Format("#MechJeb_transfer_Exception4", o.referenceBody.displayName, o.referenceBody.displayName, o.referenceBody.referenceBody.displayName)); //"an interplanetary transfer from within "<<1>>"'s sphere of influence must target a body that orbits "<<2>>"'s parent, "<<3>>.
            }

            // Simple warnings
            if (o.referenceBody.orbit.RelativeInclination(target.TargetOrbit) > 30)
            {
                errorMessage = Localizer.Format("#MechJeb_transfer_errormsg1", o.RelativeInclination(target.TargetOrbit).ToString("F0"), o.referenceBody.displayName);//"Warning: target's orbital plane is at a"<<1>>"º angle to "<<2>>"'s orbital plane (recommend at most 30º). Planned interplanetary transfer may not intercept target properly."
            }
            else
            {
                double relativeInclination = Vector3d.Angle(o.SwappedOrbitNormal(), o.referenceBody.orbit.SwappedOrbitNormal());
                if (relativeInclination > 10)
                {
                    errorMessage = Localizer.Format("#MechJeb_transfer_errormsg2", o.referenceBody.displayName, o.referenceBody.displayName, o.referenceBody.referenceBody.displayName, o.referenceBody.displayName, relativeInclination.ToString("F1"), o.referenceBody.displayName, o.referenceBody.referenceBody.displayName);//Warning: Recommend starting interplanetary transfers from  <<1>> from an orbit in the same plane as "<<2>>"'s orbit around "<<3>>". Starting orbit around "<<4>>" is inclined "<<5>>"º with respect to "<<6>>"'s orbit around "<<7>> " (recommend < 10º). Planned transfer may not intercept target properly."
                }
                else if (o.eccentricity > 0.2)
                {
                    errorMessage = Localizer.Format("#MechJeb_transfer_errormsg3", o.eccentricity.ToString("F2"));//Warning: Recommend starting interplanetary transfers from a near-circular orbit (eccentricity < 0.2). Planned transfer is starting from an orbit with eccentricity <<1>> and so may not intercept target properly.
                }
            }

            var dV = OrbitalManeuverCalculator.DeltaVAndTimeForInterplanetaryTransferEjection(o, UT, target.TargetOrbit, waitForPhaseAngle, out UT);
            List <ManeuverParameters> NodeList = new List <ManeuverParameters>();

            NodeList.Add(new ManeuverParameters(dV, UT));
            return(NodeList);
        }
Ejemplo n.º 35
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            // Check preconditions
            if (!target.NormalTargetExists)
            {
                throw new Exception("must select a target for the interplanetary transfer.");
            }

            if (o.referenceBody.referenceBody == null)
            {
                throw new Exception("doesn't make sense to plot an interplanetary transfer from an orbit around " + o.referenceBody.theName + ".");
            }

            if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
            {
                if (o.referenceBody == target.TargetOrbit.referenceBody)
                {
                    throw new Exception("use regular Hohmann transfer function to intercept another body orbiting " + o.referenceBody.theName + ".");
                }
                throw new Exception("an interplanetary transfer from within " + o.referenceBody.theName + "'s sphere of influence must target a body that orbits " + o.referenceBody.theName + "'s parent, " + o.referenceBody.referenceBody.theName + ".");
            }

            // Simple warnings
            if (o.referenceBody.orbit.RelativeInclination(target.TargetOrbit) > 30)
            {
                errorMessage = "Warning: target's orbital plane is at a " + o.RelativeInclination(target.TargetOrbit).ToString("F0") + "º angle to " + o.referenceBody.theName + "'s orbital plane (recommend at most 30º). Planned interplanetary transfer may not intercept target properly.";
            }
            else
            {
                double relativeInclination = Vector3d.Angle(o.SwappedOrbitNormal(), o.referenceBody.orbit.SwappedOrbitNormal());
                if (relativeInclination > 10)
                {
                    errorMessage = "Warning: Recommend starting interplanetary transfers from " + o.referenceBody.theName + " from an orbit in the same plane as " + o.referenceBody.theName + "'s orbit around " + o.referenceBody.referenceBody.theName + ". Starting orbit around " + o.referenceBody.theName + " is inclined " + relativeInclination.ToString("F1") + "º with respect to " + o.referenceBody.theName + "'s orbit around " + o.referenceBody.referenceBody.theName + " (recommend < 10º). Planned transfer may not intercept target properly.";
                }
                else if (o.eccentricity > 0.2)
                {
                    errorMessage = "Warning: Recommend starting interplanetary transfers from a near-circular orbit (eccentricity < 0.2). Planned transfer is starting from an orbit with eccentricity " + o.eccentricity.ToString("F2") + " and so may not intercept target properly.";
                }
            }

            var dV = OrbitalManeuverCalculator.DeltaVAndTimeForInterplanetaryTransferEjection(o, UT, target.TargetOrbit, waitForPhaseAngle, out UT);

            return(new ManeuverParameters(dV, UT));
        }
Ejemplo n.º 36
0
 public List <ManeuverParameters> MakeNodes(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     errorMessage = "";
     try
     {
         return(MakeNodesImpl(o, universalTime, target));
     }
     catch (OperationException e)
     {
         errorMessage = e.Message;
         return(null);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
         errorMessage = Localizer.Format("#MechJeb_Maneu_errorMessage");//An error occurred while creating the node.
         return(null);
     }
 }
Ejemplo n.º 37
0
 public ManeuverParameters MakeNode(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     errorMessage = "";
     try
     {
         return(MakeNodeImpl(o, universalTime, target));
     }
     catch (OperationException e)
     {
         errorMessage = e.Message;
         return(null);
     }
     catch (Exception e)
     {
         errorMessage = "An error occurred while creating the node.";
         Log.err(e, this);
         return(null);
     }
 }
Ejemplo n.º 38
0
 public ManeuverParameters MakeNode(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     errorMessage = "";
     try
     {
         return MakeNodeImpl(o, universalTime, target);
     }
     catch (OperationException e)
     {
         errorMessage = e.Message;
         return null;
     }
     catch (Exception e)
     {
         Debug.LogException(e);
         errorMessage = "An error occurred while creating the node.";
         return null;
     }
 }
		private string CheckPreconditions(Orbit o, MechJebModuleTargetController target)
		{
			if (o.eccentricity >= 1 || o.ApR >= o.referenceBody.sphereOfInfluence)
				return "initial orbit must not be hyperbolic";

			if (!target.NormalTargetExists)
				return "must select a target for the interplanetary transfer.";

			if (o.referenceBody.referenceBody == null)
				return "doesn't make sense to plot an interplanetary transfer from an orbit around " + o.referenceBody.theName + ".";

			if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
			{
				if (o.referenceBody == target.TargetOrbit.referenceBody)
					return "use regular Hohmann transfer function to intercept another body orbiting " + o.referenceBody.theName + ".";
				return "an interplanetary transfer from within " + o.referenceBody.theName + "'s sphere of influence must target a body that orbits " + o.referenceBody.theName + "'s parent, " + o.referenceBody.referenceBody.theName + ".";
			}
			return null;
		}
Ejemplo n.º 40
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            string burnAltitude = MuUtils.ToSI(o.Radius(UT) - o.referenceBody.Radius) + "m";
            if (o.referenceBody.Radius + newPeA > o.Radius(UT))
            {
                throw new OperationException("new periapsis cannot be higher than the altitude of the burn (" + burnAltitude + ")");
            }
            else if (o.referenceBody.Radius + newApA < o.Radius(UT))
            {
                throw new OperationException("new apoapsis cannot be lower than the altitude of the burn (" + burnAltitude + ")");
            }
            else if (newPeA < -o.referenceBody.Radius)
            {
                throw new OperationException("new periapsis cannot be lower than minus the radius of " + o.referenceBody.theName + "(-" + MuUtils.ToSI(o.referenceBody.Radius, 3) + "m)");
            }

            return new ManeuverParameters(OrbitalManeuverCalculator.DeltaVToEllipticize(o, UT, newPeA + o.referenceBody.Radius, newApA + o.referenceBody.Radius), UT);
        }
Ejemplo n.º 41
0
        public override List <ManeuverParameters> MakeNodesImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {
            if (!target.NormalTargetExists)
            {
                throw new OperationException(Localizer.Format("#MechJeb_approach_Exception1"));//must select a target for the course correction.
            }
            Orbit correctionPatch = o;

            while (correctionPatch != null)
            {
                if (correctionPatch.referenceBody == target.TargetOrbit.referenceBody)
                {
                    o  = correctionPatch;
                    UT = correctionPatch.StartUT;
                    break;
                }
                correctionPatch = target.core.vessel.GetNextPatch(correctionPatch);
            }

            if (correctionPatch == null || correctionPatch.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new OperationException(Localizer.Format("#MechJeb_approach_Exception2"));//"target for course correction must be in the same sphere of influence"
            }
            if (o.NextClosestApproachTime(target.TargetOrbit, UT) < UT + 1 ||
                o.NextClosestApproachDistance(target.TargetOrbit, UT) > target.TargetOrbit.semiMajorAxis * 0.2)
            {
                errorMessage = Localizer.Format("#MechJeb_Approach_errormsg");//Warning: orbit before course correction doesn't seem to approach target very closely. Planned course correction may be extreme. Recommend plotting an approximate intercept orbit and then plotting a course correction.
            }

            CelestialBody targetBody = target.Target as CelestialBody;
            Vector3d      dV         = targetBody != null?
                                       OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, targetBody, targetBody.Radius + courseCorrectFinalPeA, out UT) :
                                           OrbitalManeuverCalculator.DeltaVAndTimeForCheapestCourseCorrection(o, UT, target.TargetOrbit, interceptDistance, out UT);


            List <ManeuverParameters> NodeList = new List <ManeuverParameters>();

            NodeList.Add(new ManeuverParameters(dV, UT));
            return(NodeList);
        }
Ejemplo n.º 42
0
        private string CheckPreconditions(Orbit o, MechJebModuleTargetController target)
        {
            if (o.eccentricity >= 1)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions1"));//initial orbit must not be hyperbolic
            }
            if (o.ApR >= o.referenceBody.sphereOfInfluence)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions2", o.referenceBody.displayName));//"initial orbit must not escape " " sphere of influence."
            }
            if (!target.NormalTargetExists)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions3")); //"must select a target for the interplanetary transfer."
            }
            if (o.referenceBody.referenceBody == null)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions4", o.referenceBody.displayName));//"doesn't make sense to plot an interplanetary transfer from an orbit around <<1>> ."
            }
            if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
            {
                if (o.referenceBody == target.TargetOrbit.referenceBody)
                {
                    return(Localizer.Format("#MechJeb_adv_Preconditions5", o.referenceBody.displayName));                                                                     //"use regular Hohmann transfer function to intercept another body orbiting <<1>>."
                }
                return(Localizer.Format("#MechJeb_adv_Preconditions6", o.referenceBody.displayName, o.referenceBody.displayName, o.referenceBody.referenceBody.displayName)); //"an interplanetary transfer from within <<1>>'s sphere of influence must target a body that orbits <<2>>'s parent,<<3>> "
            }

            if (o.referenceBody == Planetarium.fetch.Sun)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions7"));//"use regular Hohmann transfer function to intercept another body orbiting the Sun."
            }

            if (target.Target is CelestialBody && o.referenceBody == target.targetBody)
            {
                return(Localizer.Format("#MechJeb_adv_Preconditions8", o.referenceBody.displayName));//you are already orbiting <<1>>.
            }

            return(null);
        }
		void ComputeStuff(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			errorMessage = CheckPreconditions(o, target);
			if (errorMessage == null)
				errorMessage = "";
			else
				return;

			if (worker != null)
				worker.stop = true;
			plot = null;

			switch (selectionMode)
			{
			case Mode.LimitedTime:
				worker = new TransferCalculator (o, target.TargetOrbit, universalTime, maxArrivalTime, minSamplingStep);
				break;
			case Mode.Porkchop:
				worker = new AllGraphTransferCalculator(o, target.TargetOrbit, minDepartureTime, maxDepartureTime, minTransferTime, maxTransferTime, windowWidth, porkchop_Height);
				break;
			}
		}
        public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
        {

            // Check preconditions
            if (!target.NormalTargetExists)
                throw new OperationException("must select a target for the interplanetary transfer.");

            if (o.referenceBody.referenceBody == null)
                throw new OperationException("doesn't make sense to plot an interplanetary transfer from an orbit around " + o.referenceBody.theName + ".");

            if (o.referenceBody.referenceBody != target.TargetOrbit.referenceBody)
            {
                if (o.referenceBody == target.TargetOrbit.referenceBody)
                    throw new OperationException("use regular Hohmann transfer function to intercept another body orbiting " + o.referenceBody.theName + ".");
                throw new OperationException("an interplanetary transfer from within " + o.referenceBody.theName + "'s sphere of influence must target a body that orbits " + o.referenceBody.theName + "'s parent, " + o.referenceBody.referenceBody.theName + ".");
            }

            // Simple warnings
            if (o.referenceBody.orbit.RelativeInclination(target.TargetOrbit) > 30)
            {
                errorMessage = "Warning: target's orbital plane is at a " + o.RelativeInclination(target.TargetOrbit).ToString("F0") + "º angle to " + o.referenceBody.theName + "'s orbital plane (recommend at most 30º). Planned interplanetary transfer may not intercept target properly.";
            }
            else
            {
                double relativeInclination = Vector3d.Angle(o.SwappedOrbitNormal(), o.referenceBody.orbit.SwappedOrbitNormal());
                if (relativeInclination > 10)
                {
                    errorMessage = "Warning: Recommend starting interplanetary transfers from " + o.referenceBody.theName + " from an orbit in the same plane as " + o.referenceBody.theName + "'s orbit around " + o.referenceBody.referenceBody.theName + ". Starting orbit around " + o.referenceBody.theName + " is inclined " + relativeInclination.ToString("F1") + "º with respect to " + o.referenceBody.theName + "'s orbit around " + o.referenceBody.referenceBody.theName + " (recommend < 10º). Planned transfer may not intercept target properly.";
                }
                else if (o.eccentricity > 0.2)
                {
                    errorMessage = "Warning: Recommend starting interplanetary transfers from a near-circular orbit (eccentricity < 0.2). Planned transfer is starting from an orbit with eccentricity " + o.eccentricity.ToString("F2") + " and so may not intercept target properly.";
                }
            }

            var dV = OrbitalManeuverCalculator.DeltaVAndTimeForInterplanetaryTransferEjection(o, UT, target.TargetOrbit, waitForPhaseAngle, out UT);
            return new ManeuverParameters(dV, UT);
        }
Ejemplo n.º 45
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GuiUtils.SimpleTextBox("New inclination:", newInc, "º");
     timeSelector.DoChooseTimeGUI();
 }
Ejemplo n.º 46
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            if (o.referenceBody.Radius + newApA < o.Radius(UT))
            {
                string burnAltitude = MuUtils.ToSI(o.Radius(UT) - o.referenceBody.Radius) + "m";
                throw new OperationException(Localizer.Format("#MechJeb_Ap_Exception", burnAltitude));//new apoapsis cannot be lower than the altitude of the burn (<<1>>)
            }

            return(new ManeuverParameters(OrbitalManeuverCalculator.DeltaVToChangeApoapsis(o, UT, newApA + o.referenceBody.Radius), UT));
        }
Ejemplo n.º 47
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_Ap_label1"), newApA, "km");//New apoapsis:
     timeSelector.DoChooseTimeGUI();
 }
		private void DoPorkchopGui(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			if (worker == null)
				return;
			string dv = " - ";
			string departure = " - ";
			string duration = " - ";
			if (worker.Finished && worker.computed.GetLength(1) == porkchop_Height)
			{
				if (plot == null && Event.current.type == EventType.Layout)
				{
					plot = new PlotArea(
						worker.minDepartureTime,
						worker.maxDepartureTime,
						worker.minTransferTime,
						worker.maxTransferTime,
						new Porkchop(worker.computed).texture,
						(xmin, xmax, ymin, ymax) => {
							minDepartureTime = Math.Max(xmin, universalTime);
							maxDepartureTime = xmax;
							minTransferTime = Math.Max(ymin, 3600);
							maxTransferTime = ymax;
							GUI.changed = true;
						});
					plot.selectedPoint = new int[]{worker.bestDate, worker.bestDuration};
				}
			}
			if (plot != null)
			{
				var point = plot.selectedPoint;
				if (plot.hoveredPoint != null)
					point = plot.hoveredPoint;

				var p = worker.computed[point[0], point[1]];
				if (p != null)
				{
					dv = MuUtils.ToSI(p.dV.magnitude) + "m/s";
					if (worker.DateFromIndex(point[0]) < Planetarium.GetUniversalTime())
						departure = "any time now";
					else
						departure = GuiUtils.TimeToDHMS(worker.DateFromIndex(point[0]) - Planetarium.GetUniversalTime());
					duration = GuiUtils.TimeToDHMS(worker.DurationFromIndex(point[1]));
				}
				plot.DoGUI();
				if (!plot.draggable) _draggable = false;
			}
			else
			{
				GUIStyle progressStyle = new GUIStyle
				{
					font = GuiUtils.skin.font,
					fontSize = GuiUtils.skin.label.fontSize,
					fontStyle = GuiUtils.skin.label.fontStyle,
					normal = {textColor = GuiUtils.skin.label.normal.textColor}
				};

				GUILayout.Box("Computing: " + worker.Progress + "%", progressStyle, new GUILayoutOption[] {
					GUILayout.Width(windowWidth),
					GUILayout.Height(porkchop_Height)});
			}
			GUILayout.BeginHorizontal();
			GUILayout.Label("ΔV: " + dv);
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Reset", GuiUtils.yellowOnHover))
				ComputeTimes(o, target.TargetOrbit, universalTime);
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			GUILayout.Label("Select: ");
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Lowest ΔV"))
			{
				plot.selectedPoint = new int[]{ worker.bestDate, worker.bestDuration };
				GUI.changed = false;
			}

			if (GUILayout.Button("ASAP"))
			{
				int bestDuration = 0;
				for (int i = 1; i < worker.computed.GetLength(1); i++)
				{
					if (worker.computed[0, bestDuration].dV.sqrMagnitude > worker.computed[0, i].dV.sqrMagnitude)
						bestDuration = i;
				}
				plot.selectedPoint = new int[]{ 0, bestDuration };
				GUI.changed = false;
			}
			GUILayout.EndHorizontal();

			GUILayout.Label("Departure in " + departure);
			GUILayout.Label("Transit duration " + duration);
		}
Ejemplo n.º 49
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GuiUtils.SimpleTextBox("New periapsis:", newPeA, "km");
     timeSelector.DoChooseTimeGUI();
 }
Ejemplo n.º 50
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();
			}
		}
Ejemplo n.º 51
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     GuiUtils.SimpleTextBox("Approximate final periapsis:", moonReturnAltitude, "km");
     GUILayout.Label("Schedule the burn at the next return window.");
 }
Ejemplo n.º 52
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);

            return new ManeuverParameters(OrbitalManeuverCalculator.DeltaVToChangeInclination(o, UT, newInc), UT);
        }
Ejemplo n.º 53
0
 // Draw the parameter part of the Operation (ask for time, altitudes etc)
 // Input parameters are orbit and time parameters after the last maneuver and current target
 public abstract void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target);
Ejemplo n.º 54
0
 // Function called when create node is pressed; input parameters are orbit and time parameters after the last maneuver and current target
 // ManeuverParameters contain a single time and dV describing the node that should be executed
 // In case of error you can throw an OperationException, the message will be displayed and no node will be created.
 public abstract ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target);
		public override ManeuverParameters MakeNodeImpl(Orbit o, double UT, MechJebModuleTargetController target)
		{
			// Check preconditions
			string message = CheckPreconditions(o, target);
			if (message != null)
				throw new OperationException(message);

			// Check if computation is finished
			if (worker != null && !worker.Finished)
				throw new OperationException("Computation not finished");
			if (worker == null)
			{
				ComputeStuff(o, UT, target);
				throw new OperationException("Started computation");
			}

			if (worker.result == null)
			{
				throw new OperationException("Computation failed");
			}
			if (selectionMode == Mode.Porkchop)
			{
				if (plot == null || plot.selectedPoint == null)
					throw new OperationException("Invalid point selected.");
				return TransferCalculator.OptimizeEjection(
					worker.computed[plot.selectedPoint[0], plot.selectedPoint[1]],
					o, worker.destinationOrbit,
					worker.DateFromIndex(plot.selectedPoint[0]) + worker.DurationFromIndex(plot.selectedPoint[1]),
					UT);
			}

			return worker.OptimizedResult;
		}
Ejemplo n.º 56
0
        public double ComputeManeuverTime(Orbit o, double UT, MechJebModuleTargetController target)
        {
            switch (allowedTimeRef[currentTimeRef])
            {
            case TimeReference.X_FROM_NOW:
                UT += leadTime.val;
                break;

            case TimeReference.APOAPSIS:
                if (o.eccentricity < 1)
                {
                    UT = o.NextApoapsisTime(UT);
                }
                else
                {
                    throw new OperationException("Warning: orbit is hyperbolic, so apoapsis doesn't exist.");
                }
                break;

            case TimeReference.PERIAPSIS:
                UT = o.NextPeriapsisTime(UT);
                break;

            case TimeReference.CLOSEST_APPROACH:
                if (target.NormalTargetExists)
                {
                    UT = o.NextClosestApproachTime(target.TargetOrbit, UT);
                }
                else
                {
                    throw new OperationException("Warning: no target selected.");
                }
                break;

            case TimeReference.ALTITUDE:
                if (circularizeAltitude > o.PeA && (circularizeAltitude < o.ApA || o.eccentricity >= 1))
                {
                    UT = o.NextTimeOfRadius(UT, o.referenceBody.Radius + circularizeAltitude);
                }
                else
                {
                    throw new OperationException("Warning: can't circularize at this altitude, since current orbit does not reach it.");
                }
                break;

            case TimeReference.EQ_ASCENDING:
                if (o.AscendingNodeEquatorialExists())
                {
                    UT = o.TimeOfAscendingNodeEquatorial(UT);
                }
                else
                {
                    throw new OperationException("Warning: equatorial ascending node doesn't exist.");
                }
                break;

            case TimeReference.EQ_DESCENDING:
                if (o.DescendingNodeEquatorialExists())
                {
                    UT = o.TimeOfDescendingNodeEquatorial(UT);
                }
                else
                {
                    throw new OperationException("Warning: equatorial descending node doesn't exist.");
                }
                break;
            
            case TimeReference.EQ_NEAREST_AD:
                if(o.AscendingNodeEquatorialExists())
                {
                    UT = o.DescendingNodeEquatorialExists()
                        ? System.Math.Min(o.TimeOfAscendingNodeEquatorial(UT), o.TimeOfDescendingNodeEquatorial(UT))
                        : o.TimeOfAscendingNodeEquatorial(UT);
                }
                else if(o.DescendingNodeEquatorialExists())
                {
                    UT = o.TimeOfDescendingNodeEquatorial(UT);
                }
                else
                {
                    throw new OperationException("Warning: neither ascending nor descending node exists.");
                }
                break;

            case TimeReference.EQ_HIGHEST_AD:
                if(o.AscendingNodeEquatorialExists())
                {
                    if(o.DescendingNodeEquatorialExists())
                    {
                        var anTime = o.TimeOfAscendingNodeEquatorial(UT);
                        var dnTime = o.TimeOfDescendingNodeEquatorial(UT);
                        UT = o.getOrbitalVelocityAtUT(anTime).magnitude <= o.getOrbitalVelocityAtUT(dnTime).magnitude
                            ? anTime
                            : dnTime;
                    }
                    else
                    {
                        UT = o.TimeOfAscendingNodeEquatorial(UT);
                    }
                }
                else if(o.DescendingNodeEquatorialExists())
                {
                    UT = o.TimeOfDescendingNodeEquatorial(UT);
                }
                else
                {
                    throw new OperationException("Warning: neither ascending nor descending node exists.");
                }
                break;
            }

            universalTime = UT;
            return universalTime;
        }
Ejemplo n.º 57
0
        void LoadComputerModules()
        {
            if (moduleRegistry == null)
            {
                moduleRegistry = new List <Type>();
                foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try
                    {
                        foreach (var module in (from t in ass.GetTypes() where t.IsSubclassOf(typeof(ComputerModule)) select t).ToList())
                        {
                            moduleRegistry.Add(module);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("MechJeb moduleRegistry creation threw an exception in LoadComputerModules loading " + ass.FullName + ": " + e);
                    }
                }
            }

            Assembly        assembly        = Assembly.GetExecutingAssembly();
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

            // Mono compiler is stupid and use AssemblyVersion for the AssemblyFileVersion
            // So we use an other field to store the dev build number ...
            Attribute[] attributes  = Attribute.GetCustomAttributes(assembly, typeof(AssemblyInformationalVersionAttribute));
            string      dev_version = "";

            if (attributes != null && attributes.Length != 0)
            {
                dev_version = ((AssemblyInformationalVersionAttribute)(attributes[0])).InformationalVersion;
            }

            if (dev_version == "")
            {
                version = fileVersionInfo.FileMajorPart + "." + fileVersionInfo.FileMinorPart + "." + fileVersionInfo.FileBuildPart;
            }
            else
            {
                version = dev_version;
            }

            try
            {
                foreach (Type t in moduleRegistry)
                {
                    if ((t != typeof(ComputerModule)) && (t != typeof(DisplayModule) && (t != typeof(MechJebModuleCustomInfoWindow))) &&
                        (t != typeof(AutopilotModule)) &&
                        !blacklist.Contains(t.Name) && (GetComputerModule(t.Name) == null))
                    {
                        AddComputerModule((ComputerModule)(t.GetConstructor(new Type[] { typeof(MechJebCore) }).Invoke(new object[] { this })));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("MechJeb moduleRegistry loading threw an exception in LoadComputerModules: " + e);
            }

            attitude   = GetComputerModule <MechJebModuleAttitudeController>();
            staging    = GetComputerModule <MechJebModuleStagingController>();
            thrust     = GetComputerModule <MechJebModuleThrustController>();
            target     = GetComputerModule <MechJebModuleTargetController>();
            warp       = GetComputerModule <MechJebModuleWarpController>();
            rcs        = GetComputerModule <MechJebModuleRCSController>();
            rcsbal     = GetComputerModule <MechJebModuleRCSBalancer>();
            rover      = GetComputerModule <MechJebModuleRoverController>();
            node       = GetComputerModule <MechJebModuleNodeExecutor>();
            solarpanel = GetComputerModule <MechJebModuleSolarPanelController>();
            landing    = GetComputerModule <MechJebModuleLandingAutopilot>();
        }
Ejemplo n.º 58
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     timeSelector.DoChooseTimeGUI();
 }
Ejemplo n.º 59
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
            var    dV = OrbitalManeuverCalculator.DeltaVToResonantOrbit(o, UT, (double)resonanceNumerator.val / resonanceDenominator.val);

            return(new ManeuverParameters(dV, UT));
        }
Ejemplo n.º 60
0
 public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
 {
     timeSelector.DoChooseTimeGUI();
     GUILayout.Label("New Surface Longitude after one orbit:");
     target.targetLongitude.DrawEditGUI(EditableAngle.Direction.EW);
 }