Use DateTicksScaled for Vehicle::last_loading_tick

pull/642/head
Jonathan G Rennison 4 months ago
parent 74686b9c63
commit 1ce8930583

@ -3907,11 +3907,15 @@ bool AfterLoadGame()
/* Use current order time to approximate last loading time */
if (IsSavegameVersionBefore(SLV_LAST_LOADING_TICK) && SlXvIsFeatureMissing(XSLFI_LAST_LOADING_TICK)) {
for (Vehicle *v : Vehicle::Iterate()) {
v->last_loading_tick = std::max(_scaled_tick_counter, static_cast<uint64_t>(v->current_order_time)) - v->current_order_time;
v->last_loading_tick = _scaled_date_ticks - v->current_order_time;
}
} else if (SlXvIsFeaturePresent(XSLFI_LAST_LOADING_TICK, 1, 1)) {
} else if (SlXvIsFeatureMissing(XSLFI_LAST_LOADING_TICK, 3)) {
const DateTicksScaledDelta delta = _scaled_date_ticks.base() - (int64_t)_scaled_tick_counter;
for (Vehicle *v : Vehicle::Iterate()) {
v->last_loading_tick *= _settings_game.economy.day_length_factor;
if (v->last_loading_tick != 0) {
if (SlXvIsFeaturePresent(XSLFI_LAST_LOADING_TICK, 1, 1)) v->last_loading_tick = v->last_loading_tick.base() * _settings_game.economy.day_length_factor;
v->last_loading_tick += delta;
}
}
}

@ -178,7 +178,7 @@ public:
SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SLV_TIMETABLE_TICKS_TYPE),
SLE_CONDVAR(Vehicle, current_order_time, SLE_FILE_I32 | SLE_VAR_U32, 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, last_loading_tick, SLE_FILE_U64 | SLE_VAR_I64, 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)

@ -197,7 +197,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr },
{ XSLFI_U64_TICK_COUNTER, XSCF_NULL, 1, 1, "u64_tick_counter", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_TRAVEL_TIME, XSCF_NULL, 1, 1, "linkgraph_travel_time", nullptr, nullptr, nullptr },
{ XSLFI_LAST_LOADING_TICK, XSCF_NULL, 2, 2, "last_loading_tick", nullptr, nullptr, nullptr },
{ XSLFI_LAST_LOADING_TICK, XSCF_NULL, 3, 3, "last_loading_tick", nullptr, nullptr, nullptr },
{ XSLFI_SCRIPT_LEAGUE_TABLES, XSCF_NULL, 1, 1, "script_league_tables", nullptr, nullptr, "LEAE,LEAT" },
{ XSLFI_VELOCITY_NAUTICAL, XSCF_IGNORABLE_ALL, 1, 1, "velocity_nautical", nullptr, nullptr, nullptr },
{ XSLFI_CONSISTENT_PARTIAL_Z, XSCF_NULL, 1, 1, "consistent_partial_z", nullptr, nullptr, nullptr },

@ -832,7 +832,7 @@ SaveLoadTable GetVehicleDescription(VehicleType vt)
SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION),
SLE_CONDVAR_X(Vehicle, current_loading_time, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_AUTO_TIMETABLE)),
SLE_CONDVAR_X(Vehicle, current_loading_time, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP, SL_JOKER_1_23)),
SLE_CONDVAR_X(Vehicle, last_loading_tick, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LAST_LOADING_TICK)),
SLE_CONDVAR_X(Vehicle, last_loading_tick, SLE_INT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LAST_LOADING_TICK)),
SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SPRINGPP)),
SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION),

