Skip to content

Commit

Permalink
fixed knight robot
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceToad committed Jun 29, 2014
1 parent 99309b3 commit 487b0cc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 49 deletions.
30 changes: 25 additions & 5 deletions common/buildcraft/core/robots/AIRobotAttack.java
Expand Up @@ -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
Expand All @@ -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++;
Expand All @@ -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();
}
}
}
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}
}
6 changes: 3 additions & 3 deletions common/buildcraft/core/robots/AIRobotGotoStationToLoad.java
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
33 changes: 20 additions & 13 deletions common/buildcraft/core/robots/boards/BoardRobotKnight.java
Expand Up @@ -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 {

Expand All @@ -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) {
Expand All @@ -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));
}
}
}

Expand Down

0 comments on commit 487b0cc

Please sign in to comment.