no need for systematic cycle latency with sleep implementation
This commit is contained in:
parent
f61c3cacaa
commit
ab699b2480
32 changed files with 63 additions and 47 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, int updateLatency) {
|
||||
super(iRobot, 0, updateLatency);
|
||||
public RedstoneBoardRobot(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package buildcraft.api.robots;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
||||
public class AIRobot {
|
||||
public EntityRobotBase robot;
|
||||
|
@ -9,15 +8,10 @@ public class AIRobot {
|
|||
private AIRobot delegateAI;
|
||||
private AIRobot parentAI;
|
||||
private double energyCost;
|
||||
private SafeTimeTracker updateTracker;
|
||||
|
||||
public AIRobot(EntityRobotBase iRobot, double iEnergyCost, int updateLatency) {
|
||||
public AIRobot(EntityRobotBase iRobot, double iEnergyCost) {
|
||||
robot = iRobot;
|
||||
energyCost = iEnergyCost;
|
||||
|
||||
if (updateLatency > 1) {
|
||||
updateTracker = new SafeTimeTracker(updateLatency, updateLatency / 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
@ -70,10 +64,8 @@ public class AIRobot {
|
|||
if (delegateAI != null) {
|
||||
delegateAI.cycle();
|
||||
} else {
|
||||
if (updateTracker == null || updateTracker.markTimeIfDelay(robot.worldObj)) {
|
||||
robot.setEnergy(robot.getEnergy() - energyCost);
|
||||
update();
|
||||
}
|
||||
robot.setEnergy(robot.getEnergy() - energyCost);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,6 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory
|
|||
|
||||
public abstract IBox getAreaToWork();
|
||||
|
||||
public abstract boolean containsItems();
|
||||
|
||||
}
|
||||
|
|
|
@ -96,7 +96,6 @@ import buildcraft.core.robots.EntityRobot;
|
|||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.triggers.ActionMachineControl.Mode;
|
||||
import buildcraft.core.triggers.ActionRedstoneOutput;
|
||||
import buildcraft.core.triggers.BCTrigger;
|
||||
import buildcraft.core.triggers.DefaultActionProvider;
|
||||
import buildcraft.core.triggers.DefaultTriggerProvider;
|
||||
import buildcraft.core.triggers.StatementIconProvider;
|
||||
|
|
|
@ -20,7 +20,7 @@ public class AIRobotAttack extends AIRobot {
|
|||
private int delay = 10;
|
||||
|
||||
public AIRobotAttack(EntityRobotBase iRobot, EntityMob iTarget) {
|
||||
super(iRobot, 5, 1);
|
||||
super(iRobot, 5);
|
||||
|
||||
target = iTarget;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class AIRobotBreakWithTool extends AIRobot {
|
|||
private float speed;
|
||||
|
||||
public AIRobotBreakWithTool(EntityRobotBase iRobot, BlockIndex iBlockToBreak) {
|
||||
super(iRobot, 2, 1);
|
||||
super(iRobot, 2);
|
||||
|
||||
blockToBreak = iBlockToBreak;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
|
|||
private IStackFilter filter;
|
||||
|
||||
public AIRobotFetchAndEquipItemStack(EntityRobotBase iRobot, IStackFilter iFilter) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class AIRobotFetchItem extends AIRobot {
|
|||
private int pickTime = -1;
|
||||
|
||||
public AIRobotFetchItem(EntityRobotBase iRobot, float iMaxRange, IStackFilter iStackFilter) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
stackFilter = iStackFilter;
|
||||
|
|
|
@ -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, 1);
|
||||
super(iRobot, 2);
|
||||
|
||||
range = iRange;
|
||||
filter = iFilter;
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotGoAndLinkToDock extends AIRobot {
|
|||
public DockingStation station;
|
||||
|
||||
public AIRobotGoAndLinkToDock(EntityRobotBase iRobot, DockingStation iStation) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
station = iStation;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public abstract class AIRobotGoto extends AIRobot {
|
|||
protected double dirX, dirY, dirZ;
|
||||
|
||||
public AIRobotGoto(EntityRobotBase iRobot) {
|
||||
super(iRobot, 1, 1);
|
||||
super(iRobot, 1);
|
||||
}
|
||||
|
||||
protected void setDestination(EntityRobotBase robot, float x, float y, float z) {
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotGotoDock extends AIRobot {
|
|||
private DockingStation station;
|
||||
|
||||
public AIRobotGotoDock(EntityRobotBase iRobot, DockingStation iStation) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
station = iStation;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AIRobotGotoMob extends AIRobot {
|
|||
private float maxRange;
|
||||
|
||||
public AIRobotGotoMob(EntityRobotBase iRobot, float iMaxRange) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
}
|
||||
|
|
|
@ -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, 1);
|
||||
super(iRobot, 2);
|
||||
|
||||
range = iRange;
|
||||
filter = iFilter;
|
||||
|
|
|
@ -14,7 +14,7 @@ import buildcraft.api.robots.EntityRobotBase;
|
|||
public class AIRobotGotoSleep extends AIRobot {
|
||||
|
||||
public AIRobotGotoSleep(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AIRobotGotoStationToLoad extends AIRobot {
|
|||
private IStackFilter filter;
|
||||
|
||||
public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,8 @@ import buildcraft.transport.Pipe;
|
|||
|
||||
public class AIRobotGotoStationToUnload extends AIRobot {
|
||||
|
||||
|
||||
public AIRobotGotoStationToUnload(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class AIRobotLoad extends AIRobot {
|
|||
private IStackFilter filter;
|
||||
|
||||
public AIRobotLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class AIRobotLookForStation extends AIRobot {
|
|||
private IStationFilter filter;
|
||||
|
||||
public AIRobotLookForStation(EntityRobotBase iRobot, IStationFilter iFilter) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
|
||||
filter = iFilter;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AIRobotMain extends AIRobot {
|
|||
private AIRobot overridingAI;
|
||||
|
||||
public AIRobotMain(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AIRobotPlantSaple extends AIRobot {
|
|||
private int plantCycles = 0;
|
||||
|
||||
public AIRobotPlantSaple(EntityRobotBase iRobot, BlockIndex index) {
|
||||
super(iRobot, 2, 1);
|
||||
super(iRobot, 2);
|
||||
|
||||
toPlant = index;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class AIRobotRecharge extends AIRobot {
|
|||
private DockingStation axeDocking = null;
|
||||
|
||||
public AIRobotRecharge(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AIRobotSearchBlock extends AIRobot {
|
|||
private IPathFound pathFound;
|
||||
|
||||
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
|
||||
super(iRobot, 2, 1);
|
||||
super(iRobot, 2);
|
||||
|
||||
pathFound = iPathFound;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class AIRobotSleep extends AIRobot {
|
|||
private int sleptTime = 0;
|
||||
|
||||
public AIRobotSleep(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import buildcraft.transport.Pipe;
|
|||
public class AIRobotUnload extends AIRobot {
|
||||
|
||||
public AIRobotUnload(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0, 1);
|
||||
super(iRobot, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -670,4 +670,15 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
for (ItemStack element : inv) {
|
||||
if (element != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BoardRobotBomber extends RedstoneBoardRobot {
|
|||
private int flyingHeight = 20;
|
||||
|
||||
public BoardRobotBomber(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0);
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ import buildcraft.core.robots.AIRobotUnload;
|
|||
public class BoardRobotCarrier extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotCarrier(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0);
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,7 @@ import buildcraft.core.utils.IPathFound;
|
|||
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotGenericBreakBlock(EntityRobotBase iRobot) {
|
||||
super(iRobot, 1);
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public abstract boolean isExpectedTool(ItemStack stack);
|
||||
|
|
|
@ -23,7 +23,7 @@ import buildcraft.core.robots.AIRobotGotoMob;
|
|||
public class BoardRobotKnight extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotKnight(EntityRobotBase iRobot) {
|
||||
super(iRobot, 0);
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,9 +25,11 @@ 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.AIRobotGotoSleep;
|
||||
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
||||
import buildcraft.core.robots.AIRobotLookForStation;
|
||||
import buildcraft.core.robots.AIRobotSleep;
|
||||
import buildcraft.core.robots.AIRobotUnload;
|
||||
import buildcraft.core.robots.DockingStation;
|
||||
|
||||
public class BoardRobotPicker extends RedstoneBoardRobot {
|
||||
|
||||
|
@ -41,7 +43,7 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
private IStackFilter stackFilter;
|
||||
|
||||
public BoardRobotPicker(EntityRobotBase robot, NBTTagCompound nbt) {
|
||||
super(robot, 40);
|
||||
super(robot);
|
||||
data = nbt;
|
||||
|
||||
board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt);
|
||||
|
@ -75,11 +77,22 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
// if we could get an item, let's try to get another one
|
||||
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter));
|
||||
} else {
|
||||
// otherwise, let's deliver items
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot));
|
||||
// otherwise, let's deliver items if any
|
||||
|
||||
if (robot.containsItems()) {
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
}
|
||||
}
|
||||
} else if (ai instanceof AIRobotGotoStationToUnload) {
|
||||
DockingStation station = (DockingStation) robot.getDockingStation();
|
||||
|
||||
if (station != null) {
|
||||
startDelegateAI(new AIRobotUnload(robot));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotSleep(robot));
|
||||
}
|
||||
} else if (ai instanceof AIRobotLookForStation) {
|
||||
startDelegateAI(new AIRobotUnload(robot));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import buildcraft.core.robots.IBlockFilter;
|
|||
public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||
|
||||
public BoardRobotPlanter(EntityRobotBase iRobot) {
|
||||
super(iRobot, 1);
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue