diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index 335a589ef6..fcb2e3759c 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -388,6 +388,13 @@ public: uint8_t speed_frac = (GetEffectiveWaterClass(n.GetTile()) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac; if (speed_frac > 0) c += YAPF_TILE_LENGTH * (1 + tf->tiles_skipped) * speed_frac / (256 - speed_frac); + /* Lock penalty. */ + if (IsTileType(n.GetTile(), MP_WATER) && IsLock(n.GetTile()) && GetLockPart(n.GetTile()) == LOCK_PART_MIDDLE) { + const uint canal_speed = svi->ApplyWaterClassSpeedFrac(svi->max_speed, false); + /* Cost is proportional to the vehicle's speed as the vehicle stops in the lock. */ + c += (TILE_HEIGHT * YAPF_TILE_LENGTH * canal_speed) / 128; + } + /* Apply it. */ n.cost = n.parent->cost + c; return true;