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'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.
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.
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.
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