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
{
27 /** Data of the economy. */
29 Money max_loan
; ///< NOSAVE: Maximum possible loan
30 int16 fluct
; ///< Economy fluctuation status
31 byte interest_rate
; ///< Interest
32 byte infl_amount
; ///< inflation amount
33 byte infl_amount_pr
; ///< inflation rate for payment rates
34 uint32 industry_daily_change_counter
; ///< Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily
35 uint32 industry_daily_increment
; ///< The value which will increment industry_daily_change_counter. Computed value. NOSAVE
36 uint64 inflation_prices
; ///< Cumulated inflation of prices since game start; 16 bit fractional part
37 uint64 inflation_payment
; ///< Cumulated inflation of cargo payment since game start; 16 bit fractional part
39 /* Old stuff for savegame conversion only */
40 Money old_max_loan_unround
; ///< Old: Unrounded max loan
41 uint16 old_max_loan_unround_fract
; ///< Old: Fraction of the unrounded max loan
44 /** Score categories in the detailed performance rating. */
56 SCORE_TOTAL
= 9, ///< This must always be the last entry
57 SCORE_END
= 10, ///< How many scores are there..
59 SCORE_MAX
= 1000, ///< The max score that can be in the performance history
60 /* the scores together of score_info is allowed to be more! */
62 DECLARE_POSTFIX_INCREMENT(ScoreID
)
64 /** Data structure for storing how the score is computed for a single score id. */
66 int needed
; ///< How much you need to get the perfect score
67 int score
; ///< How much score it will give
71 * Enumeration of all base prices for use with #Prices.
72 * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them.
85 PR_BUILD_STATION_RAIL
,
86 PR_BUILD_STATION_RAIL_LENGTH
,
87 PR_BUILD_STATION_AIRPORT
,
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
,
106 PR_CLEAR_DEPOT_TRAIN
,
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
,
118 PR_RUNNING_TRAIN_STEAM
,
119 PR_RUNNING_TRAIN_DIESEL
,
120 PR_RUNNING_TRAIN_ELECTRIC
,
128 PR_BUILD_WAYPOINT_RAIL
,
129 PR_CLEAR_WAYPOINT_RAIL
,
130 PR_BUILD_WAYPOINT_BUOY
,
131 PR_CLEAR_WAYPOINT_BUOY
,
134 PR_BUILD_INDUSTRY_RAW
,
142 PR_INFRASTRUCTURE_RAIL
,
143 PR_INFRASTRUCTURE_ROAD
,
144 PR_INFRASTRUCTURE_WATER
,
145 PR_INFRASTRUCTURE_STATION
,
146 PR_INFRASTRUCTURE_AIRPORT
,
151 DECLARE_POSTFIX_INCREMENT(Price
)
153 typedef Money Prices
[PR_END
]; ///< Prices of everything. @see Price
154 typedef int8 PriceMultipliers
[PR_END
];
156 /** Types of expenses. */
157 enum ExpensesType
: byte
{
158 EXPENSES_CONSTRUCTION
= 0, ///< Construction costs.
159 EXPENSES_NEW_VEHICLES
, ///< New vehicles.
160 EXPENSES_TRAIN_RUN
, ///< Running costs trains.
161 EXPENSES_ROADVEH_RUN
, ///< Running costs road vehicles.
162 EXPENSES_AIRCRAFT_RUN
, ///< Running costs aircraft.
163 EXPENSES_SHIP_RUN
, ///< Running costs ships.
164 EXPENSES_PROPERTY
, ///< Property costs.
165 EXPENSES_TRAIN_INC
, ///< Income from trains.
166 EXPENSES_ROADVEH_INC
, ///< Income from road vehicles.
167 EXPENSES_AIRCRAFT_INC
, ///< Income from aircraft.
168 EXPENSES_SHIP_INC
, ///< Income from ships.
169 EXPENSES_LOAN_INT
, ///< Interest payments over the loan.
170 EXPENSES_OTHER
, ///< Other expenses.
171 EXPENSES_END
, ///< Number of expense types.
172 INVALID_EXPENSES
= 0xFF, ///< Invalid expense type.
175 /** Define basic enum properties for ExpensesType */
176 template <> struct EnumPropsT
<ExpensesType
> : MakeEnumPropsT
<ExpensesType
, byte
, EXPENSES_CONSTRUCTION
, EXPENSES_END
, INVALID_EXPENSES
, 8> {};
179 * Categories of a price bases.
182 PCAT_NONE
, ///< Not affected by difficulty settings
183 PCAT_RUNNING
, ///< Price is affected by "vehicle running cost" difficulty setting
184 PCAT_CONSTRUCTION
, ///< Price is affected by "construction cost" difficulty setting
188 * Describes properties of price bases.
190 struct PriceBaseSpec
{
191 Money start_price
; ///< Default value at game start, before adding multipliers.
192 PriceCategory category
; ///< Price is affected by certain difficulty settings.
193 uint grf_feature
; ///< GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none.
194 Price fallback_price
; ///< Fallback price multiplier for new prices but old grfs.
197 /** The "steps" in loan size, in British Pounds! */
198 static const int LOAN_INTERVAL
= 10000;
199 /** The size of loan for a new company, in British Pounds! */
200 static const int64 INITIAL_LOAN
= 100000;
203 * Maximum inflation (including fractional part) without causing overflows in int64 price computations.
204 * This allows for 32 bit base prices (21 are currently needed).
205 * Considering the sign bit and 16 fractional bits, there are 15 bits left.
206 * 170 years of 4% inflation result in a inflation of about 822, so 10 bits are actually enough.
207 * Note that NewGRF multipliers share the 16 fractional bits.
208 * @see MAX_PRICE_MODIFIER
210 static const uint64 MAX_INFLATION
= (1ull << (63 - 32)) - 1;
213 * Maximum NewGRF price modifiers.
214 * Increasing base prices by factor 65536 should be enough.
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;
221 /** Multiplier for how many regular track bits a tunnel/bridge counts. */
222 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
= 4;
223 /** Multiplier for how many regular track bits a level crossing counts. */
224 static const uint LEVELCROSSING_TRACKBIT_FACTOR
= 2;
225 /** Multiplier for how many regular track bits a road depot counts. */
226 static const uint ROAD_DEPOT_TRACKBIT_FACTOR
= 2;
227 /** Multiplier for how many regular track bits a bay stop counts. */
228 static const uint ROAD_STOP_TRACKBIT_FACTOR
= 2;
229 /** Multiplier for how many regular tiles a lock counts. */
230 static const uint LOCK_DEPOT_TILE_FACTOR
= 2;
233 typedef uint32 CargoPaymentID
;
235 #endif /* ECONOMY_TYPE_H */