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/>.
8 /** @file economy_type.h Types related to the economy. */
10 #ifndef ECONOMY_TYPE_H
11 #define ECONOMY_TYPE_H
13 #include "core/overflowsafe_type.hpp"
14 #include "core/enum_type.hpp"
16 typedef OverflowSafeInt64 Money
;
18 /** Type of the game economy. */
19 enum EconomyType
: uint8_t {
28 * Minimum allowed value of town_cargo_scale/industry_cargo_scale.
29 * Below 13, callback-based industries would produce less than once per month. We round up to 15% because it's a nicer number.
30 * Towns use the same minimum to match, and because below this small towns often produce no cargo.
32 static const int MIN_CARGO_SCALE
= 15;
34 * Maximum allowed value of town_cargo_scale/industry_cargo_scale.
35 * Above 340, callback-based industries would produce more than once per day, which GRFs do not expect.
36 * Towns use the same maximum to match.
38 static const int MAX_CARGO_SCALE
= 300;
39 /** Default value of town_cargo_scale/industry_cargo_scale. */
40 static const int DEF_CARGO_SCALE
= 100;
42 /** Data of the economy. */
44 Money max_loan
; ///< NOSAVE: Maximum possible loan
45 int16_t fluct
; ///< Economy fluctuation status
46 byte interest_rate
; ///< Interest
47 byte infl_amount
; ///< inflation amount
48 byte infl_amount_pr
; ///< inflation rate for payment rates
49 uint32_t industry_daily_change_counter
; ///< Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily
50 uint32_t industry_daily_increment
; ///< The value which will increment industry_daily_change_counter. Computed value. NOSAVE
51 uint64_t inflation_prices
; ///< Cumulated inflation of prices since game start; 16 bit fractional part
52 uint64_t inflation_payment
; ///< Cumulated inflation of cargo payment since game start; 16 bit fractional part
54 /* Old stuff for savegame conversion only */
55 Money old_max_loan_unround
; ///< Old: Unrounded max loan
56 uint16_t old_max_loan_unround_fract
; ///< Old: Fraction of the unrounded max loan
59 /** Score categories in the detailed performance rating. */
71 SCORE_TOTAL
= 9, ///< This must always be the last entry
72 SCORE_END
= 10, ///< How many scores are there..
74 SCORE_MAX
= 1000, ///< The max score that can be in the performance history
75 /* the scores together of score_info is allowed to be more! */
77 DECLARE_POSTFIX_INCREMENT(ScoreID
)
79 /** Data structure for storing how the score is computed for a single score id. */
81 int needed
; ///< How much you need to get the perfect score
82 int score
; ///< How much score it will give
86 * Enumeration of all base prices for use with #Prices.
87 * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them.
100 PR_BUILD_STATION_RAIL
,
101 PR_BUILD_STATION_RAIL_LENGTH
,
102 PR_BUILD_STATION_AIRPORT
,
103 PR_BUILD_STATION_BUS
,
104 PR_BUILD_STATION_TRUCK
,
105 PR_BUILD_STATION_DOCK
,
106 PR_BUILD_VEHICLE_TRAIN
,
107 PR_BUILD_VEHICLE_WAGON
,
108 PR_BUILD_VEHICLE_AIRCRAFT
,
109 PR_BUILD_VEHICLE_ROAD
,
110 PR_BUILD_VEHICLE_SHIP
,
121 PR_CLEAR_DEPOT_TRAIN
,
126 PR_CLEAR_STATION_RAIL
,
127 PR_CLEAR_STATION_AIRPORT
,
128 PR_CLEAR_STATION_BUS
,
129 PR_CLEAR_STATION_TRUCK
,
130 PR_CLEAR_STATION_DOCK
,
133 PR_RUNNING_TRAIN_STEAM
,
134 PR_RUNNING_TRAIN_DIESEL
,
135 PR_RUNNING_TRAIN_ELECTRIC
,
143 PR_BUILD_WAYPOINT_RAIL
,
144 PR_CLEAR_WAYPOINT_RAIL
,
145 PR_BUILD_WAYPOINT_BUOY
,
146 PR_CLEAR_WAYPOINT_BUOY
,
149 PR_BUILD_INDUSTRY_RAW
,
157 PR_INFRASTRUCTURE_RAIL
,
158 PR_INFRASTRUCTURE_ROAD
,
159 PR_INFRASTRUCTURE_WATER
,
160 PR_INFRASTRUCTURE_STATION
,
161 PR_INFRASTRUCTURE_AIRPORT
,
166 DECLARE_POSTFIX_INCREMENT(Price
)
168 typedef Money Prices
[PR_END
]; ///< Prices of everything. @see Price
169 typedef int8_t PriceMultipliers
[PR_END
];
171 /** Types of expenses. */
172 enum ExpensesType
: byte
{
173 EXPENSES_CONSTRUCTION
= 0, ///< Construction costs.
174 EXPENSES_NEW_VEHICLES
, ///< New vehicles.
175 EXPENSES_TRAIN_RUN
, ///< Running costs trains.
176 EXPENSES_ROADVEH_RUN
, ///< Running costs road vehicles.
177 EXPENSES_AIRCRAFT_RUN
, ///< Running costs aircraft.
178 EXPENSES_SHIP_RUN
, ///< Running costs ships.
179 EXPENSES_PROPERTY
, ///< Property costs.
180 EXPENSES_TRAIN_REVENUE
, ///< Revenue from trains.
181 EXPENSES_ROADVEH_REVENUE
, ///< Revenue from road vehicles.
182 EXPENSES_AIRCRAFT_REVENUE
, ///< Revenue from aircraft.
183 EXPENSES_SHIP_REVENUE
, ///< Revenue from ships.
184 EXPENSES_LOAN_INTEREST
, ///< Interest payments over the loan.
185 EXPENSES_OTHER
, ///< Other expenses.
186 EXPENSES_END
, ///< Number of expense types.
187 INVALID_EXPENSES
= 0xFF, ///< Invalid expense type.
191 * Data type for storage of Money for each #ExpensesType category.
193 using Expenses
= std::array
<Money
, EXPENSES_END
>;
196 * Categories of a price bases.
199 PCAT_NONE
, ///< Not affected by difficulty settings
200 PCAT_RUNNING
, ///< Price is affected by "vehicle running cost" difficulty setting
201 PCAT_CONSTRUCTION
, ///< Price is affected by "construction cost" difficulty setting
205 * Describes properties of price bases.
207 struct PriceBaseSpec
{
208 Money start_price
; ///< Default value at game start, before adding multipliers.
209 PriceCategory category
; ///< Price is affected by certain difficulty settings.
210 uint grf_feature
; ///< GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none.
211 Price fallback_price
; ///< Fallback price multiplier for new prices but old grfs.
214 /** The "steps" in loan size, in British Pounds! */
215 static const int LOAN_INTERVAL
= 10000;
216 /** The size of loan for a new company, in British Pounds! */
217 static const int64_t INITIAL_LOAN
= 100000;
218 /** The max amount possible to configure for a max loan of a company. */
219 static const int64_t MAX_LOAN_LIMIT
= 2000000000;
222 * Maximum inflation (including fractional part) without causing overflows in int64_t price computations.
223 * This allows for 32 bit base prices (21 are currently needed).
224 * Considering the sign bit and 16 fractional bits, there are 15 bits left.
225 * 170 years of 4% inflation result in a inflation of about 822, so 10 bits are actually enough.
226 * Note that NewGRF multipliers share the 16 fractional bits.
227 * @see MAX_PRICE_MODIFIER
229 static const uint64_t MAX_INFLATION
= (1ull << (63 - 32)) - 1;
232 * Maximum NewGRF price modifiers.
233 * Increasing base prices by factor 65536 should be enough.
236 static const int MIN_PRICE_MODIFIER
= -8;
237 static const int MAX_PRICE_MODIFIER
= 16;
238 static const int INVALID_PRICE_MODIFIER
= MIN_PRICE_MODIFIER
- 1;
240 /** Multiplier for how many regular track bits a tunnel/bridge counts. */
241 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
= 4;
242 /** Multiplier for how many regular track bits a level crossing counts. */
243 static const uint LEVELCROSSING_TRACKBIT_FACTOR
= 2;
244 /** Multiplier for how many regular track bits a road depot counts. */
245 static const uint ROAD_DEPOT_TRACKBIT_FACTOR
= 2;
246 /** Multiplier for how many regular track bits a bay stop counts. */
247 static const uint ROAD_STOP_TRACKBIT_FACTOR
= 2;
248 /** Multiplier for how many regular tiles a lock counts. */
249 static const uint LOCK_DEPOT_TILE_FACTOR
= 2;
252 typedef uint32_t CargoPaymentID
;
254 #endif /* ECONOMY_TYPE_H */