コード例 #1
0
ファイル: VesselData.cs プロジェクト: zajc3w/OrbitalDecay
 public void OnDestroy()
 {
     if (DecayManager.CheckSceneStateMain(HighLogic.LoadedScene))
     {
         if ((Planetarium.GetUniversalTime() == HighLogic.CurrentGame.UniversalTime) || HighLogic.LoadedScene == GameScenes.FLIGHT)
         {
             print("WhitecatIndustries - Orbital Decay - Vessel Information saved. Ondestroy");
             File.ClearNodes();
             VesselInformation.Save(FilePath);
             // VesselInformation.ClearNodes();
         }
     }
 }
コード例 #2
0
        /*
         * public void NBodyManagerWindow(int id) // 1.6.0
         * {
         *  if (GUI.Button(new Rect(NBodyManagerwindowPosition.width - 22, 3, 19, 19), "x"))
         *  {
         *      if (NBodyBreakdownVisible != null)
         *          NBodyBreakdownVisible = false;
         *  }
         *  GUILayout.BeginVertical();
         *  GUILayout.Space(10);
         *
         *  /*
         *  if (NBodyVesselAccelTimes.ContainsKey(subwindowVessel)) // 1.6.0 Lag Busting
         *  {
         *      double StoredTime = 0;
         *      NBodyVesselAccelTimes.TryGetValue(subwindowVessel, out StoredTime);
         *      print("StoredTime " + StoredTime);
         *
         *      if (HighLogic.CurrentGame.UniversalTime > (StoredTime + 1.0))
         *      {
         *          NBodyMomentaryDeltaV = NBodyManager.GetMomentaryDeltaV(subwindowVessel, HighLogic.CurrentGame.UniversalTime);
         *          NBodyVesselAccelTimes.Remove(subwindowVessel);
         *          NBodyVesselAccelTimes.Add(subwindowVessel, HighLogic.CurrentGame.UniversalTime);
         *      }
         *  }
         *
         *  else
         *  {
         *      NBodyVesselAccelTimes.Add(subwindowVessel, HighLogic.CurrentGame.UniversalTime);
         *      NBodyMomentaryDeltaV = NBodyManager.GetMomentaryDeltaV(subwindowVessel, HighLogic.CurrentGame.UniversalTime);
         *  }
         * */
        /*
         *  try
         *  {
         *      NBodyMomentaryDeltaV = NBodyManager.GetMomentaryDeltaV(subwindowVessel, HighLogic.CurrentGame.UniversalTime);
         *  }
         *
         *  catch (NullReferenceException)
         *  {
         *      NBodyMomentaryDeltaV = new Vector3d(0, 0, 0) ;
         *  }
         *
         *  try
         *  {
         *      Vessel vessel = subwindowVessel;
         *
         *      GUILayout.Label("Vessel: " + vessel.GetName());
         *      GUILayout.Space(4); // Make new parsing here for vel formatting
         *      GUILayout.Label("Total Change in velocity from external forces: " + (NBodyMomentaryDeltaV.x + NBodyMomentaryDeltaV.y + NBodyMomentaryDeltaV.z).ToString("F9") + "m/s");
         *      GUILayout.Space(2);
         *      GUILayout.Label("Change in velocity from external forces (Prograde): " + NBodyMomentaryDeltaV.x.ToString("F9") + "m/s");
         *      GUILayout.Space(2);
         *      GUILayout.Label("Change in velocity from external forces (Normal): " + NBodyMomentaryDeltaV.y.ToString("F9") + "m/s");
         *      GUILayout.Space(2);
         *      GUILayout.Label("Change in velocity from external forces (Radial): " + NBodyMomentaryDeltaV.z.ToString("F9")+ "m/s");
         *      GUILayout.Space(2);
         *
         *
         *  }
         *
         *  catch (ArgumentNullException)
         *  {
         *      GUILayout.Label("WARNING: Error Detected");
         *      GUILayout.Space(2);
         *      GUILayout.Label("Please post an error report in the Orbital Decay Forum. This is an N-Body problem.");
         *      GUILayout.Space(2);
         *      GUILayout.Label("Thanks, Whitecat106");
         *  }
         *  GUILayout.EndVertical();
         *  GUI.DragWindow();
         *  //NBodyManagerwindowPosition.x = Mathf.Clamp(MainwindowPosition.x, 0f, Screen.width - MainwindowPosition.width);
         *  //NBodyManagerwindowPosition.y = Mathf.Clamp(MainwindowPosition.y, 0f, Screen.height - MainwindowPosition.height);
         *
         * }
         */

        public void DecayBreakdownWindow(int id)
        {
            if (GUI.Button(new Rect(DecayBreakdownwindowPosition.width - 22, 3, 19, 19), "x"))
            {
                if (DecayBreakdownVisible)
                {
                    DecayBreakdownVisible = false;
                }
            }
            GUILayout.BeginVertical();
            GUILayout.Space(10);
            try
            {
                Vessel vessel  = subwindowVessel;
                double ADDR    = DecayManager.DecayRateAtmosphericDrag(vessel);
                double GPDR    = DecayManager.DecayRateGravitationalPertubation(vessel);
                double GPIDR   = MasConManager.GetSecularIncChange(vessel, vessel.orbitDriver.orbit.LAN, vessel.orbitDriver.orbit.meanAnomaly, vessel.orbitDriver.orbit.argumentOfPeriapsis, vessel.orbitDriver.orbit.eccentricity, vessel.orbitDriver.orbit.inclination, vessel.orbitDriver.orbit.semiMajorAxis, vessel.orbitDriver.orbit.epoch);
                double GPLANDR = MasConManager.GetSecularLANChange(vessel, vessel.orbitDriver.orbit.LAN, vessel.orbitDriver.orbit.meanAnomaly, vessel.orbitDriver.orbit.argumentOfPeriapsis, vessel.orbitDriver.orbit.eccentricity, vessel.orbitDriver.orbit.inclination, vessel.orbitDriver.orbit.semiMajorAxis, vessel.orbitDriver.orbit.epoch);
                double PRDR    = DecayManager.DecayRateRadiationPressure(vessel);
                double YEDR    = DecayManager.DecayRateYarkovskyEffect(vessel);


                GUILayout.Label("Vessel: " + vessel.GetName());
                GUILayout.Space(4);
                GUILayout.Label("Atmospheric Drag Decay Rate (Delta SMA): " + FormatDecayRateToString(ADDR));
                GUILayout.Space(2);
                GUILayout.Label("Radiation Pressure Decay Rate (Delta SMA): " + FormatDecayRateToString(PRDR));
                GUILayout.Space(2);
                GUILayout.Label("Gravitational Effect Decay Rate (Delta SMA): " + FormatDecayRateToString(GPDR));
                GUILayout.Space(2);
                GUILayout.Label("Gravitational Effect Decay Rate (Delta INC): " + FormatDecayRateDegreesToString(GPIDR));
                GUILayout.Space(2);
                GUILayout.Label("Gravitational Effect Decay Rate (Delta LAN): " + FormatDecayRateDegreesToString(GPLANDR));
                GUILayout.Space(2);
                GUILayout.Label("Yarkovsky Effect Decay Rate (Delta SMA): " + FormatDecayRateSmallToString(YEDR));
                GUILayout.Space(2);
                GUILayout.Label("Note: Prediction estimates accurate to +/- 10% per day.");
            }
            catch (ArgumentNullException)
            {
                GUILayout.Label("WARNING: Error detected, this is a MasCon issue, this will not effect gameplay.");
                GUILayout.Space(2);
                GUILayout.Label("Please make a note of your vessel latitude and longitude and reference body and post in the Orbital Decay Forum.");
                GUILayout.Space(2);
                GUILayout.Label("Thanks, Whitecat106");
            }
            GUILayout.EndVertical();
            GUI.DragWindow();
            //MainwindowPosition.x = Mathf.Clamp(MainwindowPosition.x, 0f, Screen.width - MainwindowPosition.width);
            //MainwindowPosition.y = Mathf.Clamp(MainwindowPosition.y, 0f, Screen.height - MainwindowPosition.height);
        }
