public void GenerateTerrainAfterErosion()
 {
     // this can be parallelized
     TerrainInfo._Terrain.terrainData.SetHeights(0, 0, TerrainInfo.HeightMap);
     TerrainInfo.TemperatureMap = NoiseGeneration.GenerateTemperatureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap, TerrainInfo);
     TerrainInfo.MoistureMap    = NoiseGeneration.GenerateMoistureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap);
 }
Example #2
0
 void Update()
 {
     if (shakeTime > 0)
     {
         transform.position = Camera.main.transform.position + NoiseGeneration.Shake2D(amplitude, frequency, octaves, persistance, lacunarity, burstFrequency, burstContrast, Time.time);
         shakeTime         -= Time.deltaTime;
     }
 }
    public void GenerateMap(float x, float y)
    {
        float firstObjectX = x + tilesize / 2f;
        float firstObjectY = y + tilesize / 2f;

        float[,] noiseMap = NormalizeNoise(NoiseGeneration.generateNoiseMap(map_Height, map_Width, noiseScale, seed, octaves, persistance, lacunarity, offset), minIslandProximity, fiveFieldsNeighbours);
        Vector3    startingPoint = new Vector3(firstObjectX, firstObjectY, 0);
        GameObject temp          = null;

        for (int i = 0; i < map_Width; i++)
        {
            for (int j = 0; j < map_Height; j++)
            {
                temp = null;
                if (noiseMap[i, j] >= islandMarker)
                {
                    temp = Instantiate(islandType1);


                    temp.transform.position = new Vector3(startingPoint.x + tilesize * i, startingPoint.y - tilesize * j, 0);
                    //ameObject island = Instantiate(meduza);
                    // meduza.transform.position = new Vector3(temp.transform.position.x, temp.transform.position.y, temp.transform.position.z-0.6f);
                    temp.GetComponent <Isle_Behaviour>().field  = new Isle(i, j, 10);
                    temp.GetComponent <Isle_Behaviour>().tevent = new TriggeredEvent("Na wyspie znajduje się pare rozbitków chetnych do dołączenia. Więzieni są jednak przez tubylców. Czy im pomożesz?", "Tak", "Nie", new Penalty(), new Prize());
                }
                else
                {
                    if (noiseMap[i, j] >= islandMarker * percent_factor)
                    {
                        temp = Instantiate(islandType2);
                        temp.transform.position = new Vector3(startingPoint.x + tilesize * i, startingPoint.y - tilesize * j, 0);
                        temp.GetComponent <Isle_Behaviour>().field = new Water(i, j, false);
                    }
                    else
                    {
                        if (noiseMap[i, j] < islandMarker * percent_factor)
                        {
                            temp = Instantiate(islandType3);
                            //, new Vector3(startingPoint.x + tilesize * i, startingPoint.y - tilesize * j, 0), Quaternion.identity
                            temp.transform.position = new Vector3(startingPoint.x + tilesize * i, startingPoint.y - tilesize * j, 0);
                            temp.GetComponent <Isle_Behaviour>().field = new Water(i, j, true);
                            if (noiseMap[i, j] < (islandMarker * percent_factor) / 4)
                            {
                                temp.transform.GetChild(1).gameObject.SetActive(true);
                                temp.GetComponent <Isle_Behaviour>().isPassable = false;
                            }
                        }
                    }
                }
                temp.transform.parent = map.transform;
                //temp.GetComponent<Isle_Behaviour>().field = new Water(i, j, true);
                map_array[i, j] = temp.GetComponent <Isle_Behaviour>();
            }
        }
    }
Example #4
0
 // A lot of stuff can be paralelized, stuff is decoupled for clarity when developing, in the end will be re-facced so shit that can get run paralel will
 public void GenerateTerrainOnDemand()
 {
     TerrainInfo.HeightMap = NoiseGeneration.GenerateTerrain(TerrainInfo);
     TerrainInfo._Terrain.terrainData.SetHeights(0, 0, TerrainInfo.HeightMap);
     TerrainInfo.TemperatureMap = NoiseGeneration.GenerateTemperatureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap);
     TerrainInfo.MoistureMap    = NoiseGeneration.GenerateMoistureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap);
     ApplyErosion();
     AssignSplatMap.DoSplat(TerrainInfo);
     TerrainInfo.BiomeMap = BiomeGeneration.GenerateBiomeMap(TerrainInfo);
     ContentManager.InitializeBiomePlacementObjects(TerrainInfo);
     ContentGenerator.GenerateBiomeContent(TerrainInfo);
 }
    MapData GenerateMapData(Vector2 centre, int Size)
    {
        float[,] noiseMap  = NoiseGeneration.GenerateNoiseMap(Size, Size, seed, noiseScale, sheets, persistance, lacunarity, centre + offset);
        float[,] islandMap = new float[Size, Size];
        float[,] fallMap   = FalloffGenerator.GenerateFalloff((halfIslandSize * 2) + 1, falloff_a, falloff_b);
        List <Vector2> islands = new List <Vector2>();
        List <float>   heights = new List <float>();

        Color[] colorMap = new Color[Size * Size];
        for (int y = 0; y < Size; y++)
        {
            for (int x = 0; x < Size; x++)
            {
                if (falloff)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]);
                }
                float currentHeight = noiseMap[x, y];
                if (currentHeight >= falloffHeight &&
                    checkIslandOverlap(islands, x, y))
                {
                    islands.Add(new Vector2(x, y));
                    heights.Add(currentHeight);
                }
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colorMap[y * Size + x] = regions[i].color;
                        break;
                    }
                }
            }
        }
        for (int i = 0; i < islands.Count; i++)
        {
            int x = (int)islands[i].x;
            int y = (int)islands[i].y;
            for (int o = -halfIslandSize; o < halfIslandSize; o++)
            {
                for (int p = -halfIslandSize; p < halfIslandSize; p++)
                {
                    if (y + o > 0 && y + o < Size && x + p > 0 && x + p < Size)
                    {
                        noiseMap[x + p, y + o]  = Mathf.Clamp01(noiseMap[x + p, y + o] - fallMap[p + halfIslandSize, o + halfIslandSize]);
                        islandMap[x + p, y + o] = noiseMap[x + p, y + o];
                    }
                }
            }
        }
        return(new global::MapData(islandMap, colorMap));
    }
