OpenTTD Source 20260206-master-g4d4e37dbf1
economy_func.h File Reference

Functions related to the economy. More...

#include "economy_type.h"
#include "station_type.h"
#include "cargo_type.h"
#include "vehicle_type.h"
#include "company_type.h"
#include "settings_type.h"
#include "source_type.h"
#include "core/random_func.hpp"

Go to the source code of this file.

Functions

void ResetPriceBaseMultipliers ()
 Reset changes to the price base multipliers.
void SetPriceBaseMultiplier (Price price, int factor)
 Change a price base by the given factor.
int UpdateCompanyRatingAndValue (Company *c, bool update)
 if update is set to true, the economy is updated with this score (also the house is updated, should only be true in the on-tick event)
void StartupIndustryDailyChanges (bool init_counter)
 Initialize the variables that will maintain the daily industry change system.
Money GetTransportedGoodsIncome (uint num_pieces, uint dist, uint16_t transit_periods, CargoType cargo_type)
uint MoveGoodsToStation (CargoType cargo, uint amount, Source source, const StationList &all_stations, Owner exclusivity=INVALID_OWNER)
void PrepareUnload (Vehicle *front_v)
 Prepare the vehicle to be unloaded.
void LoadUnloadStation (Station *st)
 Load/unload the vehicles in this station according to the order they entered.
Money GetPrice (Price index, uint cost_factor, const struct GRFFile *grf_file, int shift=0)
void InitializeEconomy ()
 Resets economy to initial values.
void RecomputePrices ()
 Computes all prices, payments and maximum loan.
bool AddInflation (bool check_year=true)
 Add monthly inflation.
bool EconomyIsInRecession ()
 Is the economy in recession?
static uint ScaleByInverseCargoScale (uint num, bool town)
 Scale a number by the inverse of the cargo scale setting, e.g.
uint ScaleByCargoScale (uint num, bool town)
 Scale a number by the cargo scale setting.

Variables

const EnumClassIndexContainer< std::array< ScoreInfo, to_underlying(ScoreID::End)>, ScoreID_score_info
 Score info, values used for computing the detailed performance rating.
TypedIndexContainer< std::array< EnumClassIndexContainer< std::array< int64_t, to_underlying(ScoreID::End)>, ScoreID >, MAX_COMPANIES >, CompanyID > _score_part
Economy _economy
Prices _price

Detailed Description

Functions related to the economy.

Definition in file economy_func.h.

Function Documentation

◆ AddInflation()

bool AddInflation ( bool check_year)

Add monthly inflation.

Parameters
check_yearShall the inflation get stopped after 170 years?
Returns
true if inflation is maxed and nothing was changed

Definition at line 699 of file economy.cpp.

References MAX_INFLATION, TimerGameConst< struct Calendar >::ORIGINAL_MAX_YEAR, and TimerGameCalendar::year.

Referenced by AfterLoadGame().

◆ EconomyIsInRecession()

bool EconomyIsInRecession ( )
inline

Is the economy in recession?

Returns
True if economy is in recession, false otherwise.

Definition at line 50 of file economy_func.h.

Referenced by TownGenerateCargo(), TransportIndustryGoods(), and IndustryBuildData::TryBuildNewIndustry().

◆ GetTransportedGoodsIncome()

Money GetTransportedGoodsIncome ( uint num_pieces,
uint dist,
uint16_t transit_periods,
CargoType cargo_type )

Definition at line 956 of file economy.cpp.

◆ InitializeEconomy()

void InitializeEconomy ( )

Resets economy to initial values.

Definition at line 925 of file economy.cpp.

References ClearCargoDeliveryMonitoring(), and ClearCargoPickupMonitoring().

◆ LoadUnloadStation()

void LoadUnloadStation ( Station * st)

Load/unload the vehicles in this station according to the order they entered.

Parameters
stthe station to do the loading/unloading for

Definition at line 1922 of file economy.cpp.

References _cargo_delivery_destinations, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Vehicle::load_unload_ticks, LoadUnloadVehicle(), TriggerIndustryProduction(), and Vehicle::vehstatus.

◆ MoveGoodsToStation()

