From 487b0cc7e60a500f67ecbb1d2192d2308f2d9a3d Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sun, 29 Jun 2014 12:34:09 +0200 Subject: [PATCH] fixed knight robot --- .../buildcraft/core/robots/AIRobotAttack.java | 30 ++++++++++++++--- ...IRobotGotoMob.java => AIRobotFindMob.java} | 33 +++---------------- .../core/robots/AIRobotGotoStationToLoad.java | 6 ++-- .../core/robots/boards/BoardRobotKnight.java | 33 +++++++++++-------- 4 files changed, 53 insertions(+), 49 deletions(-) rename common/buildcraft/core/robots/{AIRobotGotoMob.java => AIRobotFindMob.java} (70%) diff --git a/common/buildcraft/core/robots/AIRobotAttack.java b/common/buildcraft/core/robots/AIRobotAttack.java index 5d0bf63b..0bca6b59 100755 --- a/common/buildcraft/core/robots/AIRobotAttack.java +++ b/common/buildcraft/core/robots/AIRobotAttack.java @@ -26,10 +26,13 @@ public class AIRobotAttack extends AIRobot { } @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 class AIRobotAttack extends AIRobot { } 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 class AIRobotAttack extends AIRobot { 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 7f7920a5..c5f7ee62 100755 --- a/common/buildcraft/core/robots/AIRobotGotoMob.java +++ b/common/buildcraft/core/robots/AIRobotFindMob.java @@ -16,14 +16,14 @@ import buildcraft.api.robots.AIRobot; 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 class AIRobotGotoMob extends AIRobot { 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 class AIRobotGotoMob extends AIRobot { } } - 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 4878f9ab..e2e1f3d5 100755 --- a/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java +++ b/common/buildcraft/core/robots/AIRobotGotoStationToLoad.java @@ -57,7 +57,7 @@ public class AIRobotGotoStationToLoad extends AIRobot { @Override public boolean matches(DockingStation station) { - boolean found = false; + boolean actionFound = false; Pipe pipe = station.pipe.pipe; @@ -66,13 +66,13 @@ public class AIRobotGotoStationToLoad extends AIRobot { 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 6336df29..8d88e0e3 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotKnight.java +++ b/common/buildcraft/core/robots/boards/BoardRobotKnight.java @@ -18,7 +18,8 @@ import buildcraft.api.robots.EntityRobotBase; 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 class BoardRobotKnight extends RedstoneBoardRobot { 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 class BoardRobotKnight extends RedstoneBoardRobot { } })); } 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)); + } } }