Exemple #1
0
        public bool SetWeatherPattern(string code, bool updateInstant)
        {
            WeatherPattern pattern = WeatherPatterns.FirstOrDefault(p => p.config.Code == code);

            if (pattern == null)
            {
                return(false);
            }

            OldWePattern    = NewWePattern;
            NewWePattern    = pattern;
            Weight          = 1;
            Transitioning   = false;
            TransitionDelay = 0;
            if (NewWePattern != OldWePattern || updateInstant)
            {
                NewWePattern.OnBeginUse();
            }

            UpdateWeatherData();

            sendState(updateInstant);

            return(true);
        }
Exemple #2
0
        public void TriggerTransition(float delay)
        {
            Transitioning   = true;
            TransitionDelay = delay;

            Weight       = 0;
            OldWePattern = NewWePattern;
            NewWePattern = RandomWeatherPattern();
            if (NewWePattern != OldWePattern)
            {
                NewWePattern.OnBeginUse();
            }


            wsServer.SendWeatherStateUpdate(new WeatherState()
            {
                RegionX         = regionX,
                RegionZ         = regionZ,
                NewPattern      = NewWePattern.State,
                OldPattern      = OldWePattern.State,
                WindPattern     = CurWindPattern.State,
                WeatherEvent    = CurWeatherEvent?.State,
                TransitionDelay = TransitionDelay,
                Transitioning   = true,
                Weight          = Weight,
                LcgCurrentSeed  = Rand.currentSeed,
                LcgMapGenSeed   = Rand.mapGenSeed,
                LcgWorldSeed    = Rand.worldSeed
            });
        }
        public void SetAmbient(WeatherPattern left, float addFogDensity = 0)
        {
            // 1-(1.1-x)^4
            // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIxLSgxLjEteCleNCIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIjAiLCIxIiwiMCIsIjEiXX1d
            float drynessMultiplier = GameMath.Clamp(1 - (float)Math.Pow(1.1 - climateCond.Rainfall, 4), 0, 1);
            float fogMultiplier     = drynessMultiplier;


            Ambient.FlatFogDensity.Value   = left.State.nowMistDensity / 250f;
            Ambient.FlatFogDensity.Weight  = 1;
            Ambient.FlatFogDensity.Weight *= fogMultiplier;

            Ambient.FlatFogYPos.Value  = left.State.nowMistYPos;
            Ambient.FlatFogYPos.Weight = 1;

            Ambient.FogDensity.Value  = (addFogDensity + left.State.nowFogDensity) / 1000f;
            Ambient.FogDensity.Weight = fogMultiplier;

            Ambient.CloudBrightness.Value  = left.State.nowCloudBrightness;
            Ambient.CloudBrightness.Weight = 1;

            //PrecParticleSize = left.State.nowPrecParticleSize;
            //PrecIntensity = drynessMultiplier * left.State.nowPrecIntensity;

            Ambient.CloudDensity.Value  = left.State.nowbaseThickness;
            Ambient.CloudDensity.Weight = 1;

            Ambient.SceneBrightness.Value  = left.State.nowSceneBrightness;
            Ambient.SceneBrightness.Weight = 1f;

            Ambient.FogBrightness.Value  = left.State.nowFogBrightness;
            Ambient.FogBrightness.Weight = 1f;
        }
Exemple #4
0
        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
            });
        }
