add ShipPool.setParent()
authorAdam Megacz <adam@megacz.com>
Mon, 27 Jul 2009 03:23:13 +0000 (20:23 -0700)
committerAdam Megacz <adam@megacz.com>
Mon, 27 Jul 2009 03:23:13 +0000 (20:23 -0700)
src/edu/berkeley/fleet/loops/ShipPool.java

index f120139..1d35e1d 100644 (file)
@@ -63,4 +63,17 @@ public class ShipPool implements Iterable<Ship> {
         for (Ship ship : toRelease)
             releaseShip(ship);
     }
+
+    public void setParent(ShipPool parent) {
+        if (this.parent!=null) {
+            for (Ship ship : allocatedShips)
+                this.parent.releaseShip(ship);
+            this.parent = null;
+        }
+        if (parent != null) {
+            for (Ship ship : allocatedShips)
+                parent.allocateShip(ship);
+        }
+        this.parent = parent;
+    }
 }