Exemplo n.º 1
0
        // Distributes humidity using perlin noise
        private void GeneratePerlinHumidity(Configuration file, TerrainToComposition attackComposition, TerrainToComposition defendComposition, double[] weighValue, int gridWidth, int gridHeight)
        {
            int    structureSize           = file.GetProperty <int>("structureSize");
            double structureSizeApplicable = structureSize / 100.0;

            double[,] humidityMap = GeneratePerlinGrid(gridWidth, gridHeight, structureSizeApplicable);
            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    Tile   currentTile    = this[x, y] as Tile;
                    double humidity       = humidityMap[x, y];
                    double defenseValue   = weighValue[y];
                    double attackValue    = 1 - defenseValue;
                    double humidChance    = defenseValue * defendComposition.humidChance + attackValue * attackComposition.humidChance;
                    double humidThreshold = ChanceToThreshold(true, humidChance);

                    if (humidity > humidThreshold)
                    {
                        if (currentTile.Terrain == Terrain.Plains)
                        {
                            currentTile.Terrain = Terrain.Forest;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Distributes temperature using perlin noise
        private void GeneratePerlinTemperature(Configuration file, TerrainToComposition attackComposition, TerrainToComposition defendComposition, double[] weighValue, int gridWidth, int gridHeight)
        {
            int    structureSize           = file.GetProperty <int>("structureSize");
            double structureSizeApplicable = structureSize / 100.0;

            double[,] temperatureMap = GeneratePerlinGrid(gridWidth, gridHeight, structureSizeApplicable);
            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    Tile   currentTile  = this[x, y] as Tile;
                    double temperature  = temperatureMap[x, y];
                    double defenseValue = weighValue[y];
                    double attackValue  = 1 - defenseValue;
                    double hotChance    = defenseValue * defendComposition.hotChance + attackValue * attackComposition.hotChance;
                    double hotThreshold = ChanceToThreshold(true, hotChance);

                    double coldChance    = defenseValue * defendComposition.coldChance + attackValue * attackComposition.coldChance;
                    double coldThreshold = ChanceToThreshold(false, coldChance);

                    if (temperature > hotThreshold)
                    {
                        if (currentTile.Terrain == Terrain.Plains)
                        {
                            currentTile.Terrain = Terrain.Desert;
                        }
                        else if (currentTile.Terrain == Terrain.Forest)
                        {
                            currentTile.Terrain = Terrain.Jungle;
                        }
                        else if (currentTile.Terrain == Terrain.Mountain)
                        {
                            currentTile.Terrain = Terrain.DesertMountain;
                        }
                    }
                    else if (temperature < coldThreshold)
                    {
                        if (currentTile.Terrain == Terrain.Plains)
                        {
                            currentTile.Terrain = Terrain.Tundra;
                        }
                        else if (currentTile.Terrain == Terrain.Forest)
                        {
                            currentTile.Terrain = Terrain.Swamp;
                        }
                        else if (currentTile.Terrain == Terrain.Mountain)
                        {
                            currentTile.Terrain = Terrain.TundraMountain;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        // Generates a battlemap: a transition between two economygrid tiles
        public void BattleGenerate(Terrain attackTerrain, bool attackHills, Terrain defendTerrain, bool defendHills, int gridWidth, int gridHeight, Player attackingPlayer, Player defendingPlayer)
        {
            this.attackingPlayer = attackingPlayer;
            this.defendingPlayer = defendingPlayer;
            defenseBonusTerrain  = defendTerrain;
            attackBonusTerrain   = attackTerrain;
            Configuration        file = FileManager.LoadConfig("TerrainGeneration");
            TerrainToComposition attackComposition = GetTerrainSpecsFromFile(attackTerrain, attackHills);
            TerrainToComposition defendComposition = GetTerrainSpecsFromFile(defendTerrain, defendHills);

            GenerateEnvironmentalValues(file, attackComposition, defendComposition, gridWidth, gridHeight);
        }
Exemplo n.º 4
0
        // Distributes height using perlin noise
        private bool GeneratePerlingridHeights(Configuration file, TerrainToComposition attackComposition, TerrainToComposition defendComposition, double[] weighValue, int gridWidth, int gridHeight)
        {
            int    structureSize           = file.GetProperty <int>("structureSize");
            double structureSizeApplicable = structureSize / 100.0; // Determines randomness for PerlinGrid

            double[,] heightMap = GeneratePerlinGrid(gridWidth, gridHeight, structureSizeApplicable);
            for (int x = 0; x < gridWidth; x++)
            {
                for (int y = 0; y < gridHeight; y++)
                {
                    Tile   currentTile       = this[x, y] as Tile;
                    double height            = heightMap[x, y];
                    double defenseValue      = weighValue[y];
                    double attackValue       = 1 - defenseValue;
                    double mountainChance    = defenseValue * defendComposition.mountainchance + attackValue * attackComposition.mountainchance;
                    double mountainThreshold = ChanceToThreshold(true, mountainChance);

                    double hillsChance    = defenseValue * defendComposition.hillschance + attackValue * attackComposition.hillschance;
                    double hillsThreshold = ChanceToThreshold(true, hillsChance);

                    double lakeChance    = defenseValue * defendComposition.lakechance + attackValue * attackComposition.lakechance;
                    double lakeThreshold = ChanceToThreshold(false, lakeChance);

                    if (height > mountainThreshold)
                    {
                        currentTile.Terrain = Terrain.Mountain;
                        currentTile.hills   = false;
                    }
                    else if (height > hillsThreshold)
                    {
                        currentTile.Terrain = Terrain.Plains;
                        currentTile.hills   = true;
                    }
                    else if (height < lakeThreshold)
                    {
                        currentTile.Terrain = Terrain.Lake;
                        currentTile.hills   = false;
                    }
                    else
                    {
                        currentTile.Terrain = Terrain.Plains;
                        currentTile.hills   = false;
                    }
                }
            }
            return(CheckIfEveryTileIsAccessible(file, gridWidth, gridHeight));
        }
Exemplo n.º 5
0
        // Generates terain using 3 layers of values: height, humidity, and temperature
        private void GenerateEnvironmentalValues(Configuration file, TerrainToComposition attackComposition, TerrainToComposition defendComposition, int gridWidth, int gridHeight)
        {
            double[] weighValue          = new double[gridHeight];
            int      defendingpercentage = file.GetProperty <int>("PercentageDefendingTile");
            int      defendingRows       = (int)((defendingpercentage / 100.0) * gridHeight);

            for (int i = 0; i < defendingRows; i++)
            {
                weighValue[i] = 1.0; // The upper rows are determined only by the defending tile.
            }
            for (int i = defendingRows; i < gridHeight; i++)
            {
                weighValue[i] = 1 - ((i - defendingRows) / (double)(gridHeight - 1 - defendingRows)); // Generates a weighvalue for all transitionrows
            }
            bool validHeightMap = false;

            while (!validHeightMap)
            {
                validHeightMap = GeneratePerlingridHeights(file, attackComposition, defendComposition, weighValue, gridWidth, gridHeight); // If not evertything is accessible, generates new heightmap
            }
            GeneratePerlinHumidity(file, attackComposition, defendComposition, weighValue, gridWidth, gridHeight);
            GeneratePerlinTemperature(file, attackComposition, defendComposition, weighValue, gridWidth, gridHeight);
        }