From a7e9c9ce65bc0527c3b85da6b848d2ad5d05194e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 30 Nov 2015 22:28:20 +0000 Subject: [PATCH 1/2] Fix ClearSeparation() not being called when auto-separation disabled. This can causes crashes if auto-separation is re-enabled as the next/prev separation ptrs can end up dangling. --- src/order_cmd.cpp | 4 ++-- src/timetable_cmd.cpp | 4 ++-- src/vehicle.cpp | 8 ++++---- src/vehicle_cmd.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 8bfbc1469b..b53a7da479 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1161,7 +1161,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS); - if (_settings_game.order.timetable_separation) v->ClearSeparation(); + v->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); } @@ -1626,7 +1626,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 SetBit(dst->vehicle_flags, VF_AUTOMATE_TIMETABLE); } - if (_settings_game.order.timetable_separation) dst->ClearSeparation(); + dst->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(dst->vehicle_flags, VF_TIMETABLE_STARTED); InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS); diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index d3440fc281..b0e41d9659 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -591,7 +591,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) /* Start automated timetables at first opportunity */ if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED) && HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)) { - if (_settings_game.order.timetable_separation) v->ClearSeparation(); + v->ClearSeparation(); SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED); v->lateness_counter = 0; if (_settings_game.order.timetable_separation) UpdateSeparationOrder(v); @@ -680,7 +680,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) * Otherwise we risk trains blocking 1-lane stations for long times. */ ChangeTimetable(v, v->cur_real_order_index, 0, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) { - if (_settings_game.order.timetable_separation) v2->ClearSeparation(); + v2->ClearSeparation(); ClrBit(v2->vehicle_flags, VF_TIMETABLE_STARTED); SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 6a79977d37..139670547e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -209,7 +209,7 @@ uint Vehicle::Crash(bool flooded) v->MarkAllViewportsDirty(); } - if (_settings_game.order.timetable_separation) this->ClearSeparation(); + this->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED); /* Dirty some windows */ @@ -2230,7 +2230,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) if (flags & DC_EXEC) { this->current_order.SetDepotOrderType(ODTF_MANUAL); this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); - if (_settings_game.order.timetable_separation) this->ClearSeparation(); + this->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED); SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); } @@ -2248,7 +2248,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); } - if (_settings_game.order.timetable_separation) this->ClearSeparation(); + this->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED); this->current_order.MakeDummy(); @@ -2701,7 +2701,7 @@ void Vehicle::RemoveFromShared() this->next_shared = NULL; this->previous_shared = NULL; - if (_settings_game.order.timetable_separation) this->ClearSeparation(); + this->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(this->vehicle_flags, VF_TIMETABLE_STARTED); } diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index b86ead98d0..8ea1ac7786 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -578,7 +578,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, if (flags & DC_EXEC) { if (v->IsStoppedInDepot() && (flags & DC_AUTOREPLACE) == 0) DeleteVehicleNews(p1, STR_NEWS_TRAIN_IS_WAITING + v->type); - if (_settings_game.order.timetable_separation) v->ClearSeparation(); + v->ClearSeparation(); if (_settings_game.order.timetable_separation) ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); v->vehstatus ^= VS_STOPPED; From d2b87485fb59ac3e5c646ce8a4a8372cc1fbfde4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 30 Nov 2015 19:48:44 +0000 Subject: [PATCH 2/2] When clearing auto timetables, mark times as undefined rather than 0. Fix unautomate timetable having reversed ctrl key behaviour, update tooltip string with ctrl behaviour. Minor comment/whitespace fixes. --- src/command.cpp | 2 +- src/lang/english.txt | 2 +- src/timetable_cmd.cpp | 10 +++++----- src/timetable_gui.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 1a26cdc5d4..b76efa86ab 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -352,7 +352,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CHANGE_TIMETABLE DEF_CMD(CmdSetVehicleOnTime, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_VEHICLE_ON_TIME DEF_CMD(CmdAutofillTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_AUTOFILL_TIMETABLE - DEF_CMD(CmdAutomateTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_AUTOMATE_TIMETABLE] + DEF_CMD(CmdAutomateTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_AUTOMATE_TIMETABLE DEF_CMD(CmdSetTimetableStart, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_TIMETABLE_START DEF_CMD(CmdOpenCloseAirport, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_OPEN_CLOSE_AIRPORT diff --git a/src/lang/english.txt b/src/lang/english.txt index 38a1bf4edc..266870af64 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3944,7 +3944,7 @@ 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) STR_TIMETABLE_AUTOMATE :{BLACK}Automate -STR_TIMETABLE_AUTOMATE_TOOLTIP :{BLACK}Manage the timetables automatically by updating the values for each journey +STR_TIMETABLE_AUTOMATE_TOOLTIP :{BLACK}Manage the timetables automatically by updating the values for each journey (Ctrl+Click when disabling to keep the current timetable) STR_TIMETABLE_EXPECTED :{BLACK}Expected STR_TIMETABLE_SCHEDULED :{BLACK}Scheduled diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index b0e41d9659..3a0902e689 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -263,9 +263,9 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp * Set the start date of the timetable. * @param tile Not used. * @param flags Operation to perform. - * @param p2 Various bitstuffed elements - * - p2 = (bit 0-19) - Vehicle ID. - * - p2 = (bit 20) - Set to 1 to set timetable start for all vehicles sharing this order + * @param p1 Various bitstuffed elements + * - p1 = (bit 0-19) - Vehicle ID. + * - p1 = (bit 20) - Set to 1 to set timetable start for all vehicles sharing this order * @param p2 The timetable start date. * @param text Not used. * @return The error or cost of the operation. @@ -432,8 +432,8 @@ CommandCost CmdAutomateTimetable(TileIndex index, DoCommandFlag flags, uint32 p1 OrderList *orders = v2->orders.list; if (orders != NULL) { for (int i = 0; i < orders->GetNumOrders(); i++) { - ChangeTimetable(v2, i, 0, MTF_WAIT_TIME, true); - ChangeTimetable(v2, i, 0, MTF_TRAVEL_TIME, true); + ChangeTimetable(v2, i, 0, MTF_WAIT_TIME, false); + ChangeTimetable(v2, i, 0, MTF_TRAVEL_TIME, false); } } } diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 738ae3c2e6..cb9e478ba1 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -612,7 +612,7 @@ struct TimetableWindow : Window { case WID_VT_AUTOMATE: { uint32 p2 = 0; if (!HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)) SetBit(p2, 0); - if (!_ctrl_pressed) SetBit(p2, 1); + if (_ctrl_pressed) SetBit(p2, 1); DoCommandP(0, v->index, p2, CMD_AUTOMATE_TIMETABLE | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE)); break; }