1
0
Fork 0

Codechange: Use EnumBitSet for DepotCommand(Flag)s.

pull/11338/merge
Peter Nelson 2025-01-29 17:47:52 +00:00 committed by Peter Nelson
parent 2560339472
commit f51627c76f
9 changed files with 24 additions and 25 deletions

View File

@ -1287,7 +1287,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
const Station *st = GetTargetAirportIfValid(v); const Station *st = GetTargetAirportIfValid(v);
if (st == nullptr) { if (st == nullptr) {
Backup<CompanyID> cur_company(_current_company, v->owner); Backup<CompanyID> cur_company(_current_company, v->owner);
CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommand::None, {}); CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommandFlag{}, {});
cur_company.Restore(); cur_company.Restore();
if (ret.Failed()) CrashAirplane(v); if (ret.Failed()) CrashAirplane(v);
@ -1653,7 +1653,7 @@ static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass
/* Send the helicopter to a hangar if needed for replacement */ /* Send the helicopter to a hangar if needed for replacement */
if (v->NeedsAutomaticServicing()) { if (v->NeedsAutomaticServicing()) {
Backup<CompanyID> cur_company(_current_company, v->owner); Backup<CompanyID> cur_company(_current_company, v->owner);
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommand::Service | DepotCommand::LocateHangar, {}); Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommandFlags{DepotCommandFlag::Service, DepotCommandFlag::LocateHangar}, {});
cur_company.Restore(); cur_company.Restore();
} }
} }
@ -1704,7 +1704,7 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *)
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
if (v->NeedsAutomaticServicing()) { if (v->NeedsAutomaticServicing()) {
Backup<CompanyID> cur_company(_current_company, v->owner); Backup<CompanyID> cur_company(_current_company, v->owner);
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommand::Service, {}); Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(DC_EXEC, v->index, DepotCommandFlag::Service, {});
cur_company.Restore(); cur_company.Restore();
} }
} }

View File

@ -1017,7 +1017,7 @@ public:
break; break;
case ADI_SERVICE: // Send for servicing case ADI_SERVICE: // Send for servicing
case ADI_DEPOT: { // Send to Depots case ADI_DEPOT: { // Send to Depots
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli); Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli);
break; break;
} }

View File

