fixed recalculating movement cost
This commit is contained in:
parent
2e184c1b4c
commit
5d46a3d0d9
@ -45,6 +45,7 @@ public class PathingBehavior extends Behavior {
|
|||||||
private PathingBehavior() {}
|
private PathingBehavior() {}
|
||||||
|
|
||||||
private PathExecutor current;
|
private PathExecutor current;
|
||||||
|
private PathExecutor next;
|
||||||
|
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
|
|
||||||
|
@ -17,16 +17,13 @@
|
|||||||
|
|
||||||
package baritone.bot.pathing.path;
|
package baritone.bot.pathing.path;
|
||||||
|
|
||||||
|
import baritone.bot.pathing.movement.CalculationContext;
|
||||||
import baritone.bot.pathing.movement.Movement;
|
import baritone.bot.pathing.movement.Movement;
|
||||||
import baritone.bot.utils.Utils;
|
import baritone.bot.utils.Utils;
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
@ -111,22 +108,13 @@ public interface IPath {
|
|||||||
return pos.get(pos.size() - 1);
|
return pos.get(pos.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
default double ticksRemaining(int pathPosition) {
|
||||||
* For rendering purposes, what blocks should be highlighted in red
|
double sum = 0;
|
||||||
*
|
CalculationContext ctx = new CalculationContext();
|
||||||
* @return an unordered collection of positions
|
for (int i = pathPosition; i < movements().size(); i++) {
|
||||||
*/
|
sum += movements().get(i).getCost(ctx);
|
||||||
default Collection<BlockPos> getBlocksToBreak() {
|
}
|
||||||
return movements().stream().map(Movement::toBreak).flatMap(ArrayList::stream).collect(Collectors.toCollection(HashSet::new));
|
return sum;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For rendering purposes, what blocks should be highlighted in green
|
|
||||||
*
|
|
||||||
* @return an unordered collection of positions
|
|
||||||
*/
|
|
||||||
default Collection<BlockPos> getBlocksToPlace() {
|
|
||||||
return movements().stream().map(Movement::toPlace).flatMap(ArrayList::stream).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumNodesConsidered();
|
int getNumNodesConsidered();
|
||||||
|
@ -48,6 +48,8 @@ public class PathExecutor extends Behavior {
|
|||||||
private int pathPosition;
|
private int pathPosition;
|
||||||
private int ticksAway;
|
private int ticksAway;
|
||||||
private int ticksOnCurrent;
|
private int ticksOnCurrent;
|
||||||
|
private Double currentMovementInitialCostEstimate;
|
||||||
|
private Integer costEstimateIndex;
|
||||||
private boolean failed;
|
private boolean failed;
|
||||||
private boolean recalcBP = true;
|
private boolean recalcBP = true;
|
||||||
private HashSet<BlockPos> toBreak = new HashSet<>();
|
private HashSet<BlockPos> toBreak = new HashSet<>();
|
||||||
@ -171,7 +173,7 @@ public class PathExecutor extends Behavior {
|
|||||||
HashSet<BlockPos> newBreak = new HashSet<>();
|
HashSet<BlockPos> newBreak = new HashSet<>();
|
||||||
HashSet<BlockPos> newPlace = new HashSet<>();
|
HashSet<BlockPos> newPlace = new HashSet<>();
|
||||||
HashSet<BlockPos> newWalkInto = new HashSet<>();
|
HashSet<BlockPos> newWalkInto = new HashSet<>();
|
||||||
for (int i = 0; i < path.movements().size(); i++) {
|
for (int i = pathPosition; i < path.movements().size(); i++) {
|
||||||
newBreak.addAll(path.movements().get(i).toBreak());
|
newBreak.addAll(path.movements().get(i).toBreak());
|
||||||
newPlace.addAll(path.movements().get(i).toPlace());
|
newPlace.addAll(path.movements().get(i).toPlace());
|
||||||
newWalkInto.addAll(path.movements().get(i).toWalkInto());
|
newWalkInto.addAll(path.movements().get(i).toWalkInto());
|
||||||
@ -186,13 +188,18 @@ public class PathExecutor extends Behavior {
|
|||||||
//displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
|
//displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
|
||||||
}
|
}
|
||||||
Movement movement = path.movements().get(pathPosition);
|
Movement movement = path.movements().get(pathPosition);
|
||||||
if (movement.recalculateCost() >= ActionCosts.COST_INF) {
|
double currentCost = movement.recalculateCost();
|
||||||
|
if (currentCost >= ActionCosts.COST_INF) {
|
||||||
displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling.");
|
displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||||
pathPosition = path.length() + 3;
|
pathPosition = path.length() + 3;
|
||||||
failed = true;
|
failed = true;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||||
|
costEstimateIndex = pathPosition;
|
||||||
|
currentMovementInitialCostEstimate = currentCost; // do this only once, when the movement starts
|
||||||
|
}
|
||||||
MovementState.MovementStatus movementStatus = movement.update();
|
MovementState.MovementStatus movementStatus = movement.update();
|
||||||
if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
|
if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
|
||||||
displayChatMessageRaw("Movement returns status " + movementStatus);
|
displayChatMessageRaw("Movement returns status " + movementStatus);
|
||||||
@ -209,7 +216,11 @@ public class PathExecutor extends Behavior {
|
|||||||
onTick(event);
|
onTick(event);
|
||||||
} else {
|
} else {
|
||||||
ticksOnCurrent++;
|
ticksOnCurrent++;
|
||||||
if (ticksOnCurrent > movement.recalculateCost() + 100) {
|
if (ticksOnCurrent > currentMovementInitialCostEstimate + 100) {
|
||||||
|
// only fail if the total time has exceeded the initial estimate
|
||||||
|
// as you break the blocks required, the remaining cost goes down, to the point where
|
||||||
|
// ticksOnCurrent is greater than recalculateCost + 1000
|
||||||
|
// this is why we cache cost at the beginning, and don't recalculate for this comparison every tick
|
||||||
displayChatMessageRaw("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + movement.getCost(null) + "). Cancelling.");
|
displayChatMessageRaw("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + movement.getCost(null) + "). Cancelling.");
|
||||||
movement.cancel();
|
movement.cancel();
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
|
Loading…
Reference in New Issue
Block a user