예제 #1
0
        // return true if body is relevant to the player
        // - body: reference body of the planetary system
        static bool Body_is_relevant(CelestialBody body)
        {
            // [disabled]
            // special case: home system is always relevant
            // note: we deal with the case of a planet mod setting homebody as a moon
            //if (body == Lib.PlanetarySystem(FlightGlobals.GetHomeBody())) return true;

            // for each vessel
            foreach (Vessel v in FlightGlobals.Vessels)
            {
                // if inside the system
                if (Lib.GetParentPlanet(v.mainBody) == body)
                {
                    // get info from the cache
                    VesselData vd = v.KerbalismData();

                    // skip invalid vessels
                    if (!vd.IsSimulated)
                    {
                        continue;
                    }

                    // obey message config
                    if (!v.KerbalismData().cfg_storm)
                    {
                        continue;
                    }

                    // body is relevant
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>Estimated solar flux from the first parent sun of the given body, including other neighbouring stars/suns (binary systems handling)</summary>
        /// <param name="body"></param>
        /// <param name="worstCase">if true, we use the largest distance between the body and the sun</param>
        /// <param name="mainSun"></param>
        /// <param name="mainSunDirection"></param>
        /// <param name="mainSunDistance"></param>
        /// <returns></returns>
        public static double SolarFluxAtBody(CelestialBody body, bool worstCase, out CelestialBody mainSun, out Vector3d mainSunDirection, out double mainSunDistance)
        {
            // get first parent sun
            mainSun = Lib.GetParentSun(body);

            // get direction and distance
            mainSunDirection = (mainSun.position - body.position).normalized;
            if (worstCase)
            {
                mainSunDistance = Sim.Apoapsis(Lib.GetParentPlanet(body)) - mainSun.Radius - body.Radius;
            }
            else
            {
                mainSunDistance = Sim.SunDistance(body.position, mainSun);
            }

            // get solar flux
            int mainSunIndex = mainSun.flightGlobalsIndex;

            Sim.SunData mainSunData = Sim.suns.Find(pr => pr.bodyIndex == mainSunIndex);
            double      solarFlux   = mainSunData.SolarFlux(mainSunDistance);

            // multiple suns handling (binary systems...)
            foreach (Sim.SunData otherSun in Sim.suns)
            {
                if (otherSun.body == mainSun)
                {
                    continue;
                }
                Vector3d otherSunDir = (otherSun.body.position - body.position).normalized;
                double   otherSunDist;
                if (worstCase)
                {
                    otherSunDist = Sim.Apoapsis(Lib.GetParentPlanet(body)) - otherSun.body.Radius;
                }
                else
                {
                    otherSunDist = Sim.SunDistance(body.position, otherSun.body);
                }
                // account only for other suns that have approximatively the same direction (+/- 30°), discard the others
                if (Vector3d.Angle(otherSunDir, mainSunDirection) > 30.0)
                {
                    continue;
                }
                solarFlux += otherSun.SolarFlux(otherSunDist);
            }
            return(solarFlux);
        }
예제 #3
0
        /// <summary>return true if a storm is in progress</summary>
        public static bool InProgress(Vessel v)
        {
            var bd = Lib.IsSun(v.mainBody) ? v.KerbalismData().stormData : DB.Storm(Lib.GetParentPlanet(v.mainBody).name);

            return(bd.storm_state == 2);
        }
예제 #4
0
        /// <summary>return true if a storm is incoming</summary>
        public static bool Incoming(Vessel v)
        {
            var bd = Lib.IsSun(v.mainBody) ? v.KerbalismData().stormData : DB.Storm(Lib.GetParentPlanet(v.mainBody).name);

            return(bd.storm_state == 1 && bd.display_warning);
        }
예제 #5
0
        void Problem_storm(Vessel v, ref List <Texture2D> icons, ref List <string> tooltips)
        {
            if (Storm.Incoming(v))
            {
                icons.Add(Textures.storm_yellow);

                var bd  = Lib.IsSun(v.mainBody) ? v.KerbalismData().stormData : DB.Storm(Lib.GetParentPlanet(v.mainBody).name);
                var tti = bd.storm_time - Planetarium.GetUniversalTime();
                tooltips.Add(Lib.BuildString(Lib.Color(Local.Monitor_ejectionincoming, Lib.Kolor.Orange), "\n<i>", Local.Monitor_TimetoimpactCoronalmass, Lib.HumanReadableDuration(tti), "</i>"));                //"Coronal mass ejection incoming"Time to impact:
            }
            if (Storm.InProgress(v))
            {
                icons.Add(Textures.storm_red);

                var bd = Lib.IsSun(v.mainBody) ? v.KerbalismData().stormData : DB.Storm(Lib.GetParentPlanet(v.mainBody).name);
                var remainingDuration = bd.storm_time + bd.displayed_duration - Planetarium.GetUniversalTime();
                tooltips.Add(Lib.BuildString(Lib.Color(Local.Monitor_Solarstorminprogress, Lib.Kolor.Red), "\n<i>", Local.Monitor_SolarstormRemaining, Lib.HumanReadableDuration(remainingDuration), "</i>"));                //"Solar storm in progress"Remaining duration:
            }
        }