MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetCost

Method GetCost

src/engine.cpp:317–351  ·  view source on GitHub ↗

* Return how much a new engine costs. * @return Cost of the engine. */

Source from the content-addressed store, hash-verified

315 * @return Cost of the engine.
316 */
317Money Engine::GetCost() const
318{
319 Price base_price;
320 uint cost_factor;
321 switch (this->type) {
322 case VEH_ROAD:
323 base_price = PR_BUILD_VEHICLE_ROAD;
324 cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->VehInfo<RoadVehicleInfo>().cost_factor);
325 break;
326
327 case VEH_TRAIN:
328 if (this->VehInfo<RailVehicleInfo>().railveh_type == RAILVEH_WAGON) {
329 base_price = PR_BUILD_VEHICLE_WAGON;
330 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo<RailVehicleInfo>().cost_factor);
331 } else {
332 base_price = PR_BUILD_VEHICLE_TRAIN;
333 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo<RailVehicleInfo>().cost_factor);
334 }
335 break;
336
337 case VEH_SHIP:
338 base_price = PR_BUILD_VEHICLE_SHIP;
339 cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->VehInfo<ShipVehicleInfo>().cost_factor);
340 break;
341
342 case VEH_AIRCRAFT:
343 base_price = PR_BUILD_VEHICLE_AIRCRAFT;
344 cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->VehInfo<AircraftVehicleInfo>().cost_factor);
345 break;
346
347 default: NOT_REACHED();
348 }
349
350 return GetPrice(base_price, cost_factor, this->GetGRF(), -8);
351}
352
353/**
354 * Returns max speed of the engine for display purposes

Callers 15

ReplaceChainFunction · 0.45
CmdAutoreplaceVehicleFunction · 0.45
CmdBuildShipDepotFunction · 0.45
DoBuildLockFunction · 0.45
CmdBuildCanalFunction · 0.45
OnNewEconomyDayMethod · 0.45
CmdClearAreaFunction · 0.45
CmdBuildSingleRailFunction · 0.45
CmdRailTrackHelperFunction · 0.45
CmdSignalTrackHelperFunction · 0.45
ClearTile_TrackFunction · 0.45
CmdBuildBridgeFunction · 0.45

Calls 4

GetGRFMethod · 0.95
GetEnginePropertyFunction · 0.85
NOT_REACHEDFunction · 0.85
GetPriceFunction · 0.85

Tested by

no test coverage detected