Changeset - r28278:1fc682037ca2
[Not reviewed]
master
0 7 0
Tyler Trahan - 7 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
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file base_consist.h Properties for front vehicles/consists. */
 

	
 
#ifndef BASE_CONSIST_H
 
#define BASE_CONSIST_H
 

	
 
#include "order_type.h"
 
#include "timer/timer_game_tick.h"
 

	
 
/** 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
 

	
 
	uint16_t vehicle_flags;               ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
 

	
 
	virtual ~BaseConsist() = default;
 

	
 
	void CopyConsistPropertiesFrom(const BaseConsist *src);
 
};
 

	
 
#endif /* BASE_CONSIST_H */
src/economy.cpp
Show inline comments
 
@@ -1851,49 +1851,49 @@ static void LoadUnloadVehicle(Vehicle *f
 
			TriggerStationAnimation(st, front->tile, SAT_TRAIN_LOADS);
 
		} else if (front->type == VEH_ROAD) {
 
			TriggerRoadStopRandomisation(st, front->tile, RSRT_VEH_LOADS);
 
			TriggerRoadStopAnimation(st, front->tile, SAT_TRAIN_LOADS);
 
		}
 
	}
 

	
 
	/* Only set completely_emptied, if we just unloaded all remaining cargo */
 
	completely_emptied &= anything_unloaded;
 

	
 
	if (!anything_unloaded) delete payment;
 

	
 
	ClrBit(front->vehicle_flags, VF_STOP_LOADING);
 
	if (anything_loaded || anything_unloaded) {
 
		if (_settings_game.order.gradual_loading) {
 
			/* The time it takes to load one 'slice' of cargo or passengers depends
 
			 * on the vehicle type - the values here are those found in TTDPatch */
 
			const uint gradual_loading_wait_time[] = { 40, 20, 10, 20 };
 

	
 
			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.
 
		bool finished_loading = true;
 
		if (front->current_order.GetLoadType() & OLFB_FULL_LOAD) {
 
			if (front->current_order.GetLoadType() == OLF_FULL_LOAD_ANY) {
 
				/* if the aircraft carries passengers and is NOT full, then
 
				 * continue loading, no matter how much mail is in */
 
				if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->cargo.StoredCount()) ||
 
						(cargo_not_full != 0 && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes
 
					finished_loading = false;
 
				}
 
			} else if (cargo_not_full != 0) {
 
				finished_loading = false;
 
			}
 

	
 
			/* Refresh next hop stats if we're full loading to make the links
 
			 * known to the distribution algorithm and allow cargo to be sent
 
			 * along them. Otherwise the vehicle could wait for cargo
 
			 * indefinitely if it hasn't visited the other links yet, or if the
 
			 * links die while it's loading. */
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -212,50 +212,49 @@ void LinkRefresher::RefreshStats(const O
 

	
 
			if (this->vehicle->GetDisplayMaxSpeed() == 0) continue;
 

	
 
			/* If not allowed to merge link graphs, make sure the stations are
 
			 * already in the same link graph. */
 
			if (!this->allow_merge && st->goods[c].link_graph != st_to->goods[c].link_graph) {
 
				continue;
 
			}
 

	
 
			/* A link is at least partly restricted if a vehicle can't load at its source. */
 
			EdgeUpdateMode restricted_mode = (cur->GetLoadType() & OLFB_NO_LOAD) == 0 ?
 
						EUM_UNRESTRICTED : EUM_RESTRICTED;
 
			/* This estimates the travel time of the link as the time needed
 
			 * to travel between the stations at half the max speed of the consist.
 
			 * The result is in tiles/tick (= 2048 km-ish/h). */
 
			uint32_t time_estimate = DistanceManhattan(st->xy, st_to->xy) * 4096U / this->vehicle->GetDisplayMaxSpeed();
 

	
 
			/* If the vehicle is currently full loading, increase the capacities at the station
 
			 * 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) {
 
					IncreaseStats(st, c, next_station, 1, 0, 0, EUM_INCREASE | restricted_mode);
 
				} else {
 
					IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);
 
				}
 
			} else {
 
				IncreaseStats(st, c, next_station, cargo_quantity, 0, time_estimate, EUM_REFRESH | restricted_mode);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Iterate over orders starting at \a cur and \a next and refresh links
 
 * associated with them. \a cur and \a next can be equal. If they're not they
 
 * must be "neighbours" in their order list, which means \a next must be directly
 
 * reachable from \a cur without passing any further OT_GOTO_STATION or
 
 * OT_IMPLICIT orders in between.
 
 * @param cur Current order being evaluated.
src/saveload/saveload.h
Show inline comments
 
@@ -344,48 +344,49 @@ enum SaveLoadVersion : uint16_t {
 
	SLV_NEWGRF_ROAD_STOPS,                  ///< 303  PR#10144 NewGRF road stops.
 
	SLV_LINKGRAPH_EDGES,                    ///< 304  PR#10314 Explicitly store link graph edges destination, PR#10471 int64_t instead of uint64_t league rating
 

	
 
	SLV_VELOCITY_NAUTICAL,                  ///< 305  PR#10594 Separation of land and nautical velocity (knots!)
 
	SLV_CONSISTENT_PARTIAL_Z,               ///< 306  PR#10570 Conversion from an inconsistent partial Z calculation for slopes, to one that is (more) consistent.
 
	SLV_MORE_CARGO_AGE,                     ///< 307  PR#10596 Track cargo age for a longer period.
 
	SLV_LINKGRAPH_SECONDS,                  ///< 308  PR#10610 Store linkgraph update intervals in seconds instead of days.
 
	SLV_AI_START_DATE,                      ///< 309  PR#10653 Removal of individual AI start dates and added a generic one.
 

	
 
	SLV_EXTEND_VEHICLE_RANDOM,              ///< 310  PR#10701 Extend vehicle random bits.
 
	SLV_EXTEND_ENTITY_MAPPING,              ///< 311  PR#10672 Extend entity mapping range.
 
	SLV_DISASTER_VEH_STATE,                 ///< 312  PR#10798 Explicit storage of disaster vehicle state.
 
	SLV_SAVEGAME_ID,                        ///< 313  PR#10719 Add an unique ID to every savegame (used to deduplicate surveys).
 
	SLV_STRING_GAMELOG,                     ///< 314  PR#10801 Use std::string in gamelog.
 

	
 
	SLV_INDUSTRY_CARGO_REORGANISE,          ///< 315  PR#10853 Industry accepts/produced data reorganised.
 
	SLV_PERIODS_IN_TRANSIT_RENAME,          ///< 316  PR#11112 Rename days in transit to (cargo) periods in transit.
 
	SLV_NEWGRF_LAST_SERVICE,                ///< 317  PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
 
	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 {
 
	SL_OK     = 0, ///< completed successfully
 
	SL_ERROR  = 1, ///< error that was caught before internal structures were modified
 
	SL_REINIT = 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
 
};
 

	
 
/** Deals with the type of the savegame, independent of extension */
 
struct FileToSaveLoad {
 
	SaveLoadOperation file_op;       ///< File operation to perform.
 
	DetailedFileType detail_ftype;   ///< Concrete file type (PNG, BMP, old save, etc).
 
	AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
 
	std::string name;                ///< Name of the file.
 
	std::string title;               ///< Internal name of the game.
 

	
 
	void SetMode(FiosType ft);
 
	void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft);
 
	void Set(const FiosItem &item);
 
};
 

	
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -699,49 +699,50 @@ public:
 
		SLE_CONDVAR(Vehicle, build_year,            SLE_FILE_U8 | SLE_VAR_I32,    SL_MIN_VERSION,  SLV_31),
 
		SLE_CONDVAR(Vehicle, build_year,            SLE_INT32,                   SLV_31, SL_MAX_VERSION),
 

	
 
		    SLE_VAR(Vehicle, load_unload_ticks,     SLE_UINT16),
 
		SLEG_CONDVAR("cargo_paid_for", _cargo_paid_for, SLE_UINT16,              SLV_45, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, vehicle_flags,         SLE_FILE_U8 | SLE_VAR_U16,   SLV_40, SLV_180),
 
		SLE_CONDVAR(Vehicle, vehicle_flags,         SLE_UINT16,                 SLV_180, SL_MAX_VERSION),
 

	
 
		SLE_CONDVAR(Vehicle, profit_this_year,      SLE_FILE_I32 | SLE_VAR_I64,   SL_MIN_VERSION,  SLV_65),
 
		SLE_CONDVAR(Vehicle, profit_this_year,      SLE_INT64,                   SLV_65, SL_MAX_VERSION),
 
		SLE_CONDVAR(Vehicle, profit_last_year,      SLE_FILE_I32 | SLE_VAR_I64,   SL_MIN_VERSION,  SLV_65),
 
		SLE_CONDVAR(Vehicle, profit_last_year,      SLE_INT64,                   SLV_65, SL_MAX_VERSION),
 
		SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64,  SLV_51,  SLV_65),
 
		SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64,                   SLV_65,  SLV_68),
 
		SLE_CONDVAR(Vehicle, value,                 SLE_FILE_I32 | SLE_VAR_I64,   SL_MIN_VERSION,  SLV_65),
 
		SLE_CONDVAR(Vehicle, value,                 SLE_INT64,                   SLV_65, SL_MAX_VERSION),
 

	
 
		SLE_CONDVAR(Vehicle, random_bits,           SLE_FILE_U8 | SLE_VAR_U16,    SLV_2, SLV_EXTEND_VEHICLE_RANDOM),
 
		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;
 
	}
 
#endif
 
	inline const static SaveLoadCompatTable compat_description = _vehicle_common_sl_compat;
 

	
 
	void Save(Vehicle *v) const override
 
	{
 
		SlObject(v, this->GetDescription());
 
	}
 

	
 
	void Load(Vehicle *v) const override
 
	{
 
		SlObject(v, this->GetLoadDescription());
 
	}
 

	
 
	void FixPointers(Vehicle *v) const override
 
	{
 
		SlObject(v, this->GetDescription());
 
	}
 
};
src/timetable_cmd.cpp
Show inline comments
 
@@ -243,49 +243,49 @@ CommandCost CmdBulkChangeTimetable(DoCom
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Clear the lateness counter to make the vehicle on time.
 
 * @param flags Operation to perform.
 
 * @param veh Vehicle with the orders to change.
 
 * @param apply_to_group Set to reset the late counter for all vehicles sharing the orders.
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_to_group)
 
{
 
	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;
 

	
 
	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;
 
				}
 
			}
 
			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);
 
				}
 
			}
 
		} else {
 
			v->lateness_counter = 0;
 
			SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
 
		}
 
	}
 

	
 
	return CommandCost();
 
@@ -433,49 +433,49 @@ CommandCost CmdAutofillTimetable(DoComma
 
			ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
 
			ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
 
		}
 

	
 
		for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
 
			if (v2 != v) {
 
				/* Stop autofilling; only one vehicle at a time can perform autofill */
 
				ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE);
 
				ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
 
			}
 
			SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index);
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * 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;
 
	Order *real_current_order = v->GetOrder(v->cur_real_order_index);
 
	assert(real_current_order != nullptr);
 

	
 
	VehicleOrderID first_manual_order = 0;
 
	for (Order *o = v->GetFirstOrder(); o != nullptr && o->IsType(OT_IMPLICIT); o = o->next) {
 
		++first_manual_order;
 
	}
 

	
 
	bool just_started = false;
 

	
 
	/* This vehicle is arriving at the first destination in the timetable. */
 
	if (v->cur_real_order_index == first_manual_order && travelling) {
 
		/* If the start date hasn't been set, or it was set automatically when
 
		 * the vehicle last arrived at the first destination, update it to the
 
		 * current time. Otherwise set the late counter appropriately to when
 
		 * the vehicle should have arrived. */
 
		just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
 

	
 
@@ -493,69 +493,69 @@ void UpdateVehicleTimetable(Vehicle *v, 
 
	bool autofilling = HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
 
	bool remeasure_wait_time = !real_current_order->IsWaitTimetabled() ||
 
			(autofilling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME));
 

	
 
	if (travelling && remeasure_wait_time) {
 
		/* We just finished travelling and want to remeasure the loading time,
 
		 * so do not apply any restrictions for the loading to finish. */
 
		v->current_order.SetWaitTime(0);
 
	}
 

	
 
	if (just_started) return;
 

	
 
	/* Before modifying waiting times, check whether we want to preserve bigger ones. */
 
	if (!real_current_order->IsType(OT_CONDITIONAL) &&
 
			(travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) {
 
		/* Round the time taken up to the nearest day, as this will avoid
 
		 * confusion for people who are timetabling in days, and can be
 
		 * adjusted later by people who aren't.
 
		 * 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);
 
		}
 
	}
 

	
 
	if (v->cur_real_order_index == first_manual_order && travelling) {
 
		/* If we just started we would have returned earlier and have not reached
 
		 * this code. So obviously, we have completed our round: So turn autofill
 
		 * off again. */
 
		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;
 

	
 
	v->lateness_counter -= (timetabled - time_taken);
 

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

	
 
	for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
 
		SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
 
	}
 
}
src/vehicle.cpp
Show inline comments
 
@@ -2312,49 +2312,49 @@ void Vehicle::LeaveStation()
 
		}
 
	}
 

	
 

	
 
	this->MarkDirty();
 
}
 

	
 
/**
 
 * Reset all refit_cap in the consist to cargo_cap.
 
 */
 
void Vehicle::ResetRefitCaps()
 
{
 
	for (Vehicle *v = this; v != nullptr; v = v->Next()) v->refit_cap = v->cargo_cap;
 
}
 

	
 
/**
 
 * Handle the loading of the vehicle; when not it skips through dummy
 
 * orders and does nothing in all other cases.
 
 * @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();
 

	
 
			this->LeaveStation();
 

	
 
			/* Only advance to next order if we just loaded at the current one */
 
			const Order *order = this->GetOrder(this->cur_implicit_order_index);
 
			if (order == nullptr ||
 
					(!order->IsType(OT_IMPLICIT) && !order->IsType(OT_GOTO_STATION)) ||
 
					order->GetDestination() != this->last_station_visited) {
 
				return;
 
			}
 
			break;
 
		}
 

	
 
		case OT_DUMMY: break;
 

	
 
		default: return;
 
	}
 

	
 
	this->IncrementImplicitOrderIndex();
0 comments (0 inline, 0 general)