From 12c89708cb463660d9e39c738471b1c018096cf0 Mon Sep 17 00:00:00 2001 From: glx Date: Thu, 22 Jan 2009 21:33:08 +0000 Subject: [PATCH] (svn r15210) -Fix: Vehicle::GetRunningCost() was wrong for ships and aircraft --- src/aircraft.h | 2 +- src/aircraft_cmd.cpp | 7 ++++++- src/roadveh_cmd.cpp | 3 +-- src/ship.h | 2 +- src/ship_cmd.cpp | 7 ++++++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/aircraft.h b/src/aircraft.h index faf888f881..2f50517df4 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -104,7 +104,7 @@ struct Aircraft : public Vehicle { SpriteID GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 16; } int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 16; } - Money GetRunningCost() const { return AircraftVehInfo(this->engine_type)->running_cost * _price.aircraft_running; } + Money GetRunningCost() const; bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); } void Tick(); void OnNewDay(); diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index f901306f58..2effe517a5 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -629,6 +629,11 @@ static void CheckIfAircraftNeedsService(Vehicle *v) } } +Money Aircraft::GetRunningCost() const +{ + return GetVehicleProperty(this, 0x0E, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running; +} + void Aircraft::OnNewDay() { if (!IsNormalAircraft(this)) return; @@ -643,7 +648,7 @@ void Aircraft::OnNewDay() if (this->running_ticks == 0) return; - CommandCost cost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(this, 0x0E, AircraftVehInfo(this->engine_type)->running_cost) * _price.aircraft_running * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); + CommandCost cost(EXPENSES_AIRCRAFT_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 10a85cc04e..914f8e2d80 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1999,8 +1999,7 @@ void RoadVehicle::OnNewDay() if (this->running_ticks == 0) return; - const RoadVehicleInfo *rvi = RoadVehInfo(this->engine_type); - CommandCost cost(EXPENSES_ROADVEH_RUN, rvi->running_cost * GetPriceByIndex(rvi->running_cost_class) * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); + CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0; diff --git a/src/ship.h b/src/ship.h index 79ab4c156f..831a692dd9 100644 --- a/src/ship.h +++ b/src/ship.h @@ -38,7 +38,7 @@ struct Ship: public Vehicle { SpriteID GetImage(Direction direction) const; int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; } int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } - Money GetRunningCost() const { return ShipVehInfo(this->engine_type)->running_cost * _price.ship_running; } + Money GetRunningCost() const; bool IsInDepot() const { return this->u.ship.state == TRACK_BIT_DEPOT; } void Tick(); void OnNewDay(); diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index ca400db875..45361fc963 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -159,6 +159,11 @@ static void CheckIfShipNeedsService(Vehicle *v) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } +Money Ship::GetRunningCost() const +{ + return GetVehicleProperty(this, 0x0F, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running; +} + void Ship::OnNewDay() { if ((++this->day_counter & 7) == 0) @@ -172,7 +177,7 @@ void Ship::OnNewDay() if (this->running_ticks == 0) return; - CommandCost cost(EXPENSES_SHIP_RUN, GetVehicleProperty(this, 0x0F, ShipVehInfo(this->engine_type)->running_cost) * _price.ship_running * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); + CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS)); this->profit_this_year -= cost.GetCost(); this->running_ticks = 0;