示例#1
0
 private static void EnforceSavanna(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
     if (gameTime.Season == SeasonTypes.Winter &&
         cell.Hemisphere == HemisphereTypes.North &&
         cell.Humidity > 0)
     {
         delta.ChangeHumidity(-5);
     }
     else if (cell.Temperature < 60)
     {
         delta.ChangePrecip(2);
     }
     else if (gameTime.Season == SeasonTypes.Summer &&
              cell.Hemisphere == HemisphereTypes.North &&
              cell.Humidity < 50)
     {
         delta.ChangeHumidity(5);
     }
     else if (gameTime.Season == SeasonTypes.Summer &&
              cell.Hemisphere == HemisphereTypes.South &&
              cell.Humidity > 0)
     {
         delta.ChangeHumidity(-5);
     }
     else if (gameTime.Season == SeasonTypes.Winter &&
              cell.Hemisphere == HemisphereTypes.South &&
              cell.Humidity < 50)
     {
         delta.ChangeHumidity(5);
     }
 }
示例#2
0
        public void RandomizeCells(TimeInfoData gameTime)
        {
            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    var cell = GetCellFromMap(x, y);

                    var rangeData = WeatherConstants.WeatherData.FirstOrDefault(d => d.Hemisphere == cell.Hemisphere &&
                                                                                d.Season == gameTime.Season &&
                                                                                d.Climate == cell.Climate);
                    if (rangeData == null)
                    {
                        // TODO Error
                        continue;
                    }

                    cell.ChangeTemperature(SmaugRandom.Between(rangeData.Temperature.ToList()[0], rangeData.Temperature.ToList()[1]));
                    cell.ChangePressure(SmaugRandom.Between(rangeData.Pressure.ToList()[0], rangeData.Pressure.ToList()[1]));
                    cell.ChangeCloudCover(SmaugRandom.Between(rangeData.CloudCover.ToList()[0], rangeData.CloudCover.ToList()[1]));
                    cell.ChangeHumidity(SmaugRandom.Between(rangeData.Humidity.ToList()[0], rangeData.Humidity.ToList()[1]));
                    cell.ChangePrecip(SmaugRandom.Between(rangeData.Precipitation.ToList()[0], rangeData.Precipitation.ToList()[1]));
                    cell.ChangeEnergy(SmaugRandom.Between(rangeData.Energy.ToList()[0], rangeData.Energy.ToList()[1]));
                    cell.ChangeWindSpeedX(SmaugRandom.Between(rangeData.WindSpeedX.ToList()[0], rangeData.WindSpeedX.ToList()[1]));
                    cell.ChangeWindSpeedY(SmaugRandom.Between(rangeData.WindSpeedY.ToList()[0], rangeData.WindSpeedY.ToList()[1]));
                }
            }
        }
示例#3
0
        public void Initialize(TimeInfoData timeInfo, int height, int width)
        {
            try
            {
                if (!_dbContext.Weather.Any())
                {
                    return;
                }

                var cells = _dbContext.Weather.Select(cell => new WeatherCell(cell.Id)
                {
                    XCoord        = cell.CellXCoordinate,
                    YCoord        = cell.CellYCoordinate,
                    Climate       = cell.ClimateType,
                    Hemisphere    = cell.HemisphereType,
                    CloudCover    = cell.CloudCover,
                    Energy        = cell.Energy,
                    Humidity      = cell.Humidity,
                    Precipitation = cell.Precipitation,
                    Pressure      = cell.Pressure,
                    Temperature   = cell.Temperature,
                    WindSpeedX    = cell.WindSpeedX,
                    WindSpeedY    = cell.WindSpeedY
                }).ToList();

                Weather = new WeatherMap(timeInfo, width, height, cells);
                _logManager.Boot("Loaded {0} Weather Cells", cells.Count);
            }
            catch (DbException ex)
            {
                _logManager.Error(ex);
                throw;
            }
        }
示例#4
0
 public void SetGameTime(TimeInfoData gameTime)
 {
     if (GameTime == null)
     {
         GameTime = gameTime;
     }
 }
示例#5
0
 public WeatherMap(TimeInfoData gameTime, int width, int height, IEnumerable <WeatherCell> cells)
     : this(gameTime, width, height)
 {
     foreach (var cell in cells)
     {
         _map[cell.XCoord][cell.YCoord] = cell;
     }
 }
示例#6
0
 private static void EnforceRainforest(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
     if (cell.Temperature < 80)
     {
         delta.ChangeTemperature(3);
     }
     else if (cell.Temperature < 50)
     {
         delta.ChangeHumidity(2);
     }
 }
