mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use economy timer for vehicle day proc
parent
255b2e8a1a
commit
82ce84e5f9
|
@ -107,7 +107,7 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tick() override;
|
bool Tick() override;
|
||||||
void OnNewDay() override;
|
void OnNewEconomyDay() override;
|
||||||
uint Crash(bool flooded = false) override;
|
uint Crash(bool flooded = false) override;
|
||||||
TileIndex GetOrderStationLocation(StationID station) override;
|
TileIndex GetOrderStationLocation(StationID station) override;
|
||||||
ClosestDepot FindClosestDepot() override;
|
ClosestDepot FindClosestDepot() override;
|
||||||
|
|
|
@ -440,7 +440,7 @@ Money Aircraft::GetRunningCost() const
|
||||||
return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF());
|
return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Aircraft::OnNewDay()
|
void Aircraft::OnNewEconomyDay()
|
||||||
{
|
{
|
||||||
if (!this->IsNormalAircraft()) return;
|
if (!this->IsNormalAircraft()) return;
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ struct RoadVehicle FINAL : public GroundVehicle<RoadVehicle, VEH_ROAD> {
|
||||||
int GetDisplayImageWidth(Point *offset = nullptr) const;
|
int GetDisplayImageWidth(Point *offset = nullptr) const;
|
||||||
bool IsInDepot() const override { return this->state == RVSB_IN_DEPOT; }
|
bool IsInDepot() const override { return this->state == RVSB_IN_DEPOT; }
|
||||||
bool Tick() override;
|
bool Tick() override;
|
||||||
void OnNewDay() override;
|
void OnNewEconomyDay() override;
|
||||||
uint Crash(bool flooded = false) override;
|
uint Crash(bool flooded = false) override;
|
||||||
Trackdir GetVehicleTrackdir() const override;
|
Trackdir GetVehicleTrackdir() const override;
|
||||||
TileIndex GetOrderStationLocation(StationID station) override;
|
TileIndex GetOrderStationLocation(StationID station) override;
|
||||||
|
|
|
@ -1706,7 +1706,7 @@ static void CheckIfRoadVehNeedsService(RoadVehicle *v)
|
||||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoadVehicle::OnNewDay()
|
void RoadVehicle::OnNewEconomyDay()
|
||||||
{
|
{
|
||||||
AgeVehicle(this);
|
AgeVehicle(this);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct Ship FINAL : public SpecializedVehicle<Ship, VEH_SHIP> {
|
||||||
Money GetRunningCost() const override;
|
Money GetRunningCost() const override;
|
||||||
bool IsInDepot() const override { return this->state == TRACK_BIT_DEPOT; }
|
bool IsInDepot() const override { return this->state == TRACK_BIT_DEPOT; }
|
||||||
bool Tick() override;
|
bool Tick() override;
|
||||||
void OnNewDay() override;
|
void OnNewEconomyDay() override;
|
||||||
Trackdir GetVehicleTrackdir() const override;
|
Trackdir GetVehicleTrackdir() const override;
|
||||||
TileIndex GetOrderStationLocation(StationID station) override;
|
TileIndex GetOrderStationLocation(StationID station) override;
|
||||||
ClosestDepot FindClosestDepot() override;
|
ClosestDepot FindClosestDepot() override;
|
||||||
|
|
|
@ -223,7 +223,7 @@ Money Ship::GetRunningCost() const
|
||||||
return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
|
return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ship::OnNewDay()
|
void Ship::OnNewEconomyDay()
|
||||||
{
|
{
|
||||||
if ((++this->day_counter & 7) == 0) {
|
if ((++this->day_counter & 7) == 0) {
|
||||||
DecreaseVehicleValue(this);
|
DecreaseVehicleValue(this);
|
||||||
|
|
|
@ -123,7 +123,7 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
|
||||||
int GetDisplayImageWidth(Point *offset = nullptr) const;
|
int GetDisplayImageWidth(Point *offset = nullptr) const;
|
||||||
bool IsInDepot() const override { return this->track == TRACK_BIT_DEPOT; }
|
bool IsInDepot() const override { return this->track == TRACK_BIT_DEPOT; }
|
||||||
bool Tick() override;
|
bool Tick() override;
|
||||||
void OnNewDay() override;
|
void OnNewEconomyDay() override;
|
||||||
uint Crash(bool flooded = false) override;
|
uint Crash(bool flooded = false) override;
|
||||||
Trackdir GetVehicleTrackdir() const override;
|
Trackdir GetVehicleTrackdir() const override;
|
||||||
TileIndex GetOrderStationLocation(StationID station) override;
|
TileIndex GetOrderStationLocation(StationID station) override;
|
||||||
|
|
|
@ -4165,7 +4165,7 @@ static void CheckIfTrainNeedsService(Train *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update day counters of the train vehicle. */
|
/** Update day counters of the train vehicle. */
|
||||||
void Train::OnNewDay()
|
void Train::OnNewEconomyDay()
|
||||||
{
|
{
|
||||||
AgeVehicle(this);
|
AgeVehicle(this);
|
||||||
|
|
||||||
|
|
|
@ -918,15 +918,15 @@ void VehicleEnteredDepotThisTick(Vehicle *v)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increases the day counter for all vehicles and calls 1-day and 32-day handlers.
|
* Increases the day counter for all vehicles and calls 1-day and 32-day handlers.
|
||||||
* Each tick, it processes vehicles with "index % DAY_TICKS == TimerGameCalendar::date_fract",
|
* Each tick, it processes vehicles with "index % DAY_TICKS == TimerGameEconomy::date_fract",
|
||||||
* so each day, all vehicles are processes in DAY_TICKS steps.
|
* so each day, all vehicles are processes in DAY_TICKS steps.
|
||||||
*/
|
*/
|
||||||
static void RunVehicleDayProc()
|
static void RunEconomyVehicleDayProc()
|
||||||
{
|
{
|
||||||
if (_game_mode != GM_NORMAL) return;
|
if (_game_mode != GM_NORMAL) return;
|
||||||
|
|
||||||
/* Run the day_proc for every DAY_TICKS vehicle starting at TimerGameCalendar::date_fract. */
|
/* Run the economy day proc for every DAY_TICKS vehicle starting at TimerGameEconomy::date_fract. */
|
||||||
for (size_t i = TimerGameCalendar::date_fract; i < Vehicle::GetPoolSize(); i += Ticks::DAY_TICKS) {
|
for (size_t i = TimerGameEconomy::date_fract; i < Vehicle::GetPoolSize(); i += Ticks::DAY_TICKS) {
|
||||||
Vehicle *v = Vehicle::Get(i);
|
Vehicle *v = Vehicle::Get(i);
|
||||||
if (v == nullptr) continue;
|
if (v == nullptr) continue;
|
||||||
|
|
||||||
|
@ -947,7 +947,7 @@ static void RunVehicleDayProc()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is called once per day for each vehicle, but not in the first tick of the day */
|
/* This is called once per day for each vehicle, but not in the first tick of the day */
|
||||||
v->OnNewDay();
|
v->OnNewEconomyDay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -955,7 +955,7 @@ void CallVehicleTicks()
|
||||||
{
|
{
|
||||||
_vehicles_to_autoreplace.clear();
|
_vehicles_to_autoreplace.clear();
|
||||||
|
|
||||||
RunVehicleDayProc();
|
RunEconomyVehicleDayProc();
|
||||||
|
|
||||||
{
|
{
|
||||||
PerformanceMeasurer framerate(PFE_GL_ECONOMY);
|
PerformanceMeasurer framerate(PFE_GL_ECONOMY);
|
||||||
|
|
|
@ -567,9 +567,9 @@ public:
|
||||||
virtual bool Tick() { return true; };
|
virtual bool Tick() { return true; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the new day handler of the vehicle
|
* Calls the new economy day handler of the vehicle
|
||||||
*/
|
*/
|
||||||
virtual void OnNewDay() {};
|
virtual void OnNewEconomyDay() {};
|
||||||
|
|
||||||
void ShiftDates(TimerGameEconomy::Date interval);
|
void ShiftDates(TimerGameEconomy::Date interval);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue