Codechange: Always set the ODATFB_NEAREST_DEPOT flag for 'any depot' orders

This commit is contained in:
Nicolas Chappe 2022-07-26 18:27:54 +02:00 committed by Michael Lutz
parent 4daad7f348
commit a9a21e784d
6 changed files with 12 additions and 8 deletions

View File

@ -10,9 +10,13 @@
#ifndef DEPOT_TYPE_H
#define DEPOT_TYPE_H
typedef uint16 DepotID; ///< Type for the unique identifier of depots.
#include "station_type.h"
typedef StationID DepotID; ///< Type for the unique identifier of depots.
struct Depot;
static const DepotID INVALID_DEPOT = INVALID_STATION;
static const uint MAX_LENGTH_DEPOT_NAME_CHARS = 32; ///< The maximum length of a depot name in characters including '\0'
#endif /* DEPOT_TYPE_H */

View File

@ -656,7 +656,7 @@ void OrderList::DebugCheckSanity() const
static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
{
return o->IsType(OT_GOTO_STATION) ||
(v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
(v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && o->GetDestination() != INVALID_STATION);
}
/**
@ -690,7 +690,7 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
return BaseStation::Get(this->GetDestination())->xy;
case OT_GOTO_DEPOT:
if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE;
if (this->GetDestination() == INVALID_DEPOT) return INVALID_TILE;
return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy;
default:
@ -1991,7 +1991,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
if (pbs_look_ahead && reverse) return false;
v->SetDestTile(location);
v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
v->current_order.SetDestination(destination);
/* If there is no depot in front, reverse automatically (trains only) */
if (v->type == VEH_TRAIN && reverse) Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(DC_EXEC, v->index, false);

View File

@ -619,7 +619,7 @@ private:
Order order;
order.next = nullptr;
order.index = 0;
order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
order.MakeGoToDepot(INVALID_DEPOT, ODTFB_PART_OF_ORDERS,
_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
order.SetDepotActionType(ODATFB_NEAREST_DEPOT);

View File

@ -470,7 +470,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
if (order_flags & OF_GOTO_NEAREST_DEPOT) odaf |= ODATFB_NEAREST_DEPOT;
OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & OF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
if (order_flags & OF_GOTO_NEAREST_DEPOT) {
order.MakeGoToDepot(0, odtf, onsf, odaf);
order.MakeGoToDepot(INVALID_DEPOT, odtf, onsf, odaf);
} else {
/* Check explicitly if the order is to a station (for aircraft) or
* to a depot (other vehicle types). */

View File

@ -3974,7 +3974,7 @@ static void CheckIfTrainNeedsService(Train *v)
}
SetBit(v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE);
v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, ODATFB_NEAREST_DEPOT);
v->dest_tile = tfdd.tile;
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
}

View File

@ -2864,7 +2864,7 @@ public:
SetDParam(0, v->type);
SetDParam(1, v->current_order.GetDestination());
SetDParam(2, v->GetDisplaySpeed());
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
if (v->current_order.GetDestination() == INVALID_DEPOT) {
/* This case *only* happens when multiple nearest depot orders
* follow each other (including an order list only one order: a
* nearest depot order) and there are no reachable depots.