Skip to content

Commit

Permalink
Change OpenTTD#8001: Don't add docking tile cost when ships are still…
Browse files Browse the repository at this point in the history
… too far from their destination
  • Loading branch information
SamuXarick committed Feb 19, 2020
1 parent 4bc7883 commit 0b4cac0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/pathfinder/npf/npf.cpp
Expand Up @@ -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? */
Expand Down
8 changes: 5 additions & 3 deletions src/pathfinder/yapf/yapf_ship.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0b4cac0

Please sign in to comment.