uint MoveGoodsToStation ( CargoType cargo,
uint amount,
Source source,
const StationList & all_stations,
Owner exclusivity = INVALID_OWNER )

Definition at line 4604 of file station_cmd.cpp.

◆ PrepareUnload()

◆ RecomputePrices()

◆ ResetPriceBaseMultipliers()

void ResetPriceBaseMultipliers ( )

Reset changes to the price base multipliers.

Definition at line 861 of file economy.cpp.

Referenced by ResetNewGRFData().

◆ ScaleByCargoScale()

uint ScaleByCargoScale ( uint num,
bool town )
inline

Scale a number by the cargo scale setting.

Parameters
numThe number to scale.
townAre we scaling town production, or industry production?
Returns
The number scaled by the current cargo scale setting. May be 0.

Definition at line 78 of file economy_func.h.

References _settings_game, Chance16(), and ScaleByInverseCargoScale().

Referenced by ChopLumberMillTrees(), DoCreateNewIndustry(), ProduceIndustryGoodsHelper(), TownGenerateCargo(), and UpdateTownMaxPass().

◆ ScaleByInverseCargoScale()

uint ScaleByInverseCargoScale ( uint num,
bool town )
static

Scale a number by the inverse of the cargo scale setting, e.g.

a scale of 25% multiplies the number by 4.

Parameters
numThe number to scale.
townAre we scaling town production, or industry production?
Returns
The number scaled by the inverse of the cargo scale setting, minimum of 1.

Definition at line 61 of file economy_func.h.

References _settings_game.

Referenced by ScaleByCargoScale().

◆ SetPriceBaseMultiplier()

void SetPriceBaseMultiplier ( Price price,
int factor )

Change a price base by the given factor.

The price base is altered by factors of two. NewBaseCost = OldBaseCost * 2^n

Parameters
priceIndex of price base to change.
factorAmount to change by.

Definition at line 873 of file economy.cpp.

References Clamp(), End, and MIN_PRICE_MODIFIER.

Referenced by FinalisePriceBaseMultipliers().

◆ StartupIndustryDailyChanges()

void StartupIndustryDailyChanges ( bool init_counter)

Initialize the variables that will maintain the daily industry change system.

Parameters
init_counterspecifies if the counter is required to be initialized

Definition at line 883 of file economy.cpp.

References Map::LogX(), and Map::LogY().

Referenced by ECMYChunkHandler::Load().

◆ UpdateCompanyRatingAndValue()

int UpdateCompanyRatingAndValue ( Company * c,
bool update )

if update is set to true, the economy is updated with this score (also the house is updated, should only be true in the on-tick event)

Parameters
updatethe economy with calculated score
ccompany been evaluated
Returns
actual score of this company

Definition at line 202 of file economy.cpp.

References _score_info, Begin, CalculateCompanyValue(), Cargo, Clamp(), CompanyProperties::current_loan, Delivered, End, IsCompanyBuildableVehicleType(), SpecializedStation< Station, false >::Iterate(), Loan, CompanyProperties::location_of_HQ, MaxIncome, MinIncome, MinProfit, Money, CompanyProperties::money, CompanyProperties::num_valid_stat_ent, CompanyProperties::old_economy, SCORE_MAX, SetWindowDirty(), Stations, Total, UpdateCompanyHQ(), VEHICLE_PROFIT_MIN_AGE, Vehicles, and WC_PERFORMANCE_DETAIL.

Referenced by CmdBuildObject(), and CompaniesGenStatistics().

Variable Documentation

◆ _economy

Economy _economy
extern

Definition at line 105 of file economy.cpp.

◆ _price

Prices _price
extern

Definition at line 106 of file economy.cpp.

◆ _score_info

const EnumClassIndexContainer<std::array<ScoreInfo, to_underlying(ScoreID::End)>, ScoreID> _score_info
extern

Score info, values used for computing the detailed performance rating.

Definition at line 91 of file economy.cpp.

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

◆ _score_part

TypedIndexContainer<std::array<EnumClassIndexContainer<std::array<int64_t, to_underlying(ScoreID::End)>, ScoreID>, MAX_COMPANIES>, CompanyID> _score_part
extern

Definition at line 104 of file economy.cpp.