Exemplo n.º 1
0
        private static void OnAreaEnter()
        {
            using (new Profiler("WeatherService.OnAreaEnter"))
            {
                SetWeather();

                LoggingService.Trace(TraceComponent.Weather, "Applying weather to creature: " + GetName(GetEnteringObject()));

                DoWeatherEffects(GetEnteringObject());

                NWArea oArea     = (OBJECT_SELF);
                int    nHour     = GetTimeHour();
                int    nLastHour = oArea.GetLocalInt("WEATHER_LAST_HOUR");

                if (nHour != nLastHour)
                {
                    if (!oArea.Data.ContainsKey("WEATHER_OBJECTS"))
                    {
                        oArea.Data["WEATHER_OBJECTS"] = new List <NWPlaceable>();
                    }
                    List <NWPlaceable> weatherObjects = oArea.Data["WEATHER_OBJECTS"];

                    LoggingService.Trace(TraceComponent.Weather, "Cleaning up old weather");

                    // Clean up any old weather placeables.
                    for (int x = weatherObjects.Count - 1; x >= 0; x--)
                    {
                        var placeable = weatherObjects.ElementAt(x);
                        placeable.Destroy();
                        weatherObjects.RemoveAt(x);
                    }

                    // Create new ones depending on the current weather.
                    var nWeather = GetWeather();
                    LoggingService.Trace(TraceComponent.Weather, "Current weather: " + nWeather.ToString());

                    if (nWeather == Weather.Foggy)
                    {
                        // Get the size in tiles.
                        int nSizeX = GetAreaSize(Dimension.Width, oArea);
                        int nSizeY = GetAreaSize(Dimension.Height, oArea);

                        // We want one placeable per 8 tiles.
                        int nMax = (nSizeX * nSizeY) / 8;
                        LoggingService.Trace(TraceComponent.Weather, "Creating up to " + nMax.ToString() + " mist objects.");

                        for (int nCount = d6(); nCount < nMax; nCount++)
                        {
                            Vector vPosition = GetPosition(GetEnteringObject());

                            // Vectors are in meters - 10 meters to a tile.
                            vPosition.X = IntToFloat(Random(nSizeX * 10));
                            vPosition.Y = IntToFloat(Random(nSizeY * 10));

                            float fFacing = IntToFloat(Random(360));

                            string sResRef = "x3_plc_mist";

                            NWPlaceable oPlaceable = CreateObject(ObjectType.Placeable, sResRef, Location(oArea, vPosition, fFacing));
                            SetObjectVisualTransform(oPlaceable, ObjectVisualTransform.Scale, IntToFloat(200 + Random(200)) / 100.0f);

                            weatherObjects.Add(oPlaceable);
                        }
                    }

                    oArea.Data["WEATHER_OBJECTS"] = weatherObjects;
                    oArea.SetLocalInt("WEATHER_LAST_HOUR", nHour);
                }
            }
        }
Exemplo n.º 2
0
        public static bool AdjustWeather()
        {
            LoggingService.Trace(TraceComponent.Weather, "Adjusting module weather");
            NWObject oMod = GetModule();

            //--------------------------------------------------------------------------
            // Always change the weather the very first time
            //--------------------------------------------------------------------------
            if (oMod.GetLocalInt(VAR_INITIALIZED) == 0)
            {
                oMod.SetLocalInt(VAR_INITIALIZED, 1);
                _SetHumidity(Random(10) + 1);
            }
            else if (GetTimeHour() != oMod.GetLocalInt(VAR_WEATHER_CHANGE))
            {
                LoggingService.Trace(TraceComponent.Weather, "No change needed... yet.");
                return(false);
            }

            //--------------------------------------------------------------------------
            // Adjust the indices.  Only humidity is affected by the current values.
            //--------------------------------------------------------------------------
            int nHumidity = GetHumidity(OBJECT_SELF);
            int nWind     = GetWindStrength(OBJECT_SELF);

            //--------------------------------------------------------------------------
            // Heat is affected by time of year.
            //--------------------------------------------------------------------------
            var nHeat = Random(5) + (6 - abs(GetCalendarMonth() - 6));

            if (nHeat < 1)
            {
                nHeat = 1;
            }

            //--------------------------------------------------------------------------
            // Humidity is random but moves slowly.
            //--------------------------------------------------------------------------
            nHumidity = nHumidity + (Random(2 * nWind + 1) - nWind);
            if (nHumidity > 10)
            {
                nHumidity = 20 - nHumidity;
            }
            if (nHumidity < 1)
            {
                nHumidity = 1 - nHumidity;
            }

            //--------------------------------------------------------------------------
            // Wind is more likely to be calm, but can change quickly.
            //--------------------------------------------------------------------------
            nWind = d10(2) - 10;
            if (nWind < 1)
            {
                nWind = 1 - nWind;
            }

            LoggingService.Trace(TraceComponent.Weather, "New weather settings: heat - " + IntToString(nHeat) +
                                 ", humidity - " + IntToString(nHumidity) +
                                 ", wind - " + IntToString(nWind));

            _SetHeatIndex(nHeat);
            _SetHumidity(nHumidity);
            _SetWindStrength(nWind);

            //--------------------------------------------------------------------------
            // Work out when to next change the weather.
            //--------------------------------------------------------------------------
            int nNextChange = GetTimeHour() + (11 - nWind);

            if (nNextChange > 23)
            {
                nNextChange -= 24;
            }
            LoggingService.Trace(TraceComponent.Weather, "Change the weather next at hour " + IntToString(nNextChange));
            oMod.SetLocalInt(VAR_WEATHER_CHANGE, nNextChange);

            // Update all occupied areas with the new settings.
            NWObject oPC = GetFirstPC();

            while (GetIsObjectValid(oPC) == true)
            {
                SetWeather(GetArea(oPC));
                oPC = GetNextPC();
            }

            return(true);
        }
