Translations update
[openttd/fttd.git] / src / newgrf.h
blob752873a60e3d8ced9e00781142086fd71702052e
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 "fileio_type.h"
18 #include "core/bitmath_func.hpp"
19 #include "core/alloc_type.hpp"
20 #include "core/smallvec_type.hpp"
22 /**
23 * List of different canal 'features'.
24 * Each feature gets an entry in the canal spritegroup table
26 enum CanalFeature {
27 CF_WATERSLOPE,
28 CF_LOCKS,
29 CF_DIKES,
30 CF_ICON,
31 CF_DOCKS,
32 CF_RIVER_SLOPE,
33 CF_RIVER_EDGE,
34 CF_RIVER_GUI,
35 CF_BUOY,
36 CF_END,
39 /** Canal properties local to the NewGRF */
40 struct CanalProperties {
41 uint8 callback_mask; ///< Bitmask of canal callbacks that have to be called.
42 uint8 flags; ///< Flags controlling display.
45 enum GrfLoadingStage {
46 GLS_FILESCAN,
47 GLS_SAFETYSCAN,
48 GLS_LABELSCAN,
49 GLS_INIT,
50 GLS_RESERVE,
51 GLS_ACTIVATION,
52 GLS_END,
55 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
57 enum GrfMiscBit {
58 GMB_DESERT_TREES_FIELDS = 0, // Unsupported.
59 GMB_DESERT_PAVED_ROADS = 1,
60 GMB_FIELD_BOUNDING_BOX = 2, // Unsupported.
61 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
62 GMB_AMBIENT_SOUND_CALLBACK = 4,
63 GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
64 GMB_SECOND_ROCKY_TILE_SET = 6,
67 enum GrfSpecFeature {
68 GSF_TRAINS,
69 GSF_ROADVEHICLES,
70 GSF_SHIPS,
71 GSF_AIRCRAFT,
72 GSF_STATIONS,
73 GSF_CANALS,
74 GSF_BRIDGES,
75 GSF_HOUSES,
76 GSF_GLOBALVAR,
77 GSF_INDUSTRYTILES,
78 GSF_INDUSTRIES,
79 GSF_CARGOES,
80 GSF_SOUNDFX,
81 GSF_AIRPORTS,
82 GSF_SIGNALS,
83 GSF_OBJECTS,
84 GSF_RAILTYPES,
85 GSF_AIRPORTTILES,
86 GSF_END,
88 GSF_FAKE_TOWNS = GSF_END, ///< Fake town GrfSpecFeature for NewGRF debugging (parent scope)
89 GSF_FAKE_END, ///< End of the fake features
91 GSF_INVALID = 0xFF, ///< An invalid spec feature
94 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
96 struct GRFLabel {
97 byte label;
98 uint32 nfo_line;
99 size_t pos;
100 struct GRFLabel *next;
103 /** Dynamic data of a loaded NewGRF */
104 struct GRFFile : ZeroedMemoryAllocator {
105 char *filename;
106 bool is_ottdfile;
107 uint32 grfid;
108 byte grf_version;
110 uint sound_offset;
111 uint16 num_sounds;
113 struct StationSpec **stations;
114 struct HouseSpec **housespec;
115 struct IndustrySpec **industryspec;
116 struct IndustryTileSpec **indtspec;
117 struct ObjectSpec **objectspec;
118 struct AirportSpec **airportspec;
119 struct AirportTileSpec **airtspec;
121 uint32 param[0x80];
122 uint param_end; ///< one more than the highest set parameter
124 GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.
126 SmallVector<CargoLabel, 4> cargo_list; ///< Cargo translation table (local ID -> label)
127 uint8 cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID)
129 SmallVector<RailTypeLabel, 4> railtype_list; ///< Railtype translation table
130 RailTypeByte railtype_map[RAILTYPE_END];
132 CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF
134 struct LanguageMap *language_map; ///< Mappings related to the languages.
136 int traininfo_vehicle_pitch; ///< Vertical offset for draing train images in depot GUI and vehicle details
137 uint traininfo_vehicle_width; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details
139 uint32 grf_features; ///< Bitset of GrfSpecFeature the grf uses
140 PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf.
142 GRFFile(const struct GRFConfig *config);
143 ~GRFFile();
145 /** Get GRF Parameter with range checking */
146 uint32 GetParam(uint number) const
148 /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
149 * In fact this is the more important test, as param is zeroed anyway. */
150 assert(this->param_end <= lengthof(this->param));
151 return (number < this->param_end) ? this->param[number] : 0;
155 enum ShoreReplacement {
156 SHORE_REPLACE_NONE, ///< No shore sprites were replaced.
157 SHORE_REPLACE_ACTION_5, ///< Shore sprites were replaced by Action5.
158 SHORE_REPLACE_ACTION_A, ///< Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
159 SHORE_REPLACE_ONLY_NEW, ///< Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
162 struct GRFLoadedFeatures {
163 bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours).
164 uint64 used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines.
165 bool has_newhouses; ///< Set if there are any newhouses loaded.
166 bool has_newindustries; ///< Set if there are any newindustries loaded.
167 ShoreReplacement shore; ///< It which way shore sprites were replaced.
171 * Check for grf miscellaneous bits
172 * @param bit The bit to check.
173 * @return Whether the bit is set.
175 static inline bool HasGrfMiscBit(GrfMiscBit bit)
177 extern byte _misc_grf_features;
178 return HasBit(_misc_grf_features, bit);
181 /* Indicates which are the newgrf features currently loaded ingame */
182 extern GRFLoadedFeatures _loaded_newgrf_features;
184 byte GetGRFContainerVersion();
186 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
187 void LoadNewGRF(uint load_index, uint file_index);
188 void ReloadNewGRFData(); // in saveload/afterload.cpp
189 void ResetNewGRFData();
190 void ResetPersistentNewGRFData();
192 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
194 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
196 StringID MapGRFStringID(uint32 grfid, StringID str);
197 void ShowNewGRFError();
199 #endif /* NEWGRF_H */