New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5713: Use pathfinder to find closest ship depot #6928

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@SamuXarick
Copy link
Contributor

SamuXarick commented Oct 1, 2018

When ships are asked to find the closest depot, the depot that is provided is not always reachable. This patch provides the closest reachable ship depot, by utilizing the pathfinder (Original, NPF or Yapf) first. Only if it fails, it would then be provided by the original method, distance manhattan based.

https://www.tt-forums.net/viewtopic.php?f=33&t=76137

@nielsmh
Copy link
Contributor

nielsmh left a comment

I don't like this approach at all. It's far too intrusive and adds far too many special cases to the pathfinding code, which is already very complex. Start over with something simpler that doesn't need to change code in all the pathfinders.

@nielsmh

This comment has been minimized.

Copy link
Contributor

nielsmh commented Nov 1, 2018

An idea for an alternate approach could be to insert the logic in ShipController instead. If after ChooseShipTrack the VF_PATHFINDER_LOST flag is set, and the current order is go to depot (and it's not a scheduled order) then select a different depot and try again. It's probably necessary to keep a list of depots already tried (and failed), but it can just be local to the ship controller function.

Of course that won't handle the case of OPF, since that never signals no path found. I would suggest not doing anything about that for now, but maybe make a separate change that keeps track of how far a ship has sailed since it last completed an order, and compare that to the expected distance, and send a warning to the player if the ship appears to be taking too long.

@nielsmh

This comment has been minimized.

Copy link
Contributor

nielsmh commented Nov 2, 2018

I tried implementing the approach I outlined above, it's probably not complete like this, but it's significantly shorter and touches much less code: nielsmh@fd90477

@TrueBrain

This comment has been minimized.

Copy link
Member

TrueBrain commented Jan 5, 2019

We recently switched from Jenkins as CI to Azure Pipelines as CI. This means you need to rebase before this Pull Request will pass its checks. Sorry for the troubles!

@SamuXarick SamuXarick force-pushed the SamuXarick:find-closest-reachable-ship-depot branch from e556519 to b8b7878 Jan 10, 2019

@SamuXarick

This comment has been minimized.

Copy link
Contributor

SamuXarick commented Jan 10, 2019

@nielsmh
I just experimented your approach and it causes stalls during gameplay when there's too many unreachable depots nearby. It calls the pathfinder for everyone of them.

@J0anJosep has already implemented part of what I had in mind for npf, which got into master, and some of the complexity that was on npf.cpp is gone. Unless you mean the other changes...

@SamuXarick SamuXarick force-pushed the SamuXarick:find-closest-reachable-ship-depot branch from b8b7878 to e4a026e Jan 10, 2019

@nielsmh
Copy link
Contributor

nielsmh left a comment

Still think this looks like too much complexity to attempt to improve a few corner cases.

Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.h Outdated
Show resolved Hide resolved src/ship_cmd.cpp Outdated
Show resolved Hide resolved src/ship_cmd.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated
Show resolved Hide resolved src/pathfinder/opf/opf_ship.cpp Outdated

@SamuXarick SamuXarick force-pushed the SamuXarick:find-closest-reachable-ship-depot branch 3 times, most recently from 3060a64 to a5c5df2 Jan 12, 2019

@SamuXarick

This comment has been minimized.

Copy link
Contributor

SamuXarick commented Jan 12, 2019

NoNoCAB v5 (O) 1.7.2.zip
Savegame with 5000 ships for testing

Show resolved Hide resolved src/pathfinder/npf/npf.cpp
@@ -180,7 +187,7 @@ bad:;
} while (bits != TRACK_BIT_NONE);

*track = best_track;
return best_bird_dist;
return best_length;

This comment has been minimized.

@nielsmh

nielsmh Jan 12, 2019

Contributor

This will probably require a lot of testing since I can imagine it affecting the pathfinder's results significantly.

This comment has been minimized.

@SamuXarick

SamuXarick Jan 12, 2019

Contributor

Just tested, it is reversing in situations where it shouldn't, for example, after departing from a dock, where the next order is closer if the ships reverses direction. Gonna revert and come up with something else.

case VPF_NPF: return NPFShipFindNearestDepot(v, max_distance);
case VPF_YAPF: return YapfShipFindNearestDepot(v, max_distance);

default: NOT_REACHED();

This comment has been minimized.

@nielsmh

nielsmh Jan 12, 2019

Contributor

Indentation does not match the above

@SamuXarick SamuXarick force-pushed the SamuXarick:find-closest-reachable-ship-depot branch from a5c5df2 to 74e3985 Jan 13, 2019

@SamuXarick

This comment has been minimized.

Copy link
Contributor

SamuXarick commented Jan 16, 2019

SamuXarick added some commits Oct 1, 2018

Fix #5713: Use pathfinder to find closest ship depot
When ships are asked to find the closest depot, the depot that is provided is not always reachable. This patch provides the closest reachable ship depot, by utilizing the pathfinder (Original, NPF or Yapf) first. Only if it fails, it would then be provided by the original method, distance manhattan based.

@SamuXarick SamuXarick force-pushed the SamuXarick:find-closest-reachable-ship-depot branch from 4ba1fe3 to 7a9d5c1 Jan 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment