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
 
@@ -15,14 +15,14 @@
 

	
 
/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
 
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 %.
 

	
 
	VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order
 
	VehicleOrderID cur_implicit_order_index;///< The index to the current implicit order
src/economy.cpp
Show inline comments
 
@@ -1869,13 +1869,13 @@ static void LoadUnloadVehicle(Vehicle *f
 

	
 
			new_load_unload_ticks = gradual_loading_wait_time[front->type];
 
		}
 
		/* 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);
 
		}
 

	
 
		UpdateLoadUnloadTicks(front, st, new_load_unload_ticks);
 
	} else {
 
		UpdateLoadUnloadTicks(front, st, 20); // We need the ticks for link refreshing.
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -230,14 +230,13 @@ void LinkRefresher::RefreshStats(const O
 
			 * where it is loading by an estimate of what it would have transported if it wasn't
 
			 * loading. Don't do that if the vehicle has been waiting for longer than the entire
 
			 * order list is supposed to take, though. If that is the case the total duration is
 
			 * 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 /
 
							this->vehicle->orders->GetTotalDuration(), 0, 0,
 
							EUM_INCREASE | restricted_mode);
 
				} else if (RandomRange(this->vehicle->orders->GetTotalDuration()) < effective_capacity) {
src/saveload/saveload.h
Show inline comments
 
@@ -362,12 +362,13 @@ enum SaveLoadVersion : uint16_t {
 
	SLV_REMOVE_LOADED_AT_XY,                ///< 318  PR#11276 Remove loaded_at_xy variable from CargoPacket.
 
	SLV_CARGO_TRAVELLED,                    ///< 319  PR#11283 CargoPacket now tracks how far it travelled inside a vehicle.
 

	
 
	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
 
};
 

	
 
/** Save or load result codes. */
 
enum SaveOrLoadResult {
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -717,13 +717,14 @@ public:
 
		SLE_CONDVAR(Vehicle, random_bits,           SLE_UINT16,                   SLV_EXTEND_VEHICLE_RANDOM, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, waiting_triggers,      SLE_UINT8,                    SLV_2, SL_MAX_VERSION),
 

	
 
		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),
 
	};
 
#if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916)
 
		return description;
 
	}
src/timetable_cmd.cpp
Show inline comments
 
@@ -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;
 
		}
 
	}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -2330,13 +2330,13 @@ void Vehicle::ResetRefitCaps()
 
 * @param mode is the non-first call for this vehicle in this tick?
 
 */
 
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;
 

	
 
			this->PlayLeaveStationSound();
 

	
0 comments (0 inline, 0 general)