Exemplo n.º 1
0
        public static double TimeToDaylight(double lat, double lon,
                                            CelestialBody body, double offset)
        {
            double rotPeriod, localTime;

            localTime = Sunrise.GetLocalTime(lon, body, instance.sun);
            rotPeriod = body.rotationPeriod;
            var orbit = body.orbit;

            while (orbit?.referenceBody != instance.sun)
            {
                orbit = orbit.referenceBody.orbit;
            }
            if (orbit != null)
            {
                double or = rotPeriod;
                rotPeriod = orbit.period * rotPeriod / (orbit.period - rotPeriod);
                Debug.Log($"[EarlyBird] rotation period: {or} reference period: {orbit.period} day length: {rotPeriod}");
            }

            offset = (offset * 60) / rotPeriod;
            double dayLength      = Sunrise.GetDayLength(lat, body, instance.sun);
            double timeOfDawn     = 0.5 - dayLength / 2 + offset;
            double timeToDaylight = rotPeriod * UtilMath.WrapAround(timeOfDawn - localTime, 0, 1);

            Debug.Log($"[EarlyBird] WarpToMorning: daylight: {dayLength}({dayLength * rotPeriod}), dawn {timeOfDawn}, warpTime: {timeToDaylight}");
            return(timeToDaylight);
        }
Exemplo n.º 2
0
        public static void WarpToMorning(double lat, double lon,
                                         CelestialBody body, double offset)
        {
            if (FlightDriver.Pause)
            {
                return;
            }
            if (instance.sun == null)
            {
                Debug.LogError("Cannot warp to next morning due to lack of sun");
                return;
            }

            if (TimeWarp.fetch.CancelAutoWarp(0))
            {
                return;
            }

            double rotPeriod, localTime;

            localTime = Sunrise.GetLocalTime(lon, body, instance.sun);
            rotPeriod = body.rotationPeriod;
            if (body.orbit != null)
            {
                rotPeriod = body.orbit.period * rotPeriod / (body.orbit.period - rotPeriod);
            }

            offset = (offset * 60) / rotPeriod;
            double dayLength      = Sunrise.GetDayLength(lat, body, instance.sun);
            double timeOfDawn     = 0.5 - dayLength / 2 + offset;;
            double timeToDaylight = rotPeriod * UtilMath.WrapAround(timeOfDawn - localTime, 0, 1);

            Debug.LogFormat("[EarlyBird] WarpToMorning: daylight: {0}({1}), dawn {2}, warpTime: {3}", dayLength, dayLength * rotPeriod, timeOfDawn, timeToDaylight);
            TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + timeToDaylight, 8, 1);
        }
Exemplo n.º 3
0
        public static void WarpToMorning(double lat, double lon,
                                         CelestialBody body, double offset)
        {
            if (FlightDriver.Pause)
            {
                return;
            }
            if (instance.sun == null)
            {
                Debug.LogError("Cannot warp to next morning due to lack of sun");
                return;
            }

            if (TimeWarp.fetch.CancelAutoWarp(0))
            {
                return;
            }

            double rotPeriod, localTime;

            localTime = Sunrise.GetLocalTime(lon, body, instance.sun);
            rotPeriod = body.rotationPeriod;
            var orbit = body.orbit;

            while (orbit?.referenceBody != instance.sun)
            {
                orbit = orbit.referenceBody.orbit;
            }
            if (orbit != null)
            {
                double or = rotPeriod;
                rotPeriod = orbit.period * rotPeriod / (orbit.period - rotPeriod);
                Debug.Log($"[EarlyBird] rotation period: {or} reference period: {orbit.period} day length: {rotPeriod}");
            }

            offset = (offset * 60) / rotPeriod;
            double dayLength      = Sunrise.GetDayLength(lat, body, instance.sun);
            double timeOfDawn     = 0.5 - dayLength / 2 + offset;
            double timeToDaylight = rotPeriod * UtilMath.WrapAround(timeOfDawn - localTime, 0, 1);

            Debug.Log($"[EarlyBird] WarpToMorning: daylight: {dayLength}({dayLength * rotPeriod}), dawn {timeOfDawn}, warpTime: {timeToDaylight}");
            TimeWarp.fetch.WarpTo(Planetarium.GetUniversalTime() + timeToDaylight, 8, 1);
        }