OpenTTD Source 20260129-master-g2bb01bd0e4
economy_type.h File Reference

Types related to the economy. More...

Go to the source code of this file.

Data Structures

struct  Economy
 Data of the economy. More...
 
struct  ScoreInfo
 Data structure for storing how the score is computed for a single score id. More...
 

Typedefs

typedef OverflowSafeInt64 Money
 
using Prices = EnumClassIndexContainer< std::array< Money, to_underlying(Price::End)>, Price >
 Prices of everything.
 
using PriceMultipliers = EnumClassIndexContainer< std::array< int8_t, to_underlying(Price::End)>, Price >
 
using Expenses = std::array< Money, EXPENSES_END >
 Data type for storage of Money for each ExpensesType category.
 
using CargoPaymentID = PoolID< uint32_t, struct CargoPaymentIDTag, 0xFF000, 0xFFFFF >
 

Enumerations

enum class  EconomyType : uint8_t {
  Begin , Original = EconomyType::Begin , Smooth , Frozen ,
  End
}
 Type of the game economy. More...
 
enum class  ScoreID : uint8_t {
  Begin , Vehicles = ScoreID::Begin , Stations , MinProfit ,
  MinIncome , MaxIncome , Delivered , Cargo ,
  Money , Loan , Total , End
}
 Score categories in the detailed performance rating. More...
 
enum class  Price : uint8_t {
  Begin , StationValue = Price::Begin , BuildRail , BuildRoad ,
  BuildSignals , BuildBridge , BuildDepotTrain , BuildDepotRoad ,
  BuildDepotShip , BuildTunnel , BuildStationRail , BuildStationRailLength ,
  BuildStationAirport , BuildStationBus , BuildStationTruck , BuildStationDock ,
  BuildVehicleTrain , BuildVehicleWagon , BuildVehicleAircraft , BuildVehicleRoad ,
  BuildVehicleShip , BuildTrees , Terraform , ClearGrass ,
  ClearRough , ClearRocks , ClearFields , ClearTrees ,
  ClearRail , ClearSignals , ClearBridge , ClearDepotTrain ,
  ClearDepotRoad , ClearDepotShip , ClearTunnel , ClearWater ,
  ClearStationRail , ClearStationAirport , ClearStationBus , ClearStationTruck ,
  ClearStationDock , ClearHouse , ClearRoad , RunningTrainSteam ,
  RunningTrainDiesel , RunningTrainElectric , RunningAircraft , RunningRoadveh ,
  RunningShip , BuildIndustry , ClearIndustry , BuildObject ,
  ClearObject , BuildWaypointRail , ClearWaypointRail , BuildWaypointBuoy ,
  ClearWaypointBuoy , TownAction , BuildFoundation , BuildIndustryRaw ,
  BuildTown , BuildCanal , ClearCanal , BuildAqueduct ,
  ClearAqueduct , BuildLock , ClearLock , InfrastructureRail ,
  InfrastructureRoad , InfrastructureWater , InfrastructureStation , InfrastructureAirport ,
  End , Invalid = 0xFF
}
 Enumeration of all base prices for use with Prices. More...
 
enum  ExpensesType : uint8_t {
  EXPENSES_CONSTRUCTION = 0 , EXPENSES_NEW_VEHICLES , EXPENSES_TRAIN_RUN , EXPENSES_ROADVEH_RUN ,
  EXPENSES_AIRCRAFT_RUN , EXPENSES_SHIP_RUN , EXPENSES_PROPERTY , EXPENSES_TRAIN_REVENUE ,
  EXPENSES_ROADVEH_REVENUE , EXPENSES_AIRCRAFT_REVENUE , EXPENSES_SHIP_REVENUE , EXPENSES_LOAN_INTEREST ,
  EXPENSES_OTHER , EXPENSES_END , INVALID_EXPENSES = 0xFF
}
 Types of expenses. More...
 
enum  PriceCategory : uint8_t { PCAT_NONE , PCAT_RUNNING , PCAT_CONSTRUCTION }
 Categories of a price bases. More...
 

Variables

static const int MIN_CARGO_SCALE = 15
 Minimum allowed value of town_cargo_scale/industry_cargo_scale.
 
static const int MAX_CARGO_SCALE = 300
 Maximum allowed value of town_cargo_scale/industry_cargo_scale.
 
static const int DEF_CARGO_SCALE = 100
 Default value of town_cargo_scale/industry_cargo_scale.
 
static constexpr int SCORE_MAX = 1000
 The max score that can be in the performance history.
 
static const int LOAN_INTERVAL = 10000
 The "steps" in loan size, in British Pounds!
 
static const int64_t INITIAL_LOAN = 100000
 The size of loan for a new company, in British Pounds!
 
static const int64_t MAX_LOAN_LIMIT = 2000000000
 The max amount possible to configure for a max loan of a company.
 
