示例#1
0
        public void SetPhase(MoonPhases masserPhase, MoonPhases secundaPhase)
        {
            if (Enum.IsDefined(typeof(MoonPhases), masserPhase))
            {
                this.MasserPhase = masserPhase;
            }

            if (Enum.IsDefined(typeof(MoonPhases), secundaPhase))
            {
                this.SecundaPhase = secundaPhase;
            }

            if (MasserPhase != MoonPhases.New)
            {
                Texture2D masserTexture = GetTexture(MasserPhase, masserTextureLookup);
                if (masserTexture != null)
                {
                    _masserRend.material.mainTexture = masserTexture;
                }
            }
            if (SecundaPhase != MoonPhases.New)
            {
                Texture2D secundaTexture = GetTexture(SecundaPhase, secundaTextureLookup);
                if (secundaTexture != null)
                {
                    _secundaRend.material.mainTexture = secundaTexture;
                }
            }
        }
示例#2
0
        public void FinishRequest()
        {
            FishingRecord record;

            // validate fields
            try
            {
                // date and time
                CommonPresenterStuff.ValidateDateEarlierThanNow(_view.DateTimeStart, "start date and time");
                CommonPresenterStuff.ValidateCronologicalDates(_view.DateTimeStart, _view.DateTimeEnd,
                                                               "start date and time", "end date and time");

                // location name
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Location, "location");

                // nature events
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Wind, "wind");
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.MoonPhase, "moon phase");
                CommonPresenterStuff.ValidateFieldNotEmpty(_view.Tide, "tide");
            }
            catch (Exception e)
            {
                _view.ShowErrorMessage(e.Message);
                return;
            }

            // if fish catch or sale is empty, warn user
            if (_fishCatch.GetCaughtFish().Count == 0)
            {
                if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish catch")))
                {
                    return;
                }
            }
            if (_fishCatch.GetSoldFish().Count == 0)
            {
                if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish sale")))
                {
                    return;
                }
            }

            // try create record
            Winds      wind      = CommonPresenterStuff.GetWindEnum(_view.Wind);
            MoonPhases moonPhase = CommonPresenterStuff.GetMoonPhaseEnum(_view.MoonPhase);
            Tides      tide      = CommonPresenterStuff.GetTideEnum(_view.Tide);

            try
            {
                record = FishingRecordFactory.CreateFishingRecord(_view.DateTimeStart, _view.DateTimeEnd,
                                                                  _view.Location, wind, moonPhase, tide, _fishCatch);
            }
            catch (Exception)
            {
                _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage());
                return;
            }

            Finish(record);
        }
示例#3
0
        /// <summary>
        /// Looks up file name for moon texture and returns texture
        /// </summary>
        private Texture2D GetTexture(MoonPhases phase, List <string> textureLookup)
        {
            Texture2D moonText = null;

            if (textureLookup == null)
            {
                Debug.LogError("Invalid texture lookup dictionary");
                return(moonText);
            }
            string textVal = textureLookup[(int)phase];

            if (string.IsNullOrEmpty(textVal))
            {
                Debug.LogError("Texture value is null or empty");
                return(moonText);
            }
            moonText = Resources.Load(textVal) as Texture2D;

            if (moonText == null)
            {
                Debug.Log("failed to load moon texture for: " + phase.ToString());
                try
                {
                    moonText = Resources.Load(textureLookup[4]) as Texture2D;         //try to load full as default
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message);
                }
            }

            return(moonText);
        }