コード例 #3
0
        public double GetMaximumPossibleLifetime()
        {
            double Lifetime = 0;

            Part[] constructParts = EditorLogic.RootPart.FindChildParts <Part>();
            constructParts.AddUnique(EditorLogic.RootPart);

            foreach (Part p in constructParts)
            {
                Dictionary <string, double> UsableFuels = new Dictionary <string, double>();
                Dictionary <string, double> FuelRatios  = new Dictionary <string, double>();

                if (GetEfficiencyEng(p) != 0)
                {
                    for (int i = 0; i < GetResources().Count; i++)
                    {
                        foreach (Propellant pro in p.FindModuleImplementing <ModuleEngines>().propellants)
                        {
                            if (pro.ToString() == GetResources().ElementAt(i))
                            {
                                // Blah blah blah
                                UsableFuels.Add(pro.ToString(), pro.totalResourceCapacity);
                                FuelRatios.Add(pro.ToString(), pro.ratio);

                                double ResEff     = 1.0 / GetEfficiencyEng(p);
                                bool   ClockType  = Settings.Read24Hr();
                                double HoursInDay = 6;

                                if (ClockType)
                                {
                                    HoursInDay = 24.0;
                                }
                                else
                                {
                                    HoursInDay = 6.0;
                                }

                                Lifetime = Lifetime + pro.totalResourceCapacity / (DecayManager.EditorDecayRateRadiationPressure(CalculateMass(), CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody) * ResEff * Settings.ReadResourceRateDifficulty()) / (60 * 60 * HoursInDay);
                            }
                        }
                    }
                }
            }

            return(Lifetime);
        }
