From 10606d32aa39a413a93a376dad081bb14093cbfa Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:59:57 +0000 Subject: [PATCH] Fix #11862: Ships leaving docks could be momentarily lost When a ship is departing from a dock, and wants to go back to it again, the destination tile is set as the origin, making the ship have a OT_LEAVESTATION OrderType. With this order type, the docking tiles aren't added as origins even though the tile is still that of a dock. OT_LEAVESTATION OrderType still has the same destination as that of OT_GOTO_STATION, so assume they still belong to the same dock. --- src/pathfinder/yapf/yapf_ship.cpp | 3 ++- src/pathfinder/yapf/yapf_ship_regions.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index a5b9fc3e13..b4e2d57a2f 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -44,8 +44,9 @@ protected: public: void SetDestination(const Ship *v) { - if (v->current_order.IsType(OT_GOTO_STATION)) { + if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_LEAVESTATION)) { this->dest_station = v->current_order.GetDestination(); + assert(Station::IsValidID(this->dest_station)); this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, StationType::Dock); this->dest_trackdirs = INVALID_TRACKDIR_BIT; } else { diff --git a/src/pathfinder/yapf/yapf_ship_regions.cpp b/src/pathfinder/yapf/yapf_ship_regions.cpp index 36a939ea74..6c79838694 100644 --- a/src/pathfinder/yapf/yapf_ship_regions.cpp +++ b/src/pathfinder/yapf/yapf_ship_regions.cpp @@ -184,8 +184,9 @@ public: Tpf pf(std::min(static_cast(Map::Size() * NODES_PER_REGION) / WATER_REGION_NUMBER_OF_TILES, MAX_NUMBER_OF_NODES)); pf.SetDestination(start_water_region_patch); - if (v->current_order.IsType(OT_GOTO_STATION)) { + if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_LEAVESTATION)) { DestinationID station_id = v->current_order.GetDestination(); + assert(Station::IsValidID(station_id)); const BaseStation *station = BaseStation::Get(station_id); TileArea tile_area; station->GetTileArea(&tile_area, StationType::Dock);