Beispiel #1
0
        public double TotalDeltaVAtmosphere()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);
            return(stats.atmoStats.Sum(s => s.deltaV));
        }
        public float TotalDeltaVVaccum()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);
            return(stats.vacStats.Sum(s => s.deltaV));
        }
Beispiel #3
0
        public string TotalDeltaVAtmosphereAndVac()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            double atmDv = stats.atmoStats.Sum(s => s.deltaV);
            double vacDv = stats.vacStats.Sum(s => s.deltaV);

            return(String.Format("{0:F0}, {1:F0}", atmDv, vacDv));
        }
Beispiel #4
0
        public string StageDeltaVAtmosphereAndVac()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            double atmDv = (stats.atmoStats.Length == 0) ? 0 : stats.atmoStats[stats.atmoStats.Length - 1].deltaV;
            double vacDv = (stats.vacStats.Length == 0) ? 0 : stats.vacStats[stats.vacStats.Length - 1].deltaV;

            return(String.Format("{0:F0}, {1:F0}", atmDv, vacDv));
        }
Beispiel #5
0
        public double StageDeltaVAtmosphere()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            if (stats.atmoStats.Length == 0)
            {
                return(0);
            }

            return(stats.atmoStats[stats.atmoStats.Length - 1].deltaV);
        }
        public float StageDeltaVVacuum()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            if (stats.vacStats.Length == 0)
            {
                return(0);
            }

            return(stats.vacStats[stats.vacStats.Length - 1].deltaV);
        }
Beispiel #7
0
        public float StageTimeLeftFullThrottle()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            if (stats.vacStats.Length == 0 || stats.atmoStats.Length == 0)
            {
                return(0);
            }

            float vacTimeLeft  = (float)stats.vacStats[stats.vacStats.Length - 1].time;
            float atmoTimeLeft = (float)stats.atmoStats[stats.atmoStats.Length - 1].time;
            float timeLeft     = Mathf.Lerp(vacTimeLeft, atmoTimeLeft, Mathf.Clamp01((float)FlightGlobals.getStaticPressure()));

            return(timeLeft);
        }
