More debug for waypoints

This commit is contained in:
Guillaume 2022-05-04 11:31:12 +02:00
parent e41749135e
commit 5a2e05bb12
2 changed files with 17 additions and 9 deletions

View File

@ -184,17 +184,20 @@ public class WaypointViewer extends EditableInventory {
paths.put(pathInfo.getFinalWaypoint(), pathInfo); paths.put(pathInfo.getFinalWaypoint(), pathInfo);
} }
if (current == null) { if (current == null) {
//Iterate through all the dynamic points and find all the points it is linked to and the path
HashMap<Waypoint, Double> dynamicPoints = new HashMap<>();
//We first check all the dynamic waypoints //We first check all the dynamic waypoints
for (Waypoint waypoint : waypoints) { for (Waypoint waypoint : waypoints) {
if (waypoint.canHaveDynamicUse(playerData.getPlayer())) if (waypoint.canHaveDynamicUse(playerData.getPlayer())) {
paths.put(waypoint, new Waypoint.PathInfo(waypoint, waypoint.getDynamicCost())); paths.put(waypoint, new Waypoint.PathInfo(waypoint, waypoint.getDynamicCost()));
dynamicPoints.put(waypoint, waypoint.getDynamicCost());
} }
//Iterate through all the dynamic points and find all the points it is linked to and the path }
HashSet<Waypoint> waypointSet = new HashSet<>(paths.keySet()); for(Waypoint source: dynamicPoints.keySet()){
for (Waypoint source : waypointSet) {
for (Waypoint.PathInfo target : source.getAllPath()) { for (Waypoint.PathInfo target : source.getAllPath()) {
if (!paths.containsKey(target.getFinalWaypoint()) || paths.get(target.getFinalWaypoint()).getCost() > target.getCost()) { if (!paths.containsKey(target.getFinalWaypoint()) || paths.get(target.getFinalWaypoint()).getCost() > target.getCost()+dynamicPoints.get(source)) {
paths.put(target.getFinalWaypoint(), target); paths.put(target.getFinalWaypoint(), target.addCost(dynamicPoints.get(source)));
} }
} }
} }

View File

@ -240,7 +240,7 @@ public class Waypoint implements Unlockable {
public static class PathInfo { public static class PathInfo {
private final ArrayList<Waypoint> waypoints; private final ArrayList<Waypoint> waypoints;
private final double cost; private double cost;
public ArrayList<Waypoint> getWaypoints() { public ArrayList<Waypoint> getWaypoints() {
return waypoints; return waypoints;
@ -261,6 +261,11 @@ public class Waypoint implements Unlockable {
this.cost = cost; this.cost = cost;
} }
public PathInfo addCost(double cost) {
this.cost+=cost;
return this;
}
public ArrayList<PathInfo> addInOrder(ArrayList<PathInfo> pathInfos) { public ArrayList<PathInfo> addInOrder(ArrayList<PathInfo> pathInfos) {
int index = 0; int index = 0;
while (index < pathInfos.size()) { while (index < pathInfos.size()) {