improved carrier robot behavior and adjusted energy consumption
This commit is contained in:
parent
d38ab37cc0
commit
99309b381a
12 changed files with 62 additions and 27 deletions
|
@ -27,7 +27,6 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void updateBoard(EntityRobotBase container) {
|
public final void updateBoard(EntityRobotBase container) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class AIRobotFindRandomGroundBlock extends AIRobot {
|
||||||
private int attempts = 0;
|
private int attempts = 0;
|
||||||
|
|
||||||
public AIRobotFindRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
public AIRobotFindRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
||||||
super(iRobot, 2);
|
super(iRobot, 0);
|
||||||
|
|
||||||
range = iRange;
|
range = iRange;
|
||||||
filter = iFilter;
|
filter = iFilter;
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class AIRobotGotoRandomGroundBlock extends AIRobot {
|
||||||
private IBox area;
|
private IBox area;
|
||||||
|
|
||||||
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
||||||
super(iRobot, 2);
|
super(iRobot, 0);
|
||||||
|
|
||||||
range = iRange;
|
range = iRange;
|
||||||
filter = iFilter;
|
filter = iFilter;
|
||||||
|
|
|
@ -27,6 +27,8 @@ import buildcraft.transport.gates.ActionSlot;
|
||||||
|
|
||||||
public class AIRobotGotoStationToLoad extends AIRobot {
|
public class AIRobotGotoStationToLoad extends AIRobot {
|
||||||
|
|
||||||
|
public boolean found = false;
|
||||||
|
|
||||||
private IStackFilter filter;
|
private IStackFilter filter;
|
||||||
private IBox box;
|
private IBox box;
|
||||||
|
|
||||||
|
@ -39,13 +41,17 @@ public class AIRobotGotoStationToLoad extends AIRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
startDelegateAI(new AIRobotLookForStation(robot, new StationFilter(), box));
|
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), box));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delegateAIEnded(AIRobot ai) {
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
|
if (ai instanceof AIRobotSearchAndGotoStation) {
|
||||||
|
found = ((AIRobotSearchAndGotoStation) ai).targetStation != null;
|
||||||
|
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class StationFilter implements IStationFilter {
|
private class StationFilter implements IStationFilter {
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ import buildcraft.transport.gates.ActionSlot;
|
||||||
|
|
||||||
public class AIRobotGotoStationToUnload extends AIRobot {
|
public class AIRobotGotoStationToUnload extends AIRobot {
|
||||||
|
|
||||||
|
public boolean found = false;
|
||||||
|
|
||||||
private IBox box;
|
private IBox box;
|
||||||
|
|
||||||
public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IBox iBox) {
|
public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IBox iBox) {
|
||||||
|
@ -33,13 +35,17 @@ public class AIRobotGotoStationToUnload extends AIRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
startDelegateAI(new AIRobotLookForStation(robot, new StationInventory(), box));
|
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationInventory(), box));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delegateAIEnded(AIRobot ai) {
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
|
if (ai instanceof AIRobotSearchAndGotoStation) {
|
||||||
|
found = ((AIRobotSearchAndGotoStation) ai).targetStation != null;
|
||||||
|
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class StationInventory implements IStationFilter {
|
private class StationInventory implements IStationFilter {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class AIRobotLoad extends AIRobot {
|
||||||
private int waitedCycles = 0;
|
private int waitedCycles = 0;
|
||||||
|
|
||||||
public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
|
public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
|
||||||
super(iRobot, 0);
|
super(iRobot, 2);
|
||||||
|
|
||||||
filter = iFilter;
|
filter = iFilter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class AIRobotRecharge extends AIRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
startDelegateAI(new AIRobotLookForStation(robot, new IStationFilter() {
|
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(DockingStation station) {
|
public boolean matches(DockingStation station) {
|
||||||
return station.pipe.getPipeType() == PipeType.POWER;
|
return station.pipe.getPipeType() == PipeType.POWER;
|
||||||
|
@ -46,7 +46,7 @@ public class AIRobotRecharge extends AIRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delegateAIEnded(AIRobot ai) {
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
if (ai instanceof AIRobotLookForStation) {
|
if (ai instanceof AIRobotSearchAndGotoStation) {
|
||||||
if (robot.getDockingStation() == null
|
if (robot.getDockingStation() == null
|
||||||
|| !(((DockingStation) robot.getDockingStation()).pipe.pipe.transport instanceof PipeTransportPower)) {
|
|| !(((DockingStation) robot.getDockingStation()).pipe.pipe.transport instanceof PipeTransportPower)) {
|
||||||
terminate();
|
terminate();
|
||||||
|
|
|
@ -15,13 +15,13 @@ import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.api.robots.IDockingStation;
|
import buildcraft.api.robots.IDockingStation;
|
||||||
import buildcraft.silicon.statements.ActionStationForbidRobot;
|
import buildcraft.silicon.statements.ActionStationForbidRobot;
|
||||||
|
|
||||||
public class AIRobotLookForStation extends AIRobot {
|
public class AIRobotSearchAndGotoStation extends AIRobot {
|
||||||
|
|
||||||
public DockingStation targetStation;
|
public DockingStation targetStation;
|
||||||
private IStationFilter filter;
|
private IStationFilter filter;
|
||||||
private IBox box;
|
private IBox box;
|
||||||
|
|
||||||
public AIRobotLookForStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) {
|
public AIRobotSearchAndGotoStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) {
|
||||||
super(iRobot, 0);
|
super(iRobot, 0);
|
||||||
|
|
||||||
filter = iFilter;
|
filter = iFilter;
|
|
@ -25,7 +25,7 @@ public class AIRobotSearchBlock extends AIRobot {
|
||||||
private IPathFound pathFound;
|
private IPathFound pathFound;
|
||||||
|
|
||||||
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
|
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
|
||||||
super(iRobot, 2);
|
super(iRobot, 0);
|
||||||
|
|
||||||
pathFound = iPathFound;
|
pathFound = iPathFound;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class AIRobotUnload extends AIRobot {
|
||||||
private int waitedCycles = 0;
|
private int waitedCycles = 0;
|
||||||
|
|
||||||
public AIRobotUnload(EntityRobotBase iRobot) {
|
public AIRobotUnload(EntityRobotBase iRobot) {
|
||||||
super(iRobot, 0);
|
super(iRobot, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,7 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.robots.AIRobot;
|
import buildcraft.api.robots.AIRobot;
|
||||||
import buildcraft.api.robots.EntityRobotBase;
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.core.inventory.filters.PassThroughStackFilter;
|
import buildcraft.core.inventory.filters.PassThroughStackFilter;
|
||||||
|
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||||
import buildcraft.core.robots.AIRobotGotoStationToLoad;
|
import buildcraft.core.robots.AIRobotGotoStationToLoad;
|
||||||
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
||||||
import buildcraft.core.robots.AIRobotLoad;
|
import buildcraft.core.robots.AIRobotLoad;
|
||||||
|
@ -20,6 +21,9 @@ import buildcraft.core.robots.AIRobotUnload;
|
||||||
|
|
||||||
public class BoardRobotCarrier extends RedstoneBoardRobot {
|
public class BoardRobotCarrier extends RedstoneBoardRobot {
|
||||||
|
|
||||||
|
private boolean loadFound = true;
|
||||||
|
private boolean unloadFound = true;
|
||||||
|
|
||||||
public BoardRobotCarrier(EntityRobotBase iRobot) {
|
public BoardRobotCarrier(EntityRobotBase iRobot) {
|
||||||
super(iRobot);
|
super(iRobot);
|
||||||
}
|
}
|
||||||
|
@ -41,9 +45,34 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
|
||||||
@Override
|
@Override
|
||||||
public void delegateAIEnded(AIRobot ai) {
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
if (ai instanceof AIRobotGotoStationToLoad) {
|
if (ai instanceof AIRobotGotoStationToLoad) {
|
||||||
|
if (((AIRobotGotoStationToLoad) ai).found) {
|
||||||
|
loadFound = true;
|
||||||
startDelegateAI(new AIRobotLoad(robot, new PassThroughStackFilter()));
|
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) {
|
} else if (ai instanceof AIRobotGotoStationToUnload) {
|
||||||
|
if (((AIRobotGotoStationToUnload) ai).found) {
|
||||||
|
unloadFound = true;
|
||||||
startDelegateAI(new AIRobotUnload(robot));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.core.inventory.filters.ArrayStackFilter;
|
import buildcraft.core.inventory.filters.ArrayStackFilter;
|
||||||
import buildcraft.core.inventory.filters.IStackFilter;
|
import buildcraft.core.inventory.filters.IStackFilter;
|
||||||
import buildcraft.core.robots.AIRobotFetchItem;
|
import buildcraft.core.robots.AIRobotFetchItem;
|
||||||
import buildcraft.core.robots.AIRobotGotoDock;
|
|
||||||
import buildcraft.core.robots.AIRobotGotoSleep;
|
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||||
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
||||||
import buildcraft.core.robots.AIRobotSleep;
|
import buildcraft.core.robots.AIRobotSleep;
|
||||||
|
@ -74,20 +73,16 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
||||||
@Override
|
@Override
|
||||||
public void delegateAIEnded(AIRobot ai) {
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
if (ai instanceof AIRobotFetchItem) {
|
if (ai instanceof AIRobotFetchItem) {
|
||||||
if (((AIRobotFetchItem) ai).noItemPicked) {
|
AIRobotFetchItem fetching = (AIRobotFetchItem) ai;
|
||||||
startDelegateAI(new AIRobotGotoDock(robot, (DockingStation) robot.getLinkedStation()));
|
|
||||||
} else if (((AIRobotFetchItem) ai).target != null) {
|
if (!fetching.noItemPicked && fetching.target != null) {
|
||||||
// if we could get an item, let's try to get another one
|
// if we could get an item, let's try to get another one
|
||||||
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter, robot.getAreaToWork()));
|
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter, robot.getAreaToWork()));
|
||||||
} else {
|
} else if (robot.containsItems()) {
|
||||||
// otherwise, let's deliver items if any
|
|
||||||
|
|
||||||
if (robot.containsItems()) {
|
|
||||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, null));
|
startDelegateAI(new AIRobotGotoStationToUnload(robot, null));
|
||||||
} else {
|
} else {
|
||||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (ai instanceof AIRobotGotoStationToUnload) {
|
} else if (ai instanceof AIRobotGotoStationToUnload) {
|
||||||
DockingStation station = (DockingStation) robot.getDockingStation();
|
DockingStation station = (DockingStation) robot.getDockingStation();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue