Beispiel #1
0
        public QTreeNode getLeaf(int x, int y)
        {
            QTreeNode node = this;
            int       cx = x, cy = y;

            while (node != null)
            {
                if (node.isLeaf)
                {
                    return(node);
                }
                else
                {
                    int index = ((cx & 0xC000) >> 14) | ((cy & 0xC000) >> 12);
                    if (node.child[index] != null)
                    {
                        node = node.child[index];
                        cx <<= 2;
                        cy <<= 2;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        public void removeTile(int x, int y, int z)
        {
            QTreeNode leaf    = root.getLeafForce(x, y);
            Floor     floor   = leaf.createFloor(z);
            int       offsetX = x & 3;
            int       offsetY = y & 3;

            floor.tiles[offsetX * 4 + offsetY] = null;
        }
Beispiel #3
0
        public Tile getTile(int x, int y, int z)
        {
            QTreeNode leaf = root.getLeaf(x, y);

            if (leaf != null)
            {
                Floor floor = leaf.getFloor(z);
                if (floor != null)
                {
                    return(floor.tiles[(x & 3) * 4 + (y & 3)]);
                }
            }
            return(null);
        }
Beispiel #4
0
        public void setTile(int x, int y, int z, Tile newtile, bool remove = false)
        {
            QTreeNode leaf    = root.getLeafForce(x, y);
            Floor     floor   = leaf.createFloor(z);
            int       offsetX = x & 3;
            int       offsetY = y & 3;

            Tile tile = floor.tiles[offsetX * 4 + offsetY];

            if (newtile != null)
            {
                if (tile != null)
                {
                    newtile.stealExits(tile);
                    //newtile->spawn_count = tile->spawn_count;
                    //newtile->spawn = tile->spawn;
                }
                else
                {
                    tilecount++;
                }
            }
            else if (tile != null)
            {
                if ((tile.spawn_count != 0) || tile.isHouseExit())
                {
                    newtile = new Tile(x, y, z);
                    newtile.stealExits(tile);
                    newtile.spawn_count    = tile.spawn_count;
                    newtile.waypoint_count = tile.waypoint_count;
                    //newtile->spawn = tile->spawn;
                }
                else
                {
                    tilecount--;
                }
            }
            if (remove)
            {
                tile = null;
            }
            floor.tiles[offsetX * 4 + offsetY] = newtile;
        }
Beispiel #5
0
        public Tile swapTile(int x, int y, int z, Tile newtile)
        {
            QTreeNode leaf     = root.getLeafForce(x, y);
            Floor     floor    = leaf.createFloor(z);
            int       offset_x = x & 3;
            int       offset_y = y & 3;
            Tile      tile     = floor.tiles[offset_x * 4 + offset_y];

            if (newtile != null)
            {
                if (tile == null)
                {
                    ++tilecount;
                }
                else
                {
                    newtile.stealExits(tile);
                    newtile.spawn_count    = tile.spawn_count;
                    newtile.waypoint_count = tile.waypoint_count;
                    //newtile->spawn = tile->spawn;
                }
            }
            else if (tile != null)
            {
                if ((tile.spawn_count != 0) || tile.isHouseExit())
                {
                    newtile = new Tile(x, y, z);
                    newtile.stealExits(tile);
                    newtile.spawn_count    = tile.spawn_count;
                    newtile.waypoint_count = tile.waypoint_count;
                    //newtile->spawn = tile->spawn;
                }
                else
                {
                    --tilecount;
                }
            }
            Tile oldtile = tile;

            floor.tiles[offset_x * 4 + offset_y] = newtile;
            return(oldtile);
        }
Beispiel #6
0
        public QTreeNode getLeafForce(int x, int y)
        {
            QTreeNode node = this;
            int       cx = x, cy = y;
            int       level = 6;

            while (node != null)
            {
                int index = ((cx & 0xC000) >> 14) | ((cy & 0xC000) >> 12);

                QTreeNode qt = node.child[index];
                if (qt != null)
                {
                    if (qt.isLeaf)
                    {
                        return(qt);
                    }
                }
                else
                {
                    if (level == 0)
                    {
                        qt                = new QTreeNode();
                        qt.isLeaf         = true;
                        node.child[index] = qt;
                        return(qt);
                    }
                    else
                    {
                        qt = new QTreeNode();
                        node.child[index] = qt;
                    }
                }
                node   = node.child[index];
                cx   <<= 2;
                cy   <<= 2;
                level -= 1;
            }
            return(null);
        }
Beispiel #7
0
 public BaseMap()
 {
     tilecount = 0;
     root      = new QTreeNode();
 }