Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / newgrf.h
blob9ca54e86d209e49883538cb7d00c0ff116e65d7e
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 newgrf.h Base for the NewGRF implementation. */
10 #ifndef NEWGRF_H
11 #define NEWGRF_H
13 #include "cargotype.h"
14 #include "rail_type.h"
15 #include "road_type.h"
16 #include "fileio_type.h"
17 #include "core/bitmath_func.hpp"
18 #include "core/alloc_type.hpp"
19 #include "core/mem_func.hpp"
21 /**
22 * List of different canal 'features'.
23 * Each feature gets an entry in the canal spritegroup table
25 enum CanalFeature {
26 CF_WATERSLOPE,
27 CF_LOCKS,
28 CF_DIKES,
29 CF_ICON,
30 CF_DOCKS,
31 CF_RIVER_SLOPE,
32 CF_RIVER_EDGE,
33 CF_RIVER_GUI,
34 CF_BUOY,
35 CF_END,
38 /** Canal properties local to the NewGRF */
39 struct CanalProperties {
40 uint8_t callback_mask; ///< Bitmask of canal callbacks that have to be called.
41 uint8_t flags; ///< Flags controlling display.
44 enum GrfLoadingStage {
45 GLS_FILESCAN,
46 GLS_SAFETYSCAN,
47 GLS_LABELSCAN,
48 GLS_INIT,
49 GLS_RESERVE,
50 GLS_ACTIVATION,
51 GLS_END,
54 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
56 enum GrfMiscBit {
57 GMB_DESERT_TREES_FIELDS = 0, // Unsupported.
58 GMB_DESERT_PAVED_ROADS = 1,
59 GMB_FIELD_BOUNDING_BOX = 2, // Unsupported.
60 GMB_TRAIN_WIDTH_32_PIXELS = 3, ///< Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable; @see GRFFile::traininfo_vehicle_width
61 GMB_AMBIENT_SOUND_CALLBACK = 4,
62 GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
63 GMB_SECOND_ROCKY_TILE_SET = 6,
66 enum GrfSpecFeature {
67 GSF_TRAINS,
68 GSF_ROADVEHICLES,
69 GSF_SHIPS,
70 GSF_AIRCRAFT,
71 GSF_STATIONS,
72 GSF_CANALS,
73 GSF_BRIDGES,
74 GSF_HOUSES,
75 GSF_GLOBALVAR,
76 GSF_INDUSTRYTILES,
77 GSF_INDUSTRIES,
78 GSF_CARGOES,
79 GSF_SOUNDFX,
80 GSF_AIRPORTS,
81 GSF_SIGNALS,
82 GSF_OBJECTS,
83 GSF_RAILTYPES,
84 GSF_AIRPORTTILES,
85 GSF_ROADTYPES,
86 GSF_TRAMTYPES,
87 GSF_ROADSTOPS,
88 GSF_END,
90 GSF_FAKE_TOWNS = GSF_END, ///< Fake town GrfSpecFeature for NewGRF debugging (parent scope)
91 GSF_FAKE_END, ///< End of the fake features
93 GSF_INVALID = 0xFF, ///< An invalid spec feature
96 static const uint32_t INVALID_GRFID = 0xFFFFFFFF;
98 struct GRFLabel {
99 byte label;
100 uint32_t nfo_line;
101 size_t pos;
103 GRFLabel(byte label, uint32_t nfo_line, size_t pos) : label(label), nfo_line(nfo_line), pos(pos) {}
106 /** Dynamic data of a loaded NewGRF */
107 struct GRFFile : ZeroedMemoryAllocator {
108 std::string filename;
109 uint32_t grfid;
110 byte grf_version;
112 uint sound_offset;
113 uint16_t num_sounds;
115 std::vector<std::unique_ptr<struct StationSpec>> stations;
116 std::vector<std::unique_ptr<struct HouseSpec>> housespec;
117 std::vector<std::unique_ptr<struct IndustrySpec>> industryspec;
118 std::vector<std::unique_ptr<struct IndustryTileSpec>> indtspec;
119 std::vector<std::unique_ptr<struct ObjectSpec>> objectspec;
120 std::vector<std::unique_ptr<struct AirportSpec>> airportspec;
121 std::vector<std::unique_ptr<struct AirportTileSpec>> airtspec;
122 std::vector<std::unique_ptr<struct RoadStopSpec>> roadstops;
124 std::array<uint32_t, 0x80> param;
125 uint param_end; ///< one more than the highest set parameter
127 std::vector<GRFLabel> labels; ///< List of labels
129 std::vector<CargoLabel> cargo_list; ///< Cargo translation table (local ID -> label)
130 std::array<uint8_t, NUM_CARGO> cargo_map{}; ///< Inverse cargo translation table (CargoID -> local ID)
132 std::vector<RailTypeLabel> railtype_list; ///< Railtype translation table
133 RailType railtype_map[RAILTYPE_END];
135 std::vector<RoadTypeLabel> roadtype_list; ///< Roadtype translation table (road)
136 RoadType roadtype_map[ROADTYPE_END];
138 std::vector<RoadTypeLabel> tramtype_list; ///< Roadtype translation table (tram)
139 RoadType tramtype_map[ROADTYPE_END];
141 CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF
143 struct LanguageMap *language_map; ///< Mappings related to the languages.
145 int traininfo_vehicle_pitch; ///< Vertical offset for drawing train images in depot GUI and vehicle details
146 uint traininfo_vehicle_width; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details
148 uint32_t grf_features; ///< Bitset of GrfSpecFeature the grf uses
149 PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf.
151 GRFFile(const struct GRFConfig *config);
152 ~GRFFile();
154 /** Get GRF Parameter with range checking */
155 uint32_t GetParam(uint number) const
157 /* Note: We implicitly test for number < this->param.size() and return 0 for invalid parameters.
158 * In fact this is the more important test, as param is zeroed anyway. */
159 assert(this->param_end <= this->param.size());
160 return (number < this->param_end) ? this->param[number] : 0;
164 enum ShoreReplacement {
165 SHORE_REPLACE_NONE, ///< No shore sprites were replaced.
166 SHORE_REPLACE_ACTION_5, ///< Shore sprites were replaced by Action5.
167 SHORE_REPLACE_ACTION_A, ///< Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
168 SHORE_REPLACE_ONLY_NEW, ///< Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
171 enum TramReplacement {
172 TRAMWAY_REPLACE_DEPOT_NONE, ///< No tram depot graphics were loaded.
173 TRAMWAY_REPLACE_DEPOT_WITH_TRACK, ///< Electrified depot graphics with tram track were loaded.
174 TRAMWAY_REPLACE_DEPOT_NO_TRACK, ///< Electrified depot graphics without tram track were loaded.
177 struct GRFLoadedFeatures {
178 bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours).
179 uint64_t used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines.
180 ShoreReplacement shore; ///< In which way shore sprites were replaced.
181 TramReplacement tram; ///< In which way tram depots were replaced.
185 * Check for grf miscellaneous bits
186 * @param bit The bit to check.
187 * @return Whether the bit is set.
189 inline bool HasGrfMiscBit(GrfMiscBit bit)
191 extern byte _misc_grf_features;
192 return HasBit(_misc_grf_features, bit);
195 /* Indicates which are the newgrf features currently loaded ingame */
196 extern GRFLoadedFeatures _loaded_newgrf_features;
198 void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
199 void LoadNewGRF(uint load_index, uint num_baseset);
200 void ReloadNewGRFData(); // in saveload/afterload.cpp
201 void ResetNewGRFData();
202 void ResetPersistentNewGRFData();
204 void GrfMsgI(int severity, const std::string &msg);
205 #define GrfMsg(severity, format_string, ...) GrfMsgI(severity, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
207 bool GetGlobalVariable(byte param, uint32_t *value, const GRFFile *grffile);
209 StringID MapGRFStringID(uint32_t grfid, StringID str);
210 void ShowNewGRFError();
212 #endif /* NEWGRF_H */