OpenTTD: src/newgrf.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf.h
Go to the documentation of this file.
1 /* $Id: newgrf.h 26364 2014-02-22 21:12:28Z rubidium $ */
2
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 */
9
12 #ifndef NEWGRF_H
13 #define NEWGRF_H
14
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"
21
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,
37 };
38
40 struct CanalProperties {
41 uint8 callback_mask;
42 uint8 flags;
43 };
44
45 enum GrfLoadingStage {
46 GLS_FILESCAN,
47 GLS_SAFETYSCAN,
48 GLS_LABELSCAN,
49 GLS_INIT,
50 GLS_RESERVE,
51 GLS_ACTIVATION,
52 GLS_END,
53 };
54
55 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
56
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,
62 GMB_AMBIENT_SOUND_CALLBACK = 4,
63 GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
64 };
65
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_END,
86
87 GSF_FAKE_TOWNS = GSF_END,
88 GSF_FAKE_END,
89
90 GSF_INVALID = 0xFF,
91 };
92
93 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
94
95 struct GRFLabel {
96 byte label;
97 uint32 nfo_line;
98 size_t pos;
99 struct GRFLabel *next;
100 };
101
103 struct GRFFile : ZeroedMemoryAllocator {
104 char *filename;
105 bool is_ottdfile;
106 uint32 grfid;
107 byte grf_version;
108
109 uint sound_offset;
110 uint16 num_sounds;
111
112 struct StationSpec **stations;
113 struct HouseSpec **housespec;
114 struct IndustrySpec **industryspec;
115 struct IndustryTileSpec **indtspec;
116 struct ObjectSpec **objectspec;
117 struct AirportSpec **airportspec;
118 struct AirportTileSpec **airtspec;
119
120 uint32 param[0x80];
121 uint param_end;
122
123 GRFLabel *label;
124
125 SmallVector<CargoLabel, 4> cargo_list;
126 uint8 cargo_map[NUM_CARGO];
127
128 SmallVector<RailTypeLabel, 4> railtype_list;
129 RailTypeByte railtype_map[RAILTYPE_END];
130
131 CanalProperties canal_local_properties[CF_END];
132
133 struct LanguageMap *language_map;
134
135 int traininfo_vehicle_pitch;
136 uint traininfo_vehicle_width;
137
138 uint32 grf_features;
139 PriceMultipliers price_base_multipliers;
140
141 GRFFile(const struct GRFConfig *config);
142 ~GRFFile();
143
145 uint32 GetParam(uint number) const
146 {
147 /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
148 * In fact this is the more important test, as param is zeroed anyway. */
149 assert(this->param_end <= lengthof(this->param));
150 return (number < this->param_end) ? this->param[number] : 0;
151 }
152 };
153
154 enum ShoreReplacement {
155 SHORE_REPLACE_NONE,
156 SHORE_REPLACE_ACTION_5,
157 SHORE_REPLACE_ACTION_A,
158 SHORE_REPLACE_ONLY_NEW,
159 };
160
161 struct GRFLoadedFeatures {
162 bool has_2CC;
163 uint64 used_liveries;
164 bool has_newhouses;
165 bool has_newindustries;
166 ShoreReplacement shore;
167 };
168
174 static inline bool HasGrfMiscBit(GrfMiscBit bit)
175 {
176 extern byte _misc_grf_features;
177 return HasBit(_misc_grf_features, bit);
178 }
179
180 /* Indicates which are the newgrf features currently loaded ingame */
181 extern GRFLoadedFeatures _loaded_newgrf_features;
182
183 byte GetGRFContainerVersion();
184
185 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
186 void LoadNewGRF(uint load_index, uint file_index);
187 void ReloadNewGRFData(); // in saveload/afterload.cpp
188 void ResetNewGRFData();
189 void ResetPersistentNewGRFData();
190
191 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
192
193 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
194
195 StringID MapGRFStringID(uint32 grfid, StringID str);
196 void ShowNewGRFError();
197
198 #endif /* NEWGRF_H */