Fix #8584: Vehicles with shared orders getting invalid or unexpected start dates
This commit is contained in:

committed by
Michael Lutz

parent
67608350b6
commit
6d154e72dd
@@ -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) {
|
||||
|
||||
|
Reference in New Issue
Block a user