示例#4
0
        public static FishingRecord CreateFishingRecord(DateTime inDtStart, DateTime inDtEnd, string inLocationName,
                                                        Winds inWind, MoonPhases inMoonPhase, Tides inTide, FishCatch inFishCatch)
        {
            DateTime         dtAdded    = DateTime.Now;
            DateTimeInterval dtInterval = new DateTimeInterval(inDtStart, inDtEnd);
            Location         location   = LocationRepository.GetInstance().GetLocation(inLocationName);
            NatureEvents     nContext   = new NatureEvents(inWind, inMoonPhase, inTide);

            FishingRecord record = new FishingRecord(dtAdded, dtInterval, location, nContext, inFishCatch);

            return(record);
        }
 public static string MoonPhaseToString(MoonPhases m)
 {
     return(m switch
     {
         MoonPhases.newmoon => "New Moon",
         MoonPhases.waxingcrescent => "Waxing Crescent",
         MoonPhases.firstquarter => "First Quarter",
         MoonPhases.waxinggibbous => "Waxing Gibbous",
         MoonPhases.fullmoon => "Full Moon",
         MoonPhases.waninggibbous => "Waning Gibbous",
         MoonPhases.lastquarter => "Last Quarter",
         MoonPhases.waningcrescent => "Waning Crescent",
         _ => ""
     });
示例#6
0
        public void AddFishingRecordRequest()
        {
            // ensure nature contex is not empty
            if (_view.Wind == "")
            {
                _view.ShowErrorMessage(_windEmptyError);
                return;
            }
            if (_view.MoonPhase == "")
            {
                _view.ShowErrorMessage(_moonPhaseEmptyError);
                return;
            }
            if (_view.Tide == "")
            {
                _view.ShowErrorMessage(_tideEmptyError);
                return;
            }

            Winds      wind      = CommonFunctionalities.GetWindEnum(_view.Wind);
            MoonPhases moonPhase = CommonFunctionalities.GetMoonPhaseEnum(_view.MoonPhase);
            Tides      tide      = CommonFunctionalities.GetTideEnum(_view.Tide);

            try
            {
                FishingRecord record = FishingRecordFactory.CreateFishingRecord(_view.StartDateTime, _view.EndDateTime,
                                                                                _view.Location, wind, moonPhase, tide, fishCatch);

                FishingRecordRepository.GetInstance().AddRecord(record);
            }
            catch (FishermanBaseException e)
            {
                _view.ShowErrorMessage(e.Info);
                return;
            }

            _parent.AddRecordName(DateTime.Now);

            _view.End();
        }
示例#7
0
        public static JulianDay FindPhase(int year, int month, int day, MoonPhases phase)
        {
            var jd = new JulianDay(year, month, day);
            double length = 365;
            if (jd.IsLeapYear)
            { length = 366; }

            double Y = Math.Round(year + ((double)jd.DayOfYear / length), 2);
            double k = ((Y - 2000) * 12.3685);

            switch (phase)
            {
                case MoonPhases.New:
                    k = Math.Round(k);
                    break;
                case MoonPhases.FirstQuarter:
                    if (k < 0)
                    { k = Math.Round(k) - 0.25; }
                    else
                    { k = Math.Floor(k) + 0.25; }
                    break;
                case MoonPhases.Full:
                    if (k < 0)
                    { k = Math.Round(k) - 0.50; }
                    else
                    { k = Math.Floor(k) + 0.50; }
                    break;
                case MoonPhases.LastQuarter:
                    if (k < 0)
                    { k = Math.Round(k) - 0.75; }
                    else
                    { k = Math.Floor(k) + 0.75; }
                    break;
            }

            Debug.WriteLine("k\t=\t" + Math.Round(k, 2));

            double T = k / 1236.85;
            double T2 = Math.Pow(T, 2);
            double T3 = Math.Pow(T, 3);
            double T4 = Math.Pow(T, 4);

            Debug.WriteLine("T\t=\t" + Math.Round(T, 5));

            double JDE = 2451550.09766 + 29.530588861 * k
            + 0.00015437 * T2
            - 0.000000150 * T3
            + 0.00000000073 * T4;

            Debug.WriteLine("JDE\t=\t" + Math.Round(JDE, 5));

            //Corrections

            double E = 1 - 0.002516 * T - 0.0000074 * T2;

            double M = 2.5534 + 29.10535670 * k
                        - 0.0000014 * T2
                        - 0.00000011 * T3;

            Debug.Write("M\t=\t" + Math.Round(M, 4));
            M = AstroMath.Mod(M, 360);
            Debug.WriteLine("\t=\t" + Math.Round(M, 4));

            double Mp = 201.5643 + (385.81693528 * k)
                        + (0.0107582 * T2)
                        + (0.00001238 * T3)
                        - (0.000000058 * T4);

            Debug.Write("M′\t=\t" + Math.Round(Mp, 4));
            Mp = AstroMath.Mod(Mp, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Mp, 4));

            double F = 160.7180 + 390.67050284 * k
                        - 0.0016118 * T2
                        - 0.00000227 * T3
                        + 0.000000011 * T4;

            Debug.Write("F\t=\t" + Math.Round(F, 4));
            F = AstroMath.Mod(F, 360);
            Debug.WriteLine("\t=\t" + Math.Round(F, 4));

            double Ω = 124.7746 - (1.56375588 * k)
                        + (0.0020672 * T2)
                        + (0.00000215 * T3);

            Debug.Write("Ω\t=\t" + Math.Round(Ω, 4));
            Ω = AstroMath.Mod(Ω, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Ω, 4));

            double correction = 0;
            //switch (phase)
            //{
            //    case MoonPhases.Full:
            //        correction = FullMoonCorrections(E, M, Mp, F, Ω);
            //        break;
            //}

            //PlanetaryArguments
            double additionalCorrection = 0;
            for (int i = 0; i <= 13; i++)
            {
                IList<double> S = PlanetaryArguments[i];
                additionalCorrection += AdditionalCorrections[i] * AstroMath.Sin(S[0] + (S[1] * k) - (S[2] * T2));
            }

            Debug.WriteLine("Additional Corrections:\t" + Math.Round(additionalCorrection, 5));
            JDE = JDE + correction + additionalCorrection;

            return new JulianDay(JDE);
        }