Example #6
0
 public void CreateTerrain(int width, int length)
 {
     //find the mesh and noiseGeneration script
     mesh            = new Mesh();
     mesh            = FindObjectOfType <MeshFilter>().mesh;
     noiseGeneration = FindObjectOfType <NoiseGeneration>();
     //find the size
     xSize = width;
     zSize = length;
     //define the size of each array
     VertcieLocations = new Vector3[(xSize + 1) * (zSize + 1)];
     noiseMap         = noiseGeneration.Generate(xSize + 1, zSize + 1);
     //call functions secquentially
     GenerateVertArray(VertcieLocations);
     GenerateTriArray();
     AddColor();
     CreateMesh();
 }
 // A lot of stuff can be paralelized, stuff is decoupled for clarity when developing, in the end will be re-facced so shit that can get run paralel will
 public void GenerateTerrainOnDemand(bool onlyUseTerrainParameteters = false)
 {
     TerrainInfo.HeightMap = NoiseGeneration.GenerateTerrain(TerrainInfo);
     TerrainInfo._Terrain.terrainData.SetHeights(0, 0, TerrainInfo.HeightMap);
     if (TerrainInfo.GenerateTerrain)
     {
         TerrainInfo.TemperatureMap = NoiseGeneration.GenerateTemperatureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap, TerrainInfo);
         TerrainInfo.MoistureMap    = NoiseGeneration.GenerateMoistureMap(TerrainInfo.TerrainWidth, TerrainInfo.TerrainHeight, TerrainInfo.HeightMap);
     }
     if (!onlyUseTerrainParameteters)
     {
         ApplyErosion();
         TerrainInfo.BiomeMap = BiomeGeneration.GenerateBiomeMap(TerrainInfo);
         var RoadList = RoadGenerator.GenerateRoad(TerrainInfo, SplineScript);
         AssignSplatMap.DoSplat(TerrainInfo);
         ContentManager.InitializeBiomePlacementObjects(TerrainInfo);
         ContentGenerator.PlaceHousesNearRoads(RoadList, TerrainInfo, ContentManager.GetParentContentObject());
         ContentGenerator.GenerateBiomeContent(TerrainInfo);
     }
 }
    private GameObject currentTerrain; //holds a reference to the current terrainType, used to check if next tile is the same type

    /*
     * Method to generate my map from the noise, uses helper methods to generate the trees and grass
     */
    public void GenerateMap()
    {
        //creating the individual maps which add together to make the overall map
        float[,] heightMap   = NoiseGeneration.GenerateNoiseMap(mapWidth, mapHeight, seed, zoom, octaves, amplitudeModifier, frequencyModifier);
        float[,] moistureMap = NoiseGeneration.GenerateNoiseMap(mapWidth, mapHeight, moistureSeed, moistureZoom, moistureOctaves, moistureAmplitudeModifier, moistureFrequencyModifier);
        float[,] falloffMap  = FalloffGeneration.GenerateFalloffMap(mapWidth, falloffPower, falloffOffset);

        currentTerrain = biomes[0].terrain;         //first block will always be 'deepWater' so sets currentTerrain to 'deepWater'

        //loop to go through each point in my map, generate its terrain block, and have a chance to spawn trees and grass on it
        for (int x = 0; x < mapWidth; x++)
        {
            for (int y = 0; y < mapHeight; y++)
            {
                float noiseHeight   = Mathf.Clamp01(heightMap [x, y] - falloffMap[x, y]);
                float noiseMoisture = moistureMap [x, y];
                //loop to categorise the points into their biomes (based on the noiseHeight and noiseMoisture variables)
                for (int i = 0; i < biomes.Length; i++)
                {
                    if (noiseHeight <= biomes [i].height)
                    {
                        Director.GetComponent <Director> ().SetSpawnHeight(x, y, biomes [i].terrainHeight + 0.5f);
                        if (biomes [i].terrainHeight == 1)
                        {
                            Director.GetComponent <Director> ().NotSpawnable(x, y);                             //sets water tiles (the only tiles with terrainHeight 1) to non spawnable
                        }
                        if (noiseMoisture <= biomes [i].moisture)
                        {
                            spawnTerrain(biomes[i], x, y);                         //spawning in terrain
                            spawnGrass(biomes [i], x, y);                          //has a chance to spawn 'grass' on each block
                            if (x % 2 != 0 && y % 2 != 0)                          //has a chance to place a tree every other block
                            {
                                spawnTrees(biomes [i], x, y);
                            }
                            break;
                        }
                    }
                }
            }
        }
    }