Beispiel #1
0
        public BiomeSwitchCell  FindBiome(BiomeSwitchValues values)
        {
            BiomeSwitchCell currentCell = (lastCell == null) ? rootCell : lastCell;

            if (!isBuilt || currentCell == null)
            {
                return(null);
            }

            //since there is no default state, we can do this:
            if (currentCell.Matches(values))
            {
                return(currentCell);
            }

            int maxSearchDepth = 100;
            int i = 0;

            while (true)
            {
                if (i > maxSearchDepth)
                {
                    Debug.LogError("[BiomeSurfaceGraph] Infinite loop detected, exiting ...");
                    return(null);
                }

                i++;
                if (currentCell.Matches(values))
                {
                    //try to find a better link
                    var betterCell = CheckForBetterCell(currentCell, values);

                    //if there is nothing better, we've the solution
                    if (betterCell == null)
                    {
                        lastCell = currentCell;
                        return(currentCell);
                    }
                    else
                    {
                        currentCell = betterCell;
                    }

                    continue;
                }
                else
                {
                    //find the best link to take to get near from the node we look for
                    currentCell = FindBestCell(currentCell, values);

                    if (currentCell == null)
                    {
                        return(null);
                    }
                }
            }
        }