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 /** Data of the economy. */
20 Money max_loan
; ///< NOSAVE: Maximum possible loan
21 int16 fluct
; ///< Economy fluctuation status
22 byte interest_rate
; ///< Interest
23 byte infl_amount
; ///< inflation amount
24 byte infl_amount_pr
; ///< inflation rate for payment rates
25 uint32 industry_daily_change_counter
; ///< Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily
26 uint32 industry_daily_increment
; ///< The value which will increment industry_daily_change_counter. Computed value. NOSAVE
27 uint64 inflation_prices
; ///< Cumulated inflation of prices since game start; 16 bit fractional part
28 uint64 inflation_payment
; ///< Cumulated inflation of cargo paypent since game start; 16 bit fractional part
30 /* Old stuff for savegame conversion only */
31 Money old_max_loan_unround
; ///< Old: Unrounded max loan
32 uint16 old_max_loan_unround_fract
; ///< Old: Fraction of the unrounded max loan
35 /** Score categories in the detailed performance rating. */
47 SCORE_TOTAL
= 9, ///< This must always be the last entry
48 SCORE_END
= 10, ///< How many scores are there..
50 SCORE_MAX
= 1000, ///< The max score that can be in the performance history
51 /* the scores together of score_info is allowed to be more! */
53 DECLARE_POSTFIX_INCREMENT(ScoreID
)
55 /** Data structure for storing how the score is computed for a single score id. */
57 int needed
; ///< How much you need to get the perfect score
58 int score
; ///< How much score it will give
62 * Enumeration of all base prices for use with #Prices.
63 * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them.
76 PR_BUILD_STATION_RAIL
,
77 PR_BUILD_STATION_RAIL_LENGTH
,
78 PR_BUILD_STATION_AIRPORT
,
80 PR_BUILD_STATION_TRUCK
,
81 PR_BUILD_STATION_DOCK
,
82 PR_BUILD_VEHICLE_TRAIN
,
83 PR_BUILD_VEHICLE_WAGON
,
84 PR_BUILD_VEHICLE_AIRCRAFT
,
85 PR_BUILD_VEHICLE_ROAD
,
86 PR_BUILD_VEHICLE_SHIP
,
102 PR_CLEAR_STATION_RAIL
,
103 PR_CLEAR_STATION_AIRPORT
,
104 PR_CLEAR_STATION_BUS
,
105 PR_CLEAR_STATION_TRUCK
,
106 PR_CLEAR_STATION_DOCK
,
109 PR_RUNNING_TRAIN_STEAM
,
110 PR_RUNNING_TRAIN_DIESEL
,
111 PR_RUNNING_TRAIN_ELECTRIC
,
119 PR_BUILD_WAYPOINT_RAIL
,
120 PR_CLEAR_WAYPOINT_RAIL
,
121 PR_BUILD_WAYPOINT_BUOY
,
122 PR_CLEAR_WAYPOINT_BUOY
,
125 PR_BUILD_INDUSTRY_RAW
,
133 PR_INFRASTRUCTURE_RAIL
,
134 PR_INFRASTRUCTURE_ROAD
,
135 PR_INFRASTRUCTURE_WATER
,
136 PR_INFRASTRUCTURE_STATION
,
137 PR_INFRASTRUCTURE_AIRPORT
,
142 DECLARE_POSTFIX_INCREMENT(Price
)
144 typedef Money Prices
[PR_END
]; ///< Prices of everything. @see Price
145 typedef int8 PriceMultipliers
[PR_END
];
147 /** Types of expenses. */
148 enum ExpensesType
: byte
{
149 EXPENSES_CONSTRUCTION
= 0, ///< Construction costs.
150 EXPENSES_NEW_VEHICLES
, ///< New vehicles.
151 EXPENSES_TRAIN_RUN
, ///< Running costs trains.
152 EXPENSES_ROADVEH_RUN
, ///< Running costs road vehicles.
153 EXPENSES_AIRCRAFT_RUN
, ///< Running costs aircraft.
154 EXPENSES_SHIP_RUN
, ///< Running costs ships.
155 EXPENSES_PROPERTY
, ///< Property costs.
156 EXPENSES_TRAIN_INC
, ///< Income from trains.
157 EXPENSES_ROADVEH_INC
, ///< Income from road vehicles.
158 EXPENSES_AIRCRAFT_INC
, ///< Income from aircraft.
159 EXPENSES_SHIP_INC
, ///< Income from ships.
160 EXPENSES_LOAN_INT
, ///< Interest payments over the loan.
161 EXPENSES_OTHER
, ///< Other expenses.
162 EXPENSES_END
, ///< Number of expense types.
163 INVALID_EXPENSES
= 0xFF, ///< Invalid expense type.
166 /** Define basic enum properties for ExpensesType */
167 template <> struct EnumPropsT
<ExpensesType
> : MakeEnumPropsT
<ExpensesType
, byte
, EXPENSES_CONSTRUCTION
, EXPENSES_END
, INVALID_EXPENSES
, 8> {};
170 * Categories of a price bases.
173 PCAT_NONE
, ///< Not affected by difficulty settings
174 PCAT_RUNNING
, ///< Price is affected by "vehicle running cost" difficulty setting
175 PCAT_CONSTRUCTION
, ///< Price is affected by "construction cost" difficulty setting
179 * Describes properties of price bases.
181 struct PriceBaseSpec
{
182 Money start_price
; ///< Default value at game start, before adding multipliers.
183 PriceCategory category
; ///< Price is affected by certain difficulty settings.
184 uint grf_feature
; ///< GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none.
185 Price fallback_price
; ///< Fallback price multiplier for new prices but old grfs.
188 /** The "steps" in loan size, in British Pounds! */
189 static const int LOAN_INTERVAL
= 10000;
192 * Maximum inflation (including fractional part) without causing overflows in int64 price computations.
193 * This allows for 32 bit base prices (21 are currently needed).
194 * Considering the sign bit and 16 fractional bits, there are 15 bits left.
195 * 170 years of 4% inflation result in a inflation of about 822, so 10 bits are actually enough.
196 * Note that NewGRF multipliers share the 16 fractional bits.
197 * @see MAX_PRICE_MODIFIER
199 static const uint64 MAX_INFLATION
= (1ull << (63 - 32)) - 1;
202 * Maximum NewGRF price modifiers.
203 * Increasing base prices by factor 65536 should be enough.
206 static const int MIN_PRICE_MODIFIER
= -8;
207 static const int MAX_PRICE_MODIFIER
= 16;
208 static const int INVALID_PRICE_MODIFIER
= MIN_PRICE_MODIFIER
- 1;
210 /** Multiplier for how many regular track bits a tunnel/bridge counts. */
211 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
= 4;
212 /** Multiplier for how many regular track bits a level crossing counts. */
213 static const uint LEVELCROSSING_TRACKBIT_FACTOR
= 2;
214 /** Multiplier for how many regular tiles a lock counts. */
215 static const uint LOCK_DEPOT_TILE_FACTOR
= 2;
218 typedef uint32 CargoPaymentID
;
220 #endif /* ECONOMY_TYPE_H */