From 2889c2bdb48ee328c8e80dd124b827435001a4cd Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Sun, 5 Apr 2015 18:13:43 -0300 Subject: [PATCH] cleanup carrier and bomber robot --- .../ai/AIRobotCraftAssemblyTable.java | 2 +- .../robotics/ai/AIRobotCraftFurnace.java | 4 +- .../ai/AIRobotGotoStationAndLoad.java | 6 ++- .../buildcraft/robotics/ai/AIRobotLoad.java | 11 ++--- .../robotics/boards/BoardRobotBomber.java | 15 +++++-- .../robotics/boards/BoardRobotCarrier.java | 43 +++++-------------- .../robotics/boards/BoardRobotDelivery.java | 2 +- 7 files changed, 32 insertions(+), 51 deletions(-) diff --git a/common/buildcraft/robotics/ai/AIRobotCraftAssemblyTable.java b/common/buildcraft/robotics/ai/AIRobotCraftAssemblyTable.java index 8e8c51a1..3556709f 100755 --- a/common/buildcraft/robotics/ai/AIRobotCraftAssemblyTable.java +++ b/common/buildcraft/robotics/ai/AIRobotCraftAssemblyTable.java @@ -67,7 +67,7 @@ public class AIRobotCraftAssemblyTable extends AIRobotCraftGeneric { if (table != null) { if (!craftStarted) { if (requirements.size() != 0) { - startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqStackFilter(), robot.getZoneToWork())); + startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqStackFilter(), robot.getZoneToWork(), 1)); return; } diff --git a/common/buildcraft/robotics/ai/AIRobotCraftFurnace.java b/common/buildcraft/robotics/ai/AIRobotCraftFurnace.java index a1b51fd7..de41f24d 100755 --- a/common/buildcraft/robotics/ai/AIRobotCraftFurnace.java +++ b/common/buildcraft/robotics/ai/AIRobotCraftFurnace.java @@ -64,14 +64,14 @@ public class AIRobotCraftFurnace extends AIRobotCraftGeneric { if (furnace != null) { if (!craftStarted) { if (furnace.getStackInSlot(FUEL_SLOT) == null && InvUtils.getItem(robot, new FuelFilter()) == null) { - startDelegateAI(new AIRobotGotoStationAndLoad(robot, new FuelFilter(), robot.getZoneToWork())); + startDelegateAI(new AIRobotGotoStationAndLoad(robot, new FuelFilter(), robot.getZoneToWork(), 1)); return; } if (InvUtils.getItem(robot, new ArrayStackFilter(input)) == null) { startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ArrayStackFilter(input), - robot.getZoneToWork())); + robot.getZoneToWork(), 1)); return; } diff --git a/common/buildcraft/robotics/ai/AIRobotGotoStationAndLoad.java b/common/buildcraft/robotics/ai/AIRobotGotoStationAndLoad.java index 855b3ca1..91b2a8b3 100755 --- a/common/buildcraft/robotics/ai/AIRobotGotoStationAndLoad.java +++ b/common/buildcraft/robotics/ai/AIRobotGotoStationAndLoad.java @@ -17,16 +17,18 @@ public class AIRobotGotoStationAndLoad extends AIRobot { private IStackFilter filter; private IZone zone; + private int quantity; public AIRobotGotoStationAndLoad(EntityRobotBase iRobot) { super(iRobot); } - public AIRobotGotoStationAndLoad(EntityRobotBase iRobot, IStackFilter iFilter, IZone iZone) { + public AIRobotGotoStationAndLoad(EntityRobotBase iRobot, IStackFilter iFilter, IZone iZone, int iQuantity) { this(iRobot); filter = iFilter; zone = iZone; + quantity = iQuantity; } @Override @@ -38,7 +40,7 @@ public class AIRobotGotoStationAndLoad extends AIRobot { public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotGotoStationToLoad) { if (ai.success()) { - startDelegateAI(new AIRobotLoad(robot, filter, 1)); + startDelegateAI(new AIRobotLoad(robot, filter, quantity)); } else { setSuccess(false); terminate(); diff --git a/common/buildcraft/robotics/ai/AIRobotLoad.java b/common/buildcraft/robotics/ai/AIRobotLoad.java index b79476f3..013aa99a 100755 --- a/common/buildcraft/robotics/ai/AIRobotLoad.java +++ b/common/buildcraft/robotics/ai/AIRobotLoad.java @@ -25,20 +25,15 @@ import buildcraft.robotics.statements.ActionStationProvideItems; public class AIRobotLoad extends AIRobot { + public static final int ANY_QUANTITY = -1; private IStackFilter filter; - private int quantity = -1; + private int quantity; private int waitedCycles = 0; public AIRobotLoad(EntityRobotBase iRobot) { super(iRobot); } - public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) { - this(iRobot); - - filter = iFilter; - } - public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter, int iQuantity) { super(iRobot); @@ -86,7 +81,7 @@ public class AIRobotLoad extends AIRobot { ITransactor t = Transactor.getTransactorFor(robot); - if (quantity == -1) { + if (quantity == ANY_QUANTITY) { ItemStack added = t.add(slot.getStackInSlot(), ForgeDirection.UNKNOWN, true); slot.decreaseStackInSlot(added.stackSize); } else { diff --git a/common/buildcraft/robotics/boards/BoardRobotBomber.java b/common/buildcraft/robotics/boards/BoardRobotBomber.java index 9e54c2ec..0319ae53 100755 --- a/common/buildcraft/robotics/boards/BoardRobotBomber.java +++ b/common/buildcraft/robotics/boards/BoardRobotBomber.java @@ -23,7 +23,8 @@ import buildcraft.core.lib.inventory.filters.ArrayStackFilter; import buildcraft.core.lib.inventory.filters.IStackFilter; import buildcraft.core.lib.utils.IBlockFilter; import buildcraft.robotics.ai.AIRobotGotoBlock; -import buildcraft.robotics.ai.AIRobotGotoStationToLoad; +import buildcraft.robotics.ai.AIRobotGotoSleep; +import buildcraft.robotics.ai.AIRobotGotoStationAndLoad; import buildcraft.robotics.ai.AIRobotLoad; import buildcraft.robotics.ai.AIRobotSearchRandomGroundBlock; @@ -53,7 +54,7 @@ public class BoardRobotBomber extends RedstoneBoardRobot { } if (!containItems) { - startDelegateAI(new AIRobotGotoStationToLoad(robot, TNT_FILTER, null)); + startDelegateAI(new AIRobotGotoStationAndLoad(robot, TNT_FILTER, null, AIRobotLoad.ANY_QUANTITY)); } else { startDelegateAI(new AIRobotSearchRandomGroundBlock(robot, 100, new IBlockFilter() { @Override @@ -66,8 +67,10 @@ public class BoardRobotBomber extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { - if (ai instanceof AIRobotGotoStationToLoad) { - startDelegateAI(new AIRobotLoad(robot, TNT_FILTER)); + if (ai instanceof AIRobotGotoStationAndLoad) { + if (!ai.success()) { + startDelegateAI(new AIRobotGotoSleep(robot)); + } } else if (ai instanceof AIRobotSearchRandomGroundBlock) { if (ai.success()) { AIRobotSearchRandomGroundBlock aiFind = (AIRobotSearchRandomGroundBlock) ai; @@ -75,6 +78,8 @@ public class BoardRobotBomber extends RedstoneBoardRobot { startDelegateAI(new AIRobotGotoBlock(robot, aiFind.blockFound.x, aiFind.blockFound.y + flyingHeight, aiFind.blockFound.z)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); } } else if (ai instanceof AIRobotGotoBlock) { if (ai.success()) { @@ -90,6 +95,8 @@ public class BoardRobotBomber extends RedstoneBoardRobot { robot.worldObj.spawnEntityInWorld(tnt); robot.worldObj.playSoundAtEntity(tnt, "game.tnt.primed", 1.0F, 1.0F); } + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); } } } diff --git a/common/buildcraft/robotics/boards/BoardRobotCarrier.java b/common/buildcraft/robotics/boards/BoardRobotCarrier.java index 3b5e5908..d044d562 100755 --- a/common/buildcraft/robotics/boards/BoardRobotCarrier.java +++ b/common/buildcraft/robotics/boards/BoardRobotCarrier.java @@ -12,17 +12,15 @@ import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.EntityRobotBase; +import buildcraft.core.lib.inventory.filters.IStackFilter; import buildcraft.robotics.ai.AIRobotGotoSleep; +import buildcraft.robotics.ai.AIRobotGotoStationAndLoad; import buildcraft.robotics.ai.AIRobotGotoStationAndUnload; -import buildcraft.robotics.ai.AIRobotGotoStationToLoad; import buildcraft.robotics.ai.AIRobotLoad; import buildcraft.robotics.statements.ActionRobotFilter; public class BoardRobotCarrier extends RedstoneBoardRobot { - private boolean loadFound = true; - private boolean unloadFound = true; - public BoardRobotCarrier(EntityRobotBase iRobot) { super(iRobot); } @@ -35,8 +33,9 @@ public class BoardRobotCarrier extends RedstoneBoardRobot { @Override public void update() { if (!robot.containsItems()) { - startDelegateAI(new AIRobotGotoStationToLoad(robot, ActionRobotFilter.getGateFilter(robot - .getLinkedStation()), robot.getZoneToWork())); + IStackFilter filter = ActionRobotFilter.getGateFilter(robot.getLinkedStation()); + startDelegateAI(new AIRobotGotoStationAndLoad(robot, filter, robot.getZoneToWork(), + AIRobotLoad.ANY_QUANTITY)); } else { startDelegateAI(new AIRobotGotoStationAndUnload(robot, robot.getZoneToWork())); } @@ -44,36 +43,14 @@ public class BoardRobotCarrier extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { - if (ai instanceof AIRobotGotoStationToLoad) { - if (ai.success()) { - loadFound = true; - startDelegateAI(new AIRobotLoad(robot, ActionRobotFilter.getGateFilter(robot - .getLinkedStation()))); - } else { - loadFound = false; - - if (robot.containsItems()) { - startDelegateAI(new AIRobotGotoStationAndUnload(robot, robot.getZoneToWork())); - } else { - unloadFound = false; - } + if (ai instanceof AIRobotGotoStationAndLoad) { + if (!ai.success()) { + startDelegateAI(new AIRobotGotoSleep(robot)); } } else if (ai instanceof AIRobotGotoStationAndUnload) { - if (ai.success()) { - unloadFound = true; - } else { - unloadFound = false; - startDelegateAI(new AIRobotGotoStationToLoad(robot, ActionRobotFilter.getGateFilter(robot - .getLinkedStation()), robot.getZoneToWork())); + if (!ai.success()) { + startDelegateAI(new AIRobotGotoSleep(robot)); } } - - 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/robotics/boards/BoardRobotDelivery.java b/common/buildcraft/robotics/boards/BoardRobotDelivery.java index a0980f0a..cedc4e9e 100755 --- a/common/buildcraft/robotics/boards/BoardRobotDelivery.java +++ b/common/buildcraft/robotics/boards/BoardRobotDelivery.java @@ -53,7 +53,7 @@ public class BoardRobotDelivery extends RedstoneBoardRobot { startDelegateAI(new AIRobotSearchStackRequest(robot, ActionRobotFilter.getGateFilter(robot .getLinkedStation()), deliveryBlacklist)); } else { - startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqFilter(), robot.getZoneToWork())); + startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqFilter(), robot.getZoneToWork(), 1)); } }