Exemplo n.º 3
0
        public static void SetWeather(NWObject oArea)
        {
            if (oArea.GetLocalInt(VAR_INITIALIZED) == 0)
            {
                if (GetIsAreaInterior(oArea) == true ||
                    GetIsAreaAboveGround(oArea) == false)
                {
                    return;
                }
                oArea.SetLocalInt(VAR_SKYBOX, (int)GetSkyBox(oArea));
                oArea.SetLocalInt(VAR_FOG_SUN, GetFogAmount(FogType.Sun, oArea));
                oArea.SetLocalInt(VAR_FOG_MOON, GetFogAmount(FogType.Moon, oArea));
                oArea.SetLocalInt(VAR_FOG_C_SUN, (int)GetFogColor(FogType.Sun, oArea));
                oArea.SetLocalInt(VAR_FOG_C_MOON, (int)GetFogColor(FogType.Moon, oArea));
                oArea.SetLocalInt(VAR_INITIALIZED, 1);
            }

            int  nHeat      = GetHeatIndex(oArea);
            int  nHumidity  = GetHumidity(oArea);
            int  nWind      = GetWindStrength(oArea);
            bool bStormy    = GetSkyBox(oArea) == Skybox.GrassStorm;
            bool bDustStorm = (oArea.GetLocalInt("DUST_STORM") == 1);
            bool bSandStorm = (oArea.GetLocalInt("SAND_STORM") == 1);
            bool bSnowStorm = (oArea.GetLocalInt("SNOW_STORM") == 1);

            //--------------------------------------------------------------------------
            // Process weather rules for this area.
            //--------------------------------------------------------------------------
            if (nHumidity > 7 && nHeat > 3)
            {
                if (nHeat < 6 && nWind < 3)
                {
                    _.SetWeather(oArea, WeatherType.Clear);
                }
                else
                {
                    _.SetWeather(oArea, WeatherType.Rain);
                }
            }
            else if (nHumidity > 7)
            {
                _.SetWeather(oArea, WeatherType.Snow);
            }
            else
            {
                _.SetWeather(oArea, WeatherType.Clear);
            }

            //--------------------------------------------------------------------------
            // Stormy if heat is greater than 4 only; if already stormy then 2 in 3
            // chance of storm clearing, otherwise x in 20 chance of storm starting,
            // where x is the wind level.
            //--------------------------------------------------------------------------
            if (nHeat > 4 && nHumidity > 7 &&
                ((bStormy && d20() - nWind < 1) || (bStormy && d3() == 1)))
            {
                LoggingService.Trace(TraceComponent.Weather, "A thunderstorm is now raging in " + GetName(oArea));
                SetSkyBox(Skybox.GrassStorm, oArea);
                Thunderstorm(oArea);
                oArea.SetLocalInt("GS_AM_SKY_OVERRIDE", 1);
                bStormy = true;
            }
            else
            {
                SetSkyBox((Skybox)oArea.GetLocalInt(VAR_SKYBOX), oArea);
                oArea.DeleteLocalInt("GS_AM_SKY_OVERRIDE");
                bStormy = false;
            }

            // Does this area suffer from dust or sand storms?
            if (!bStormy && nWind >= 9 && d3() == 1)
            {
                // Dust storm - low visibility but no damage.
                if (_GetClimate(oArea).Sand_Storm)
                {
                    SetFogColor(FogType.Sun, FogColor.OrangeDark, oArea);
                    SetFogColor(FogType.Moon, FogColor.OrangeDark, oArea);
                    SetFogAmount(FogType.Sun, 80, oArea);
                    SetFogAmount(FogType.Moon, 80, oArea);

                    oArea.SetLocalInt("SAND_STORM", 1);
                    bSandStorm = true;
                }
                else if (_GetClimate(oArea).Snow_Storm)
                {
                    SetFogColor(FogType.Sun, FogColor.White, oArea);
                    SetFogColor(FogType.Moon, FogColor.White, oArea);
                    SetFogAmount(FogType.Sun, 80, oArea);
                    SetFogAmount(FogType.Moon, 80, oArea);

                    oArea.SetLocalInt("SNOW_STORM", 1);
                    bSnowStorm = true;
                }
            }
            else if (bDustStorm || bSandStorm || bSnowStorm)
            {
                // End the storm.
                oArea.DeleteLocalInt("DUST_STORM");
                oArea.DeleteLocalInt("SAND_STORM");
                oArea.DeleteLocalInt("SNOW_STORM");

                SetFogColor(FogType.Sun, (FogColor)oArea.GetLocalInt(VAR_FOG_C_SUN), oArea);
                SetFogColor(FogType.Moon, (FogColor)oArea.GetLocalInt(VAR_FOG_C_MOON), oArea);
                SetFogAmount(FogType.Sun, oArea.GetLocalInt(VAR_FOG_SUN), oArea);
                SetFogAmount(FogType.Moon, oArea.GetLocalInt(VAR_FOG_MOON), oArea);
                bSandStorm = false;
                bDustStorm = false;
                bSnowStorm = false;
            }

            LoggingService.Trace(TraceComponent.Weather, "Area weather settings for area: " + GetName(oArea) +
                                 ", heat - " + IntToString(nHeat) +
                                 ", humidity - " + IntToString(nHumidity) +
                                 ", wind - " + IntToString(nWind) +
                                 ", thunderstorm - " + bStormy.ToString() +
                                 ", sand storm - " + bSandStorm.ToString() +
                                 ", snow storm - " + bSnowStorm.ToString() +
                                 ", dust storm - " + bDustStorm.ToString());
        }
