OpenTTD Source: src/economy_type.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef ECONOMY_TYPE_H
11#define ECONOMY_TYPE_H
12
13#include "core/overflowsafe_type.hpp"
14#include "core/enum_type.hpp"
15#include "core/pool_type.hpp"
16
17typedef OverflowSafeInt64 Money;
18
20 enum EconomyType : uint8_t {
21 ET_BEGIN = 0,
22 ET_ORIGINAL = 0,
23 ET_SMOOTH = 1,
24 ET_FROZEN = 2,
25 ET_END = 3,
26};
27
33 static const int MIN_CARGO_SCALE = 15;
39 static const int MAX_CARGO_SCALE = 300;
41 static const int DEF_CARGO_SCALE = 100;
42
44 struct Economy {
45 Money max_loan;
46 int16_t fluct;
47 uint8_t interest_rate;
48 uint8_t infl_amount;
49 uint8_t infl_amount_pr;
50 uint32_t industry_daily_change_counter;
51 uint32_t industry_daily_increment;
52 uint64_t inflation_prices;
53 uint64_t inflation_payment;
54
55 /* Old stuff for savegame conversion only */
56 Money old_max_loan_unround;
57 uint16_t old_max_loan_unround_fract;
58};
59
61 enum ScoreID : uint8_t {
62 SCORE_BEGIN = 0,
63 SCORE_VEHICLES = 0,
64 SCORE_STATIONS = 1,
65 SCORE_MIN_PROFIT = 2,
66 SCORE_MIN_INCOME = 3,
67 SCORE_MAX_INCOME = 4,
68 SCORE_DELIVERED = 5,
69 SCORE_CARGO = 6,
70 SCORE_MONEY = 7,
71 SCORE_LOAN = 8,
72 SCORE_TOTAL = 9,
73 SCORE_END = 10,
74
75
76};
77 DECLARE_INCREMENT_DECREMENT_OPERATORS(ScoreID)
78
79
83static constexpr int SCORE_MAX = 1000;
84
86struct ScoreInfo {
87 int needed;
88 int score;
89};
90
95 enum Price : uint8_t {
96 PR_BEGIN = 0,
97 PR_STATION_VALUE = 0,
98 PR_BUILD_RAIL,
99 PR_BUILD_ROAD,
100 PR_BUILD_SIGNALS,
101 PR_BUILD_BRIDGE,
102 PR_BUILD_DEPOT_TRAIN,
103 PR_BUILD_DEPOT_ROAD,
104 PR_BUILD_DEPOT_SHIP,
105 PR_BUILD_TUNNEL,
106 PR_BUILD_STATION_RAIL,
107 PR_BUILD_STATION_RAIL_LENGTH,
108 PR_BUILD_STATION_AIRPORT,
109 PR_BUILD_STATION_BUS,
110 PR_BUILD_STATION_TRUCK,
111 PR_BUILD_STATION_DOCK,
112 PR_BUILD_VEHICLE_TRAIN,
113 PR_BUILD_VEHICLE_WAGON,
114 PR_BUILD_VEHICLE_AIRCRAFT,
115 PR_BUILD_VEHICLE_ROAD,
116 PR_BUILD_VEHICLE_SHIP,
117 PR_BUILD_TREES,
118 PR_TERRAFORM,
119 PR_CLEAR_GRASS,
120 PR_CLEAR_ROUGH,
121 PR_CLEAR_ROCKS,
122 PR_CLEAR_FIELDS,
123 PR_CLEAR_TREES,
124 PR_CLEAR_RAIL,
125 PR_CLEAR_SIGNALS,
126 PR_CLEAR_BRIDGE,
127 PR_CLEAR_DEPOT_TRAIN,
128 PR_CLEAR_DEPOT_ROAD,
129 PR_CLEAR_DEPOT_SHIP,
130 PR_CLEAR_TUNNEL,
131 PR_CLEAR_WATER,
132 PR_CLEAR_STATION_RAIL,
133 PR_CLEAR_STATION_AIRPORT,
134 PR_CLEAR_STATION_BUS,
135 PR_CLEAR_STATION_TRUCK,
136 PR_CLEAR_STATION_DOCK,
137 PR_CLEAR_HOUSE,
138 PR_CLEAR_ROAD,
139 PR_RUNNING_TRAIN_STEAM,
140 PR_RUNNING_TRAIN_DIESEL,
141 PR_RUNNING_TRAIN_ELECTRIC,
142 PR_RUNNING_AIRCRAFT,
143 PR_RUNNING_ROADVEH,
144 PR_RUNNING_SHIP,
145 PR_BUILD_INDUSTRY,
146 PR_CLEAR_INDUSTRY,
147 PR_BUILD_OBJECT,
148 PR_CLEAR_OBJECT,
149 PR_BUILD_WAYPOINT_RAIL,
150 PR_CLEAR_WAYPOINT_RAIL,
151 PR_BUILD_WAYPOINT_BUOY,
152 PR_CLEAR_WAYPOINT_BUOY,
153 PR_TOWN_ACTION,
154 PR_BUILD_FOUNDATION,
155 PR_BUILD_INDUSTRY_RAW,
156 PR_BUILD_TOWN,
157 PR_BUILD_CANAL,
158 PR_CLEAR_CANAL,
159 PR_BUILD_AQUEDUCT,
160 PR_CLEAR_AQUEDUCT,
161 PR_BUILD_LOCK,
162 PR_CLEAR_LOCK,
163 PR_INFRASTRUCTURE_RAIL,
164 PR_INFRASTRUCTURE_ROAD,
165 PR_INFRASTRUCTURE_WATER,
166 PR_INFRASTRUCTURE_STATION,
167 PR_INFRASTRUCTURE_AIRPORT,
168
169 PR_END,
170 INVALID_PRICE = 0xFF
171};
172 DECLARE_INCREMENT_DECREMENT_OPERATORS(Price)
173
174typedef Money Prices[PR_END];
175using PriceMultipliers = std::array<int8_t, PR_END>;
176
178enum ExpensesType : uint8_t {
179 EXPENSES_CONSTRUCTION = 0,
180 EXPENSES_NEW_VEHICLES,
181 EXPENSES_TRAIN_RUN,
182 EXPENSES_ROADVEH_RUN,
183 EXPENSES_AIRCRAFT_RUN,
184 EXPENSES_SHIP_RUN,
185 EXPENSES_PROPERTY,
186 EXPENSES_TRAIN_REVENUE,
187 EXPENSES_ROADVEH_REVENUE,
188 EXPENSES_AIRCRAFT_REVENUE,
189 EXPENSES_SHIP_REVENUE,
190 EXPENSES_LOAN_INTEREST,
191 EXPENSES_OTHER,
192 EXPENSES_END,
193 INVALID_EXPENSES = 0xFF,
194};
195
199 using Expenses = std::array<Money, EXPENSES_END>;
200
204 enum PriceCategory : uint8_t {
205 PCAT_NONE,
206 PCAT_RUNNING,
207 PCAT_CONSTRUCTION,
208};
209
211 static const int LOAN_INTERVAL = 10000;
213 static const int64_t INITIAL_LOAN = 100000;
215 static const int64_t MAX_LOAN_LIMIT = 2000000000;
216
225 static const uint64_t MAX_INFLATION = (1ull << (63 - 32)) - 1;
226
232 static const int MIN_PRICE_MODIFIER = -8;
233static const int MAX_PRICE_MODIFIER = 16;
234static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1;
235
237 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4;
239 static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2;
241 static const uint ROAD_DEPOT_TRACKBIT_FACTOR = 2;
243 static const uint ROAD_STOP_TRACKBIT_FACTOR = 2;
245 static const uint LOCK_DEPOT_TILE_FACTOR = 2;
246
247struct CargoPayment;
248using CargoPaymentID = PoolID<uint32_t, struct CargoPaymentIDTag, 0xFF000, 0xFFFFF>;
249
250#endif /* ECONOMY_TYPE_H */
OverflowSafeInt< int64_t >
ScoreID
ScoreID
Score categories in the detailed performance rating.
Definition economy_type.h:61
SCORE_END
@ SCORE_END
How many scores are there..
Definition economy_type.h:73
SCORE_TOTAL
@ SCORE_TOTAL
This must always be the last entry.
Definition economy_type.h:72
LOCK_DEPOT_TILE_FACTOR
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition economy_type.h:245
LEVELCROSSING_TRACKBIT_FACTOR
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition economy_type.h:239
MAX_LOAN_LIMIT
static const int64_t MAX_LOAN_LIMIT
The max amount possible to configure for a max loan of a company.
Definition economy_type.h:215
EconomyType
EconomyType
Type of the game economy.
Definition economy_type.h:20
MIN_PRICE_MODIFIER
static const int MIN_PRICE_MODIFIER
Maximum NewGRF price modifiers.
Definition economy_type.h:232
ROAD_STOP_TRACKBIT_FACTOR
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
Definition economy_type.h:243
ROAD_DEPOT_TRACKBIT_FACTOR
static const uint ROAD_DEPOT_TRACKBIT_FACTOR
Multiplier for how many regular track bits a road depot counts.
Definition economy_type.h:241
Expenses
std::array< Money, EXPENSES_END > Expenses
Data type for storage of Money for each ExpensesType category.
Definition economy_type.h:199
ExpensesType
ExpensesType
Types of expenses.
Definition economy_type.h:178
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition economy_type.h:182
EXPENSES_END
@ EXPENSES_END
Number of expense types.
Definition economy_type.h:192
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition economy_type.h:181
EXPENSES_AIRCRAFT_REVENUE
@ EXPENSES_AIRCRAFT_REVENUE
Revenue from aircraft.
Definition economy_type.h:188
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition economy_type.h:179
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition economy_type.h:183
EXPENSES_ROADVEH_REVENUE
@ EXPENSES_ROADVEH_REVENUE
Revenue from road vehicles.
Definition economy_type.h:187
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition economy_type.h:185
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition economy_type.h:191
EXPENSES_SHIP_REVENUE
@ EXPENSES_SHIP_REVENUE
Revenue from ships.
Definition economy_type.h:189
EXPENSES_LOAN_INTEREST
@ EXPENSES_LOAN_INTEREST
Interest payments over the loan.
Definition economy_type.h:190
EXPENSES_TRAIN_REVENUE
@ EXPENSES_TRAIN_REVENUE
Revenue from trains.
Definition economy_type.h:186
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition economy_type.h:184
INVALID_EXPENSES
@ INVALID_EXPENSES
Invalid expense type.
Definition economy_type.h:193
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition economy_type.h:180
Prices
Money Prices[PR_END]
Prices of everything.
Definition economy_type.h:174
PriceCategory
PriceCategory
Categories of a price bases.
Definition economy_type.h:204
PCAT_RUNNING
@ PCAT_RUNNING
Price is affected by "vehicle running cost" difficulty setting.
Definition economy_type.h:206
PCAT_CONSTRUCTION
@ PCAT_CONSTRUCTION
Price is affected by "construction cost" difficulty setting.
Definition economy_type.h:207
PCAT_NONE
@ PCAT_NONE
Not affected by difficulty settings.
Definition economy_type.h:205
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition economy_type.h:211
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition economy_type.h:237
MIN_CARGO_SCALE
static const int MIN_CARGO_SCALE
Minimum allowed value of town_cargo_scale/industry_cargo_scale.
Definition economy_type.h:33
INITIAL_LOAN
static const int64_t INITIAL_LOAN
The size of loan for a new company, in British Pounds!
Definition economy_type.h:213
MAX_INFLATION
static const uint64_t MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64_t price computations...
Definition economy_type.h:225
Price
Price
Enumeration of all base prices for use with Prices.
Definition economy_type.h:95
SCORE_MAX
static constexpr int SCORE_MAX
The max score that can be in the performance history.
Definition economy_type.h:83
MAX_CARGO_SCALE
static const int MAX_CARGO_SCALE
Maximum allowed value of town_cargo_scale/industry_cargo_scale.
Definition economy_type.h:39
DEF_CARGO_SCALE
static const int DEF_CARGO_SCALE
Default value of town_cargo_scale/industry_cargo_scale.
Definition economy_type.h:41
enum_type.hpp
Type (helpers) for enums.
DECLARE_INCREMENT_DECREMENT_OPERATORS
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:63
overflowsafe_type.hpp
An overflow safe integer-like type.
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
CargoPayment
Helper class to perform the cargo payment.
Definition economy_base.h:23
Economy
Data of the economy.
Definition economy_type.h:44
Economy::inflation_payment
uint64_t inflation_payment
Cumulated inflation of cargo payment since game start; 16 bit fractional part.
Definition economy_type.h:53
Economy::infl_amount
uint8_t infl_amount
inflation amount
Definition economy_type.h:48
Economy::inflation_prices
uint64_t inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition economy_type.h:52
Economy::old_max_loan_unround
Money old_max_loan_unround
Old: Unrounded max loan.
Definition economy_type.h:56
Economy::fluct
int16_t fluct
Economy fluctuation status.
Definition economy_type.h:46
Economy::infl_amount_pr
uint8_t infl_amount_pr
inflation rate for payment rates
Definition economy_type.h:49
Economy::industry_daily_change_counter
uint32_t industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
Definition economy_type.h:50
Economy::industry_daily_increment
uint32_t industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
Definition economy_type.h:51
Economy::old_max_loan_unround_fract
uint16_t old_max_loan_unround_fract
Old: Fraction of the unrounded max loan.
Definition economy_type.h:57
Economy::max_loan
Money max_loan
NOSAVE: Maximum possible loan.
Definition economy_type.h:45
Economy::interest_rate
uint8_t interest_rate
Interest.
Definition economy_type.h:47
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
ScoreInfo
Data structure for storing how the score is computed for a single score id.
Definition economy_type.h:86
ScoreInfo::needed
int needed
How much you need to get the perfect score.
Definition economy_type.h:87
ScoreInfo::score
int score
How much score it will give.
Definition economy_type.h:88