コード例 #4
0
        public static void OnQuickSave()
        {
            if (DecayManager.CheckSceneStateMain(HighLogic.LoadedScene))
            {
                if (Planetarium.GetUniversalTime() == HighLogic.CurrentGame.UniversalTime || HighLogic.LoadedScene == GameScenes.FLIGHT)
                {
                    print("WhitecatIndustries - Orbital Decay - Vessel Information saved.");
                    SaveVesselInformation();
#if false
                    File.ClearNodes();
                    VesselInformation.Save(FilePath);
                    VesselInformation.ClearNodes();
#endif
                    print("WhitecatIndustries - Orbital Decay - Vessel Information lost OnQuickSave");
                }
            }
        }
コード例 #5
0
        public void InformationTab()
        {
            GUILayout.BeginHorizontal();
            GUI.skin.label.fontSize  = 16;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Vessel Information", GUILayout.Width(290));
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            GUI.skin.label.fontSize  = 12;
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical();

            // 1.5.2 Filtering //

            GUILayout.Space(3);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_unmannedtech", false)))
            {
                if (FilterTypes.Contains(VesselType.Probe))
                {
                    FilterTypes.Remove(VesselType.Probe);
                }

                else
                {
                    FilterTypes.Add(VesselType.Probe);
                }
            }

            GUILayout.Space(3);
            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advunmanned", false)))
            {
                if (FilterTypes.Contains(VesselType.Relay))
                {
                    FilterTypes.Remove(VesselType.Relay);
                }

                else
                {
                    FilterTypes.Add(VesselType.Relay);
                }
            }

            GUILayout.Space(3);

            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/RDicon_commandmodules", false)))
            {
                if (FilterTypes.Contains(VesselType.Ship))
                {
                    FilterTypes.Remove(VesselType.Ship);
                }

                else
                {
                    FilterTypes.Add(VesselType.Ship);
                }
            }

            GUILayout.Space(3);

            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_specializedconstruction", false)))
            {
                if (FilterTypes.Contains(VesselType.Station))
                {
                    FilterTypes.Remove(VesselType.Station);
                }

                else
                {
                    FilterTypes.Add(VesselType.Station);
                }
            }

            GUILayout.Space(3);

            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/RDicon_telescope", false)))
            {
                if (FilterTypes.Contains(VesselType.SpaceObject))
                {
                    FilterTypes.Remove(VesselType.SpaceObject);
                }

                else
                {
                    FilterTypes.Add(VesselType.SpaceObject);
                }

                if (FilterTypes.Contains(VesselType.Unknown))
                {
                    FilterTypes.Remove(VesselType.Unknown);
                }

                else
                {
                    FilterTypes.Add(VesselType.Unknown);
                }
            }

            GUILayout.Space(3);

            if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_composites", false)))
            {
                if (FilterTypes.Contains(VesselType.Debris))
                {
                    FilterTypes.Remove(VesselType.Debris);
                }

                else
                {
                    FilterTypes.Add(VesselType.Debris);
                }
            }

            GUILayout.Space(3);


            GUILayout.EndHorizontal();
            GUILayout.Space(3);
            GUILayout.Label("_______________________________________");
            GUILayout.EndVertical();

            scrollPosition1 = GUILayout.BeginScrollView(scrollPosition1, GUILayout.Width(290), GUILayout.Height(350));
            bool Realistic = Settings.ReadRD();
            bool ClockType = Settings.Read24Hr();

            //151var Resource = Settings.ReadStationKeepingResource();

            foreach (Vessel vessel in FlightGlobals.Vessels)
            {
                if (FilterTypes.Contains(vessel.vesselType))
                {
                    if (vessel.situation == Vessel.Situations.ORBITING)
                    {
                        string StationKeeping = VesselData.FetchStationKeeping(vessel).ToString();
                        string StationKeepingFuelRemaining = ResourceManager.GetResources(vessel).ToString("F3");
                        string Resource   = ResourceManager.GetResourceNames(vessel);
                        string ButtonText = "";
                        double HoursInDay = 6.0;

                        double DaysInYear = 0;
                        bool   KerbinTime = GameSettings.KERBIN_TIME;

                        if (KerbinTime)
                        {
                            DaysInYear = 9203545 / (60 * 60 * HoursInDay);
                        }
                        else
                        {
                            DaysInYear = 31557600 / (60 * 60 * HoursInDay);
                        }


                        if (StationKeeping == "True")
                        {
                            ButtonText = "Disable Station Keeping";
                        }
                        else
                        {
                            ButtonText = "Enable Station Keeping";
                        }

                        if (ClockType)
                        {
                            HoursInDay = 24.0;
                        }
                        else
                        {
                            HoursInDay = 6.0;
                        }

                        GUILayout.BeginVertical();
                        //   GUILayout.Label("Vessels count" + VesselData.VesselInformation.CountNodes.ToString());
                        GUILayout.Label("Vessel Name: " + vessel.vesselName);
                        //    GUILayout.Label("Vessel Area: " + VesselData.FetchArea(vessel).ToString());
                        //    GUILayout.Label("Vessel Mass: " + VesselData.FetchMass(vessel).ToString());
                        GUILayout.Space(2);
                        GUILayout.Label("Orbiting Body: " + vessel.orbitDriver.orbit.referenceBody.GetName());
                        GUILayout.Space(2);

                        if (StationKeeping == "True")
                        {
                            GUILayout.Label("Current Total Decay Rate: Vessel is Station Keeping");
                            GUILayout.Space(2);
                        }
                        else
                        {
                            double TotalDecayRatePerSecond = Math.Abs(DecayManager.DecayRateAtmosphericDrag(vessel)) + Math.Abs(DecayManager.DecayRateRadiationPressure(vessel)) + Math.Abs(DecayManager.DecayRateYarkovskyEffect(vessel)); //+ Math.Abs(DecayManager.DecayRateGravitationalPertubation(vessel));
                            double ADDR = DecayManager.DecayRateAtmosphericDrag(vessel);
                            double GPDR = DecayManager.DecayRateGravitationalPertubation(vessel);
                            double PRDR = DecayManager.DecayRateRadiationPressure(vessel);
                            double YEDR = DecayManager.DecayRateYarkovskyEffect(vessel);

                            GUILayout.Label("Current Total Decay Rate: " + FormatDecayRateToString(TotalDecayRatePerSecond));
                            GUILayout.Space(2);

                            if (GUILayout.Button("Toggle Decay Rate Breakdown")) // Display a new window here?
                            {
                                subwindowVessel       = vessel;
                                DecayBreakdownVisible = !DecayBreakdownVisible;
                            }

                            // 1.7.0 maybe?
                            if (Settings.ReadNB())
                            {
                                GUILayout.Space(2);
                                if (GUILayout.Button("Toggle NBody Breakdown")) // New Window for NBody
                                {
                                    subwindowVessel = vessel;
                                    NBodyVesselAccelTimes.Clear();
                                    NBodyBreakdownVisible = !NBodyBreakdownVisible;
                                }
                            }


                            GUILayout.Space(2);

                            double TimeUntilDecayInUnits = 0.0;
                            string TimeUntilDecayInDays  = "";

                            if (ADDR != 0)
                            {
                                TimeUntilDecayInUnits = DecayManager.DecayTimePredictionExponentialsVariables(vessel);
                                TimeUntilDecayInDays  = FormatTimeUntilDecayInDaysToString(TimeUntilDecayInUnits);
                            }
                            else
                            {
                                TimeUntilDecayInUnits = DecayManager.DecayTimePredictionLinearVariables(vessel);
                                TimeUntilDecayInDays  = FormatTimeUntilDecayInSecondsToString(TimeUntilDecayInUnits);
                            }

                            GUILayout.Label("Approximate Time Until Decay: " + TimeUntilDecayInDays);
                            GUILayout.Space(2);
                        }

                        GUILayout.Label("Station Keeping: " + StationKeeping);
                        GUILayout.Space(2);
                        GUILayout.Label("Station Keeping Fuel Remaining: " + StationKeepingFuelRemaining);
                        GUILayout.Space(2);
                        GUILayout.Label("Using Fuel Type: " + Resource); //151
                        GUILayout.Space(2);                              //151

                        if (StationKeeping == "True")
                        {
                            double DecayRateSKL = 0;

                            DecayRateSKL = DecayManager.DecayRateAtmosphericDrag(vessel) + DecayManager.DecayRateRadiationPressure(vessel) + DecayManager.DecayRateYarkovskyEffect(vessel);


                            double StationKeepingLifetime = double.Parse(StationKeepingFuelRemaining) / (DecayRateSKL / TimeWarp.CurrentRate * VesselData.FetchEfficiency(vessel) /*ResourceManager.GetEfficiency(Resource)*/ * Settings.ReadResourceRateDifficulty()) / (60 * 60 * HoursInDay);

                            if (StationKeepingLifetime < -5) // SRP Fixes
                            {
                                GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years.");
                            }

                            else
                            {
                                if (StationKeepingLifetime > 365000 && HoursInDay == 24)
                                {
                                    GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years.");
                                }

                                else if (StationKeepingLifetime > 425000 && HoursInDay == 6)
                                {
                                    GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years.");
                                }

                                else
                                {
                                    if (StationKeepingLifetime > 425 && HoursInDay == 6)
                                    {
                                        GUILayout.Label("Station Keeping Fuel Lifetime: " + (StationKeepingLifetime / 425).ToString("F1") + " years.");
                                    }

                                    else if (StationKeepingLifetime > 365 && HoursInDay == 24)
                                    {
                                        GUILayout.Label("Station Keeping Fuel Lifetime: " + (StationKeepingLifetime / 365).ToString("F1") + " years.");
                                    }

                                    else
                                    {
                                        GUILayout.Label("Station Keeping Fuel Lifetime: " + StationKeepingLifetime.ToString("F1") + " days.");
                                    }
                                }
                            }
                            GUILayout.Space(3);
                        }

                        if (GUILayout.Button(ButtonText))
                        {
                            if (StationKeeping == "True")
                            {
                                VesselData.UpdateStationKeeping(vessel, false);
                                ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + ": Station Keeping Disabled");
                            }

                            if (StationKeeping == "False")
                            {
                                if (StationKeepingManager.EngineCheck(vessel))
                                {
                                    if (double.Parse(StationKeepingFuelRemaining) > 0.01) // Good enough...
                                    {
                                        VesselData.UpdateStationKeeping(vessel, true);
                                        ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + ": Station Keeping Enabled");
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + " has no fuel to Station Keep!");
                                    }
                                }
                                else
                                {
                                    ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + " has no Engines or RCS modules on board!");
                                }
                            }
                        }
                        GUILayout.Space(2);
                        GUILayout.Label("_____________________________________");
                        GUILayout.Space(3);
                        GUILayout.EndVertical();
                    }
                }
            }
            GUILayout.EndScrollView();
        }
コード例 #6
0
        public static void FuelManager(Vessel vessel)
        {
            string ResourceName = "";

            ResourceName = ResourceManager.GetResourceNames(vessel);
            double CurrentFuel = 0;

            CurrentFuel = ResourceManager.GetResources(vessel);
            double ResourceEfficiency = VesselData.FetchEfficiency(vessel);// effi calculation based on vessel engine ISP stored in stationKeepData.ISP NEED ballance
            double LostFuel           = 0.0;

            LostFuel = Math.Abs((DecayManager.DecayRateAtmosphericDrag(vessel) + DecayManager.DecayRateRadiationPressure(vessel) + DecayManager.DecayRateYarkovskyEffect(vessel))) * Settings.ReadResourceRateDifficulty() * ResourceEfficiency; // * Fuel Multiplier

            double FuelNew = CurrentFuel - LostFuel;

            /// Remote tech compatibility - 1.6.0 ///
            bool RemoteTechInstalled = LoadingCheck.RemoteTechInstalled;
            bool SignalCheck         = false;
            bool ConnectionToVessel  = true;

            if (RemoteTechInstalled)
            {
                // Add Part Module Checks Here // Maybe 1.6.0


                if (ConnectionToVessel == false)
                {
                    SignalCheck = false;
                    ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has no connection to send Station Keeping command!");
                    VesselData.UpdateStationKeeping(vessel, false);
                }
            }
            else
            {
                SignalCheck = true;
            }

            if (SignalCheck == true)
            {
                if (EngineCheck(vessel) == false) // 1.3.0
                {
                    ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has no operational Engines or RCS modules, Station Keeping disabled.");
                    VesselData.UpdateStationKeeping(vessel, false);
                }

                else if (EngineCheck(vessel) == true)
                {
                    if (FuelNew <= 0)
                    {
                        ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has run out of " + ResourceName + ", Station Keeping disabled.");
                        VesselData.UpdateStationKeeping(vessel, false);
                        VesselData.UpdateVesselFuel(vessel, 0);
                    }
                    else
                    {
                        VesselData.UpdateVesselFuel(vessel, FuelNew);
                        ResourceManager.RemoveResources(vessel, LostFuel);
                    }
                }
            }
        }
