From 35ad964c6bc1164ab9951bd5ac47ba5206cbe9a6 Mon Sep 17 00:00:00 2001 From: "Bilongozhko, Serhii (Contractor)" Date: Fri, 10 Feb 2023 13:29:29 -0500 Subject: [PATCH] Feature: Ctrl+Click to reset late counter for the entire vehicle group. --- src/lang/english.txt | 2 +- src/timetable_cmd.cpp | 22 +++++++++++++++++++--- src/timetable_cmd.h | 2 +- src/timetable_gui.cpp | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 4a9786b53a..ef80b11ac5 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4529,7 +4529,7 @@ STR_TIMETABLE_CLEAR_SPEED :{BLACK}Clear Sp STR_TIMETABLE_CLEAR_SPEED_TOOLTIP :{BLACK}Clear the maximum travel speed of the highlighted order. Ctrl+Click clears the speed for all orders STR_TIMETABLE_RESET_LATENESS :{BLACK}Reset Late Counter -STR_TIMETABLE_RESET_LATENESS_TOOLTIP :{BLACK}Reset the lateness counter, so the vehicle will be on time +STR_TIMETABLE_RESET_LATENESS_TOOLTIP :{BLACK}Reset the lateness counter, so the vehicle will be on time. Ctrl+Click will reset the entire group so the latest vehicle will be on time and all others will be early STR_TIMETABLE_AUTOFILL :{BLACK}Autofill STR_TIMETABLE_AUTOFILL_TOOLTIP :{BLACK}Fill the timetable automatically with the values from the next journey. Ctrl+Click to try to keep waiting times diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index a1f4ea4ebe..09106c418f 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -211,9 +211,10 @@ CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTim * Clear the lateness counter to make the vehicle on time. * @param flags Operation to perform. * @param veh Vehicle with the orders to change. + * @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) +CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_to_group) { Vehicle *v = Vehicle::GetIfValid(veh); if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR; @@ -222,8 +223,23 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh) if (ret.Failed()) return ret; if (flags & DC_EXEC) { - v->lateness_counter = 0; - SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); + if (apply_to_group) { + int32 most_late = 0; + for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) { + if (u->lateness_counter > most_late) { + most_late = u->lateness_counter; + } + } + if (most_late > 0) { + for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) { + u->lateness_counter -= most_late; + SetWindowDirty(WC_VEHICLE_TIMETABLE, u->index); + } + } + } else { + v->lateness_counter = 0; + SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); + } } return CommandCost(); diff --git a/src/timetable_cmd.h b/src/timetable_cmd.h index 7be7982320..73b518f4dd 100644 --- a/src/timetable_cmd.h +++ b/src/timetable_cmd.h @@ -14,7 +14,7 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16 data); CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTimetableFlags mtf, uint16 data); -CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh); +CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_to_group); CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time); CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date); diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index c76148dd07..8e0252a333 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -600,7 +600,7 @@ struct TimetableWindow : Window { } case WID_VT_RESET_LATENESS: // Reset the vehicle's late counter. - Command::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index); + Command::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, _ctrl_pressed); break; case WID_VT_AUTOFILL: { // Autofill the timetable.