internal void LoadRandomPattern() { NewWePattern = RandomWeatherPattern(); OldWePattern = RandomWeatherPattern(); NewWePattern.OnBeginUse(); OldWePattern.OnBeginUse(); CurWindPattern = WindPatterns[Rand.NextInt(WindPatterns.Length)]; CurWindPattern.OnBeginUse(); CurWeatherEvent = RandomWeatherEvent(); CurWeatherEvent.OnBeginUse(); Weight = 1; wsServer?.SendWeatherStateUpdate(new WeatherState() { RegionX = regionX, RegionZ = regionZ, NewPattern = NewWePattern.State, OldPattern = OldWePattern.State, WindPattern = CurWindPattern.State, WeatherEvent = CurWeatherEvent?.State, TransitionDelay = 0, Transitioning = false, Weight = Weight, updateInstant = false, LcgCurrentSeed = Rand.currentSeed, LcgMapGenSeed = Rand.mapGenSeed, LcgWorldSeed = Rand.worldSeed }); }
public bool SetWindPattern(string code, bool updateInstant) { WindPattern pattern = WindPatterns.FirstOrDefault(p => p.config.Code == code); if (pattern == null) { return(false); } CurWindPattern = pattern; CurWindPattern.OnBeginUse(); wsServer.SendWeatherStateUpdate(new WeatherState() { RegionX = regionX, RegionZ = regionZ, NewPattern = NewWePattern.State, OldPattern = OldWePattern.State, WindPattern = CurWindPattern.State, TransitionDelay = 0, Transitioning = false, Weight = Weight, updateInstant = updateInstant, LcgCurrentSeed = Rand.currentSeed, LcgMapGenSeed = Rand.mapGenSeed, LcgWorldSeed = Rand.worldSeed }); return(true); }
internal void Initialize() { for (int i = 0; i < WeatherPatterns.Length; i++) { WeatherPatterns[i].Initialize(i, ws.api.World.Seed); } NewWePattern = WeatherPatterns[0]; OldWePattern = WeatherPatterns[0]; CurWindPattern = WindPatterns[0]; IsInitialized = true; }
public bool SetWindPattern(string code, bool updateInstant) { WindPattern pattern = WindPatterns.FirstOrDefault(p => p.config.Code == code); if (pattern == null) { return(false); } CurWindPattern = pattern; CurWindPattern.OnBeginUse(); sendState(updateInstant); return(true); }
internal void ReloadPatterns(int seed) { WeatherPatterns = new WeatherPattern[ws.weatherConfigs.Length]; for (int i = 0; i < ws.weatherConfigs.Length; i++) { WeatherPatterns[i] = new WeatherPattern(ws, ws.weatherConfigs[i], Rand, cloudTilebasePosX, cloudTilebasePosZ); WeatherPatterns[i].State.Index = i; } WindPatterns = new WindPattern[ws.windConfigs.Length]; for (int i = 0; i < ws.windConfigs.Length; i++) { WindPatterns[i] = new WindPattern(ws.api, ws.windConfigs[i], i, Rand, seed); } }
internal void FromBytes(byte[] data) { if (data == null) { LoadRandomPattern(); NewWePattern.OnBeginUse(); } else { WeatherState state = SerializerUtil.Deserialize <WeatherState>(data); if (state.NewPattern != null) { NewWePattern = WeatherPatterns[state.NewPattern.Index]; NewWePattern.State = state.NewPattern; } else { NewWePattern = WeatherPatterns[0]; } if (state.OldPattern != null) { OldWePattern = WeatherPatterns[state.OldPattern.Index]; OldWePattern.State = state.OldPattern; } else { OldWePattern = WeatherPatterns[0]; } if (state.WindPattern != null) { CurWindPattern = WindPatterns[state.WindPattern.Index]; CurWindPattern.State = state.WindPattern; } Weight = state.Weight; TransitionDelay = state.TransitionDelay; Transitioning = state.Transitioning; LastUpdateTotalHours = state.LastUpdateTotalHours; Rand.worldSeed = state.LcgWorldSeed; Rand.currentSeed = state.LcgCurrentSeed; Rand.mapGenSeed = state.LcgMapGenSeed; } }
internal void FromBytes(byte[] data) { if (data == null) { LoadRandomPattern(); NewWePattern.OnBeginUse(); } else { WeatherState state = SerializerUtil.Deserialize <WeatherState>(data); if (state.NewPattern != null) { NewWePattern = WeatherPatterns[state.NewPattern.Index]; NewWePattern.State = state.NewPattern; } else { NewWePattern = WeatherPatterns[0]; } if (state.OldPattern != null && state.OldPattern.Index < WeatherPatterns.Length) { OldWePattern = WeatherPatterns[state.OldPattern.Index]; OldWePattern.State = state.OldPattern; } else { OldWePattern = WeatherPatterns[0]; } if (state.WindPattern != null) { CurWindPattern = WindPatterns[state.WindPattern.Index]; CurWindPattern.State = state.WindPattern; } Weight = state.Weight; TransitionDelay = state.TransitionDelay; Transitioning = state.Transitioning; LastUpdateTotalHours = state.LastUpdateTotalHours; Rand.worldSeed = state.LcgWorldSeed; Rand.currentSeed = state.LcgCurrentSeed; Rand.mapGenSeed = state.LcgMapGenSeed; double nowTotalHours = ws.api.World.Calendar.TotalHours; // Cap that at max 1 year or we simulate forever on startup LastUpdateTotalHours = Math.Max(LastUpdateTotalHours, nowTotalHours - 12 * 12 * 24); SnowAccumSnapshots = new RingArray <SnowAccumSnapshot>((int)(ws.api.World.Calendar.DaysPerYear * ws.api.World.Calendar.HoursPerDay) + 1, state.SnowAccumSnapshots); if (state.WeatherEvent != null) { CurWeatherEvent = WeatherEvents[state.WeatherEvent.Index]; CurWeatherEvent.State = state.WeatherEvent; } if (CurWeatherEvent == null) { CurWeatherEvent = RandomWeatherEvent(); CurWeatherEvent.OnBeginUse(); } } }
public void TickEvery25ms(float dt) { if (ws.api.Side == EnumAppSide.Client) { clientUpdate(dt); } else { double nowTotalHours = ws.api.World.Calendar.TotalHours; while (nowTotalHours - LastUpdateTotalHours > 1) { TickEveryInGameHourServer(LastUpdateTotalHours); LastUpdateTotalHours++; } } if (Transitioning) { float speed = ws.api.World.Calendar.SpeedOfTime / 60f; Weight += dt / TransitionDelay * speed; if (Weight > 1) { Transitioning = false; Weight = 1; } } else { if (ws.autoChangePatterns && ws.api.Side == EnumAppSide.Server && ws.api.World.Calendar.TotalHours > NewWePattern.State.ActiveUntilTotalHours) { TriggerTransition(); } } if (ws.autoChangePatterns && ws.api.Side == EnumAppSide.Server) { bool sendPacket = false; if (ws.api.World.Calendar.TotalHours > CurWindPattern.State.ActiveUntilTotalHours) { CurWindPattern = WindPatterns[Rand.NextInt(WindPatterns.Length)]; CurWindPattern.OnBeginUse(); sendPacket = true; } if (ws.api.World.Calendar.TotalHours > CurWeatherEvent.State.ActiveUntilTotalHours || CurWeatherEvent.ShouldStop(weatherData.climateCond.Rainfall, weatherData.climateCond.Temperature)) { CurWeatherEvent = RandomWeatherEvent(); CurWeatherEvent.OnBeginUse(); sendPacket = true; } if (sendPacket) { wsServer.SendWeatherStateUpdate(new WeatherState() { RegionX = regionX, RegionZ = regionZ, NewPattern = NewWePattern.State, OldPattern = OldWePattern.State, WindPattern = CurWindPattern.State, WeatherEvent = CurWeatherEvent?.State, TransitionDelay = TransitionDelay, Transitioning = Transitioning, Weight = Weight, LcgCurrentSeed = Rand.currentSeed, LcgMapGenSeed = Rand.mapGenSeed, LcgWorldSeed = Rand.worldSeed }); } } NewWePattern.Update(dt); OldWePattern.Update(dt); CurWindPattern.Update(dt); CurWeatherEvent.Update(dt); float curWindSpeed = weatherData.curWindSpeed.X; float targetWindSpeed = (float)GetWindSpeed(ws.api.World.SeaLevel); curWindSpeed += GameMath.Clamp((targetWindSpeed - curWindSpeed) * dt, -0.001f, 0.001f); weatherData.curWindSpeed.X = curWindSpeed; quarterSecAccum += dt; if (quarterSecAccum > 0.25f) { regionCenterPos.Y = ws.api.World.BlockAccessor.GetRainMapHeightAt(regionCenterPos); if (regionCenterPos.Y == 0) { regionCenterPos.Y = ws.api.World.SeaLevel; // Map chunk might not be loaded. In that case y will be 0. } ClimateCondition nowcond = ws.api.World.BlockAccessor.GetClimateAt(regionCenterPos); if (nowcond != null) { weatherData.climateCond = nowcond; } quarterSecAccum = 0; } weatherData.BlendedPrecType = CurWeatherEvent.State.PrecType; }