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
This commit is contained in:
Jonathan G Rennison
2021-11-18 23:55:48 +00:00
parent bb8e4eb18a
commit f22a5685c3
4 changed files with 24 additions and 23 deletions

View File

@@ -463,18 +463,18 @@ Money Aircraft::GetRunningCost() const
{ {
const Engine *e = this->GetEngine(); const Engine *e = this->GetEngine();
uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost); 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->cur_speed == 0) {
if (this->IsInDepot()) { if (this->IsInDepot()) {
/* running costs if in depot */ /* running costs if in depot */
cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_in_depot);
} else { } else {
/* running costs if stopped */ /* running costs if stopped */
cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_when_stopped);
} }
} }
return cost;
return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF());
} }
void Aircraft::OnNewDay() void Aircraft::OnNewDay()

View File

@@ -2131,17 +2131,18 @@ Money RoadVehicle::GetRunningCost() const
uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost); uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost);
if (cost_factor == 0) return 0; 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->cur_speed == 0) {
if (this->IsInDepot()) { if (this->IsInDepot()) {
/* running costs if in depot */ /* running costs if in depot */
cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_in_depot);
} else { } else {
/* running costs if stopped */ /* running costs if stopped */
cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_when_stopped);
} }
} }
return cost;
return GetPrice(e->u.road.running_cost_class, cost_factor, e->GetGRF());
} }
bool RoadVehicle::Tick() bool RoadVehicle::Tick()

View File

@@ -229,18 +229,18 @@ Money Ship::GetRunningCost() const
{ {
const Engine *e = this->GetEngine(); const Engine *e = this->GetEngine();
uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost); 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->cur_speed == 0) {
if (this->IsInDepot()) { if (this->IsInDepot()) {
/* running costs if in depot */ /* running costs if in depot */
cost_factor /= _settings_game.difficulty.vehicle_costs_in_depot; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_in_depot);
} else { } else {
/* running costs if stopped */ /* running costs if stopped */
cost_factor /= _settings_game.difficulty.vehicle_costs_when_stopped; cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_when_stopped);
} }
}; }
return cost;
return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
} }
void Ship::OnNewDay() void Ship::OnNewDay()

View File

@@ -6456,19 +6456,19 @@ Money Train::GetRunningCost() const
/* Halve running cost for multiheaded parts */ /* Halve running cost for multiheaded parts */
if (v->IsMultiheaded()) cost_factor /= 2; 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()); cost += GetPrice(e->u.rail.running_cost_class, cost_factor, e->GetGRF());
} while ((v = v->GetNextVehicle()) != nullptr); } while ((v = v->GetNextVehicle()) != nullptr);
if (this->cur_speed == 0) {
if (this->IsInDepot()) {
/* running costs if in depot */
cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_in_depot);
} else {
/* running costs if stopped */
cost = CeilDivT<Money>(cost, _settings_game.difficulty.vehicle_costs_when_stopped);
}
}
return cost; return cost;
} }