From 322ce224b4db4334903a8ddb1588412b3d17cc50 Mon Sep 17 00:00:00 2001 From: Cyprian Klimaszewski Date: Mon, 12 Jan 2026 22:22:45 +0100 Subject: [PATCH] Codechange: Make Price an enum class. --- src/aircraft_cmd.cpp | 2 +- src/airport_gui.cpp | 2 +- src/bridge_gui.cpp | 2 +- src/build_vehicle_gui.cpp | 4 +- src/clear_cmd.cpp | 14 +-- src/economy.cpp | 10 +- src/economy_type.h | 154 +++++++++++++-------------- src/engine.cpp | 18 ++-- src/industry_cmd.cpp | 8 +- src/landscape.cpp | 2 +- src/newgrf.cpp | 18 ++-- src/newgrf/newgrf_act0_globalvar.cpp | 2 +- src/newgrf_object.h | 4 +- src/object_cmd.cpp | 4 +- src/rail.h | 8 +- src/rail_cmd.cpp | 32 +++--- src/road.h | 6 +- src/road_cmd.cpp | 20 ++-- src/road_func.h | 2 +- src/roadveh_cmd.cpp | 2 +- src/script/api/script_airport.cpp | 4 +- src/script/api/script_bridge.cpp | 2 +- src/script/api/script_marine.cpp | 10 +- src/script/api/script_rail.cpp | 8 +- src/script/api/script_road.cpp | 6 +- src/script/api/script_tile.cpp | 18 ++-- src/ship_cmd.cpp | 2 +- src/station.cpp | 2 +- src/station_cmd.cpp | 40 +++---- src/station_func.h | 2 +- src/table/engines.h | 10 +- src/table/pricebase.h | 145 +++++++++++++------------ src/terraform_cmd.cpp | 2 +- src/town_cmd.cpp | 12 +-- src/town_gui.cpp | 4 +- src/train_cmd.cpp | 2 +- src/tree_cmd.cpp | 6 +- src/tunnelbridge_cmd.cpp | 22 ++-- src/vehicle_cmd.cpp | 8 +- src/water.h | 2 +- src/water_cmd.cpp | 20 ++-- src/waypoint_cmd.cpp | 10 +- 42 files changed, 325 insertions(+), 326 deletions(-) diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 4cb6ebb27c..8828f2f925 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -437,7 +437,7 @@ Money Aircraft::GetRunningCost() const { const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_AIRCRAFT_RUNNING_COST_FACTOR, e->VehInfo().running_cost); - return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF()); + return GetPrice(Price::RunningAircraft, cost_factor, e->GetGRF()); } /** Calendar day handler */ diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 948fd06ed7..e02570a7d4 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -442,7 +442,7 @@ public: } if (_settings_game.economy.infrastructure_maintenance) { - Money monthly = _price[PR_INFRASTRUCTURE_AIRPORT] * as->maintenance_cost >> 3; + Money monthly = _price[Price::InfrastructureAirport] * as->maintenance_cost >> 3; DrawString(r, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_BUILD_INFRASTRUCTURE_COST_PERIOD : STR_STATION_BUILD_INFRASTRUCTURE_COST_YEAR, monthly * 12)); r.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; } diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 844d7c3b54..538c287f02 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -423,7 +423,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo item.spec = GetBridgeSpec(brd_type); /* Add to terraforming & bulldozing costs the cost of the * bridge itself (not computed with DoCommandFlag::QueryCost) */ - item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost; + item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[Price::BuildBridge] * item.spec->price) >> 8) + infra_cost; any_available = true; } } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index a2f185f85c..2cba8cc6b3 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -611,7 +611,7 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine } /* Running cost */ - if (rvi->running_cost_class != INVALID_PRICE) { + if (rvi->running_cost_class != Price::Invalid) { DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost())); y += GetCharacterHeight(FS_NORMAL); } @@ -662,7 +662,7 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin } /* Running cost */ - if (rvi->running_cost_class != INVALID_PRICE) { + if (rvi->running_cost_class != Price::Invalid) { DrawString(left, right, y, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_PURCHASE_INFO_RUNNINGCOST_PERIOD : STR_PURCHASE_INFO_RUNNINGCOST_YEAR, e->GetRunningCost())); y += GetCharacterHeight(FS_NORMAL); } diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index 874d31fe25..414cfc0d0f 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -26,12 +26,12 @@ static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlags flags) { static constexpr Price clear_price_table[] = { - PR_CLEAR_GRASS, - PR_CLEAR_ROUGH, - PR_CLEAR_ROCKS, - PR_CLEAR_FIELDS, - PR_CLEAR_ROUGH, - PR_CLEAR_ROUGH, + Price::ClearGrass, + Price::ClearRough, + Price::ClearRocks, + Price::ClearFields, + Price::ClearRough, + Price::ClearRough, }; CommandCost price(EXPENSES_CONSTRUCTION); @@ -40,7 +40,7 @@ static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlags flags) if (IsSnowTile(tile)) { price.AddCost(_price[clear_price_table[ground]]); /* Add a little more for removing snow. */ - price.AddCost(std::abs(_price[PR_CLEAR_ROUGH] - _price[PR_CLEAR_GRASS])); + price.AddCost(std::abs(_price[Price::ClearRough] - _price[Price::ClearGrass])); } else if (ground != CLEAR_GRASS || density != 0) { price.AddCost(_price[clear_price_table[ground]]); } diff --git a/src/economy.cpp b/src/economy.cpp index fc4192630a..6f8d41fef9 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -122,7 +122,7 @@ static Money CalculateCompanyAssetValue(const Company *c) if (st->owner == owner) num += st->facilities.Count(); } - Money value = num * _price[PR_STATION_VALUE] * 25; + Money value = num * _price[Price::StationValue] * 25; for (const Vehicle *v : Vehicle::Iterate()) { if (v->owner != owner) continue; @@ -740,7 +740,7 @@ void RecomputePrices() _economy.max_loan = ((uint64_t)_settings_game.difficulty.max_loan * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL; /* Setup price bases */ - for (Price i = PR_BEGIN; i < PR_END; i++) { + for (Price i = Price::Begin; i < Price::End; i++) { Money price = _price_base_specs[i].start_price; /* Apply difficulty settings */ @@ -828,7 +828,7 @@ static void CompaniesPayInterest() SubtractMoneyFromCompany(c->index, CommandCost(EXPENSES_LOAN_INTEREST, up_to_this_month - up_to_previous_month)); - SubtractMoneyFromCompany(c->index, CommandCost(EXPENSES_OTHER, _price[PR_STATION_VALUE] >> 2)); + SubtractMoneyFromCompany(c->index, CommandCost(EXPENSES_OTHER, _price[Price::StationValue] >> 2)); } } @@ -872,7 +872,7 @@ void ResetPriceBaseMultipliers() */ void SetPriceBaseMultiplier(Price price, int factor) { - assert(price < PR_END); + assert(price < Price::End); _price_base_multiplier[price] = Clamp(factor, MIN_PRICE_MODIFIER, MAX_PRICE_MODIFIER); } @@ -939,7 +939,7 @@ void InitializeEconomy() */ Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift) { - if (index >= PR_END) return 0; + if (index >= Price::End) return 0; Money cost = _price[index] * cost_factor; if (grf_file != nullptr) shift += grf_file->price_base_multipliers[index]; diff --git a/src/economy_type.h b/src/economy_type.h index 3f70fd4b67..dca2ed1e97 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -90,86 +90,86 @@ struct ScoreInfo { * Enumeration of all base prices for use with #Prices. * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them. */ -enum Price : uint8_t { - PR_BEGIN = 0, ///< The lowest valid value. - PR_STATION_VALUE = 0, ///< Stations value and additional constant company running fee. - PR_BUILD_RAIL, ///< Price for building rails. - PR_BUILD_ROAD, ///< Price for building roads. - PR_BUILD_SIGNALS, ///< Price for building rail signals. - PR_BUILD_BRIDGE, ///< Price for building bridges. - PR_BUILD_DEPOT_TRAIN, ///< Price for building train depots. - PR_BUILD_DEPOT_ROAD, ///< Price for building road vehicle depots. - PR_BUILD_DEPOT_SHIP, ///< Price for building ship depots. - PR_BUILD_TUNNEL, ///< Price for building tunnels. - PR_BUILD_STATION_RAIL, ///< Price for building rail stations. - PR_BUILD_STATION_RAIL_LENGTH, ///< Additional price for building rail stations dependent on their length. - PR_BUILD_STATION_AIRPORT, ///< Price for building airports. - PR_BUILD_STATION_BUS, ///< Price for building bus stops. - PR_BUILD_STATION_TRUCK, ///< Price for building lorry stations. - PR_BUILD_STATION_DOCK, ///< Price for building docks. - PR_BUILD_VEHICLE_TRAIN, ///< Price for purchasing new train engines. - PR_BUILD_VEHICLE_WAGON, ///< Price for purchasing new wagons. - PR_BUILD_VEHICLE_AIRCRAFT, ///< Price for purchasing new aircrafts. - PR_BUILD_VEHICLE_ROAD, ///< Price for purchasing new road vehicles. - PR_BUILD_VEHICLE_SHIP, ///< Price for purchasing new ships. - PR_BUILD_TREES, ///< Price for planting trees. - PR_TERRAFORM, ///< Price for terraforming land, e.g. rising, lowering and flattening. - PR_CLEAR_GRASS, ///< Price for destroying grass. - PR_CLEAR_ROUGH, ///< Price for destroying rough land. - PR_CLEAR_ROCKS, ///< Price for destroying rocks. - PR_CLEAR_FIELDS, ///< Price for destroying fields. - PR_CLEAR_TREES, ///< Price for destroying trees. - PR_CLEAR_RAIL, ///< Price for destroying rails. - PR_CLEAR_SIGNALS, ///< Price for destroying rail signals. - PR_CLEAR_BRIDGE, ///< Price for destroying bridges. - PR_CLEAR_DEPOT_TRAIN, ///< Price for destroying train depots. - PR_CLEAR_DEPOT_ROAD, ///< Price for destroying road vehicle depots. - PR_CLEAR_DEPOT_SHIP, ///< Price for destroying ship depots. - PR_CLEAR_TUNNEL, ///< Price for destroying tunnels. - PR_CLEAR_WATER, ///< Price for destroying water e.g. see, rives. - PR_CLEAR_STATION_RAIL, ///< Price for destroying rail stations. - PR_CLEAR_STATION_AIRPORT, ///< Price for destroying airports. - PR_CLEAR_STATION_BUS, ///< Price for destroying bus stops. - PR_CLEAR_STATION_TRUCK, ///< Price for destroying lorry stations. - PR_CLEAR_STATION_DOCK, ///< Price for destroying docks. - PR_CLEAR_HOUSE, ///< Price for destroying houses and other town buildings. - PR_CLEAR_ROAD, ///< Price for destroying roads. - PR_RUNNING_TRAIN_STEAM, ///< Running cost of steam trains. - PR_RUNNING_TRAIN_DIESEL, ///< Running cost of diesel trains. - PR_RUNNING_TRAIN_ELECTRIC, ///< Running cost of electric trains. - PR_RUNNING_AIRCRAFT, ///< Running cost of aircrafts. - PR_RUNNING_ROADVEH, ///< Running cost of road vehicles. - PR_RUNNING_SHIP, ///< Running cost of ships. - PR_BUILD_INDUSTRY, ///< Price for funding new industries. - PR_CLEAR_INDUSTRY, ///< Price for destroying industries. - PR_BUILD_OBJECT, ///< Price for building new objects. - PR_CLEAR_OBJECT, ///< Price for destroying objects. - PR_BUILD_WAYPOINT_RAIL, ///< Price for building new rail waypoints. - PR_CLEAR_WAYPOINT_RAIL, ///< Price for destroying rail waypoints. - PR_BUILD_WAYPOINT_BUOY, ///< Price for building new buoys. - PR_CLEAR_WAYPOINT_BUOY, ///< Price for destroying buoys. - PR_TOWN_ACTION, ///< Price for interaction with local authorities. - PR_BUILD_FOUNDATION, ///< Price for building foundation under other constructions e.g. roads, rails, depots, objects, etc., etc.. - PR_BUILD_INDUSTRY_RAW, ///< Price for funding new raw industries, e.g. coal mine, forest. - PR_BUILD_TOWN, ///< Price for funding new towns and cities. - PR_BUILD_CANAL, ///< Price for building new canals. - PR_CLEAR_CANAL, ///< Price for destroying canals. - PR_BUILD_AQUEDUCT, ///< Price for building new aqueducts. - PR_CLEAR_AQUEDUCT, ///< Price for destroying aqueducts. - PR_BUILD_LOCK, ///< Price for building new locks. - PR_CLEAR_LOCK, ///< Price for destroying locks. - PR_INFRASTRUCTURE_RAIL, ///< Rails maintenance cost. - PR_INFRASTRUCTURE_ROAD, ///< Roads maintenance cost. - PR_INFRASTRUCTURE_WATER, ///< Canals maintenance cost. - PR_INFRASTRUCTURE_STATION, ///< Stations maintenance cost. - PR_INFRASTRUCTURE_AIRPORT, ///< Airports maintenance cost. - PR_END, ///< Price base end marker. - INVALID_PRICE = 0xFF ///< Invalid base price. +enum class Price : uint8_t { + Begin, ///< The lowest valid value. + StationValue = Price::Begin, ///< Stations value and additional constant company running fee. + BuildRail, ///< Price for building rails. + BuildRoad, ///< Price for building roads. + BuildSignals, ///< Price for building rail signals. + BuildBridge, ///< Price for building bridges. + BuildDepotTrain, ///< Price for building train depots. + BuildDepotRoad, ///< Price for building road vehicle depots. + BuildDepotShip, ///< Price for building ship depots. + BuildTunnel, ///< Price for building tunnels. + BuildStationRail, ///< Price for building rail stations. + BuildStationRailLength, ///< Additional price for building rail stations dependent on their length. + BuildStationAirport, ///< Price for building airports. + BuildStationBus, ///< Price for building bus stops. + BuildStationTruck, ///< Price for building lorry stations. + BuildStationDock, ///< Price for building docks. + BuildVehicleTrain, ///< Price for purchasing new train engines. + BuildVehicleWagon, ///< Price for purchasing new wagons. + BuildVehicleAircraft, ///< Price for purchasing new aircrafts. + BuildVehicleRoad, ///< Price for purchasing new road vehicles. + BuildVehicleShip, ///< Price for purchasing new ships. + BuildTrees, ///< Price for planting trees. + Terraform, ///< Price for terraforming land, e.g. rising, lowering and flattening. + ClearGrass, ///< Price for destroying grass. + ClearRough, ///< Price for destroying rough land. + ClearRocks, ///< Price for destroying rocks. + ClearFields, ///< Price for destroying fields. + ClearTrees, ///< Price for destroying trees. + ClearRail, ///< Price for destroying rails. + ClearSignals, ///< Price for destroying rail signals. + ClearBridge, ///< Price for destroying bridges. + ClearDepotTrain, ///< Price for destroying train depots. + ClearDepotRoad, ///< Price for destroying road vehicle depots. + ClearDepotShip, ///< Price for destroying ship depots. + ClearTunnel, ///< Price for destroying tunnels. + ClearWater, ///< Price for destroying water e.g. see, rives. + ClearStationRail, ///< Price for destroying rail stations. + ClearStationAirport, ///< Price for destroying airports. + ClearStationBus, ///< Price for destroying bus stops. + ClearStationTruck, ///< Price for destroying lorry stations. + ClearStationDock, ///< Price for destroying docks. + ClearHouse, ///< Price for destroying houses and other town buildings. + ClearRoad, ///< Price for destroying roads. + RunningTrainSteam, ///< Running cost of steam trains. + RunningTrainDiesel, ///< Running cost of diesel trains. + RunningTrainElectric, ///< Running cost of electric trains. + RunningAircraft, ///< Running cost of aircrafts. + RunningRoadveh, ///< Running cost of road vehicles. + RunningShip, ///< Running cost of ships. + BuildIndustry, ///< Price for funding new industries. + ClearIndustry, ///< Price for destroying industries. + BuildObject, ///< Price for building new objects. + ClearObject, ///< Price for destroying objects. + BuildWaypointRail, ///< Price for building new rail waypoints. + ClearWaypointRail, ///< Price for destroying rail waypoints. + BuildWaypointBuoy, ///< Price for building new buoys. + ClearWaypointBuoy, ///< Price for destroying buoys. + TownAction, ///< Price for interaction with local authorities. + BuildFoundation, ///< Price for building foundation under other constructions e.g. roads, rails, depots, objects, etc., etc.. + BuildIndustryRaw, ///< Price for funding new raw industries, e.g. coal mine, forest. + BuildTown, ///< Price for funding new towns and cities. + BuildCanal, ///< Price for building new canals. + ClearCanal, ///< Price for destroying canals. + BuildAqueduct, ///< Price for building new aqueducts. + ClearAqueduct, ///< Price for destroying aqueducts. + BuildLock, ///< Price for building new locks. + ClearLock, ///< Price for destroying locks. + InfrastructureRail, ///< Rails maintenance cost. + InfrastructureRoad, ///< Roads maintenance cost. + InfrastructureWater, ///< Canals maintenance cost. + InfrastructureStation, ///< Stations maintenance cost. + InfrastructureAirport, ///< Airports maintenance cost. + End, ///< Price base end marker. + Invalid = 0xFF ///< Invalid base price. }; DECLARE_INCREMENT_DECREMENT_OPERATORS(Price) -typedef Money Prices[PR_END]; ///< Prices of everything. @see Price -using PriceMultipliers = std::array; +using Prices = EnumClassIndexContainer, Price>; ///< Prices of everything. @see Price +using PriceMultipliers = EnumClassIndexContainer, Price>; /** Types of expenses. */ enum ExpensesType : uint8_t { diff --git a/src/engine.cpp b/src/engine.cpp index c137882cd9..8d3f1adabb 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -288,23 +288,23 @@ Money Engine::GetRunningCost() const switch (this->type) { case VEH_ROAD: base_price = this->VehInfo().running_cost_class; - if (base_price == INVALID_PRICE) return 0; + if (base_price == Price::Invalid) return 0; cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->VehInfo().running_cost); break; case VEH_TRAIN: base_price = this->VehInfo().running_cost_class; - if (base_price == INVALID_PRICE) return 0; + if (base_price == Price::Invalid) return 0; cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->VehInfo().running_cost); break; case VEH_SHIP: - base_price = PR_RUNNING_SHIP; + base_price = Price::RunningShip; cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->VehInfo().running_cost); break; case VEH_AIRCRAFT: - base_price = PR_RUNNING_AIRCRAFT; + base_price = Price::RunningAircraft; cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->VehInfo().running_cost); break; @@ -324,27 +324,27 @@ Money Engine::GetCost() const uint cost_factor; switch (this->type) { case VEH_ROAD: - base_price = PR_BUILD_VEHICLE_ROAD; + base_price = Price::BuildVehicleRoad; cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->VehInfo().cost_factor); break; case VEH_TRAIN: if (this->VehInfo().railveh_type == RAILVEH_WAGON) { - base_price = PR_BUILD_VEHICLE_WAGON; + base_price = Price::BuildVehicleWagon; cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo().cost_factor); } else { - base_price = PR_BUILD_VEHICLE_TRAIN; + base_price = Price::BuildVehicleTrain; cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->VehInfo().cost_factor); } break; case VEH_SHIP: - base_price = PR_BUILD_VEHICLE_SHIP; + base_price = Price::BuildVehicleShip; cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->VehInfo().cost_factor); break; case VEH_AIRCRAFT: - base_price = PR_BUILD_VEHICLE_AIRCRAFT; + base_price = Price::BuildVehicleAircraft; cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->VehInfo().cost_factor); break; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 099bcf54b0..b23fb69e0b 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -3204,7 +3204,7 @@ Money IndustrySpec::GetConstructionCost() const { /* Building raw industries like secondary uses different price base */ return (_price[(_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry()) ? - PR_BUILD_INDUSTRY_RAW : PR_BUILD_INDUSTRY] * this->cost_multiplier) >> 8; + Price::BuildIndustryRaw : Price::BuildIndustry] * this->cost_multiplier) >> 8; } /** @@ -3215,7 +3215,7 @@ Money IndustrySpec::GetConstructionCost() const */ Money IndustrySpec::GetRemovalCost() const { - return (_price[PR_CLEAR_INDUSTRY] * this->removal_cost_multiplier) >> 8; + return (_price[Price::ClearIndustry] * this->removal_cost_multiplier) >> 8; } /** @@ -3252,10 +3252,10 @@ static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlags flags, if (itspec->callback_mask.Test(IndustryTileCallbackMask::Autoslope)) { /* If the callback fails, allow autoslope. */ uint16_t res = GetIndustryTileCallback(CBID_INDTILE_AUTOSLOPE, 0, 0, gfx, Industry::GetByTile(tile), tile); - if (res == CALLBACK_FAILED || !ConvertBooleanCallback(itspec->grf_prop.grffile, CBID_INDTILE_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (res == CALLBACK_FAILED || !ConvertBooleanCallback(itspec->grf_prop.grffile, CBID_INDTILE_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } else { /* allow autoslope */ - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } } } diff --git a/src/landscape.cpp b/src/landscape.cpp index 2f2ad555db..465d04d567 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -686,7 +686,7 @@ CommandCost CmdLandscapeClear(DoCommandFlags flags, TileIndex tile) /* Buoy tiles are special as they can be cleared by anyone, but the underlying tile shouldn't be cleared if it has a different owner. */ if (!IsBuoyTile(tile) || GetTileOwner(tile) == _current_company) { do_clear = true; - cost.AddCost(GetWaterClass(tile) == WaterClass::Canal ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]); + cost.AddCost(GetWaterClass(tile) == WaterClass::Canal ? _price[Price::ClearCanal] : _price[Price::ClearWater]); } } diff --git a/src/newgrf.cpp b/src/newgrf.cpp index b814ce48ec..55f3708422 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -47,6 +47,7 @@ #include "newgrf/newgrf_stringmapping.h" #include "table/strings.h" +#include "table/pricebase.h" #include "safeguards.h" @@ -333,14 +334,14 @@ void ConvertTTDBasePrice(uint32_t base_pointer, std::string_view error_location, { /* Special value for 'none' */ if (base_pointer == 0) { - *index = INVALID_PRICE; + *index = Price::Invalid; return; } static const uint32_t start = 0x4B34; ///< Position of first base price static const uint32_t size = 6; ///< Size of each base price record - if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) { + if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= to_underlying(Price::End)) { GrfMsg(1, "{}: Unsupported running cost base 0x{:04X}, ignoring", error_location, base_pointer); return; } @@ -1478,7 +1479,6 @@ static void ActivateOldTramDepot() */ static void FinalisePriceBaseMultipliers() { - extern const PriceBaseSpec _price_base_specs[]; /** Features, to which '_grf_id_overrides' applies. Currently vehicle features only. */ static constexpr GrfSpecFeatures override_features{GSF_TRAINS, GSF_ROADVEHICLES, GSF_SHIPS, GSF_AIRCRAFT}; @@ -1508,7 +1508,7 @@ static void FinalisePriceBaseMultipliers() source.grf_features.Set(features); dest.grf_features.Set(features); - for (Price p = PR_BEGIN; p < PR_END; p++) { + for (Price p = Price::Begin; p < Price::End; p++) { /* No price defined -> nothing to do */ if (!features.Test(_price_base_specs[p].grf_feature) || source.price_base_multipliers[p] == INVALID_PRICE_MODIFIER) continue; Debug(grf, 3, "'{}' overrides price base multiplier {} of '{}'", source.filename, p, dest.filename); @@ -1526,7 +1526,7 @@ static void FinalisePriceBaseMultipliers() source.grf_features.Set(features); dest.grf_features.Set(features); - for (Price p = PR_BEGIN; p < PR_END; p++) { + for (Price p = Price::Begin; p < Price::End; p++) { /* Already a price defined -> nothing to do */ if (!features.Test(_price_base_specs[p].grf_feature) || dest.price_base_multipliers[p] != INVALID_PRICE_MODIFIER) continue; Debug(grf, 3, "Price base multiplier {} from '{}' propagated to '{}'", p, source.filename, dest.filename); @@ -1544,7 +1544,7 @@ static void FinalisePriceBaseMultipliers() source.grf_features.Set(features); dest.grf_features.Set(features); - for (Price p = PR_BEGIN; p < PR_END; p++) { + for (Price p = Price::Begin; p < Price::End; p++) { if (!features.Test(_price_base_specs[p].grf_feature)) continue; if (source.price_base_multipliers[p] != dest.price_base_multipliers[p]) { Debug(grf, 3, "Price base multiplier {} from '{}' propagated to '{}'", p, dest.filename, source.filename); @@ -1557,9 +1557,9 @@ static void FinalisePriceBaseMultipliers() for (auto &file : _grf_files) { if (file.grf_version >= 8) continue; PriceMultipliers &price_base_multipliers = file.price_base_multipliers; - for (Price p = PR_BEGIN; p < PR_END; p++) { + for (Price p = Price::Begin; p < Price::End; p++) { Price fallback_price = _price_base_specs[p].fallback_price; - if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) { + if (fallback_price != Price::Invalid && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) { /* No price multiplier has been set. * So copy the multiplier from the fallback price, maybe a multiplier was set there. */ price_base_multipliers[p] = price_base_multipliers[fallback_price]; @@ -1570,7 +1570,7 @@ static void FinalisePriceBaseMultipliers() /* Decide local/global scope of price base multipliers */ for (auto &file : _grf_files) { PriceMultipliers &price_base_multipliers = file.price_base_multipliers; - for (Price p = PR_BEGIN; p < PR_END; p++) { + for (Price p = Price::Begin; p < Price::End; p++) { if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) { /* No multiplier was set; set it to a neutral value */ price_base_multipliers[p] = 0; diff --git a/src/newgrf/newgrf_act0_globalvar.cpp b/src/newgrf/newgrf_act0_globalvar.cpp index 7d07bc9b31..025785ee05 100644 --- a/src/newgrf/newgrf_act0_globalvar.cpp +++ b/src/newgrf/newgrf_act0_globalvar.cpp @@ -135,7 +135,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, Byt case 0x08: { // Cost base factor int factor = buf.ReadByte(); - if (id < PR_END) { + if (id < to_underlying(Price::End)) { _cur_gps.grffile->price_base_multipliers[id] = std::min(factor - 8, MAX_PRICE_MODIFIER); } else { GrfMsg(1, "GlobalVarChangeInfo: Price {} out of range, ignoring", id); diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 6c32a08b6a..fc39c9e4ba 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -86,13 +86,13 @@ struct ObjectSpec : NewGRFSpecBase { * Get the cost for building a structure of this type. * @return The cost for building. */ - Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); } + Money GetBuildCost() const { return GetPrice(Price::BuildObject, this->build_cost_multiplier, this->grf_prop.grffile, 0); } /** * Get the cost for clearing a structure of this type. * @return The cost for clearing. */ - Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); } + Money GetClearCost() const { return GetPrice(Price::ClearObject, this->clear_cost_multiplier, this->grf_prop.grffile, 0); } bool IsEverAvailable() const; bool WasEverAvailable() const; diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index bfecf1e9ce..5aefb0096f 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -924,10 +924,10 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlags flags, in if (spec->callback_mask.Test(ObjectCallbackMask::Autoslope)) { /* If the callback fails, allow autoslope. */ uint16_t res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile); - if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } else if (spec->IsEnabled()) { /* allow autoslope */ - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } } } diff --git a/src/rail.h b/src/rail.h index 560f9d3602..c566bcd431 100644 --- a/src/rail.h +++ b/src/rail.h @@ -428,7 +428,7 @@ inline bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def = _sett inline Money RailBuildCost(RailType railtype) { assert(railtype < RAILTYPE_END); - return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3; + return (_price[Price::BuildRail] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3; } /** @@ -444,7 +444,7 @@ inline Money RailClearCost(RailType railtype) * cost. */ assert(railtype < RAILTYPE_END); - return std::max(_price[PR_CLEAR_RAIL], -RailBuildCost(railtype) * 3 / 4); + return std::max(_price[Price::ClearRail], -RailBuildCost(railtype) * 3 / 4); } /** @@ -483,7 +483,7 @@ inline Money RailConvertCost(RailType from, RailType to) inline Money RailMaintenanceCost(RailType railtype, uint32_t num, uint32_t total_num) { assert(railtype < RAILTYPE_END); - return (_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 11; // 4 bits fraction for the multiplier and 7 bits scaling. + return (_price[Price::InfrastructureRail] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 11; // 4 bits fraction for the multiplier and 7 bits scaling. } /** @@ -493,7 +493,7 @@ inline Money RailMaintenanceCost(RailType railtype, uint32_t num, uint32_t total */ inline Money SignalMaintenanceCost(uint32_t num) { - return (_price[PR_INFRASTRUCTURE_RAIL] * 15 * num * (1 + IntSqrt(num))) >> 8; // 1 bit fraction for the multiplier and 7 bits scaling. + return (_price[Price::InfrastructureRail] * 15 * num * (1 + IntSqrt(num))) >> 8; // 1 bit fraction for the multiplier and 7 bits scaling. } void DrawTrainDepotSprite(int x, int y, int image, RailType railtype); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 73477414bf..8fbf69e659 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -402,7 +402,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex } Foundation f_old = GetRailFoundation(tileh, existing); - return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price[PR_BUILD_FOUNDATION] : (Money)0); + return CommandCost(EXPENSES_CONSTRUCTION, f_new != f_old ? _price[Price::BuildFoundation] : (Money)0); } /* Validate functions for rail building */ @@ -575,8 +575,8 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra cost.AddCost(ret.GetCost()); if (water_ground) { - cost.AddCost(-_price[PR_CLEAR_WATER]); - cost.AddCost(_price[PR_CLEAR_ROUGH]); + cost.AddCost(-_price[Price::ClearWater]); + cost.AddCost(_price[Price::ClearRough]); } if (flags.Test(DoCommandFlag::Execute)) { @@ -978,7 +978,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType ra if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) { return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); } - cost.AddCost(_price[PR_BUILD_FOUNDATION]); + cost.AddCost(_price[Price::BuildFoundation]); } /* Allow the user to rotate the depot instead of having to destroy it and build it again */ @@ -1022,7 +1022,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlags flags, TileIndex tile, RailType ra YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir)); } - cost.AddCost(_price[PR_BUILD_DEPOT_TRAIN]); + cost.AddCost(_price[Price::BuildDepotTrain]); cost.AddCost(RailBuildCost(railtype)); return cost; } @@ -1076,17 +1076,17 @@ CommandCost CmdBuildSingleSignal(DoCommandFlags flags, TileIndex tile, Track tra CommandCost cost; if (!HasSignalOnTrack(tile, track)) { /* build new signals */ - cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS]); + cost = CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildSignals]); } else { if (signals_copy != 0 && sigvar != GetSignalVariant(tile, track)) { /* convert signals <-> semaphores */ - cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]); + cost = CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildSignals] + _price[Price::ClearSignals]); } else if (convert_signal) { /* convert button pressed */ if (ctrl_pressed || GetSignalVariant(tile, track) != sigvar) { /* it costs money to change signal variant (light or semaphore) */ - cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_SIGNALS] + _price[PR_CLEAR_SIGNALS]); + cost = CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildSignals] + _price[Price::ClearSignals]); } else { /* it is free to change signal type (block, exit, entry, combo, path, etc) */ cost = CommandCost(); @@ -1507,7 +1507,7 @@ CommandCost CmdRemoveSingleSignal(DoCommandFlags flags, TileIndex tile, Track tr MarkTileDirtyByTile(tile); } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_SIGNALS]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearSignals]); } /** @@ -1786,7 +1786,7 @@ static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlags flags) if (v != nullptr) TryPathReserve(v, true); } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_TRAIN]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearDepotTrain]); } static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags) @@ -1830,7 +1830,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags) if (flags.Test(DoCommandFlag::Execute)) { DoClearSquare(tile); } - cost.AddCost(_price[PR_CLEAR_WATER]); + cost.AddCost(_price[Price::ClearWater]); } return cost; @@ -3022,7 +3022,7 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, DoCommandFlags flags, /* Surface slope must not be changed */ default: if (z_old != z_new || tileh_old != tileh_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } /* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */ @@ -3030,11 +3030,11 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, DoCommandFlags flags, z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner); if (z_old != z_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK); - CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); /* Make the ground dirty, if surface slope has changed */ if (tileh_old != tileh_new) { /* If there is flat water on the lower halftile add the cost for clearing it */ - if (GetRailGroundType(tile) == RailGroundType::HalfTileWater && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price[PR_CLEAR_WATER]); + if (GetRailGroundType(tile) == RailGroundType::HalfTileWater && IsSlopeWithOneCornerRaised(tileh_old)) cost.AddCost(_price[Price::ClearWater]); if (flags.Test(DoCommandFlag::Execute)) SetRailGroundType(tile, RailGroundType::Barren); } return cost; @@ -3081,10 +3081,10 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlags flags, int if (flags.Test(DoCommandFlag::Execute)) SetRailGroundType(tile, RailGroundType::Barren); /* allow terraforming */ - return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[PR_CLEAR_WATER] : (Money)0); + return CommandCost(EXPENSES_CONSTRUCTION, was_water ? _price[Price::ClearWater] : (Money)0); } else if (_settings_game.construction.build_on_slopes && AutoslopeEnabled() && AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRailDepotDirection(tile))) { - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } return Command::Do(flags, tile); } diff --git a/src/road.h b/src/road.h index fe74115d64..5ce376abea 100644 --- a/src/road.h +++ b/src/road.h @@ -240,7 +240,7 @@ inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype) inline Money RoadBuildCost(RoadType roadtype) { assert(roadtype < ROADTYPE_END); - return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3; + return (_price[Price::BuildRoad] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3; } /** @@ -253,11 +253,11 @@ inline Money RoadClearCost(RoadType roadtype) assert(roadtype < ROADTYPE_END); /* Flat fee for removing road. */ - if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD]; + if (RoadTypeIsRoad(roadtype)) return _price[Price::ClearRoad]; /* Clearing tram earns a little money, but also incurs the standard clear road cost, * so no profit can be made. */ - return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4; + return _price[Price::ClearRoad] - RoadBuildCost(roadtype) * 3 / 4; } /** diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index c1cc317a4a..4c8b07d354 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -474,7 +474,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pie CommandCost cost(EXPENSES_CONSTRUCTION, CountBits(pieces) * RoadClearCost(existing_rt)); /* If we build a foundation we have to pay for it. */ - if (f == FOUNDATION_NONE && GetRoadFoundation(tileh, present) != FOUNDATION_NONE) cost.AddCost(_price[PR_BUILD_FOUNDATION]); + if (f == FOUNDATION_NONE && GetRoadFoundation(tileh, present) != FOUNDATION_NONE) cost.AddCost(_price[Price::BuildFoundation]); return cost; } @@ -554,7 +554,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi if (_settings_game.construction.build_on_slopes && (_invalid_tileh_slopes_road[0][tileh] & (other | type_bits)) == ROAD_NONE) { /* If we add leveling we've got to pay for it */ - if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); return CommandCost(); } @@ -574,12 +574,12 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi if (_settings_game.construction.build_on_slopes) { /* If we add foundation we've got to pay for it */ - if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if ((other | existing) == ROAD_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); return CommandCost(); } } else { - if (HasExactlyOneBit(existing) && GetRoadFoundation(tileh, existing) == FOUNDATION_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (HasExactlyOneBit(existing) && GetRoadFoundation(tileh, existing) == FOUNDATION_NONE) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); return CommandCost(); } } @@ -1145,7 +1145,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) { return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); } - cost.AddCost(_price[PR_BUILD_FOUNDATION]); + cost.AddCost(_price[Price::BuildFoundation]); } /* Allow the user to rotate the depot instead of having to destroy it and build it again */ @@ -1187,7 +1187,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, MarkTileDirtyByTile(tile); } - cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]); + cost.AddCost(_price[Price::BuildDepotRoad]); return cost; } @@ -1215,7 +1215,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlags flags) DoClearSquare(tile); } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearDepotRoad]); } static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags) @@ -2369,11 +2369,11 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) { switch (GetRoadTileType(tile)) { case RoadTileType::Crossing: - if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) && HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); break; case RoadTileType::Depot: - if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetRoadDepotDirection(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); break; case RoadTileType::Normal: { @@ -2390,7 +2390,7 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int z_new += ApplyFoundationToSlope(GetRoadFoundation(tileh_new, bits), tileh_new); /* The surface slope must not be changed */ - if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if ((z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } } break; diff --git a/src/road_func.h b/src/road_func.h index 8e77195fdc..545fd191bb 100644 --- a/src/road_func.h +++ b/src/road_func.h @@ -125,7 +125,7 @@ inline RoadBits AxisToRoadBits(Axis a) inline Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num) { assert(roadtype < ROADTYPE_END); - return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12; + return (_price[Price::InfrastructureRoad] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12; } /** diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index a6eafb56d6..932ae1330c 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1642,7 +1642,7 @@ static bool RoadVehController(RoadVehicle *v) Money RoadVehicle::GetRunningCost() const { const Engine *e = this->GetEngine(); - if (e->VehInfo().running_cost_class == INVALID_PRICE) return 0; + if (e->VehInfo().running_cost_class == Price::Invalid) return 0; uint cost_factor = GetVehicleProperty(this, PROP_ROADVEH_RUNNING_COST_FACTOR, e->VehInfo().running_cost); if (cost_factor == 0) return 0; diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp index a77b454af1..00a1c09ce5 100644 --- a/src/script/api/script_airport.cpp +++ b/src/script/api/script_airport.cpp @@ -32,7 +32,7 @@ if (!IsValidAirportType(type)) return -1; const AirportSpec *as = ::AirportSpec::Get(type); - return _price[PR_BUILD_STATION_AIRPORT] * as->size_x * as->size_y; + return _price[Price::BuildStationAirport] * as->size_x * as->size_y; } /* static */ bool ScriptAirport::IsHangarTile(TileIndex tile) @@ -170,7 +170,7 @@ { if (!IsAirportInformationAvailable(type)) return -1; - return (int64_t)GetMaintenanceCostFactor(type) * _price[PR_INFRASTRUCTURE_AIRPORT] >> 3; + return (int64_t)GetMaintenanceCostFactor(type) * _price[Price::InfrastructureAirport] >> 3; } /* static */ SQInteger ScriptAirport::GetAirportNumHelipads(AirportType type) diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index 4c1589335f..d1f400d636 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -151,7 +151,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance &instance) length = Clamp(length, 0, INT32_MAX); - return ::CalcBridgeLenCostFactor(length) * _price[PR_BUILD_BRIDGE] * ::GetBridgeSpec(bridge_type)->price >> 8; + return ::CalcBridgeLenCostFactor(length) * _price[Price::BuildBridge] * ::GetBridgeSpec(bridge_type)->price >> 8; } /* static */ SQInteger ScriptBridge::GetMaxLength(BridgeType bridge_type) diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp index 89e5269d05..d3f9047296 100644 --- a/src/script/api/script_marine.cpp +++ b/src/script/api/script_marine.cpp @@ -167,11 +167,11 @@ /* static */ Money ScriptMarine::GetBuildCost(BuildType build_type) { switch (build_type) { - case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, nullptr); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, nullptr); - case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, nullptr); - case BT_LOCK: return ::GetPrice(PR_BUILD_LOCK, 1, nullptr); - case BT_CANAL: return ::GetPrice(PR_BUILD_CANAL, 1, nullptr); + case BT_DOCK: return ::GetPrice(Price::BuildStationDock, 1, nullptr); + case BT_DEPOT: return ::GetPrice(Price::BuildDepotShip, 1, nullptr); + case BT_BUOY: return ::GetPrice(Price::BuildWaypointBuoy, 1, nullptr); + case BT_LOCK: return ::GetPrice(Price::BuildLock, 1, nullptr); + case BT_CANAL: return ::GetPrice(Price::BuildCanal, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index 2b6c81a818..17eea2e45c 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -494,10 +494,10 @@ static bool IsValidSignalType(int signal_type) switch (build_type) { case BT_TRACK: return ::RailBuildCost((::RailType)railtype); - case BT_SIGNAL: return ::GetPrice(PR_BUILD_SIGNALS, 1, nullptr); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_TRAIN, 1, nullptr); - case BT_STATION: return ::GetPrice(PR_BUILD_STATION_RAIL, 1, nullptr) + ::GetPrice(PR_BUILD_STATION_RAIL_LENGTH, 1, nullptr); - case BT_WAYPOINT: return ::GetPrice(PR_BUILD_WAYPOINT_RAIL, 1, nullptr); + case BT_SIGNAL: return ::GetPrice(Price::BuildSignals, 1, nullptr); + case BT_DEPOT: return ::GetPrice(Price::BuildDepotTrain, 1, nullptr); + case BT_STATION: return ::GetPrice(Price::BuildStationRail, 1, nullptr) + ::GetPrice(Price::BuildStationRailLength, 1, nullptr); + case BT_WAYPOINT: return ::GetPrice(Price::BuildWaypointRail, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index c75dcd2dec..79d50a58dd 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -647,9 +647,9 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD switch (build_type) { case BT_ROAD: return ::RoadBuildCost((::RoadType)roadtype); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_ROAD, 1, nullptr); - case BT_BUS_STOP: return ::GetPrice(PR_BUILD_STATION_BUS, 1, nullptr); - case BT_TRUCK_STOP: return ::GetPrice(PR_BUILD_STATION_TRUCK, 1, nullptr); + case BT_DEPOT: return ::GetPrice(Price::BuildDepotRoad, 1, nullptr); + case BT_BUS_STOP: return ::GetPrice(Price::BuildStationBus, 1, nullptr); + case BT_TRUCK_STOP: return ::GetPrice(Price::BuildStationTruck, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index 90276de8d4..5024182048 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -338,15 +338,15 @@ /* static */ Money ScriptTile::GetBuildCost(BuildType build_type) { switch (build_type) { - case BT_FOUNDATION: return ::GetPrice(PR_BUILD_FOUNDATION, 1, nullptr); - case BT_TERRAFORM: return ::GetPrice(PR_TERRAFORM, 1, nullptr); - case BT_BUILD_TREES: return ::GetPrice(PR_BUILD_TREES, 1, nullptr); - case BT_CLEAR_GRASS: return ::GetPrice(PR_CLEAR_GRASS, 1, nullptr); - case BT_CLEAR_ROUGH: return ::GetPrice(PR_CLEAR_ROUGH, 1, nullptr); - case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, nullptr); - case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, nullptr); - case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, nullptr); - case BT_CLEAR_WATER: return ::GetPrice(PR_CLEAR_WATER, 1, nullptr); + case BT_FOUNDATION: return ::GetPrice(Price::BuildFoundation, 1, nullptr); + case BT_TERRAFORM: return ::GetPrice(Price::Terraform, 1, nullptr); + case BT_BUILD_TREES: return ::GetPrice(Price::BuildTrees, 1, nullptr); + case BT_CLEAR_GRASS: return ::GetPrice(Price::ClearGrass, 1, nullptr); + case BT_CLEAR_ROUGH: return ::GetPrice(Price::ClearRough, 1, nullptr); + case BT_CLEAR_ROCKY: return ::GetPrice(Price::ClearRocks, 1, nullptr); + case BT_CLEAR_FIELDS: return ::GetPrice(Price::ClearFields, 1, nullptr); + case BT_CLEAR_HOUSE: return ::GetPrice(Price::ClearHouse, 1, nullptr); + case BT_CLEAR_WATER: return ::GetPrice(Price::ClearWater, 1, nullptr); default: return -1; } } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 4ddb3c6b4f..84a9cc8dbe 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -247,7 +247,7 @@ Money Ship::GetRunningCost() const { const Engine *e = this->GetEngine(); uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->VehInfo().running_cost); - return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF()); + return GetPrice(Price::RunningShip, cost_factor, e->GetGRF()); } /** Calendar day handler. */ diff --git a/src/station.cpp b/src/station.cpp index 1afa57a40b..1b0bd6b262 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -716,7 +716,7 @@ Money AirportMaintenanceCost(Owner owner) for (const Station *st : Station::Iterate()) { if (st->owner == owner && st->facilities.Test(StationFacility::Airport)) { - total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost; + total_cost += _price[Price::InfrastructureAirport] * st->airport.GetSpec()->maintenance_cost; } } /* 3 bits fraction for the maintenance cost factor. */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index b4a037bc08..c4d518952c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -815,7 +815,7 @@ CommandCost CheckBuildableTile(TileIndex tile, DiagDirections invalid_dirs, int return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); } } - cost.AddCost(_price[PR_BUILD_FOUNDATION]); + cost.AddCost(_price[Price::BuildFoundation]); } /* The level of this tile must be equal to allowed_z. */ @@ -1371,7 +1371,7 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlags f CommandCost ret = CheckFlatLandRailStation(cur_tile, tile_area.tile, allowed_z, flags, axis, station, rt, affected_vehicles, spec_class, spec_index, plat_len, numtracks); if (ret.Failed()) return ret; - /* Only add _price[PR_BUILD_STATION_RAIL_LENGTH] once for each valid plat_len. */ + /* Only add _price[Price::BuildStationRailLength] once for each valid plat_len. */ if (tracknum == numtracks) { length_price_ready = true; tracknum = 0; @@ -1382,11 +1382,11 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlags f /* AddCost for new or rotated rail stations. */ if (!IsRailStationTile(cur_tile) || (IsRailStationTile(cur_tile) && GetRailStationAxis(cur_tile) != axis)) { cost.AddCost(ret.GetCost()); - cost.AddCost(_price[PR_BUILD_STATION_RAIL]); + cost.AddCost(_price[Price::BuildStationRail]); cost.AddCost(RailBuildCost(rt)); if (length_price_ready) { - cost.AddCost(_price[PR_BUILD_STATION_RAIL_LENGTH]); + cost.AddCost(_price[Price::BuildStationRailLength]); length_price_ready = false; } } @@ -1781,7 +1781,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector &affected_st if (keep_rail || IsStationTileBlocked(tile)) { /* Don't refund the 'steel' of the track when we keep the * rail, or when the tile didn't have any rail at all. */ - total_cost.AddCost(-_price[PR_CLEAR_RAIL]); + total_cost.AddCost(-_price[Price::ClearRail]); } if (flags.Test(DoCommandFlag::Execute)) { @@ -1860,7 +1860,7 @@ CommandCost CmdRemoveFromRailStation(DoCommandFlags flags, TileIndex start, Tile TileArea ta(start, end); std::vector affected_stations; - CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_STATION_RAIL], keep_rail); + CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[Price::ClearStationRail], keep_rail); if (ret.Failed()) return ret; /* Do all station specific functions here. */ @@ -1893,7 +1893,7 @@ CommandCost CmdRemoveFromRailWaypoint(DoCommandFlags flags, TileIndex start, Til TileArea ta(start, end); std::vector affected_stations; - return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_WAYPOINT_RAIL], keep_rail); + return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[Price::ClearWaypointRail], keep_rail); } @@ -1948,7 +1948,7 @@ static CommandCost RemoveRailStation(TileIndex tile, DoCommandFlags flags) } Station *st = Station::GetByTile(tile); - CommandCost cost = RemoveRailStation(st, flags, _price[PR_CLEAR_STATION_RAIL]); + CommandCost cost = RemoveRailStation(st, flags, _price[Price::ClearStationRail]); if (flags.Test(DoCommandFlag::Execute)) st->RecomputeCatchment(); @@ -1968,7 +1968,7 @@ static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlags flags) return Command::Do(DoCommandFlag::Execute, tile, TileIndex{}, false); } - return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]); + return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[Price::ClearWaypointRail]); } @@ -2113,9 +2113,9 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width /* Total road stop cost. */ Money unit_cost; if (roadstopspec != nullptr) { - unit_cost = roadstopspec->GetBuildCost(is_truck_stop ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS); + unit_cost = roadstopspec->GetBuildCost(is_truck_stop ? Price::BuildStationTruck : Price::BuildStationBus); } else { - unit_cost = _price[is_truck_stop ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]; + unit_cost = _price[is_truck_stop ? Price::BuildStationTruck : Price::BuildStationBus]; } StationID est = StationID::Invalid(); CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, is_drive_through, is_truck_stop ? StationType::Truck : StationType::Bus, roadstopspec, axis, ddir, &est, rt, unit_cost); @@ -2342,7 +2342,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlags flags, int repl } } - Price category = is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS; + Price category = is_truck ? Price::ClearStationTruck : Price::ClearStationBus; return CommandCost(EXPENSES_CONSTRUCTION, spec != nullptr ? spec->GetClearCost(category) : _price[category]); } @@ -2406,7 +2406,7 @@ CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlags flags, int rep } } - return CommandCost(EXPENSES_CONSTRUCTION, spec != nullptr ? spec->GetClearCost(PR_CLEAR_STATION_TRUCK) : _price[PR_CLEAR_STATION_TRUCK]); + return CommandCost(EXPENSES_CONSTRUCTION, spec != nullptr ? spec->GetClearCost(Price::ClearStationTruck) : _price[Price::ClearStationTruck]); } /** @@ -2702,7 +2702,7 @@ CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airpor } for (AirportTileTableIterator iter(as->layouts[layout].tiles, tile); iter != INVALID_TILE; ++iter) { - cost.AddCost(_price[PR_BUILD_STATION_AIRPORT]); + cost.AddCost(_price[Price::BuildStationAirport]); } if (flags.Test(DoCommandFlag::Execute)) { @@ -2797,7 +2797,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlags flags) CommandCost ret = EnsureNoVehicleOnGround(tile_cur); if (ret.Failed()) return ret; - cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]); + cost.AddCost(_price[Price::ClearStationAirport]); if (flags.Test(DoCommandFlag::Execute)) { DoClearSquare(tile_cur); @@ -2910,7 +2910,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station ret = IsDockBridgeAboveOk(tile, to_underlying(direction)); if (ret.Failed()) return ret; - CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]); + CommandCost cost(EXPENSES_CONSTRUCTION, _price[Price::BuildStationDock]); ret = Command::Do(flags, tile); if (ret.Failed()) return ret; cost.AddCost(ret.GetCost()); @@ -3103,7 +3103,7 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlags flags) } } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_STATION_DOCK]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearStationDock]); } /** @@ -4954,11 +4954,11 @@ static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlags flags, i case StationType::RailWaypoint: case StationType::Rail: { if (!AutoslopeCheckForAxis(tile, z_new, tileh_new, GetRailStationAxis(tile))) break; - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } case StationType::Airport: - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); case StationType::Truck: case StationType::Bus: @@ -4968,7 +4968,7 @@ static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlags flags, i } else { if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, GetBayRoadStopDir(tile))) break; } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } default: break; diff --git a/src/station_func.h b/src/station_func.h index 3e74745412..0f9ec8da0f 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -59,7 +59,7 @@ void RerouteCargo(Station *st, CargoType cargo, StationID avoid, StationID avoid */ inline Money StationMaintenanceCost(uint32_t num) { - return (_price[PR_INFRASTRUCTURE_STATION] * num * (1 + IntSqrt(num))) >> 7; // 7 bits scaling. + return (_price[Price::InfrastructureStation] * num * (1 + IntSqrt(num))) >> 7; // 7 bits scaling. } Money AirportMaintenanceCost(Owner owner); diff --git a/src/table/engines.h b/src/table/engines.h index c52b160973..086e5a0790 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -402,10 +402,10 @@ static constexpr EngineInfo _orig_engine_info[] = { #define O RAILTYPE_MONO #define L RAILTYPE_MAGLEV -#define RC_S PR_RUNNING_TRAIN_STEAM -#define RC_D PR_RUNNING_TRAIN_DIESEL -#define RC_E PR_RUNNING_TRAIN_ELECTRIC -#define RC_W INVALID_PRICE +#define RC_S Price::RunningTrainSteam +#define RC_D Price::RunningTrainDiesel +#define RC_E Price::RunningTrainElectric +#define RC_W Price::Invalid static constexpr RailVehicleInfo _orig_rail_vehicle_info[] = { /* image_index max_speed running_cost engclass @@ -667,7 +667,7 @@ static constexpr AircraftVehicleInfo _orig_aircraft_vehicle_info[] = { * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 * Air drag value depends on the top speed of the vehicle. */ -#define ROV(a, b, c, d, e, f, g, h) { a, b, c, PR_RUNNING_ROADVEH, d, e, f, g, h, 76, 0, VE_DEFAULT, 0, ROADTYPE_ROAD } +#define ROV(a, b, c, d, e, f, g, h) { a, b, c, Price::RunningRoadveh, d, e, f, g, h, 76, 0, VE_DEFAULT, 0, ROADTYPE_ROAD } static constexpr RoadVehicleInfo _orig_road_vehicle_info[] = { /* image_index sfx max_speed power * | cost_factor | | capacity | diff --git a/src/table/pricebase.h b/src/table/pricebase.h index f8c37c6e9f..e7eb6483ac 100644 --- a/src/table/pricebase.h +++ b/src/table/pricebase.h @@ -7,77 +7,76 @@ /** @file pricebase.h Table of all default price bases. */ -extern const PriceBaseSpec _price_base_specs[] = { - { 100, PCAT_NONE, GSF_END, INVALID_PRICE }, ///< PR_STATION_VALUE - { 100, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_RAIL - { 95, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_ROAD - { 65, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_SIGNALS - { 275, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_BRIDGE - { 600, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_DEPOT_TRAIN - { 500, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_DEPOT_ROAD - { 700, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_DEPOT_SHIP - { 450, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_TUNNEL - { 200, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_RAIL - { 180, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_RAIL_LENGTH - { 600, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_AIRPORT - { 200, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_BUS - { 200, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_TRUCK - { 350, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_STATION_DOCK - { 400000, PCAT_CONSTRUCTION, GSF_TRAINS, INVALID_PRICE }, ///< PR_BUILD_VEHICLE_TRAIN - { 2000, PCAT_CONSTRUCTION, GSF_TRAINS, INVALID_PRICE }, ///< PR_BUILD_VEHICLE_WAGON - { 700000, PCAT_CONSTRUCTION, GSF_AIRCRAFT, INVALID_PRICE }, ///< PR_BUILD_VEHICLE_AIRCRAFT - { 14000, PCAT_CONSTRUCTION, GSF_ROADVEHICLES, INVALID_PRICE }, ///< PR_BUILD_VEHICLE_ROAD - { 65000, PCAT_CONSTRUCTION, GSF_SHIPS, INVALID_PRICE }, ///< PR_BUILD_VEHICLE_SHIP - { 20, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_TREES - { 250, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_TERRAFORM - { 20, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_GRASS - { 40, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_ROUGH - { 200, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_ROCKS - { 500, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_FIELDS - { 20, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_TREES - { -70, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_RAIL - { 10, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_SIGNALS - { 50, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_BRIDGE - { 80, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_DEPOT_TRAIN - { 80, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_DEPOT_ROAD - { 90, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_DEPOT_SHIP - { 30, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_TUNNEL - { 10000, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_WATER - { 50, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_STATION_RAIL - { 30, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_STATION_AIRPORT - { 50, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_STATION_BUS - { 50, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_STATION_TRUCK - { 55, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_STATION_DOCK - { 1600, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_HOUSE - { 40, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_CLEAR_ROAD - { 5600, PCAT_RUNNING, GSF_TRAINS, INVALID_PRICE }, ///< PR_RUNNING_TRAIN_STEAM - { 5200, PCAT_RUNNING, GSF_TRAINS, INVALID_PRICE }, ///< PR_RUNNING_TRAIN_DIESEL - { 4800, PCAT_RUNNING, GSF_TRAINS, INVALID_PRICE }, ///< PR_RUNNING_TRAIN_ELECTRIC - { 9600, PCAT_RUNNING, GSF_AIRCRAFT, INVALID_PRICE }, ///< PR_RUNNING_AIRCRAFT - { 1600, PCAT_RUNNING, GSF_ROADVEHICLES, INVALID_PRICE }, ///< PR_RUNNING_ROADVEH - { 5600, PCAT_RUNNING, GSF_SHIPS, INVALID_PRICE }, ///< PR_RUNNING_SHIP - {1000000, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_INDUSTRY - { 1600, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_HOUSE }, ///< PR_CLEAR_INDUSTRY - { 40, PCAT_CONSTRUCTION, GSF_OBJECTS, PR_CLEAR_ROUGH }, ///< PR_BUILD_OBJECT - { 40, PCAT_CONSTRUCTION, GSF_OBJECTS, PR_CLEAR_ROUGH }, ///< PR_CLEAR_OBJECT - { 600, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_DEPOT_TRAIN }, ///< PR_BUILD_WAYPOINT_RAIL - { 80, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_DEPOT_TRAIN }, ///< PR_CLEAR_WAYPOINT_RAIL - { 350, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_STATION_DOCK }, ///< PR_BUILD_WAYPOINT_BUOY - { 50, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_STATION_TRUCK}, ///< PR_CLEAR_WAYPOINT_BUOY - {1000000, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_INDUSTRY }, ///< PR_TOWN_ACTION - { 250, PCAT_CONSTRUCTION, GSF_END, PR_TERRAFORM }, ///< PR_BUILD_FOUNDATION - {8000000, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_INDUSTRY }, ///< PR_BUILD_INDUSTRY_RAW - {1000000, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_INDUSTRY }, ///< PR_BUILD_TOWN - { 5000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_BUILD_CANAL - { 5000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_CLEAR_CANAL - { 10000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_BUILD_AQUEDUCT - { 2000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_BRIDGE }, ///< PR_CLEAR_AQUEDUCT - { 7500, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_BUILD_LOCK - { 2000, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_WATER }, ///< PR_CLEAR_LOCK - { 10, PCAT_RUNNING, GSF_END, PR_BUILD_RAIL }, ///< PR_INFRASTRUCTURE_RAIL - { 10, PCAT_RUNNING, GSF_END, PR_BUILD_ROAD }, ///< PR_INFRASTRUCTURE_ROAD - { 8, PCAT_RUNNING, GSF_END, PR_BUILD_CANAL }, ///< PR_INFRASTRUCTURE_WATER - { 100, PCAT_RUNNING, GSF_END, PR_STATION_VALUE }, ///< PR_INFRASTRUCTURE_STATION - { 5000, PCAT_RUNNING, GSF_END, PR_BUILD_STATION_AIRPORT}, ///< PR_INFRASTRUCTURE_AIRPORT +static const EnumClassIndexContainer, Price> _price_base_specs = { + PriceBaseSpec(100, PCAT_NONE, GSF_END, Price::Invalid), ///< Price::StationValue + PriceBaseSpec(100, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildRail + PriceBaseSpec(95, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildRoad + PriceBaseSpec(65, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildSignals + PriceBaseSpec(275, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildBridge + PriceBaseSpec(600, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildDepotTrain + PriceBaseSpec(500, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildDepotRoad + PriceBaseSpec(700, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildDepotShip + PriceBaseSpec(450, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildTunnel + PriceBaseSpec(200, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationRail + PriceBaseSpec(180, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationRailLength + PriceBaseSpec(600, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationAirport + PriceBaseSpec(200, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationBus + PriceBaseSpec(200, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationTruck + PriceBaseSpec(350, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildStationDock + PriceBaseSpec(400000, PCAT_CONSTRUCTION, GSF_TRAINS, Price::Invalid), ///< Price::BuildVehicleTrain + PriceBaseSpec(2000, PCAT_CONSTRUCTION, GSF_TRAINS, Price::Invalid), ///< Price::BuildVehicleWagon + PriceBaseSpec(700000, PCAT_CONSTRUCTION, GSF_AIRCRAFT, Price::Invalid), ///< Price::BuildVehicleAircraft + PriceBaseSpec(14000, PCAT_CONSTRUCTION, GSF_ROADVEHICLES, Price::Invalid), ///< Price::BuildVehicleRoad + PriceBaseSpec(65000, PCAT_CONSTRUCTION, GSF_SHIPS, Price::Invalid), ///< Price::BuildVehicleShip + PriceBaseSpec(20, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildTrees + PriceBaseSpec(250, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::Terraform + PriceBaseSpec(20, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearGrass + PriceBaseSpec(40, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearRough + PriceBaseSpec(200, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearRocks + PriceBaseSpec(500, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearFields + PriceBaseSpec(20, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearTrees + PriceBaseSpec(-70, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearRail + PriceBaseSpec(10, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearSignals + PriceBaseSpec(50, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearBridge + PriceBaseSpec(80, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearDepotTrain + PriceBaseSpec(80, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearDepotRoad + PriceBaseSpec(90, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearDepotShip + PriceBaseSpec(30, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearTunnel + PriceBaseSpec(10000, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearWater + PriceBaseSpec(50, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearStationRail + PriceBaseSpec(30, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearStationAirport + PriceBaseSpec(50, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearStationBus + PriceBaseSpec(50, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearStationTruck + PriceBaseSpec(55, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearStationDock + PriceBaseSpec(1600, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearHouse + PriceBaseSpec(40, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::ClearRoad + PriceBaseSpec(5600, PCAT_RUNNING, GSF_TRAINS, Price::Invalid), ///< Price::RunningTrainSteam + PriceBaseSpec(5200, PCAT_RUNNING, GSF_TRAINS, Price::Invalid), ///< Price::RunningTrainDiesel + PriceBaseSpec(4800, PCAT_RUNNING, GSF_TRAINS, Price::Invalid), ///< Price::RunningTrainElectric + PriceBaseSpec(9600, PCAT_RUNNING, GSF_AIRCRAFT, Price::Invalid), ///< Price::RunningAircraft + PriceBaseSpec(1600, PCAT_RUNNING, GSF_ROADVEHICLES, Price::Invalid), ///< Price::RunningRoadveh + PriceBaseSpec(5600, PCAT_RUNNING, GSF_SHIPS, Price::Invalid), ///< Price::RunningShip + PriceBaseSpec(1000000, PCAT_CONSTRUCTION, GSF_END, Price::Invalid), ///< Price::BuildIndustry + PriceBaseSpec(1600, PCAT_CONSTRUCTION, GSF_END, Price::ClearHouse), ///< Price::ClearIndustry + PriceBaseSpec(40, PCAT_CONSTRUCTION, GSF_OBJECTS, Price::ClearRough), ///< Price::BuildObject + PriceBaseSpec(40, PCAT_CONSTRUCTION, GSF_OBJECTS, Price::ClearRough), ///< Price::ClearObject + PriceBaseSpec(600, PCAT_CONSTRUCTION, GSF_END, Price::BuildDepotTrain), ///< Price::BuildWaypointRail + PriceBaseSpec(80, PCAT_CONSTRUCTION, GSF_END, Price::ClearDepotTrain), ///< Price::ClearWaypointRail + PriceBaseSpec(350, PCAT_CONSTRUCTION, GSF_END, Price::BuildStationDock), ///< Price::BuildWaypointBuoy + PriceBaseSpec(50, PCAT_CONSTRUCTION, GSF_END, Price::ClearStationTruck), ///< Price::ClearWaypointBuoy + PriceBaseSpec(1000000, PCAT_CONSTRUCTION, GSF_END, Price::BuildIndustry), ///< Price::TownAction + PriceBaseSpec(250, PCAT_CONSTRUCTION, GSF_END, Price::Terraform), ///< Price::BuildFoundation + PriceBaseSpec(8000000, PCAT_CONSTRUCTION, GSF_END, Price::BuildIndustry), ///< Price::BuildIndustryRaw + PriceBaseSpec(1000000, PCAT_CONSTRUCTION, GSF_END, Price::BuildIndustry), ///< Price::BuildTown + PriceBaseSpec(5000, PCAT_CONSTRUCTION, GSF_END, Price::ClearWater), ///< Price::BuildCanal + PriceBaseSpec(5000, PCAT_CONSTRUCTION, GSF_END, Price::ClearWater), ///< Price::ClearCanal + PriceBaseSpec(10000, PCAT_CONSTRUCTION, GSF_END, Price::ClearWater), ///< Price::BuildAqueduct + PriceBaseSpec(2000, PCAT_CONSTRUCTION, GSF_END, Price::ClearBridge), ///< Price::ClearAqueduct + PriceBaseSpec(7500, PCAT_CONSTRUCTION, GSF_END, Price::ClearWater), ///< Price::BuildLock + PriceBaseSpec(2000, PCAT_CONSTRUCTION, GSF_END, Price::ClearWater), ///< Price::ClearLock + PriceBaseSpec(10, PCAT_RUNNING, GSF_END, Price::BuildRail), ///< Price::InfrastructureRail + PriceBaseSpec(10, PCAT_RUNNING, GSF_END, Price::BuildRoad), ///< Price::InfrastructureRoad + PriceBaseSpec(8, PCAT_RUNNING, GSF_END, Price::BuildCanal), ///< Price::InfrastructureWater + PriceBaseSpec(100, PCAT_RUNNING, GSF_END, Price::StationValue), ///< Price::InfrastructureStation + PriceBaseSpec(5000, PCAT_RUNNING, GSF_END, Price::BuildStationAirport), ///< Price::InfrastructureAirport }; -static_assert(lengthof(_price_base_specs) == PR_END); diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp index cace1afb4c..0505a8f341 100644 --- a/src/terraform_cmd.cpp +++ b/src/terraform_cmd.cpp @@ -132,7 +132,7 @@ static std::tuple TerraformTileHeight(TerraformerState * CommandCost total_cost(EXPENSES_CONSTRUCTION); /* Increment cost */ - total_cost.AddCost(_price[PR_TERRAFORM]); + total_cost.AddCost(_price[Price::Terraform]); /* Recurse to neighboured corners if height difference is larger than 1 */ for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d1753bf211..72d5539ee7 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -231,7 +231,7 @@ void Town::FillCachedName() const */ Money HouseSpec::GetRemovalCost() const { - return (_price[PR_CLEAR_HOUSE] * this->removal_cost) >> 8; + return (_price[Price::ClearHouse] * this->removal_cost) >> 8; } static bool TryBuildTownHouse(Town *t, TileIndex tile, TownExpandModes modes); @@ -1123,7 +1123,7 @@ static bool TerraformTownTile(TileIndex tile, Slope edges, bool dir) assert(tile < Map::Size()); CommandCost r = std::get<0>(Command::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, edges, dir)); - if (r.Failed() || r.GetCost() >= (_price[PR_TERRAFORM] + 2) * 8) return false; + if (r.Failed() || r.GetCost() >= (_price[Price::Terraform] + 2) * 8) return false; Command::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater, DoCommandFlag::Execute}, tile, edges, dir); return true; } @@ -2235,7 +2235,7 @@ std::tuple CmdFoundTown(DoCommandFlags flags, TileIn /* multidimensional arrays have to have defined length of non-first dimension */ static_assert(lengthof(price_mult[0]) == 4); - CommandCost cost(EXPENSES_OTHER, _price[PR_BUILD_TOWN]); + CommandCost cost(EXPENSES_OTHER, _price[Price::BuildTown]); uint8_t mult = price_mult[city][size]; cost.MultiplyCost(mult); @@ -3760,7 +3760,7 @@ TownActions GetMaskOfTownActions(CompanyID cid, const Town *t) /* Is the company not able to build a statue ? */ if (cur == TownAction::BuildStatue && t->statues.Test(cid)) continue; - if (avail >= GetTownActionCost(cur) * _price[PR_TOWN_ACTION] >> 8) { + if (avail >= GetTownActionCost(cur) * _price[Price::TownAction] >> 8) { buttons.Set(cur); } } @@ -3785,7 +3785,7 @@ CommandCost CmdDoTownAction(DoCommandFlags flags, TownID town_id, TownAction act if (!GetMaskOfTownActions(_current_company, t).Test(action)) return CMD_ERROR; - CommandCost cost(EXPENSES_OTHER, _price[PR_TOWN_ACTION] * GetTownActionCost(action) >> 8); + CommandCost cost(EXPENSES_OTHER, _price[Price::TownAction] * GetTownActionCost(action) >> 8); CommandCost ret = _town_action_proc[to_underlying(action)](t, flags); if (ret.Failed()) return ret; @@ -4225,7 +4225,7 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlags flags, int if (res != CALLBACK_FAILED && ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_AUTOSLOPE, res)) allow_terraform = false; } - if (allow_terraform) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (allow_terraform) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 0e36544d62..502e6d723a 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -235,7 +235,7 @@ public: switch (widget) { case WID_TA_ACTION_INFO: if (this->sel_action != TownAction::End) { - Money action_cost = _price[PR_TOWN_ACTION] * GetTownActionCost(this->sel_action) >> 8; + Money action_cost = _price[Price::TownAction] * GetTownActionCost(this->sel_action) >> 8; bool affordable = Company::IsValidID(_local_company) && action_cost < GetAvailableMoney(_local_company); DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect), @@ -253,7 +253,7 @@ public: assert(size.width > padding.width && size.height > padding.height); Dimension d = {0, 0}; for (TownAction i = {}; i != TownAction::End; ++i) { - Money price = _price[PR_TOWN_ACTION] * GetTownActionCost(i) >> 8; + Money price = _price[Price::TownAction] * GetTownActionCost(i) >> 8; d = maxdim(d, GetStringMultiLineBoundingBox(GetString(this->action_tooltips[to_underlying(i)], price), size)); } d.width += padding.width; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index d8ee596f2b..ac430a7e26 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -4089,7 +4089,7 @@ Money Train::GetRunningCost() const do { const Engine *e = v->GetEngine(); - if (e->VehInfo().running_cost_class == INVALID_PRICE) continue; + if (e->VehInfo().running_cost_class == Price::Invalid) continue; uint cost_factor = GetVehicleProperty(v, PROP_TRAIN_RUNNING_COST_FACTOR, e->VehInfo().running_cost); if (cost_factor == 0) continue; diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 29b710ebed..4efcd04354 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -536,7 +536,7 @@ CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_t if (c != nullptr) c->tree_limit -= 1 << 16; } /* 2x as expensive to add more trees to an existing tile */ - cost.AddCost(_price[PR_BUILD_TREES] * 2); + cost.AddCost(_price[Price::BuildTrees] * 2); break; case MP_WATER: @@ -607,7 +607,7 @@ CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_t SetTropicZone(current_tile, TROPICZONE_RAINFOREST); } } - cost.AddCost(_price[PR_BUILD_TREES]); + cost.AddCost(_price[Price::BuildTrees]); break; } @@ -729,7 +729,7 @@ static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlags flags) if (flags.Test(DoCommandFlag::Execute)) DoClearSquare(tile); - return CommandCost(EXPENSES_CONSTRUCTION, num * _price[PR_CLEAR_TREES]); + return CommandCost(EXPENSES_CONSTRUCTION, num * _price[Price::ClearTrees]); } static void GetTileDesc_Trees(TileIndex tile, TileDesc &td) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index d9dfda7772..b8eda8399f 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -226,7 +226,7 @@ static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope if (f == FOUNDATION_NONE) return CommandCost(); - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } /** @@ -280,7 +280,7 @@ static Money TunnelBridgeClearCost(TileIndex tile, Price base_price) case TRANSPORT_RAIL: base_cost += RailClearCost(GetRailType(tile)); break; /* Aqueducts have their own clear price. */ - case TRANSPORT_WATER: base_cost = _price[PR_CLEAR_AQUEDUCT]; break; + case TRANSPORT_WATER: base_cost = _price[Price::ClearAqueduct]; break; default: break; } @@ -451,7 +451,7 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t } /* The cost of clearing the current bridge. */ - cost.AddCost(bridge_len * TunnelBridgeClearCost(tile_start, PR_CLEAR_BRIDGE)); + cost.AddCost(bridge_len * TunnelBridgeClearCost(tile_start, Price::ClearBridge)); owner = GetTileOwner(tile_start); /* If bridge belonged to bankrupt company, it has a new owner now */ @@ -623,10 +623,10 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t if (c != nullptr) bridge_len = CalcBridgeLenCostFactor(bridge_len); if (transport_type != TRANSPORT_WATER) { - cost.AddCost((int64_t)bridge_len * _price[PR_BUILD_BRIDGE] * GetBridgeSpec(bridge_type)->price >> 8); + cost.AddCost((int64_t)bridge_len * _price[Price::BuildBridge] * GetBridgeSpec(bridge_type)->price >> 8); } else { /* Aqueducts use a separate base cost. */ - cost.AddCost((int64_t)bridge_len * _price[PR_BUILD_AQUEDUCT]); + cost.AddCost((int64_t)bridge_len * _price[Price::BuildAqueduct]); } } @@ -727,12 +727,12 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport tiles_bump *= 2; } - cost.AddCost(_price[PR_BUILD_TUNNEL]); + cost.AddCost(_price[Price::BuildTunnel]); cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels } /* Add the cost of the entrance */ - cost.AddCost(_price[PR_BUILD_TUNNEL]); + cost.AddCost(_price[Price::BuildTunnel]); cost.AddCost(ret.GetCost()); /* if the command fails from here on we want the end tile to be highlighted */ @@ -780,7 +780,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND); cost.AddCost(ret.GetCost()); } - cost.AddCost(_price[PR_BUILD_TUNNEL]); + cost.AddCost(_price[Price::BuildTunnel]); /* Pay for the rail/road in the tunnel including entrances */ switch (transport_type) { @@ -893,7 +893,7 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlags flags) ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags); } - Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_TUNNEL); + Money base_cost = TunnelBridgeClearCost(tile, Price::ClearTunnel); uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles. if (flags.Test(DoCommandFlag::Execute)) { @@ -974,7 +974,7 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlags flags) ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM, flags); } - Money base_cost = TunnelBridgeClearCost(tile, PR_CLEAR_BRIDGE); + Money base_cost = TunnelBridgeClearCost(tile, Price::ClearBridge); uint len = GetTunnelBridgeLength(tile, endtile) + 2; // Don't forget the end tiles. if (flags.Test(DoCommandFlag::Execute)) { @@ -2117,7 +2117,7 @@ static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlags fla } /* Surface slope is valid and remains unchanged? */ - if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildFoundation]); } return Command::Do(flags, tile); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index b53ae1e1ad..d9d276893c 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -310,22 +310,22 @@ static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoTyp int cost_factor = GetRefitCostFactor(v, engine_type, new_cargo_type, new_subtype, auto_refit_allowed); switch (e->type) { case VEH_SHIP: - base_price = PR_BUILD_VEHICLE_SHIP; + base_price = Price::BuildVehicleShip; expense_type = EXPENSES_SHIP_RUN; break; case VEH_ROAD: - base_price = PR_BUILD_VEHICLE_ROAD; + base_price = Price::BuildVehicleRoad; expense_type = EXPENSES_ROADVEH_RUN; break; case VEH_AIRCRAFT: - base_price = PR_BUILD_VEHICLE_AIRCRAFT; + base_price = Price::BuildVehicleAircraft; expense_type = EXPENSES_AIRCRAFT_RUN; break; case VEH_TRAIN: - base_price = (e->VehInfo().railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN; + base_price = (e->VehInfo().railveh_type == RAILVEH_WAGON) ? Price::BuildVehicleWagon : Price::BuildVehicleTrain; cost_factor <<= 1; expense_type = EXPENSES_TRAIN_RUN; break; diff --git a/src/water.h b/src/water.h index f81c4adf89..0498844a7a 100644 --- a/src/water.h +++ b/src/water.h @@ -52,7 +52,7 @@ bool IsWateredTile(TileIndex tile, Direction from); */ inline Money CanalMaintenanceCost(uint32_t num) { - return (_price[PR_INFRASTRUCTURE_WATER] * num * (1 + IntSqrt(num))) >> 6; // 6 bits scaling. + return (_price[Price::InfrastructureWater] * num * (1 + IntSqrt(num))) >> 6; // 6 bits scaling. } #endif /* WATER_H */ diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index c41c953ec2..b6da565fa1 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -129,7 +129,7 @@ CommandCost CmdBuildShipDepot(DoCommandFlags flags, TileIndex tile, Axis axis) WaterClass wc1 = GetWaterClass(tile); WaterClass wc2 = GetWaterClass(tile2); - CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]); + CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[Price::BuildDepotShip]); bool add_cost = !IsWaterTile(tile); CommandCost ret = Command::Do(flags | DoCommandFlag::Auto, tile); @@ -298,7 +298,7 @@ static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlags flags) MakeWaterKeepingClass(tile2, GetTileOwner(tile2)); } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearDepotShip]); } /** @@ -344,7 +344,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags ret = Command::Do(flags, tile - delta); if (ret.Failed()) return ret; cost.AddCost(ret.GetCost()); - cost.AddCost(_price[PR_BUILD_CANAL]); + cost.AddCost(_price[Price::BuildCanal]); } if (!IsTileFlat(tile - delta)) { return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); @@ -356,7 +356,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags ret = Command::Do(flags, tile + delta); if (ret.Failed()) return ret; cost.AddCost(ret.GetCost()); - cost.AddCost(_price[PR_BUILD_CANAL]); + cost.AddCost(_price[Price::BuildCanal]); } if (!IsTileFlat(tile + delta)) { return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); @@ -394,7 +394,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags InvalidateWaterRegion(tile - delta); InvalidateWaterRegion(tile + delta); } - cost.AddCost(_price[PR_BUILD_LOCK]); + cost.AddCost(_price[Price::BuildLock]); return cost; } @@ -441,7 +441,7 @@ static CommandCost RemoveLock(TileIndex tile, DoCommandFlags flags) MarkCanalsAndRiversAroundDirty(tile + delta); } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearLock]); } /** @@ -558,7 +558,7 @@ CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_ CheckForDockingTile(current_tile); } - cost.AddCost(_price[PR_BUILD_CANAL]); + cost.AddCost(_price[Price::BuildCanal]); } if (cost.GetCost() == 0) { @@ -575,7 +575,7 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlags flags) case WaterTileType::Clear: { if (flags.Test(DoCommandFlag::NoWater)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER); - Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]; + Money base_cost = IsCanal(tile) ? _price[Price::ClearCanal] : _price[Price::ClearWater]; /* Make sure freeform edges are allowed or it's not an edge tile. */ if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, Map::MaxX() - 1) || !IsInsideMM(TileY(tile), 1, Map::MaxY() - 1))) { @@ -618,9 +618,9 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlags flags) ClearNeighbourNonFloodingStates(tile); } if (IsSlopeWithOneCornerRaised(slope)) { - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearWater]); } else { - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearRough]); } } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 60221228e8..4490774b9c 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -231,7 +231,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi /* only AddCost for non-existing waypoints */ CommandCost cost(EXPENSES_CONSTRUCTION); for (TileIndex cur_tile : new_location) { - if (!IsRailWaypointTile(cur_tile)) cost.AddCost(_price[PR_BUILD_WAYPOINT_RAIL]); + if (!IsRailWaypointTile(cur_tile)) cost.AddCost(_price[Price::BuildWaypointRail]); } /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ @@ -367,9 +367,9 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi /* Total road stop cost. */ Money unit_cost; if (roadstopspec != nullptr) { - unit_cost = roadstopspec->GetBuildCost(PR_BUILD_STATION_TRUCK); + unit_cost = roadstopspec->GetBuildCost(Price::BuildStationTruck); } else { - unit_cost = _price[PR_BUILD_STATION_TRUCK]; + unit_cost = _price[Price::BuildStationTruck]; } StationID est = StationID::Invalid(); CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, true, StationType::RoadWaypoint, roadstopspec, axis, AxisToDiagDir(axis), &est, INVALID_ROADTYPE, unit_cost); @@ -483,7 +483,7 @@ CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile) Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE, false); if (wp == nullptr && !Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING); - CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]); + CommandCost cost(EXPENSES_CONSTRUCTION, _price[Price::BuildWaypointBuoy]); if (!IsWaterTile(tile)) { CommandCost ret = Command::Do(flags | DoCommandFlag::Auto, tile); if (ret.Failed()) return ret; @@ -558,7 +558,7 @@ CommandCost RemoveBuoy(TileIndex tile, DoCommandFlags flags) wp->delete_ctr = 0; } - return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]); + return CommandCost(EXPENSES_CONSTRUCTION, _price[Price::ClearWaypointBuoy]); } /**