diff --git a/common/buildcraft/core/robots/AIRobotAttack.java b/common/buildcraft/core/robots/AIRobotAttack.java index 5d0bf63b77..0bca6b59d4 100755 --- a/common/buildcraft/core/robots/AIRobotAttack.java +++ b/common/buildcraft/core/robots/AIRobotAttack.java @@ -26,10 +26,13 @@ public AIRobotAttack(EntityRobotBase iRobot, EntityMob iTarget) { } @Override - public void start() { - robot.setItemActive(true); - robot.aimItemAt((int) Math.floor(target.posX), (int) Math.floor(target.posY), - (int) Math.floor(target.posZ)); + public void preempt(AIRobot ai) { + if (ai instanceof AIRobotGotoBlock) { + if (robot.getDistanceToEntity(target) <= 2.0) { + abortDelegateAI(); + robot.setItemActive(true); + } + } } @Override @@ -40,7 +43,11 @@ public void update() { } if (robot.getDistanceToEntity(target) > 2.0) { - terminate(); + startDelegateAI(new AIRobotGotoBlock(robot, (int) Math.floor(target.posX), + (int) Math.floor(target.posY), (int) Math.floor(target.posZ))); + robot.setItemActive(false); + + return; } delay++; @@ -57,4 +64,17 @@ public void update() { public void end() { robot.setItemActive(false); } + + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotGotoBlock) { + AIRobotGotoBlock aiGoto = (AIRobotGotoBlock) ai; + + if (((AIRobotGotoBlock) ai).unreachable) { + robot.unreachableEntityDetected(target); + } + + terminate(); + } + } } diff --git a/common/buildcraft/core/robots/AIRobotGotoMob.java b/common/buildcraft/core/robots/AIRobotFindMob.java similarity index 70% rename from common/buildcraft/core/robots/AIRobotGotoMob.java rename to common/buildcraft/core/robots/AIRobotFindMob.java index 7f7920a554..c5f7ee6282 100755 --- a/common/buildcraft/core/robots/AIRobotGotoMob.java +++ b/common/buildcraft/core/robots/AIRobotFindMob.java @@ -16,14 +16,14 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.TransactorSimple; -public class AIRobotGotoMob extends AIRobot { +public class AIRobotFindMob extends AIRobot { public EntityMob target; private float maxRange; private IBox box; - public AIRobotGotoMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) { + public AIRobotFindMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) { super(iRobot, 0); maxRange = iMaxRange; @@ -40,7 +40,8 @@ public void start() { if (!e.isDead && e instanceof EntityMob - && (box == null || box.contains(e.posX, e.posY, e.posZ))) { + && (box == null || box.contains(e.posX, e.posY, e.posZ)) + && (!robot.isKnownUnreachable(e))) { double dx = e.posX - robot.posX; double dy = e.posY - robot.posY; double dz = e.posZ - robot.posZ; @@ -64,30 +65,6 @@ public void start() { } } - if (target != null) { - startDelegateAI(new AIRobotGotoBlock(robot, (int) Math.floor(target.posX), - (int) Math.floor(target.posY), (int) Math.floor(target.posZ))); - - } else { - // No mob was found, terminate this AI - terminate(); - } - } - - @Override - public void preempt(AIRobot ai) { - if (target.isDead) { - terminate(); - } - } - - @Override - public void update() { - if (target.isDead) { - terminate(); - } else { - // fight - terminate(); - } + terminate(); } } diff --git a/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java b/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java index 4878f9abf1..e2e1f3d5bd 100755 --- a/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java +++ b/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java @@ -57,7 +57,7 @@ private class StationFilter implements IStationFilter { @Override public boolean matches(DockingStation station) { - boolean found = false; + boolean actionFound = false; Pipe pipe = station.pipe.pipe; @@ -66,13 +66,13 @@ public boolean matches(DockingStation station) { StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters); if (!param.hasFilter() || param.matches(filter)) { - found = true; + actionFound = true; break; } } } - if (!found) { + if (!actionFound) { return false; } diff --git a/common/buildcraft/core/robots/boards/BoardRobotKnight.java b/common/buildcraft/core/robots/boards/BoardRobotKnight.java index 6336df294c..8d88e0e36b 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotKnight.java +++ b/common/buildcraft/core/robots/boards/BoardRobotKnight.java @@ -18,7 +18,8 @@ import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.robots.AIRobotAttack; import buildcraft.core.robots.AIRobotFetchAndEquipItemStack; -import buildcraft.core.robots.AIRobotGotoMob; +import buildcraft.core.robots.AIRobotFindMob; +import buildcraft.core.robots.AIRobotGotoSleep; public class BoardRobotKnight extends RedstoneBoardRobot { @@ -31,17 +32,6 @@ public RedstoneBoardRobotNBT getNBTHandler() { return BoardRobotKnightNBT.instance; } - @Override - public void preempt(AIRobot ai) { - if (ai instanceof AIRobotGotoMob) { - AIRobotGotoMob mobAI = (AIRobotGotoMob) ai; - - if (robot.getDistanceToEntity(mobAI.target) < 2.0) { - startDelegateAI(new AIRobotAttack(robot, mobAI.target)); - } - } - } - @Override public final void update() { if (robot.getItemInUse() == null) { @@ -52,7 +42,24 @@ public boolean matches(ItemStack stack) { } })); } else { - startDelegateAI(new AIRobotGotoMob(robot, 250, robot.getAreaToWork())); + startDelegateAI(new AIRobotFindMob(robot, 250, robot.getAreaToWork())); + } + } + + @Override + public void delegateAIEnded(AIRobot ai) { + if (ai instanceof AIRobotFetchAndEquipItemStack) { + if (robot.getItemInUse() == null) { + startDelegateAI(new AIRobotGotoSleep(robot)); + } + } else if (ai instanceof AIRobotFindMob) { + AIRobotFindMob mobAI = (AIRobotFindMob) ai; + + if (mobAI.target != null) { + startDelegateAI(new AIRobotAttack(robot, ((AIRobotFindMob) ai).target)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); + } } }