Exemple #5
0
        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;
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        internal void Initialize()
        {
            for (int i = 0; i < Patterns.Length; i++)
            {
                Patterns[i].Initialize(i);
            }

            if (ws.api.Side == EnumAppSide.Client)
            {
                smoothedLightLevel = ws.capi.World.BlockAccessor.GetLightLevel(ws.capi.World.Player.Entity.Pos.AsBlockPos, EnumLightLevelType.OnlySunLight);
            }

            NewPattern = Patterns[0];
            OldPattern = Patterns[0];
        }
        public void InitDummySim()
        {
            dummySim         = new WeatherSimulationRegion(this, 0, 0);
            dummySim.IsDummy = true;
            dummySim.Initialize();

            var rand = new LCGRandom(api.World.Seed);

            rand.InitPositionSeed(3, 3);

            rainOverlayPattern = new WeatherPattern(this, GeneralConfig.RainOverlayPattern, rand, 0, 0);
            rainOverlayPattern.Initialize(0, api.World.Seed);
            rainOverlayPattern.OnBeginUse();

            rainOverlaySnap = new WeatherDataSnapshot();
        }
        public void LoadLerp(Vec3d pos, bool useArgValues, float lerpRainCloudOverlay = 0, float lerpRainOverlay = 0, float dt = 1)
        {
            int regSize = api.World.BlockAccessor.RegionSize;

            double regionRelX = (pos.X / regSize) - (int)Math.Round(pos.X / regSize);
            double regionRelZ = (pos.Z / regSize) - (int)Math.Round(pos.Z / regSize);

            LerpTopBot    = GameMath.Smootherstep(regionRelX + 0.5);
            LerpLeftRight = GameMath.Smootherstep(regionRelZ + 0.5);

            rainOverlayData = ws.rainOverlayPattern;
            rainSnapData    = ws.rainOverlaySnap;


            if (hereMapRegion == null)
            {
                this.lerpRainCloudOverlay = 0;
                this.lerpRainOverlay      = 0;
            }
            else
            {
                if (useArgValues)
                {
                    this.lerpRainCloudOverlay = lerpRainCloudOverlay;
                    this.lerpRainOverlay      = lerpRainOverlay;
                }
                else
                {
                    tmpPos.Set((int)pos.X, (int)pos.Y, (int)pos.Z);

                    int noiseSizeClimate = hereMapRegion.ClimateMap.InnerSize;
                    int climate          = 128 | (128 << 8) | (128 << 16);

                    if (noiseSizeClimate > 0)
                    {
                        double posXInRegionClimate = Math.Max(0, (pos.X / regSize - (int)pos.X / regSize) * noiseSizeClimate);
                        double posZInRegionClimate = Math.Max(0, (pos.Z / regSize - (int)pos.Z / regSize) * noiseSizeClimate);
                        climate = hereMapRegion.ClimateMap.GetUnpaddedColorLerped((float)posXInRegionClimate, (float)posZInRegionClimate);
                    }

                    ClimateCondition conds  = ws.GetClimateFast(tmpPos, climate);
                    float            tspeed = Math.Min(1, dt * 10);
                    this.lerpRainCloudOverlay = this.lerpRainCloudOverlay + (conds.RainCloudOverlay - this.lerpRainCloudOverlay) * tspeed;
                    this.lerpRainOverlay      = this.lerpRainOverlay + (conds.Rainfall - this.lerpRainOverlay) * tspeed;
                }
            }
        }
Exemple #10
0
        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;
            }
        }
Exemple #11
0
        public void TriggerTransition(float delay)
        {
            Transitioning   = true;
            TransitionDelay = delay;

            Weight     = 0;
            OldPattern = NewPattern;
            NewPattern = RandomPattern();
            if (NewPattern != OldPattern)
            {
                NewPattern.OnBeginUse();
            }

            ws.serverChannel.BroadcastPacket(new WeatherState()
            {
                NewPatternIndex = NewPattern.Index,
                OldPatternIndex = OldPattern.Index,
                TransitionDelay = TransitionDelay,
                Transitioning   = true
            });
        }
Exemple #12
0
        public bool SetWeatherPattern(string code, bool updateInstant)
        {
            WeatherPattern pattern = WeatherPatterns.FirstOrDefault(p => p.config.Code == code);

            if (pattern == null)
            {
                return(false);
            }

            OldWePattern    = NewWePattern;
            NewWePattern    = pattern;
            Weight          = 1;
            Transitioning   = false;
            TransitionDelay = 0;
            if (NewWePattern != OldWePattern || updateInstant)
            {
                NewWePattern.OnBeginUse();
            }

            UpdateWeatherData();

            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);
        }
Exemple #13
0
        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();
                }
            }
        }
