I have done some more work since and the idea has evolved somewhat from the initial idea as a means to see if two tiles are in the same waterbody. Now I use it as a way to plot the "macro path" then just join the dots with landscaping, as it were. Also I have planned to include my canals methods in the process rather than a separate thing. Currently the code is incomplete and kind of a mess, but I have a detailed outline for how it will work:
1) Run water pathfinder with step size n = 10 and land costing disabled.
This pathfinder rapidly checks iff all tiles are water n distance apart using aystar. Land tiles are not allowed. (updated of the version I posted above to include land cost and changed to include diagonals (like railpathfinder), which is significantly quicker than the previous version.
Null return means tiles are not connected (subject to n accuracy) by same water body. Now we either try again with n++ or switch to canal pathfinder (goto 2).
True means we found a prospective path (goto 3).
2) Run canal pathfinder.
Uses the water pathfinder but allows for "tunnels" across land masses based on modified road pathfinder, these are then later joined with canals based on modified road builder (goto 3).
3) Run path builder.
This does a few things, on a path object returned by the pathfinders:
- If a node is flagged as "tunnel", build locks at each end and run canal builder between them (goto 4, then resume 3).
- If distance between nodes is > 1, run water pathfinder with n = 1, and enable land costing (goto 1). This is to ensure path is viable by a more traditional pathfinding way, and seeing of there is any land blocking the route by landscaping any "skipped" land bridges. In most cases this is not needed so its quite fast.
- If path has an associated land cost, run landscaping for each node function to ensure each is at sea level (or whatever baseline level).
- Every x tiles, build a buoy and add to a list object which stores the final "route" for ships. This can also be used for demolish.
- If we fail at any point, like we hit a ship or some new thing in the way etc, this has some recover capability. Error handle (wait for ship to move, etc) or find new path from last successful tile (goto 1).
4) Run canal builder.
For building canals between two locks. Very similar to road builder and includes some recover ability for runtime error encounters and demolish on hard fail.
Once this is all finished we have a table of tiles with buoys on. This should be saved so we can demolish routes to cleanup map, and possibly integrate a feature into pathfinder to reuse existing paths by detecting nearby buoys. List is also used to create the ships routes.
The non-canal parts are mostly done so will see if I can't have a testable version up. I think something like this is nice as it can rapidly and accurately build ship routes across long distances, especially now since 4048*2 maps are in trunk