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/>.
10 /** @file newgrf.h Base for the NewGRF implementation. */
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"
23 * List of different canal 'features'.
24 * Each feature gets an entry in the canal spritegroup table
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
{
55 DECLARE_POSTFIX_INCREMENT(GrfLoadingStage
)
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.
87 GSF_FAKE_TOWNS
= GSF_END
, ///< Fake town GrfSpecFeature for NewGRF debugging (parent scope)
88 GSF_FAKE_END
, ///< End of the fake features
90 GSF_INVALID
= 0xFF, ///< An invalid spec feature
93 static const uint32 INVALID_GRFID
= 0xFFFFFFFF;
99 struct GRFLabel
*next
;
102 /** Dynamic data of a loaded NewGRF */
103 struct GRFFile
: ZeroedMemoryAllocator
{
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
;
121 uint param_end
; ///< one more than the highest set parameter
123 GRFLabel
*label
; ///< Pointer to the first label. This is a linked list, not an array.
125 SmallVector
<CargoLabel
, 4> cargo_list
; ///< Cargo translation table (local ID -> label)
126 uint8 cargo_map
[NUM_CARGO
]; ///< Inverse cargo translation table (CargoID -> local ID)
128 SmallVector
<RailTypeLabel
, 4> railtype_list
; ///< Railtype translation table
129 RailType railtype_map
[RAILTYPE_END
];
131 CanalProperties canal_local_properties
[CF_END
]; ///< Canal properties as set by this NewGRF
133 struct LanguageMap
*language_map
; ///< Mappings related to the languages.
135 int traininfo_vehicle_pitch
; ///< Vertical offset for draing train images in depot GUI and vehicle details
136 uint traininfo_vehicle_width
; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details
138 uint32 grf_features
; ///< Bitset of GrfSpecFeature the grf uses
139 PriceMultipliers price_base_multipliers
; ///< Price base multipliers as set by the grf.
141 GRFFile(const struct GRFConfig
*config
);
144 /** Get GRF Parameter with range checking */
145 uint32
GetParam(uint number
) const
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;
154 enum ShoreReplacement
{
155 SHORE_REPLACE_NONE
, ///< No shore sprites were replaced.
156 SHORE_REPLACE_ACTION_5
, ///< Shore sprites were replaced by Action5.
157 SHORE_REPLACE_ACTION_A
, ///< Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
158 SHORE_REPLACE_ONLY_NEW
, ///< Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
161 struct GRFLoadedFeatures
{
162 bool has_2CC
; ///< Set if any vehicle is loaded which uses 2cc (two company colours).
163 uint64 used_liveries
; ///< Bitmask of #LiveryScheme used by the defined engines.
164 bool has_newhouses
; ///< Set if there are any newhouses loaded.
165 bool has_newindustries
; ///< Set if there are any newindustries loaded.
166 ShoreReplacement shore
; ///< It which way shore sprites were replaced.
170 * Check for grf miscellaneous bits
171 * @param bit The bit to check.
172 * @return Whether the bit is set.
174 static inline bool HasGrfMiscBit(GrfMiscBit bit
)
176 extern byte _misc_grf_features
;
177 return HasBit(_misc_grf_features
, bit
);
180 /* Indicates which are the newgrf features currently loaded ingame */
181 extern GRFLoadedFeatures _loaded_newgrf_features
;
183 byte
GetGRFContainerVersion();
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();
191 void CDECL
grfmsg(int severity
, const char *str
, ...) WARN_FORMAT(2, 3);
193 bool GetGlobalVariable(byte param
, uint32
*value
, const GRFFile
*grffile
);
195 StringID
MapGRFStringID(uint32 grfid
, StringID str
);
196 void ShowNewGRFError();
198 #endif /* NEWGRF_H */