From 0b4cac0d7706a04079bb5a2e211b6ad4dc1051cc Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Tue, 18 Feb 2020 17:02:19 +0000 Subject: [PATCH] Change #8001: Don't add docking tile cost when ships are still too far from their destination --- src/pathfinder/npf/npf.cpp | 13 +++++++++---- src/pathfinder/yapf/yapf_ship.cpp | 8 +++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 34b85791bd79e..94c33cd0b80c6 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -328,10 +328,15 @@ static int32 NPFWaterPathCost(AyStar *as, AyStarNode *current, OpenListNode *par } if (IsDockingTile(current->tile)) { - /* Check docking tile for occupancy */ - uint count = 1; - HasVehicleOnPos(current->tile, &count, &CountShipProc); - cost += count * 3 * _trackdir_length[trackdir]; + NPFFindStationOrTileData *fstd = (NPFFindStationOrTileData*)as->user_target; + if (IsShipDestinationTile(current->tile, fstd->v->current_order.GetDestination()) && fstd->v->current_order.IsType(OT_GOTO_STATION)) { + /* Check docking tile for occupancy */ + uint count = 0; + if (DistanceManhattan(CalcClosestStationTile(fstd->v->current_order.GetDestination(), fstd->v->tile, STATION_DOCK), fstd->v->tile) < 16) { + HasVehicleOnPos(current->tile, &count, &CountShipProc); + } + cost += count * 3 * _trackdir_length[trackdir]; + } } /* @todo More penalties? */ diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index 2f2ed7e441f53..fe3045209bf50 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -285,10 +285,12 @@ class CYapfCostShipT /* additional penalty for curves */ c += CurveCost(n.m_parent->GetTrackdir(), n.GetTrackdir()); - if (IsDockingTile(n.GetTile())) { + if (IsDockingTile(n.GetTile()) && IsShipDestinationTile(n.GetTile(), Yapf().GetVehicle()->current_order.GetDestination()) && Yapf().GetVehicle()->current_order.IsType(OT_GOTO_STATION)) { /* Check docking tile for occupancy */ - uint count = 1; - HasVehicleOnPos(n.GetTile(), &count, &CountShipProc); + uint count = 0; + if (DistanceManhattan(CalcClosestStationTile(Yapf().GetVehicle()->current_order.GetDestination(), Yapf().GetVehicle()->tile, STATION_DOCK), Yapf().GetVehicle()->tile) < 16) { + HasVehicleOnPos(n.GetTile(), &count, &CountShipProc); + } c += count * 3 * YAPF_TILE_LENGTH; }