Example #1
0
 void GenerateElevationMap()
 {
     for (int i = 0; i < elevationMap.GetLength(0); i++)
     {
         for (int j = 0; j < elevationMap.GetLength(1); j++)
         {
             elevationMap[i, j] = new ChunkElevation(
                 generatorMatrix[i, j].Next(mapGenerationData.maxElevation),
                 new IntegerPair(generatorMatrix[i, j].Next(chunkTileWidth), generatorMatrix[i, j].Next(chunkTileWidth)));
         }
     }
 }
Example #2
0
        public void Add(ChunkElevation elevation)
        {
            int index = 0;

            for (int i = 0; i < lowestToHighest.Count; i++)
            {
                if (elevation.Mean < lowestToHighest[i].Mean)
                {
                    index = i;
                }
            }
            lowestToHighest.Insert(index, elevation);
        }
Example #3
0
 public OrderedElevationList(ChunkElevation elevation)
 {
     lowestToHighest = new List <ChunkElevation>();
     lowestToHighest.Add(elevation);
 }
Example #4
0
    void GenerateRiverValleys(GameObject[,] chunkMap)
    {
        ClearBinaryMatrix();

        for (int i = 0; i < elevationMap.GetLength(0); i++)
        {
            for (int j = 0; j < elevationMap.GetLength(1); j++)
            {
                RiverValley          riverValley;
                ChunkElevation       centerElevation;
                ChunkElevation       northElevation;
                ChunkElevation       eastElevation;
                ChunkElevation       southElevation;
                ChunkElevation       westElevation;
                OrderedElevationList adjacentRiverValleys = new OrderedElevationList();

                centerElevation = elevationMap[i, j];

                if (j < elevationMap.GetLength(1) - 1)
                {
                    northElevation = elevationMap[i, j + 1];
                    if (northElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(northElevation);
                    }
                }
                else
                {
                    northElevation = new ChunkElevation();
                }

                if (i < elevationMap.GetLength(0) - 1)
                {
                    eastElevation = elevationMap[i + 1, j];
                    if (eastElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(eastElevation);
                    }
                }
                else
                {
                    eastElevation = new ChunkElevation();
                }

                if (j > 0)
                {
                    southElevation = elevationMap[i, j - 1];
                    if (southElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(southElevation);
                    }
                }
                else
                {
                    southElevation = new ChunkElevation();
                }

                if (i > 0)
                {
                    westElevation = elevationMap[i - 1, j];
                    if (westElevation.Mean < mapGenerationData.valleyElevationMaximum)
                    {
                        adjacentRiverValleys.Add(westElevation);
                    }
                }
                else
                {
                    westElevation = new ChunkElevation();
                }

                // if below elevation threshold and there's adjacent river valleys, assume center chunk has a river valley
                if (centerElevation.Mean < mapGenerationData.valleyElevationMaximum && adjacentRiverValleys.Count != 0)
                {
                    IntegerPair    start;
                    IntegerPair    end;
                    ChunkElevation lowest;


                    riverValley = new RiverValley(true);


                    //if center lowest
                    //  main.end = center.slope
                    //  main.start = toward lowest edge.slope
                    //  branch.end = center.slope
                    //  branch.start = toward branch edge.slope
                    //
                    //if center highest ie. multiple main starts
                    //
                    //  main.end = toward lowest edge.slope
                    //  main.start = toward centre.slope
                    //  branch.start = toward center.slope
                    //  branch.end = toward branch edge.slope
                    //
                    //if no adjacent river valleys
                    //  nothing
                    //
                    //if one adjacent lower valley
                    //  either center lowest or highest for main
                    //  no branches
                    //
                    //multiple adjacent valleys
                    //  main.end = toward lowest edge.slope
                    //  main.start = toward second lowest edge.slope
                    //  branch.end = center.slope
                    //  branch.start = toward branch edge.slope

                    lowest = adjacentRiverValleys.PickLowest;

                    if (centerElevation.Mean <= lowest.Mean)
                    {
                        if (lowest == northElevation)
                        {
                            start = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), chunkTileWidth - 1);
                        }
                        else if (lowest == eastElevation)
                        {
                            start = new IntegerPair(chunkTileWidth - 1, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else if (lowest == southElevation)
                        {
                            start = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), 0);
                        }
                        else if (lowest == westElevation)
                        {
                            start = new IntegerPair(0, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else
                        {
                            Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                            start = new IntegerPair();
                        }
                        end = centerElevation.Slope;
                    }
                    else
                    {
                        if (lowest == northElevation)
                        {
                            end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), chunkTileWidth - 1);
                        }
                        else if (lowest == eastElevation)
                        {
                            end = new IntegerPair(chunkTileWidth - 1, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else if (lowest == southElevation)
                        {
                            end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), 0);
                        }
                        else if (lowest == westElevation)
                        {
                            end = new IntegerPair(0, Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                        }
                        else
                        {
                            Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                            end = new IntegerPair();
                        }
                        start = centerElevation.Slope;
                    }

                    riverValley.AddMain(start, end);

                    while (adjacentRiverValleys.Count > 0)
                    {
                        lowest = adjacentRiverValleys.PickLowest;

                        if (centerElevation.Mean <= lowest.Mean)
                        {
                            if (lowest == northElevation)
                            {
                                start = new IntegerPair(
                                    Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2),
                                    chunkTileWidth - 1);
                            }
                            else if (lowest == eastElevation)
                            {
                                start = new IntegerPair(
                                    chunkTileWidth - 1,
                                    Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else if (lowest == southElevation)
                            {
                                start = new IntegerPair(
                                    Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2),
                                    0);
                            }
                            else if (lowest == westElevation)
                            {
                                start = new IntegerPair(
                                    0,
                                    Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else
                            {
                                Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                                start = new IntegerPair();
                            }
                            end = centerElevation.Slope;
                        }
                        else
                        {
                            if (lowest == northElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + chunkTileWidth - 1) / 2));
                            }
                            else if (lowest == eastElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + chunkTileWidth - 1) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else if (lowest == southElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X + northElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y) / 2));
                            }
                            else if (lowest == westElevation)
                            {
                                end = new IntegerPair(Mathf.RoundToInt((centerElevation.Slope.X) / 2), Mathf.RoundToInt((centerElevation.Slope.Y + northElevation.Slope.Y) / 2));
                            }
                            else
                            {
                                Debug.Log("No adjacent elevation matching lowest found, blank IntegerPair returned.");
                                end = new IntegerPair();
                            }
                            start = centerElevation.Slope;
                        }
                        riverValley.AddSource(start, end);
                    }
                }
                else
                {
                    riverValley = new RiverValley(false);
                }

                if (riverValley.Exists)
                {
                    if (riverValley.Main.Exists)
                    {
                        //Draw Main Branch
                        DrawRiver(
                            new IntegerPair(chunkTileWidth * i + riverValley.Main.Start.X, chunkTileWidth * j + riverValley.Main.Start.Y),
                            new IntegerPair(chunkTileWidth * i + riverValley.Main.End.X, chunkTileWidth * j + riverValley.Main.End.Y),
                            generatorMatrix[i, j]);
                    }
                    for (int source = 0; source < riverValley.SourceCount; source++)
                    {
                        DrawRiver(
                            new IntegerPair(chunkTileWidth * i + riverValley.Source(source).Start.X, chunkTileWidth * j + riverValley.Source(source).Start.Y),
                            new IntegerPair(chunkTileWidth * i + riverValley.Source(source).End.X, chunkTileWidth * j + riverValley.Source(source).End.Y),
                            generatorMatrix[i, j]);
                    }
                }
            }
        }

        //SmoothShapeEdges();
        ApplyBinaryMatrixToMap(chunkMap, mapGenerationData.waterTilePrefab);
    }