@ -201,7 +201,7 @@
EnforceCompanyModeValid(false); EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(vehicle_id, DepotCommand::None, {}); return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(vehicle_id, DepotCommandFlags{}, {});
} }
/* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id) /* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id)
@ -209,7 +209,7 @@
EnforceCompanyModeValid(false); EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id)); EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(vehicle_id, DepotCommand::Service, {}); return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(vehicle_id, DepotCommandFlag::Service, {});
} }
/* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id) /* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id)

View File

@ -2580,7 +2580,7 @@ bool Vehicle::IsWaitingForUnbunching() const
* @param command the command to execute. * @param command the command to execute.
* @return the cost of the depot action. * @return the cost of the depot action.
*/ */
CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommandFlags command)
{ {
CommandCost ret = CheckOwnership(this->owner); CommandCost ret = CheckOwnership(this->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -2593,7 +2593,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (this->current_order.IsType(OT_GOTO_DEPOT)) { if (this->current_order.IsType(OT_GOTO_DEPOT)) {
bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0; bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0;
if (HasFlag(command, DepotCommand::Service) == halt_in_depot) { if (command.Test(DepotCommandFlag::Service) == halt_in_depot) {
/* We called with a different DEPOT_SERVICE setting. /* We called with a different DEPOT_SERVICE setting.
* Now we change the setting to apply the new one and let the vehicle head for the same depot. * Now we change the setting to apply the new one and let the vehicle head for the same depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */ * Note: the if is (true for requesting service == true for ordered to stop in depot) */
@ -2605,7 +2605,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
return CommandCost(); return CommandCost();
} }
if (HasFlag(command, DepotCommand::DontCancel)) return CMD_ERROR; // Requested no cancellation of depot orders if (command.Test(DepotCommandFlag::DontCancel)) return CMD_ERROR; // Requested no cancellation of depot orders
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
/* If the orders to 'goto depot' are in the orders list (forced servicing), /* If the orders to 'goto depot' are in the orders list (forced servicing),
* then skip to the next order; effectively cancelling this forced service */ * then skip to the next order; effectively cancelling this forced service */
@ -2636,7 +2636,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
this->SetDestTile(closestDepot.location); this->SetDestTile(closestDepot.location);
this->current_order.MakeGoToDepot(closestDepot.destination, ODTF_MANUAL); this->current_order.MakeGoToDepot(closestDepot.destination, ODTF_MANUAL);
if (!HasFlag(command, DepotCommand::Service)) this->current_order.SetDepotActionType(ODATFB_HALT); if (!command.Test(DepotCommandFlag::Service)) this->current_order.SetDepotActionType(ODATFB_HALT);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
/* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */ /* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */

View File

@ -806,7 +806,7 @@ public:
virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; } virtual void SetDestTile(TileIndex tile) { this->dest_tile = tile; }
CommandCost SendToDepot(DoCommandFlag flags, DepotCommand command); CommandCost SendToDepot(DoCommandFlag flags, DepotCommandFlags command);
void UpdateVisualEffect(bool allow_power_change = true); void UpdateVisualEffect(bool allow_power_change = true);
void ShowVisualEffect() const; void ShowVisualEffect() const;

View File

@ -1020,7 +1020,7 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con
bool had_success = false; bool had_success = false;
for (uint i = 0; i < list.size(); i++) { for (uint i = 0; i < list.size(); i++) {
const Vehicle *v = list[i]; const Vehicle *v = list[i];
CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(flags, v->index, (service ? DepotCommand::Service : DepotCommand::None) | DepotCommand::DontCancel, {}); CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(flags, v->index, (service ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::DontCancel, {});
if (ret.Succeeded()) { if (ret.Succeeded()) {
had_success = true; had_success = true;
@ -1044,12 +1044,12 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con
* @param vli VehicleListIdentifier. * @param vli VehicleListIdentifier.
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli) CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommandFlags depot_cmd, const VehicleListIdentifier &vli)
{ {
if (HasFlag(depot_cmd, DepotCommand::MassSend)) { if (depot_cmd.Test(DepotCommandFlag::MassSend)) {
/* Mass goto depot requested */ /* Mass goto depot requested */
if (!vli.Valid()) return CMD_ERROR; if (!vli.Valid()) return CMD_ERROR;
return SendAllVehiclesToDepot(flags, HasFlag(depot_cmd, DepotCommand::Service), vli); return SendAllVehiclesToDepot(flags, depot_cmd.Test(DepotCommandFlag::Service), vli);
} }
Vehicle *v = Vehicle::GetIfValid(veh_id); Vehicle *v = Vehicle::GetIfValid(veh_id);

View File

@ -20,7 +20,7 @@
std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id); std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id);
CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id); CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, bool backup_order, ClientID client_id);
std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoType new_cargo_type, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles); std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoType new_cargo_type, uint8_t new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles);
CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommand depot_cmd, const VehicleListIdentifier &vli); CommandCost CmdSendVehicleToDepot(DoCommandFlag flags, VehicleID veh_id, DepotCommandFlags depot_cmd, const VehicleListIdentifier &vli);
CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent); CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent);
CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text); CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text);
std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders); std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders);

View File

@ -2245,7 +2245,7 @@ public:
break; break;
case ADI_SERVICE: // Send for servicing case ADI_SERVICE: // Send for servicing
case ADI_DEPOT: // Send to Depots case ADI_DEPOT: // Send to Depots
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli); Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli);
break; break;
case ADI_CREATE_GROUP: // Create group case ADI_CREATE_GROUP: // Create group
@ -3346,7 +3346,7 @@ public:
break; break;
case WID_VV_GOTO_DEPOT: // goto hangar case WID_VV_GOTO_DEPOT: // goto hangar
Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(v), v->index, _ctrl_pressed ? DepotCommand::Service : DepotCommand::None, {}); Command<CMD_SEND_VEHICLE_TO_DEPOT>::Post(GetCmdSendToDepotMsg(v), v->index, _ctrl_pressed ? DepotCommandFlag::Service : DepotCommandFlags{}, {});
break; break;
case WID_VV_REFIT: // refit case WID_VV_REFIT: // refit
ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this); ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this);

View File

@ -54,14 +54,13 @@ struct BaseVehicle
static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle. static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle.
/** Flags for goto depot commands. */ /** Flags for goto depot commands. */
enum class DepotCommand : uint8_t { enum class DepotCommandFlag : uint8_t {
None = 0, ///< No special flags. Service, ///< The vehicle will leave the depot right after arrival (service only)
Service = (1U << 0), ///< The vehicle will leave the depot right after arrival (service only) MassSend, ///< Tells that it's a mass send to depot command (type in VLW flag)
MassSend = (1U << 1), ///< Tells that it's a mass send to depot command (type in VLW flag) DontCancel, ///< Don't cancel current goto depot command if any
DontCancel = (1U << 2), ///< Don't cancel current goto depot command if any LocateHangar, ///< Find another airport if the target one lacks a hangar
LocateHangar = (1U << 3), ///< Find another airport if the target one lacks a hangar
}; };
DECLARE_ENUM_AS_BIT_SET(DepotCommand) using DepotCommandFlags = EnumBitSet<DepotCommandFlag, uint8_t>;
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of a vehicle name in characters including '\0' static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of a vehicle name in characters including '\0'