baritone/src/main/java/baritone/bot/pathing/calc/PathNode.java

76 lines
2.0 KiB
Java
Raw Normal View History

2018-08-02 15:07:10 +00:00
package baritone.bot.pathing.calc;
2018-08-01 15:34:35 +00:00
2018-08-02 15:07:10 +00:00
import baritone.bot.pathing.goals.Goal;
2018-08-03 13:55:17 +00:00
import baritone.bot.pathing.movement.Movement;
2018-08-01 15:34:35 +00:00
import net.minecraft.util.math.BlockPos;
2018-08-02 15:07:10 +00:00
import java.util.Objects;
2018-08-01 15:34:35 +00:00
/**
2018-08-02 15:07:10 +00:00
* A node in the path, containing the cost and steps to get to it.
2018-08-01 15:34:35 +00:00
*
* @author leijurv
*/
2018-08-02 15:07:10 +00:00
class PathNode {
2018-08-03 03:48:21 +00:00
2018-08-01 15:34:35 +00:00
final BlockPos pos;
2018-08-03 03:48:21 +00:00
2018-08-01 15:34:35 +00:00
final Goal goal;
2018-08-03 03:48:21 +00:00
2018-08-01 15:34:35 +00:00
final double estimatedCostToGoal;
2018-08-02 15:07:10 +00:00
// These three fields are mutable and are changed by PathFinder
double cost;
2018-08-03 03:48:21 +00:00
public double combinedCost;
2018-08-02 15:07:10 +00:00
PathNode previous;
2018-08-03 03:48:21 +00:00
2018-08-02 22:35:36 +00:00
Movement previousMovement;
2018-08-02 15:07:10 +00:00
/**
* Is this a member of the open set in A*? (only used during pathfinding)
*/
2018-08-01 15:34:35 +00:00
boolean isOpen;
2018-08-03 03:48:21 +00:00
2018-08-02 15:07:10 +00:00
/**
* In the linked list of open nodes, which one is next? (only used during pathfinding)
*/
PathNode nextOpen;
public PathNode(BlockPos pos, Goal goal) {
2018-08-01 15:34:35 +00:00
this.pos = pos;
this.previous = null;
this.cost = Short.MAX_VALUE;
this.goal = goal;
this.estimatedCostToGoal = goal.heuristic(pos);
2018-08-02 22:35:36 +00:00
this.previousMovement = null;
2018-08-01 15:34:35 +00:00
this.isOpen = false;
}
2018-08-02 15:07:10 +00:00
2018-08-03 03:48:21 +00:00
/**
* TODO: Possibly reimplement hashCode and equals. They are necessary for this class to function but they could be done better
*
* @return The hash code value for this {@link PathNode}
*/
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public int hashCode() {
2018-08-01 15:34:35 +00:00
int hash = 3241;
hash = 3457689 * hash + this.pos.getX();
hash = 8734625 * hash + this.pos.getY();
hash = 2873465 * hash + this.pos.getZ();
2018-08-03 03:48:21 +00:00
// Don't call goal.hashCode(). this calls objects hashcode to verify that the actual goal objects are == identical, which is important for node caching
hash = 3241543 * hash + Objects.hashCode(this.goal);
2018-08-01 15:34:35 +00:00
return hash;
}
2018-08-02 15:07:10 +00:00
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof PathNode))
2018-08-01 15:34:35 +00:00
return false;
2018-08-03 03:48:21 +00:00
2018-08-02 15:07:10 +00:00
final PathNode other = (PathNode) obj;
2018-08-03 03:48:21 +00:00
return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);
2018-08-01 15:34:35 +00:00
}
}