Chunnel: Adjust z position of vehicles in chunnels to go "under" the water.
[openttd-joker.git] / src / economy_type.h
blob9fac6d44f9cdd6b4586c6e1aff63285a97778278
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
10 /** @file economy_type.h Types related to the economy. */
12 #ifndef ECONOMY_TYPE_H
13 #define ECONOMY_TYPE_H
15 #include "core/overflowsafe_type.hpp"
16 #include "core/enum_type.hpp"
18 typedef OverflowSafeInt64 Money;
20 /** Data of the economy. */
21 struct Economy {
22 Money max_loan; ///< NOSAVE: Maximum possible loan
23 int16 fluct; ///< Economy fluctuation status
24 byte interest_rate; ///< Interest
25 byte infl_amount; ///< inflation amount
26 byte infl_amount_pr; ///< inflation rate for payment rates
27 uint32 industry_daily_change_counter; ///< Bits 31-16 are number of industry to be performed, 15-0 are fractional collected daily
28 uint32 industry_daily_increment; ///< The value which will increment industry_daily_change_counter. Computed value. NOSAVE
29 uint64 inflation_prices; ///< Cumulated inflation of prices since game start; 16 bit fractional part
30 uint64 inflation_payment; ///< Cumulated inflation of cargo paypent since game start; 16 bit fractional part
31 Money industry_helper;
33 /* Old stuff for savegame conversion only */
34 Money old_max_loan_unround; ///< Old: Unrounded max loan
35 uint16 old_max_loan_unround_fract; ///< Old: Fraction of the unrounded max loan
38 /** Score categories in the detailed performance rating. */
39 enum ScoreID {
40 SCORE_BEGIN = 0,
41 SCORE_VEHICLES = 0,
42 SCORE_STATIONS = 1,
43 SCORE_MIN_PROFIT = 2,
44 SCORE_MIN_INCOME = 3,
45 SCORE_MAX_INCOME = 4,
46 SCORE_DELIVERED = 5,
47 SCORE_CARGO = 6,
48 SCORE_MONEY = 7,
49 SCORE_LOAN = 8,
50 SCORE_TOTAL = 9, ///< This must always be the last entry
51 SCORE_END = 10, ///< How many scores are there..
53 SCORE_MAX = 1000, ///< The max score that can be in the performance history
54 /* the scores together of score_info is allowed to be more! */
56 DECLARE_POSTFIX_INCREMENT(ScoreID)
58 /** Data structure for storing how the score is computed for a single score id. */
59 struct ScoreInfo {
60 int needed; ///< How much you need to get the perfect score
61 int score; ///< How much score it will give
64 /**
65 * Enumeration of all base prices for use with #Prices.
66 * The prices are ordered as they are expected by NewGRF cost multipliers, so don't shuffle them.
68 enum Price {
69 PR_BEGIN = 0,
70 PR_STATION_VALUE = 0,
71 PR_BUILD_RAIL,
72 PR_BUILD_ROAD,
73 PR_BUILD_SIGNALS,
74 PR_BUILD_BRIDGE,
75 PR_BUILD_DEPOT_TRAIN,
76 PR_BUILD_DEPOT_ROAD,
77 PR_BUILD_DEPOT_SHIP,
78 PR_BUILD_TUNNEL,
79 PR_BUILD_STATION_RAIL,
80 PR_BUILD_STATION_RAIL_LENGTH,
81 PR_BUILD_STATION_AIRPORT,
82 PR_BUILD_STATION_BUS,
83 PR_BUILD_STATION_TRUCK,
84 PR_BUILD_STATION_DOCK,
85 PR_BUILD_VEHICLE_TRAIN,
86 PR_BUILD_VEHICLE_WAGON,
87 PR_BUILD_VEHICLE_AIRCRAFT,
88 PR_BUILD_VEHICLE_ROAD,
89 PR_BUILD_VEHICLE_SHIP,
90 PR_BUILD_TREES,
91 PR_TERRAFORM,
92 PR_CLEAR_GRASS,
93 PR_CLEAR_ROUGH,
94 PR_CLEAR_ROCKS,
95 PR_CLEAR_FIELDS,
96 PR_CLEAR_TREES,
97 PR_CLEAR_RAIL,
98 PR_CLEAR_SIGNALS,
99 PR_CLEAR_BRIDGE,
100 PR_CLEAR_DEPOT_TRAIN,
101 PR_CLEAR_DEPOT_ROAD,
102 PR_CLEAR_DEPOT_SHIP,
103 PR_CLEAR_TUNNEL,
104 PR_CLEAR_WATER,
105 PR_CLEAR_STATION_RAIL,
106 PR_CLEAR_STATION_AIRPORT,
107 PR_CLEAR_STATION_BUS,
108 PR_CLEAR_STATION_TRUCK,
109 PR_CLEAR_STATION_DOCK,
110 PR_CLEAR_HOUSE,
111 PR_CLEAR_ROAD,
112 PR_RUNNING_TRAIN_STEAM,
113 PR_RUNNING_TRAIN_DIESEL,
114 PR_RUNNING_TRAIN_ELECTRIC,
115 PR_RUNNING_AIRCRAFT,
116 PR_RUNNING_ROADVEH,
117 PR_RUNNING_SHIP,
118 PR_BUILD_INDUSTRY,
119 PR_CLEAR_INDUSTRY,
120 PR_BUILD_OBJECT,
121 PR_CLEAR_OBJECT,
122 PR_BUILD_WAYPOINT_RAIL,
123 PR_CLEAR_WAYPOINT_RAIL,
124 PR_BUILD_WAYPOINT_BUOY,
125 PR_CLEAR_WAYPOINT_BUOY,
126 PR_TOWN_ACTION,
127 PR_BUILD_FOUNDATION,
128 PR_BUILD_INDUSTRY_RAW,
129 PR_BUILD_TOWN,
130 PR_BUILD_CANAL,
131 PR_CLEAR_CANAL,
132 PR_BUILD_AQUEDUCT,
133 PR_CLEAR_AQUEDUCT,
134 PR_BUILD_LOCK,
135 PR_CLEAR_LOCK,
136 PR_INFRASTRUCTURE_RAIL,
137 PR_INFRASTRUCTURE_ROAD,
138 PR_INFRASTRUCTURE_WATER,
139 PR_INFRASTRUCTURE_STATION,
140 PR_INFRASTRUCTURE_AIRPORT,
142 PR_END,
143 INVALID_PRICE = 0xFF
145 DECLARE_POSTFIX_INCREMENT(Price)
147 typedef Money Prices[PR_END]; ///< Prices of everything. @see Price
148 typedef int8 PriceMultipliers[PR_END];
150 /** Types of expenses. */
151 enum ExpensesType {
152 EXPENSES_CONSTRUCTION = 0, ///< Construction costs.
153 EXPENSES_NEW_VEHICLES, ///< New vehicles.
154 EXPENSES_TRAIN_RUN, ///< Running costs trains.
155 EXPENSES_ROADVEH_RUN, ///< Running costs road vehicles.
156 EXPENSES_AIRCRAFT_RUN, ///< Running costs aircrafts.
157 EXPENSES_SHIP_RUN, ///< Running costs ships.
158 EXPENSES_PROPERTY, ///< Property costs.
159 EXPENSES_TRAIN_INC, ///< Income from trains.
160 EXPENSES_ROADVEH_INC, ///< Income from road vehicles.
161 EXPENSES_AIRCRAFT_INC, ///< Income from aircrafts.
162 EXPENSES_SHIP_INC, ///< Income from ships.
163 EXPENSES_LOAN_INT, ///< Interest payments over the loan.
164 EXPENSES_OTHER, ///< Other expenses.
165 EXPENSES_END, ///< Number of expense types.
166 INVALID_EXPENSES = 0xFF, ///< Invalid expense type.
169 /** Define basic enum properties for ExpensesType */
170 template <> struct EnumPropsT<ExpensesType> : MakeEnumPropsT<ExpensesType, byte, EXPENSES_CONSTRUCTION, EXPENSES_END, INVALID_EXPENSES, 8> {};
171 typedef TinyEnumT<ExpensesType> ExpensesTypeByte; ///< typedefing-enumification of ExpensesType
174 * Categories of a price bases.
176 enum PriceCategory {
177 PCAT_NONE, ///< Not affected by difficulty settings
178 PCAT_RUNNING, ///< Price is affected by "vehicle running cost" difficulty setting
179 PCAT_CONSTRUCTION, ///< Price is affected by "construction cost" difficulty setting
183 * Describes properties of price bases.
185 struct PriceBaseSpec {
186 Money start_price; ///< Default value at game start, before adding multipliers.
187 PriceCategory category; ///< Price is affected by certain difficulty settings.
188 uint grf_feature; ///< GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none.
189 Price fallback_price; ///< Fallback price multiplier for new prices but old grfs.
192 /** The "steps" in loan size, in British Pounds! */
193 static const int LOAN_INTERVAL = 10000;
196 * Maximum inflation (including fractional part) without causing overflows in int64 price computations.
197 * This allows for 32 bit base prices (21 are currently needed).
198 * Considering the sign bit and 16 fractional bits, there are 15 bits left.
199 * 170 years of 4% inflation result in a inflation of about 822, so 10 bits are actually enough.
200 * Note that NewGRF multipliers share the 16 fractional bits.
201 * @see MAX_PRICE_MODIFIER
203 static const uint64 MAX_INFLATION = (1ull << (63 - 32)) - 1;
206 * Maximum NewGRF price modifiers.
207 * Increasing base prices by factor 65536 should be enough.
208 * @see MAX_INFLATION
210 static const int MIN_PRICE_MODIFIER = -8;
211 static const int MAX_PRICE_MODIFIER = 16;
212 static const int INVALID_PRICE_MODIFIER = MIN_PRICE_MODIFIER - 1;
214 /** Multiplier for how many regular track bits a tunnel/bridge counts. */
215 static const uint TUNNELBRIDGE_TRACKBIT_FACTOR = 4;
216 /** Multiplier for how many regular track bits a level crossing counts. */
217 static const uint LEVELCROSSING_TRACKBIT_FACTOR = 2;
218 /** Multiplier for how many regular tiles a lock counts. */
219 static const uint LOCK_DEPOT_TILE_FACTOR = 2;
221 struct CargoPayment;
222 typedef uint32 CargoPaymentID;
224 #endif /* ECONOMY_TYPE_H */