public override bool Equals(object obj) { WeatherSystem other = obj as WeatherSystem; if (other == null) { return(false); } return(Id == other.Id); }
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; } }
public static WeatherSystem CreateRandomWeatherSystem( GameConstants.WeatherSystemTypes weatherType, GameConstants.WeatherSystemSeasonTypes season, double latitude) { WeatherSystem system = new WeatherSystem(); system.WindDirectionFromDeg = GameManager.Instance.GetRandomNumber(360); if (GameManager.Instance.ThrowDice(34)) { system.WindDirectionFromDeg = GameManager.Instance.GetRandomNumber(30) + 240; //wind tends to be from the west } double MinTemp = 0; double MaxTemp = 0; GetMinMaxTempFromLatitude(season, latitude, out MinTemp, out MaxTemp); int TempRange = (int)GetRange(MinTemp, MaxTemp); system.TemperatureC = GameManager.Instance.GetRandomNumber(TempRange) + MinTemp; switch (weatherType) { case GameConstants.WeatherSystemTypes.Random: system.CloudCover8ths = GameManager.Instance.GetRandomNumber(8); if (season == GameConstants.WeatherSystemSeasonTypes.Summer && GameManager.Instance.ThrowDice(50)) { system.CloudCover8ths = GameManager.Instance.GetRandomNumber(3); } system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(30); if (system.WindSpeedMSec > 10 && GameManager.Instance.ThrowDice(25)) { system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(5); } system.Precipitation = (GameConstants.PrecipitationLevel) GameManager.Instance.GetRandomNumber((int)GameConstants.PrecipitationLevel.Heavy); if (GameManager.Instance.ThrowDice(25)) { system.Precipitation = GameConstants.PrecipitationLevel.None; } if (system.Precipitation > GameConstants.PrecipitationLevel.None) { if (system.TemperatureC > 0) { system.PrecipitationType = GameConstants.PrecipitationType.Rain; } else { system.PrecipitationType = GameConstants.PrecipitationType.Snow; } } break; case GameConstants.WeatherSystemTypes.Fine: system.CloudCover8ths = GameManager.Instance.GetRandomNumber(2); system.Precipitation = GameConstants.PrecipitationLevel.None; system.TemperatureC = system.TemperatureC.Clamp(-5, 25); system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(5); break; case GameConstants.WeatherSystemTypes.Fair: system.CloudCover8ths = GameManager.Instance.GetRandomNumber(2); system.Precipitation = GameConstants.PrecipitationLevel.None; if (GameManager.Instance.ThrowDice(20)) { system.Precipitation = GameConstants.PrecipitationLevel.Light; } system.TemperatureC = system.TemperatureC.Clamp(-5, 25); system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(12); break; case GameConstants.WeatherSystemTypes.Rough: system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(15) + 10; system.Precipitation = (GameConstants.PrecipitationLevel) GameManager.Instance.GetRandomNumber((int)GameConstants.PrecipitationLevel.Heavy); if (system.Precipitation > GameConstants.PrecipitationLevel.None) { if (system.TemperatureC > 0) { system.PrecipitationType = GameConstants.PrecipitationType.Rain; } else { system.PrecipitationType = GameConstants.PrecipitationType.Snow; } } break; case GameConstants.WeatherSystemTypes.Severe: system.WindSpeedMSec = GameManager.Instance.GetRandomNumber(20) + 20; system.Precipitation = (GameConstants.PrecipitationLevel) GameManager.Instance.GetRandomNumber((int)GameConstants.PrecipitationLevel.Heavy); if (system.Precipitation > GameConstants.PrecipitationLevel.None) { if (system.TemperatureC > 0) { system.PrecipitationType = GameConstants.PrecipitationType.Rain; } else { system.PrecipitationType = GameConstants.PrecipitationType.Snow; } } break; } if (system.Precipitation >= GameConstants.PrecipitationLevel.Light && system.CloudCover8ths < 7) { system.CloudCover8ths = 7; } if (system.Precipitation > GameConstants.PrecipitationLevel.Intermediate && system.CloudCover8ths < 8) { system.CloudCover8ths = 8; } return(system); }
public static WeatherSystem CreateInterpolatedWeatherSystem(Coordinate coord) { WeatherSystem system = new WeatherSystem(); system.Coordinate = new Coordinate(coord);//coord; BlackboardFinder <WeatherSystem> finder = new BlackboardFinder <WeatherSystem>(); WeatherSystem mainSystem = (WeatherSystem)finder.GetClosestObject(coord); if (mainSystem == null) { return(null); } WeatherSystem otherSystem = null; List <IBlackboardObject> wsystems = finder.GetAllSortedByCoordinateAndType(coord, 10000000).ToList <IBlackboardObject>(); //{ // WeatherSystem wsystem = wsys as WeatherSystem; // if (wsystem !=null && wsys.Id != mainSystem.Id) // { // otherSystem = wsystem; // } //} if (wsystems.Count > 1) { otherSystem = (WeatherSystem)wsystems[1]; } system = (WeatherSystem)mainSystem.MemberwiseClone(); system.Coordinate = new Coordinate(coord);//coord; system.GameTime = GameManager.Instance.Game.GameCurrentTime; double BearingDegToMain = MapHelper.CalculateBearingDegrees(coord, mainSystem.Coordinate); if (otherSystem != null) { double BearingDegToOther = MapHelper.CalculateBearingDegrees(coord, otherSystem.Coordinate); double DistanceToMain = MapHelper.CalculateDistanceM(mainSystem.Coordinate, coord); double DistanceToOther = MapHelper.CalculateDistanceM(otherSystem.Coordinate, coord); double WeightMainPercent = (DistanceToMain / (DistanceToMain + DistanceToOther)) * 100; //if (Math.Abs(BearingDegToMain - BearingDegToOther) > 100) //{ system.CloudCover8ths = InterpolateInt(mainSystem.CloudCover8ths, otherSystem.CloudCover8ths); system.PrecipitationType = (GameConstants.PrecipitationType)InterpolateInt( (int)mainSystem.PrecipitationType, (int)otherSystem.PrecipitationType); system.TemperatureC = Math.Round(InterpolateWeighedDouble(mainSystem.TemperatureC, otherSystem.TemperatureC, WeightMainPercent)); system.WindDirectionFromDeg = Math.Round(InterpolateWeighedDouble(mainSystem.WindDirectionFromDeg, otherSystem.WindDirectionFromDeg, WeightMainPercent)); system.WindSpeedMSec = Math.Round(InterpolateWeighedDouble(mainSystem.WindSpeedMSec, otherSystem.WindSpeedMSec, WeightMainPercent)); // } } //Add some random variation system.CloudCover8ths += GameManager.Instance.GetRandomNumber(2) - 1; if (system.CloudCover8ths > 8) { system.CloudCover8ths = 8; } else if (system.CloudCover8ths < 0) { system.CloudCover8ths = 0; } system.TemperatureC += GameManager.Instance.GetRandomNumber(2) - 1; system.WindSpeedMSec += GameManager.Instance.GetRandomNumber(2) - 1; if (system.WindSpeedMSec < 0) { system.WindSpeedMSec = 0; } if (system.Precipitation > GameConstants.PrecipitationLevel.None && system.Precipitation < GameConstants.PrecipitationLevel.Heavy) { system.Precipitation = (GameConstants.PrecipitationLevel)((int)system.Precipitation) + (GameManager.Instance.GetRandomNumber(2) - 1); } if (system.Precipitation > GameConstants.PrecipitationLevel.None && system.CloudCover8ths < 7) { system.CloudCover8ths = 7; } if (system.Precipitation > GameConstants.PrecipitationLevel.Light && system.CloudCover8ths < 8) { system.CloudCover8ths = 8; } if (system.Precipitation != GameConstants.PrecipitationLevel.None) { if (system.TemperatureC <= 0) { system.PrecipitationType = GameConstants.PrecipitationType.Snow; if (system.TemperatureC > -5 && system.WindSpeedMSec < 15 && GameManager.Instance.ThrowDice(5)) { system.PrecipitationType = GameConstants.PrecipitationType.Hail; } } else { system.PrecipitationType = GameConstants.PrecipitationType.Rain; } } system.RecalculateMoonAndSunInformation(); system.RecalculateSunshine(); return(system); }