Esempio n. 1
0
    public int GetSurroundingUrbanCount(GridCoord coord)
    {
        // The minus and plus ones in the loop here allow us to search
        // in a 3x3 sqr around the selected tile
        int urbanCount = 0;

        BlockType[] rural = new BlockType[2] {
            BlockType.forest, BlockType.mountain
        };
        for (int neighborX = coord.x - 1; neighborX <= coord.x + 1; neighborX++)
        {
            for (int neighborZ = coord.z - 1; neighborZ <= coord.z + 1; neighborZ++)
            {
                if (neighborX != coord.x || neighborX != coord.z)
                {
                    // Neighbor at coords is NOT rural, or is an edge
                    Block neighbor = GetBlockAtCoords(new GridCoord(neighborX, neighborZ));
                    if (!neighbor)
                    {
                        urbanCount += 1;
                        continue;
                    }
                    if (Array.IndexOf(rural, neighbor.type) == -1)
                    {
                        urbanCount += 1;
                    }
                }
            }
        }
        return(urbanCount);
    }
Esempio n. 2
0
 static void AddCell(GridCoord coord, TypeCell type)
 {
     if (!cells.Exists((c) => c.coord == coord))
     {
         cells.Add(new CellData(coord, type));
     }
 }
Esempio n. 3
0
    // spawns the new currentPlayerPiece
    private bool spawnPiece(bool fromHeldPiece = false)
    {
        // shift all the next pieces up and spawn the next piece
        if (!fromHeldPiece)
        {
            currentPlayerPiece = nextPieces[0].piece;
            for (int i = 0; i < nextPieces.Length - 1; i++)
            {
                nextPieces[i].set(nextPieces[i + 1].piece);
            }
            nextPieces[nextPieces.Length - 1].set(Instantiate(piece).GetComponent <Piece> ());
        }
        else             // we're spawning from the held piece
        {
            Piece newPiece = heldPiece.piece;
            heldPiece.set(currentPlayerPiece);
            currentPlayerPiece = newPiece;
            if (currentPlayerPiece == null)
            {
                return(spawnPiece());
            }
        }
        GridCoord gridTopLeft = new GridCoord(0, width / 2 - (currentPlayerPiece.width + 1) / 2 + (currentPlayerPiece.width == 3 ? Random.Range(0, 2) : 0));
        bool      result      = currentPlayerPiece.addToGrid(grid, gridTopLeft);

        drawPieces();
        return(result);
    }
Esempio n. 4
0
    public void CreateNeighborhood()
    {
        for (int x = 0, i = 0; x < width; x++)
        {
            for (int z = 0; z < height; z++)
            {
                GridCoord coord = new GridCoord(x, z);
                if (UnityEngine.Random.value * 100 < residentialChance)
                {
                    CreateBlock(4, coord, i++);
                }
                else
                {
                    CreateBlock(1, coord, i++);
                }
            }
        }
        IterativelySmooth(smoothCount);
        // CalculateAllNeighbors();

        LayMountainRanges();
        AttemptGrowCity();
        PlaceParks();
        PlaceShopping();
        SetEdgeRoads();
        CheckCornerBlocks();
        CarSpawner carSpawner = GetComponent <CarSpawner>();

        if (carSpawner)
        {
            carSpawner.Begin();
        }
    }
