Пример #1
0
        public bool addShipToField(Ship _ship)
        {
            int   regionId = GeometryIndex.calcRegionId(_ship.posX, _ship.posY);
            Field field    = GeometryIndex.regions[regionId].findOrCreateField(_ship.posX, _ship.posY);

            SpacegameServer.Core.NodeQuadTree.Field shipField2 = new SpacegameServer.Core.NodeQuadTree.Field(_ship.posX, _ship.posY);
            nodeQuadTree.insertShip(shipField2, _ship);

            return(field.AddShip(_ship));
        }
Пример #2
0
        public bool insertShip(Field p, Ship ship)
        {
            // Ignore objects that do not belong in this quad tree
            if (!boundary.containsField(p))
            {
                return(false);
            }

            // If there is space in this quad tree, add the object here
            if (this.boundary.dimension == 1)
            {
                ships.Add(ship);
                return(true);
            }

            // Otherwise, subdivide and then add the point to whichever node will accept it
            if (northWest == null)
            {
                subdivide();
            }

            if (northWest.insertShip(p, ship))
            {
                return(true);
            }
            if (northEast.insertShip(p, ship))
            {
                return(true);
            }
            if (southWest.insertShip(p, ship))
            {
                return(true);
            }
            if (southEast.insertShip(p, ship))
            {
                return(true);
            }

            // Otherwise, the point cannot be inserted for some unknown reason (this should never happen)
            return(false);
        }