* Learn the price of refitting a certain engine * @param v The vehicle we are refitting, can be nullptr. * @param engine_type Which engine to refit * @param new_cargo_type Cargo type we are refitting to. * @param new_subtype New cargo subtype. * @param[out] auto_refit_allowed The refit is allowed as an auto-refit. * @return Price for refitting */
| 303 | * @return Price for refitting |
| 304 | */ |
| 305 | static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoType new_cargo_type, uint8_t new_subtype, bool *auto_refit_allowed) |
| 306 | { |
| 307 | ExpensesType expense_type; |
| 308 | const Engine *e = Engine::Get(engine_type); |
| 309 | Price base_price; |
| 310 | int cost_factor = GetRefitCostFactor(v, engine_type, new_cargo_type, new_subtype, auto_refit_allowed); |
| 311 | switch (e->type) { |
| 312 | case VEH_SHIP: |
| 313 | base_price = PR_BUILD_VEHICLE_SHIP; |
| 314 | expense_type = EXPENSES_SHIP_RUN; |
| 315 | break; |
| 316 | |
| 317 | case VEH_ROAD: |
| 318 | base_price = PR_BUILD_VEHICLE_ROAD; |
| 319 | expense_type = EXPENSES_ROADVEH_RUN; |
| 320 | break; |
| 321 | |
| 322 | case VEH_AIRCRAFT: |
| 323 | base_price = PR_BUILD_VEHICLE_AIRCRAFT; |
| 324 | expense_type = EXPENSES_AIRCRAFT_RUN; |
| 325 | break; |
| 326 | |
| 327 | case VEH_TRAIN: |
| 328 | base_price = (e->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN; |
| 329 | cost_factor <<= 1; |
| 330 | expense_type = EXPENSES_TRAIN_RUN; |
| 331 | break; |
| 332 | |
| 333 | default: NOT_REACHED(); |
| 334 | } |
| 335 | if (cost_factor < 0) { |
| 336 | return CommandCost(expense_type, -GetPrice(base_price, -cost_factor, e->GetGRF(), -10)); |
| 337 | } else { |
| 338 | return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->GetGRF(), -10)); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /** Helper structure for RefitVehicle() */ |
| 343 | struct RefitResult { |
no test coverage detected