1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-29 23:24:31 +01:00

Codechange: Use EnumBitSet for DoCommandFlags

This commit is contained in:
Rubidium
2025-02-13 23:35:52 +01:00
committed by rubidium42
parent f309b90a1d
commit c3d5e6d2a0
95 changed files with 871 additions and 873 deletions

View File

@@ -130,7 +130,7 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16_t va
* 0 to clear times, UINT16_MAX to clear speed limit.
* @return the cost of this operation or an error
*/
CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16_t data)
CommandCost CmdChangeTimetable(DoCommandFlags flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16_t data)
{
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
@@ -180,7 +180,7 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderI
if (travel_time != order->GetTravelTime() && order->IsType(OT_CONDITIONAL)) return CMD_ERROR;
if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
switch (mtf) {
case MTF_WAIT_TIME:
/* Set time if changing the value or confirming an estimated time as timetabled. */
@@ -225,7 +225,7 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderI
* 0 to clear times, UINT16_MAX to clear speed limit.
* @return the cost of this operation or an error
*/
CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTimetableFlags mtf, uint16_t data)
CommandCost CmdBulkChangeTimetable(DoCommandFlags flags, VehicleID veh, ModifyTimetableFlags mtf, uint16_t data)
{
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
@@ -237,12 +237,12 @@ CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTim
if (v->GetNumOrders() == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
for (VehicleOrderID order_number = 0; order_number < v->GetNumOrders(); order_number++) {
Order *order = v->GetOrder(order_number);
if (order == nullptr || order->IsType(OT_IMPLICIT)) continue;
Command<CMD_CHANGE_TIMETABLE>::Do(DC_EXEC, v->index, order_number, mtf, data);
Command<CMD_CHANGE_TIMETABLE>::Do(DoCommandFlag::Execute, v->index, order_number, mtf, data);
}
}
@@ -256,7 +256,7 @@ CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTim
* @param apply_to_group Set to reset the late counter for all vehicles sharing the orders.
* @return the cost of this operation or an error
*/
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_to_group)
CommandCost CmdSetVehicleOnTime(DoCommandFlags flags, VehicleID veh, bool apply_to_group)
{
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
@@ -268,7 +268,7 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_t
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
if (apply_to_group) {
TimerGameTick::Ticks most_late = 0;
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
@@ -348,7 +348,7 @@ static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
* @param start_tick The TimerGameTick::counter tick when the timetable starts.
* @return The error or cost of the operation.
*/
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, TimerGameTick::TickCounter start_tick)
CommandCost CmdSetTimetableStart(DoCommandFlags flags, VehicleID veh_id, bool timetable_all, TimerGameTick::TickCounter start_tick)
{
Vehicle *v = Vehicle::GetIfValid(veh_id);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
@@ -374,7 +374,7 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
/* Don't allow invalid start dates for other vehicles in the shared order group. */
if (timetable_all && start_date + (total_duration / Ticks::DAY_TICKS) > EconomyTime::MAX_DATE) return CMD_ERROR;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
std::vector<Vehicle *> vehs;
if (timetable_all) {
@@ -422,7 +422,7 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
* @param preserve_wait_time Set to preserve waiting times in non-destructive mode
* @return the cost of this operation or an error
*/
CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time)
CommandCost CmdAutofillTimetable(DoCommandFlags flags, VehicleID veh, bool autofill, bool preserve_wait_time)
{
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
@@ -430,7 +430,7 @@ CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofi
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
if (autofill) {
/* Start autofilling the timetable, which clears the
* "timetable has started" bit. Times are not cleared anymore, but are