diff --git a/api/buildcraft/api/boards/RedstoneBoardRobot.java b/api/buildcraft/api/boards/RedstoneBoardRobot.java index c6e86bdf..406f293b 100755 --- a/api/buildcraft/api/boards/RedstoneBoardRobot.java +++ b/api/buildcraft/api/boards/RedstoneBoardRobot.java @@ -27,7 +27,6 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa @Override public final void updateBoard(EntityRobotBase container) { - // TODO Auto-generated method stub } diff --git a/common/buildcraft/core/robots/AIRobotFindRandomGroundBlock.java b/common/buildcraft/core/robots/AIRobotFindRandomGroundBlock.java index 175f05e5..881b2406 100755 --- a/common/buildcraft/core/robots/AIRobotFindRandomGroundBlock.java +++ b/common/buildcraft/core/robots/AIRobotFindRandomGroundBlock.java @@ -26,7 +26,7 @@ public class AIRobotFindRandomGroundBlock extends AIRobot { private int attempts = 0; public AIRobotFindRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) { - super(iRobot, 2); + super(iRobot, 0); range = iRange; filter = iFilter; diff --git a/common/buildcraft/core/robots/AIRobotGotoRandomGroundBlock.java b/common/buildcraft/core/robots/AIRobotGotoRandomGroundBlock.java index b441d19b..2e14645b 100755 --- a/common/buildcraft/core/robots/AIRobotGotoRandomGroundBlock.java +++ b/common/buildcraft/core/robots/AIRobotGotoRandomGroundBlock.java @@ -28,7 +28,7 @@ public class AIRobotGotoRandomGroundBlock extends AIRobot { private IBox area; public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) { - super(iRobot, 2); + super(iRobot, 0); range = iRange; filter = iFilter; diff --git a/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java b/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java index 89ff2a18..4878f9ab 100755 --- a/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java +++ b/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java @@ -27,6 +27,8 @@ import buildcraft.transport.gates.ActionSlot; public class AIRobotGotoStationToLoad extends AIRobot { + public boolean found = false; + private IStackFilter filter; private IBox box; @@ -39,12 +41,16 @@ public class AIRobotGotoStationToLoad extends AIRobot { @Override public void update() { - startDelegateAI(new AIRobotLookForStation(robot, new StationFilter(), box)); + startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), box)); } @Override public void delegateAIEnded(AIRobot ai) { - terminate(); + if (ai instanceof AIRobotSearchAndGotoStation) { + found = ((AIRobotSearchAndGotoStation) ai).targetStation != null; + + terminate(); + } } private class StationFilter implements IStationFilter { diff --git a/common/buildcraft/core/robots/AIRobotGotoStationToUnload.java b/common/buildcraft/core/robots/AIRobotGotoStationToUnload.java index e4aad71a..d13a76b9 100755 --- a/common/buildcraft/core/robots/AIRobotGotoStationToUnload.java +++ b/common/buildcraft/core/robots/AIRobotGotoStationToUnload.java @@ -22,6 +22,8 @@ import buildcraft.transport.gates.ActionSlot; public class AIRobotGotoStationToUnload extends AIRobot { + public boolean found = false; + private IBox box; public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IBox iBox) { @@ -33,12 +35,16 @@ public class AIRobotGotoStationToUnload extends AIRobot { @Override public void start() { - startDelegateAI(new AIRobotLookForStation(robot, new StationInventory(), box)); + startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationInventory(), box)); } @Override public void delegateAIEnded(AIRobot ai) { - terminate(); + if (ai instanceof AIRobotSearchAndGotoStation) { + found = ((AIRobotSearchAndGotoStation) ai).targetStation != null; + + terminate(); + } } private class StationInventory implements IStationFilter { diff --git a/common/buildcraft/core/robots/AIRobotLoad.java b/common/buildcraft/core/robots/AIRobotLoad.java index b66859e0..0dc68ce9 100755 --- a/common/buildcraft/core/robots/AIRobotLoad.java +++ b/common/buildcraft/core/robots/AIRobotLoad.java @@ -32,7 +32,7 @@ public class AIRobotLoad extends AIRobot { private int waitedCycles = 0; public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) { - super(iRobot, 0); + super(iRobot, 2); filter = iFilter; } diff --git a/common/buildcraft/core/robots/AIRobotRecharge.java b/common/buildcraft/core/robots/AIRobotRecharge.java index 626c1f62..a20e324b 100755 --- a/common/buildcraft/core/robots/AIRobotRecharge.java +++ b/common/buildcraft/core/robots/AIRobotRecharge.java @@ -23,7 +23,7 @@ public class AIRobotRecharge extends AIRobot { @Override public void start() { - startDelegateAI(new AIRobotLookForStation(robot, new IStationFilter() { + startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() { @Override public boolean matches(DockingStation station) { return station.pipe.getPipeType() == PipeType.POWER; @@ -46,7 +46,7 @@ public class AIRobotRecharge extends AIRobot { @Override public void delegateAIEnded(AIRobot ai) { - if (ai instanceof AIRobotLookForStation) { + if (ai instanceof AIRobotSearchAndGotoStation) { if (robot.getDockingStation() == null || !(((DockingStation) robot.getDockingStation()).pipe.pipe.transport instanceof PipeTransportPower)) { terminate(); diff --git a/common/buildcraft/core/robots/AIRobotLookForStation.java b/common/buildcraft/core/robots/AIRobotSearchAndGotoStation.java similarity index 92% rename from common/buildcraft/core/robots/AIRobotLookForStation.java rename to common/buildcraft/core/robots/AIRobotSearchAndGotoStation.java index 54bb2549..8f849f30 100755 --- a/common/buildcraft/core/robots/AIRobotLookForStation.java +++ b/common/buildcraft/core/robots/AIRobotSearchAndGotoStation.java @@ -15,13 +15,13 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.IDockingStation; import buildcraft.silicon.statements.ActionStationForbidRobot; -public class AIRobotLookForStation extends AIRobot { +public class AIRobotSearchAndGotoStation extends AIRobot { public DockingStation targetStation; private IStationFilter filter; private IBox box; - public AIRobotLookForStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) { + public AIRobotSearchAndGotoStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) { super(iRobot, 0); filter = iFilter; diff --git a/common/buildcraft/core/robots/AIRobotSearchBlock.java b/common/buildcraft/core/robots/AIRobotSearchBlock.java index 4bab7702..4bad2ceb 100755 --- a/common/buildcraft/core/robots/AIRobotSearchBlock.java +++ b/common/buildcraft/core/robots/AIRobotSearchBlock.java @@ -25,7 +25,7 @@ public class AIRobotSearchBlock extends AIRobot { private IPathFound pathFound; public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) { - super(iRobot, 2); + super(iRobot, 0); pathFound = iPathFound; } diff --git a/common/buildcraft/core/robots/AIRobotUnload.java b/common/buildcraft/core/robots/AIRobotUnload.java index be4d20f7..47f948e1 100755 --- a/common/buildcraft/core/robots/AIRobotUnload.java +++ b/common/buildcraft/core/robots/AIRobotUnload.java @@ -24,7 +24,7 @@ public class AIRobotUnload extends AIRobot { private int waitedCycles = 0; public AIRobotUnload(EntityRobotBase iRobot) { - super(iRobot, 0); + super(iRobot, 2); } @Override diff --git a/common/buildcraft/core/robots/boards/BoardRobotCarrier.java b/common/buildcraft/core/robots/boards/BoardRobotCarrier.java index d0d76b52..385f67b6 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotCarrier.java +++ b/common/buildcraft/core/robots/boards/BoardRobotCarrier.java @@ -13,6 +13,7 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.filters.PassThroughStackFilter; +import buildcraft.core.robots.AIRobotGotoSleep; import buildcraft.core.robots.AIRobotGotoStationToLoad; import buildcraft.core.robots.AIRobotGotoStationToUnload; import buildcraft.core.robots.AIRobotLoad; @@ -20,6 +21,9 @@ import buildcraft.core.robots.AIRobotUnload; public class BoardRobotCarrier extends RedstoneBoardRobot { + private boolean loadFound = true; + private boolean unloadFound = true; + public BoardRobotCarrier(EntityRobotBase iRobot) { super(iRobot); } @@ -41,9 +45,34 @@ public class BoardRobotCarrier extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotGotoStationToLoad) { - startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter())); + if (((AIRobotGotoStationToLoad) ai).found) { + loadFound = true; + startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter())); + } else { + loadFound = false; + + if (robot.containsItems()) { + startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getAreaToWork())); + } else { + unloadFound = false; + } + } } else if (ai instanceof AIRobotGotoStationToUnload) { - startDelegateAI(new AIRobotUnload(robot)); + if (((AIRobotGotoStationToUnload) ai).found) { + unloadFound = true; + startDelegateAI(new AIRobotUnload(robot)); + } else { + unloadFound = false; + startDelegateAI(new AIRobotGotoStationToLoad(robot, new PassThroughStackFilter(), robot.getAreaToWork())); + } + } + + if (!loadFound && !unloadFound) { + startDelegateAI(new AIRobotGotoSleep(robot)); + + // reset load and unload so that upon waking up both are tried. + loadFound = true; + unloadFound = true; } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotPicker.java b/common/buildcraft/core/robots/boards/BoardRobotPicker.java index ab8625cb..7de91b1b 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPicker.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPicker.java @@ -25,7 +25,6 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.filters.ArrayStackFilter; import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.robots.AIRobotFetchItem; -import buildcraft.core.robots.AIRobotGotoDock; import buildcraft.core.robots.AIRobotGotoSleep; import buildcraft.core.robots.AIRobotGotoStationToUnload; import buildcraft.core.robots.AIRobotSleep; @@ -74,19 +73,15 @@ public class BoardRobotPicker extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotFetchItem) { - if (((AIRobotFetchItem) ai).noItemPicked) { - startDelegateAI(new AIRobotGotoDock(robot, (DockingStation) robot.getLinkedStation())); - } else if (((AIRobotFetchItem) ai).target != null) { + AIRobotFetchItem fetching = (AIRobotFetchItem) ai; + + if (!fetching.noItemPicked && fetching.target != null) { // if we could get an item, let's try to get another one startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter, robot.getAreaToWork())); + } else if (robot.containsItems()) { + startDelegateAI(new AIRobotGotoStationToUnload(robot, null)); } else { - // otherwise, let's deliver items if any - - if (robot.containsItems()) { - startDelegateAI(new AIRobotGotoStationToUnload(robot, null)); - } else { - startDelegateAI(new AIRobotGotoSleep(robot)); - } + startDelegateAI(new AIRobotGotoSleep(robot)); } } else if (ai instanceof AIRobotGotoStationToUnload) { DockingStation station = (DockingStation) robot.getDockingStation();