# HG changeset patch # User Bilongozhko, Serhii (Contractor) # Date 2023-02-10 18:29:29 # Node ID 14e8578f092aa07e5b47abc880f74dafefe29bfd # Parent 4f6a4f56e921ce4f816bc34bf27da79d68368934 Feature: Ctrl+Click to reset late counter for the entire vehicle group. diff --git a/src/lang/english.txt b/src/lang/english.txt --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4529,7 +4529,7 @@ STR_TIMETABLE_CLEAR_SPEED 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 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -211,9 +211,10 @@ CommandCost CmdBulkChangeTimetable(DoCom * 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(DoComman 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 --- 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 --- 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.