コード例 #7
0
        public double GetMaximumPossibleLifetime()
        {
            double Lifetime = 0;

            //List<Part> constructPartsList = EditorLogic.RootPart.FindChildParts<Part>().ToList();
            //constructPartsList.AddUnique(EditorLogic.RootPart);
            var constructParts = EditorLogic.SortedShipList.ToArray();
            //Part[] constructParts = EditorLogic.RootPart.FindChildParts<Part>();
            //constructParts.AddUnique(EditorLogic.RootPart);

            bool   ClockType  = Settings.Read24Hr();
            double HoursInDay = 6;

            if (ClockType)
            {
                HoursInDay = 24.0;
            }
            else
            {
                HoursInDay = 6.0;
            }
            AllUsableFuels.Clear();

            var allResources = GetResources(constructParts);

            for (int pi = 0; pi < constructParts.Length; pi++)
            {
                Part p = constructParts[pi];

                Dictionary <string, double> UsableFuels = new Dictionary <string, double>();
                Dictionary <string, double> FuelRatios  = new Dictionary <string, double>();

                var moduleEngines = p.FindModuleImplementing <ModuleEngines>();
                if (moduleEngines != null)
                {
                    double engEfficiency = moduleEngines.atmosphereCurve.Evaluate(0);

                    if (moduleEngines != null)
                    {
                        for (int mep = 0; mep < moduleEngines.propellants.Count; mep++)
                        {
                            Propellant pro = moduleEngines.propellants[mep];

                            //if (pro.ToString() == GetResources(constructParts, pro.name)[i])
                            if (allResources.ContainsKey(pro.name))
                            {
                                // Blah blah blah
                                if (!UsableFuels.ContainsKey(pro.name))
                                {
                                    UsableFuels.Add(pro.name, pro.totalResourceCapacity);
                                    FuelRatios.Add(pro.name, pro.ratio);
                                }
                                if (!AllUsableFuels.ContainsKey(pro.name))
                                {
                                    AllUsableFuels.Add(pro.name, pro.totalResourceCapacity);
                                }

                                double ResEff = 1.0 / engEfficiency;

                                Lifetime = Lifetime + allResources[pro.name] /
                                           (DecayManager.EditorDecayRateRadiationPressure(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody) * ResEff * Settings.ReadResourceRateDifficulty() +
                                            DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)
                                           ) / (60 * 60 * HoursInDay);
                            }
                        }
                    }
                }
                var moduleRCS = p.FindModuleImplementing <ModuleRCS>();
                if (moduleRCS != null)
                {
                    var rcsEfficiency = moduleRCS.atmosphereCurve.Evaluate(0);
                    if (moduleRCS != null)
                    {
                        for (int mep = 0; mep < moduleRCS.propellants.Count; mep++)
                        {
                            Propellant pro = moduleRCS.propellants[mep];
                            if (allResources.ContainsKey(pro.name))
                            {
                                // Blah blah blah
                                if (!UsableFuels.ContainsKey(pro.name))
                                {
                                    UsableFuels.Add(pro.name, pro.totalResourceCapacity);
                                    FuelRatios.Add(pro.name, pro.ratio);
                                }
                                if (!AllUsableFuels.ContainsKey(pro.name))
                                {
                                    AllUsableFuels.Add(pro.name, pro.totalResourceCapacity);
                                }

                                double ResEff = 1.0 / rcsEfficiency;

                                Lifetime = Lifetime + allResources[pro.name] /
                                           (DecayManager.EditorDecayRateRadiationPressure(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody) * ResEff * Settings.ReadResourceRateDifficulty() +
                                            DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)
                                           ) / (60 * 60 * HoursInDay);
                            }
                        }
                    }
                }
            }
            return(Lifetime);
        }
