Fix #8584: Vehicles with shared orders getting invalid or unexpected start dates

pull/428/head
Nicolas Chappe 2 years ago committed by Michael Lutz
parent 67608350b6
commit 6d154e72dd

@ -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

@ -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<Vehicle *> 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) {

Loading…
Cancel
Save