示例#7
0
        public void Update(TimeInfoData gameTime, bool save = false)
        {
            ClearWeatherDeltas();
            CalculateCellToCellChanges(gameTime);
            EnforceClimateConditions();
            ApplyDeltaChanges();

            if (save)
            {
                Save();
            }
        }
示例#8
0
 private static void AdjustTemperatureForDayNight(TimeInfoData gameTime, WeatherCell delta, WeatherCell cell)
 {
     if (gameTime.Sunlight == SunPositionTypes.Sunrise ||
         gameTime.Sunlight == SunPositionTypes.Light)
     {
         delta.ChangeTemperature(SmaugRandom.Between(-1, 2) + (cell.CloudCover / 10 > 5 ? -1 : 1));
     }
     else
     {
         delta.ChangeTemperature(SmaugRandom.Between(-2, 0) + (cell.CloudCover / 10 > 5 ? 2 : -3));
     }
 }
示例#9
0
        public void CalculateCellToCellChanges(TimeInfoData gameTime)
        {
            PickAndUpdateRandomCell();

            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    var cell  = GetCellFromMap(x, y);
                    var delta = GetCellFromDelta(x, y);

                    AdjustTemperatureForDayNight(gameTime, delta, cell);
                    AdjustHumidityForPrecipitation(cell, delta);
                    AdjustPrecipitationForHumidityAndPressure(cell);
                    AdjustCloudCoverForHumitityAndPrecipitation(cell, delta);

                    var totalPressure    = cell.Pressure;
                    var numPressureCells = -1;

                    for (var dy = -1; dy <= 1; ++dy)
                    {
                        for (var dx = -1; dx <= 1; ++dx)
                        {
                            var nx = x + dx;
                            var ny = y + dy;

                            if (dx == 0 && dy == 0)
                            {
                                continue;
                            }

                            if (nx < 0 || nx >= Width || ny < 0 || ny >= Height)
                            {
                                continue;
                            }

                            var neighborCell  = GetCellFromMap(nx, ny);
                            var neighborDelta = GetCellFromDelta(nx, ny);

                            totalPressure = AdjustWindSpeedsBasedOnPressure(cell, neighborCell, dx, delta, dy,
                                                                            totalPressure);
                            ++numPressureCells;

                            AdjustTemperatureAndHumidityWhenWindy(cell, neighborCell, dx, dy, neighborDelta, delta);
                        }
                    }

                    ChangePressure(delta, totalPressure, numPressureCells, cell);
                }
            }
        }
示例#10
0
        public void CalculateSeason(TimeInfoData gameTime)
        {
            var day         = gameTime.Month * GameConstants.GetSystemValue <int>("DaysPerMonth") + gameTime.Day;
            var daysPerYear = GameConstants.GetSystemValue <int>("DaysPerYear");

            if (day < daysPerYear / 4)
            {
                gameTime.Season = SeasonTypes.Spring;
                if (gameTime.Hour == 0 && day == 0)
                {
                    StartSpringSeason();
                }
            }
            else if (day < daysPerYear / 4 * 2)
            {
                gameTime.Season = SeasonTypes.Summer;
                if (gameTime.Hour == 0 && day == daysPerYear / 4)
                {
                    StartSummerSeason();
                }
            }
            else if (day < daysPerYear / 4 * 3)
            {
                gameTime.Season = SeasonTypes.Fall;
                if (gameTime.Hour == 0 && day == daysPerYear / 4 * 2)
                {
                    StartFallSeason();
                }
            }
            else if (day < daysPerYear)
            {
                gameTime.Season = SeasonTypes.Winter;
                if (gameTime.Hour == 0 && day == daysPerYear / 4 * 3)
                {
                    StartWinterSeason();
                }
            }
            else
            {
                gameTime.Season = SeasonTypes.Spring;
            }

            UpdateSeason(gameTime);
        }
示例#11
0
        private void UpdateGameTime(TimeInfoData timeInfo)
        {
            _gameManager.SetGameTime(timeInfo);

            _logManager.Boot("Resetting mud time based on current system time.");
            var lhour = (DateTime.Now.ToFileTimeUtc() - 650336715) /
                        (GameConstants.GetSystemValue <int>("PulseTick") / GameConstants.GetSystemValue <int>("PulsesPerSecond"));

            _gameManager.GameTime.Hour = (int)(lhour % GameConstants.GetSystemValue <int>("HoursPerDay"));

            var lday = lhour / GameConstants.GetSystemValue <int>("HoursPerDay");

            _gameManager.GameTime.Day = (int)(lday % GameConstants.GetSystemValue <int>("DaysPerMonth"));

            var lmonth = lday / GameConstants.GetSystemValue <int>("DaysPerMonth");

            _gameManager.GameTime.Month = (int)(lmonth % GameConstants.GetSystemValue <int>("MonthsPerYear"));

            _gameManager.GameTime.Year = (int)(lmonth % GameConstants.GetSystemValue <int>("MonthsPerYear"));
        }
示例#12
0
        private static void UpdateSeason(TimeInfoData gameTime)
        {
            var day = db.GetHoliday(gameTime.Month, gameTime.Day);

            if (gameTime.Day + 1 == day?.Day && gameTime.Hour == 0)
            {
                act_wiz.echo_to_all(ATTypes.AT_IMMORT, day.Announce, (int)EchoTypes.All);
            }

            if (gameTime.Season == SeasonTypes.Winter && !_winterFreeze)
            {
                _winterFreeze = true;
                foreach (var room in RepositoryManager.Instance.ROOMS.CastAs <Repository <long, RoomTemplate> >().Values
                         .Where(x => x.SectorType == SectorTypes.DeepWater ||
                                x.SectorType == SectorTypes.ShallowWater))
                {
                    room.WinterSector = room.SectorType;
                    room.SectorType   = SectorTypes.Ice;
                }
            }
        }
示例#13
0
        public WeatherMap(TimeInfoData gameTime, int width, int height)
        {
            _gameTime = gameTime;
            Width     = width;
            Height    = height;

            _map = new WeatherCell[width][];
            for (var i = 0; i < width; i++)
            {
                _map[i] = new WeatherCell[height];
            }

            _delta = new WeatherCell[width][];
            for (var i = 0; i < width; i++)
            {
                _delta[i] = new WeatherCell[height];
            }

            StarMap = new List <string>();
            SunMap  = new List <string>();
            MoonMap = new List <string>();
        }
示例#14
0
 private static void EnforceDesert(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
     if ((gameTime.Sunlight == SunPositionTypes.Sunset ||
          gameTime.Sunlight == SunPositionTypes.Dark) &&
         cell.Temperature > 30)
     {
         delta.ChangeTemperature(-5);
     }
     else if ((gameTime.Sunlight == SunPositionTypes.Sunrise ||
               gameTime.Sunlight == SunPositionTypes.Light) &&
              cell.Temperature < 64)
     {
         delta.ChangeTemperature(2);
     }
     else if (cell.Humidity > 10)
     {
         delta.ChangeHumidity(-2);
     }
     else if (cell.Pressure < 50)
     {
         delta.ChangePressure(2);
     }
 }
示例#15
0
        public TimeInfoData LoadTimeInfo()
        {
            using (var proxy = new TextReaderProxy(new StreamReader(Filename)))
            {
                var timeInfo = new TimeInfoData();

                IEnumerable <string> lines = proxy.ReadIntoList();
                foreach (var line in lines.Where(x => !x.StartsWith("*")))
                {
                    if (line.StartsWithIgnoreCase("#time"))
                    {
                        timeInfo.Load(lines);
                        break;
                    }
                    if (line.EqualsIgnoreCase("end"))
                    {
                        break;
                    }
                }

                return(timeInfo);
            }
        }
示例#16
0
        public void Initialize()
        {
            _systemData = _gameManager.SystemData;
            _logManager.Boot("Setting time and weather.");

            try
            {
                TimeInfoData timeInfo;

                var gameState = _dbContext.GameStates.FirstOrDefault();
                if (gameState == null)
                {
                    timeInfo = new TimeInfoData {
                        Day = 28, Hour = 0, Month = 6, Year = 628
                    }
                }
                ;
                else
                {
                    timeInfo = new TimeInfoData
                    {
                        Year  = gameState.GameYear,
                        Month = gameState.GameMonth,
                        Day   = gameState.GameDay,
                        Hour  = gameState.GameHour
                    };
                }

                UpdateGameTime(timeInfo);
                GameTime = timeInfo;
            }
            catch (Exception ex)
            {
                _logManager.Error(ex);
            }
        }
示例#17
0
 private static void EnforceGrasslands(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
 }
示例#18
0
 private static void EnforceChapparal(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
 }
示例#19
0
 private static void EnforceDeciduous(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
 }
示例#20
0
 private static void EnforceArctic(TimeInfoData gameTime, WeatherCell cell, WeatherCell delta)
 {
 }