Beispiel #8
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)) && !t.IsAbstract 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.Length > 0)
            {
                dev_version = ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
            }

            if (dev_version == "")
            {
                version = string.Format("{0}.{1}.{2}", fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart);
            }
            else
            {
                version = dev_version;
            }

            if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)
            {
                print("Loading Mechjeb " + 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))
                    {
                        ConstructorInfo constructorInfo = t.GetConstructor(new[] { typeof(MechJebCore) });
                        if (constructorInfo != null)
                        {
                            AddComputerModule((ComputerModule)(constructorInfo.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>();
            antennaControl = GetComputerModule <MechJebModuleDeployableAntennaController>();
            landing        = GetComputerModule <MechJebModuleLandingAutopilot>();
            settings       = GetComputerModule <MechJebModuleSettings>();
            airplane       = GetComputerModule <MechJebModuleAirplaneAutopilot>();
            guidance       = GetComputerModule <MechJebModuleGuidanceController>();
            stageStats     = GetComputerModule <MechJebModuleStageStats>();
            stageTracking  = GetComputerModule <MechJebModuleLogicalStageTracking>();
        }
Beispiel #9
0
        public void AllStageStats()
        {
            // Unity throws an exception if we change our layout between the Layout event and
            // the Repaint event, so only get new data right before the Layout event.
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            KerbalEngineer.VesselSimulator.Stage[] vacStats  = stats.vacStats;
            KerbalEngineer.VesselSimulator.Stage[] atmoStats = stats.atmoStats;
            if (Event.current.type == EventType.Layout)
            {
                stats.RequestUpdate(this);
            }

            int numStages = atmoStats.Length;
            var stages    = Enumerable.Range(0, numStages);

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Stage stats", GUILayout.ExpandWidth(true));

            if (HighLogic.LoadedSceneIsEditor)
            {
                // We're in the VAB/SPH
                TWRbody          = GuiUtils.ComboBox.Box(TWRbody, FlightGlobals.Bodies.ConvertAll(b => b.GetName()).ToArray(), this);
                stats.editorBody = FlightGlobals.Bodies[TWRbody];
            }

            if (GUILayout.Button("All stats", GUILayout.ExpandWidth(false)))
            {
                // NK detect necessity of atmo initial TWR
                //bool hasMFE = parts.Any(p => p.IsMFE());

                if (showInitialMass)
                {
                    showInitialTWR = showAtmoInitialTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                    //showAtmoInitialTWR = hasMFE; // NK
                    showInitialMass = showFinalMass = showMaxTWR = false;
                }
                else
                {
                    showInitialMass = showInitialTWR = showAtmoInitialTWR = showMaxTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                    //showAtmoInitialTWR = hasMFE; // NK
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DrawStageStatsColumn("Stage", stages.Select(s => s.ToString()));
            if (showInitialMass)
            {
                showInitialMass = !DrawStageStatsColumn("Start mass", stages.Select(s => vacStats[s].totalMass.ToString("F1") + " t"));
            }
            if (showFinalMass)
            {
                showFinalMass = !DrawStageStatsColumn("End mass", stages.Select(s => (vacStats[s].totalMass - vacStats[s].resourceMass).ToString("F1") + " t"));
            }
            if (showInitialTWR)
            {
                showInitialTWR = !DrawStageStatsColumn("TWR", stages.Select(s => vacStats[s].thrustToWeight.ToString("F2")));
            }
            if (showAtmoInitialTWR)
            {
                showAtmoInitialTWR = !DrawStageStatsColumn("SLT", stages.Select(s => atmoStats[s].thrustToWeight.ToString("F2")));                     // NK
            }
            if (showMaxTWR)
            {
                showMaxTWR = !DrawStageStatsColumn("Max TWR", stages.Select(s => vacStats[s].maxThrustToWeight.ToString("F2")));
            }
            if (showAtmoDeltaV)
            {
                showAtmoDeltaV = !DrawStageStatsColumn("Atmo ΔV", stages.Select(s => atmoStats[s].deltaV.ToString("F0") + " m/s"));
            }
            //if (showAtmoTime) showAtmoTime = !DrawStageStatsColumn("Atmo time", stages.Select(s => GuiUtils.TimeToDHMS(atmoStats[s].time)));
            if (showVacDeltaV)
            {
                showVacDeltaV = !DrawStageStatsColumn("Vac ΔV", stages.Select(s => vacStats[s].deltaV.ToString("F0") + " m/s"));
            }
            if (showVacTime)
            {
                showVacTime = !DrawStageStatsColumn("Time", stages.Select(s => GuiUtils.TimeToDHMS(vacStats[s].time)));
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
        public void AllStageStats()
        {
            MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();

            stats.RequestUpdate(this);

            int numStages = stats.atmoStats.Length;
            var stages    = Enumerable.Range(0, numStages);

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Stage stats", GUILayout.ExpandWidth(true));
            if (GUILayout.Button("All stats", GUILayout.ExpandWidth(false)))
            {
                if (showInitialMass)
                {
                    showInitialTWR  = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                    showInitialMass = showFinalMass = showMaxTWR = false;
                }
                else
                {
                    showInitialMass = showInitialTWR = showMaxTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                }
            }
            GUILayout.EndHorizontal();

            double geeASL = (HighLogic.LoadedSceneIsEditor ? 1 : mainBody.GeeASL);

            GUILayout.BeginHorizontal();
            DrawStageStatsColumn("Stage", stages.Select(s => s.ToString()));
            if (showInitialMass)
            {
                showInitialMass = !DrawStageStatsColumn("Start mass", stages.Select(s => stats.vacStats[s].startMass.ToString("F1") + " t"));
            }
            if (showFinalMass)
            {
                showFinalMass = !DrawStageStatsColumn("End mass", stages.Select(s => stats.vacStats[s].endMass.ToString("F1") + " t"));
            }
            if (showInitialTWR)
            {
                showInitialTWR = !DrawStageStatsColumn("TWR", stages.Select(s => stats.vacStats[s].StartTWR(geeASL).ToString("F2")));
            }
            if (showMaxTWR)
            {
                showMaxTWR = !DrawStageStatsColumn("Max TWR", stages.Select(s => stats.vacStats[s].MaxTWR(geeASL).ToString("F2")));
            }
            if (showAtmoDeltaV)
            {
                showAtmoDeltaV = !DrawStageStatsColumn("Atmo ΔV", stages.Select(s => stats.atmoStats[s].deltaV.ToString("F0") + " m/s"));
            }
            if (showAtmoTime)
            {
                showAtmoTime = !DrawStageStatsColumn("Atmo time", stages.Select(s => GuiUtils.TimeToDHMS(stats.atmoStats[s].deltaTime)));
            }
            if (showVacDeltaV)
            {
                showVacDeltaV = !DrawStageStatsColumn("Vac ΔV", stages.Select(s => stats.vacStats[s].deltaV.ToString("F0") + " m/s"));
            }
            if (showVacTime)
            {
                showVacTime = !DrawStageStatsColumn("Vac time", stages.Select(s => GuiUtils.TimeToDHMS(stats.vacStats[s].deltaTime)));
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Beispiel #11
0
        public void AllStageStats()
        {
            // Unity throws an exception if we change our layout between the Layout event and
            // the Repaint event, so only get new data right before the Layout event.
            if (Event.current.type == EventType.Layout)
            {
                MechJebModuleStageStats stats = core.GetComputerModule <MechJebModuleStageStats>();
                vacStats  = stats.vacStats;
                atmoStats = stats.atmoStats;
                stats.RequestUpdate(this);
            }

            int numStages = atmoStats.Length;
            var stages    = Enumerable.Range(0, numStages);

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Stage stats", GUILayout.ExpandWidth(true));

            double geeASL;

            if (HighLogic.LoadedSceneIsEditor)
            {
                // We're in the VAB/SPH
                TWRbody = (int)GuiUtils.ArrowSelector(TWRbody, FlightGlobals.Bodies.Count, FlightGlobals.Bodies[(int)TWRbody].GetName());
                geeASL  = FlightGlobals.Bodies[TWRbody].GeeASL;
            }
            else
            {
                // We're in flight
                geeASL = mainBody.GeeASL;
            }

            if (GUILayout.Button("All stats", GUILayout.ExpandWidth(false)))
            {
                // NK detect necessity of atmo initial TWR
                bool hasMFE = false;
                if (HighLogic.LoadedSceneIsEditor)
                {
                    foreach (Part p in parts)
                    {
                        if (p.Modules.Contains("ModuleEngineConfigs") || p.Modules.Contains("ModuleHybridEngine") || p.Modules.Contains("ModuleHybridEngines"))
                        {
                            hasMFE = true;
                            break;
                        }
                    }
                }
                else
                {
                    hasMFE = vesselState.hasMFE;
                }

                if (showInitialMass)
                {
                    showInitialTWR     = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                    showAtmoInitialTWR = hasMFE; // NK
                    showInitialMass    = showFinalMass = showMaxTWR = false;
                }
                else
                {
                    showInitialMass    = showInitialTWR = showMaxTWR = showVacDeltaV = showVacTime = showAtmoDeltaV = showAtmoTime = true;
                    showAtmoInitialTWR = hasMFE; // NK
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            DrawStageStatsColumn("Stage", stages.Select(s => s.ToString()));
            if (showInitialMass)
            {
                showInitialMass = !DrawStageStatsColumn("Start mass", stages.Select(s => vacStats[s].startMass.ToString("F1") + " t"));
            }
            if (showFinalMass)
            {
                showFinalMass = !DrawStageStatsColumn("End mass", stages.Select(s => vacStats[s].endMass.ToString("F1") + " t"));
            }
            if (showInitialTWR)
            {
                showInitialTWR = !DrawStageStatsColumn("TWR", stages.Select(s => vacStats[s].StartTWR(geeASL).ToString("F2")));
            }
            if (showAtmoInitialTWR)
            {
                showAtmoInitialTWR = !DrawStageStatsColumn("SLT", stages.Select(s => atmoStats[s].StartTWR(geeASL).ToString("F2")));                     // NK
            }
            if (showMaxTWR)
            {
                showMaxTWR = !DrawStageStatsColumn("Max TWR", stages.Select(s => vacStats[s].MaxTWR(geeASL).ToString("F2")));
            }
            if (showAtmoDeltaV)
            {
                showAtmoDeltaV = !DrawStageStatsColumn("Atmo ΔV", stages.Select(s => atmoStats[s].deltaV.ToString("F0") + " m/s"));
            }
            if (showAtmoTime)
            {
                showAtmoTime = !DrawStageStatsColumn("Atmo time", stages.Select(s => GuiUtils.TimeToDHMS(atmoStats[s].deltaTime)));
            }
            if (showVacDeltaV)
            {
                showVacDeltaV = !DrawStageStatsColumn("Vac ΔV", stages.Select(s => vacStats[s].deltaV.ToString("F0") + " m/s"));
            }
            if (showVacTime)
            {
                showVacTime = !DrawStageStatsColumn("Vac time", stages.Select(s => GuiUtils.TimeToDHMS(vacStats[s].deltaTime)));
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }