OpenTTD
newgrf.h
Go to the documentation of this file.
1 /* $Id$ */
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 "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"
22 
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,
38 };
39 
42  uint8 callback_mask;
43  uint8 flags;
44 };
45 
46 enum GrfLoadingStage {
47  GLS_FILESCAN,
48  GLS_SAFETYSCAN,
49  GLS_LABELSCAN,
50  GLS_INIT,
51  GLS_RESERVE,
52  GLS_ACTIVATION,
53  GLS_END,
54 };
55 
56 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage)
57 
58 enum GrfMiscBit {
59  GMB_DESERT_TREES_FIELDS = 0, // Unsupported.
60  GMB_DESERT_PAVED_ROADS = 1,
61  GMB_FIELD_BOUNDING_BOX = 2, // Unsupported.
63  GMB_AMBIENT_SOUND_CALLBACK = 4,
64  GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
65  GMB_SECOND_ROCKY_TILE_SET = 6,
66 };
67 
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,
90 
91  GSF_FAKE_TOWNS = GSF_END,
93 
94  GSF_INVALID = 0xFF,
95 };
96 
97 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
98 
99 struct GRFLabel {
100  byte label;
101  uint32 nfo_line;
102  size_t pos;
103  struct GRFLabel *next;
104 };
105 
108  char *filename;
109  uint32 grfid;
110  byte grf_version;
111 
112  uint sound_offset;
113  uint16 num_sounds;
114 
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;
122 
123  uint32 param[0x80];
124  uint param_end;
125 
127 
128  std::vector<CargoLabel> cargo_list;
129  uint8 cargo_map[NUM_CARGO];
130 
131  std::vector<RailTypeLabel> railtype_list;
132  RailType railtype_map[RAILTYPE_END];
133 
134  std::vector<RoadTypeLabel> roadtype_list;
135  RoadType roadtype_map[ROADTYPE_END];
136 
137  std::vector<RoadTypeLabel> tramtype_list;
138  RoadType tramtype_map[ROADTYPE_END];
139 
140  CanalProperties canal_local_properties[CF_END];
141 
143 
146 
147  uint32 grf_features;
148  PriceMultipliers price_base_multipliers;
149 
150  GRFFile(const struct GRFConfig *config);
151  ~GRFFile();
152 
154  uint32 GetParam(uint number) const
155  {
156  /* Note: We implicitly test for number < lengthof(this->param) and return 0 for invalid parameters.
157  * In fact this is the more important test, as param is zeroed anyway. */
158  assert(this->param_end <= lengthof(this->param));
159  return (number < this->param_end) ? this->param[number] : 0;
160  }
161 };
162 
168 };
169 
174 };
175 
177  bool has_2CC;
178  uint64 used_liveries;
183 };
184 
190 static inline bool HasGrfMiscBit(GrfMiscBit bit)
191 {
192  extern byte _misc_grf_features;
193  return HasBit(_misc_grf_features, bit);
194 }
195 
196 /* Indicates which are the newgrf features currently loaded ingame */
198 
200 
201 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
202 void LoadNewGRF(uint load_index, uint file_index, uint num_baseset);
203 void ReloadNewGRFData(); // in saveload/afterload.cpp
204 void ResetNewGRFData();
206 
207 void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3);
208 
209 bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
210 
211 StringID MapGRFStringID(uint32 grfid, StringID str);
212 void ShowNewGRFError();
213 
214 #endif /* NEWGRF_H */
std::vector< RoadTypeLabel > roadtype_list
Roadtype translation table (road)
Definition: newgrf.h:134
Enums and other types related to roads.
struct LanguageMap * language_map
Mappings related to the languages.
Definition: newgrf.h:142
Electrified depot graphics without tram track were loaded.
Definition: newgrf.h:173
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
void ResetPersistentNewGRFData()
Reset NewGRF data which is stored persistently in savegames.
Definition: newgrf.cpp:8630
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
Used for iterations.
Definition: road_type.h:31
Station specification.
CanalFeature
List of different canal &#39;features&#39;.
Definition: newgrf.h:27
uint32 grf_features
Bitset of GrfSpecFeature the grf uses.
Definition: newgrf.h:147
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition: newgrf.cpp:78
StringID MapGRFStringID(uint32 grfid, StringID str)
Used when setting an object&#39;s property to map to the GRF&#39;s strings while taking in consideration the ...
Definition: newgrf.cpp:549
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
Functions related to bit mathematics.
uint8 flags
Flags controlling display.
Definition: newgrf.h:43
Helper types related to the allocation of memory.
TramReplacement tram
In which way tram depots were replaced.
Definition: newgrf.h:182
RoadType
The different roadtypes we support.
Definition: road_type.h:27
GRFLabel * label
Pointer to the first label. This is a linked list, not an array.
Definition: newgrf.h:126
uint32 GetParam(uint number) const
Get GRF Parameter with range checking.
Definition: newgrf.h:154
An invalid spec feature.
Definition: newgrf.h:94
No shore sprites were replaced.
Definition: newgrf.h:164
Types for Standard In/Out file operations.
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Definition: newgrf.h:91
GrfSpecFeature
Definition: newgrf.h:68
ShoreReplacement shore
In which way shore sprites were replaced.
Definition: newgrf.h:181
uint param_end
one more than the highest set parameter
Definition: newgrf.h:124
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Definition: newgrf.h:144
Shore sprites were replaced by Action5.
Definition: newgrf.h:165
Information about GRF, used in the game and (part of it) in savegames.
No tram depot graphics were loaded.
Definition: newgrf.h:171
Mapping of language data between a NewGRF and OpenTTD.
Definition: newgrf_text.h:47
End of the fake features.
Definition: newgrf.h:92
uint traininfo_vehicle_width
Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details.
Definition: newgrf.h:145
Defines the data structure for constructing industry.
Definition: industrytype.h:108
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
GrfMiscBit
Definition: newgrf.h:58
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:87
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
bool has_newhouses
Set if there are any newhouses loaded.
Definition: newgrf.h:179
Shore sprites were replaced by ActionA (using grass tiles for the corner-shores). ...
Definition: newgrf.h:166
uint8 callback_mask
Bitmask of canal callbacks that have to be called.
Definition: newgrf.h:42
void ShowNewGRFError()
Show the first NewGRF error we can find.
Definition: newgrf_gui.cpp:46
void CDECL bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
Definition: newgrf.cpp:6230
ShoreReplacement
Definition: newgrf.h:163
TramReplacement
Definition: newgrf.h:170
void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
Load a particular NewGRF.
Definition: newgrf.cpp:9333
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
Canal properties local to the NewGRF.
Definition: newgrf.h:41
bool has_newindustries
Set if there are any newindustries loaded.
Definition: newgrf.h:180
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:377
Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
Definition: newgrf.h:167
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
Definition: newgrf.h:177
std::vector< RailTypeLabel > railtype_list
Railtype translation table.
Definition: newgrf.h:131
Defines the data structure of each individual tile of an airport.
byte GetGRFContainerVersion()
Get the container version of the currently opened GRF file.
Definition: newgrf.cpp:9307
Types/functions related to cargoes.
uint64 used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition: newgrf.h:178
Used for iterations.
Definition: rail_type.h:35
std::vector< CargoLabel > cargo_list
Cargo translation table (local ID -> label)
Definition: newgrf.h:128
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
byte _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
Definition: newgrf.cpp:72
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:157
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3234
Defines the data structure for an airport.
Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;...
Definition: newgrf.h:62
void ResetNewGRFData()
Reset all NewGRF loaded data.
Definition: newgrf.cpp:8533
static bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition: newgrf.h:190
void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
Load all the NewGRFs.
Definition: newgrf.cpp:9741
Electrified depot graphics with tram track were loaded.
Definition: newgrf.h:172
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
The different types of rail.