示例#1
0
        public static DateTimeFromTo CalculateSunRiseSunSet(DateTime time, Coordinate coordinate)
        {
            DateTime     theDate         = time.Date;
            DaylightTime daylightChanges = TimeZone.CurrentTimeZone.GetDaylightChanges(time.Year);
            SunTime      sunTime         = new SunTime(coordinate.LatitudeDeg, coordinate.LongitudeDeg,
                                                       1, daylightChanges, time);
            DateTimeFromTo result = new DateTimeFromTo(sunTime.RiseTime, sunTime.SetTime);

            return(result);
        }
示例#2
0
        public void RecalculateMoonAndSunInformation()
        {
            if (GameManager.Instance.Game == null || Coordinate == null)
            {
                return;
            }
            DateTime date = GameManager.Instance.Game.GameCurrentTime;

            double jd = date.DtToJulianDay();

            JulianDay = jd;
            //bool is_rise = true;
            GameConstants.RiseSetType riseSetType = GameConstants.RiseSetType.Lunar;
            GameConstants.TideEvent   tideEvent   = GameConstants.TideEvent.MoonSet; //init
            double jdout;

            try
            {
                AstronomyHelper.findNextRiseOrSet(date, Coordinate, ref riseSetType, ref tideEvent, out jdout);
                TimeNextTideEvent = jdout.JdToDateTime();
                NextTideEvent     = tideEvent;
                IsMoonUp          = (NextTideEvent == GameConstants.TideEvent.MoonSet);
            }
            catch (Exception)
            {
                //TODO: Fix
                //GameManager.Instance.Log.LogError(
                //    string.Format("RecalculateMoonPhase failed for Time {0}, Coordinate {1}", date, Coordinate)
                //    + ". " + ex.Message);
            }
            //And now for the sun
            CurrentSunheightDeg      = WeatherSystem.CalculateSunHeightDeg(date, Coordinate);
            CurrentSunDeclinationDeg = WeatherSystem.CalculateSunDeclination(date, Coordinate);
            DateTimeFromTo SunRiseSet = WeatherSystem.CalculateSunRiseSunSet(date, Coordinate);

            if (SunRiseSet.FromTime != null)
            {
                SunriseTime  = (DateTime)SunRiseSet.FromTime;
                IsSunSetting = true;
            }
            else
            {
                IsSunSetting = false;
            }
            if (SunRiseSet.ToTime != null)
            {
                SunsetTime  = (DateTime)SunRiseSet.ToTime;
                IsSunRising = true;
            }
            else
            {
                IsSunSetting = false;
            }
        }