|
@@ -261,13 +261,13 @@ CommandCost CmdSetVehicleOnTime(DoComman
|
|
|
|
|
|
CommandCost ret = CheckOwnership(v->owner);
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
if (apply_to_group) {
|
|
|
int32_t most_late = 0;
|
|
|
TimerGameTick::Ticks most_late = 0;
|
|
|
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
|
|
|
/* A vehicle can't be late if its timetable hasn't started. */
|
|
|
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) continue;
|
|
|
|
|
|
if (u->lateness_counter > most_late) {
|
|
|
most_late = u->lateness_counter;
|
|
@@ -451,13 +451,13 @@ CommandCost CmdAutofillTimetable(DoComma
|
|
|
* Update the timetable for the vehicle.
|
|
|
* @param v The vehicle to update the timetable for.
|
|
|
* @param travelling Whether we just travelled or waited at a station.
|
|
|
*/
|
|
|
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
|
|
|
{
|
|
|
uint time_taken = v->current_order_time;
|
|
|
TimerGameTick::Ticks time_taken = v->current_order_time;
|
|
|
|
|
|
v->current_order_time = 0;
|
|
|
|
|
|
if (v->current_order.IsType(OT_IMPLICIT)) return; // no timetabling of auto orders
|
|
|
|
|
|
if (v->cur_real_order_index >= v->GetNumOrders()) return;
|
|
@@ -511,13 +511,13 @@ void UpdateVehicleTimetable(Vehicle *v,
|
|
|
* For trains/aircraft multiple movement cycles are done in one
|
|
|
* tick. This makes it possible to leave the station and process
|
|
|
* e.g. a depot order in the same tick, causing it to not fill
|
|
|
* the timetable entry like is done for road vehicles/ships.
|
|
|
* Thus always make sure at least one tick is used between the
|
|
|
* processing of different orders when filling the timetable. */
|
|
|
uint time_to_set = CeilDiv(std::max(time_taken, 1U), Ticks::DAY_TICKS) * Ticks::DAY_TICKS;
|
|
|
uint time_to_set = CeilDiv(std::max(time_taken, 1), Ticks::DAY_TICKS) * Ticks::DAY_TICKS;
|
|
|
|
|
|
if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) {
|
|
|
ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling);
|
|
|
} else if (!travelling && (autofilling || !real_current_order->IsWaitTimetabled())) {
|
|
|
ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_WAIT_TIME, autofilling);
|
|
|
}
|
|
@@ -530,13 +530,13 @@ void UpdateVehicleTimetable(Vehicle *v,
|
|
|
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
|
|
|
ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
|
|
|
}
|
|
|
|
|
|
if (autofilling) return;
|
|
|
|
|
|
uint timetabled = travelling ? real_current_order->GetTimetabledTravel() :
|
|
|
TimerGameTick::Ticks timetabled = travelling ? real_current_order->GetTimetabledTravel() :
|
|
|
real_current_order->GetTimetabledWait();
|
|
|
|
|
|
/* Vehicles will wait at stations if they arrive early even if they are not
|
|
|
* timetabled to wait there, so make sure the lateness counter is updated
|
|
|
* when this happens. */
|
|
|
if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
|
|
@@ -545,13 +545,13 @@ void UpdateVehicleTimetable(Vehicle *v,
|
|
|
|
|
|
/* When we are more late than this timetabled bit takes we (somewhat expensively)
|
|
|
* check how many ticks the (fully filled) timetable has. If a timetable cycle is
|
|
|
* shorter than the amount of ticks we are late we reduce the lateness by the
|
|
|
* length of a full cycle till lateness is less than the length of a timetable
|
|
|
* cycle. When the timetable isn't fully filled the cycle will be Ticks::INVALID_TICKS. */
|
|
|
if (v->lateness_counter > (int)timetabled) {
|
|
|
if (v->lateness_counter > timetabled) {
|
|
|
TimerGameTick::Ticks cycle = v->orders->GetTimetableTotalDuration();
|
|
|
if (cycle != Ticks::INVALID_TICKS && v->lateness_counter > cycle) {
|
|
|
v->lateness_counter %= cycle;
|
|
|
}
|
|
|
}
|
|
|
|