From 750b200d90f8c192e213526dd9def37e01de8357 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Wed, 25 Feb 2015 23:50:42 -0500 Subject: [PATCH 1/3] Use the Positions hashcode implementation and utilize toStringHelper within Node. --- src/org/apollo/game/model/entity/path/Node.java | 7 ++++--- .../game/model/entity/path/SimplePathfindingAlgorithm.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/org/apollo/game/model/entity/path/Node.java b/src/org/apollo/game/model/entity/path/Node.java index 096cc843..1028abb8 100644 --- a/src/org/apollo/game/model/entity/path/Node.java +++ b/src/org/apollo/game/model/entity/path/Node.java @@ -5,6 +5,8 @@ import java.util.Optional; import org.apollo.game.model.Position; +import com.google.common.base.MoreObjects; + /** * A node representing a weighted {@link Position}. * @@ -100,7 +102,7 @@ final class Node { @Override public int hashCode() { - return position.getX() * 31 + position.getY(); + return position.hashCode(); } /** @@ -141,8 +143,7 @@ final class Node { @Override public String toString() { - return Node.class.getSimpleName() + " [x=" + position.getX() + ", y=" + position.getY() + ", open=" + open + ", cost=" - + cost + "]"; + return MoreObjects.toStringHelper(this).add("position", position).add("open", open).add("cost", cost).toString(); } } \ No newline at end of file diff --git a/src/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java b/src/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java index 21d62763..0ef4b77d 100644 --- a/src/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java +++ b/src/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java @@ -8,7 +8,7 @@ import org.apollo.game.model.Position; /** * A very simple pathfinding algorithm that simply walks in the direction of the target until it either reaches it or is - * blocked. TODO diagonal movement support. + * blocked. * * @author Major */ From f0b6208d951f0a3c7ee3da64f69fed2812411720 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Wed, 25 Feb 2015 23:51:14 -0500 Subject: [PATCH 2/3] Remove the redundant createIfAbsent method within the AStarPathfindingAlgorithm. --- .../path/AStarPathfindingAlgorithm.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java b/src/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java index 12c0d410..eb06d263 100644 --- a/src/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java +++ b/src/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java @@ -71,7 +71,7 @@ final class AStarPathfindingAlgorithm extends PathfindingAlgorithm { Position adjacent = new Position(nextX, nextY); if (traversable(adjacent)) { - Node node = createIfAbsent(adjacent, nodes); + Node node = nodes.computeIfAbsent(adjacent, Node::new); compare(active, node, open, sorted, heuristic); } } @@ -118,24 +118,6 @@ final class AStarPathfindingAlgorithm extends PathfindingAlgorithm { } } - /** - * Creates a {@link Node} and inserts it into the specified {@link Map} if one does not already exist, then returns - * that node. - * - * @param position The {@link Position}. - * @param nodes The map of positions to nodes. - * @return The node. - */ - private Node createIfAbsent(Position position, Map nodes) { - Node existing = nodes.get(position); - if (existing == null) { - existing = new Node(position); - nodes.put(position, existing); - } - - return existing; - } - /** * Gets the cheapest open {@link Node} from the {@link Queue}. * From 7c09ab1433051ef5c0bddd28404140cbc8a7feb5 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Thu, 26 Feb 2015 00:25:05 -0500 Subject: [PATCH 3/3] Add object obstruction to object definitions. --- .../fs/decoder/ObjectDefinitionDecoder.java | 2 ++ .../game/model/def/ObjectDefinition.java | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java index 765acfda..672e633b 100644 --- a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java @@ -120,6 +120,8 @@ public final class ObjectDefinitionDecoder { data.get(); } else if (opcode >= 70 && opcode <= 72) { data.getShort(); + } else if (opcode == 73) { + definition.setObstructive(true); } else if (opcode == 75) { data.get(); } else { diff --git a/src/org/apollo/game/model/def/ObjectDefinition.java b/src/org/apollo/game/model/def/ObjectDefinition.java index 98e1aa02..a890b4cc 100644 --- a/src/org/apollo/game/model/def/ObjectDefinition.java +++ b/src/org/apollo/game/model/def/ObjectDefinition.java @@ -82,6 +82,11 @@ public final class ObjectDefinition { */ private boolean interactive; + /** + * Denotes whether or not this object obstructs the ground. + */ + private boolean obstructive; + /** * This object's length. */ @@ -173,7 +178,8 @@ public final class ObjectDefinition { /** * Indicates the impenetrability of this object. * - * @return {@code true} if this object is impenetrable, otherwise {@code false}. + * @return {@code true} if this object is impenetrable, otherwise + * {@code false}. */ public boolean isImpenetrable() { return impenetrable; @@ -182,12 +188,23 @@ public final class ObjectDefinition { /** * Indicates the interactivity of this object. * - * @return {@code true} if the object is interactive, otherwise {@code false}. + * @return {@code true} if the object is interactive, otherwise + * {@code false}. */ public boolean isInteractive() { return interactive; } + /** + * Indicates whether or not this object obstructs the ground. + * + * @return {@code true} if the object obstructs the ground otherwise + * {@code false}. + */ + public boolean isObstructive() { + return obstructive; + } + /** * Indicates the solidity of this object. * @@ -269,4 +286,13 @@ public final class ObjectDefinition { this.width = width; } + /** + * Sets whether or not this object is obstructive to the ground. + * + * @param obstructive Whether or not this object obstructs the ground. + */ + public void setObstructive(boolean obstructive) { + this.obstructive = obstructive; + } + } \ No newline at end of file