private bool AdvanceWeather() { Random rander = new Random(); HashSet <MeterologicalFront> newFronts = new HashSet <MeterologicalFront>(); foreach (MeterologicalFront front in MeterologicalFronts) { //TODO: Fix my bullshit math and switch weather event cloud types as they shift and fix altitude IPressureSystem frontFront = front.Event; float originalPressure = frontFront.Pressure; //Calculate strength and pressure changes IEnumerable <IZone> myZones = LiveCache.GetAll <IZone>().Where(z => z.IsOutside() && z.Hemisphere == frontFront.Direction); if (myZones.Count() > 0) { double zoneInfluenceUp = myZones.Average(z => z.EffectiveHumidity()); double zoneInfluenceDown = myZones.Average(z => z.EffectiveTemperature()); frontFront.Pressure += DataUtility.TryConvert <float>(zoneInfluenceUp - (zoneInfluenceDown * 45)); int frontVariance = frontFront.Pressure > originalPressure ? -1 : 1; frontFront.Strength = Math.Max(1, Math.Min(100, frontFront.Strength + frontVariance)); //Alter zones foreach (IZone zone in myZones) { float zoneVariance = zone.WeatherEvents.Sum(wEvent => (wEvent.Strength + wEvent.Drain) / (wEvent.Altitude / 10000)); List <IWeatherEvent> zoneEventList = new List <IWeatherEvent>(); foreach (IWeatherEvent cloud in zone.WeatherEvents) { cloud.Drain += zoneVariance; cloud.Coverage += cloud.Drain; cloud.PrecipitationAmount += cloud.Drain; cloud.Strength -= cloud.Drain; if (cloud.Strength > 0) { zoneEventList.Add(cloud); } } //Spawn new weather event? if (zoneVariance < 10) { zoneEventList.Add(new WeatherEvent() { Altitude = rander.Next(7500, 50000), Coverage = rander.Next(1, 35), Drain = 0, PrecipitationAmount = 0, Strength = rander.Next(100, 1000), Type = WeatherEventType.Altocumulus }); zone.WeatherEvents = zoneEventList; BroadcastEvent("Clouds begin to darken overhead."); } zone.Humidity += DataUtility.TryConvert <int>(Math.Max(870, Math.Min(1080, frontVariance * zoneVariance * 45))); zone.Temperature += DataUtility.TryConvert <int>(Math.Max(-50, Math.Min(50, frontVariance * zoneVariance))); zone.Save(); } } //Move it float newPosition = front.Position + frontFront.Speed; //TODO: Not hardcode this, but this is HMR not a normal mud int hemisphericLength = 3185495; //if this goes over it wants to move to a new hemisphere if (newPosition > hemisphericLength) { newPosition = Math.Abs(hemisphericLength - (newPosition - hemisphericLength)); switch (frontFront.Direction) { case HemispherePlacement.NorthEast: frontFront.Direction = HemispherePlacement.SouthWest; break; case HemispherePlacement.NorthWest: frontFront.Direction = HemispherePlacement.SouthEast; break; case HemispherePlacement.SouthEast: frontFront.Direction = HemispherePlacement.NorthWest; break; case HemispherePlacement.SouthWest: frontFront.Direction = HemispherePlacement.NorthEast; break; } } newFronts.Add(new MeterologicalFront(frontFront, newPosition)); } MeterologicalFronts = newFronts; Save(); return(true); }
public MeterologicalFront(IPressureSystem weatherEvent, float position) { Event = weatherEvent; Position = position; }