improvements to robot pathfinding
This commit is contained in:
parent
abd1330031
commit
57ea745c6f
|
@ -4,4 +4,5 @@ Bugs fixed:
|
|||
* [#3071] Filled cylinder pattern incorrect (asie)
|
||||
* [#3069, #2865] Fluid pipe extraction speed ~25% lower than intended (asie, mconwa01)
|
||||
* Filler not changing pattern on parameter change (asie)
|
||||
* Improvements to robot pathfinding logic (asie, hea3ven)
|
||||
* Rotated quarry not detecting its own frame (asie)
|
||||
|
|
|
@ -68,7 +68,9 @@ import buildcraft.api.boards.RedstoneBoardRobot;
|
|||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.events.RobotEvent;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.DockingStation;
|
||||
|
@ -114,12 +116,14 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
|
||||
public ItemStack itemInUse;
|
||||
public float itemAngle1 = 0;
|
||||
public float renderItemAngle1 = 0;
|
||||
public float itemAngle2 = 0;
|
||||
public boolean itemActive = false;
|
||||
public float itemActiveStage = 0;
|
||||
public long lastUpdateTime = 0;
|
||||
|
||||
private SafeTimeTracker expensiveVerificationsTracker = new SafeTimeTracker(10);
|
||||
private boolean isMovingOutOfStuck;
|
||||
|
||||
private DockingStation currentDockingStation;
|
||||
private List<ItemStack> wearables = new ArrayList<ItemStack>();
|
||||
|
||||
|
@ -129,7 +133,7 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
private int maxFluid = FluidContainerRegistry.BUCKET_VOLUME * 4;
|
||||
private ResourceLocation texture;
|
||||
|
||||
private WeakHashMap<Entity, Boolean> unreachableEntities = new WeakHashMap<Entity, Boolean>();
|
||||
private WeakHashMap<Entity, Long> unreachableEntities = new WeakHashMap<Entity, Long>();
|
||||
|
||||
private NBTTagList stackRequestNBT;
|
||||
|
||||
|
@ -350,14 +354,34 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
currentDockingStationSide);
|
||||
}
|
||||
|
||||
if (linkedDockingStation == null || linkedDockingStation.isInitialized()) {
|
||||
this.worldObj.theProfiler.startSection("bcRobotAIMainCycle");
|
||||
mainAI.cycle();
|
||||
this.worldObj.theProfiler.endSection();
|
||||
if (expensiveVerificationsTracker.markTimeIfDelay(worldObj)) {
|
||||
int collisions = worldObj.getCollidingBoundingBoxes(this, getBoundingBox()).size();
|
||||
|
||||
if (energySpendPerCycle != mainAI.getActiveAI().getEnergyCost()) {
|
||||
energySpendPerCycle = mainAI.getActiveAI().getEnergyCost();
|
||||
dataWatcher.updateObject(19, energySpendPerCycle);
|
||||
if (collisions > 0) {
|
||||
isMovingOutOfStuck = true;
|
||||
|
||||
motionX = 0.0F;
|
||||
motionY = 0.05F;
|
||||
motionZ = 0.0F;
|
||||
} else if (isMovingOutOfStuck) {
|
||||
isMovingOutOfStuck = false;
|
||||
|
||||
board.abortDelegateAI();
|
||||
|
||||
motionY = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMovingOutOfStuck) {
|
||||
if (linkedDockingStation == null || linkedDockingStation.isInitialized()) {
|
||||
this.worldObj.theProfiler.startSection("bcRobotAI");
|
||||
mainAI.cycle();
|
||||
this.worldObj.theProfiler.endSection();
|
||||
|
||||
if (energySpendPerCycle != mainAI.getActiveAI().getEnergyCost()) {
|
||||
energySpendPerCycle = mainAI.getActiveAI().getEnergyCost();
|
||||
dataWatcher.updateObject(19, energySpendPerCycle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1124,12 +1148,21 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
|
||||
@Override
|
||||
public void unreachableEntityDetected(Entity entity) {
|
||||
unreachableEntities.put(entity, true);
|
||||
unreachableEntities.put(entity, worldObj.getTotalWorldTime() + 1200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKnownUnreachable(Entity entity) {
|
||||
return unreachableEntities.containsKey(entity);
|
||||
if (unreachableEntities.containsKey(entity)) {
|
||||
if (unreachableEntities.get(entity) >= worldObj.getTotalWorldTime()) {
|
||||
return true;
|
||||
} else {
|
||||
unreachableEntities.remove(entity);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRobotHit(boolean attacked) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagList;
|
|||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.lib.utils.IterableAlgorithmRunner;
|
||||
import buildcraft.core.lib.utils.PathFinding;
|
||||
|
@ -115,9 +116,14 @@ public class AIRobotGotoBlock extends AIRobotGoto {
|
|||
private void setNextInPath() {
|
||||
if (path.size() > 0) {
|
||||
BlockIndex next = path.getFirst();
|
||||
setDestination(robot, next.x + 0.5F, next.y + 0.5F, next.z + 0.5F);
|
||||
prevDistance = Double.MAX_VALUE;
|
||||
robot.aimItemAt(next.x, next.y, next.z);
|
||||
if (BuildCraftAPI.isSoftBlock(robot.worldObj, next.x, next.y, next.z)) {
|
||||
setDestination(robot, next.x + 0.5F, next.y + 0.5F, next.z + 0.5F);
|
||||
prevDistance = Double.MAX_VALUE;
|
||||
robot.aimItemAt(next.x, next.y, next.z);
|
||||
} else {
|
||||
setSuccess(false);
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class AIRobotShutdown extends AIRobot {
|
|||
public void update() {
|
||||
if (skip == 0) {
|
||||
List<?> boxes = robot.worldObj.getCollidingBoundingBoxes(robot,
|
||||
getRobotBox().addCoord(robot.motionX, -0.075f, robot.motionZ));
|
||||
robot.getBoundingBox().addCoord(robot.motionX, -0.075f, robot.motionZ));
|
||||
if (boxes.size() == 0) {
|
||||
robot.motionY = -0.075f;
|
||||
} else {
|
||||
|
@ -55,12 +55,6 @@ public class AIRobotShutdown extends AIRobot {
|
|||
} else {
|
||||
skip--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private AxisAlignedBB getRobotBox() {
|
||||
return AxisAlignedBB.getBoundingBox(robot.posX - 0.25d, robot.posY - 0.25d,
|
||||
robot.posZ - 0.25d, robot.posX + 0.25d, robot.posY + 0.25d, robot.posZ + 0.25d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue