• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Vote for the theme of Hive's HD Modeling Contest #7! Click here to vote! - Please only vote if you plan on participating❗️

Find Shortest Path

Status
Not open for further replies.
Is there a system out there that can find the shortest path a ground unit can take from point A to point B? GetCloestsWidget was useful for a custom harvesting system up until it dawned onto me that if a town hall is closer but up on a cliff or something, my workers will try to go to it instead of taking a shorter route to a farther town hall that's they will get to faster.
 
Only a few systems have been made to accomplish this:
http://www.wc3c.net/showthread.php?t=89813

Pathfinding is quite expensive to compute, especially through an interpreted language like JASS. Sometimes it may be better to take advantage of the built-in system. If it is a gold mine system, then take advantage of the fact that gold mines are preplaced on the map. Lumber systems, even if they are preplaced, are a bit tricky since they are so plentiful--so yeah you might need a pathfinding algorithm.
 
Hmm, I'm not entirely sure in what way it'll be performance-heavy (I'm not well versed in JASS), but all I need is to pick the closest town hall in term of pathing, then order a unit to move to the town hall's location. I don't need it to stick to a path - once the order is given, the unit moves on it's own. Is there any difference there or would that require the same amount of computing power?
 
Level 15
Joined
Aug 7, 2013
Messages
1,341
Is there a system out there that can find the shortest path a ground unit can take from point A to point B? GetCloestsWidget was useful for a custom harvesting system up until it dawned onto me that if a town hall is closer but up on a cliff or something, my workers will try to go to it instead of taking a shorter route to a farther town hall that's they will get to faster.

Purgefire is correct, that in the general case what you want to do is computationally 'expensive'. He can go into the actual details and theory of why.

Consider your town hall case. Suppose town hall A is located on a cliff right above the gold mine, and town hall B is located further absolute distance away, but in reality because your workers don't fly, it takes more distance to get to A.

Warcraft doesn't compute this by default, and it's dynamic because you can put your town halls anywhere and it changes.

Here is one silly solution with caching, you could modify it depending on your needs:

If you have at least 2 Town Halls (TH) and a worker has gathered a resource:
Create a very fast ground unit with these properties:
a. Zero collision (walks through other units)
b. Moves very very fast
c. Invisible, uncontrollable, unkillable
For each TH:
Order the unit to move to that TH and time it
For the worker (or custom resource), set a flag saying that the worker
should go to that TH everytime it returns the resource.
Cache this value, so you don't recompute for the worker (or custom goldmine).
Whenever you make a new TH, you recompute.
Whenever the worker starts mining from a new resource, you recompute.
Whenever you order the worker to return a resource, you recompute.
 
Status
Not open for further replies.
Top