Esempio n. 5
0
    public void recompute_minimums()
    {
        Debug.Log("I was asked to recompute.");
        int x = num_vertices_x;
        int y = num_vertices_y;

        for (int a = 0; a < x; a++)
        {
            for (int b = 0; b < y; b++)
            {
                // Immediate source-Dest pairs by weight
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        for (int k = 0; k < x; k++)
                        {
                            for (int l = 0; l < y; l++)
                            {
                                double alt = dist[i, j, a, b] + dist[a, b, k, l];
                                if (alt < dist[i, j, k, l])
                                {
                                    dist[i, j, k, l] = alt;
                                    next[i, j, k, l] = new GridCoord(a, b, alt);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 6
0
    // Passes in the grid it should be added to and the top left coordinate
    // where the piece should be placed
    public bool addToGrid(Block[,] grid, GridCoord topLeft)
    {
        initializeBlocks();
        this.grid    = grid;
        this.topLeft = topLeft;
        GridCoord[] tests = { new GridCoord(topLeft.row - 3, topLeft.col),
                              new GridCoord(topLeft.row - 2, topLeft.col),
                              new GridCoord(topLeft.row - 1, topLeft.col), topLeft };
        GridCoord   resultCoord = null;

        foreach (GridCoord coord in tests)
        {
            if (canAddAt(coord))
            {
                resultCoord = coord;
            }
        }
        if (resultCoord != null)
        {
            addAt(resultCoord);
        }
        if (resultCoord != topLeft)
        {
            return(false);
        }
        return(true);
    }
Esempio n. 7
0
            public int CalcDistance(GridCoord other)
            {
                var xDist = Math.Abs(X - other.X);
                var yDist = Math.Abs(Y - other.Y);

                return(xDist + yDist);
            }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        Ray        mouseRay = mainCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit rayHit   = new RaycastHit();

        if (Physics.Raycast(mouseRay, out rayHit, 1000))
        {
            GameObject hit = rayHit.collider.gameObject;
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }
            if (hit.GetComponentInParent <Square>() == null)
            {
                return;
            }
            Square s = hit.GetComponentInParent <Square>();
            if (!GridCoord.IsAdjacent(thisCar.gridCoord, s.coord))
            {
                return;
            }
            if (s.squareType == Square.SquareType.BUILDING)
            {
                return;
            }
            if (s.squareType == Square.SquareType.BANK)
            {
                gameController.RobBank(s);
                return;
            }
            gameController.ClickOnSquare(s);
        }
    }
Esempio n. 9
0
    Car SpawnCop()
    {
        GameObject spawnedCop = Instantiate(copCarPrefab);
        Car        copCar     = spawnedCop.GetComponent <Car>();

        copCar.carName = GetRandomName();
        bool found = false;

        do
        {
            GridCoord gridCoord = new GridCoord(Random.Range(0, gridGenerator.dimensionsX), Random.Range(0, gridGenerator.dimensionsY));
            if (gridGenerator.GetSquare(gridCoord).squareType == Square.SquareType.ROAD && gridCoord.x != 0 && gridCoord.y != Mathf.FloorToInt((gridGenerator.dimensionsY) / 2))
            {
                Square s = gridGenerator.GetSquare(gridCoord);
                if (CanMoveTo(copCar, s, true))
                {
                    MoveToSquare(copCar, gridGenerator.GetSquare(gridCoord));
                    found = true;
                }
                continue;
            }
        } while (!found);
        copCars.Add(copCar);
        uiController.SetCopAmount(copCars.Count);
        return(copCar);
    }
Esempio n. 10
0
        public static uint GetTerrainMapId(PhaseShift phaseShift, Map map, float x, float y)
        {
            if (phaseShift.VisibleMapIds.Empty())
            {
                return(map.GetId());
            }

            if (phaseShift.VisibleMapIds.Count == 1)
            {
                return(phaseShift.VisibleMapIds.First().Key);
            }

            GridCoord gridCoord = GridDefines.ComputeGridCoord(x, y);
            uint      gx        = ((MapConst.MaxGrids - 1) - gridCoord.X_coord);
            uint      gy        = ((MapConst.MaxGrids - 1) - gridCoord.Y_coord);

            foreach (var visibleMap in phaseShift.VisibleMapIds)
            {
                if (map.HasChildMapGridFile(visibleMap.Key, gx, gy))
                {
                    return(visibleMap.Key);
                }
            }

            return(map.GetId());
        }
Esempio n. 11
0
 public void AttemptGrowCity()
 {
     for (int x = 0; x < width; x++)
     {
         for (int z = 0; z < height; z++)
         {
             GridCoord coord = new GridCoord(x, z);
             int       index = GetIndex(coord);
             Block     block = blocks[index];
             if (block.type != BlockType.residential)
             {
                 continue;
             }
             BlockType[] urban = new BlockType[2] {
                 BlockType.residential, BlockType.city
             };
             // TODO: This will check tiles that are north or south in the NEXT col
             Block northBlock         = GetBlockInDirection(Direction.North, coord);
             Block eastBlock          = GetBlockInDirection(Direction.East, coord);
             Block southBlock         = GetBlockInDirection(Direction.South, coord);
             Block westBlock          = GetBlockInDirection(Direction.West, coord);
             bool  northIsResidential = northBlock ? Array.IndexOf(urban, northBlock.type) > -1 : false;
             bool  eastIsResidential  = eastBlock ? Array.IndexOf(urban, eastBlock.type) > -1 : false;
             bool  southIsResidential = southBlock ? Array.IndexOf(urban, southBlock.type) > -1 : false;
             bool  westIsResidential  = westBlock ? Array.IndexOf(urban, westBlock.type) > -1 : false;
             if (northIsResidential && eastIsResidential && southIsResidential && westIsResidential)
             {
                 ReplaceBlock(0, coord);
             }
         }
     }
 }
Esempio n. 12
0
    /// <summary>
    /// Нахождение свободной ячейки для особых спаунов
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    static CellData FindFreePlaceForSpecial(Direction dir)
    {
        while (true)
        {
            int x = 0;
            int z = 0;
            switch (dir)
            {
            case Direction.Forward:
                x = Random.Range(1, GameLogic.levelSize - 2);
                z = Random.Range(1, 3);
                break;

            case Direction.Back:
                x = Random.Range(1, GameLogic.levelSize - 2);
                z = Random.Range(GameLogic.levelSize - 4, GameLogic.levelSize - 2);
                break;
            }
            GridCoord coord    = new GridCoord(x, z);
            CellData  findCell = null;
            if (cells.Exists((c) => c.coord == coord, out findCell) && findCell.type == TypeCell.Free)
            {
                return(findCell);
            }
        }
    }
Esempio n. 13
0
    public GridCoord IndexToCoord(int index)
    {
        int       x     = index / height;
        int       z     = index - (x * height);
        GridCoord coord = new GridCoord(x, z);

        return(coord);
    }
 public override void OnRemoveFromLevel(LevelGrid grid, GridCoord position)
 {
     // Unlink from other tile.
     if (triggerSquare != null)
     {
         triggerSquare.toggleSquare = null;
     }
 }
Esempio n. 15
0
    public void Pick()
    {
        var point = camera.ScreenPointToRay(Input.mousePosition).GetPoint(distanceFromOrigin);
        var coord = new GridCoord(point);

        if (grid.Get(coord) == VoxelType.Empty)
            grid.Set(coord, VoxelType.White);
    }
Esempio n. 16
0
    public static Vector3 GridCoordToWorld(GridCoord gridCoord, float tSize)
    {
        float rowOffset = Camera.main.orthographicSize;
        float colOffset = Camera.main.orthographicSize * Camera.main.aspect;
        float x         = gridCoord.col * tSize - colOffset + tSize / 2;
        float y         = gridCoord.row * tSize - rowOffset + tSize / 2;

        return(new Vector3(x, y, 0));
    }
Esempio n. 17
0
        public bool ExistMapAndVMap(uint mapid, float x, float y)
        {
            GridCoord p = GridDefines.ComputeGridCoord(x, y);

            uint gx = (MapConst.MaxGrids - 1) - p.X_coord;
            uint gy = (MapConst.MaxGrids - 1) - p.Y_coord;

            return(Map.ExistMap(mapid, gx, gy) && Map.ExistVMap(mapid, gx, gy));
        }
Esempio n. 18
0
        public bool ExistMapAndVMap(uint mapid, float x, float y)
        {
            GridCoord p = GridDefines.ComputeGridCoord(x, y);

            uint gx = 63 - p.x_coord;
            uint gy = 63 - p.y_coord;

            return(Map.ExistMap(mapid, gx, gy) && Map.ExistVMap(mapid, gx, gy));
        }
Esempio n. 19
0
    // Attempts to rotate the piece (uses wall kicks if it can't rotate in place)
    // If it's at the bottom, it can perform floor kicks
    // If the piece cannot rotate, returns false;
    public bool rotate()
    {
        bool atBottom = isAtBottom();

        removeFromGrid();
        cycleRotation();
        GridCoord left  = new GridCoord(topLeft.row, topLeft.col - 1);
        GridCoord right = new GridCoord(topLeft.row, topLeft.col + 1);

        if (canAddAt(topLeft))
        {
            addAt(topLeft);
            return(true);
        }
        else if (atBottom)             // it has blocks below it and can't go down, so try a floor kick
        {
            GridCoord up = new GridCoord(topLeft.row - 1, topLeft.col);
            if (canAddAt(up))
            {
                addAt(up);
                topLeft = up;
                return(true);
            }
        }
        else if (canAddAt(left))
        {
            addAt(left);
            topLeft = left;
            return(true);
        }
        else if (canAddAt(right))
        {
            addAt(right);
            topLeft = right;
            return(true);
        }
        else if (shape == barShape)             // the bar shape can have 2 columns of whitespace, so it can kick 2
        {
            GridCoord left2  = new GridCoord(topLeft.row, topLeft.col - 2);
            GridCoord right2 = new GridCoord(topLeft.row, topLeft.col + 2);
            if (canAddAt(left2))
            {
                addAt(left2);
                topLeft = left2;
                return(true);
            }
            else if (canAddAt(right2))
            {
                addAt(right2);
                topLeft = right2;
                return(true);
            }
        }
        cycleRotation(-1);
        addAt(topLeft);
        return(false);
    }
Esempio n. 20
0
            public Grid(int XLowest, int XHighest, int YLowest, int YHighest)
            {
                this.XLowest  = XLowest;
                this.XHighest = XHighest;
                this.YLowest  = YLowest;
                this.YHighest = YHighest;

                GridCoords = new GridCoord[XHighest - XLowest + 1, YHighest - YLowest + 1];
            }
Esempio n. 21
0
    public void ReplaceBlock(int blockIndex, GridCoord coord)
    {
        int     index            = GetIndex(coord);
        Block   oldBlock         = blocks[index];
        Vector3 oldBlockPosition = oldBlock.transform.position;

        CreateBlock(blockIndex, coord, index);

        Destroy(oldBlock.gameObject);
    }
Esempio n. 22
0
    public Vector3 query_graph_to_vec3(int pos_x, int pos_y, int goal_x, int goal_y)
    {
        int       i = pos_x, j = pos_y, k = goal_x, l = goal_y;
        GridCoord n = next[i, j, k, l];

        Debug.Log("I was queried.");
        Debug.Log(n);

        return(world_coords_from_grid_coords(n.x, n.y));
    }
Esempio n. 23
0
    public TileChunk AddChunk(GridCoord coord)
    {
        TileChunk chunk = (TileChunk)Instantiate(m_chunkPrefab, new Vector3(coord.x, coord.y, 3), Quaternion.identity);
        chunk.Init(coord, m_chunkSize);

        m_chunks[coord] = chunk;
        chunk.transform.parent = transform;

        return chunk;
    }
Esempio n. 24
0
    public override bool Equals(object obj)
    {
        if (!(obj is GridCoord))
        {
            return(false);
        }
        GridCoord gc = (GridCoord)obj;

        return(this.x == gc.x && this.y == gc.y);
    }
    public override void OnAddToLevel(LevelGrid grid, GridCoord position)
    {
        // Try to link to an unused trigger.
        TriggeredPlatformSquare trigger = FindUnusedTriggeredPlatformSquare(grid);

        if (trigger != null)
        {
            triggerSquare = trigger;
            triggerSquare.toggleSquare = this;
        }
    }
Esempio n. 26
0
    public int[] query_graph(int pos_x, int pos_y, int goal_x, int goal_y)
    {
        int       i = pos_x, j = pos_y, k = goal_x, l = goal_y;
        GridCoord v = next[i, j, k, l];

        Debug.Log("I was queried.");
        Debug.Log(next[i, j, k, l]);

        int[] val = new int[] { v.x, v.y };
        return(val);
    }
Esempio n. 27
0
    public override void OnAddToLevel(LevelGrid grid, GridCoord position)
    {
        // Try to link to an unused toggle.
        ToggleTriggerPlatformSquare toggle = FindUnusedToggleTriggerPlatformSquare(grid);

        if (toggle != null)
        {
            toggleSquare = toggle;
            toggleSquare.triggerSquare = this;
        }
    }
Esempio n. 28
0
    public void PlaceShopping()
    {
        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < height; z++)
            {
                GridCoord coord = new GridCoord(x, z);
                int       index = GetIndex(coord);
                if (Array.IndexOf(new BlockType[2] {
                    BlockType.residential, BlockType.city
                }, blocks[index].type) == -1)
                {
                    continue;
                }
                bool        residentialSeen = false;
                bool        citySeen        = false;
                BlockType[] urban           = new BlockType[2] {
                    BlockType.residential, BlockType.city
                };

                Block northBlock = GetBlockInDirection(Direction.North, coord);
                Block eastBlock  = GetBlockInDirection(Direction.East, coord);
                Block southBlock = GetBlockInDirection(Direction.South, coord);
                Block westBlock  = GetBlockInDirection(Direction.West, coord);

                bool northIsResidential = northBlock ? Array.IndexOf(urban, northBlock.type) > -1 : false;
                bool eastIsResidential  = eastBlock ? Array.IndexOf(urban, eastBlock.type) > -1 : false;
                bool southIsResidential = southBlock ? Array.IndexOf(urban, southBlock.type) > -1 : false;
                bool westIsResidential  = westBlock ? Array.IndexOf(urban, westBlock.type) > -1 : false;

                Block[] neighbors = new Block[4] {
                    northBlock, eastBlock, southBlock, westBlock
                };
                foreach (Block neighbor in neighbors)
                {
                    if (neighbor && neighbor.type == BlockType.residential)
                    {
                        residentialSeen = true;
                    }
                    if (neighbor && neighbor.type == BlockType.city)
                    {
                        citySeen = true;
                    }
                }
                if (
                    northIsResidential && eastIsResidential && southIsResidential && westIsResidential &&
                    residentialSeen && citySeen &&
                    UnityEngine.Random.value * 100 < shoppingChance)
                {
                    ReplaceBlock(5, coord);
                }
            }
        }
    }
Esempio n. 29
0
    public void CreateBlock(int blockIndex, GridCoord coord, int i)
    {
        Vector3 newPosition = new Vector3(coord.x * blockOffset, 0f, coord.z * blockOffset);
        Block   blockPrefab = blockPrefabs[blockIndex];
        Block   block       = blocks[i] = Instantiate <Block>(blockPrefab);

        block.transform.SetParent(transform, false);
        block.transform.localPosition = newPosition;
        block.neighborhood            = this;
        block.coord = coord;
        block.index = GetIndex(coord);
    }
Esempio n. 30
0
    public Block GetBlockAtCoords(GridCoord coord)
    {
        if (parentShape != null)
        {
            if (coord.x < 0)
            {
                Neighborhood borderingNeighborhood = parentShape.GetNeighborhoodInDirection(Direction.West, this);
                if (!borderingNeighborhood)
                {
                    return(null);
                }
                return(borderingNeighborhood.GetBlockAtCoords(new GridCoord(width - 1, coord.z)));
            }
            if (coord.z < 0)
            {
                Neighborhood borderingNeighborhood = parentShape.GetNeighborhoodInDirection(Direction.South, this);
                if (!borderingNeighborhood)
                {
                    return(null);
                }
                return(borderingNeighborhood.GetBlockAtCoords(new GridCoord(coord.x, height - 1)));
            }
            if (coord.x > width - 1)
            {
                Neighborhood borderingNeighborhood = parentShape.GetNeighborhoodInDirection(Direction.East, this);
                if (!borderingNeighborhood)
                {
                    return(null);
                }
                return(borderingNeighborhood.GetBlockAtCoords(new GridCoord(0, coord.z)));
            }
            if (coord.z > height - 1)
            {
                Neighborhood borderingNeighborhood = parentShape.GetNeighborhoodInDirection(Direction.North, this);
                if (!borderingNeighborhood)
                {
                    return(null);
                }
                return(borderingNeighborhood.GetBlockAtCoords(new GridCoord(coord.x, 0)));
            }
        }
        int index = GetIndex(coord);

        if (ContainsIndex(index))
        {
            Block block = blocks[index];
            return(block);
        }
        else
        {
            throw new Exception("Coordinate not inside known neighborhoods.");
        }
    }
Esempio n. 31
0
    // Removes the shape from the grid, checks if it can be readded one space below.
    // If it can't, then it's at the bottom (and true will be returned). Re-adds the
    // shape to the grid, then returns the result
    public bool isAtBottom()
    {
        removeFromGrid();
        GridCoord belowCoords = new GridCoord(topLeft.row + 1, topLeft.col);

        if (!canAddAt(belowCoords))            // it can't go down further
        {
            addAt(topLeft);
            return(true);
        }
        addAt(topLeft);
        return(false);
    }
Esempio n. 32
0
    // Shifts the shape in the given horizontal and vertical directions. Returns whether
    // or not the shift succeeded.
    private bool shift(int horizontal, int vertical)
    {
        removeFromGrid();
        GridCoord newCoords = new GridCoord(topLeft.row + vertical, topLeft.col + horizontal);

        if (canAddAt(newCoords))
        {
            addAt(newCoords);
            topLeft = newCoords;
            return(true);
        }
        addAt(topLeft);
        return(false);
    }
Esempio n. 33
0
    public GridCoord RandomAdjacent(GridCoord coord)
    {
        int dirX = 0;
        int dirY = 0;
        int dirZ = 0;

        do
        {
            dirX = Random.Range(-1, 2);
            dirY = Random.Range(-1, 2);
            dirZ = Random.Range(-1, 2);
        } while (dirX == 0 && dirY == 0 && dirZ == 0);

        return new GridCoord(coord.x + dirX, coord.y + dirY, coord.z + dirZ);
    }
Esempio n. 34
0
    public void Move(GridCoord start, GridCoord end)
    {
        if (start.Equals(end))
            return;

        var occupying = gridGOs[end.x, end.y, end.z];
        if (occupying != null)
            Destroy(occupying);

        gridGOs[start.x, start.y, start.z].transform.position = end.WorldPosition;
        gridGOs[end.x, end.y, end.z] = gridGOs[start.x, start.y, start.z];
        gridGOs[start.x, start.y, start.z] = null;

        grid[end.x, end.y, end.z] = grid[start.x, start.y, start.z];
        grid[start.x, start.y, start.z] = VoxelType.Empty;
    }
Esempio n. 35
0
 public void UpdateLight(GridCoord coord, float intensity)
 {
     try
     {
         for (int i = 0; i < 8; i++)
         {
             for (int j = 0; j < 8; j++)
             {
                 lightMap.SetPixel((coord.x + (m_width / 2)) * 8 + i, (coord.y + (m_height / 2)) * 8 + j, new Color(0, 0, 0, intensity));
             }
         }
         update = true;
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
     }
 }
Esempio n. 36
0
        public void UpdateLight(GridCoord coord)
        {
            Building building = BuildingManager.Inst.Get(coord);

            if (building != null)
            {
                UpdateLight(coord, 1);
                return;
            }

            Tile tile = TileManager.Inst.Get(coord);

            if (tile != null)
            {
                UpdateLight(coord, tile.m_health == 0 ? 0.5f : 1f);
                return;
            }

            UpdateLight(coord, 0);
        }
Esempio n. 37
0
    /// <summary>
    /// Adds the object. returns true if the object was added
    /// </summary>
    /// <returns>
    /// The object.
    /// </returns>
    /// <param name='x'>
    /// If set to <c>true</c> x.
    /// </param>
    /// <param name='y'>
    /// If set to <c>true</c> y.
    /// </param>
    /// <param name='newObject'>
    /// If set to <c>true</c> new object.
    /// </param>
    public bool AddObject(GridCoord location, GameObject newObject)
    {
        //sanity check
        if(OutOfBounds(location) || newObject == null)
            return false;

        if(grid[location.x,location.y].IsOccupied())
        {
            return false;
        }

        grid[location.x,location.y].occupier = newObject;

        //grid is dirty
        isDirty = true;

        //tell any observers that we've updated the view
        ObjectAdded(location, newObject);

        return true;
    }
Esempio n. 38
0
    public bool IsSurrounded(GridCoord location)
    {
        //sanity - out of bounds is 'surrounded'
        if(OutOfBounds(location))
            return true;

        return IsOccupied(location.x + 1, location.y ) &&
               IsOccupied(location.x - 1, location.y) &&
               IsOccupied(location.x, location.y + 1) &&
               IsOccupied(location.x, location.y - 1);
    }
Esempio n. 39
0
 public bool OutOfBounds(GridCoord location)
 {
     return 	location.x >= GetWidth() || location.y >= GetHeight()
         || location.x < 0 || location.y < 0;
 }
Esempio n. 40
0
    public bool IsOccupied(GridCoord location)
    {
        //sanity
        if(OutOfBounds(location))
            return true;

        try
        {
            return grid[location.x, location.y].IsOccupied();
        }
        catch
        {
            Debug.Log("failed looking for " + location);
            return true;
        }
    }
Esempio n. 41
0
 public bool IsOccupied(int x, int y)
 {
     //sanity
     GridCoord location = new GridCoord(x,y);
     return IsOccupied(location);
 }
Esempio n. 42
0
 public bool Equals(GridCoord other)
 {
     return other.x == x && other.y == y && other.z == z;
 }
Esempio n. 43
0
 public GridSpace GetGridSpace(GridCoord position)
 {
     return grid[position.x, position.y];
 }
Esempio n. 44
0
 public GridCoordDist(GridCoord coord, float dist)
 {
     this.coord = coord;
     this.distance = dist;
 }
Esempio n. 45
0
    void DeleteTile(Vector2 point)
    {
        GridCoord coord = new GridCoord((short)(Mathf.FloorToInt((point.x + 0.5f) / maker.m_tileSize) * maker.m_tileSize), (short)(Mathf.FloorToInt((point.y + 0.5f) / maker.m_tileSize) * maker.m_tileSize));

        maker.Remove(coord);
    }
Esempio n. 46
0
 public GridCoord ToChunkCoord(GridCoord coord)
 {
     return new GridCoord((short)(coord.x - Calc.mod(coord.x, m_chunkSize)), (short)(coord.y - Calc.mod(coord.y, m_chunkSize)));
 }
Esempio n. 47
0
    public TileChunk FindChunk(GridCoord coord)
    {
        GridCoord chunkCoord = ToChunkCoord(coord);
        if (m_chunks.ContainsKey(chunkCoord))
            return m_chunks[chunkCoord];

        return null;
    }
Esempio n. 48
0
 public void Remove(GridCoord coord)
 {
     if (m_tiles.ContainsKey(coord))
     {
         Tile tile = m_tiles[coord];
         m_tiles.Remove(coord);
         tile.RemoveForMaker();
     }
 }
Esempio n. 49
0
 public Tile GenTile(TileType type, GridCoord coord)
 {
     Tile tile = new Tile(tileID, m_tileTypeDic[type], coord, null);
     tileID++;
     return tile;
 }
Esempio n. 50
0
 public Tile GenBrushTile(GridCoord coord)
 {
     Tile tile = new Tile(tileID, m_brushTile, coord, null);
     tileID++;
     return tile;
 }
Esempio n. 51
0
    public void Set(GridCoord coord, VoxelType type)
    {
        var previousType = grid[coord.x, coord.y, coord.z];
        AdjustFillCount(previousType, type);

        grid[coord.x, coord.y, coord.z] = type;

        CreateVoxel(coord, type);
    }
Esempio n. 52
0
    public GridCoord FindRandomEmptyAdjacentSpace(GridCoord startSpace)
    {
        //we will never have more than 4 spaces so might as well not
        //use too much memory?
        List<GridCoord> eligibleSpaces = new List<GridCoord>(4);

        //get all the spaces we could possible have

        //north space
        GridCoord space = new GridCoord(startSpace.x, startSpace.y + 1);
        if(!OutOfBounds(space) && !IsOccupied(space))
        {
            eligibleSpaces.Add(space);
        }

        //east space
        space = new GridCoord(startSpace.x + 1, startSpace.y);
        if(!OutOfBounds(space) && !IsOccupied(space))
        {
            eligibleSpaces.Add(space);
        }

        //south space
        space = new GridCoord(startSpace.x, startSpace.y - 1);
        if(!OutOfBounds(space) && !IsOccupied(space))
        {
            eligibleSpaces.Add(space);
        }

        //west space
        space = new GridCoord(startSpace.x - 1, startSpace.y);
        if(!OutOfBounds(space) && !IsOccupied(space))
        {
            eligibleSpaces.Add(space);
        }

        //pick a random space
        int pickedSpace = UnityEngine.Random.Range(0, eligibleSpaces.Count - 1);

        return eligibleSpaces[pickedSpace];
    }
Esempio n. 53
0
    void CreateVoxel(GridCoord coord, VoxelType type)
    {
        var voxel = gridGOs[coord.x, coord.y, coord.z];

        if (voxel == null)
        {
            voxel = (GameObject)Instantiate(voxelGO, coord.WorldPosition, Quaternion.identity);
            gridGOs[coord.x, coord.y, coord.z] = voxel;
        }

        voxel.GetComponent<VoxelMaterialAdjuster>().SetType(type);

        if (type == VoxelType.Black)
        {
            var black = voxel.AddComponent<BlackVoxel>();
            black.Initialize(this, coord);
        }
    }
Esempio n. 54
0
 public VoxelType Get(GridCoord coord)
 {
     return grid[coord.x, coord.y, coord.z];
 }