@ -263,7 +263,7 @@ class NIHVehicle : public NIHelper {
seprintf(buffer, lastof(buffer), " V Last loading station: %u, %s", v->last_loading_station, BaseStation::Get(v->last_loading_station)->GetCachedName());
output.print(buffer);
seprintf(buffer, lastof(buffer), " V Last loading tick: " OTTD_PRINTF64 " (" OTTD_PRINTF64 ", " OTTD_PRINTF64 " mins ago)",
v->last_loading_tick, _scaled_tick_counter - v->last_loading_tick, (_scaled_tick_counter - v->last_loading_tick) / _settings_time.ticks_per_minute);
v->last_loading_tick.base(), (_scaled_date_ticks - v->last_loading_tick).base(), (_scaled_date_ticks - v->last_loading_tick).base() / _settings_time.ticks_per_minute);
output.print(buffer);
}
if (v->IsGroundVehicle()) {

@ -3239,7 +3239,7 @@ static void VehicleIncreaseStats(const Vehicle *front)
{
for (const Vehicle *v = front; v != nullptr; v = v->Next()) {
StationID last_loading_station = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_station : front->last_loading_station;
uint64_t loading_tick = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_tick : front->last_loading_tick;
DateTicksScaled loading_tick = HasBit(front->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? v->last_loading_tick : front->last_loading_tick;
if (v->refit_cap > 0 &&
last_loading_station != INVALID_STATION &&
last_loading_station != front->last_station_visited &&
@ -3254,7 +3254,7 @@ static void VehicleIncreaseStats(const Vehicle *front)
EdgeUpdateMode restricted_mode = EUM_INCREASE;
if (v->type == VEH_AIRCRAFT) restricted_mode |= EUM_AIRCRAFT;
IncreaseStats(Station::Get(last_loading_station), v->cargo_type, front->last_station_visited, v->refit_cap,
std::min<uint>(v->refit_cap, v->cargo.StoredCount()), _scaled_tick_counter - loading_tick, restricted_mode);
std::min<uint>(v->refit_cap, v->cargo.StoredCount()), (_scaled_date_ticks - loading_tick).AsTicksT<uint32_t>(), restricted_mode);
}
}
}
@ -3474,7 +3474,7 @@ void Vehicle::LeaveStation()
/* if the vehicle could load here or could stop with cargo loaded set the last loading station */
this->last_loading_station = this->last_station_visited;
this->last_loading_tick = _scaled_tick_counter;
this->last_loading_tick = _scaled_date_ticks;
ClrBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP);
} else if (cargoes_can_leave_with_cargo == 0) {
/* can leave with no cargoes */
@ -3488,14 +3488,14 @@ void Vehicle::LeaveStation()
/* NB: this is saved here as we overwrite it on the first iteration of the loop below */
StationID head_last_loading_station = this->last_loading_station;
uint64_t head_last_loading_tick = this->last_loading_tick;
DateTicksScaled head_last_loading_tick = this->last_loading_tick;
for (Vehicle *u = this; u != nullptr; u = u->Next()) {
StationID last_loading_station = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_station : head_last_loading_station;
uint64_t last_loading_tick = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_tick : head_last_loading_tick;
DateTicksScaled last_loading_tick = HasBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP) ? u->last_loading_tick : head_last_loading_tick;
if (u->cargo_type < NUM_CARGO && HasBit(cargoes_can_load_unload, u->cargo_type)) {
if (HasBit(cargoes_can_leave_with_cargo, u->cargo_type)) {
u->last_loading_station = this->last_station_visited;
u->last_loading_tick = _scaled_tick_counter;
u->last_loading_tick = _scaled_date_ticks;
} else {
u->last_loading_station = INVALID_STATION;
}
@ -4692,6 +4692,7 @@ void AdjustVehicleScaledTickBase(DateTicksScaledDelta delta)
{
for (Vehicle *v : Vehicle::Iterate()) {
if (v->timetable_start != 0) v->timetable_start += delta;
if (v->last_loading_tick != 0) v->last_loading_tick += delta;
}
for (OrderList *order_list : OrderList::Iterate()) {

@ -380,7 +380,7 @@ public:
StationID last_station_visited; ///< The last station we stopped at.
StationID last_loading_station; ///< Last station the vehicle has stopped at and could possibly leave from with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
uint64_t last_loading_tick; ///< Last time (relative to _scaled_tick_counter) the vehicle has stopped at a station and could possibly leave with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
DateTicksScaled last_loading_tick; ///< Last tick (_scaled_date_ticks) the vehicle has stopped at a station and could possibly leave with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
uint16_t cargo_cap; ///< total capacity

Loading…
Cancel
Save