OpenTTD
newgrf.h
Go to the documentation of this file.
1 /* $Id: newgrf.h 27730 2017-01-14 15:48:19Z frosch $ */
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 
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 
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.
62  GMB_AMBIENT_SOUND_CALLBACK = 4,
63  GMB_CATENARY_ON_3RD_TRACK = 5, // Unsupported.
64  GMB_SECOND_ROCKY_TILE_SET = 6,
65 };
66 
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,
87 
88  GSF_FAKE_TOWNS = GSF_END,
90 
91  GSF_INVALID = 0xFF,
92 };
93 
94 static const uint32 INVALID_GRFID = 0xFFFFFFFF;
95 
96 struct GRFLabel {
97  byte label;
98  uint32 nfo_line;
99  size_t pos;
100  struct GRFLabel *next;
101 };
102 
105  char *filename;
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 
124 
126  uint8 cargo_map[NUM_CARGO];
127 
129  RailTypeByte railtype_map[RAILTYPE_END];
130 
131  CanalProperties canal_local_properties[CF_END];
132 
134 
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 
159 };
160 
162  bool has_2CC;
163  uint64 used_liveries;
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 */
182 
184 
185 void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir);
186 void LoadNewGRF(uint load_index, uint file_index, uint num_baseset);
187 void ReloadNewGRFData(); // in saveload/afterload.cpp
188 void ResetNewGRFData();
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 */
Used for iterations.
Definition: rail_type.h:35
struct LanguageMap * language_map
Mappings related to the languages.
Definition: newgrf.h:133
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:8166
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
Station specification.
CanalFeature
List of different canal &#39;features&#39;.
Definition: newgrf.h:26
uint32 grf_features
Bitset of GrfSpecFeature the grf uses.
Definition: newgrf.h:138
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition: newgrf.cpp:77
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:552
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
Functions related to bit mathematics.
uint8 flags
Flags controlling display.
Definition: newgrf.h:42
Helper types related to the allocation of memory.
GRFLabel * label
Pointer to the first label. This is a linked list, not an array.
Definition: newgrf.h:123
uint32 GetParam(uint number) const
Get GRF Parameter with range checking.
Definition: newgrf.h:145
An invalid spec feature.
Definition: newgrf.h:91
No shore sprites were replaced.
Definition: newgrf.h:155
Types for Standard In/Out file operations.
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Definition: newgrf.h:88
GrfSpecFeature
Definition: newgrf.h:67
ShoreReplacement shore
It which way shore sprites were replaced.
Definition: newgrf.h:166
uint param_end
one more than the highest set parameter
Definition: newgrf.h:121
int traininfo_vehicle_pitch
Vertical offset for draing train images in depot GUI and vehicle details.
Definition: newgrf.h:135
Shore sprites were replaced by Action5.
Definition: newgrf.h:156
Information about GRF, used in the game and (part of it) in savegames.
SmallVector< RailTypeLabel, 4 > railtype_list
Railtype translation table.
Definition: newgrf.h:128
Mapping of language data between a NewGRF and OpenTTD.
Definition: newgrf_text.h:47
End of the fake features.
Definition: newgrf.h:89
uint traininfo_vehicle_width
Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details.
Definition: newgrf.h:136
Defines the data structure for constructing industry.
Definition: industrytype.h:101
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
GrfMiscBit
Definition: newgrf.h:57
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:150
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:164
Shore sprites were replaced by ActionA (using grass tiles for the corner-shores). ...
Definition: newgrf.h:157
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
uint8 callback_mask
Bitmask of canal callbacks that have to be called.
Definition: newgrf.h:41
void ShowNewGRFError()
Show the first NewGRF error we can find.
Definition: newgrf_gui.cpp:45
void CDECL bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
Definition: newgrf.cpp:5755
ShoreReplacement
Definition: newgrf.h:154
void LoadNewGRFFile(struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
Load a particular NewGRF.
Definition: newgrf.cpp:8863
Canal properties local to the NewGRF.
Definition: newgrf.h:40
SmallVector< CargoLabel, 4 > cargo_list
Cargo translation table (local ID -> label)
Definition: newgrf.h:125
bool has_newindustries
Set if there are any newindustries loaded.
Definition: newgrf.h:165
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:375
Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
Definition: newgrf.h:158
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
Definition: newgrf.h:162
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:8837
Types/functions related to cargoes.
uint64 used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition: newgrf.h:163
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:71
Defines the data structure of each individual tile of an industry.
Definition: industrytype.h:148
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3004
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:61
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
void ResetNewGRFData()
Reset all NewGRF loaded data TODO.
Definition: newgrf.cpp:8073
static bool HasGrfMiscBit(GrfMiscBit bit)
Check for grf miscellaneous bits.
Definition: newgrf.h:174
void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
Load all the NewGRFs.
Definition: newgrf.cpp:9228
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:104
The different types of rail.