// 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);
     }
 }
Beispiel #2
0
    int[,] GenerateRoads()
    {
        // 1 = major road point, 2 = minor road point

        int[,] pointMap = new int[BorderDimension, BorderDimension];
        int[,] roadMap  = new int[BorderDimension, BorderDimension];

        int edge = Mathf.FloorToInt((int)villageSize / minCellSize) * minCellSize;

        //Major roads
        if (useMajorRoads)
        {
            for (int y = 0; y < VillageDimension; y += minCellSize * majorRoadFrequency)
            {
                for (int x = 0; x < VillageDimension; x += minCellSize * majorRoadFrequency)
                {
                    var chance = rand.Next(0, 100) / 100f;

                    if (chance <= majorRoadDensity)
                    {
                        pointMap[Position(x), Position(y)] = 1;

                        //Place a path point
                        if (y == 0 || x == 0 || y == edge || x == edge)
                        {
                            //var offset = (int)villageSize / 2;
                            //var pos = new Vector3Int((int)transform.position.x + x - offset, (int)transform.position.y + y - offset, 0);
                            //var GO = Instantiate(ObjectStore.instance.pathGoal, pos, Quaternion.identity);
                            //var goal = GO.GetComponent<PathGoal>();

                            //if(x == 0)
                            //        goal.facingDirection = PathGoal.Direction.North;
                            //else if(x == edge)
                            //        goal.facingDirection = PathGoal.Direction.South;

                            //else if(y == 0)
                            //        goal.facingDirection = PathGoal.Direction.East;
                            //else if(y == edge)
                            //        goal.facingDirection = PathGoal.Direction.West;
                        }
                    }
                }
            }
        }

        //Minor roads
        for (int y = 0; y < VillageDimension; y += minCellSize)
        {
            for (int x = 0; x < VillageDimension; x += minCellSize)
            {
                var chance = rand.Next(0, 100) / 100f;

                if (chance <= minorRoadDensity)
                {
                    if (pointMap[Position(x), Position(y)] != 1)
                    {
                        pointMap[Position(x), Position(y)] = 2;
                    }
                }
            }
        }

        if (linkRoads)
        {
            LinkRoads();
        }

        return(linkRoads ? roadMap : pointMap);

        void LinkRoads()
        {
            potentialLargeBuildingLocations = new List <Vector2Int>();

            for (int y = 0; y < VillageDimension; y += minCellSize)
            {
                for (int x = 0; x < VillageDimension; x += minCellSize)
                {
                    var posX = Position(x);
                    var posY = Position(y);

                    //Placing large buildings in valid spots
                    int roadType = pointMap[posX, posY];
                    if (roadType < 1)
                    {
                        potentialLargeBuildingLocations.Add(new Vector2Int(posX, posY));
                        continue;
                    }

                    //Placing roads
                    int multiplier = (roadType == 1) ? majorRoadFrequency : 1;

                    if (GenericHelper.InBounds(posX, posY - minCellSize * multiplier, pointMap))
                    {
                        var other = pointMap[posX, posY - minCellSize * multiplier];
                        if (other <= roadType && other > 0) //Vertical
                        {
                            RoadGenerator.GenerateRoad(ref roadMap, posX, posY, minCellSize, multiplier, roadType, thickRoads, Axis.Vertical);
                        }
                    }

                    if (GenericHelper.InBounds(posX - minCellSize * multiplier, posY, pointMap))
                    {
                        var other = pointMap[posX - minCellSize * multiplier, posY];

                        if (other <= roadType && other > 0) //Horizontal
                        {
                            RoadGenerator.GenerateRoad(ref roadMap, posX, posY, minCellSize, multiplier, roadType, thickRoads, Axis.Horizontal);
                        }
                    }
                }
            }
        }
    }