Ejemplo n.º 1
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;
        }
    }