OpenTTD Source  12.0-beta2
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 
16 typedef OverflowSafeInt64 Money;
17 
19 enum EconomyType : uint8 {
20  ET_BEGIN = 0,
21  ET_ORIGINAL = 0,
22  ET_SMOOTH = 1,
23  ET_FROZEN = 2,
24  ET_END = 3,
25 };
26 
28 struct Economy {
30  int16 fluct;
32  byte infl_amount;
38 
39  /* Old stuff for savegame conversion only */
42 };
43 
45 enum ScoreID {
46  SCORE_BEGIN = 0,
47  SCORE_VEHICLES = 0,
48  SCORE_STATIONS = 1,
49  SCORE_MIN_PROFIT = 2,
50  SCORE_MIN_INCOME = 3,
51  SCORE_MAX_INCOME = 4,
52  SCORE_DELIVERED = 5,
53  SCORE_CARGO = 6,
54  SCORE_MONEY = 7,
55  SCORE_LOAN = 8,
57  SCORE_END = 10,
58 
59  SCORE_MAX = 1000,
60  /* the scores together of score_info is allowed to be more! */
61 };
63 
64 
65 struct ScoreInfo {
66  int needed;
67  int score;
68 };
69 
74 enum Price {
75  PR_BEGIN = 0,
76  PR_STATION_VALUE = 0,
77  PR_BUILD_RAIL,
78  PR_BUILD_ROAD,
79  PR_BUILD_SIGNALS,
80  PR_BUILD_BRIDGE,
81  PR_BUILD_DEPOT_TRAIN,
82  PR_BUILD_DEPOT_ROAD,
83  PR_BUILD_DEPOT_SHIP,
84  PR_BUILD_TUNNEL,
85  PR_BUILD_STATION_RAIL,
86  PR_BUILD_STATION_RAIL_LENGTH,
87  PR_BUILD_STATION_AIRPORT,
88  PR_BUILD_STATION_BUS,
89  PR_BUILD_STATION_TRUCK,
90  PR_BUILD_STATION_DOCK,
91  PR_BUILD_VEHICLE_TRAIN,
92  PR_BUILD_VEHICLE_WAGON,
93  PR_BUILD_VEHICLE_AIRCRAFT,
94  PR_BUILD_VEHICLE_ROAD,
95  PR_BUILD_VEHICLE_SHIP,
96  PR_BUILD_TREES,
97  PR_TERRAFORM,
98  PR_CLEAR_GRASS,
99  PR_CLEAR_ROUGH,
100  PR_CLEAR_ROCKS,
101  PR_CLEAR_FIELDS,
102  PR_CLEAR_TREES,
103  PR_CLEAR_RAIL,
104  PR_CLEAR_SIGNALS,
105  PR_CLEAR_BRIDGE,
106  PR_CLEAR_DEPOT_TRAIN,
107  PR_CLEAR_DEPOT_ROAD,
108  PR_CLEAR_DEPOT_SHIP,
109  PR_CLEAR_TUNNEL,
110  PR_CLEAR_WATER,
111  PR_CLEAR_STATION_RAIL,
112  PR_CLEAR_STATION_AIRPORT,
113  PR_CLEAR_STATION_BUS,
114  PR_CLEAR_STATION_TRUCK,
115  PR_CLEAR_STATION_DOCK,
116  PR_CLEAR_HOUSE,
117  PR_CLEAR_ROAD,
118  PR_RUNNING_TRAIN_STEAM,
119  PR_RUNNING_TRAIN_DIESEL,
120  PR_RUNNING_TRAIN_ELECTRIC,
121  PR_RUNNING_AIRCRAFT,
122  PR_RUNNING_ROADVEH,
123  PR_RUNNING_SHIP,
124  PR_BUILD_INDUSTRY,
125  PR_CLEAR_INDUSTRY,
126  PR_BUILD_OBJECT,
127  PR_CLEAR_OBJECT,
128  PR_BUILD_WAYPOINT_RAIL,
129  PR_CLEAR_WAYPOINT_RAIL,
130  PR_BUILD_WAYPOINT_BUOY,
131  PR_CLEAR_WAYPOINT_BUOY,
132  PR_TOWN_ACTION,
133  PR_BUILD_FOUNDATION,
134  PR_BUILD_INDUSTRY_RAW,
135  PR_BUILD_TOWN,
136  PR_BUILD_CANAL,
137  PR_CLEAR_CANAL,
138  PR_BUILD_AQUEDUCT,
139  PR_CLEAR_AQUEDUCT,
140  PR_BUILD_LOCK,
141  PR_CLEAR_LOCK,
142  PR_INFRASTRUCTURE_RAIL,
143  PR_INFRASTRUCTURE_ROAD,
144  PR_INFRASTRUCTURE_WATER,
145  PR_INFRASTRUCTURE_STATION,
146  PR_INFRASTRUCTURE_AIRPORT,
147 
148  PR_END,
149  INVALID_PRICE = 0xFF
150 };
152 
153 typedef Money Prices[PR_END];
154 typedef int8 PriceMultipliers[PR_END];
155 
157 enum ExpensesType : byte {
173 };
174 
176 template <> struct EnumPropsT<ExpensesType> : MakeEnumPropsT<ExpensesType, byte, EXPENSES_CONSTRUCTION, EXPENSES_END, INVALID_EXPENSES, 8> {};
177 
185 };
186 
193  uint grf_feature;
195 };
196 
198 static const int LOAN_INTERVAL = 10000;
200 static const int64 INITIAL_LOAN = 100000;
201 
210 static const uint64 MAX_INFLATION = (1ull << (63 - 32)) - 1;
211 
217 static const int MIN_PRICE_MODIFIER = -8;
218 static const int MAX_PRICE_MODIFIER = 16;
219 static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1;
220 
222 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4;
224 static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2;
226 static const uint ROAD_DEPOT_TRACKBIT_FACTOR = 2;
228 static const uint ROAD_STOP_TRACKBIT_FACTOR = 2;
230 static const uint LOCK_DEPOT_TILE_FACTOR = 2;
231 
232 struct CargoPayment;
233 typedef uint32 CargoPaymentID;
234 
235 #endif /* ECONOMY_TYPE_H */
Economy::inflation_prices
uint64 inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition: economy_type.h:36
PriceBaseSpec::category
PriceCategory category
Price is affected by certain difficulty settings.
Definition: economy_type.h:192
EXPENSES_ROADVEH_RUN
@ EXPENSES_ROADVEH_RUN
Running costs road vehicles.
Definition: economy_type.h:161
INVALID_EXPENSES
@ INVALID_EXPENSES
Invalid expense type.
Definition: economy_type.h:172
EXPENSES_END
@ EXPENSES_END
Number of expense types.
Definition: economy_type.h:171
Economy::inflation_payment
uint64 inflation_payment
Cumulated inflation of cargo payment since game start; 16 bit fractional part.
Definition: economy_type.h:37
SCORE_TOTAL
@ SCORE_TOTAL
This must always be the last entry.
Definition: economy_type.h:56
EXPENSES_OTHER
@ EXPENSES_OTHER
Other expenses.
Definition: economy_type.h:170
LOAN_INTERVAL
static const int LOAN_INTERVAL
The "steps" in loan size, in British Pounds!
Definition: economy_type.h:198
Economy::interest_rate
byte interest_rate
Interest.
Definition: economy_type.h:31
Economy::industry_daily_change_counter
uint32 industry_daily_change_counter
Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily.
Definition: economy_type.h:34
LEVELCROSSING_TRACKBIT_FACTOR
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition: economy_type.h:224
Price
Price
Enumeration of all base prices for use with Prices.
Definition: economy_type.h:74
INITIAL_LOAN
static const int64 INITIAL_LOAN
The size of loan for a new company, in British Pounds!
Definition: economy_type.h:200
PriceBaseSpec::grf_feature
uint grf_feature
GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none.
Definition: economy_type.h:193
overflowsafe_type.hpp
EXPENSES_AIRCRAFT_RUN
@ EXPENSES_AIRCRAFT_RUN
Running costs aircraft.
Definition: economy_type.h:162
Economy::max_loan
Money max_loan
NOSAVE: Maximum possible loan.
Definition: economy_type.h:29
MIN_PRICE_MODIFIER
static const int MIN_PRICE_MODIFIER
Maximum NewGRF price modifiers.
Definition: economy_type.h:217
PCAT_NONE
@ PCAT_NONE
Not affected by difficulty settings.
Definition: economy_type.h:182
ScoreInfo::score
int score
How much score it will give.
Definition: economy_type.h:67
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
Economy::industry_daily_increment
uint32 industry_daily_increment
The value which will increment industry_daily_change_counter. Computed value. NOSAVE.
Definition: economy_type.h:35
Economy::fluct
int16 fluct
Economy fluctuation status.
Definition: economy_type.h:30
Economy::infl_amount_pr
byte infl_amount_pr
inflation rate for payment rates
Definition: economy_type.h:33
EnumPropsT
Informative template class exposing basic enumeration properties used by several other templates belo...
Definition: enum_type.hpp:48
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
SCORE_END
@ SCORE_END
How many scores are there..
Definition: economy_type.h:57
CargoPayment
Helper class to perform the cargo payment.
Definition: economy_base.h:24
EXPENSES_SHIP_INC
@ EXPENSES_SHIP_INC
Income from ships.
Definition: economy_type.h:168
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition: economy_type.h:222
PriceBaseSpec::fallback_price
Price fallback_price
Fallback price multiplier for new prices but old grfs.
Definition: economy_type.h:194
PCAT_CONSTRUCTION
@ PCAT_CONSTRUCTION
Price is affected by "construction cost" difficulty setting.
Definition: economy_type.h:184
EXPENSES_AIRCRAFT_INC
@ EXPENSES_AIRCRAFT_INC
Income from aircraft.
Definition: economy_type.h:167
EXPENSES_LOAN_INT
@ EXPENSES_LOAN_INT
Interest payments over the loan.
Definition: economy_type.h:169
PriceBaseSpec::start_price
Money start_price
Default value at game start, before adding multipliers.
Definition: economy_type.h:191
SCORE_MAX
@ SCORE_MAX
The max score that can be in the performance history.
Definition: economy_type.h:59
PriceBaseSpec
Describes properties of price bases.
Definition: economy_type.h:190
EconomyType
EconomyType
Type of the game economy.
Definition: economy_type.h:19
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:226
MAX_INFLATION
static const uint64 MAX_INFLATION
Maximum inflation (including fractional part) without causing overflows in int64 price computations.
Definition: economy_type.h:210
PCAT_RUNNING
@ PCAT_RUNNING
Price is affected by "vehicle running cost" difficulty setting.
Definition: economy_type.h:183
Economy::infl_amount
byte infl_amount
inflation amount
Definition: economy_type.h:32
ScoreInfo::needed
int needed
How much you need to get the perfect score.
Definition: economy_type.h:66
Economy
Data of the economy.
Definition: economy_type.h:28
Economy::old_max_loan_unround
Money old_max_loan_unround
Old: Unrounded max loan.
Definition: economy_type.h:40
EXPENSES_PROPERTY
@ EXPENSES_PROPERTY
Property costs.
Definition: economy_type.h:164
enum_type.hpp
EXPENSES_NEW_VEHICLES
@ EXPENSES_NEW_VEHICLES
New vehicles.
Definition: economy_type.h:159
MakeEnumPropsT
Helper template class that makes basic properties of given enumeration type visible from outsize.
Definition: enum_type.hpp:62
LOCK_DEPOT_TILE_FACTOR
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition: economy_type.h:230
ScoreID
ScoreID
Score categories in the detailed performance rating.
Definition: economy_type.h:45
EXPENSES_TRAIN_RUN
@ EXPENSES_TRAIN_RUN
Running costs trains.
Definition: economy_type.h:160
OverflowSafeInt< int64 >
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:228
PriceCategory
PriceCategory
Categories of a price bases.
Definition: economy_type.h:181
ExpensesType
ExpensesType
Types of expenses.
Definition: economy_type.h:157
Economy::old_max_loan_unround_fract
uint16 old_max_loan_unround_fract
Old: Fraction of the unrounded max loan.
Definition: economy_type.h:41
EXPENSES_ROADVEH_INC
@ EXPENSES_ROADVEH_INC
Income from road vehicles.
Definition: economy_type.h:166
EXPENSES_SHIP_RUN
@ EXPENSES_SHIP_RUN
Running costs ships.
Definition: economy_type.h:163
EXPENSES_TRAIN_INC
@ EXPENSES_TRAIN_INC
Income from trains.
Definition: economy_type.h:165
Prices
Money Prices[PR_END]
Prices of everything.
Definition: economy_type.h:153
ScoreInfo
Data structure for storing how the score is computed for a single score id.
Definition: economy_type.h:65