Changeset - r28064:25d3484657a5
[Not reviewed]
master
0 2 0
Tyler Trahan - 7 months ago 2023-11-01 19:26:39
tyler@tylertrahan.com
Change: Don't set vehicle on time if timetable not started (#11359)
2 files changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -5189,6 +5189,7 @@ STR_ERROR_CAN_T_TIMETABLE_VEHICLE       
 
STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS                       :{WHITE}Vehicles can only wait at stations
 
STR_ERROR_TIMETABLE_NOT_STOPPING_HERE                           :{WHITE}This vehicle is not stopping at this station
 
STR_ERROR_TIMETABLE_INCOMPLETE                                  :{WHITE}... timetable is incomplete
 
STR_ERROR_TIMETABLE_NOT_STARTED                                 :{WHITE}... timetable has not started yet
 

	
 
# Sign related errors
 
STR_ERROR_TOO_MANY_SIGNS                                        :{WHITE}... too many signs
src/timetable_cmd.cpp
Show inline comments
 
@@ -221,6 +221,10 @@ CommandCost CmdSetVehicleOnTime(DoComman
 
	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(DoComman
 
		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);
 
				}
0 comments (0 inline, 0 general)