Changeset - r28278:1fc682037ca2
[Not reviewed]
master
0 7 0
Tyler Trahan - 11 months ago 2023-11-26 16:12:02
tyler@tylertrahan.com
Codechange: Use Ticks for BaseConsist timetable fields
7 files changed with 13 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/base_consist.h
Show inline comments
 
@@ -18,8 +18,8 @@ struct BaseConsist {
 
	std::string name;                   ///< Name of vehicle
 

	
 
	/* Used for timetabling. */
 
	uint32_t current_order_time;               ///< How many ticks have passed since this order started.
 
	int32_t lateness_counter;                  ///< How many ticks late (or early if negative) this vehicle is.
 
	TimerGameTick::Ticks current_order_time;    ///< How many ticks have passed since this order started.
 
	TimerGameTick::Ticks lateness_counter;      ///< How many ticks late (or early if negative) this vehicle is.
 
	TimerGameTick::TickCounter timetable_start; ///< At what tick of TimerGameTick::counter the vehicle should start its timetable.
 

	
 
	uint16_t service_interval;            ///< The interval for (automatic) servicing; either in days or %.
src/economy.cpp
Show inline comments
 
@@ -1872,7 +1872,7 @@ static void LoadUnloadVehicle(Vehicle *f
 
		/* We loaded less cargo than possible for all cargo types and it's not full
 
		 * load and we're not supposed to wait any longer: stop loading. */
 
		if (!anything_unloaded && full_load_amount == 0 && reservation_left == 0 && !(front->current_order.GetLoadType() & OLFB_FULL_LOAD) &&
 
				front->current_order_time >= (uint)std::max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0)) {
 
				front->current_order_time >= std::max(front->current_order.GetTimetabledWait() - front->lateness_counter, 0)) {
 
			SetBit(front->vehicle_flags, VF_STOP_LOADING);
 
		}
 

	
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -233,8 +233,7 @@ void LinkRefresher::RefreshStats(const O
 
			 * probably far off and we'd greatly overestimate the capacity by increasing.*/
 
			if (this->is_full_loading && this->vehicle->orders != nullptr &&
 
					st->index == vehicle->last_station_visited &&
 
					this->vehicle->orders->GetTotalDuration() >
 
					(TimerGameTick::Ticks)this->vehicle->current_order_time) {
 
					this->vehicle->orders->GetTotalDuration() > this->vehicle->current_order_time) {
 
				uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
 
				if (effective_capacity > (uint)this->vehicle->orders->GetTotalDuration()) {
 
					IncreaseStats(st, c, next_station, effective_capacity /
src/saveload/saveload.h
Show inline comments
 
@@ -365,6 +365,7 @@ enum SaveLoadVersion : uint16_t {
 
	SLV_STATION_RATING_CHEAT,               ///< 320  PR#11346 Add cheat to fix station ratings at 100%.
 
	SLV_TIMETABLE_START_TICKS,              ///< 321  PR#11468 Convert timetable start from a date to ticks.
 
	SLV_TIMETABLE_START_TICKS_FIX,          ///< 322  PR#11557 Fix for missing convert timetable start from a date to ticks.
 
	SLV_TIMETABLE_TICKS_TYPE,               ///< 323  PR#11435 Convert timetable current order time to ticks.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -720,7 +720,8 @@ public:
 
		SLE_CONDREF(Vehicle, next_shared,           REF_VEHICLE,                  SLV_2, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, group_id,              SLE_UINT16,                  SLV_60, SL_MAX_VERSION),
 

	
 
		SLE_CONDVAR(Vehicle, current_order_time,    SLE_UINT32,                  SLV_67, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, current_order_time,    SLE_FILE_U32 | SLE_VAR_I32,  SLV_67, SLV_TIMETABLE_TICKS_TYPE),
 
		SLE_CONDVAR(Vehicle, current_order_time,    SLE_INT32,                   SLV_TIMETABLE_TICKS_TYPE, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, last_loading_tick,     SLE_UINT64,                   SLV_LAST_LOADING_TICK, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, lateness_counter,      SLE_INT32,                   SLV_67, SL_MAX_VERSION),
 
	};
src/timetable_cmd.cpp
Show inline comments
 
@@ -264,7 +264,7 @@ CommandCost CmdSetVehicleOnTime(DoComman
 

	
 
	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;
 
@@ -454,7 +454,7 @@ CommandCost CmdAutofillTimetable(DoComma
 
 */
 
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;
 

	
 
@@ -514,7 +514,7 @@ void UpdateVehicleTimetable(Vehicle *v, 
 
		 * 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);
 
@@ -533,7 +533,7 @@ void UpdateVehicleTimetable(Vehicle *v, 
 

	
 
	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
 
@@ -548,7 +548,7 @@ void UpdateVehicleTimetable(Vehicle *v, 
 
	 * 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;
src/vehicle.cpp
Show inline comments
 
@@ -2333,7 +2333,7 @@ void Vehicle::HandleLoading(bool mode)
 
{
 
	switch (this->current_order.GetType()) {
 
		case OT_LOADING: {
 
			uint wait_time = std::max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
 
			TimerGameTick::Ticks wait_time = std::max(this->current_order.GetTimetabledWait() - this->lateness_counter, 0);
 

	
 
			/* Not the first call for this tick, or still loading */
 
			if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || this->current_order_time < wait_time) return;
0 comments (0 inline, 0 general)