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.