OpenTTD Source 20250205-master-gfd85ab1e2c
economy_type.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef ECONOMY_TYPE_H
11#define ECONOMY_TYPE_H
12
14#include "core/enum_type.hpp"
15
17
19enum EconomyType : uint8_t {
20 ET_BEGIN = 0,
21 ET_ORIGINAL = 0,
22 ET_SMOOTH = 1,
23 ET_FROZEN = 2,
24 ET_END = 3,
25};
26
32static const int MIN_CARGO_SCALE = 15;
38static const int MAX_CARGO_SCALE = 300;
40static const int DEF_CARGO_SCALE = 100;
41
43struct Economy {
45 int16_t fluct;
46 uint8_t interest_rate;
47 uint8_t infl_amount;
53
54 /* Old stuff for savegame conversion only */
57};
58
60enum ScoreID : uint8_t {
61 SCORE_BEGIN = 0,
62 SCORE_VEHICLES = 0,
63 SCORE_STATIONS = 1,
64 SCORE_MIN_PROFIT = 2,
65 SCORE_MIN_INCOME = 3,
66 SCORE_MAX_INCOME = 4,
67 SCORE_DELIVERED = 5,
68 SCORE_CARGO = 6,
69 SCORE_MONEY = 7,
70 SCORE_LOAN = 8,
72 SCORE_END = 10,
73
74
75};
77
78
82static constexpr int SCORE_MAX = 1000;
83
85struct ScoreInfo {
86 int needed;
87 int score;
88};
89
94enum Price : uint8_t {
95 PR_BEGIN = 0,
96 PR_STATION_VALUE = 0,
97 PR_BUILD_RAIL,
98 PR_BUILD_ROAD,
99 PR_BUILD_SIGNALS,
100 PR_BUILD_BRIDGE,
101 PR_BUILD_DEPOT_TRAIN,
102 PR_BUILD_DEPOT_ROAD,
103 PR_BUILD_DEPOT_SHIP,
104 PR_BUILD_TUNNEL,
105 PR_BUILD_STATION_RAIL,
106 PR_BUILD_STATION_RAIL_LENGTH,
107 PR_BUILD_STATION_AIRPORT,
108 PR_BUILD_STATION_BUS,
109 PR_BUILD_STATION_TRUCK,
110 PR_BUILD_STATION_DOCK,
111 PR_BUILD_VEHICLE_TRAIN,
112 PR_BUILD_VEHICLE_WAGON,
113 PR_BUILD_VEHICLE_AIRCRAFT,
114 PR_BUILD_VEHICLE_ROAD,
115 PR_BUILD_VEHICLE_SHIP,
116 PR_BUILD_TREES,
117 PR_TERRAFORM,
118 PR_CLEAR_GRASS,
119 PR_CLEAR_ROUGH,
120 PR_CLEAR_ROCKS,
121 PR_CLEAR_FIELDS,
122 PR_CLEAR_TREES,
123 PR_CLEAR_RAIL,
124 PR_CLEAR_SIGNALS,
125 PR_CLEAR_BRIDGE,
126 PR_CLEAR_DEPOT_TRAIN,
127 PR_CLEAR_DEPOT_ROAD,
128 PR_CLEAR_DEPOT_SHIP,
129 PR_CLEAR_TUNNEL,
130 PR_CLEAR_WATER,
131 PR_CLEAR_STATION_RAIL,
132 PR_CLEAR_STATION_AIRPORT,
133 PR_CLEAR_STATION_BUS,
134 PR_CLEAR_STATION_TRUCK,
135 PR_CLEAR_STATION_DOCK,
136 PR_CLEAR_HOUSE,
137 PR_CLEAR_ROAD,
138 PR_RUNNING_TRAIN_STEAM,
139 PR_RUNNING_TRAIN_DIESEL,
140 PR_RUNNING_TRAIN_ELECTRIC,
141 PR_RUNNING_AIRCRAFT,
142 PR_RUNNING_ROADVEH,
143 PR_RUNNING_SHIP,
144 PR_BUILD_INDUSTRY,
145 PR_CLEAR_INDUSTRY,
146 PR_BUILD_OBJECT,
147 PR_CLEAR_OBJECT,
148 PR_BUILD_WAYPOINT_RAIL,
149 PR_CLEAR_WAYPOINT_RAIL,
150 PR_BUILD_WAYPOINT_BUOY,
151 PR_CLEAR_WAYPOINT_BUOY,
152 PR_TOWN_ACTION,
153 PR_BUILD_FOUNDATION,
154 PR_BUILD_INDUSTRY_RAW,
155 PR_BUILD_TOWN,
156 PR_BUILD_CANAL,
157 PR_CLEAR_CANAL,
158 PR_BUILD_AQUEDUCT,
159 PR_CLEAR_AQUEDUCT,
160 PR_BUILD_LOCK,
161 PR_CLEAR_LOCK,
162 PR_INFRASTRUCTURE_RAIL,
163 PR_INFRASTRUCTURE_ROAD,
164 PR_INFRASTRUCTURE_WATER,
165 PR_INFRASTRUCTURE_STATION,
166 PR_INFRASTRUCTURE_AIRPORT,
167
168 PR_END,
169 INVALID_PRICE = 0xFF
170};
172
173typedef Money Prices[PR_END];
174typedef int8_t PriceMultipliers[PR_END];
175
194
198using Expenses = std::array<Money, EXPENSES_END>;
199
208
218
220static const int LOAN_INTERVAL = 10000;
222static const int64_t INITIAL_LOAN = 100000;
224static const int64_t MAX_LOAN_LIMIT = 2000000000;
225
234static const uint64_t MAX_INFLATION = (1ull << (63 - 32)) - 1;
235
241static const int MIN_PRICE_MODIFIER = -8;
242static const int MAX_PRICE_MODIFIER = 16;
243static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1;
244
246static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4;
248static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2;
250static const uint ROAD_DEPOT_TRACKBIT_FACTOR = 2;
252static const uint ROAD_STOP_TRACKBIT_FACTOR = 2;
254static const uint LOCK_DEPOT_TILE_FACTOR = 2;
255
256struct CargoPayment;
257typedef uint32_t CargoPaymentID;
258
259#endif /* ECONOMY_TYPE_H */
ScoreID
Score categories in the detailed performance rating.
@ SCORE_END
How many scores are there..
@ SCORE_TOTAL
This must always be the last entry.
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
static const int64_t MAX_LOAN_LIMIT
The max amount possible to configure for a max loan of a company.
EconomyType
Type of the game economy.
static const int MIN_PRICE_MODIFIER
Maximum NewGRF price modifiers.
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
static const uint ROAD_DEPOT_TRACKBIT_FACTOR
Multiplier for how many regular track bits a road depot counts.
std::array< Money, EXPENSES_END > Expenses
Data type for storage of Money for each ExpensesType category.
ExpensesType
Types of expenses.
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
@ EXPENSES_END
Number of expense types.
@ EXPENSES_TRAIN_RUN
Running costs trains.
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
@ EXPENSES_CONSTRUCTION
Construction costs.
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
@ EXPENSES_PROPERTY
Property costs.
@ EXPENSES_OTHER
Other expenses.
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
@ EXPENSES_SHIP_RUN
Running costs ships.
@ INVALID_EXPENSES
Invalid expense type.
@ EXPENSES_NEW_VEHICLES
New vehicles.
Money Prices[PR_END]
Prices of everything.
PriceCategory
Categories of a price bases.
@ PCAT_RUNNING
Price is affected by "vehicle running cost" difficulty setting.
@ PCAT_CONSTRUCTION
Price is affected by "construction cost" difficulty setting.
@ PCAT_NONE
Not affected by difficulty settings.
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
static const int MIN_CARGO_SCALE
Minimum allowed value of town_cargo_scale/industry_cargo_scale.
static const int64_t INITIAL_LOAN
The size of loan for a new company, in British Pounds!
static const uint64_t MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64_t price computations...
Price
Enumeration of all base prices for use with Prices.
static constexpr int SCORE_MAX
The max score that can be in the performance history.
static const int MAX_CARGO_SCALE
Maximum allowed value of town_cargo_scale/industry_cargo_scale.
static const int DEF_CARGO_SCALE
Default value of town_cargo_scale/industry_cargo_scale.
Type (helpers) for enums.
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:61
An overflow safe integer-like type.
Helper class to perform the cargo payment.
Data of the economy.
uint64_t inflation_payment
Cumulated inflation of cargo payment since game start; 16 bit fractional part.
uint8_t infl_amount
inflation amount
uint64_t inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Money old_max_loan_unround
Old: Unrounded max loan.
int16_t fluct
Economy fluctuation status.
uint8_t infl_amount_pr
inflation rate for payment rates
uint32_t industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
uint32_t industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
uint16_t old_max_loan_unround_fract
Old: Fraction of the unrounded max loan.
Money max_loan
NOSAVE: Maximum possible loan.
uint8_t interest_rate
Interest.
Describes properties of price bases.
Price fallback_price
Fallback price multiplier for new prices but old grfs.
PriceCategory category
Price is affected by certain difficulty settings.
Money start_price
Default value at game start, before adding multipliers.
uint grf_feature
GRF Feature that decides whether price multipliers apply locally or globally, GSF_END if none.
Data structure for storing how the score is computed for a single score id.
int needed
How much you need to get the perfect score.
int score
How much score it will give.