Skip to content

Commit

Permalink
completing some find issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CubBossa committed Nov 17, 2023
1 parent 2f6ed26 commit 41d2424
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import de.cubbossa.pathapi.node.Node;
import de.cubbossa.pathapi.visualizer.VisualizerPath;
import de.cubbossa.pathfinder.graph.PathSolver;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

/**
* The core element to manage path visualizations on an existing graph.
*
Expand Down Expand Up @@ -107,7 +108,13 @@ record NavigationRequestContext(UUID playerId, Collection<Node> nodes) {
*/
interface NavigateLocation {
Node getNode();

boolean isExternal();

void setExternal(boolean external);

boolean isAgile();

void setAgile(boolean agile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static <PlayerT> void printResult(NavigateResult result, PathPlayer<Playe
case FAIL_BLOCKED, FAIL_EVENT_CANCELLED -> Messages.CMD_FIND_BLOCKED;
case FAIL_EMPTY -> Messages.CMD_FIND_EMPTY;
case FAIL_TOO_FAR_AWAY -> Messages.CMD_FIND_TOO_FAR;
case FAIL_UNKNOWN -> Messages.CMD_FIND_UNKNOWN;
default -> null;
};
if (message != null) {
Expand Down Expand Up @@ -119,8 +120,7 @@ public CompletableFuture<NavigateResult> findPathToNodes(PathPlayer<PlayerT> pla
NavigateLocation location = new CommonNavigateLocation(new PlayerNode(player));
location.setAgile(true);
return findPath(player, location, targets.stream()
.map(Node::getLocation)
.map(CommonNavigateLocation::staticLocation)
.map(CommonNavigateLocation::staticNode)
.collect(Collectors.toList()));
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public CompletableFuture<NavigateResult> findPath(PathPlayer<PlayerT> viewer, Na
navigateLocations.addAll(target);

// graph becomes static, so this step and all following must be repeated for each path update.
return getGraph(Collections.singleton(start), target).thenCompose(graph -> findPath(graph, start, target)).thenApply(path -> {
return getGraph(Collections.singleton(start), target).thenCompose(graph -> findPath(graph, start, target)).thenApply((path) -> {

NodeGroup highest = path.get(path.size() - 1).groups().stream()
.filter(g -> g.hasModifier(FindDistanceModifier.KEY))
Expand All @@ -168,9 +168,11 @@ public CompletableFuture<NavigateResult> findPath(PathPlayer<PlayerT> viewer, Na
return setPath(viewer, path, path.get(path.size() - 1).node().getLocation(), (float) findDist, !updating ? null : () -> {
return getGraph(Collections.singleton(start), target).thenCompose(graph -> findPath(graph, start, target)).join();
});

}).exceptionally(throwable -> {
throwable.printStackTrace();
}).exceptionally(t -> {
if (t.getCause().getCause() instanceof NoPathFoundException) {
return NavigateResult.FAIL_BLOCKED;
}
t.printStackTrace();
return NavigateResult.FAIL_UNKNOWN;
});
}
Expand Down Expand Up @@ -340,6 +342,7 @@ private CompletableFuture<MutableValueGraph<GroupedNode, Double>> getGraph(Colle
Collection<NavigateLocation> locations = new HashSet<>(entries);
locations.addAll(exits);

// TODO
// check if any agile location has changed. If not, just return the last graph.
if (false && cachedGraphWithTargets != null && locations.stream().filter(NavigateLocation::isAgile).map(NavigateLocation::getNode)
.map(Node::getLocation).toList().equals(cachedAgileLocations)) {
Expand All @@ -351,12 +354,16 @@ private CompletableFuture<MutableValueGraph<GroupedNode, Double>> getGraph(Colle
GraphEntrySolver<GroupedNode> solver = new EdgeBasedGraphEntrySolver();

for (NavigateLocation location : entries) {
if (!location.isExternal()) continue;

GroupedNode g = new SimpleGroupedNode(location.getNode(), new HashSet<>());
graph.addNode(g);
graph = solver.solveEntry(g, graph);
graph.successors(g).forEach((groupedNode) -> g.groups().addAll(groupedNode.groups()));
}
for (NavigateLocation location : exits) {
if (!location.isExternal()) continue;

GroupedNode g = new SimpleGroupedNode(location.getNode(), new HashSet<>());
graph.addNode(g);
graph = solver.solveExit(g, graph);
Expand Down Expand Up @@ -437,6 +444,7 @@ private CompletableFuture<MutableValueGraph<GroupedNode, Double>> createGraph()
static class CommonNavigateLocation implements NavigateLocation {

private final Node node;
private boolean external = true;
private boolean agile;

public static NavigateLocation agileNode(Node node) {
Expand All @@ -456,6 +464,12 @@ public Location getLocation() {
return navloc;
}

public static NavigateLocation staticNode(Node node) {
var n = new CommonNavigateLocation(node);
n.setExternal(false);
return n;
}

public static NavigateLocation staticLocation(Location location) {
Node n = new Waypoint(UUID.randomUUID());
n.setLocation(location);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.cubbossa.pathfinder;

public class StateMachine {

public enum State {
STARTUP,
RUNNING,
DUMPING,
SHUTDOWN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,25 +320,28 @@ public static MessageFormatter formatter() {
public static final Message CMD_DISCOVERIES_FOOTER = new MessageBuilder("commands.discoveries.list.footer")
.withDefault("<gradient:black:dark_gray:black>-------------<t> <click:run_command:/discoveries <prev-page>>←</click> <page>/<pages> <click:run_command:/discoveries <next-page>>→</click> </t>--------------</gradient>")
.withPlaceholders("page", "next-page", "prev-page", "pages")
.build();
.build();
public static final Message CMD_FIND_EMPTY = new MessageBuilder("commands.find.no_nodes_found")
.withDefault("<msg:prefix>No matching waypoints could be found.")
.build();
.withDefault("<msg:prefix>No matching waypoints could be found.")
.build();
public static final Message CMD_FIND_TOO_FAR = new MessageBuilder("commands.find.too_far_away")
.withDefault("<msg:prefix>The given location is too far away from any waypoint.")
.build();
.withDefault("<msg:prefix>The given location is too far away from any waypoint.")
.build();
public static final Message CMD_FIND_BLOCKED = new MessageBuilder("commands.find.no_path_found")
.withDefault("<msg:prefix>No possible way could be found to reach that target.")
.build();
.withDefault("<msg:prefix>No possible way could be found to reach that target.")
.build();
public static final Message CMD_FIND_UNKNOWN = new MessageBuilder("commands.find.unknown_error")
.withDefault("<c-negative>An unknown error occurred.</c-negative>")
.build();
public static final Message CMD_CANCEL = new MessageBuilder("commands.cancel_path")
.withDefault("<msg:prefix>Navigation cancelled.")
.build();
.withDefault("<msg:prefix>Navigation cancelled.")
.build();
public static final Message CMD_FINDP_OFFLINE = new MessageBuilder("commands.find_player.target_offline")
.withDefault("<c-negative>Player not found.</c-negative>")
.build();
.withDefault("<c-negative>Player not found.</c-negative>")
.build();
public static final Message CMD_FINDP_NO_SELF = new MessageBuilder("commands.find_player.no_requests_to_self")
.withDefault("<c-negative>You cannot make requests to yourself.</c-negative>")
.build();
.withDefault("<c-negative>You cannot make requests to yourself.</c-negative>")
.build();
public static final Message CMD_FINDP_NO_REQ = new MessageBuilder("commands.find_player.no_requests")
.withDefault("<c-negative>No requests found.</c-negative>")
.build();
Expand Down

0 comments on commit 41d2424

Please sign in to comment.