Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / economy_type.h
blob26474b7b9d872676c370b088a3cf5c3ba1f2d758
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 */
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 {
20 ET_BEGIN = 0,
21 ET_ORIGINAL = 0,
22 ET_SMOOTH = 1,
23 ET_FROZEN = 2,
24 ET_END = 3,
27 /**
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;
33 /**
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. */
43 struct 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. */
60 enum ScoreID {
61 SCORE_BEGIN = 0,
62 SCORE_VEHICLES = 0,
63 SCORE_STATIONS = 1,
64 SCORE_MIN_PROFIT = 2,
65 SCORE_MIN_INCOME = 3,
66 SCORE_MAX_INCOME = 4,
67 SCORE_DELIVERED = 5,
68 SCORE_CARGO = 6,
69 SCORE_MONEY = 7,
70 SCORE_LOAN = 8,
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. */
80 struct ScoreInfo {
81 int needed; ///< How much you need to get the perfect score
82 int score; ///< How much score it will give
85 /**
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.
89 enum Price {
90 PR_BEGIN = 0,
91 PR_STATION_VALUE = 0,
92 PR_BUILD_RAIL,
93 PR_BUILD_ROAD,
94 PR_BUILD_SIGNALS,
95 PR_BUILD_BRIDGE,
96 PR_BUILD_DEPOT_TRAIN,
97 PR_BUILD_DEPOT_ROAD,
98 PR_BUILD_DEPOT_SHIP,
99 PR_BUILD_TUNNEL,
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,
111 PR_BUILD_TREES,
112 PR_TERRAFORM,
113 PR_CLEAR_GRASS,
114 PR_CLEAR_ROUGH,
115 PR_CLEAR_ROCKS,
116 PR_CLEAR_FIELDS,
117 PR_CLEAR_TREES,
118 PR_CLEAR_RAIL,
119 PR_CLEAR_SIGNALS,
120 PR_CLEAR_BRIDGE,
121 PR_CLEAR_DEPOT_TRAIN,
122 PR_CLEAR_DEPOT_ROAD,
123 PR_CLEAR_DEPOT_SHIP,
124 PR_CLEAR_TUNNEL,
125 PR_CLEAR_WATER,
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,
131 PR_CLEAR_HOUSE,
132 PR_CLEAR_ROAD,
133 PR_RUNNING_TRAIN_STEAM,
134 PR_RUNNING_TRAIN_DIESEL,
135 PR_RUNNING_TRAIN_ELECTRIC,
136 PR_RUNNING_AIRCRAFT,
137 PR_RUNNING_ROADVEH,
138 PR_RUNNING_SHIP,
139 PR_BUILD_INDUSTRY,
140 PR_CLEAR_INDUSTRY,
141 PR_BUILD_OBJECT,
142 PR_CLEAR_OBJECT,
143 PR_BUILD_WAYPOINT_RAIL,
144 PR_CLEAR_WAYPOINT_RAIL,
145 PR_BUILD_WAYPOINT_BUOY,
146 PR_CLEAR_WAYPOINT_BUOY,
147 PR_TOWN_ACTION,
148 PR_BUILD_FOUNDATION,
149 PR_BUILD_INDUSTRY_RAW,
150 PR_BUILD_TOWN,
151 PR_BUILD_CANAL,
152 PR_CLEAR_CANAL,
153 PR_BUILD_AQUEDUCT,
154 PR_CLEAR_AQUEDUCT,
155 PR_BUILD_LOCK,
156 PR_CLEAR_LOCK,
157 PR_INFRASTRUCTURE_RAIL,
158 PR_INFRASTRUCTURE_ROAD,
159 PR_INFRASTRUCTURE_WATER,
160 PR_INFRASTRUCTURE_STATION,
161 PR_INFRASTRUCTURE_AIRPORT,
163 PR_END,
164 INVALID_PRICE = 0xFF
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.
198 enum PriceCategory {
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.
234 * @see MAX_INFLATION
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;
251 struct CargoPayment;
252 typedef uint32_t CargoPaymentID;
254 #endif /* ECONOMY_TYPE_H */