cleanup carrier and bomber robot

This commit is contained in:
Hea3veN 2015-04-05 18:13:43 -03:00
parent 63472e04f2
commit 2889c2bdb4
7 changed files with 32 additions and 51 deletions

View file

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

View file

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

View file

@ -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();

View file

@ -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 {

View file

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

View file

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

View file

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