diff options
author | Peter Nelson <peter1138@openttd.org> | 2019-02-15 16:50:04 +0000 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-03-08 16:52:08 +0100 |
commit | 7ca1793ec4d75c99de41dc27431c3b9c8353d7a1 (patch) | |
tree | 4f0e8b42a0ef18404e580f277c91c9b300bc0a55 /src/pathfinder/yapf | |
parent | b8a0107ad157e946c46a4e65cb3f63bec1812670 (diff) | |
download | openttd-7ca1793ec4d75c99de41dc27431c3b9c8353d7a1.tar.xz |
Change: Automatically use Trackdir node key as needed if ship curve penalties differ.
Diffstat (limited to 'src/pathfinder/yapf')
-rw-r--r-- | src/pathfinder/yapf/yapf_ship.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index c71bf8af5..63abd592e 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -241,6 +241,16 @@ struct CYapfShip1 : CYapfT<CYapfShip_TypesT<CYapfShip1, CFollowTrackWater , C /* YAPF type 2 - uses TileIndex/DiagDirection as Node key */ struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , CShipNodeListExitDir > > {}; +static inline bool RequireTrackdirKey() +{ + /* If the two curve penalties are not equal, then it is not possible to use the + * ExitDir keyed node list, as it there will be key overlap. Using Trackdir keyed + * nodes means potentially more paths are tested, which would be wasteful if it's + * not necessary. + */ + return _settings_game.pf.yapf.ship_curve45_penalty != _settings_game.pf.yapf.ship_curve90_penalty; +} + /** Ship controller helper - path finder invoker */ Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache) { @@ -249,7 +259,7 @@ Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir /* check if non-default YAPF type needed */ - if (_settings_game.pf.yapf.disable_node_optimization) { + if (_settings_game.pf.yapf.disable_node_optimization || RequireTrackdirKey()) { pfnChooseShipTrack = &CYapfShip1::ChooseShipTrack; // Trackdir } @@ -267,7 +277,7 @@ bool YapfShipCheckReverse(const Ship *v) PfnCheckReverseShip pfnCheckReverseShip = CYapfShip2::CheckShipReverse; // default: ExitDir /* check if non-default YAPF type needed */ - if (_settings_game.pf.yapf.disable_node_optimization) { + if (_settings_game.pf.yapf.disable_node_optimization || RequireTrackdirKey()) { pfnCheckReverseShip = &CYapfShip1::CheckShipReverse; // Trackdir } |