From f22a5685c38b073e94fed594218fe172559d287d Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 18 Nov 2021 23:55:48 +0000 Subject: [PATCH] Divide cost instead of cost_factor in running costs division This is to prevent 0 running costs for cheap vehicles when cost_factor would be < 1 --- src/aircraft_cmd.cpp | 8 ++++---- src/roadveh_cmd.cpp | 9 +++++---- src/ship_cmd.cpp | 10 +++++----- src/train_cmd.cpp | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index b2ef6d0d78..af24164f86 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -463,18 +463,18 @@ Money Aircraft::GetRunningCost() const { const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost); + Money cost = GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF()); if (this->cur_speed == 0) { if (this->IsInDepot()) { /* running costs if in depot */ - cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_in_depot); } else { /* running costs if stopped */ - cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_when_stopped); } } - - return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF()); + return cost; } void Aircraft::OnNewDay() diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index f3e99c7f0b..9ec01ab4b6 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -2131,17 +2131,18 @@ Money RoadVehicle::GetRunningCost() const uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost); if (cost_factor == 0) return 0; + Money cost = GetPrice(e->u.road.running_cost_class, cost_factor, e->GetGRF()); + if (this->cur_speed == 0) { if (this->IsInDepot()) { /* running costs if in depot */ - cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_in_depot); } else { /* running costs if stopped */ - cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_when_stopped); } } - - return GetPrice(e->u.road.running_cost_class, cost_factor, e->GetGRF()); + return cost; } bool RoadVehicle::Tick() diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index e7de6076ac..1f7914bf40 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -229,18 +229,18 @@ Money Ship::GetRunningCost() const { const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost); + Money cost = GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF()); if (this->cur_speed == 0) { if (this->IsInDepot()) { /* running costs if in depot */ - cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_in_depot); } else { /* running costs if stopped */ - cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_when_stopped); } - }; - - return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF()); + } + return cost; } void Ship::OnNewDay() diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 0a572ab817..d60cc4c74c 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -6456,19 +6456,19 @@ Money Train::GetRunningCost() const /* Halve running cost for multiheaded parts */ if (v->IsMultiheaded()) cost_factor /= 2; - if (this->cur_speed == 0) { - if (this->IsInDepot()) { - /* running costs if in depot */ - cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; - } else { - /* running costs if stopped */ - cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; - } - } - cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF()); } while ((v = v->GetNextVehicle()) != nullptr); + if (this->cur_speed == 0) { + if (this->IsInDepot()) { + /* running costs if in depot */ + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_in_depot); + } else { + /* running costs if stopped */ + cost = CeilDivT(cost, _settings_game.difficulty.vehicle_costs_when_stopped); + } + } + return cost; }