示例#1
0
        public Utilities()
        {
            ConfigNode deltaVNode = GameDatabase.Instance.GetConfigNode("WhereCanIGo/WHERE_CAN_I_GO");

            if (deltaVNode == null)
            {
                _uiDialog = GenerateErrorDialog();
                Debug.Log("[WhereCanIGo]: deltaVNode is null");
                return;
            }
            SystemNotes = deltaVNode.GetValue("notes");
            Warnings    = deltaVNode.GetValue("warning");

            ConfigNode[] bodies = deltaVNode.GetNodes("BODY");
            for (int i = 0; i < bodies.Length; i++)
            {
                ConfigNode   cn            = bodies.ElementAt(i);
                PlanetDeltaV planetToSetup = new PlanetDeltaV(cn);
                if (planetToSetup.Setup)
                {
                    Planets.Add(planetToSetup);
                }
            }

            if (Planets.Count != 0)
            {
                return;
            }
            Debug.Log("[WhereCanIGo]: No planets were setup");
            _uiDialog = GenerateErrorDialog();
        }
        private DialogGUILabel GetDeltaVString(PlanetDeltaV planet, string situation)
        {
            int    deltaV = -1;
            string s;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (situation)
            {
            case "Flyby: ":
                deltaV = planet.EscapeDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromFlybyDv;
                }
                break;

            case "Orbiting: ":
                deltaV = planet.OrbitDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromOrbitDv;
                }
                break;

            case "Landing: ":
                deltaV = planet.LandDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromLandingDv;
                }
                break;

            case "Synchronous Orbit: ":
                deltaV = planet.SynchronousDv;
                break;
            }

            deltaV -= _utilities.ConvertBodyToPlanetDeltaV(FlightGlobals.GetHomeBody()).OrbitDv;
            UIStyle style              = _utilities.GenerateStyle(deltaV, false);
            string  status             = _utilities.VesselStatus(deltaV, situation, planet);
            double  shortFallOrDeficit = Math.Round(Math.Abs(deltaV - FlightGlobals.ActiveVessel.VesselDeltaV.TotalDeltaVVac), 0);

            if (status == "NO")
            {
                status = status + " (" + shortFallOrDeficit + "m/s short)";
            }
            else
            {
                status = status + " (+" + shortFallOrDeficit + "m/s)";
            }
            if (_utilities.SituationValid(planet.RelatedBody, situation))
            {
                s = " | " + situation + status;
            }
            else
            {
                s = " | " + situation + "N/A";
            }
            return(new DialogGUILabel(s, style));
        }
示例#3
0
 public PlanetDeltaV ConvertBodyToPlanetDeltaV(CelestialBody cb)
 {
     for (int i = 0; i < Planets.Count; i++)
     {
         PlanetDeltaV p = Planets.ElementAt(i);
         if (p.Name == cb.bodyName)
         {
             return(p);
         }
     }
     return(null);
 }
        private PopupDialog GenerateDialog()
        {
            List <DialogGUIBase> guiItems = new List <DialogGUIBase>();

            if (EditorLogic.fetch == null || EditorLogic.fetch.ship == null)
            {
                guiItems.Add(new DialogGUILabel("No Vessel Detected"));
            }
            else
            {
                guiItems.Add(new DialogGUILabel(_utilities.SystemNotes, _utilities.CreateNoteStyle()));
                guiItems.Add(new DialogGUILabel(_utilities.Warnings, _utilities.CreateNoteStyle()));
                DialogGUIBase[] vertical   = new DialogGUIBase[_utilities.Planets.Count];
                DialogGUIBase[] horizontal = new DialogGUIBase[2];
                horizontal[0] = new DialogGUIToggle(() => _returnTrip, "Return Trip?", delegate { SetReturnTrip(); });
                horizontal[1] = new DialogGUIToggle(() => payloadOnly, "Payload Only", delegate { SetPayoadOnly(); });
                guiItems.Add(new DialogGUIHorizontalLayout(horizontal));
                for (int i = 0; i < _utilities.Planets.Count; i++)
                {
                    PlanetDeltaV p = _utilities.Planets.ElementAt(i);
                    horizontal    = new DialogGUIBase[4];
                    horizontal[0] = new DialogGUILabel(p.GetName(), _utilities.GenerateStyle(-1, false));
                    horizontal[1] = GetDeltaVString(p, "Flyby: ");
                    horizontal[2] = GetDeltaVString(p, "Orbiting: ");
                    if (p.IsHomeWorld && p.SynchronousDv != -1)
                    {
                        horizontal[3] = GetDeltaVString(p, "Synchronous Orbit: ");
                    }
                    else
                    {
                        horizontal[3] = GetDeltaVString(p, "Landing: ");
                    }
                    vertical[i] = new DialogGUIHorizontalLayout(horizontal);
                }
                DialogGUIVerticalLayout layout = new DialogGUIVerticalLayout(vertical);
                guiItems.Add(new DialogGUIScrollList(-Vector2.one, false, true, layout));
            }
            guiItems.Add(new DialogGUILabel("*Assuming craft has enough chutes"));
            guiItems.Add(new DialogGUIButton("Close", () => _utilities.CloseDialog(_uiDialog), false));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                                new MultiOptionDialog("WhereCanIGoDialog", "", "Where Can I Go", UISkinManager.defaultSkin,
                                                                      _geometry,
                                                                      guiItems.ToArray()), false, UISkinManager.defaultSkin));
        }
        private PopupDialog GenerateDialog()
        {
            List <DialogGUIBase> guiItems = new List <DialogGUIBase>();
            bool vesselIsHome             = FlightGlobals.ActiveVessel.mainBody == FlightGlobals.GetHomeBody();

            if (FlightGlobals.ActiveVessel == null)
            {
                guiItems.Add(new DialogGUILabel("No Vessel Detected"));
            }
            else if (vesselIsHome && FlightGlobals.ActiveVessel.situation == Vessel.Situations.ORBITING)
            {
                guiItems.Add(new DialogGUILabel(_utilities.SystemNotes, _utilities.CreateNoteStyle()));
                guiItems.Add(new DialogGUILabel(_utilities.Warnings, _utilities.CreateNoteStyle()));
                guiItems.Add(new DialogGUIToggle(() => _returnTrip, "Return Trip?", delegate { SetReturnTrip(); }));
                for (int i = 0; i < _utilities.Planets.Count; i++)
                {
                    PlanetDeltaV    p          = _utilities.Planets.ElementAt(i);
                    DialogGUIBase[] horizontal = new DialogGUIBase[4];
                    horizontal[0] = new DialogGUILabel(p.GetName(), _utilities.GenerateStyle(-1, false));
                    horizontal[1] = GetDeltaVString(p, "Flyby: ");
                    horizontal[2] = GetDeltaVString(p, "Orbiting: ");
                    if (p.IsHomeWorld && p.SynchronousDv != -1)
                    {
                        horizontal[3] = GetDeltaVString(p, "Synchronous Orbit: ");
                    }
                    else
                    {
                        horizontal[3] = GetDeltaVString(p, "Landing: ");
                    }
                    guiItems.Add(new DialogGUIHorizontalLayout(horizontal));
                }

                guiItems.Add(new DialogGUILabel("*Assuming craft has enough chutes"));
            }
            else
            {
                guiItems.Add(new DialogGUILabel("No Data Available. Achieve stable orbit around " + FlightGlobals.GetHomeBodyName(), _utilities.GenerateStyle(99999, true)));
            }
            guiItems.Add(new DialogGUIButton("Close", () => _utilities.CloseDialog(_uiDialog), false));
            return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f),
                                                new MultiOptionDialog("WhereCanIGoDialog", "", "Where Can I Go", UISkinManager.defaultSkin,
                                                                      _geometry,
                                                                      guiItems.ToArray()), false, UISkinManager.defaultSkin));
        }