Exemplo n.º 4
0
        private static PlanetaryClimate _GetClimate(NWObject oArea)
        {
            PlanetaryClimate climate = new PlanetaryClimate();

            //--------------------------------------------------------------------------
            // This line depends on the naming scheme PlanetName - AreaName.  Change it
            // if the area naming scheme changes!
            //--------------------------------------------------------------------------
            int index = GetName(oArea).IndexOf("-");

            if (index <= 0)
            {
                return(climate);
            }
            string planetName = GetName(oArea).Substring(0, index - 1);

            if (planetName == "Viscara")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Viscara.");
                climate.Heat_Modifier     = -2;
                climate.Humidity_Modifier = +2;
            }
            else if (planetName == "Tatooine")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Tatooine.");
                climate.Heat_Modifier     = +5;
                climate.Humidity_Modifier = -8;

                climate.Sand_Storm = true;

                climate.special_cloudy      = "A dusty wind sweeps through the desert; sparse clouds speed overhead.";
                climate.special_mild        = "The sun shines brilliantly, but not oppressively, over the desert; the sky is clear.";
                climate.special_mild_night  = "A clear night sky casts the desert in pale hues.";
                climate.special_warm_cloudy = "The shade of an overcast sky provides only minor relief to the sweltering temperatures.";
                climate.special_scorching   = "The desert is baked with pervasive, inescapable heat; a haze blurs the horizon.";
                climate.special_warm_windy  = "The hot wind wears at your face like a sandblaster.  A sand storm seems likely.";
                climate.special_windy       = "A scouring wind sweeps across the desert, a sand storm cannot be far away.";
            }
            else if (planetName == "Mon Cala")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Mon Cala.");
                climate.Humidity_Modifier = 0;
                climate.Wind_Modifier     = +1;
                climate.Heat_Modifier     = +1;

                climate.special_cloudy      = "Clouds build over the ocean, and the wind starts to pick up.  A storm could be brewing.";
                climate.special_cold_cloudy = "Thick clouds fill the sky, and a keen wind blows in off the ocean, exciting the waves.";
                climate.special_cold_mild   = "It is cool, but calm.  The ocean is calm and beautiful.";
                climate.special_freezing    = "A wave of cold air rolls in, stinging exposed flesh.";
                climate.special_mild        = "The sea is calm, a faint breeze rippling through the trees.";
                climate.special_mild_night  = "The sea is calm, and the sky towards the Galactic Core is full of stars.  In other directions, you see only a deep, unending black.";
                climate.special_mist        = "A mist has blown in off the sea, moisture hanging heavy in the air.";
                climate.special_warm_cloudy = "The sea is choppy and the wind has picked up. An array of clouds marshals on the horizon, ready to sweep over you.";
                climate.special_warm_mild   = "It is a beautiful day, warm and calm, though quite humid.";
                climate.special_rain_normal = "The ocean, affronted by the existence of patches of non-ocean on the surface of the planet, is attempting to reclaim the land by air drop.  In other words, it's raining.";
                climate.special_rain_warm   = "A heavy rain shower is passing over, but is doing little to dispel the humidity in the air.";
                climate.special_snow        = "It's snowing!  The local flora seems most surprised at this turn of events.";
                climate.special_storm       = "A storm rips in off the sea, filling the sky with dramatic flashes.";
                climate.special_scorching   = "The sun bakes the sand, making it extremely uncomfortable to those without insulated boots.";
                climate.special_cold_windy  = "A chill wind sweeps over the isles, the moisture in the air cutting to the bone.";
                climate.special_warm_windy  = "The wind is picking up, a warm front rolling over.  There could be a storm soon.";
                climate.special_windy       = "A strong wind sweeps in.  The sea is choppy, waves crashing onto the beach.";
            }
            else if (planetName == "Hutlar")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Hutlar.");
                climate.Heat_Modifier     = -5;
                climate.Humidity_Modifier = -8;

                climate.Snow_Storm = true;

                climate.special_freezing    = "A wave of cold air rolls in, stinging exposed flesh.";
                climate.special_snow        = "It's snowing... again...";
                climate.special_windy       = "A cold wind sweeps in.";
                climate.special_cold_windy  = "A freezing wind stings exposed flesh";
                climate.special_cloudy      = "Clouds build over head, and there is a occasional strong gust of wind.";
                climate.special_cold_cloudy = "The clouds over head build, a cold wind stings exposed flesh. Looks like it is going to snow.";
                climate.special_cold_mild   = "It is cold, the sky is clear, and there is a gentle breeze.";
            }

            return(climate);
        }