Avoid set distributed timetable start setting start dates in the past.

Adjust start dates for vehicles before the base one forward by one
timetable duration if they would start before the present date.

Whitespace/format fixes.
This commit is contained in:
Jonathan G Rennison
2016-01-30 15:16:35 +00:00
parent 7c8b4b9d6d
commit c877e10272

View File

@@ -314,6 +314,9 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
/* Do multiplication, then division to reduce rounding errors. */
w->timetable_start = start_date + idx * total_duration / num_vehs / DAY_TICKS;
if (w->timetable_start < _date && idx < 0) {
w->timetable_start += (total_duration / DAY_TICKS);
}
SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
}
@@ -693,14 +696,16 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
}
if (new_time < 1) new_time = 1;
if (new_time != (int32)timetabled)
if (new_time != (int32)timetabled) {
ChangeTimetable(v, v->cur_real_order_index, new_time, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true);
}
} else if (timetabled == 0 && HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)) {
/* Add times for orders that are not yet timetabled, even while not autofilling */
if (travelling)
ChangeTimetable(v, v->cur_real_order_index, time_taken, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true);
else
ChangeTimetable(v, v->cur_real_order_index, time_loading, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true);
if (travelling) {
ChangeTimetable(v, v->cur_real_order_index, time_taken, MTF_TRAVEL_TIME, true);
} else {
ChangeTimetable(v, v->cur_real_order_index, time_loading, MTF_WAIT_TIME, true);
}
}
/* Vehicles will wait at stations if they arrive early even if they are not