示例#6
0
        internal string VesselStatus(int deltaVRequired, string situation, PlanetDeltaV planet)
        {
            double vesselDeltaV;

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (EditorLogic.fetch.ship == null || EditorLogic.fetch.ship.vesselDeltaV == null)
                {
                    return("N/A");
                }
                vesselDeltaV = EditorLogic.fetch.ship.vesselDeltaV.TotalDeltaVVac;
            }
            else
            {
                if (FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.VesselDeltaV == null)
                {
                    return("N/A");
                }
                vesselDeltaV = FlightGlobals.ActiveVessel.VesselDeltaV.TotalDeltaVVac;
            }
            if (deltaVRequired < 0)
            {
                return("N/A");
            }
            if (deltaVRequired > vesselDeltaV)
            {
                return("NO");
            }
            if (vesselDeltaV - deltaVRequired < deltaVRequired * 0.05)
            {
                return("MARGINAL");
            }
            if (situation == "Landing: " && planet != null && planet.RequireChutes)
            {
                return("YES*");
            }
            return("YES");
        }
示例#7
0
        private DialogGUILabel GetDeltaVString(PlanetDeltaV planet, string situation)
        {
            int SituationCases = 0;

            if (situation == LocalizedStrings.Situation_Flyby + ": ")
            {
                SituationCases = 1;
            }
            else if (situation == LocalizedStrings.Situation_Orbiting + ": ")
            {
                SituationCases = 2;
            }
            else if (situation == LocalizedStrings.Situation_Landing + ": ")
            {
                SituationCases = 3;
            }
            else if (situation == LocalizedStrings.Situation_SynchronousOrbit + ": ")
            {
                SituationCases = 4;
            }
            int    deltaV = -1;
            string s;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (SituationCases)
            {
            case 1:    //"Flyby: ":
                deltaV = planet.EscapeDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromFlybyDv;
                }
                break;

            case 2:    //"Orbiting: ":
                deltaV = planet.OrbitDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromOrbitDv;
                }
                break;

            case 3:    //"Landing: ":
                deltaV = planet.LandDv;
                if (_returnTrip)
                {
                    deltaV += planet.ReturnFromLandingDv;
                }
                break;

            case 4:    //"Synchronous Orbit: ":
                deltaV = planet.SynchronousDv;
                break;
            }

            if (payloadOnly)
            {
                deltaV -= _utilities.ConvertBodyToPlanetDeltaV(FlightGlobals.GetHomeBody()).OrbitDv;
            }
            UIStyle style              = _utilities.GenerateStyle(deltaV, false);
            string  status             = _utilities.VesselStatus(deltaV, situation, planet);
            double  shortFallOrDeficit = 0;

            if (EditorLogic.fetch.ship != null && EditorLogic.fetch.ship.vesselDeltaV != null)
            {
                shortFallOrDeficit =
                    Math.Round(Math.Abs(deltaV - EditorLogic.fetch.ship.vesselDeltaV.TotalDeltaVVac), 0);
            }
            if (status == "NO")
            {
                status = status + " (" + shortFallOrDeficit +
                         "m/s short)";
            }
            else
            {
                status = status + " (+" + shortFallOrDeficit +
                         "m/s)";
            }
            if (_utilities.SituationValid(planet.RelatedBody, situation))
            {
                s = " | " + situation + status;
            }
            else
            {
                s = " | " + situation + "N/A";
            }
            return(new DialogGUILabel(s, style));
        }