diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index c1f6a336b7..83edecb34b 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1287,7 +1287,7 @@ void HandleMissingAircraftOrders(Aircraft *v) const Station *st = GetTargetAirportIfValid(v); if (st == nullptr) { Backup cur_company(_current_company, v->owner); - CommandCost ret = Command::Do(DC_EXEC, v->index, DepotCommand::None, {}); + CommandCost ret = Command::Do(DC_EXEC, v->index, DepotCommandFlag{}, {}); cur_company.Restore(); 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 */ if (v->NeedsAutomaticServicing()) { Backup cur_company(_current_company, v->owner); - Command::Do(DC_EXEC, v->index, DepotCommand::Service | DepotCommand::LocateHangar, {}); + Command::Do(DC_EXEC, v->index, DepotCommandFlags{DepotCommandFlag::Service, DepotCommandFlag::LocateHangar}, {}); 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 */ if (v->NeedsAutomaticServicing()) { Backup cur_company(_current_company, v->owner); - Command::Do(DC_EXEC, v->index, DepotCommand::Service, {}); + Command::Do(DC_EXEC, v->index, DepotCommandFlag::Service, {}); cur_company.Restore(); } } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index d1e1532530..8894bf0199 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -1017,7 +1017,7 @@ public: break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: { // Send to Depots - Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli); + Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); break; } diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 19eb6e4d8c..d375f2831c 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -201,7 +201,7 @@ EnforceCompanyModeValid(false); EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id)); - return ScriptObject::Command::Do(vehicle_id, DepotCommand::None, {}); + return ScriptObject::Command::Do(vehicle_id, DepotCommandFlags{}, {}); } /* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id) @@ -209,7 +209,7 @@ EnforceCompanyModeValid(false); EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id)); - return ScriptObject::Command::Do(vehicle_id, DepotCommand::Service, {}); + return ScriptObject::Command::Do(vehicle_id, DepotCommandFlag::Service, {}); } /* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index a264432d9e..c733620407 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2580,7 +2580,7 @@ bool Vehicle::IsWaitingForUnbunching() const * @param command the command to execute. * @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); if (ret.Failed()) return ret; @@ -2593,7 +2593,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) if (this->current_order.IsType(OT_GOTO_DEPOT)) { 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. * 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) */ @@ -2605,7 +2605,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) 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 the orders to 'goto depot' are in the orders list (forced servicing), * 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->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); /* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */ diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 2812dd9028..22b6e2222f 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -806,7 +806,7 @@ public: 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 ShowVisualEffect() const; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 07e97bca44..2e2a26e6c2 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -1020,7 +1020,7 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con bool had_success = false; for (uint i = 0; i < list.size(); i++) { const Vehicle *v = list[i]; - CommandCost ret = Command::Do(flags, v->index, (service ? DepotCommand::Service : DepotCommand::None) | DepotCommand::DontCancel, {}); + CommandCost ret = Command::Do(flags, v->index, (service ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::DontCancel, {}); if (ret.Succeeded()) { had_success = true; @@ -1044,12 +1044,12 @@ static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, con * @param vli VehicleListIdentifier. * @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 */ 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); diff --git a/src/vehicle_cmd.h b/src/vehicle_cmd.h index 1064684e15..01dcaecb00 100644 --- a/src/vehicle_cmd.h +++ b/src/vehicle_cmd.h @@ -20,7 +20,7 @@ std::tuple 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); std::tuple 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 CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::string &text); std::tuple CmdCloneVehicle(DoCommandFlag flags, TileIndex tile, VehicleID veh_id, bool share_orders); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 70d671dd2d..5be70ee921 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2245,7 +2245,7 @@ public: break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: // Send to Depots - Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, DepotCommand::MassSend | (index == ADI_SERVICE ? DepotCommand::Service : DepotCommand::None), this->vli); + Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); break; case ADI_CREATE_GROUP: // Create group @@ -3346,7 +3346,7 @@ public: break; case WID_VV_GOTO_DEPOT: // goto hangar - Command::Post(GetCmdSendToDepotMsg(v), v->index, _ctrl_pressed ? DepotCommand::Service : DepotCommand::None, {}); + Command::Post(GetCmdSendToDepotMsg(v), v->index, _ctrl_pressed ? DepotCommandFlag::Service : DepotCommandFlags{}, {}); break; case WID_VV_REFIT: // refit ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this); diff --git a/src/vehicle_type.h b/src/vehicle_type.h index b1aeb6b1cc..34f4e8e0d8 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -54,14 +54,13 @@ struct BaseVehicle static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle. /** Flags for goto depot commands. */ -enum class DepotCommand : uint8_t { - None = 0, ///< No special flags. - Service = (1U << 0), ///< The vehicle will leave the depot right after arrival (service only) - MassSend = (1U << 1), ///< Tells that it's a mass send to depot command (type in VLW flag) - DontCancel = (1U << 2), ///< Don't cancel current goto depot command if any - LocateHangar = (1U << 3), ///< Find another airport if the target one lacks a hangar +enum class DepotCommandFlag : uint8_t { + Service, ///< 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) + DontCancel, ///< Don't cancel current goto depot command if any + LocateHangar, ///< Find another airport if the target one lacks a hangar }; -DECLARE_ENUM_AS_BIT_SET(DepotCommand) +using DepotCommandFlags = EnumBitSet; static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of a vehicle name in characters including '\0'