Fixes incorrect link graph edge travel times with non-unity day length
Change vehicle last_loading_tick to be relative to _scaled_tick_counter
This commit is contained in:
@@ -229,7 +229,7 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, Edge
|
||||
if (edge.travel_time_sum == 0) {
|
||||
edge.travel_time_sum = (edge.capacity + capacity) * travel_time;
|
||||
} else if (travel_time == 0) {
|
||||
edge.travel_time_sum += edge.travel_time_sum / edge.capacity * capacity;
|
||||
edge.travel_time_sum += (edge.travel_time_sum / edge.capacity) * capacity;
|
||||
} else {
|
||||
edge.travel_time_sum += travel_time * capacity;
|
||||
}
|
||||
@@ -239,7 +239,7 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, Edge
|
||||
/* If travel time is not provided, we scale the stored time based on
|
||||
* the capacity increase. */
|
||||
if (capacity > edge.capacity && travel_time == 0) {
|
||||
edge.travel_time_sum = edge.travel_time_sum / edge.capacity * capacity;
|
||||
edge.travel_time_sum = (edge.travel_time_sum / edge.capacity) * capacity;
|
||||
edge.capacity = capacity;
|
||||
} else {
|
||||
edge.capacity = std::max(edge.capacity, capacity);
|
||||
|
@@ -3817,7 +3817,11 @@ 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(_tick_counter, static_cast<uint64>(v->current_order_time)) - v->current_order_time;
|
||||
v->last_loading_tick = std::max(_scaled_tick_counter, static_cast<uint64>(v->current_order_time)) - v->current_order_time;
|
||||
}
|
||||
} else if (SlXvIsFeaturePresent(XSLFI_LAST_LOADING_TICK, 1, 1)) {
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
v->last_loading_tick *= _settings_game.economy.day_length_factor;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -180,7 +180,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, 1, 1, "last_loading_tick", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_LAST_LOADING_TICK, XSCF_NULL, 2, 2, "last_loading_tick", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_SCRIPT_LEAGUE_TABLES, XSCF_NULL, 1, 1, "script_league_tables", nullptr, nullptr, "LEAE,LEAT" },
|
||||
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
|
||||
};
|
||||
|
@@ -1717,6 +1717,9 @@ static void DayLengthChanged(int32 new_value)
|
||||
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta);
|
||||
AdjustAllSignalSpeedRestrictionTickValues(_scaled_date_ticks - old_scaled_date_ticks);
|
||||
|
||||
extern void AdjustVehicleScaledTickBase(int64 delta);
|
||||
AdjustVehicleScaledTickBase(_scaled_date_ticks - old_scaled_date_ticks);
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
|
@@ -169,6 +169,9 @@ class NIHVehicle : public NIHelper {
|
||||
if (BaseStation::IsValidID(v->last_loading_station)) {
|
||||
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);
|
||||
output.print(buffer);
|
||||
}
|
||||
if (v->IsGroundVehicle()) {
|
||||
const GroundVehicleCache &gvc = *(v->GetGroundVehicleCache());
|
||||
|
@@ -3158,7 +3158,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()), _tick_counter - loading_tick, restricted_mode);
|
||||
std::min<uint>(v->refit_cap, v->cargo.StoredCount()), _scaled_tick_counter - loading_tick, restricted_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3379,7 +3379,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 = _tick_counter;
|
||||
this->last_loading_tick = _scaled_tick_counter;
|
||||
ClrBit(this->vehicle_flags, VF_LAST_LOAD_ST_SEP);
|
||||
} else if (cargoes_can_leave_with_cargo == 0) {
|
||||
/* can leave with no cargoes */
|
||||
@@ -3400,7 +3400,7 @@ void Vehicle::LeaveStation()
|
||||
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 = _tick_counter;
|
||||
u->last_loading_tick = _scaled_tick_counter;
|
||||
} else {
|
||||
u->last_loading_station = INVALID_STATION;
|
||||
}
|
||||
@@ -4563,6 +4563,13 @@ void DumpVehicleStats(char *buffer, const char *last)
|
||||
buffer += seprintf(buffer, last, " %10s: %5u\n", "total", (uint)Vehicle::GetNumItems());
|
||||
}
|
||||
|
||||
void AdjustVehicleScaledTickBase(int64 delta)
|
||||
{
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
v->last_loading_tick += delta;
|
||||
}
|
||||
}
|
||||
|
||||
void ShiftVehicleDates(int interval)
|
||||
{
|
||||
for (Vehicle *v : Vehicle::Iterate()) {
|
||||
@@ -4571,6 +4578,8 @@ void ShiftVehicleDates(int interval)
|
||||
|
||||
extern void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta);
|
||||
AdjustAllSignalSpeedRestrictionTickValues(interval * DAY_TICKS * _settings_game.economy.day_length_factor);
|
||||
|
||||
AdjustVehicleScaledTickBase(interval * DAY_TICKS * _settings_game.economy.day_length_factor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -349,7 +349,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 last_loading_tick; ///< Last time (relative to _tick_counter) the vehicle has stopped at a station and could possibly leave with any cargo loaded. (See VF_LAST_LOAD_ST_SEP).
|
||||
uint64 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).
|
||||
|
||||
CargoID cargo_type; ///< type of cargo this vehicle is carrying
|
||||
byte cargo_subtype; ///< Used for livery refits (NewGRF variations)
|
||||
|
Reference in New Issue
Block a user