示例#8
0
 public ParamMoonPhase(MoonPhases inMoonPhase)
 {
     _value = inMoonPhase;
 }
 public DateTime getUposathaDateForBuddhistMonth(BuddhistMonths bm, MoonPhases ps)
 {
     switch(ps)
     {
             case(MoonPhases.Full): {
                 ArrayList a = getFullMoonListForYear(gregorianDate.Year);
          		return (DateTime)a[((int)bm)-1];
             }
             case(MoonPhases.New):{
                 ArrayList a = getNewMoonListForYear(gregorianDate.Year);
                 return (DateTime)a[((int)bm)-1];
             }
             case(MoonPhases.Waning):{
                 ArrayList a = getWaningMoonListForYear(gregorianDate.Year);
                 return (DateTime)a[((int)bm)-1];
             }
             case(MoonPhases.Waxing):{
                 ArrayList a = getWaxingMoonListForYear(gregorianDate.Year);
                 return (DateTime)a[((int)bm)-1];
             }
     }
     return DateTime.Now;
 }
示例#10
0
 public SearchParamMoonPhase(MoonPhases inMoonPhase)
 {
     _value = inMoonPhase;
 }
示例#11
0
 public NatureEvents(Winds inWind, MoonPhases inMoonPhase, Tides inTide)
 {
     Wind      = inWind;
     MoonPhase = inMoonPhase;
     Tide      = inTide;
 }
        /*retrieves DateTime Object for a given lunar phase in a given month/year*/
        protected DateTime getMoonPhaseDate(int year, int month, MoonPhases phase)
        {
            DateTime a = DateTime.Now;

            int y, m, d;
            int m0;
            int h;
            int begun = 0;
            int moon = 2;

            double pmax = 1;
            double pmin = 1;
            int ymax = 0; int mmax = 0; int dmax = 0; int hmax = 0;
            int ymin = 0; int mmin = 0; int dmin = 0; int hmin = 0;
            double plast = 0;

            y = year;
            m = month;

            d = 1;
            m0 = m;

            while(true)
            {
                double p = 0;
                int ip = 0;

                for (h = 0; h < 24; h++)
                {
                    p = moon_phase(y, m, d, h, ref ip);

                    if (begun >= 0) {
                        if (p > plast && p > pmax)
                        {
                            pmax = p;
                            ymax = y;
                            mmax = m;
                            dmax = d;
                            hmax = h;
                            moon = 1;
                        }
                        else if (Convert.ToBoolean(pmax))
                        {
                            if(MoonPhases.Full == phase && ymax != 0 && mmax != 0 && dmax != 0)
                                a = new DateTime(ymax, mmax, dmax, hmax, 0 , 0);
                            pmax = 0;
                        }

                        if (p < plast && p < pmin)
                        {
                            pmin = p;
                            ymin = y;
                            mmin = m;
                            dmin = d;
                            hmin = h;
                            moon = 2;
                        }
                        else if (pmin < 1)
                        {
                            if(MoonPhases.New == phase && ymin != 0 && mmin != 0 && dmin != 0)
                                a = new DateTime(ymin, mmin, dmin, hmin, 0, 0);
                            pmin = 1;
                        }
               					if (h == 16)
               					{
               						double k = Math.Floor(p*1000+0.5)/10;
               						if(phase == MoonPhases.Waning)
               							if(k > 50.0 && k < 60.0 && moon == 2) a = new DateTime(y, m, d, h, 0, 0) ;
               						if(phase == MoonPhases.Waxing)
               							if(k > 50.0 && k < 60.0 && moon == 1) a = new DateTime(y, m, d, h, 0, 0) ;
                        }
                    }
                    else begun = 1;

                    plast = p;

                }
                nextDay(ref y, ref m, ref d, 1);
                if (m != m0) break;
            }
            return a;
        }
