Example #1
0
    public bool TryGetMapPoint(TerrainMapPoint point, Direction dir, bool onlyIfEmpty, out TerrainMapPoint newMapPoint)
    {
        newMapPoint = new TerrainMapPoint()
        {
            x = point.x,
            y = point.y
        };

        switch (dir)
        {
        case Direction.Up:
            ++newMapPoint.x;
            break;

        case Direction.Down:
            --newMapPoint.x;
            break;

        case Direction.Left:
            --newMapPoint.y;
            break;

        case Direction.Right:
            ++newMapPoint.y;
            break;
        }

        return(IsValid(newMapPoint) && (onlyIfEmpty ? (GetTerrainType(newMapPoint) == TerrainType.None) : true));
    }
Example #2
0
    private bool FillFromPoint(TerrainMapPoint point)
    {
        Direction exclusionList = Direction.None;

        do
        {
            Direction nextDirection = GetRandomDirection(exclusionList);

            TerrainMapPoint nextPoint;
            if (terrain.TryGetEmptyMapPoint(point, nextDirection, out nextPoint))
            {
                MapSquareInfo squareInfo;
                if (terrain.TrySetPointForBiome(nextPoint, this, out squareInfo))
                {
                    mapSquareInfoPoints.Add(squareInfo);
                }
                return(true);
            }
            else
            {
                exclusionList |= nextDirection;
            }
        } while (exclusionList != Direction.AllDirections);

        return(false);
    }
Example #3
0
    public void Initialize(TerrainType type, TerrainMapPoint initPoint, Terrain t)
    {
        terrain = t;
        terrainType = type;
        terrain.SetPoint(initPoint, type);

        mapPoints.Add(initPoint);
    }
Example #4
0
 public bool IsValid(TerrainMapPoint point)
 {
     return (
         point.x >= 0 &&
         point.x < TerrainSize &&
         point.y >= 0 &&
         point.y < TerrainSize
         );
 }
Example #5
0
 public bool IsValid(TerrainMapPoint point)
 {
     return(
         point.x >= 0 &&
         point.x < TerrainSize &&
         point.y >= 0 &&
         point.y < TerrainSize
         );
 }
Example #6
0
    private TerrainMapPoint GetRandomEmptyPoint()
    {
        TerrainMapPoint randomPoint = new TerrainMapPoint();

        do
        {
            randomPoint.x = UnityEngine.Random.Range(0, TerrainSize);
            randomPoint.y = UnityEngine.Random.Range(0, TerrainSize);
        } while (GetTerrainType(randomPoint) != TerrainType.None);

        return(randomPoint);
    }
Example #7
0
    public void Initialize(TerrainMapPoint initPoint, Terrain t)
    {
        terrain = t;
        centerPoint = terrain.GetCenterPoint();

        terrain.SetPoint(initPoint, TerrainType.Empty);

        mapPoints.Add(new FloodFillMapPoint()
        {
             mapPoint = initPoint,
             floodFilled = false
        });
    }
Example #8
0
    public bool SetPoint(TerrainMapPoint point, TerrainType type)
    {
        if (GetTerrainType(point) != TerrainType.None)
        {
            return false;
        }
        else
        {
            terrainMap[point.x, point.y].type = type;
        }

        return true;
    }
Example #9
0
    public void Initialize(TerrainType type, TerrainMapPoint initPoint, TerrainMap t)
    {
        thisBiomeID = biomeID++;

        terrain     = t;
        TerrainType = type;

        MapSquareInfo squareInfo;

        if (terrain.TrySetPointForBiome(initPoint, this, out squareInfo))
        {
            mapSquareInfoPoints.Add(squareInfo);
        }
    }
Example #10
0
 public bool TrySetPointForBiome(TerrainMapPoint point, Biome biome, out MapSquareInfo squareInfo)
 {
     if (GetTerrainType(point) != TerrainType.None)
     {
         squareInfo = null;
         return(false);
     }
     else
     {
         terrainMap[point.x, point.y].biomeid = biome.BiomeID;
         terrainMap[point.x, point.y].type    = biome.TerrainType;
         squareInfo = terrainMap[point.x, point.y];
         return(true);
     }
 }
Example #11
0
    private bool FillFromPoint(TerrainMapPoint point)
    {
        Direction exclusionList = Direction.None;

        do
        {
            Direction nextDirection = GetRandomDirection(exclusionList);

            TerrainMapPoint nextPoint;
            if (terrain.TryGetMapPoint(point, nextDirection, out nextPoint))
            {
                terrain.SetPoint(nextPoint, terrainType);
                mapPoints.Add(nextPoint);
                return true;
            }
            else
            {
                exclusionList |= nextDirection;
            }
        } while (exclusionList != Direction.AllDirections);

        return false;
    }
Example #12
0
    public bool TryGetSquareInfo(TerrainMapPoint point, Direction dir, out MapSquareInfo squareInfo)
    {
        squareInfo = null;

        var newMapPoint = new TerrainMapPoint()
        {
            x = point.x,
            y = point.y
        };

        switch (dir)
        {
        case Direction.Up:
            ++newMapPoint.x;
            break;

        case Direction.Down:
            --newMapPoint.x;
            break;

        case Direction.Left:
            --newMapPoint.y;
            break;

        case Direction.Right:
            ++newMapPoint.y;
            break;
        }

        if (IsValid(newMapPoint))
        {
            squareInfo = terrainMap[newMapPoint.x, newMapPoint.y];
        }

        return(squareInfo != null);
    }
Example #13
0
    public bool TryGetMapPoint(TerrainMapPoint point, Direction dir, out TerrainMapPoint newMapPoint)
    {
        newMapPoint = new TerrainMapPoint()
        {
            x = point.x,
            y = point.y
        };

        switch (dir)
        {
            case Direction.Up:
                ++newMapPoint.x;
                break;
            case Direction.Down:
                --newMapPoint.x;
                break;
            case Direction.Left:
                --newMapPoint.y;
                break;
            case Direction.Right:
                ++newMapPoint.y;
                break;
        }

        return IsValid(newMapPoint) && (GetTerrainType(newMapPoint) == TerrainType.None);
    }
Example #14
0
    private TerrainMapPoint GetRandomEmptyPoint()
    {
        TerrainMapPoint randomPoint = new TerrainMapPoint();

        do
        {
            randomPoint.x = UnityEngine.Random.Range(0, 100);
            randomPoint.y = UnityEngine.Random.Range(0, 100);
        } while (GetTerrainType(randomPoint) != TerrainType.None);

        return randomPoint;
    }
Example #15
0
 public TerrainType GetTerrainType(TerrainMapPoint point)
 {
     return(terrainMap[point.x, point.y].type);
 }
Example #16
0
 public bool TryGetEmptyMapPoint(TerrainMapPoint point, Direction dir, out TerrainMapPoint newMapPoint)
 {
     return(TryGetMapPoint(point, dir, true, out newMapPoint));
 }
Example #17
0
 public TerrainType GetTerrainType(TerrainMapPoint point)
 {
     return terrainMap[point.x, point.y].type;
 }