Skip to content

Fix sea path finding (for ships)#1917

Open
Flamefire wants to merge 12 commits into
Return-To-The-Roots:masterfrom
Flamefire:fixShipConnections
Open

Fix sea path finding (for ships)#1917
Flamefire wants to merge 12 commits into
Return-To-The-Roots:masterfrom
Flamefire:fixShipConnections

Conversation

@Flamefire
Copy link
Copy Markdown
Member

@Flamefire Flamefire commented Apr 25, 2026

If a harbor is too far we will not find the path even though it exists, see the previous TODO.
Issue happened in the map where there was a triangle of water with land in the middle.

A ship was moving between 2 far away harbors when one was destroyed.

When going home we limit the maximum distance by the longest connections of HomeHarbor which might not be enough

Pathfinding considered the current harbor when looking for connections which is not useful and required extra steps.
--> Removed together with GamePlayer::AddHarborsAtSea which was only used there and added test

I found this while debugging the previous seafaring issue.
When letting it continue to run on the triangle-map mostly land with a triangle shaped straight of water it would run into the assert.

Additional:
CreateTradeGraphs simply created a cache instance but must be manually invoked or it will crash at runtime.
Remove the method and create the instance on first access for consistency

@Flamefire Flamefire force-pushed the fixShipConnections branch 2 times, most recently from 4149525 to 3198d59 Compare May 7, 2026 15:51
@Flamefire Flamefire marked this pull request as ready for review May 7, 2026 15:54
@Flamefire Flamefire force-pushed the fixShipConnections branch from 3198d59 to 3d707b9 Compare May 7, 2026 16:06
@Flamefire Flamefire requested a review from Flow86 May 10, 2026 07:47
Flamefire added 11 commits May 10, 2026 09:48
Not required (anymore), trade path cache can be created on demand.
It could be possible that 2 harbors are at the same 2 seas.
The current harbor connections do not honor this and only store a single distance which would hence be wrong for one of those 2.
Store the seaId for each connection.
Do not try to limit pathfinding for ships.
Instead store the most common routes: Those between harbors in a small, fast lookup table.
For other routes, e.g. from shipyards or lost ships, use a LRU cache and fall back to unlimited search.
There is no meaningful result for all out-parameters in the base
pathfinding implementation.
When we are already at the goal `WanderOnWater` changes the state to
reflect it. So we must ensure to change the state only before, not after
the call to this function.
@Flamefire Flamefire force-pushed the fixShipConnections branch from 99d95e5 to bbb8cab Compare May 10, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant