예제 #1
0
    // Converts the top cell to sand if certain criteria are met
    // This modifies terrain based on neighbor stacks
    // Thus it should only be called after all cell stacks are generated
    void AddSand(CellStack cellStack)
    {
        if (cellStack.Count() == terrain.waterLevel)
        {
            HexCoordinates[] neighbors = cellStack.coordinates.GetNeighbors();
            for (int i = 0; i < 6; i++)
            {
                CellStack neighbor = GetCellStackFromWorldCoords(neighbors[i]);

                // The neighbor cell stack might not be in this chunk
                if (neighbor == null)
                {
                    TerrainChunk neighborChunk = terrain.GetChunkFromWorldCoords(neighbors[i]);
                    if (neighborChunk != null)
                    {
                        neighbor = neighborChunk.GetCellStackFromWorldCoords(neighbors[i]);
                    }
                }

                if (neighbor != null)
                {
                    if (neighbor.Count() < terrain.waterLevel)
                    {
                        cellStack.Pop();
                        cellStack.Push(CellType.Sand);
                        break;
                    }
                }
            }
        }
    }
예제 #2
0
    public void RemoveCell(HexCoordinates coordinates)
    {
        CellStack stack = GetCellStackFromWorldCoords(coordinates);

        if (stack)
        {
            stack.Pop();
            GenerateMeshes();
        }
    }
예제 #3
0
    public void AddCell(CellType cell, HexCoordinates coords)
    {
        CellStack stack = GetCellStackFromWorldCoords(coords);

        if (stack)
        {
            // Only trees can be placed on top of grass
            // So if something else is placed on top of grass, turn the grass into dirt
            if (stack.Peek() == CellType.Grass)
            {
                stack.Pop();
                stack.Push(CellType.Dirt);
            }

            stack.Push(cell);
            GenerateMeshes();
        }
    }