示例#13
0
文件: Moon.cs 项目: cbries/astronomy
        /// <summary>
        /// Initializes a new instance of the <see cref="Moon"/> class.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="day">The day.</param>
        /// <param name="hour">The hour.</param>
        public Moon(int year, int month, int day)
        {
            var P2 = 3.14159 * 2;
            var YY = year - (Int32)((12 - month) / 10);
            var MM = month + 9;

            if (MM >= 12)
            {
                MM = MM - 12;
            }
            var K1 = (Int32)(365.25 * (YY + 4712));
            var K2 = (Int32)(30.6 * MM + .5);
            var K3 = (Int32)((Int32)((YY / 100) + 49) * .75) - 38;
            var J  = K1 + K2 + day + 59;

            if (J > 2299160)
            {
                J = J - K3;
            }
            var V = (J - 2451550.1) / 29.530588853;

            V = V - (Int32)(V);
            if (V < 0)
            {
                V = V + 1;
            }
            var AG = V * 29.53;

            if ((AG > 27.6849270496875) || (AG <= 1.8456618033125))
            {
                Phase = MoonPhases.newmoon;
            }
            else if ((AG > 1.8456618033125) && (AG <= 5.5369854099375))
            {
                Phase = MoonPhases.waxingcrescent;
            }
            else if ((AG > 5.5369854099375) && (AG <= 9.2283090165625))
            {
                Phase = MoonPhases.firstquarter;
            }
            else if ((AG > 9.2283090165625) && (AG <= 12.9196326231875))
            {
                Phase = MoonPhases.waxinggibbous;
            }
            else if ((AG > 12.9196326231875) && (AG <= 16.6109562298125))
            {
                Phase = MoonPhases.fullmoon;
            }
            else if ((AG > 16.6109562298125) && (AG <= 20.3022798364375))
            {
                Phase = MoonPhases.waninggibbous;
            }
            else if ((AG > 20.3022798364375) && (AG <= 23.9936034430625))
            {
                Phase = MoonPhases.lastquarter;
            }
            else if ((AG > 23.9936034430625) && (AG <= 27.6849270496875))
            {
                Phase = MoonPhases.waningcrescent;
            }
            else
            {
                Phase = MoonPhases.fullmoon;
            }
        }
示例#14
0
        /// <summary>
        /// Finds the current phase for either Masser or Secunda, and sets the correct texture using GetTexture
        /// </summary>
        private MoonPhases GetLunarPhase(ref MoonPhases moonPhase, int day, bool isMasser = true)
        {
            List <string> textureLookup = null;
            Renderer      moonRend;
            int           offset = 3; //3 aligns full moon with vanilla DF for Masser

            if (isMasser)             //-1 for secunda
            {
                offset        = 3;
                textureLookup = masserTextureLookup;
                moonRend      = _masserRend;
            }
            else
            {
                offset        = -1;
                textureLookup = secundaTextureLookup;
                moonRend      = _secundaRend;
            }

            day += offset;
            if (DateTime.Year < 0)
            {
                Debug.LogError("Year < 0 not supported.");
            }

            int        moonRatio = day % 32;        //what moon phase the day falls in
            MoonPhases tempPhase = MoonPhases.Full;

            if (moonRatio == 0)//Full moon
            {
                tempPhase = MoonPhases.Full;
            }
            else if (moonRatio == 16)//new moon, half way
            {
                tempPhase = MoonPhases.New;
            }
            else if (moonRatio <= 5)   //three wane
            {
                tempPhase = MoonPhases.ThreeWane;
            }
            else if (moonRatio <= 10)  //half wane
            {
                tempPhase = MoonPhases.HalfWane;
            }
            else if (moonRatio <= 15) // one wane
            {
                tempPhase = MoonPhases.OneWane;
            }
            else if (moonRatio <= 22)//one wax
            {
                tempPhase = MoonPhases.OneWax;
            }
            else if (moonRatio <= 28)//half wax
            {
                tempPhase = MoonPhases.HalfWax;
            }
            else if (moonRatio <= 31)//three wax
            {
                tempPhase = MoonPhases.ThreeWax;
            }
            if (tempPhase != MoonPhases.New)
            {
                try
                {
                    Resources.UnloadAsset(moonRend.material.mainTexture);
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex.Message + " | isMasser: " + isMasser);
                }
                Texture2D tempText = GetTexture(tempPhase, textureLookup);
                if (tempText != null)
                {
                    moonRend.material.mainTexture = tempText;
                }
                else
                {
                    Debug.LogError("Failed load texture for: " + tempPhase + " isMasser: " + isMasser);
                }
            }

            return(moonPhase = tempPhase);
        }
 public DateTime getLastUposatha()
 {
     int m = getBuddhistMonth(gregorianDate);
     DateTime tg = DateTime.Now;
     DateTime dt = gregorianDate;
     DateTime a = getLastUposatha(MoonPhases.Full);
     DateTime b = getLastUposatha(MoonPhases.New);
     DateTime c = getLastUposatha(MoonPhases.Waxing);
     DateTime d = getLastUposatha(MoonPhases.Waning);
     if(dt >= d)
         {tg = b; recentUposatha = MoonPhases.New;}
     else if(dt >= b)
         {tg = c; recentUposatha = MoonPhases.Waxing;}
     else if(dt >= c)
         {tg = a; recentUposatha = MoonPhases.Full;}
     else { tg = d; recentUposatha = MoonPhases.Waning;}
     /*last uposatha is final moon in  last month*/
     if(tg == getNextUposatha())
     {recentUposatha = MoonPhases.Full; return getUposathaDateForBuddhistMonth((BuddhistMonths)(m-1), MoonPhases.Full);}
     else
         return tg;
 }
 public DateTime getNextUposatha()
 {
     int m = getBuddhistMonth(gregorianDate);
     DateTime tg = DateTime.Now;
     DateTime dt = gregorianDate;
     DateTime a = getNextUposatha(MoonPhases.Full);
     DateTime b = getNextUposatha(MoonPhases.New);
     DateTime c = getNextUposatha(MoonPhases.Waxing);
     DateTime d = getNextUposatha(MoonPhases.Waning);
     if(dt <= d)
         {tg = d; upcomingUposatha = MoonPhases.Waning;}
     else if(dt <= b)
         {tg = b; upcomingUposatha = MoonPhases.New;}
     else if(dt <= c)
         {tg = c; upcomingUposatha = MoonPhases.Waxing;}
     else {tg = a; upcomingUposatha = MoonPhases.Full;}
     return tg;
 }
