improved carrier robot behavior and adjusted energy consumption

This commit is contained in:
SpaceToad 2014-06-29 11:55:19 +02:00
parent d38ab37cc0
commit 99309b381a
12 changed files with 62 additions and 27 deletions

View file

@ -27,7 +27,6 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa
@Override
public final void updateBoard(EntityRobotBase container) {
// TODO Auto-generated method stub
}

View file

@ -26,7 +26,7 @@ public class AIRobotFindRandomGroundBlock extends AIRobot {
private int attempts = 0;
public AIRobotFindRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
super(iRobot, 2);
super(iRobot, 0);
range = iRange;
filter = iFilter;

View file

@ -28,7 +28,7 @@ public class AIRobotGotoRandomGroundBlock extends AIRobot {
private IBox area;
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
super(iRobot, 2);
super(iRobot, 0);
range = iRange;
filter = iFilter;

View file

@ -27,6 +27,8 @@ import buildcraft.transport.gates.ActionSlot;
public class AIRobotGotoStationToLoad extends AIRobot {
public boolean found = false;
private IStackFilter filter;
private IBox box;
@ -39,12 +41,16 @@ public class AIRobotGotoStationToLoad extends AIRobot {
@Override
public void update() {
startDelegateAI(new AIRobotLookForStation(robot, new StationFilter(), box));
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), box));
}
@Override
public void delegateAIEnded(AIRobot ai) {
terminate();
if (ai instanceof AIRobotSearchAndGotoStation) {
found = ((AIRobotSearchAndGotoStation) ai).targetStation != null;
terminate();
}
}
private class StationFilter implements IStationFilter {

View file

@ -22,6 +22,8 @@ import buildcraft.transport.gates.ActionSlot;
public class AIRobotGotoStationToUnload extends AIRobot {
public boolean found = false;
private IBox box;
public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IBox iBox) {
@ -33,12 +35,16 @@ public class AIRobotGotoStationToUnload extends AIRobot {
@Override
public void start() {
startDelegateAI(new AIRobotLookForStation(robot, new StationInventory(), box));
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationInventory(), box));
}
@Override
public void delegateAIEnded(AIRobot ai) {
terminate();
if (ai instanceof AIRobotSearchAndGotoStation) {
found = ((AIRobotSearchAndGotoStation) ai).targetStation != null;
terminate();
}
}
private class StationInventory implements IStationFilter {

View file

@ -32,7 +32,7 @@ public class AIRobotLoad extends AIRobot {
private int waitedCycles = 0;
public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
super(iRobot, 0);
super(iRobot, 2);
filter = iFilter;
}

View file

@ -23,7 +23,7 @@ public class AIRobotRecharge extends AIRobot {
@Override
public void start() {
startDelegateAI(new AIRobotLookForStation(robot, new IStationFilter() {
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() {
@Override
public boolean matches(DockingStation station) {
return station.pipe.getPipeType() == PipeType.POWER;
@ -46,7 +46,7 @@ public class AIRobotRecharge extends AIRobot {
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotLookForStation) {
if (ai instanceof AIRobotSearchAndGotoStation) {
if (robot.getDockingStation() == null
|| !(((DockingStation) robot.getDockingStation()).pipe.pipe.transport instanceof PipeTransportPower)) {
terminate();

View file

@ -15,13 +15,13 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IDockingStation;
import buildcraft.silicon.statements.ActionStationForbidRobot;
public class AIRobotLookForStation extends AIRobot {
public class AIRobotSearchAndGotoStation extends AIRobot {
public DockingStation targetStation;
private IStationFilter filter;
private IBox box;
public AIRobotLookForStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) {
public AIRobotSearchAndGotoStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) {
super(iRobot, 0);
filter = iFilter;

View file

@ -25,7 +25,7 @@ public class AIRobotSearchBlock extends AIRobot {
private IPathFound pathFound;
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
super(iRobot, 2);
super(iRobot, 0);
pathFound = iPathFound;
}

View file

@ -24,7 +24,7 @@ public class AIRobotUnload extends AIRobot {
private int waitedCycles = 0;
public AIRobotUnload(EntityRobotBase iRobot) {
super(iRobot, 0);
super(iRobot, 2);
}
@Override

View file

@ -13,6 +13,7 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.filters.PassThroughStackFilter;
import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotGotoStationToLoad;
import buildcraft.core.robots.AIRobotGotoStationToUnload;
import buildcraft.core.robots.AIRobotLoad;
@ -20,6 +21,9 @@ import buildcraft.core.robots.AIRobotUnload;
public class BoardRobotCarrier extends RedstoneBoardRobot {
private boolean loadFound = true;
private boolean unloadFound = true;
public BoardRobotCarrier(EntityRobotBase iRobot) {
super(iRobot);
}
@ -41,9 +45,34 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoStationToLoad) {
startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter()));
if (((AIRobotGotoStationToLoad) ai).found) {
loadFound = true;
startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter()));
} else {
loadFound = false;
if (robot.containsItems()) {
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getAreaToWork()));
} else {
unloadFound = false;
}
}
} else if (ai instanceof AIRobotGotoStationToUnload) {
startDelegateAI(new AIRobotUnload(robot));
if (((AIRobotGotoStationToUnload) ai).found) {
unloadFound = true;
startDelegateAI(new AIRobotUnload(robot));
} else {
unloadFound = false;
startDelegateAI(new AIRobotGotoStationToLoad(robot, new PassThroughStackFilter(), robot.getAreaToWork()));
}
}
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

@ -25,7 +25,6 @@ import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.robots.AIRobotFetchItem;
import buildcraft.core.robots.AIRobotGotoDock;
import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotGotoStationToUnload;
import buildcraft.core.robots.AIRobotSleep;
@ -74,19 +73,15 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotFetchItem) {
if (((AIRobotFetchItem) ai).noItemPicked) {
startDelegateAI(new AIRobotGotoDock(robot, (DockingStation) robot.getLinkedStation()));
} else if (((AIRobotFetchItem) ai).target != null) {
AIRobotFetchItem fetching = (AIRobotFetchItem) ai;
if (!fetching.noItemPicked && fetching.target != null) {
// if we could get an item, let's try to get another one
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter, robot.getAreaToWork()));
} else if (robot.containsItems()) {
startDelegateAI(new AIRobotGotoStationToUnload(robot, null));
} else {
// otherwise, let's deliver items if any
if (robot.containsItems()) {
startDelegateAI(new AIRobotGotoStationToUnload(robot, null));
} else {
startDelegateAI(new AIRobotGotoSleep(robot));
}
startDelegateAI(new AIRobotGotoSleep(robot));
}
} else if (ai instanceof AIRobotGotoStationToUnload) {
DockingStation station = (DockingStation) robot.getDockingStation();