Exemplo n.º 1
0
    //will currently stop if it meets another river
    void placeRiver(TileDisplay hill)
    {
        River              newRiver;
        TileDisplay        next          = hill;
        TileDisplay        currentLowest = null;
        List <TileDisplay> inRoute       = new List <TileDisplay>();

        TileDisplay[] toCheck;
        int           loops = 0;
        bool          done  = false;

        //this check is being done to reduce the number of rivers
        toCheck = next.GetNeightbours();
        for (int i = 0; i < 5; i++)
        {
            if (toCheck[i] != null)
            {
                if (toCheck[i].name == "Water")
                {
                    done = true;
                }
            }
        }

        while (!done)
        {
            loops += 1;
            if (loops > 999)
            {
                Debug.Log("Infinite looped");
                break;
            }
            if (next.getNextLowestNeighbour(inRoute) != null)
            {
                currentLowest = next.getNextLowestNeighbour(inRoute);
                if (currentLowest.name == "Water")
                {
                    done = true;
                }
                if (currentLowest.GetNumNeighbours() < 5)
                {
                    done = true;
                }
            }
            else //if stuck, backtrack
            {
                currentLowest = inRoute[inRoute.Count - 1];
            }
            if (currentLowest != null)
            {
                inRoute.Add(currentLowest);
                next = currentLowest;
            }
        }
        if (inRoute.Count != 0)
        {
            newRiver = new River(inRoute);
            //Debug.Log("River Finished");
            rivers.Add(newRiver);
        }
    }