static const uint64_t MAX_INFLATION = (1ull << (63 - 32)) - 1
 Maximum inflation (including fractional part) without causing overflows in int64_t price computations.
 
static const int MIN_PRICE_MODIFIER = -8
 Maximum NewGRF price modifiers.
 
static const int MAX_PRICE_MODIFIER = 16
 
static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1
 
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4
 Multiplier for how many regular track bits a tunnel/bridge counts.
 
static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2
 Multiplier for how many regular track bits a level crossing counts.
 
static const uint ROAD_DEPOT_TRACKBIT_FACTOR = 2
 Multiplier for how many regular track bits a road depot counts.
 
static const uint ROAD_STOP_TRACKBIT_FACTOR = 2
 Multiplier for how many regular track bits a bay stop counts.
 
static const uint LOCK_DEPOT_TILE_FACTOR = 2
 Multiplier for how many regular tiles a lock counts.
 

Detailed Description

Types related to the economy.

Definition in file economy_type.h.

Typedef Documentation

◆ CargoPaymentID

using CargoPaymentID = PoolID<uint32_t, struct CargoPaymentIDTag, 0xFF000, 0xFFFFF>

Definition at line 245 of file economy_type.h.

◆ Expenses

using Expenses = std::array<Money, EXPENSES_END>

Data type for storage of Money for each ExpensesType category.

Definition at line 196 of file economy_type.h.

◆ Money

Definition at line 17 of file economy_type.h.

◆ PriceMultipliers

Definition at line 172 of file economy_type.h.

◆ Prices

Prices of everything.

See also
Price

Definition at line 171 of file economy_type.h.

Enumeration Type Documentation

◆ EconomyType

enum class EconomyType : uint8_t
strong

Type of the game economy.

Enumerator
Begin 

The lowest valid value.

Original 

Imitates original TTD economy.

Smooth 

Makes production changes more often, and in smaller steps.

Frozen 

Stops production changes and industry closures.

End 

Economy type end marker.

Definition at line 20 of file economy_type.h.

◆ ExpensesType

enum ExpensesType : uint8_t

Types of expenses.

Enumerator
EXPENSES_CONSTRUCTION 

Construction costs.

EXPENSES_NEW_VEHICLES 

New vehicles.

EXPENSES_TRAIN_RUN 

Running costs trains.

EXPENSES_ROADVEH_RUN 

Running costs road vehicles.

EXPENSES_AIRCRAFT_RUN 

Running costs aircraft.

EXPENSES_SHIP_RUN 

Running costs ships.

EXPENSES_PROPERTY 

Property costs.

EXPENSES_TRAIN_REVENUE 

Revenue from trains.

EXPENSES_ROADVEH_REVENUE 

Revenue from road vehicles.

EXPENSES_AIRCRAFT_REVENUE 

Revenue from aircraft.

EXPENSES_SHIP_REVENUE 

Revenue from ships.

EXPENSES_LOAN_INTEREST 

Interest payments over the loan.

EXPENSES_OTHER 

Other expenses.

EXPENSES_END 

Number of expense types.

INVALID_EXPENSES 

Invalid expense type.

Definition at line 175 of file economy_type.h.

◆ Price

enum class Price : uint8_t
strong

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.

Enumerator
Begin 

The lowest valid value.

StationValue 

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 

Invalid base price.

Definition at line 93 of file economy_type.h.

◆ PriceCategory

enum PriceCategory : uint8_t

Categories of a price bases.

Enumerator
PCAT_NONE 

Not affected by difficulty settings.

PCAT_RUNNING 

Price is affected by "vehicle running cost" difficulty setting.

PCAT_CONSTRUCTION 

Price is affected by "construction cost" difficulty setting.

Definition at line 201 of file economy_type.h.

◆ ScoreID

enum class ScoreID : uint8_t
strong

Score categories in the detailed performance rating.

Enumerator
Begin 

The lowest valid value.

Vehicles 

Number of vehicles that turned profit last year.

Stations 

Number of recently-serviced stations.

MinProfit 

The profit of the vehicle with the lowest income.

MinIncome 

Income in the quater with the lowest profit of the last 12 quaters.

MaxIncome 

Income in the quater with the highest profit of the last 12 quaters.

Delivered 

Units of cargo delivered in the last four quaters.

Cargo 

Number of types of cargo delivered in the last four quaters.

Money 

Amount of money company has in the bank.

Loan 

The amount of money company can take as a loan.

Total 

Total points out of possible points ,must always be the last entry.

End 

Score ID end marker.

Definition at line 61 of file economy_type.h.

Variable Documentation

◆ DEF_CARGO_SCALE

const int DEF_CARGO_SCALE = 100
static

Default value of town_cargo_scale/industry_cargo_scale.

Definition at line 41 of file economy_type.h.

◆ INITIAL_LOAN

const int64_t INITIAL_LOAN = 100000
static

The size of loan for a new company, in British Pounds!