コード例 #8
0
        public void InformationTab()
        {
            double VesselMass = CalculateMass();
            double VesselArea = CalculateArea();

            GUILayout.BeginHorizontal(GUILayout.Width(WINWIDTH));
            GUI.skin.label.fontSize  = 16;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Vessel Information", GUILayout.Width(290));
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            GUI.skin.label.fontSize  = 12;
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical();

            //GUILayout.Space(3);
            //GUILayout.Label("Vessel Information:");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Mass: " + (CalculateMass() * 1000).ToString("F2") + " Kg");
            GUILayout.Space(2);
            GUILayout.Label("Prograde Area: " + CalculateArea().ToString("F2") + " Square Meters");
            GUILayout.Space(2);
            GUILayout.Label("Total Area: " + (CalculateArea() * 4).ToString("F2") + " Square Meters");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.Label("Decay Information:");
            GUILayout.Space(2);
            //GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Reference Body: " + ReferenceBody.name);
            GUILayout.Space(2);
            for (int b = 0; b < FlightGlobals.Bodies.Count; b++)
            {
                CelestialBody body = FlightGlobals.Bodies[b];
                if (body.atmosphere)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button(body.name, GUILayout.Width(WINWIDTH)))
                    {
                        ReferenceBody = body;
                        SetMaxDisplayValue(ReferenceBody);
                        AltitudeValue = Math.Max((float)ReferenceBody.atmosphereDepth, AltitudeValue);
                        AltitudeValue = Math.Min(AltitudeValue, MaxDisplayValue);
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(2);
                }
            }

            GUILayout.Space(2);
            GUILayout.Label("Reference Altitude:");
            GUILayout.Space(2);
            AltitudeValue = GUILayout.HorizontalSlider(AltitudeValue, (float)ReferenceBody.atmosphereDepth, MaxDisplayValue);
            GUILayout.Space(2);
            GUILayout.Label("Altitude set: " + (AltitudeValue / 1000).ToString("F1") + "Km.");
            GUILayout.Space(2);
            GUILayout.Label("Decay Rate (Atmospheric Drag): " + UserInterface.FormatDecayRateToString(
                                DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)
                                ));
            GUILayout.Space(2);
            GUILayout.Label("Decay Rate (Radiation Pressure): " + UserInterface.FormatDecayRateSmallToString(DecayManager.EditorDecayRateRadiationPressure(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)));
            GUILayout.Space(2);
            GUILayout.Label("Estimated Orbital Lifetime: " + UserInterface.FormatTimeUntilDecayInDaysToString(DecayManager.DecayTimePredictionEditor(CalculateArea(), CalculateMass() * 1000, ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)));
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.Label("Station Keeping Information:");
            GUILayout.Space(2);
            //GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Total Fuel: " + (GetFuel() * 1000).ToString("F1") + " Kg.");
            GUILayout.Space(2);
            GUILayout.Label("Useable Resources: ");
            // GUILayout.BeginHorizontal();

