Codechange: Store custom station layouts in a map instead of nested vectors. (#12898)
[openttd-github.git] / src / table / newgrf_debug_data.h
blobdd108464892b0bda603a90dcc2f96d241b55681c
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 */
8 /** @file newgrf_debug_data.h Data 'tables' for NewGRF debugging. */
10 #include "../newgrf_house.h"
11 #include "../newgrf_engine.h"
12 #include "../newgrf_roadtype.h"
13 #include "../newgrf_roadstop.h"
15 /* Helper for filling property tables */
16 #define NIP(prop, base, variable, type, name) { name, [] (const void *b) -> const void * { return std::addressof(static_cast<const base *>(b)->variable); }, cpp_sizeof(base, variable), prop, type }
17 #define NIP_END() { nullptr, 0, 0, 0, 0 }
19 /* Helper for filling callback tables */
20 #define NIC(cb_id, base, variable, bit) { #cb_id, [] (const void *b) -> const void * { return std::addressof(static_cast<const base *>(b)->variable); }, cpp_sizeof(base, variable), bit, cb_id }
21 #define NIC_END() { nullptr, 0, 0, 0, 0 }
23 /* Helper for filling variable tables */
24 #define NIV(var, name) { name, var }
25 #define NIV_END() { nullptr, 0 }
28 /*** NewGRF Vehicles ***/
30 #define NICV(cb_id, bit) NIC(cb_id, Engine, info.callback_mask, bit)
31 static const NICallback _nic_vehicles[] = {
32 NICV(CBID_VEHICLE_VISUAL_EFFECT, CBM_VEHICLE_VISUAL_EFFECT),
33 NICV(CBID_VEHICLE_LENGTH, CBM_VEHICLE_LENGTH),
34 NICV(CBID_VEHICLE_LOAD_AMOUNT, CBM_VEHICLE_LOAD_AMOUNT),
35 NICV(CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY),
36 NICV(CBID_VEHICLE_ARTIC_ENGINE, CBM_VEHICLE_ARTIC_ENGINE),
37 NICV(CBID_VEHICLE_CARGO_SUFFIX, CBM_VEHICLE_CARGO_SUFFIX),
38 NICV(CBID_TRAIN_ALLOW_WAGON_ATTACH, CBM_NO_BIT),
39 NICV(CBID_VEHICLE_ADDITIONAL_TEXT, CBM_NO_BIT),
40 NICV(CBID_VEHICLE_COLOUR_MAPPING, CBM_VEHICLE_COLOUR_REMAP),
41 NICV(CBID_VEHICLE_START_STOP_CHECK, CBM_NO_BIT),
42 NICV(CBID_VEHICLE_32DAY_CALLBACK, CBM_NO_BIT),
43 NICV(CBID_VEHICLE_SOUND_EFFECT, CBM_VEHICLE_SOUND_EFFECT),
44 NICV(CBID_VEHICLE_AUTOREPLACE_SELECTION, CBM_NO_BIT),
45 NICV(CBID_VEHICLE_MODIFY_PROPERTY, CBM_NO_BIT),
46 NICV(CBID_VEHICLE_NAME, CBM_VEHICLE_NAME),
47 NIC_END()
51 static const NIVariable _niv_vehicles[] = {
52 NIV(0x40, "position in consist and length"),
53 NIV(0x41, "position and length of chain of same vehicles"),
54 NIV(0x42, "transported cargo types"),
55 NIV(0x43, "player info"),
56 NIV(0x44, "aircraft info"),
57 NIV(0x45, "curvature info"),
58 NIV(0x46, "motion counter"),
59 NIV(0x47, "vehicle cargo info"),
60 NIV(0x48, "vehicle type info"),
61 NIV(0x49, "year of construction"),
62 NIV(0x4A, "current rail/road type info"),
63 NIV(0x4B, "long date of last service"),
64 NIV(0x4C, "current max speed"),
65 NIV(0x4D, "position in articulated vehicle"),
66 NIV(0x60, "count vehicle id occurrences"),
67 // 0x61 not useful, since it requires register 0x10F
68 NIV(0x62, "curvature/position difference to other vehicle"),
69 NIV(0x63, "tile compatibility wrt. track-type"),
70 NIV_END()
73 class NIHVehicle : public NIHelper {
74 bool IsInspectable(uint index) const override { return Vehicle::Get(index)->GetGRF() != nullptr; }
75 uint GetParent(uint index) const override { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); }
76 const void *GetInstance(uint index)const override { return Vehicle::Get(index); }
77 const void *GetSpec(uint index) const override { return Vehicle::Get(index)->GetEngine(); }
78 void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_VEHICLE_NAME, index); }
79 uint32_t GetGRFID(uint index) const override { return Vehicle::Get(index)->GetGRFID(); }
81 uint Resolve(uint index, uint var, uint param, bool &avail) const override
83 Vehicle *v = Vehicle::Get(index);
84 VehicleResolverObject ro(v->engine_type, v, VehicleResolverObject::WO_CACHED);
85 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
89 static const NIFeature _nif_vehicle = {
90 nullptr,
91 _nic_vehicles,
92 _niv_vehicles,
93 new NIHVehicle(),
97 /*** NewGRF station (tiles) ***/
99 #define NICS(cb_id, bit) NIC(cb_id, StationSpec, callback_mask, bit)
100 static const NICallback _nic_stations[] = {
101 NICS(CBID_STATION_AVAILABILITY, CBM_STATION_AVAIL),
102 NICS(CBID_STATION_DRAW_TILE_LAYOUT, CBM_STATION_DRAW_TILE_LAYOUT),
103 NICS(CBID_STATION_BUILD_TILE_LAYOUT,CBM_NO_BIT),
104 NICS(CBID_STATION_ANIM_START_STOP, CBM_NO_BIT),
105 NICS(CBID_STATION_ANIM_NEXT_FRAME, CBM_STATION_ANIMATION_NEXT_FRAME),
106 NICS(CBID_STATION_ANIMATION_SPEED, CBM_STATION_ANIMATION_SPEED),
107 NICS(CBID_STATION_LAND_SLOPE_CHECK, CBM_STATION_SLOPE_CHECK),
108 NIC_END()
111 static const NIVariable _niv_stations[] = {
112 NIV(0x40, "platform info and relative position"),
113 NIV(0x41, "platform info and relative position for individually built sections"),
114 NIV(0x42, "terrain and track type"),
115 NIV(0x43, "player info"),
116 NIV(0x44, "path signalling info"),
117 NIV(0x45, "rail continuation info"),
118 NIV(0x46, "platform info and relative position from middle"),
119 NIV(0x47, "platform info and relative position from middle for individually built sections"),
120 NIV(0x48, "bitmask of accepted cargoes"),
121 NIV(0x49, "platform info and relative position of same-direction section"),
122 NIV(0x4A, "current animation frame"),
123 NIV(0x60, "amount of cargo waiting"),
124 NIV(0x61, "time since last cargo pickup"),
125 NIV(0x62, "rating of cargo"),
126 NIV(0x63, "time spent on route"),
127 NIV(0x64, "information about last vehicle picking cargo up"),
128 NIV(0x65, "amount of cargo acceptance"),
129 NIV(0x66, "animation frame of nearby tile"),
130 NIV(0x67, "land info of nearby tiles"),
131 NIV(0x68, "station info of nearby tiles"),
132 NIV(0x69, "information about cargo accepted in the past"),
133 NIV(0x6A, "GRFID of nearby station tiles"),
134 NIV(0x6B, "station ID of nearby tiles"),
135 NIV_END()
138 class NIHStation : public NIHelper {
139 bool IsInspectable(uint index) const override { return GetStationSpec(index) != nullptr; }
140 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(index)->town->index); }
141 const void *GetInstance(uint ) const override { return nullptr; }
142 const void *GetSpec(uint index) const override { return GetStationSpec(index); }
143 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
144 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grffile->grfid : 0; }
146 uint Resolve(uint index, uint var, uint param, bool &avail) const override
148 StationResolverObject ro(GetStationSpec(index), Station::GetByTile(index), index);
149 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
153 static const NIFeature _nif_station = {
154 nullptr,
155 _nic_stations,
156 _niv_stations,
157 new NIHStation(),
161 /*** NewGRF house tiles ***/
163 #define NICH(cb_id, bit) NIC(cb_id, HouseSpec, callback_mask, bit)
164 static const NICallback _nic_house[] = {
165 NICH(CBID_HOUSE_ALLOW_CONSTRUCTION, CBM_HOUSE_ALLOW_CONSTRUCTION),
166 NICH(CBID_HOUSE_ANIMATION_NEXT_FRAME, CBM_HOUSE_ANIMATION_NEXT_FRAME),
167 NICH(CBID_HOUSE_ANIMATION_START_STOP, CBM_HOUSE_ANIMATION_START_STOP),
168 NICH(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE),
169 NICH(CBID_HOUSE_COLOUR, CBM_HOUSE_COLOUR),
170 NICH(CBID_HOUSE_CARGO_ACCEPTANCE, CBM_HOUSE_CARGO_ACCEPTANCE),
171 NICH(CBID_HOUSE_ANIMATION_SPEED, CBM_HOUSE_ANIMATION_SPEED),
172 NICH(CBID_HOUSE_DESTRUCTION, CBM_HOUSE_DESTRUCTION),
173 NICH(CBID_HOUSE_ACCEPT_CARGO, CBM_HOUSE_ACCEPT_CARGO),
174 NICH(CBID_HOUSE_PRODUCE_CARGO, CBM_HOUSE_PRODUCE_CARGO),
175 NICH(CBID_HOUSE_DENY_DESTRUCTION, CBM_HOUSE_DENY_DESTRUCTION),
176 NICH(CBID_HOUSE_WATCHED_CARGO_ACCEPTED, CBM_NO_BIT),
177 NICH(CBID_HOUSE_CUSTOM_NAME, CBM_NO_BIT),
178 NICH(CBID_HOUSE_DRAW_FOUNDATIONS, CBM_HOUSE_DRAW_FOUNDATIONS),
179 NICH(CBID_HOUSE_AUTOSLOPE, CBM_HOUSE_AUTOSLOPE),
180 NIC_END()
183 static const NIVariable _niv_house[] = {
184 NIV(0x40, "construction state of tile and pseudo-random value"),
185 NIV(0x41, "age of building in years"),
186 NIV(0x42, "town zone"),
187 NIV(0x43, "terrain type"),
188 NIV(0x44, "building counts"),
189 NIV(0x45, "town expansion bits"),
190 NIV(0x46, "current animation frame"),
191 NIV(0x47, "xy coordinate of the building"),
192 NIV(0x60, "other building counts (old house type)"),
193 NIV(0x61, "other building counts (new house type)"),
194 NIV(0x62, "land info of nearby tiles"),
195 NIV(0x63, "current animation frame of nearby house tile"),
196 NIV(0x64, "cargo acceptance history of nearby stations"),
197 NIV(0x65, "distance of nearest house matching a given criterion"),
198 NIV(0x66, "class and ID of nearby house tile"),
199 NIV(0x67, "GRFID of nearby house tile"),
200 NIV_END()
203 class NIHHouse : public NIHelper {
204 bool IsInspectable(uint index) const override { return HouseSpec::Get(GetHouseType(index))->grf_prop.grffile != nullptr; }
205 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, GetTownIndex(index)); }
206 const void *GetInstance(uint)const override { return nullptr; }
207 const void *GetSpec(uint index) const override { return HouseSpec::Get(GetHouseType(index)); }
208 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), index); }
209 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grffile->grfid : 0; }
211 uint Resolve(uint index, uint var, uint param, bool &avail) const override
213 HouseResolverObject ro(GetHouseType(index), index, Town::GetByTile(index));
214 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
218 static const NIFeature _nif_house = {
219 nullptr,
220 _nic_house,
221 _niv_house,
222 new NIHHouse(),
226 /*** NewGRF industry tiles ***/
228 #define NICIT(cb_id, bit) NIC(cb_id, IndustryTileSpec, callback_mask, bit)
229 static const NICallback _nic_industrytiles[] = {
230 NICIT(CBID_INDTILE_ANIM_START_STOP, CBM_NO_BIT),
231 NICIT(CBID_INDTILE_ANIM_NEXT_FRAME, CBM_INDT_ANIM_NEXT_FRAME),
232 NICIT(CBID_INDTILE_ANIMATION_SPEED, CBM_INDT_ANIM_SPEED),
233 NICIT(CBID_INDTILE_CARGO_ACCEPTANCE, CBM_INDT_CARGO_ACCEPTANCE),
234 NICIT(CBID_INDTILE_ACCEPT_CARGO, CBM_INDT_ACCEPT_CARGO),
235 NICIT(CBID_INDTILE_SHAPE_CHECK, CBM_INDT_SHAPE_CHECK),
236 NICIT(CBID_INDTILE_DRAW_FOUNDATIONS, CBM_INDT_DRAW_FOUNDATIONS),
237 NICIT(CBID_INDTILE_AUTOSLOPE, CBM_INDT_AUTOSLOPE),
238 NIC_END()
241 static const NIVariable _niv_industrytiles[] = {
242 NIV(0x40, "construction state of tile"),
243 NIV(0x41, "ground type"),
244 NIV(0x42, "current town zone in nearest town"),
245 NIV(0x43, "relative position"),
246 NIV(0x44, "animation frame"),
247 NIV(0x60, "land info of nearby tiles"),
248 NIV(0x61, "animation stage of nearby tiles"),
249 NIV(0x62, "get industry or airport tile ID at offset"),
250 NIV_END()
253 class NIHIndustryTile : public NIHelper {
254 bool IsInspectable(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile != nullptr; }
255 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_INDUSTRIES, GetIndustryIndex(index)); }
256 const void *GetInstance(uint)const override { return nullptr; }
257 const void *GetSpec(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index)); }
258 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); }
259 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile->grfid : 0; }
261 uint Resolve(uint index, uint var, uint param, bool &avail) const override
263 IndustryTileResolverObject ro(GetIndustryGfx(index), index, Industry::GetByTile(index));
264 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
268 static const NIFeature _nif_industrytile = {
269 nullptr,
270 _nic_industrytiles,
271 _niv_industrytiles,
272 new NIHIndustryTile(),
276 /*** NewGRF industries ***/
277 #define NIP_PRODUCED_CARGO(prop, base, slot, type, name) { name, [] (const void *b) -> const void * { return std::addressof(static_cast<const base *>(b)->GetProduced(slot).cargo); }, sizeof(CargoID), prop, type }
278 #define NIP_ACCEPTED_CARGO(prop, base, slot, type, name) { name, [] (const void *b) -> const void * { return std::addressof(static_cast<const base *>(b)->GetAccepted(slot).cargo); }, sizeof(CargoID), prop, type }
280 static const NIProperty _nip_industries[] = {
281 NIP_PRODUCED_CARGO(0x25, Industry, 0, NIT_CARGO, "produced cargo 0"),
282 NIP_PRODUCED_CARGO(0x25, Industry, 1, NIT_CARGO, "produced cargo 1"),
283 NIP_PRODUCED_CARGO(0x25, Industry, 2, NIT_CARGO, "produced cargo 2"),
284 NIP_PRODUCED_CARGO(0x25, Industry, 3, NIT_CARGO, "produced cargo 3"),
285 NIP_PRODUCED_CARGO(0x25, Industry, 4, NIT_CARGO, "produced cargo 4"),
286 NIP_PRODUCED_CARGO(0x25, Industry, 5, NIT_CARGO, "produced cargo 5"),
287 NIP_PRODUCED_CARGO(0x25, Industry, 6, NIT_CARGO, "produced cargo 6"),
288 NIP_PRODUCED_CARGO(0x25, Industry, 7, NIT_CARGO, "produced cargo 7"),
289 NIP_PRODUCED_CARGO(0x25, Industry, 8, NIT_CARGO, "produced cargo 8"),
290 NIP_PRODUCED_CARGO(0x25, Industry, 9, NIT_CARGO, "produced cargo 9"),
291 NIP_PRODUCED_CARGO(0x25, Industry, 10, NIT_CARGO, "produced cargo 10"),
292 NIP_PRODUCED_CARGO(0x25, Industry, 11, NIT_CARGO, "produced cargo 11"),
293 NIP_PRODUCED_CARGO(0x25, Industry, 12, NIT_CARGO, "produced cargo 12"),
294 NIP_PRODUCED_CARGO(0x25, Industry, 13, NIT_CARGO, "produced cargo 13"),
295 NIP_PRODUCED_CARGO(0x25, Industry, 14, NIT_CARGO, "produced cargo 14"),
296 NIP_PRODUCED_CARGO(0x25, Industry, 15, NIT_CARGO, "produced cargo 15"),
297 NIP_ACCEPTED_CARGO(0x26, Industry, 0, NIT_CARGO, "accepted cargo 0"),
298 NIP_ACCEPTED_CARGO(0x26, Industry, 1, NIT_CARGO, "accepted cargo 1"),
299 NIP_ACCEPTED_CARGO(0x26, Industry, 2, NIT_CARGO, "accepted cargo 2"),
300 NIP_ACCEPTED_CARGO(0x26, Industry, 3, NIT_CARGO, "accepted cargo 3"),
301 NIP_ACCEPTED_CARGO(0x26, Industry, 4, NIT_CARGO, "accepted cargo 4"),
302 NIP_ACCEPTED_CARGO(0x26, Industry, 5, NIT_CARGO, "accepted cargo 5"),
303 NIP_ACCEPTED_CARGO(0x26, Industry, 6, NIT_CARGO, "accepted cargo 6"),
304 NIP_ACCEPTED_CARGO(0x26, Industry, 7, NIT_CARGO, "accepted cargo 7"),
305 NIP_ACCEPTED_CARGO(0x26, Industry, 8, NIT_CARGO, "accepted cargo 8"),
306 NIP_ACCEPTED_CARGO(0x26, Industry, 9, NIT_CARGO, "accepted cargo 9"),
307 NIP_ACCEPTED_CARGO(0x26, Industry, 10, NIT_CARGO, "accepted cargo 10"),
308 NIP_ACCEPTED_CARGO(0x26, Industry, 11, NIT_CARGO, "accepted cargo 11"),
309 NIP_ACCEPTED_CARGO(0x26, Industry, 12, NIT_CARGO, "accepted cargo 12"),
310 NIP_ACCEPTED_CARGO(0x26, Industry, 13, NIT_CARGO, "accepted cargo 13"),
311 NIP_ACCEPTED_CARGO(0x26, Industry, 14, NIT_CARGO, "accepted cargo 14"),
312 NIP_ACCEPTED_CARGO(0x26, Industry, 15, NIT_CARGO, "accepted cargo 15"),
313 NIP_END()
316 #undef NIP_PRODUCED_CARGO
317 #undef NIP_ACCEPTED_CARGO
319 #define NICI(cb_id, bit) NIC(cb_id, IndustrySpec, callback_mask, bit)
320 static const NICallback _nic_industries[] = {
321 NICI(CBID_INDUSTRY_PROBABILITY, CBM_IND_PROBABILITY),
322 NICI(CBID_INDUSTRY_LOCATION, CBM_IND_LOCATION),
323 NICI(CBID_INDUSTRY_PRODUCTION_CHANGE, CBM_IND_PRODUCTION_CHANGE),
324 NICI(CBID_INDUSTRY_MONTHLYPROD_CHANGE, CBM_IND_MONTHLYPROD_CHANGE),
325 NICI(CBID_INDUSTRY_CARGO_SUFFIX, CBM_IND_CARGO_SUFFIX),
326 NICI(CBID_INDUSTRY_FUND_MORE_TEXT, CBM_IND_FUND_MORE_TEXT),
327 NICI(CBID_INDUSTRY_WINDOW_MORE_TEXT, CBM_IND_WINDOW_MORE_TEXT),
328 NICI(CBID_INDUSTRY_SPECIAL_EFFECT, CBM_IND_SPECIAL_EFFECT),
329 NICI(CBID_INDUSTRY_REFUSE_CARGO, CBM_IND_REFUSE_CARGO),
330 NICI(CBID_INDUSTRY_DECIDE_COLOUR, CBM_IND_DECIDE_COLOUR),
331 NICI(CBID_INDUSTRY_INPUT_CARGO_TYPES, CBM_IND_INPUT_CARGO_TYPES),
332 NICI(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, CBM_IND_OUTPUT_CARGO_TYPES),
333 NICI(CBID_INDUSTRY_PROD_CHANGE_BUILD, CBM_IND_PROD_CHANGE_BUILD),
334 NIC_END()
337 static const NIVariable _niv_industries[] = {
338 NIV(0x40, "waiting cargo 0"),
339 NIV(0x41, "waiting cargo 1"),
340 NIV(0x42, "waiting cargo 2"),
341 NIV(0x43, "distance to closest dry/land tile"),
342 NIV(0x44, "layout number"),
343 NIV(0x45, "player info"),
344 NIV(0x46, "industry construction date"),
345 NIV(0x60, "get industry tile ID at offset"),
346 NIV(0x61, "get random tile bits at offset"),
347 NIV(0x62, "land info of nearby tiles"),
348 NIV(0x63, "animation stage of nearby tiles"),
349 NIV(0x64, "distance on nearest industry with given type"),
350 NIV(0x65, "get town zone and Manhattan distance of closest town"),
351 NIV(0x66, "get square of Euclidean distance of closes town"),
352 NIV(0x67, "count of industry and distance of closest instance"),
353 NIV(0x68, "count of industry and distance of closest instance with layout filter"),
354 NIV(0x69, "produced cargo waiting"),
355 NIV(0x6A, "cargo produced this month"),
356 NIV(0x6B, "cargo transported this month"),
357 NIV(0x6C, "cargo produced last month"),
358 NIV(0x6D, "cargo transported last month"),
359 NIV(0x6E, "date since cargo was delivered"),
360 NIV(0x6F, "waiting input cargo"),
361 NIV(0x70, "production rate"),
362 NIV(0x71, "percentage of cargo transported last month"),
363 NIV_END()
366 class NIHIndustry : public NIHelper {
367 bool IsInspectable(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile != nullptr; }
368 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
369 const void *GetInstance(uint index)const override { return Industry::Get(index); }
370 const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); }
371 void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
372 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; }
374 uint Resolve(uint index, uint var, uint param, bool &avail) const override
376 Industry *i = Industry::Get(index);
377 IndustriesResolverObject ro(i->location.tile, i, i->type);
378 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
381 const std::span<int32_t> GetPSA(uint index, uint32_t) const override
383 const Industry *i = (const Industry *)this->GetInstance(index);
384 if (i->psa == nullptr) return {};
385 return i->psa->storage;
389 static const NIFeature _nif_industry = {
390 _nip_industries,
391 _nic_industries,
392 _niv_industries,
393 new NIHIndustry(),
397 /*** NewGRF objects ***/
399 #define NICO(cb_id, bit) NIC(cb_id, ObjectSpec, callback_mask, bit)
400 static const NICallback _nic_objects[] = {
401 NICO(CBID_OBJECT_LAND_SLOPE_CHECK, CBM_OBJ_SLOPE_CHECK),
402 NICO(CBID_OBJECT_ANIMATION_NEXT_FRAME, CBM_OBJ_ANIMATION_NEXT_FRAME),
403 NICO(CBID_OBJECT_ANIMATION_START_STOP, CBM_NO_BIT),
404 NICO(CBID_OBJECT_ANIMATION_SPEED, CBM_OBJ_ANIMATION_SPEED),
405 NICO(CBID_OBJECT_COLOUR, CBM_OBJ_COLOUR),
406 NICO(CBID_OBJECT_FUND_MORE_TEXT, CBM_OBJ_FUND_MORE_TEXT),
407 NICO(CBID_OBJECT_AUTOSLOPE, CBM_OBJ_AUTOSLOPE),
408 NIC_END()
411 static const NIVariable _niv_objects[] = {
412 NIV(0x40, "relative position"),
413 NIV(0x41, "tile information"),
414 NIV(0x42, "construction date"),
415 NIV(0x43, "animation counter"),
416 NIV(0x44, "object founder"),
417 NIV(0x45, "get town zone and Manhattan distance of closest town"),
418 NIV(0x46, "get square of Euclidean distance of closes town"),
419 NIV(0x47, "colour"),
420 NIV(0x48, "view"),
421 NIV(0x60, "get object ID at offset"),
422 NIV(0x61, "get random tile bits at offset"),
423 NIV(0x62, "land info of nearby tiles"),
424 NIV(0x63, "animation stage of nearby tiles"),
425 NIV(0x64, "distance on nearest object with given type"),
426 NIV_END()
429 class NIHObject : public NIHelper {
430 bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(index)->grf_prop.grffile != nullptr; }
431 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(index)->town->index); }
432 const void *GetInstance(uint index)const override { return Object::GetByTile(index); }
433 const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(index); }
434 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); }
435 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grffile->grfid : 0; }
437 uint Resolve(uint index, uint var, uint param, bool &avail) const override
439 ObjectResolverObject ro(ObjectSpec::GetByTile(index), Object::GetByTile(index), index);
440 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
444 static const NIFeature _nif_object = {
445 nullptr,
446 _nic_objects,
447 _niv_objects,
448 new NIHObject(),
452 /*** NewGRF rail types ***/
454 static const NIVariable _niv_railtypes[] = {
455 NIV(0x40, "terrain type"),
456 NIV(0x41, "enhanced tunnels"),
457 NIV(0x42, "level crossing status"),
458 NIV(0x43, "construction date"),
459 NIV(0x44, "town zone"),
460 NIV_END()
463 class NIHRailType : public NIHelper {
464 bool IsInspectable(uint) const override { return true; }
465 uint GetParent(uint) const override { return UINT32_MAX; }
466 const void *GetInstance(uint) const override { return nullptr; }
467 const void *GetSpec(uint) const override { return nullptr; }
468 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); }
469 uint32_t GetGRFID(uint) const override { return 0; }
471 uint Resolve(uint index, uint var, uint param, bool &avail) const override
473 /* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
474 * However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
475 RailTypeResolverObject ro(nullptr, index, TCX_NORMAL, RTSG_END);
476 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
480 static const NIFeature _nif_railtype = {
481 nullptr,
482 nullptr,
483 _niv_railtypes,
484 new NIHRailType(),
488 /*** NewGRF airport tiles ***/
490 #define NICAT(cb_id, bit) NIC(cb_id, AirportTileSpec, callback_mask, bit)
491 static const NICallback _nic_airporttiles[] = {
492 NICAT(CBID_AIRPTILE_DRAW_FOUNDATIONS, CBM_AIRT_DRAW_FOUNDATIONS),
493 NICAT(CBID_AIRPTILE_ANIM_START_STOP, CBM_NO_BIT),
494 NICAT(CBID_AIRPTILE_ANIM_NEXT_FRAME, CBM_AIRT_ANIM_NEXT_FRAME),
495 NICAT(CBID_AIRPTILE_ANIMATION_SPEED, CBM_AIRT_ANIM_SPEED),
496 NIC_END()
499 class NIHAirportTile : public NIHelper {
500 bool IsInspectable(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile != nullptr; }
501 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_AIRPORTS, GetStationIndex(index)); }
502 const void *GetInstance(uint)const override { return nullptr; }
503 const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); }
504 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
505 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile->grfid : 0; }
507 uint Resolve(uint index, uint var, uint param, bool &avail) const override
509 AirportTileResolverObject ro(AirportTileSpec::GetByTile(index), index, Station::GetByTile(index));
510 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
514 static const NIFeature _nif_airporttile = {
515 nullptr,
516 _nic_airporttiles,
517 _niv_industrytiles, // Yes, they share this (at least now)
518 new NIHAirportTile(),
522 /*** NewGRF airports ***/
524 static const NIVariable _niv_airports[] = {
525 NIV(0x40, "Layout number"),
526 NIV(0x48, "bitmask of accepted cargoes"),
527 NIV(0x60, "amount of cargo waiting"),
528 NIV(0x61, "time since last cargo pickup"),
529 NIV(0x62, "rating of cargo"),
530 NIV(0x63, "time spent on route"),
531 NIV(0x64, "information about last vehicle picking cargo up"),
532 NIV(0x65, "amount of cargo acceptance"),
533 NIV(0x69, "information about cargo accepted in the past"),
534 NIV(0xF1, "type of the airport"),
535 NIV(0xF6, "airport block status"),
536 NIV(0xFA, "built date"),
537 NIV_END()
540 class NIHAirport : public NIHelper {
541 bool IsInspectable(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile != nullptr; }
542 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::Get(index)->town->index); }
543 const void *GetInstance(uint index)const override { return Station::Get(index); }
544 const void *GetSpec(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type); }
545 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, index, Station::Get(index)->airport.tile); }
546 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile->grfid : 0; }
548 uint Resolve(uint index, uint var, uint param, bool &avail) const override
550 Station *st = Station::Get(index);
551 AirportResolverObject ro(st->airport.tile, st, AirportSpec::Get(st->airport.type), st->airport.layout);
552 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
555 const std::span<int32_t> GetPSA(uint index, uint32_t) const override
557 const Station *st = (const Station *)this->GetInstance(index);
558 if (st->airport.psa == nullptr) return {};
559 return st->airport.psa->storage;
563 static const NIFeature _nif_airport = {
564 nullptr,
565 nullptr,
566 _niv_airports,
567 new NIHAirport(),
571 /*** NewGRF towns ***/
573 static const NIVariable _niv_towns[] = {
574 NIV(0x40, "larger town effect on this town"),
575 NIV(0x41, "town index"),
576 NIV(0x82, "population"),
577 NIV(0x94, "zone radius 0"),
578 NIV(0x96, "zone radius 1"),
579 NIV(0x98, "zone radius 2"),
580 NIV(0x9A, "zone radius 3"),
581 NIV(0x9C, "zone radius 4"),
582 NIV(0xB6, "number of buildings"),
583 NIV_END()
586 class NIHTown : public NIHelper {
587 bool IsInspectable(uint index) const override { return Town::IsValidID(index); }
588 uint GetParent(uint) const override { return UINT32_MAX; }
589 const void *GetInstance(uint index)const override { return Town::Get(index); }
590 const void *GetSpec(uint) const override { return nullptr; }
591 void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_TOWN_NAME, index); }
592 uint32_t GetGRFID(uint) const override { return 0; }
593 bool PSAWithParameter() const override { return true; }
595 uint Resolve(uint index, uint var, uint param, bool &avail) const override
597 TownResolverObject ro(nullptr, Town::Get(index), true);
598 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
601 const std::span<int32_t> GetPSA(uint index, uint32_t grfid) const override
603 Town *t = Town::Get(index);
605 for (const auto &it : t->psa_list) {
606 if (it->grfid == grfid) return it->storage;
609 return {};
613 static const NIFeature _nif_town = {
614 nullptr,
615 nullptr,
616 _niv_towns,
617 new NIHTown(),
620 /*** NewGRF road types ***/
622 static const NIVariable _niv_roadtypes[] = {
623 NIV(0x40, "terrain type"),
624 NIV(0x41, "enhanced tunnels"),
625 NIV(0x42, "level crossing status"),
626 NIV(0x43, "construction date"),
627 NIV(0x44, "town zone"),
628 NIV_END()
631 class NIHRoadType : public NIHelper {
632 bool IsInspectable(uint) const override { return true; }
633 uint GetParent(uint) const override { return UINT32_MAX; }
634 const void *GetInstance(uint) const override { return nullptr; }
635 const void *GetSpec(uint) const override { return nullptr; }
636 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE, INVALID_STRING_ID, index); }
637 uint32_t GetGRFID(uint) const override { return 0; }
639 uint Resolve(uint index, uint var, uint param, bool &avail) const override
641 /* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
642 * However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
643 RoadTypeResolverObject ro(nullptr, index, TCX_NORMAL, ROTSG_END);
644 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
648 static const NIFeature _nif_roadtype = {
649 nullptr,
650 nullptr,
651 _niv_roadtypes,
652 new NIHRoadType(),
655 static const NIFeature _nif_tramtype = {
656 nullptr,
657 nullptr,
658 _niv_roadtypes,
659 new NIHRoadType(),
662 #define NICRS(cb_id, bit) NIC(cb_id, RoadStopSpec, callback_mask, bit)
663 static const NICallback _nic_roadstops[] = {
664 NICRS(CBID_STATION_AVAILABILITY, CBM_ROAD_STOP_AVAIL),
665 NICRS(CBID_STATION_ANIM_START_STOP, CBM_NO_BIT),
666 NICRS(CBID_STATION_ANIM_NEXT_FRAME, CBM_ROAD_STOP_ANIMATION_NEXT_FRAME),
667 NICRS(CBID_STATION_ANIMATION_SPEED, CBM_ROAD_STOP_ANIMATION_SPEED),
668 NIC_END()
671 static const NIVariable _nif_roadstops[] = {
672 NIV(0x40, "view/rotation"),
673 NIV(0x41, "stop type"),
674 NIV(0x42, "terrain type"),
675 NIV(0x43, "road type"),
676 NIV(0x44, "tram type"),
677 NIV(0x45, "town zone and Manhattan distance of town"),
678 NIV(0x46, "square of Euclidean distance of town"),
679 NIV(0x47, "player info"),
680 NIV(0x48, "bitmask of accepted cargoes"),
681 NIV(0x49, "current animation frame"),
682 NIV(0x60, "amount of cargo waiting"),
683 NIV(0x61, "time since last cargo pickup"),
684 NIV(0x62, "rating of cargo"),
685 NIV(0x63, "time spent on route"),
686 NIV(0x64, "information about last vehicle picking cargo up"),
687 NIV(0x65, "amount of cargo acceptance"),
688 NIV(0x66, "animation frame of nearby tile"),
689 NIV(0x67, "land info of nearby tiles"),
690 NIV(0x68, "road stop info of nearby tiles"),
691 NIV(0x69, "information about cargo accepted in the past"),
692 NIV(0x6A, "GRFID of nearby road stop tiles"),
693 NIV(0x6B, "road stop ID of nearby tiles"),
694 NIV_END(),
697 class NIHRoadStop : public NIHelper {
698 bool IsInspectable(uint index) const override { return GetRoadStopSpec(index) != nullptr; }
699 uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, BaseStation::GetByTile(index)->town->index); }
700 const void *GetInstance(uint)const override { return nullptr; }
701 const void *GetSpec(uint index) const override { return GetRoadStopSpec(index); }
702 void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
703 uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grffile->grfid : 0; }
705 uint Resolve(uint index, uint var, uint32_t param, bool &avail) const override
707 int view = GetRoadStopDir(index);
708 if (IsDriveThroughStopTile(index)) view += 4;
709 RoadStopResolverObject ro(GetRoadStopSpec(index), BaseStation::GetByTile(index), index, INVALID_ROADTYPE, GetStationType(index), view);
710 return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
714 static const NIFeature _nif_roadstop = {
715 nullptr,
716 _nic_roadstops,
717 _nif_roadstops,
718 new NIHRoadStop(),
721 /** Table with all NIFeatures. */
722 static const NIFeature * const _nifeatures[] = {
723 &_nif_vehicle, // GSF_TRAINS
724 &_nif_vehicle, // GSF_ROADVEHICLES
725 &_nif_vehicle, // GSF_SHIPS
726 &_nif_vehicle, // GSF_AIRCRAFT
727 &_nif_station, // GSF_STATIONS
728 nullptr, // GSF_CANALS (no callbacks/action2 implemented)
729 nullptr, // GSF_BRIDGES (no callbacks/action2)
730 &_nif_house, // GSF_HOUSES
731 nullptr, // GSF_GLOBALVAR (has no "physical" objects)
732 &_nif_industrytile, // GSF_INDUSTRYTILES
733 &_nif_industry, // GSF_INDUSTRIES
734 nullptr, // GSF_CARGOES (has no "physical" objects)
735 nullptr, // GSF_SOUNDFX (has no "physical" objects)
736 &_nif_airport, // GSF_AIRPORTS
737 nullptr, // GSF_SIGNALS (feature not implemented)
738 &_nif_object, // GSF_OBJECTS
739 &_nif_railtype, // GSF_RAILTYPES
740 &_nif_airporttile, // GSF_AIRPORTTILES
741 &_nif_roadtype, // GSF_ROADTYPES
742 &_nif_tramtype, // GSF_TRAMTYPES
743 &_nif_roadstop, // GSF_ROADSTOPS
744 &_nif_town, // GSF_FAKE_TOWNS
746 static_assert(lengthof(_nifeatures) == GSF_FAKE_END);