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.
This commit is contained in:
SamuXarick 2024-01-21 21:59:57 +00:00
parent ce3d0097f6
commit 9eb9c03a05
3 changed files with 6 additions and 4 deletions

View File

@ -1126,14 +1126,14 @@ static void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, const Vehicle *
* dest_tile, not just any stop of that station.
* So only for train orders to stations we fill fstd->station_index, for all
* others only dest_coords */
if (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_WAYPOINT)) {
if (v->current_order.IsType(OT_GOTO_STATION) || (v->current_order.IsType(OT_LEAVESTATION) && v->type == VEH_SHIP) || v->current_order.IsType(OT_GOTO_WAYPOINT)) {
fstd->station_index = v->current_order.GetDestination();
if (v->type == VEH_TRAIN) {
fstd->station_type = v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT;
} else if (v->type == VEH_ROAD) {
fstd->station_type = RoadVehicle::From(v)->IsBus() ? STATION_BUS : STATION_TRUCK;
} else if (v->type == VEH_SHIP) {
fstd->station_type = v->current_order.IsType(OT_GOTO_STATION) ? STATION_DOCK : STATION_BUOY;
fstd->station_type = (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_LEAVESTATION)) ? STATION_DOCK : STATION_BUOY;
}
fstd->not_articulated = v->type == VEH_ROAD && !RoadVehicle::From(v)->HasArticulatedPart();

View File

@ -45,8 +45,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)) {
m_destStation = v->current_order.GetDestination();
assert(Station::IsValidID(m_destStation));
m_destTile = CalcClosestStationTile(m_destStation, v->tile, STATION_DOCK);
m_destTrackdirs = INVALID_TRACKDIR_BIT;
} else {

View File

@ -197,8 +197,9 @@ public:
Tpf pf(std::min(static_cast<int>(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, STATION_DOCK);