#if true
            Dictionary <string, double> ResourceQuantites = new Dictionary <string, double>();
            //   double tempHold = 0;
            for (int i = 0; i < EditorLogic.SortedShipList.Count; i++)
            {
                Part part = EditorLogic.SortedShipList[i];
                for (int r = 0; r < part.Resources.Count; r++)
                {
                    PartResource res = part.Resources[r];
                    if (ResourceQuantites.ContainsKey(res.resourceName))
                    {
                        ResourceQuantites[res.resourceName] += res.maxAmount;
                    }
                    else
                    {
                        ResourceQuantites[res.resourceName] = res.maxAmount;
                    }
                    //GUILayout.Label(res.resourceName + ": " + res.maxAmount);
                }
            }
#endif
            GetMaximumPossibleLifetime();
            foreach (var resource in AllUsableFuels)
            {
                GUILayout.Label(resource.Key + " : " + ResourceQuantites[resource.Key].ToString("F0"));
            }



            //GUILayout.EndHorizontal();
            GUILayout.Space(2);
            GUILayout.Label("Maximum possible Station Keeping fuel lifetime: " + (UserInterface.FormatTimeUntilDecayInDaysToString(GetMaximumPossibleLifetime())));
            GUILayout.Space(2);
#if true
            GUILayout.Label("Maximum possible lifetime: " + (UserInterface.FormatTimeUntilDecayInDaysToString(DecayManager.DecayTimePredictionEditor(CalculateArea(), CalculateMass() * 1000, ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody) +
                                                                                                              +DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)
                                                                                                              + GetMaximumPossibleLifetime())));
#endif
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.EndVertical();
        }
コード例 #9
0
        public void InformationTab()
        {
            double VesselMass = CalculateMass();
            double VesselArea = CalculateArea();

            GUILayout.BeginHorizontal();
            GUI.skin.label.fontSize  = 16;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("Vessel Information", GUILayout.Width(290));
            GUI.skin.label.alignment = TextAnchor.MiddleLeft;
            GUI.skin.label.fontSize  = 12;
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical();

            GUILayout.Space(3);
            GUILayout.Label("Vessel Information:");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Mass: " + (CalculateMass() * 1000).ToString("F2") + " Kg");
            GUILayout.Space(2);
            GUILayout.Label("Prograde Area: " + CalculateArea().ToString("F2") + " Square Meters");
            GUILayout.Space(2);
            GUILayout.Label("Total Area: " + (CalculateArea() * 4).ToString("F2") + " Square Meters");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.Label("Decay Information:");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Reference Body: " + ReferenceBody.name);
            GUILayout.Space(2);
            GUILayout.BeginHorizontal();
            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                if (body.atmosphere)
                {
                    if (GUILayout.Button(body.name))
                    {
                        ReferenceBody = body;
                    }
                    GUILayout.Space(2);
                }
            }

            float MaxDisplayValue = float.Parse(ReferenceBody.atmosphereDepth.ToString()) * 30f;

            if (ReferenceBody == Sun.Instance.sun)
            {
                MaxDisplayValue = float.Parse(ReferenceBody.atmosphereDepth.ToString()) * 100000f;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(2);
            GUILayout.Label("Reference Altitude:");
            GUILayout.Space(2);
            AltitudeValue = GUILayout.HorizontalSlider(AltitudeValue, float.Parse(ReferenceBody.atmosphereDepth.ToString()), MaxDisplayValue);
            GUILayout.Space(2);
            GUILayout.Label("Altitude set: " + (AltitudeValue / 1000).ToString("F1") + "Km.");
            GUILayout.Space(2);
            GUILayout.Label("Decay Rate (Atmospheric Drag): " + UserInterface.FormatDecayRateToString(DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)));
            GUILayout.Space(2);
            GUILayout.Label("Decay Rate (Radiation Pressure): " + UserInterface.FormatDecayRateSmallToString(DecayManager.EditorDecayRateRadiationPressure(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)));
            GUILayout.Space(2);
            GUILayout.Label("Estimated Orbital Lifetime: " + UserInterface.FormatTimeUntilDecayInDaysToString(DecayManager.DecayTimePredictionEditor(CalculateArea(), CalculateMass() * 1000, ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)));
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.Label("Station Keeping Information:");
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(2);
            GUILayout.Label("Total Fuel: " + GetFuel() * 1000 + "Kg.");
            GUILayout.Space(2);
            GUILayout.Label("Useable Resources: ");
            GUILayout.BeginHorizontal();

            Dictionary <string, double> ResourceQuantites = new Dictionary <string, double>();

            //   double tempHold = 0;

            foreach (Part part in EditorLogic.SortedShipList)
            {
                foreach (PartResource res in part.Resources)
                {
                    if (ResourceQuantites.ContainsKey(res.resourceName))
                    {
                        double previousValue = 0;
                        ResourceQuantites.TryGetValue(res.resourceName, out previousValue);
                        ResourceQuantites.Remove(res.resourceName);
                        ResourceQuantites.Add(res.resourceName, previousValue + res.maxAmount);
                    }
                    else
                    {
                        ResourceQuantites.Add(res.resourceName, res.maxAmount);
                    }
                    //GUILayout.Label(res.resourceName + ": " + res.maxAmount);
                }

                foreach (string resource in ResourceQuantites.Keys)
                {
                    double quantity = 0;
                    ResourceQuantites.TryGetValue(resource, out quantity);
                    GUILayout.Label(resource + " : " + quantity);
                }
            }


            GUILayout.EndHorizontal();
            GUILayout.Space(2);
            //GUILayout.Label("Maximum possible Station Keeping fuel lifetime: " + (UserInterface.FormatTimeUntilDecayInDaysToString(GetMaximumPossibleLifetime())));
            GUILayout.Space(2);
            // GUILayout.Label("Maximum possible lifetime: " + (UserInterface.FormatTimeUntilDecayInDaysToString(DecayManager.DecayTimePredictionEditor(CalculateArea(), CalculateMass() * 1000, ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody) +
            //  + DecayManager.EditorDecayRateAtmosphericDrag(CalculateMass() * 1000, CalculateArea(), ReferenceBody.Radius + AltitudeValue, 0, ReferenceBody)
            //   + GetMaximumPossibleLifetime() )));
            GUILayout.Space(2);
            GUILayout.Label("_________________________________________");
            GUILayout.Space(3);

            GUILayout.EndVertical();
        }