InterpreterShip: fix bug that caused ships with no input docks to not be serviced
[fleet.git] / src / edu / berkeley / fleet / interpreter / InterpreterShip.java
index 7f6397c..811c02b 100644 (file)
@@ -33,20 +33,24 @@ abstract class InterpreterShip extends FleetTwoShip {
         // flushing logic (must come between dock servicing and subclass)
         boolean someflushing = false;
         boolean allflushing = true;
+        boolean someempty = false;
         for(InterpreterDock d : docks.values()) {
             if (!d.isInputDock()) continue;
             if (d.flushing) someflushing = true;
             else allflushing = false;
+            if (!d.flushing && !d.dataReadyForShip) someempty = true;
         }
-        if (allflushing) {
+        if (allflushing && someflushing) {
             for(InterpreterDock d : docks.values())
                 if (d.isInputDock())
                     d.flushing = false;
             return;
-        } else if (someflushing) {
+        } else if (someflushing && !someempty) {
             for(InterpreterDock d : docks.values())
-                if (d.isInputDock() && !d.flushing && d.dataReadyForShip)
+                if (d.isInputDock() && !d.flushing && d.dataReadyForShip) {
+                    System.out.println("FLUSH AT " + this);
                     d.dataReadyForShip = false;
+                }
         }
 
         // now pass control to the subclass