Update readme and changelog for v1.27.0
[openttd-joker.git] / src / newgrf.h
blob1b916400243d05d8f1a4d851fb20cc6b66107204
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 newgrf.h Base for the NewGRF implementation. */
12 #ifndef NEWGRF_H
13 #define NEWGRF_H
15 #include "cargotype.h"
16 #include "rail_type.h"
17 #include "road_type.h"
18 #include "fileio_type.h"
19 #include "core/bitmath_func.hpp"
20 #include "core/alloc_type.hpp"
21 #include "core/smallvec_type.hpp"
23 /**
24 * List of different canal 'features'.
25 * Each feature gets an entry in the canal spritegroup table
27 enum CanalFeature {
28 CF_WATERSLOPE,
29 CF_LOCKS,
30 CF_DIKES,
31 CF_ICON,
32 CF_DOCKS,
33 CF_RIVER_SLOPE,
34 CF_RIVER_EDGE,
35 CF_RIVER_GUI,
36 CF_BUOY,
37 CF_END,
40 /** Canal properties local to the NewGRF */
41 struct CanalProperties {
42 uint8 callback_mask; ///< Bitmask of canal callbacks that have to be called.
43 uint8 flags; ///< Flags controlling display.
46 enum GrfLoadingStage {
47 GLS_FILESCAN,
48 GLS_SAFETYSCAN,
49 GLS_LABELSCAN,
50 GLS_INIT,
51 GLS_RESERVE,
52 GLS_ACTIVATION,
53 GLS_END,
56 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
58 enum GrfMiscBit {
59 GMB_DESERT_TREES_FIELDS = 0, // Unsupported.
60 GMB_DESERT_PAVED_ROADS = 1,
61 GMB_FIELD_BOUNDING_BOX = 2, // Unsupported.
62 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
63 GMB_AMBIENT_SOUND_CALLBACK = 4,
64 GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
65 GMB_SECOND_ROCKY_TILE_SET = 6,
68 enum GrfSpecFeature {
69 GSF_TRAINS,
70 GSF_ROADVEHICLES,
71 GSF_SHIPS,
72 GSF_AIRCRAFT,
73 GSF_STATIONS,
74 GSF_CANALS,
75 GSF_BRIDGES,
76 GSF_HOUSES,
77 GSF_GLOBALVAR,
78 GSF_INDUSTRYTILES,
79 GSF_INDUSTRIES,
80 GSF_CARGOES,
81 GSF_SOUNDFX,
82 GSF_AIRPORTS,
83 GSF_SIGNALS,
84 GSF_OBJECTS,
85 GSF_RAILTYPES,
86 GSF_AIRPORTTILES,
87 GSF_ROADTYPES,
88 GSF_TRAMTYPES,
89 GSF_END,
91 GSF_FAKE_TOWNS = GSF_END, ///< Fake town GrfSpecFeature for NewGRF debugging (parent scope)
92 GSF_FAKE_END, ///< End of the fake features
94 GSF_INVALID = 0xFF, ///< An invalid spec feature
97 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
99 struct GRFLabel {
100 byte label;
101 uint32 nfo_line;
102 size_t pos;
103 struct GRFLabel *next;
106 /** Dynamic data of a loaded NewGRF */
107 struct GRFFile : ZeroedMemoryAllocator {
108 char *filename;
109 uint32 grfid;
110 byte grf_version;
112 uint sound_offset;
113 uint16 num_sounds;
115 struct StationSpec **stations;
116 struct HouseSpec **housespec;
117 struct IndustrySpec **industryspec;
118 struct IndustryTileSpec **indtspec;
119 struct ObjectSpec **objectspec;
120 struct AirportSpec **airportspec;
121 struct AirportTileSpec **airtspec;
123 uint32 param[0x80];
124 uint param_end; ///< one more than the highest set parameter
126 GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.
128 SmallVector<CargoLabel, 4> cargo_list; ///< Cargo translation table (local ID -> label)
129 uint8 cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID)
131 SmallVector<RailTypeLabel, 4> railtype_list; ///< Railtype translation table
132 RailTypeByte railtype_map[RAILTYPE_END];
134 SmallVector<RoadTypeLabel, 4> roadtype_list[ROADTYPE_END]; ///< Roadtype translation table
135 uint8 roadtype_map[ROADTYPE_END][ROADSUBTYPE_END];
137 CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF
139 struct LanguageMap *language_map; ///< Mappings related to the languages.
141 int traininfo_vehicle_pitch; ///< Vertical offset for draing train images in depot GUI and vehicle details
142 uint traininfo_vehicle_width; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details
144 uint32 grf_features; ///< Bitset of GrfSpecFeature the grf uses
145 PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf.
147 GRFFile(const struct GRFConfig *config);
148 ~GRFFile();
150 /** Get GRF Parameter with range checking */
151 uint32 GetParam(uint number) const
153 /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
154 * In fact this is the more important test, as param is zeroed anyway. */
155 assert(this->param_end <= lengthof(this->param));
156 return (number < this->param_end) ? this->param[number] : 0;
160 enum ShoreReplacement {
161 SHORE_REPLACE_NONE, ///< No shore sprites were replaced.
162 SHORE_REPLACE_ACTION_5, ///< Shore sprites were replaced by Action5.
163 SHORE_REPLACE_ACTION_A, ///< Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
164 SHORE_REPLACE_ONLY_NEW, ///< Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
167 enum TramReplacement {
168 TRAMWAY_REPLACE_DEPOT_NONE, ///< No tram depot graphics were loaded.
169 TRAMWAY_REPLACE_DEPOT_WITH_TRACK, ///< Electrified depot graphics with tram track were loaded.
170 TRAMWAY_REPLACE_DEPOT_NO_TRACK, ///< Electrified depot graphics without tram track were loaded.
173 struct GRFLoadedFeatures {
174 bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours).
175 uint64 used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines.
176 bool has_newhouses; ///< Set if there are any newhouses loaded.
177 bool has_newindustries; ///< Set if there are any newindustries loaded.
178 ShoreReplacement shore; ///< In which way shore sprites were replaced.
179 TramReplacement tram; ///< In which way tram depots were replaced.
183 * Check for grf miscellaneous bits
184 * @param bit The bit to check.
185 * @return Whether the bit is set.
187 static inline bool HasGrfMiscBit(GrfMiscBit bit)
189 extern byte _misc_grf_features;
190 return HasBit(_misc_grf_features, bit);
193 /* Indicates which are the newgrf features currently loaded ingame */
194 extern GRFLoadedFeatures _loaded_newgrf_features;
196 byte GetGRFContainerVersion();
198 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
199 void LoadNewGRF(uint load_index, uint file_index, uint num_baseset);
200 void ReloadNewGRFData(); // in saveload/afterload.cpp
201 void ResetNewGRFData();
202 void ResetPersistentNewGRFData();
204 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
206 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
208 StringID MapGRFStringID(uint32 grfid, StringID str);
209 void ShowNewGRFError();
211 uint CountSelectedGRFs(GRFConfig *grfconf);
213 struct TemplateVehicle;
215 #endif /* NEWGRF_H */