public override Leaf Remove(PhysicalObject obj)
        {
            if (this.Contains(this.GetObjPosition(obj)))
            {
                if (children.Count != 4)
                {
                    throw new Exception("child");
                }

                Leaf removedFrom = null;
                foreach (Node child in children)
                {
                    removedFrom = child.Remove(obj);
                    if (removedFrom != null)
                    {
                        break;
                    }
                }

                if (removedFrom != null)
                {
                    unitCount--;
                    return removedFrom;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
 public MemberPhysicalObject(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent)
     : base()
 {
     this.parent = parent;
     this.positionRelativeToParent = positionRelativeToParent;
     this.directionRelativeToParent = directionRelativeToParent;
     this.parent.Add(this);
 }
Beispiel #3
0
 public override Leaf Remove(PhysicalObject unit)
 {
     if (unitList.Contains(unit))
     {
         leafDictionary.SetLeaf(unit, null);
         unitList.Remove(unit);
         return this;
     }
     return null;
 }
Beispiel #4
0
 public bool Add(PhysicalObject unit)
 {
     if(root.Add(unit))
     {
         return true;
     }
     else
     {
         //throw new Exception("add failed");
         return false;
     }
 }
        public Leaf GetLeaf(PhysicalObject obj)
        {
            //this.Invariant();
            if (leafDictionary.ContainsKey(obj))
            {
                if (!leafDictionary[obj].Contains(obj))
                {
                    throw new Exception("Incorrect leaf");
                }

                return leafDictionary[obj];
            }
            throw new Exception("object does not have leaf");
        }
Beispiel #6
0
 public bool Remove(PhysicalObject unit)
 {
     Leaf removeFrom = root.Remove(unit);
     if (removeFrom != null)
     {
         removeFrom.Collapse();
         return true;
     }
     else
     {
         //throw new Exception("No object to remove");
         return false;
     }
 }
Beispiel #7
0
        public override bool Add(PhysicalObject unit)
        {
            if (this.Contains(this.GetObjPosition(unit)))
            {
                unitList.Add(unit);
                leafDictionary.SetLeaf(unit, this);

                if (ObjectCount() > max_count)
                {
                    this.Expand();
                }
                return true;
            }
            return false;
        }
 public void SetLeaf(PhysicalObject obj, Leaf leaf)
 {
     //this.Invariant();
     if (leaf != null)
     {
         if (!leafDictionary.ContainsKey(obj))
         {
             leafDictionary.Add(obj, leaf);
         }
         leafDictionary[obj] = leaf;
     }
     else
     {
         leafDictionary.Remove(obj);
     }
     //this.Invariant();
 }
        public override bool Add(PhysicalObject obj)
        {
            if (this.Contains(this.GetObjPosition(obj)))
            {
                foreach (Node child in new List<Node>(children))
                {
                    if (child.Add(obj))
                    {
                        unitCount++;
                        return true;
                    }
                }
                throw new Exception("failed adds to QuadTree");
            }
            if (Parent == null)
            {
                //throw new Exception("move out of bounds");
            }

            return false;
        }
Beispiel #10
0
 protected Vector2 GetObjPosition(PhysicalObject obj)
 {
     return positionFunc(obj);
 }
 public static Vector2 GetDrawPosition(PhysicalObject obj)
 {
     return obj.position.DrawValue;
 }
 public static void ServerInitialize(PhysicalObject obj, Vector2 position, float direction)
 {
     obj.position.Value = position;
     obj.direction.Value = direction;
 }
 public override void Move(PhysicalObject obj)
 {
     unitCount--;
     if (this.Contains(this.GetObjPosition(obj)))
     {
         this.Add(obj);
     }
     else
     {
         if (this.Parent != null)
         {
             this.Parent.Move(obj);
         }
         else
         {
             throw new Exception("move out of bounds");
         }
     }
 }
 public static Vector2 GetPreviousPosition(PhysicalObject obj)
 {
     return obj.position.PreviousValue;
 }
 public Boolean CollidesWith(PhysicalObject other)
 {
     return this.Collidable.CollidesWith(this.Position, this.Direction, other.Collidable, other.Position, other.Direction);
 }
Beispiel #16
0
 public Boolean Contains(PhysicalObject obj)
 {
     return this.unitList.Contains(obj);
 }
Beispiel #17
0
 public void Move(PhysicalObject obj)
 {
     leafDictionary.GetLeaf(obj).Move(obj);
 }
Beispiel #18
0
 public Turret(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent, float range)
     : base(parent, positionRelativeToParent, directionRelativeToParent)
 {
     this.range = range;
     gun = new Gun(this, new Vector2(50f, 0), 0);
 }
Beispiel #19
0
 public Gun(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent)
     : base(parent, positionRelativeToParent, directionRelativeToParent)
 {
 }
Beispiel #20
0
 public abstract bool Add(PhysicalObject unit);
Beispiel #21
0
 public abstract Leaf Remove(PhysicalObject unit);
Beispiel #22
0
 public abstract void Move(PhysicalObject obj);
Beispiel #23
0
 public override void Move(PhysicalObject obj)
 {
     if(unitList.Contains(obj))
     {
         if (!this.Contains(this.GetObjPosition(obj)))
         {
             this.Remove(obj);
             this.Parent.Move(obj);
             if (unitList.Contains(obj))
             {
                 throw new Exception("Move failed");
             }
             if (!this.Parent.IsChild(this))
             {
                 throw new Exception("incorrect child/parent");
             }
             this.Parent.Collapse();
         }
     }
     else
     {
         throw new Exception("No such object");
     }
 }
 public static Vector2 GetSimulationPosition(PhysicalObject obj)
 {
     return obj.position.SimulationValue;
 }