From 6d154e72dd60125a5685848114bc560a1161ca7e Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:48:04 +0200 Subject: [PATCH] Fix #8584: Vehicles with shared orders getting invalid or unexpected start dates --- src/lang/english.txt | 2 +- src/timetable_cmd.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 083bb2ee51..853b8d3329 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4468,7 +4468,7 @@ STR_TIMETABLE_STATUS_NOT_STARTED :{BLACK}This tim STR_TIMETABLE_STATUS_START_AT :{BLACK}This timetable will start at {STRING1} STR_TIMETABLE_STARTING_DATE :{BLACK}Start date -STR_TIMETABLE_STARTING_DATE_TOOLTIP :{BLACK}Select a date as starting point of this timetable. Ctrl+Click sets the starting point of this timetable and distributes all vehicles sharing this order evenly based on their relative order, if the order is completely timetabled +STR_TIMETABLE_STARTING_DATE_TOOLTIP :{BLACK}Select a date as starting point of this timetable. Ctrl+Click distributes all vehicles sharing this order evenly from the given date based on their relative order, if the order is completely timetabled STR_TIMETABLE_CHANGE_TIME :{BLACK}Change Time STR_TIMETABLE_WAIT_TIME_TOOLTIP :{BLACK}Change the amount of time that the highlighted order should take diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index b717f8224c..6f7dcca55b 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -249,11 +249,14 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim CommandCost ret = CheckOwnership(v->owner); if (ret.Failed()) return ret; + int total_duration = v->orders->GetTimetableTotalDuration(); + /* Don't let a timetable start more than 15 years into the future or 1 year in the past. */ if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR; if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR; if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR; if (timetable_all && !v->orders->IsCompleteTimetable()) return CMD_ERROR; + if (timetable_all && start_date + total_duration / DAY_TICKS > MAX_DAY) return CMD_ERROR; if (flags & DC_EXEC) { std::vector vehs; @@ -266,14 +269,13 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim vehs.push_back(v); } - int total_duration = v->orders->GetTimetableTotalDuration(); int num_vehs = (uint)vehs.size(); if (num_vehs >= 2) { std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter); } - int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v); + int idx = 0; for (Vehicle *w : vehs) {