Definition at line 210 of file economy_type.h.

Referenced by DoStartupNewCompany().

◆ INVALID_PRICE_MODIFIER

const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1
static

Definition at line 231 of file economy_type.h.

◆ LEVELCROSSING_TRACKBIT_FACTOR

const uint LEVELCROSSING_TRACKBIT_FACTOR = 2
static

Multiplier for how many regular track bits a level crossing counts.

Definition at line 236 of file economy_type.h.

Referenced by CmdBuildRoad(), CmdBuildSingleRail(), CmdConvertRail(), CmdRemoveSingleRail(), and RemoveRoad().

◆ LOAN_INTERVAL

const int LOAN_INTERVAL = 10000
static

The "steps" in loan size, in British Pounds!

Definition at line 208 of file economy_type.h.

Referenced by CmdDecreaseLoan(), CmdIncreaseLoan(), CmdSetCompanyMaxLoan(), DoStartupNewCompany(), CompanyFinancesWindow::GetWidgetString(), and RecomputePrices().

◆ LOCK_DEPOT_TILE_FACTOR

const uint LOCK_DEPOT_TILE_FACTOR = 2
static

Multiplier for how many regular tiles a lock counts.

Definition at line 242 of file economy_type.h.

Referenced by CmdBuildShipDepot(), DoBuildLock(), and RemoveLock().

◆ MAX_CARGO_SCALE

const int MAX_CARGO_SCALE = 300
static

Maximum allowed value of town_cargo_scale/industry_cargo_scale.

Above 340, callback-based industries would produce more than once per day, which GRFs do not expect. Towns use the same maximum to match.

Definition at line 39 of file economy_type.h.

◆ MAX_INFLATION

const uint64_t MAX_INFLATION = (1ull << (63 - 32)) - 1
static

Maximum inflation (including fractional part) without causing overflows in int64_t price computations.

This allows for 32 bit base prices (21 are currently needed). Considering the sign bit and 16 fractional bits, there are 15 bits left. 170 years of 4% inflation result in a inflation of about 822, so 10 bits are actually enough. Note that NewGRF multipliers share the 16 fractional bits.

See also
MAX_PRICE_MODIFIER

Definition at line 222 of file economy_type.h.

Referenced by AddInflation(), and AfterLoadGame().

◆ MAX_LOAN_LIMIT

const int64_t MAX_LOAN_LIMIT = 2000000000
static

The max amount possible to configure for a max loan of a company.

Definition at line 212 of file economy_type.h.

Referenced by CmdSetCompanyMaxLoan().

◆ MAX_PRICE_MODIFIER

const int MAX_PRICE_MODIFIER = 16
static

Definition at line 230 of file economy_type.h.

◆ MIN_CARGO_SCALE

const int MIN_CARGO_SCALE = 15
static

Minimum allowed value of town_cargo_scale/industry_cargo_scale.

Below 13, callback-based industries would produce less than once per month. We round up to 15% because it's a nicer number. Towns use the same minimum to match, and because below this small towns often produce no cargo.

Definition at line 33 of file economy_type.h.

◆ MIN_PRICE_MODIFIER

const int MIN_PRICE_MODIFIER = -8
static

Maximum NewGRF price modifiers.

Increasing base prices by factor 65536 should be enough.

See also
MAX_INFLATION

Definition at line 229 of file economy_type.h.

Referenced by SetPriceBaseMultiplier().

◆ ROAD_DEPOT_TRACKBIT_FACTOR

const uint ROAD_DEPOT_TRACKBIT_FACTOR = 2
static

Multiplier for how many regular track bits a road depot counts.

Definition at line 238 of file economy_type.h.

Referenced by CmdBuildRoadDepot(), and CmdConvertRoad().

◆ ROAD_STOP_TRACKBIT_FACTOR

const uint ROAD_STOP_TRACKBIT_FACTOR = 2
static

Multiplier for how many regular track bits a bay stop counts.

Definition at line 240 of file economy_type.h.

Referenced by CmdBuildRoadStop(), CmdBuildRoadWaypoint(), CmdConvertRoad(), RemoveRoadStop(), and RemoveRoadWaypointStop().

◆ SCORE_MAX

constexpr int SCORE_MAX = 1000
staticconstexpr

The max score that can be in the performance history.

The scores together of score_info is allowed to be more!

Definition at line 81 of file economy_type.h.

Referenced by PerformanceRatingDetailWindow::DrawWidget(), and UpdateCompanyRatingAndValue().

◆ TUNNELBRIDGE_TRACKBIT_FACTOR

const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4
static

Multiplier for how many regular track bits a tunnel/bridge counts.

Definition at line 234 of file economy_type.h.

Referenced by CmdBuildBridge(), CmdBuildRoad(), CmdBuildTunnel(), CmdConvertRail(), CmdConvertRoad(), DoClearBridge(), DoClearTunnel(), and RemoveRoad().