Change: Don't set vehicle on time if timetable not started (#11359)

This commit is contained in:
Tyler Trahan
2023-11-01 15:26:39 -04:00
committed by GitHub
parent bb50cbb772
commit 89480f3531
2 changed files with 11 additions and 0 deletions

View File

@@ -221,6 +221,10 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_t
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
/* A vehicle can't be late if its timetable hasn't started.
* If we're setting all vehicles in the group, we handle that below. */
if (!apply_to_group && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return CommandCost(STR_ERROR_TIMETABLE_NOT_STARTED);
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -228,12 +232,18 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_t
if (apply_to_group) {
int32_t 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;
}
}
if (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;
u->lateness_counter -= most_late;
SetWindowDirty(WC_VEHICLE_TIMETABLE, u->index);
}