Generalized latency property, for #1873
This commit is contained in:
parent
4428b44674
commit
eeb637d59f
18 changed files with 52 additions and 31 deletions
|
@ -18,8 +18,8 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa
|
|||
|
||||
public static HashSet<BlockIndex> reservedBlocks = new HashSet<BlockIndex>();
|
||||
|
||||
public RedstoneBoardRobot(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
public RedstoneBoardRobot(EntityRobotBase iRobot, int updateLatency) {
|
||||
super(iRobot, 0, updateLatency);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
13
api/buildcraft/api/gates/ActionState.java
Executable file
13
api/buildcraft/api/gates/ActionState.java
Executable file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.gates;
|
||||
|
||||
public class ActionState {
|
||||
|
||||
}
|
|
@ -1,21 +1,23 @@
|
|||
|
||||
package buildcraft.api.robots;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
||||
public class AIRobot {
|
||||
public EntityRobotBase robot;
|
||||
|
||||
private AIRobot delegateAI;
|
||||
private AIRobot parentAI;
|
||||
private double energyCost;
|
||||
private SafeTimeTracker updateTracker;
|
||||
|
||||
public AIRobot(EntityRobotBase iRobot, double iEnergyCost) {
|
||||
public AIRobot(EntityRobotBase iRobot, double iEnergyCost, int updateLatency) {
|
||||
robot = iRobot;
|
||||
energyCost = iEnergyCost;
|
||||
}
|
||||
|
||||
public AIRobot(EntityRobotBase iRobot) {
|
||||
robot = iRobot;
|
||||
energyCost = 0;
|
||||
if (updateLatency > 1) {
|
||||
updateTracker = new SafeTimeTracker(updateLatency, updateLatency / 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
@ -54,8 +56,10 @@ public class AIRobot {
|
|||
if (delegateAI != null) {
|
||||
delegateAI.cycle();
|
||||
} else {
|
||||
robot.setEnergy(robot.getEnergy() - energyCost);
|
||||
update();
|
||||
if (updateTracker == null || updateTracker.markTimeIfDelay(robot.worldObj)) {
|
||||
robot.setEnergy(robot.getEnergy() - energyCost);
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotGoAndLinkToDock extends AIRobot {
|
|||
public DockingStation station;
|
||||
|
||||
public AIRobotGoAndLinkToDock(EntityRobotBase iRobot, DockingStation iStation) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
|
||||
station = iStation;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotGoToDock extends AIRobot {
|
|||
private DockingStation station;
|
||||
|
||||
public AIRobotGoToDock(EntityRobotBase iRobot, DockingStation iStation) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
|
||||
station = iStation;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ import buildcraft.api.robots.IDockingStation;
|
|||
|
||||
public class AIRobotLookForStation extends AIRobot {
|
||||
|
||||
private DockingStation axeDocking = null;
|
||||
public DockingStation targetStation;
|
||||
private IStationFilter filter;
|
||||
|
||||
public AIRobotLookForStation(EntityRobotBase iRobot, IStationFilter iFilter) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ public class AIRobotLookForStation extends AIRobot {
|
|||
}
|
||||
|
||||
if (potentialStation != null) {
|
||||
targetStation = potentialStation;
|
||||
startDelegateAI(new AIRobotGoToDock(robot, potentialStation));
|
||||
} else {
|
||||
terminate();
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotMain extends AIRobot {
|
|||
private AIRobot overridingAI;
|
||||
|
||||
public AIRobotMain(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,7 @@ public abstract class AIRobotMove extends AIRobot {
|
|||
protected double dirX, dirY, dirZ;
|
||||
|
||||
public AIRobotMove(EntityRobotBase iRobot) {
|
||||
super(iRobot, 1);
|
||||
super(iRobot, 1, 1);
|
||||
}
|
||||
|
||||
protected void setDestination(EntityRobotBase robot, float x, float y, float z) {
|
||||
|
|
|
@ -18,7 +18,7 @@ public class AIRobotRecharge extends AIRobot {
|
|||
private DockingStation axeDocking = null;
|
||||
|
||||
public AIRobotRecharge(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,7 @@ public class AIRobotBreakWithTool extends AIRobot {
|
|||
private float speed;
|
||||
|
||||
public AIRobotBreakWithTool(EntityRobotBase iRobot, BlockIndex iBlockToBreak) {
|
||||
super(iRobot, 2);
|
||||
super(iRobot, 2, 1);
|
||||
|
||||
blockToBreak = iBlockToBreak;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class AIRobotFetchItem extends AIRobot {
|
|||
private int pickTime = -1;
|
||||
|
||||
public AIRobotFetchItem(EntityRobotBase iRobot, float iMaxRange, IStackFilter iStackFilter) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
stackFilter = iStackFilter;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class AIRobotFetchItemStack extends AIRobot {
|
|||
private IStackFilter filter;
|
||||
|
||||
public AIRobotFetchItemStack(EntityRobotBase iRobot, IStackFilter iFilter) {
|
||||
super(iRobot);
|
||||
super(iRobot, 0, 1);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class AIRobotGoToRandomDirt extends AIRobot {
|
|||
private PathFindingJob pathFindingJob;
|
||||
|
||||
public AIRobotGoToRandomDirt(EntityRobotBase iRobot, int iRange) {
|
||||
super(iRobot, 2);
|
||||
super(iRobot, 2, 1);
|
||||
|
||||
range = iRange;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AIRobotPlantSaple extends AIRobot {
|
|||
private int plantCycles = 0;
|
||||
|
||||
public AIRobotPlantSaple(EntityRobotBase iRobot, BlockIndex index) {
|
||||
super(iRobot, 2);
|
||||
super(iRobot, 2, 1);
|
||||
|
||||
toPlant = index;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AIRobotSearchBlock extends AIRobot {
|
|||
private IPathFound pathFound;
|
||||
|
||||
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
|
||||
super(iRobot, 2);
|
||||
super(iRobot, 2, 1);
|
||||
|
||||
pathFound = iPathFound;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import buildcraft.core.utils.IPathFound;
|
|||
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotGenericBreakBlock(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
super(iRobot, 1);
|
||||
}
|
||||
|
||||
public abstract boolean isExpectedTool(ItemStack stack);
|
||||
|
|
|
@ -24,7 +24,6 @@ import buildcraft.api.boards.RedstoneBoardNBT;
|
|||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
|
@ -42,8 +41,6 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
// TODO: Clean this when world unloaded
|
||||
public static Set<Integer> targettedItems = new HashSet<Integer>();
|
||||
|
||||
private SafeTimeTracker scanTracker = new SafeTimeTracker(40, 10);
|
||||
|
||||
private NBTTagCompound data;
|
||||
private RedstoneBoardNBT<?> board;
|
||||
private IBoardParameter[] params;
|
||||
|
@ -51,7 +48,7 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
private IStackFilter stackFilter;
|
||||
|
||||
public BoardRobotPicker(EntityRobotBase robot, NBTTagCompound nbt) {
|
||||
super(robot);
|
||||
super(robot, 40);
|
||||
data = nbt;
|
||||
|
||||
board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt);
|
||||
|
@ -75,9 +72,7 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
|
||||
@Override
|
||||
public void update() {
|
||||
if (scanTracker.markTimeIfDelay(robot.worldObj)) {
|
||||
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter));
|
||||
}
|
||||
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,6 +103,10 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
boolean found = false;
|
||||
ItemStack stackToAdd = robot.getStackInSlot(i);
|
||||
|
||||
if (stackToAdd == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Object s : pipe.getActionStates()) {
|
||||
if (s instanceof StateStationRequestItems) {
|
||||
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
|
||||
|
@ -154,6 +153,10 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
boolean found = false;
|
||||
ItemStack stackToAdd = robot.getStackInSlot(i);
|
||||
|
||||
if (stackToAdd == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Object s : pipe.getActionStates()) {
|
||||
if (s instanceof StateStationRequestItems) {
|
||||
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
|
||||
|
|
|
@ -17,7 +17,7 @@ import buildcraft.core.inventory.filters.OreStackFilter;
|
|||
public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotPlanter(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
super(iRobot, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue