Beispiel #1
0
    public static void ThermalWorkhorse(float[,] Elevation, MapLoc l, float talusAngle)
    {
        Dictionary <MapLoc, float> n = MapUtil.GetValidNeighbors(Elevation, l); // Thermal Erosion
        float di;
        float dtotal = 0f;
        float dmax   = float.NegativeInfinity;

        foreach (KeyValuePair <MapLoc, float> kvp in n)
        {
            di = Elevation[l.x, l.y] - Elevation[kvp.Key.x, kvp.Key.y];
            if (di > talusAngle)
            {
                dtotal += di;
                di      = di > dmax ? dmax : di;
            }
        }
        float startingElev = Elevation[l.x, l.y];

        foreach (KeyValuePair <MapLoc, float> kvp in n)
        {
            di = startingElev - Elevation[kvp.Key.x, kvp.Key.y];
            float delta = 0.5f * (dmax - talusAngle) * di / dtotal;
            Elevation[kvp.Key.x, kvp.Key.y] += delta;
            Elevation[l.x, l.y]             -= delta;
        }
    }
Beispiel #2
0
    public void FlowProportional(ref float[,] flowStep, Loc l)
    {
        Dictionary <Loc, float> neighbors = MapUtil.GetValidNeighbors(Elevation, l, false); // Flow Proportional
        float localHeight = Elevation[l.x, l.y];
        Dictionary <Loc, float> lowerNeighbors = new Dictionary <Loc, float>();
        float fDiff;
        float totalDiff = 0f;

        foreach (KeyValuePair <Loc, float> n in neighbors)
        {
            if (n.Value < localHeight)
            {
                fDiff = localHeight - n.Value;
                lowerNeighbors[n.Key] = fDiff;
                totalDiff            += fDiff;
            }
        }

        if (lowerNeighbors.Count > 0)
        {
            foreach (KeyValuePair <Loc, float> n in lowerNeighbors)
            {
                flowStep[n.Key.x, n.Key.y] += Water[l.x, l.y] * n.Value / totalDiff;
            }
        }
        else
        {
            float newElev = MapUtil.GetNeighborAverage(Elevation, l);
            newElev             = (newElev + Elevation[l.x, l.y]) / 2f;
            Elevation[l.x, l.y] = newElev;
        }
    }
Beispiel #3
0
 public void SetHarbor()
 {
     for (int x = 0; x < xDim; x++)
     {
         for (int y = 0; y < yDim; y++)
         {
             if (Elevation[x, y] > seaLevel && WaterFlux[x, y] < riverLevel)
             {
                 int adjacentOceanCount = 0;
                 Dictionary <MapLoc, float> neighbors = MapUtil.GetValidNeighbors(Elevation, new MapLoc(x, y));
                 foreach (KeyValuePair <MapLoc, float> kvp in neighbors)
                 {
                     if (kvp.Value < seaLevel)
                     {
                         adjacentOceanCount++;
                     }
                 }
                 if (adjacentOceanCount == 0)
                 {
                     Harbor[x, y] = 0f;
                 }
                 else if (adjacentOceanCount == 1)
                 {
                     Harbor[x, y] = 1f;
                 }
                 else
                 {
                     Harbor[x, y] = 0.5f;
                 }
             }
         }
     }
 }
Beispiel #4
0
    public void SetNodeList(float[,] _elevation, float _seaLevel, delCost fCost, float _seaTravelCost = 0f)
    {
        int xDim = _elevation.GetLength(0);
        int yDim = _elevation.GetLength(1);

        Node[,] nodes = new Node[xDim, yDim];
        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                nodes[x, y] = new Node(x, y);
                nodeDict[new MapLoc(x, y)] = nodes[x, y];
            }
        }
        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                Node n = nodes[x, y];
                n.Visited = false;
                MapLoc l = new MapLoc(x, y);
                Dictionary <MapLoc, float> d = MapUtil.GetValidNeighbors(_elevation, l);
                foreach (KeyValuePair <MapLoc, float> kvp in d)
                {
                    n.neighborWeights[nodes[kvp.Key.x, kvp.Key.y]] = fCost(l, kvp.Key, _elevation, _seaLevel, _seaTravelCost);
                    n.neighbors.Add(nodes[kvp.Key.x, kvp.Key.y]);
                }
                nodelist.Add(n);
            }
        }
    }
Beispiel #5
0
 public MapPainter(float[,] _elevation, float _seaLevel)
 {
     nodelist      = new List <Node>();
     elevation     = _elevation;
     seaLevel      = _seaLevel;
     xDim          = _elevation.GetLength(0);
     yDim          = _elevation.GetLength(1);
     Node[,] nodes = new Node[xDim, yDim];
     for (int x = 0; x < xDim; x++)
     {
         for (int y = 0; y < yDim; y++)
         {
             nodes[x, y] = new Node(x, y);
         }
     }
     for (int x = 0; x < xDim; x++)
     {
         for (int y = 0; y < yDim; y++)
         {
             Node n = nodes[x, y];
             n.Visited = false;
             MapLoc l = new MapLoc(x, y);
             Dictionary <MapLoc, float> d = MapUtil.GetValidNeighbors(_elevation, l);
             foreach (KeyValuePair <MapLoc, float> kvp in d)
             {
                 if ((_elevation[x, y] > _seaLevel && _elevation[kvp.Key.x, kvp.Key.y] > _seaLevel) ||
                     (_elevation[x, y] < _seaLevel && _elevation[kvp.Key.x, kvp.Key.y] < _seaLevel))
                 {
                     n.neighborWeights[nodes[kvp.Key.x, kvp.Key.y]] = MapUtil.Distance(kvp.Key, l);
                     n.neighbors.Add(nodes[kvp.Key.x, kvp.Key.y]);
                 }
             }
             nodelist.Add(n);
             nodedict[n.loc] = n;
         }
     }
     Paint();
 }