Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
.idea
build
out
5 changes: 5 additions & 0 deletions src/main/java/shortestpath/ShortestPathConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ default int reachedDistance() {
default boolean avoidWilderness() {
return true;
}

@ConfigItem(keyName = "avoidSailingHazards", name = "Avoid sailing hazards", description = "Whether sailing hazard zones should be avoided if possible")
default boolean avoidSailingHazards() {
return true;
}
}
22 changes: 21 additions & 1 deletion src/main/java/shortestpath/ShortestPathPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
public class ShortestPathPlugin extends Plugin {
private static final WorldArea WILDERNESS_ABOVE_GROUND = new WorldArea(2944, 3523, 448, 448, 0);
private static final WorldArea WILDERNESS_UNDERGROUND = new WorldArea(2944, 9918, 320, 442, 0);
private static final WorldArea[] SAILING_HAZARDS = {
new WorldArea(2750, 2820, 320, 200, 0), // Stormy Seas (Storm Tempor / south Kharazi)
new WorldArea(2080, 2700, 480, 400, 0), // Fetid Waters (Breakbone/Backwater/Mythic/Souls)
new WorldArea(1700, 2800, 300, 200, 0), // Fetid Waters (Zul-Egil area)
new WorldArea(2100, 2100, 400, 250, 0), // Tangled Kelp (Rainbow Reef / Southern Expanse)
new WorldArea(1750, 3750, 1250, 350, 0), // Icy Seas (Northern Ocean)
new WorldArea(1750, 4050, 700, 250, 0), // Eternal Cold (Forgotten Ocean)
new WorldArea(2700, 4050, 350, 250, 0), // Eternal Cold (Grimstone area)
new WorldArea(3100, 2100, 500, 700, 0), // Cursed Seas (Eastern Ocean)
new WorldArea(3100, 2800, 400, 300, 0), // Scalding Seas (Untamed Ocean)
};
@Inject
public Client client;
@Inject
Expand Down Expand Up @@ -117,7 +128,7 @@ protected void startUp() {
if (target == null) {
path = null;
} else {
pathfinder = new Pathfinder(map, transports, client.getLocalPlayer().getWorldLocation(), target, config.avoidWilderness() && !isInWilderness(target));
pathfinder = new Pathfinder(map, transports, client.getLocalPlayer().getWorldLocation(), target, config.avoidWilderness() && !isInWilderness(target), config.avoidSailingHazards() && !isInSailingHazard(target));
path = pathfinder.find();
pathUpdateScheduled = false;
}
Expand Down Expand Up @@ -146,6 +157,15 @@ public static boolean isInWilderness(WorldPoint p) {
WILDERNESS_UNDERGROUND.distanceTo(p) == 0;
}

public static boolean isInSailingHazard(WorldPoint p) {
for (WorldArea hazard : SAILING_HAZARDS) {
if (hazard.distanceTo(p) == 0) {
return true;
}
}
return false;
}

@Subscribe
public void onMenuOpened(MenuOpened event) {
lastMenuOpenedPoint = client.getMouseCanvasPosition();
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/shortestpath/pathfinder/Pathfinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ public class Pathfinder {
private final Set<WorldPoint> visited = new HashSet<>();
private final Map<WorldPoint, List<WorldPoint>> transports;
private final boolean avoidWilderness;
private final boolean avoidSailingHazards;
private Node nearest;

public Pathfinder(CollisionMap map, Map<WorldPoint, List<WorldPoint>> transports, WorldPoint start, WorldPoint target, boolean avoidWilderness) {
public Pathfinder(CollisionMap map, Map<WorldPoint, List<WorldPoint>> transports, WorldPoint start, WorldPoint target, boolean avoidWilderness, boolean avoidSailingHazards) {
this.map = map;
this.transports = transports;
this.target = target;
this.start = new Node(start, null);
this.avoidWilderness = avoidWilderness;
this.avoidSailingHazards = avoidSailingHazards;
nearest = null;
}

Expand Down Expand Up @@ -99,6 +101,10 @@ private void addNeighbor(Node node, WorldPoint neighbor) {
return;
}

if (avoidSailingHazards && ShortestPathPlugin.isInSailingHazard(neighbor)) {
return;
}

if (!visited.add(neighbor)) {
return;
}
Expand Down
188 changes: 188 additions & 0 deletions src/main/resources/transports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,24 @@
3018 3231 0 2962 9650 0 Climb-down Manhole 10321
2962 9650 0 3018 3233 0 Climb-up Ladder 10309

# The Pandemonium
3027 3217 0 3065 3002 0 Travel Captain Tobias 14978
3028 3217 0 3065 3002 0 Travel Captain Tobias 14978
3029 3217 0 3065 3002 0 Travel Captain Tobias 14978
3027 3218 0 3065 3002 0 Travel Captain Tobias 14978
3028 3218 0 3065 3002 0 Travel Captain Tobias 14978
3029 3218 0 3065 3002 0 Travel Captain Tobias 14978
3065 3002 0 3029 3217 0 Travel Captain Tobias 14978
2949 3151 0 3065 3002 0 Travel Customs officer 14984
2950 3151 0 3065 3002 0 Travel Customs officer 14984
2951 3151 0 3065 3002 0 Travel Customs officer 14984
2949 3152 0 3065 3002 0 Travel Customs officer 14984
2950 3152 0 3065 3002 0 Travel Customs officer 14984
2951 3152 0 3065 3002 0 Travel Customs officer 14984
3065 3002 0 2950 3151 0 Travel Customs officer 14984
3046 2996 0 3046 9396 0 Enter Cave entrance 58092
3046 9396 0 3046 2996 0 Exit Cave exit 58092

# Wizard Tower
3105 3162 0 3104 9576 0 Climb-down Ladder 2147
3104 9576 0 3105 3162 0 Climb-up Ladder 2148
Expand Down Expand Up @@ -3884,3 +3902,173 @@
# Karamja
2910 3049 0 2906 3049 0 Cross A wooden log 23644
2906 3049 0 2910 3049 0 Cross A wooden log 23644

# Sailing
# The Pandemonium
3070 2987 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 3070 2987 0 Board Gangplank 59832
# Land's End
1507 3403 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1507 3403 0 Board Gangplank 59832
# Hosidius
1726 3452 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1726 3452 0 Board Gangplank 59832
# Musa Point
2961 3146 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2961 3146 0 Board Gangplank 59832
# Port Piscarilius
1845 3687 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1845 3687 0 Board Gangplank 59832
# Rimmington
2906 3225 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2906 3225 0 Board Gangplank 59832
# Catherby
2796 3412 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2796 3412 0 Board Gangplank 59832
# Brimhaven
2758 3230 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2758 3230 0 Board Gangplank 59832
# Ardougne
2671 3265 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2671 3265 0 Board Gangplank 59832
# Port Khazard
2686 3162 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2686 3162 0 Board Gangplank 59832
# Witchaven
2747 3305 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2747 3305 0 Board Gangplank 59832
# Entrana
2879 3336 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2879 3336 0 Board Gangplank 59832
# Civitas illa Fortis
1775 3142 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1775 3142 0 Board Gangplank 59832
# Corsair Cove
2580 2844 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2580 2844 0 Board Gangplank 59832
# Dognose Island
3061 2631 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 3061 2631 0 Board Gangplank 59832
# Cairn Isle
2750 2952 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2750 2952 0 Board Gangplank 59832
# Chinchompa Island
1893 3429 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1893 3429 0 Board Gangplank 59832
# Sunset Coast
1512 2974 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1512 2974 0 Board Gangplank 59832
# Remote Island
2972 2602 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2972 2602 0 Board Gangplank 59832
# The Summer Shore
3174 2367 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 3174 2367 0 Board Gangplank 59832
# The Little Pearl
3354 2216 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 3354 2216 0 Board Gangplank 59832
# Aldarin
1452 2970 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1452 2970 0 Board Gangplank 59832
# Vatrachos Island
1872 2984 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1872 2984 0 Board Gangplank 59832
# The Onyx Crest
2997 2288 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2997 2288 0 Board Gangplank 59832
# Ruins of Unkah
3144 2825 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 3144 2825 0 Board Gangplank 59832
# Shimmering Atoll
1557 2770 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1557 2770 0 Board Gangplank 59832
# Void Knights' Outpost
2651 2678 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2651 2678 0 Board Gangplank 59832
# Port Roberts
1861 3307 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1861 3307 0 Board Gangplank 59832
# Anglers' Retreat
2466 2720 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2466 2720 0 Board Gangplank 59832
# Minotaurs' Rest
1958 3116 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1958 3116 0 Board Gangplank 59832
# Isle of Souls
2283 2822 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2283 2822 0 Board Gangplank 59832
# Isle of Bones
2533 2530 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2533 2530 0 Board Gangplank 59832
# Laguna Aurorae
1202 2732 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1202 2732 0 Board Gangplank 59832
# Charred Island
2660 2394 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2660 2394 0 Board Gangplank 59832
# Tear of the Soul
2318 2773 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2318 2773 0 Board Gangplank 59832
# Rellekka
2630 3705 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2630 3705 0 Board Gangplank 59832
# Wintumber Island
2057 2605 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2057 2605 0 Board Gangplank 59832
# The Crown Jewel
1765 2658 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1765 2658 0 Board Gangplank 59832
# Etceteria
2613 3840 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2613 3840 0 Board Gangplank 59832
# Port Tyras
2144 3120 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2144 3120 0 Board Gangplank 59832
# Lledrith Island
2097 3187 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2097 3187 0 Board Gangplank 59832
# Deepfin Point
1923 2758 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1923 2758 0 Board Gangplank 59832
# Jatizso
2412 3780 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2412 3780 0 Board Gangplank 59832
# Neitiznot
2309 3782 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2309 3782 0 Board Gangplank 59832
# Rainbow's End
2345 2269 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2345 2269 0 Board Gangplank 59832
# Prifddinas
2158 3324 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2158 3324 0 Board Gangplank 59832
# Sunbleak Island
2189 2326 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2189 2326 0 Board Gangplank 59832
# Ynysdail
2222 3464 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2222 3464 0 Board Gangplank 59832
# Waterbirth Island
2543 3765 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2543 3765 0 Board Gangplank 59832
# Piscatoris
2304 3689 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2304 3689 0 Board Gangplank 59832
# Lunar Isle
2152 3881 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2152 3881 0 Board Gangplank 59832
# Buccaneers' Haven
2080 3690 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2080 3690 0 Board Gangplank 59832
# Drumstick Isle
2150 3529 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2150 3529 0 Board Gangplank 59832
# Weiss
2861 3971 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2861 3971 0 Board Gangplank 59832
# Brittle Isle
1954 4055 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 1954 4055 0 Board Gangplank 59832
# Grimstone
2928 4055 0 3051 3193 0 Board Gangplank 59832
3051 3193 0 2928 4055 0 Board Gangplank 59832
48 changes: 48 additions & 0 deletions src/test/java/pathfinder/HazardAvoidanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package pathfinder;

import net.runelite.api.coords.WorldPoint;
import org.junit.Test;
import shortestpath.ShortestPathPlugin;

import static org.junit.Assert.*;

public class HazardAvoidanceTest {
@Test
public void stormySeas() {
// Center of Stormy Seas region (2750, 2820, 320, 200)
assertTrue(ShortestPathPlugin.isInSailingHazard(new WorldPoint(2900, 2900, 0)));
}

@Test
public void fetidWaters() {
// Center of Fetid Waters region (2080, 2700, 480, 400)
assertTrue(ShortestPathPlugin.isInSailingHazard(new WorldPoint(2300, 2900, 0)));
}

@Test
public void icySeas() {
// Center of Icy Seas region (1750, 3750, 1250, 350)
assertTrue(ShortestPathPlugin.isInSailingHazard(new WorldPoint(2375, 3900, 0)));
}

@Test
public void safeWaters() {
// Tile well outside all hazard zones (near Lumbridge)
assertFalse(ShortestPathPlugin.isInSailingHazard(new WorldPoint(3222, 3218, 0)));
}

@Test
public void hazardEdge() {
// Just inside Stormy Seas SW corner
assertTrue(ShortestPathPlugin.isInSailingHazard(new WorldPoint(2750, 2820, 0)));
// One tile outside
assertFalse(ShortestPathPlugin.isInSailingHazard(new WorldPoint(2749, 2820, 0)));
}

@Test
public void wildernessUnchanged() {
// Verify wilderness check still works independently
assertTrue(ShortestPathPlugin.isInWilderness(new WorldPoint(3100, 3600, 0)));
assertFalse(ShortestPathPlugin.isInWilderness(new WorldPoint(3222, 3218, 0)));
}
}