Пример #1
0
 public GameInfo(int worldSize = k_WorldSize, int artifacts = k_ArtifactsTotal)
 {
     ArtifactsTotal = artifacts;
     World          = new World(this, worldSize);
 }
Пример #2
0
        public static Cell[,] generateCells(World world)
        {
            //Get a heightmap with a certain ratio of water-terrain, and throw away maps with ocean in middle
            var heightMap = getHeightMapWithAverage(world.Size, world.Size, (map) => {
                var fl32AvgHeight = getAverage(map, (world.Size / 2) - 4
                                                  , (world.Size / 2) - 4, 8, 8);
                //Console.Write("\t Center 8x8 avg height: " + fl32AvgHeight + "\n");
                if (fl32AvgHeight < 0.5) // Center 8x8 must have avg height >= 0.5
                    return false;

                var avg = getAverage(map, 0, 0, world.Size, world.Size);
                //Console.Write("\t Avg height: " + avg + "\n");
                if (Math.Abs(0.45f - avg) > 0.03f) // 42% to 48% avg height
                    return false;

                return true;
            });

            float[,] rsrcMap = PerlinNoiseGenerator.generatePerlinNoise(world.Size, world.Size, 2);
            Cell [,] cells   = new Cell[world.Size,world.Size];

            //Generate world
            for (int y = 0; y < world.Size; y++)
            {
                for (int x = 0; x < world.Size; x++)
                {
                    CellType type = CellType.Ocean; //< Ocean as default.
                    if (heightMap[x, y] > 0.9)
                    {
                        type = CellType.Plains;
                    }
                    else if (heightMap[x, y] > 0.45)
                    {
                        //use resource map to choose type; more forest at higher altitude
                        if (rsrcMap[x, y] > (heightMap[x, y] > 0.8 ? 0.5 : 0.8))
                        {
                            type = CellType.Forest;
                        }
                        else
                        {
                            type = CellType.Plains;
                        }
                    }
                    else if (heightMap[x, y] > 0.4)
                    {
                        type = CellType.Coast;
                    }

                    cells[x, y] = new Cell(world, type, new Vector2(x, y));
                }
            }

            //Pick a tile for the start area
            int startX = -1, startY = -1;
            for (int y = (world.Size / 2) - 3; y < (world.Size / 2) + 3; y++)
            {
                for (int x = (world.Size / 2) - 3; x < (world.Size / 2) + 3; x++)
                {
                    //Pick highest val tile in rsrcMap within 6x6 area at center of map
                    if (startX == -1 || rsrcMap[x, y] > rsrcMap[startX, startY])
                    {
                        startX = x;
                        startY = y;
                    }
                }
            }
            cells[startX, startY] = new Cell(world, CellType.Start, new Vector2(startX, startY));

            //Place artifacts around center
            int numArtifacts = 0;
            float lastPlacement = 0.2f;
            for (int y = (world.Size / 2) - 10; y < (world.Size / 2) + 10; y++)
            {
                for (int x = (world.Size / 2) - 10; x < (world.Size / 2) + 10; x++)
                {
                    if (x != startX && y != startY && heightMap[x,y] > 0.45 && Math.Abs(rsrcMap[x, y] - lastPlacement) > 0.7)
                    {
                        cells[x, y] = new Cell(world, CellType.Artifact, new Vector2(x, y));
                        lastPlacement = rsrcMap[x, y];
                        numArtifacts++;
                        if (numArtifacts == world.Game.ArtifactsTotal)
                        {
                            return cells;
                        }
                    }
                }
            }
            Console.Write("Could not place all artifacts, regenerating...");
            return generateCells(world);
        }
Пример #3
0
 public FogOfWar(World world)
 {
     World = world;
 }