Run most "daily" vehicle tasks at a fixed frequency at day lengths >= 8
This includes: running costs, track sharing costs, breakdown checks, servicing checks, order checks
This commit is contained in:
@@ -111,6 +111,7 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
||||
|
||||
bool Tick();
|
||||
void OnNewDay();
|
||||
void OnPeriodic();
|
||||
uint Crash(bool flooded = false);
|
||||
TileIndex GetOrderStationLocation(StationID station);
|
||||
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
||||
|
@@ -483,10 +483,16 @@ void Aircraft::OnNewDay()
|
||||
|
||||
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||
|
||||
AgeVehicle(this);
|
||||
}
|
||||
|
||||
void Aircraft::OnPeriodic()
|
||||
{
|
||||
if (!this->IsNormalAircraft()) return;
|
||||
|
||||
CheckOrders(this);
|
||||
|
||||
CheckVehicleBreakdown(this);
|
||||
AgeVehicle(this);
|
||||
CheckIfAircraftNeedsService(this);
|
||||
|
||||
if (this->running_ticks == 0) return;
|
||||
|
@@ -139,6 +139,7 @@ struct RoadVehicle FINAL : public GroundVehicle<RoadVehicle, VEH_ROAD> {
|
||||
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
|
||||
bool Tick();
|
||||
void OnNewDay();
|
||||
void OnPeriodic();
|
||||
uint Crash(bool flooded = false);
|
||||
Trackdir GetVehicleTrackdir() const;
|
||||
TileIndex GetOrderStationLocation(StationID station);
|
||||
|
@@ -2228,6 +2228,12 @@ void RoadVehicle::OnNewDay()
|
||||
if (!this->IsFrontEngine()) return;
|
||||
|
||||
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||
}
|
||||
|
||||
void RoadVehicle::OnPeriodic()
|
||||
{
|
||||
if (!this->IsFrontEngine()) return;
|
||||
|
||||
if (this->blocked_ctr == 0) CheckVehicleBreakdown(this);
|
||||
|
||||
CheckIfRoadVehNeedsService(this);
|
||||
|
@@ -55,6 +55,7 @@ struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
|
||||
bool IsInDepot() const { return this->state == TRACK_BIT_DEPOT; }
|
||||
bool Tick();
|
||||
void OnNewDay();
|
||||
void OnPeriodic();
|
||||
Trackdir GetVehicleTrackdir() const;
|
||||
TileIndex GetOrderStationLocation(StationID station);
|
||||
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
||||
|
@@ -248,9 +248,12 @@ void Ship::OnNewDay()
|
||||
if ((++this->day_counter & 7) == 0) {
|
||||
DecreaseVehicleValue(this);
|
||||
}
|
||||
|
||||
CheckVehicleBreakdown(this);
|
||||
AgeVehicle(this);
|
||||
}
|
||||
|
||||
void Ship::OnPeriodic()
|
||||
{
|
||||
CheckVehicleBreakdown(this);
|
||||
CheckIfShipNeedsService(this);
|
||||
|
||||
CheckOrders(this);
|
||||
|
@@ -170,6 +170,7 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
|
||||
bool IsInDepot() const { return this->track == TRACK_BIT_DEPOT; }
|
||||
bool Tick();
|
||||
void OnNewDay();
|
||||
void OnPeriodic();
|
||||
uint Crash(bool flooded = false);
|
||||
Money CalculateCurrentOverallValue() const;
|
||||
Trackdir GetVehicleTrackdir() const;
|
||||
|
@@ -6598,7 +6598,10 @@ void Train::OnNewDay()
|
||||
AgeVehicle(this);
|
||||
|
||||
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||
}
|
||||
|
||||
void Train::OnPeriodic()
|
||||
{
|
||||
if (this->IsFrontEngine()) {
|
||||
CheckIfTrainNeedsService(this);
|
||||
|
||||
|
@@ -1245,6 +1245,9 @@ template <typename T>
|
||||
void CallVehicleOnNewDay(Vehicle *v)
|
||||
{
|
||||
T::From(v)->T::OnNewDay();
|
||||
|
||||
/* Vehicle::OnPeriodic is decoupled from Vehicle::OnNewDay at day lengths >= 8 */
|
||||
if (_settings_game.economy.day_length_factor < 8) T::From(v)->T::OnPeriodic();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1460,6 +1463,38 @@ void CallVehicleTicks()
|
||||
|
||||
if (_tick_skip_counter == 0) RunVehicleDayProc();
|
||||
|
||||
if (_settings_game.economy.day_length_factor >= 8 && _game_mode == GM_NORMAL) {
|
||||
/*
|
||||
* Vehicle::OnPeriodic is decoupled from Vehicle::OnNewDay at day lengths >= 8
|
||||
* Use a fixed interval of 512 ticks (unscaled) instead
|
||||
*/
|
||||
|
||||
Vehicle *v = nullptr;
|
||||
SCOPE_INFO_FMT([&v], "CallVehicleTicks -> OnPeriodic: %s", scope_dumper().VehicleInfo(v));
|
||||
for (size_t i = _scaled_tick_counter & 0x1FF; i < Vehicle::GetPoolSize(); i += 0x200) {
|
||||
v = Vehicle::Get(i);
|
||||
if (v == nullptr) continue;
|
||||
|
||||
/* This is called once per day for each vehicle, but not in the first tick of the day */
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN:
|
||||
Train::From(v)->Train::OnPeriodic();
|
||||
break;
|
||||
case VEH_ROAD:
|
||||
RoadVehicle::From(v)->RoadVehicle::OnPeriodic();
|
||||
break;
|
||||
case VEH_SHIP:
|
||||
Ship::From(v)->Ship::OnPeriodic();
|
||||
break;
|
||||
case VEH_AIRCRAFT:
|
||||
Aircraft::From(v)->Aircraft::OnPeriodic();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
PerformanceMeasurer framerate(PFE_GL_ECONOMY);
|
||||
Station *si_st = nullptr;
|
||||
|
@@ -615,6 +615,12 @@ public:
|
||||
*/
|
||||
virtual void OnNewDay() {};
|
||||
|
||||
/**
|
||||
* Calls the periodic handler of the vehicle
|
||||
* OnPeriodic is decoupled from OnNewDay at day lengths >= 8
|
||||
*/
|
||||
virtual void OnPeriodic() {};
|
||||
|
||||
/**
|
||||
* Crash the (whole) vehicle chain.
|
||||
* @param flooded whether the cause of the crash is flooding or not.
|
||||
|
Reference in New Issue
Block a user