示例#17
0
        public static JulianDay FindPhase(int year, int month, int day, MoonPhases phase)
        {
            var    jd     = new JulianDay(year, month, day);
            double length = 365;

            if (jd.IsLeapYear)
            {
                length = 366;
            }

            double Y = Math.Round(year + ((double)jd.DayOfYear / length), 2);
            double k = ((Y - 2000) * 12.3685);

            switch (phase)
            {
            case MoonPhases.New:
                k = Math.Round(k);
                break;

            case MoonPhases.FirstQuarter:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.25;
                }
                else
                {
                    k = Math.Floor(k) + 0.25;
                }
                break;

            case MoonPhases.Full:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.50;
                }
                else
                {
                    k = Math.Floor(k) + 0.50;
                }
                break;

            case MoonPhases.LastQuarter:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.75;
                }
                else
                {
                    k = Math.Floor(k) + 0.75;
                }
                break;
            }

            Debug.WriteLine("k\t=\t" + Math.Round(k, 2));

            double T  = k / 1236.85;
            double T2 = Math.Pow(T, 2);
            double T3 = Math.Pow(T, 3);
            double T4 = Math.Pow(T, 4);

            Debug.WriteLine("T\t=\t" + Math.Round(T, 5));

            double JDE = 2451550.09766 + 29.530588861 * k
                         + 0.00015437 * T2
                         - 0.000000150 * T3
                         + 0.00000000073 * T4;

            Debug.WriteLine("JDE\t=\t" + Math.Round(JDE, 5));

            //Corrections

            double E = 1 - 0.002516 * T - 0.0000074 * T2;

            double M = 2.5534 + 29.10535670 * k
                       - 0.0000014 * T2
                       - 0.00000011 * T3;

            Debug.Write("M\t=\t" + Math.Round(M, 4));
            M = AstroMath.Mod(M, 360);
            Debug.WriteLine("\t=\t" + Math.Round(M, 4));

            double Mp = 201.5643 + (385.81693528 * k)
                        + (0.0107582 * T2)
                        + (0.00001238 * T3)
                        - (0.000000058 * T4);


            Debug.Write("M′\t=\t" + Math.Round(Mp, 4));
            Mp = AstroMath.Mod(Mp, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Mp, 4));

            double F = 160.7180 + 390.67050284 * k
                       - 0.0016118 * T2
                       - 0.00000227 * T3
                       + 0.000000011 * T4;

            Debug.Write("F\t=\t" + Math.Round(F, 4));
            F = AstroMath.Mod(F, 360);
            Debug.WriteLine("\t=\t" + Math.Round(F, 4));

            double Ω = 124.7746 - (1.56375588 * k)
                       + (0.0020672 * T2)
                       + (0.00000215 * T3);

            Debug.Write("Ω\t=\t" + Math.Round(Ω, 4));
            Ω = AstroMath.Mod(Ω, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Ω, 4));

            double correction = 0;
            //switch (phase)
            //{
            //    case MoonPhases.Full:
            //        correction = FullMoonCorrections(E, M, Mp, F, Ω);
            //        break;
            //}

            //PlanetaryArguments
            double additionalCorrection = 0;

            for (int i = 0; i <= 13; i++)
            {
                IList <double> S = PlanetaryArguments[i];
                additionalCorrection += AdditionalCorrections[i] * AstroMath.Sin(S[0] + (S[1] * k) - (S[2] * T2));
            }

            Debug.WriteLine("Additional Corrections:\t" + Math.Round(additionalCorrection, 5));
            JDE = JDE + correction + additionalCorrection;

            return(new JulianDay(JDE));
        }
 private DateTime getNextUposatha(MoonPhases ps)
 {
     int a = getBuddhistMonth(gregorianDate);
     return getUposathaDateForBuddhistMonth((BuddhistMonths)a, ps);
 }
示例#19
0
 /// <summary>
 /// Gets the location represented by the moonphase
 /// </summary>
 /// <param name="moonPhase"></param>
 /// <returns></returns>
 public SmallMapReferences.SingleMapReference.Location GetLocationByMoonPhase(MoonPhases moonPhase)
 {
     Debug.Assert(moonPhase >= 0 && (int)moonPhase < 8);
     return((SmallMapReferences.SingleMapReference.Location)(int) moonPhase);
 }