fixed knight robot

This commit is contained in:
SpaceToad 2014-06-29 12:34:09 +02:00
parent 99309b381a
commit 487b0cc7e6
4 changed files with 53 additions and 49 deletions

View file

@ -26,10 +26,13 @@ public class AIRobotAttack extends AIRobot {
} }
@Override @Override
public void start() { public void preempt(AIRobot ai) {
robot.setItemActive(true); if (ai instanceof AIRobotGotoBlock) {
robot.aimItemAt((int) Math.floor(target.posX), (int) Math.floor(target.posY), if (robot.getDistanceToEntity(target) <= 2.0) {
(int) Math.floor(target.posZ)); abortDelegateAI();
robot.setItemActive(true);
}
}
} }
@Override @Override
@ -40,7 +43,11 @@ public class AIRobotAttack extends AIRobot {
} }
if (robot.getDistanceToEntity(target) > 2.0) { 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++; delay++;
@ -57,4 +64,17 @@ public class AIRobotAttack extends AIRobot {
public void end() { public void end() {
robot.setItemActive(false); 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();
}
}
} }

View file

@ -16,14 +16,14 @@ import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.TransactorSimple; import buildcraft.core.inventory.TransactorSimple;
public class AIRobotGotoMob extends AIRobot { public class AIRobotFindMob extends AIRobot {
public EntityMob target; public EntityMob target;
private float maxRange; private float maxRange;
private IBox box; private IBox box;
public AIRobotGotoMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) { public AIRobotFindMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) {
super(iRobot, 0); super(iRobot, 0);
maxRange = iMaxRange; maxRange = iMaxRange;
@ -40,7 +40,8 @@ public class AIRobotGotoMob extends AIRobot {
if (!e.isDead if (!e.isDead
&& e instanceof EntityMob && 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 dx = e.posX - robot.posX;
double dy = e.posY - robot.posY; double dy = e.posY - robot.posY;
double dz = e.posZ - robot.posZ; double dz = e.posZ - robot.posZ;
@ -64,30 +65,6 @@ public class AIRobotGotoMob extends AIRobot {
} }
} }
if (target != null) { terminate();
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();
}
} }
} }

View file

@ -57,7 +57,7 @@ public class AIRobotGotoStationToLoad extends AIRobot {
@Override @Override
public boolean matches(DockingStation station) { public boolean matches(DockingStation station) {
boolean found = false; boolean actionFound = false;
Pipe pipe = station.pipe.pipe; Pipe pipe = station.pipe.pipe;
@ -66,13 +66,13 @@ public class AIRobotGotoStationToLoad extends AIRobot {
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters); StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);
if (!param.hasFilter() || param.matches(filter)) { if (!param.hasFilter() || param.matches(filter)) {
found = true; actionFound = true;
break; break;
} }
} }
} }
if (!found) { if (!actionFound) {
return false; return false;
} }

View file

@ -18,7 +18,8 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.robots.AIRobotAttack; import buildcraft.core.robots.AIRobotAttack;
import buildcraft.core.robots.AIRobotFetchAndEquipItemStack; 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 { public class BoardRobotKnight extends RedstoneBoardRobot {
@ -31,17 +32,6 @@ public class BoardRobotKnight extends RedstoneBoardRobot {
return BoardRobotKnightNBT.instance; 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 @Override
public final void update() { public final void update() {
if (robot.getItemInUse() == null) { if (robot.getItemInUse() == null) {
@ -52,7 +42,24 @@ public class BoardRobotKnight extends RedstoneBoardRobot {
} }
})); }));
} else { } 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));
}
} }
} }