Exemple #14
0
        public WeatherSimulation(WeatherSystem ws)
        {
            this.ws        = ws;
            rand           = new Random(ws.api.World.Seed);
            BlendedAmbient = new AmbientModifier().EnsurePopulated();

            if (ws.api.Side == EnumAppSide.Client)
            {
                ws.capi.Ambient.CurrentModifiers.InsertBefore("serverambient", "weather", BlendedAmbient);
            }

            WeatherPattern ClearSky = new WeatherPatternClearSky(ws, "ClearSky", 1);

            ClearSky.Ambient.FogDensity = new WeightedFloat(2 / 2000f, 1);

            WeatherPattern CumulusClouds = new WeatherPattern(ws, "Cumulus Clouds", 1)
            {
                CloudDensityNoise       = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudOffsetYNoise       = new SimplexNoise(new double[] { 2 }, new double[] { 1.5 }, rand.Next())
            };

            WeatherPattern StratusClouds = CumulusClouds.Clone();

            StratusClouds.Name = "Stratus Clouds";
            StratusClouds.Ambient.FlatFogYPos    = new WeightedFloat(25, 1);
            StratusClouds.Ambient.FlatFogDensity = new WeightedFloat(6 / 250f, 1);
            StratusClouds.Ambient.FogDensity     = new WeightedFloat(10 / 2000f, 1);
            StratusClouds.Chance = 0.35f;

            WeatherPattern CumulusCloudsWithFlatMist = CumulusClouds.Clone();

            CumulusCloudsWithFlatMist.Name = "Cumulus Clouds + Flat dense Mist";
            CumulusCloudsWithFlatMist.Ambient.FlatFogYPos    = new WeightedFloat(5, 1);
            CumulusCloudsWithFlatMist.Ambient.FlatFogDensity = new WeightedFloat(-100 / 250f, 1);
            CumulusCloudsWithFlatMist.BeginUse += () =>
            {
                CumulusCloudsWithFlatMist.Ambient.FlatFogDensity.Value = (-50 - 100 * (float)(rand.NextDouble() * rand.NextDouble())) / 300f;
                CumulusCloudsWithFlatMist.Ambient.FlatFogYPos.Value    = 1 + 7 * (float)rand.NextDouble();
            };

            CumulusCloudsWithFlatMist.ChanceOfWeatherChange = 0.008f;
            CumulusCloudsWithFlatMist.Chance = 0.1f;

            WeatherPattern CumulusCloudsWithTallMist = CumulusClouds.Clone();

            CumulusCloudsWithTallMist.Name = "Cumulus Clouds + Tall dense Mist";
            CumulusCloudsWithTallMist.Ambient.FlatFogYPos    = new WeightedFloat(40, 1);
            CumulusCloudsWithTallMist.Ambient.FlatFogDensity = new WeightedFloat(-30 / 250f, 1);
            CumulusCloudsWithTallMist.BeginUse += () => {
                CumulusCloudsWithTallMist.Ambient.FlatFogDensity.Value = (-50 - 50 * (float)(rand.NextDouble() * rand.NextDouble())) / 2000f;
                CumulusCloudsWithTallMist.Ambient.FlatFogYPos.Value    = 30 + 30 * (float)rand.NextDouble();
            };
            CumulusCloudsWithTallMist.ChanceOfWeatherChange = 0.008f;
            CumulusCloudsWithTallMist.Chance = 0.05f;

            WeatherPattern CumulusCloudsWithFog = CumulusClouds.Clone();

            CumulusCloudsWithFog.Name = "Cumulus Clouds + Fog";
            CumulusCloudsWithFog.Ambient.FogDensity = new WeightedFloat(40 / 2000f, 1);
            CumulusCloudsWithFog.BeginUse          += () => { CumulusCloudsWithFog.Ambient.FogDensity.Value = (10 + 30 * (float)rand.NextDouble()) / 2000f; };
            CumulusCloudsWithFog.Chance             = 0.35f;

            WeatherPattern NimboStratusClouds = new WeatherPattern(ws, "Nimbostratus Clouds", 1)
            {
                CloudDensityNoise       = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudOffsetYNoise       = new SimplexNoise(new double[] { 2 }, new double[] { 1.5 }, rand.Next())
            };

            WeatherPattern AltoCumulusClouds = new WeatherPattern(ws, "Altocumulus Clouds", 1)
            {
                CloudDensityNoise       = new SimplexNoise(new double[] { 3 }, new double[] { 10 }, rand.Next()),
                CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudOffsetYNoise       = new SimplexNoise(new double[] { 1 }, new double[] { 1.5 }, rand.Next())
            };


            WeatherPattern CirroCumulusClouds = new WeatherPattern(ws, "Cirrocumulus Clouds", 1)
            {
                CloudDensityNoise       = new SimplexNoise(new double[] { 3 }, new double[] { 10 }, rand.Next()),
                CloudDensityOffsetNoise = new SimplexNoise(new double[] { 4 }, new double[] { 1.5 }, rand.Next()),
                CloudOffsetYNoise       = new SimplexNoise(new double[] { 1 }, new double[] { 1.5 }, rand.Next())
            };

            CirroCumulusClouds.CloudYOffset = 100;

            Patterns = new WeatherPattern[]
            {
                ClearSky, CumulusClouds, CumulusCloudsWithFlatMist, CumulusCloudsWithTallMist, CumulusCloudsWithFog, StratusClouds, NimboStratusClouds, AltoCumulusClouds, CirroCumulusClouds
            };
        }
Exemple #15
0
 internal void LoadRandomPattern()
 {
     NewPattern = RandomPattern();
     OldPattern = RandomPattern();
     Weight     = 1;
 }