diff options
-rw-r--r-- | src/aircraft_cmd.cpp | 4 | ||||
-rw-r--r-- | src/economy.cpp | 20 | ||||
-rw-r--r-- | src/economy_func.h | 2 | ||||
-rw-r--r-- | src/engine.cpp | 53 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 8 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 4 | ||||
-rw-r--r-- | src/train_cmd.cpp | 8 | ||||
-rw-r--r-- | src/vehicle_cmd.cpp | 14 |
8 files changed, 76 insertions, 37 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 22a3872a5..159033199 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -540,7 +540,9 @@ static void CheckIfAircraftNeedsService(Aircraft *v) Money Aircraft::GetRunningCost() const { - return GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, AircraftVehInfo(this->engine_type)->running_cost) * _price[PR_RUNNING_AIRCRAFT]; + const Engine *e = Engine::Get(this->engine_type); + uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->u.air.running_cost); + return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor); } void Aircraft::OnNewDay() diff --git a/src/economy.cpp b/src/economy.cpp index 1d934bd7c..b8f4f6197 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -788,15 +788,25 @@ void InitializeEconomy() } /** - * Determine a certain base price with range checking - * @param index Price of interest - * @return Base price, or zero if out of range + * Determine a certain price + * @param index Price base + * @param cost_factor Price factor + * @param shift Extra bit shifting after the computation + * @return Price */ -Money GetPriceByIndex(Price index) +Money GetPrice(Price index, uint cost_factor, int shift) { if (index >= PR_END) return 0; - return _price[index]; + Money cost = _price[index] * cost_factor; + + if (shift >= 0) { + cost <<= shift; + } else { + cost >>= -shift; + } + + return cost; } Money GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type) diff --git a/src/economy_func.h b/src/economy_func.h index e4a77fb6a..ad50971eb 100644 --- a/src/economy_func.h +++ b/src/economy_func.h @@ -41,7 +41,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc void PrepareUnload(Vehicle *front_v); void LoadUnloadStation(Station *st); -Money GetPriceByIndex(Price index); +Money GetPrice(Price index, uint cost_factor, int shift = 0); void InitializeEconomy(); void RecomputePrices(); diff --git a/src/engine.cpp b/src/engine.cpp index 2e3901393..1d0ea1b0b 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -204,48 +204,71 @@ uint Engine::GetDisplayDefaultCapacity(uint16 *mail_capacity) const Money Engine::GetRunningCost() const { + Price base_price; + uint cost_factor; switch (this->type) { - case VEH_ROAD: { - if (this->u.road.running_cost_class == INVALID_PRICE) return 0; - return GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost) * GetPriceByIndex(this->u.road.running_cost_class) >> 8; - } + case VEH_ROAD: + base_price = this->u.road.running_cost_class; + if (base_price == INVALID_PRICE) return 0; + cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost); + break; - case VEH_TRAIN: { - if (this->u.rail.running_cost_class == INVALID_PRICE) return 0; - return GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8; - } + case VEH_TRAIN: + base_price = this->u.rail.running_cost_class; + if (base_price == INVALID_PRICE) return 0; + cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost); + break; case VEH_SHIP: - return GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost) * _price[PR_RUNNING_SHIP] >> 8; + base_price = PR_RUNNING_SHIP; + cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost); + break; case VEH_AIRCRAFT: - return GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost) * _price[PR_RUNNING_AIRCRAFT] >> 8; + base_price = PR_RUNNING_AIRCRAFT; + cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost); + break; default: NOT_REACHED(); } + + return GetPrice(base_price, cost_factor, -8); } Money Engine::GetCost() const { + Price base_price; + uint cost_factor; switch (this->type) { case VEH_ROAD: - return GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor) * (_price[PR_BUILD_VEHICLE_ROAD] >> 3) >> 5; + base_price = PR_BUILD_VEHICLE_ROAD; + cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor); + break; case VEH_TRAIN: if (this->u.rail.railveh_type == RAILVEH_WAGON) { - return (GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor) * _price[PR_BUILD_VEHICLE_WAGON]) >> 8; + base_price = PR_BUILD_VEHICLE_WAGON; + cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor); } else { - return GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor) * (_price[PR_BUILD_VEHICLE_TRAIN] >> 3) >> 5; + base_price = PR_BUILD_VEHICLE_TRAIN; + cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor); } + break; case VEH_SHIP: - return GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor) * (_price[PR_BUILD_VEHICLE_SHIP] >> 3) >> 5; + base_price = PR_BUILD_VEHICLE_SHIP; + cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor); + break; case VEH_AIRCRAFT: - return GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor) * (_price[PR_BUILD_VEHICLE_AIRCRAFT] >> 3) >> 5; + base_price = PR_BUILD_VEHICLE_AIRCRAFT; + cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor); + break; default: NOT_REACHED(); } + + return GetPrice(base_price, cost_factor, -8); } /** diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index bbe258e84..bc69349c3 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1827,13 +1827,13 @@ static bool RoadVehController(RoadVehicle *v) Money RoadVehicle::GetRunningCost() const { - const RoadVehicleInfo *rvi = RoadVehInfo(this->engine_type); - if (rvi->running_cost_class == INVALID_PRICE) return 0; + const Engine *e = Engine::Get(this->engine_type); + if (e->u.road.running_cost_class == INVALID_PRICE) return 0; - uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, rvi->running_cost); + uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->u.road.running_cost); if (cost_factor == 0) return 0; - return cost_factor * GetPriceByIndex(rvi->running_cost_class); + return GetPrice(e->u.road.running_cost_class, cost_factor); } bool RoadVehicle::Tick() diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index c482539ab..fc579fc48 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -159,7 +159,9 @@ static void CheckIfShipNeedsService(Vehicle *v) Money Ship::GetRunningCost() const { - return GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, ShipVehInfo(this->engine_type)->running_cost) * _price[PR_RUNNING_SHIP]; + const Engine *e = Engine::Get(this->engine_type); + uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost); + return GetPrice(PR_RUNNING_SHIP, cost_factor); } void Ship::OnNewDay() diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index bd5205b6c..3022045d4 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -4443,16 +4443,16 @@ Money Train::GetRunningCost() const const Train *v = this; do { - const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); - if (rvi->running_cost_class == INVALID_PRICE) continue; + const Engine *e = Engine::Get(v->engine_type); + if (e->u.rail.running_cost_class == INVALID_PRICE) continue; - uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, rvi->running_cost); + uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->u.rail.running_cost); if (cost_factor == 0) continue; /* Halve running cost for multiheaded parts */ if (v->IsMultiheaded()) cost_factor /= 2; - cost += cost_factor * GetPriceByIndex(rvi->running_cost_class); + cost += GetPrice(e->u.rail.running_cost_class, cost_factor); } while ((v = v->GetNextVehicle()) != NULL); return cost; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 529d31adc..9460d2f56 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -262,33 +262,35 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 */ static CommandCost GetRefitCost(EngineID engine_type) { - Money base_cost; ExpensesType expense_type; const Engine *e = Engine::Get(engine_type); + Price base_price; + uint cost_factor = e->info.refit_cost; switch (e->type) { case VEH_SHIP: - base_cost = _price[PR_BUILD_VEHICLE_SHIP]; + base_price = PR_BUILD_VEHICLE_SHIP; expense_type = EXPENSES_SHIP_RUN; break; case VEH_ROAD: - base_cost = _price[PR_BUILD_VEHICLE_ROAD]; + base_price = PR_BUILD_VEHICLE_ROAD; expense_type = EXPENSES_ROADVEH_RUN; break; case VEH_AIRCRAFT: - base_cost = _price[PR_BUILD_VEHICLE_AIRCRAFT]; + base_price = PR_BUILD_VEHICLE_AIRCRAFT; expense_type = EXPENSES_AIRCRAFT_RUN; break; case VEH_TRAIN: - base_cost = 2 * _price[(e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN]; + base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN; + cost_factor <<= 1; expense_type = EXPENSES_TRAIN_RUN; break; default: NOT_REACHED(); } - return CommandCost(expense_type, (e->info.refit_cost * base_cost) >> 10); + return CommandCost(expense_type, GetPrice(base_price, cost_factor, -10)); } /** |