What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Get path between two GpsPoints?

I'm trying to create a plugin that uses airships to do trade runs.
To find the fastest route to the end point, I need to be able to know the distance from me to the airship dock (no, problem here). And I also need to know the distance from the second airship dock to the end location. Currently I'm finding the distance of a path using the following code.

Code:
public float GetDistanceToPoint(string nextLocation)
        {

            //Get path to point and iterate trough the path, each time adding the distance between x and x+1 points
            List<GpsPoint> path = gps.GpsGetPath(nextLocation);
            float distance = 0f;
            for (int x = 1; x < path.Capacity; x++)
            {
                distance += (float)path.ElementAt(x).dist(path.ElementAt(x + 1));
            }
            return distance;

        }

I can utilize this to get the distance between the player and a point, but not between two points.
 
I'm trying to create a plugin that uses airships to do trade runs.
To find the fastest route to the end point, I need to be able to know the distance from me to the airship dock (no, problem here). And I also need to know the distance from the second airship dock to the end location. Currently I'm finding the distance of a path using the following code.

Code:
public float GetDistanceToPoint(string nextLocation)
        {

            //Get path to point and iterate trough the path, each time adding the distance between x and x+1 points
            List<GpsPoint> path = gps.GpsGetPath(nextLocation);
            float distance = 0f;
            for (int x = 1; x < path.Capacity; x++)
            {
                distance += (float)path.ElementAt(x).dist(path.ElementAt(x + 1));
            }
            return distance;

        }

I can utilize this to get the distance between the player and a point, but not between two points.

I don't get it...that code can already do exactly what you're asking?
 
If I get this correctly, he's getting the distance from his character to a destination, but wants to get the distance between 2 points he's not at.

A possible workaround for you mario6117 might be to cache all the distances from airship towers to your destinations.
 
If I get this correctly, he's getting the distance from his character to a destination, but wants to get the distance between 2 points he's not at.

A possible workaround for you mario6117 might be to cache all the distances from airship towers to your destinations.

Yes Karis, that's exactly what I'm trying to do.
The thing you're suggesting is indeed a good idea, but it'll require a lot more work since I'll be having many destination points. (one to every trader on the eastern continent)
 
Yeah but he already has the code to loop X points...just because the whole method starts on the path from his character doesn't mean you can't start tracking the distance later in the loop and only track distance on those between your points. Give all airship waypoints a name following the same pattern and just check for it in your loop over the full route?
 
I'd wait on Out to give you a yes/no answer to implementing it in AB, but it should be quite doable to cache in some "not-a-chore" way:
- Figure out a way to store/load the data that works for you
- When the plugin tries to calculate an airship route that doesn't have the real distance cached, approximate it by some dirty calc (the length in a straight line from tower to trader/workbench * 2-3) to decide if it's worth it to explore that route
- When you're at airship tower, calculate the distances to all workbenches/traders that haven't been stored yet (and if you keep updating your DB3 file to fine-tune pathing, maybe add a timestamp to the cached distances, to refresh them every once in a while)
- After a few of these learning runs you should have quite an efficient bot

Edit for above: I assumed his routes stopped at the airship tower, so the path he gets to destination wouldn't include the airship towers.
 
Last edited:
Sidalol, let me illustrate this (with a shitty paint drawing)
View attachment 145125

(You might have to zoom in)
Imagine the player is at point A.
We can easily get the path from point A to B (gps.GpsGetPath("B")).
Now, I also want to get the path from C to D, this is currently not possible. So I'll need to work around this somehow.

I'd wait on Out to give you a yes/no answer to implementing it in AB, but it should be quite doable to cache in some "not-a-chore" way:
- Figure out a way to store/load the data that works for you
- When the plugin tries to calculate an airship route that doesn't have the real distance cached, approximate it by some dirty calc (the length in a straight line from tower to trader/workbench * 2-3) to decide if it's worth it to explore that route
- When you're at airship tower, calculate the distances to all workbenches/traders that haven't been stored yet (and if you keep updating your DB3 file to fine-tune pathing, maybe add a timestamp to the cached distances, to refresh them every once in a while)
- After a few of these learning runs you should have quite an efficient bot

Edit for above: I assumed his routes stopped at the airship tower, so the path he gets to destination wouldn't include the airship towers.

Thank you for your input Karls, you're a huge help :).
I'm thinking of creating my own gps system actually, as the current one seems to have too little options available.
 
Last edited:
The image doesn't load but I still don't see why this is so much of a problem.

Create your gps route with 3 points:
- Airship start dock
- Airship end dock
- End point

So the points you're interested in are:

A (start)
B (airship entrance)
C (airship exit)
D (end)

You're already able to loop over every point to get the distance of AD...which means you've already looped over all points along CD. If they had names such as "Airship Entrance" then you can easily just look for these in your loop no? And since you said you're going to have multiple of these you can simply name them like "Airship Entrance-1" and regex match the point name to know you've hit C.

Edit: Oh and if you can't follow BC because they're not linked, just link them with a big-ass straight line between the points. As far as you're concerned it doesn't matter, the link is just there so you can return the full route of AD to iterate over the points.
 
Last edited:
The image doesn't load but I still don't see why this is so much of a problem.

Create your gps route with 3 points:
- Airship start dock
- Airship end dock
- End point

So the points you're interested in are:

A (start)
B (airship entrance)
C (airship exit)
D (end)

You're already able to loop over every point to get the distance of AD...which means you've already looped over all points along CD. If they had names such as "Airship Entrance" then you can easily just look for these in your loop no? And since you said you're going to have multiple of these you can simply name them like "Airship Entrance-1" and regex match the point name to know you've hit C.

Edit: Oh and if you can't follow BC because they're not linked, just link them with a big-ass straight line between the points. As far as you're concerned it doesn't matter, the link is just there so you can return the full route of AD to iterate over the points.

B and C aren't linked. If they were, the bot might sometimes take a path on foot even tough the airship path may be faster
 
B and C aren't linked. If they were, the bot might sometimes take a path on foot even tough the airship path may be faster

It doesn't matter if they're linked. You're already specifying a point name for B so the bot will never try to run to C. That link's only purpose is for you to retrieve the route.
 
I'm confused now xD.
It seems like we aren't really in sync on this.
 
You are explicitly telling your bot to move to point B, so regardless of whether the path extends through C and D it still won't walk past B.
 
Yes, But I don't know wether the bot should move to point B, that's what I'm trying to figure out.

If the walking route for A -> D is smaller than A -> B + C -> D, then use the walking route, else use the airship route.
The problem is that it's impossible to get C -> D without being at point C
 
I assume you're doing something like this:

fa4df19d19.png


Even if your path stretches all the way from A > B > C > D, when you tell your bot to move to "B" it will just move to "B". Then since you have the full route mapped, you can do gps.GpsGetPath("D") to get the full route, iterate over the GpsPoints until you find one named "Airship End" or whatever and then start tracking the distance from then on, giving you only the distance of CD.

Edit: You have to start at A for this to work, now I see the issue, though I assume the calculations you're doing are to find the closest point from your current spot so it should work fine.
 
Last edited:
screen.webp
attachment.php


Now imagine A > B > E > D is shorter than A > B > C > D
The bot will then take the first path, even tough the airship path might be faster.

Edit: I really have no idea why the picture is just not showing -_-
Edit2: There, hope this works :p
 
Last edited:
Those attachments don't work, you need to untick the box in the window that pops up ;p
 
Your question was how to find the distance between two points. Whether you use my method or Out adds something to the API, neither will make any difference to the question you asked about A > B > E > D. I assume the reason you want to know the distance between two points is to calculate the best route manually...so whether the bot would take the wrong route or not doesn't matter since you're never going to directly be telling it to move to D (otherwise it'd never use airships).
 
Back
Top