OpenTTD Source: src/newgrf.h Source File

OpenTTD Source 13.2.1

newgrf.h
Go to the documentation of this file.
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 */
7
10 #ifndef NEWGRF_H
11 #define NEWGRF_H
12
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/smallvec_type.hpp"
20
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,
36 };
37
39 struct CanalProperties {
40 uint8 callback_mask;
41 uint8 flags;
42 };
43
44 enum GrfLoadingStage {
45 GLS_FILESCAN,
46 GLS_SAFETYSCAN,
47 GLS_LABELSCAN,
48 GLS_INIT,
49 GLS_RESERVE,
50 GLS_ACTIVATION,
51 GLS_END,
52 };
53
54 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
55
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,
61 GMB_AMBIENT_SOUND_CALLBACK = 4,
62 GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
63 GMB_SECOND_ROCKY_TILE_SET = 6,
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_ROADTYPES,
86 GSF_TRAMTYPES,
87 GSF_END,
88
89 GSF_FAKE_TOWNS = GSF_END,
90 GSF_FAKE_END,
91
92 GSF_INVALID = 0xFF,
93 };
94
95 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
96
97 struct GRFLabel {
98 byte label;
99 uint32 nfo_line;
100 size_t pos;
101
102 GRFLabel(byte label, uint32 nfo_line, size_t pos) : label(label), nfo_line(nfo_line), pos(pos) {}
103 };
104
106 struct GRFFile : ZeroedMemoryAllocator {
107 char *filename;
108 uint32 grfid;
109 byte grf_version;
110
111 uint sound_offset;
112 uint16 num_sounds;
113
114 struct StationSpec **stations;
115 struct HouseSpec **housespec;
116 struct IndustrySpec **industryspec;
117 struct IndustryTileSpec **indtspec;
118 struct ObjectSpec **objectspec;
119 struct AirportSpec **airportspec;
120 struct AirportTileSpec **airtspec;
121
122 uint32 param[0x80];
123 uint param_end;
124
125 std::vector<GRFLabel> labels;
126
127 std::vector<CargoLabel> cargo_list;
128 uint8 cargo_map[NUM_CARGO];
129
130 std::vector<RailTypeLabel> railtype_list;
131 RailType railtype_map[RAILTYPE_END];
132
133 std::vector<RoadTypeLabel> roadtype_list;
134 RoadType roadtype_map[ROADTYPE_END];
135
136 std::vector<RoadTypeLabel> tramtype_list;
137 RoadType tramtype_map[ROADTYPE_END];
138
139 CanalProperties canal_local_properties[CF_END];
140
141 struct LanguageMap *language_map;
142
143 int traininfo_vehicle_pitch;
144 uint traininfo_vehicle_width;
145
146 uint32 grf_features;
147 PriceMultipliers price_base_multipliers;
148
149 GRFFile(const struct GRFConfig *config);
150 ~GRFFile();
151
153 uint32 GetParam(uint number) const
154 {
155 /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
156 * In fact this is the more important test, as param is zeroed anyway. */
157 assert(this->param_end <= lengthof(this->param));
158 return (number < this->param_end) ? this->param[number] : 0;
159 }
160 };
161
162 enum ShoreReplacement {
163 SHORE_REPLACE_NONE,
164 SHORE_REPLACE_ACTION_5,
165 SHORE_REPLACE_ACTION_A,
166 SHORE_REPLACE_ONLY_NEW,
167 };
168
169 enum TramReplacement {
170 TRAMWAY_REPLACE_DEPOT_NONE,
171 TRAMWAY_REPLACE_DEPOT_WITH_TRACK,
172 TRAMWAY_REPLACE_DEPOT_NO_TRACK,
173 };
174
175 struct GRFLoadedFeatures {
176 bool has_2CC;
177 uint64 used_liveries;
178 ShoreReplacement shore;
179 TramReplacement tram;
180 };
181
187 static inline bool HasGrfMiscBit(GrfMiscBit bit)
188 {
189 extern byte _misc_grf_features;
190 return HasBit(_misc_grf_features, bit);
191 }
192
193 /* Indicates which are the newgrf features currently loaded ingame */
194 extern GRFLoadedFeatures _loaded_newgrf_features;
195
196 void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary);
197 void LoadNewGRF(uint load_index, uint num_baseset);
198 void ReloadNewGRFData(); // in saveload/afterload.cpp
199 void ResetNewGRFData();
200 void ResetPersistentNewGRFData();
201
202 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
203
204 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
205
206 StringID MapGRFStringID(uint32 grfid, StringID str);
207 void ShowNewGRFError();
208
209 #endif /* NEWGRF_H */
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
GRFFile::language_map
struct LanguageMap * language_map
Mappings related to the languages.
Definition: newgrf.h:141
GRFFile::roadtype_list
std::vector< RoadTypeLabel > roadtype_list
Roadtype translation table (road)
Definition: newgrf.h:133
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3247
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
CanalProperties::callback_mask
uint8 callback_mask
Bitmask of canal callbacks that have to be called.
Definition: newgrf.h:40
GRFFile::price_base_multipliers
PriceMultipliers price_base_multipliers
Price base multipliers as set by the grf.
Definition: newgrf.h:147
grfmsg
void CDECL grfmsg(int severity, const char *str,...)
Debug() function dedicated to newGRF debugging messages Function is essentially the same as Debug(grf...
Definition: newgrf.cpp:391
GRFFile::grf_features
uint32 grf_features
Bitset of GrfSpecFeature the grf uses.
Definition: newgrf.h:146
smallvec_type.hpp
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
GrfMiscBit
GrfMiscBit
Definition: newgrf.h:56
GetGlobalVariable
void CDECL bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
Definition: newgrf.cpp:6338
GMB_TRAIN_WIDTH_32_PIXELS
@ GMB_TRAIN_WIDTH_32_PIXELS
Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;.
Definition: newgrf.h:60
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition: newgrf.h:92
GRFLoadedFeatures::used_liveries
uint64 used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition: newgrf.h:177
GRFFile::GetParam
uint32 GetParam(uint number) const
Get GRF Parameter with range checking.
Definition: newgrf.h:153
AirportSpec
Defines the data structure for an airport.
Definition: newgrf_airport.h:98
ShowNewGRFError
void ShowNewGRFError()
Show the first NewGRF error we can find.
Definition: newgrf_gui.cpp:44
alloc_type.hpp
TramReplacement
TramReplacement
Definition: newgrf.h:169
GRFFile::traininfo_vehicle_pitch
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition: newgrf.h:143
AirportTileSpec
Defines the data structure of each individual tile of an airport.
Definition: newgrf_airporttiles.h:66
ResetPersistentNewGRFData
void ResetPersistentNewGRFData()
Reset NewGRF data which is stored persistently in savegames.
Definition: newgrf.cpp:8729
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
LoadNewGRFFile
void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
Load a particular NewGRF.
Definition: newgrf.cpp:9524
bitmath_func.hpp
GRFLoadedFeatures::has_2CC
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
Definition: newgrf.h:176
SHORE_REPLACE_NONE
@ SHORE_REPLACE_NONE
No shore sprites were replaced.
Definition: newgrf.h:163
GRFLoadedFeatures::shore
ShoreReplacement shore
In which way shore sprites were replaced.
Definition: newgrf.h:178
ResetNewGRFData
void ResetNewGRFData()
Reset all NewGRF loaded data.
Definition: newgrf.cpp:8635
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
GRFFile::tramtype_list
std::vector< RoadTypeLabel > tramtype_list
Roadtype translation table (tram)
Definition: newgrf.h:136
HasGrfMiscBit
static bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition: newgrf.h:187
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
GSF_FAKE_TOWNS
@ GSF_FAKE_TOWNS
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Definition: newgrf.h:89
SHORE_REPLACE_ONLY_NEW
@ SHORE_REPLACE_ONLY_NEW
Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
Definition: newgrf.h:166
ZeroedMemoryAllocator
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
GSF_FAKE_END
@ GSF_FAKE_END
End of the fake features.
Definition: newgrf.h:90
SHORE_REPLACE_ACTION_5
@ SHORE_REPLACE_ACTION_5
Shore sprites were replaced by Action5.
Definition: newgrf.h:164
GRFFile::param_end
uint param_end
one more than the highest set parameter
Definition: newgrf.h:123
ShoreReplacement
ShoreReplacement
Definition: newgrf.h:162
GRFFile::traininfo_vehicle_width
uint traininfo_vehicle_width
Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details.
Definition: newgrf.h:144
_loaded_newgrf_features
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition: newgrf.cpp:81
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:107
LoadNewGRF
void LoadNewGRF(uint load_index, uint num_baseset)
Load all the NewGRFs.
Definition: newgrf.cpp:9851
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
GRFFile::canal_local_properties
CanalProperties canal_local_properties[CF_END]
Canal properties as set by this NewGRF.
Definition: newgrf.h:139
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
GRFFile::GRFFile
GRFFile(const struct GRFConfig *config)
Constructor for GRFFile.
Definition: newgrf.cpp:8784
StationSpec
Station specification.
Definition: newgrf_station.h:113
LanguageMap
Mapping of language data between a NewGRF and OpenTTD.
Definition: newgrf_text.h:58
MapGRFStringID
StringID MapGRFStringID(uint32 grfid, StringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
Definition: newgrf.cpp:557
GRFLoadedFeatures::tram
TramReplacement tram
In which way tram depots were replaced.
Definition: newgrf.h:179
SHORE_REPLACE_ACTION_A
@ SHORE_REPLACE_ACTION_A
Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
Definition: newgrf.h:165
TRAMWAY_REPLACE_DEPOT_WITH_TRACK
@ TRAMWAY_REPLACE_DEPOT_WITH_TRACK
Electrified depot graphics with tram track were loaded.
Definition: newgrf.h:171
RAILTYPE_END
@ RAILTYPE_END
Used for iterations.
Definition: rail_type.h:33
CanalProperties::flags
uint8 flags
Flags controlling display.
Definition: newgrf.h:41
TRAMWAY_REPLACE_DEPOT_NONE
@ TRAMWAY_REPLACE_DEPOT_NONE
No tram depot graphics were loaded.
Definition: newgrf.h:170
TRAMWAY_REPLACE_DEPOT_NO_TRACK
@ TRAMWAY_REPLACE_DEPOT_NO_TRACK
Electrified depot graphics without tram track were loaded.
Definition: newgrf.h:172
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:128
cargotype.h
fileio_type.h
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
GRFFile::cargo_list
std::vector< CargoLabel > cargo_list
Cargo translation table (local ID -> label)
Definition: newgrf.h:127
GRFFile::labels
std::vector< GRFLabel > labels
List of labels.
Definition: newgrf.h:125
rail_type.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
road_type.h
HouseSpec
Definition: house.h:98
_misc_grf_features
byte _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
Definition: newgrf.cpp:75
CanalProperties
Canal properties local to the NewGRF.
Definition: newgrf.h:39
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:156
GRFLoadedFeatures
Definition: newgrf.h:175
GRFFile::railtype_list
std::vector< RailTypeLabel > railtype_list
Railtype translation table.
Definition: newgrf.h:130
GRFLabel
Definition: newgrf.h:97
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:106
CanalFeature
CanalFeature
List of different canal 'features'.
Definition: newgrf.h:25