Esempio n. 1
0
        /// <summary>Super brute-force road tile sequencer.</summary>
        private static TileType GetTerrainType(TerrainGenerator terrainGenerator, int x, int y)
        {
            WorldTile nTile = terrainGenerator.GetTile(x, y + 1);
            WorldTile eTile = terrainGenerator.GetTile(x + 1, y);
            WorldTile wTile = terrainGenerator.GetTile(x - 1, y);
            WorldTile sTile = terrainGenerator.GetTile(x, y - 1);

            if (terrainGenerator.Tiles[x, y].IsOpen())
            {
                // this tile is a road. what is adjacent?
                if (nTile?.IsOpen() == true)
                {
                    if (eTile?.IsOpen() == true)
                    {
                        if (wTile?.IsOpen() == true)
                        {
                            if (sTile?.IsOpen() == true)
                            {
                                return(TileType.DirtRoad_NEWS);
                            }
                            else
                            {
                                return(TileType.DirtRoad_NEW);
                            }
                        }
                        else if (sTile?.IsOpen() == true)
                        {
                            return(TileType.DirtRoad_NES);
                        }
                        else
                        {
                            return(TileType.DirtRoad_NE);
                        }
                    }
                    else if (wTile?.IsOpen() == true)
                    {
                        if (sTile?.IsOpen() == true)
                        {
                            return(TileType.DirtRoad_NSW);
                        }
                        else
                        {
                            return(TileType.DirtRoad_NW);
                        }
                    }
                    else if (sTile?.IsOpen() == true)
                    {
                        return(TileType.DirtRoad_NS);
                    }
                    else
                    {
                        return(TileType.HalfGrass_SN);
                    }
                }
                else if (eTile?.IsOpen() == true)
                {
                    if (wTile?.IsOpen() == true)
                    {
                        if (sTile?.IsOpen() == true)
                        {
                            return(TileType.DirtRoad_ESW);
                        }
                        else
                        {
                            return(TileType.DirtRoad_EW);
                        }
                    }
                    else if (sTile?.IsOpen() == true)
                    {
                        return(TileType.DirtRoad_ES);
                    }
                    else
                    {
                        return(TileType.HalfGrass_WE);
                    }
                }
                else if (wTile?.IsOpen() == true)
                {
                    if (sTile?.IsOpen() == true)
                    {
                        return(TileType.DirtRoad_SW);
                    }
                    else
                    {
                        return(TileType.HalfGrass_EW);
                    }
                }
                else if (sTile?.IsOpen() == true)
                {
                    return(TileType.HalfGrass_NS);
                }
            }

            // this is not a road tile
            return(UnityEngine.Random.value > 0.5f ? TileType.Grass : TileType.Grass2);
        }