diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -249,11 +249,14 @@ CommandCost CmdSetTimetableStart(DoComma 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(DoComma 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) {