OpenTTD
newgrf_debug_data.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 #include "../newgrf_house.h"
11 #include "../newgrf_engine.h"
12 #include "../newgrf_roadtype.h"
13 
14 /* Helper for filling property tables */
15 #define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type }
16 #define NIP_END() { nullptr, 0, 0, 0, 0 }
17 
18 /* Helper for filling callback tables */
19 #define NIC(cb_id, base, variable, bit) { #cb_id, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), bit, cb_id }
20 #define NIC_END() { nullptr, 0, 0, 0, 0 }
21 
22 /* Helper for filling variable tables */
23 #define NIV(var, name) { name, var }
24 #define NIV_END() { nullptr, 0 }
25 
26 
27 /*** NewGRF Vehicles ***/
28 
29 #define NICV(cb_id, bit) NIC(cb_id, Engine, info.callback_mask, bit)
30 static const NICallback _nic_vehicles[] = {
45  NIC_END()
46 };
47 
48 
49 static const NIVariable _niv_vehicles[] = {
50  NIV(0x40, "position in consist and length"),
51  NIV(0x41, "position and length of chain of same vehicles"),
52  NIV(0x42, "transported cargo types"),
53  NIV(0x43, "player info"),
54  NIV(0x44, "aircraft info"),
55  NIV(0x45, "curvature info"),
56  NIV(0x46, "motion counter"),
57  NIV(0x47, "vehicle cargo info"),
58  NIV(0x48, "vehicle type info"),
59  NIV(0x49, "year of construction"),
60  NIV(0x4A, "current rail/road type info"),
61  NIV(0x4B, "long date of last service"),
62  NIV(0x4C, "current max speed"),
63  NIV(0x4D, "position in articulated vehicle"),
64  NIV(0x60, "count vehicle id occurrences"),
65  // 0x61 not useful, since it requires register 0x10F
66  NIV(0x62, "Curvature/position difference to other vehicle"),
67  NIV_END()
68 };
69 
70 class NIHVehicle : public NIHelper {
71  bool IsInspectable(uint index) const override { return Vehicle::Get(index)->GetGRF() != nullptr; }
72  uint GetParent(uint index) const override { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); }
73  const void *GetInstance(uint index)const override { return Vehicle::Get(index); }
74  const void *GetSpec(uint index) const override { return Vehicle::Get(index)->GetEngine(); }
75  void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_VEHICLE_NAME, index); }
76  uint32 GetGRFID(uint index) const override { return Vehicle::Get(index)->GetGRFID(); }
77 
78  uint Resolve(uint index, uint var, uint param, bool *avail) const override
79  {
80  Vehicle *v = Vehicle::Get(index);
82  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
83  }
84 };
85 
86 static const NIFeature _nif_vehicle = {
87  nullptr,
88  _nic_vehicles,
89  _niv_vehicles,
90  new NIHVehicle(),
91 };
92 
93 
94 /*** NewGRF station (tiles) ***/
95 
96 #define NICS(cb_id, bit) NIC(cb_id, StationSpec, callback_mask, bit)
97 static const NICallback _nic_stations[] = {
105  NIC_END()
106 };
107 
108 static const NIVariable _niv_stations[] = {
109  NIV(0x40, "platform info and relative position"),
110  NIV(0x41, "platform info and relative position for individually built sections"),
111  NIV(0x42, "terrain and track type"),
112  NIV(0x43, "player info"),
113  NIV(0x44, "path signalling info"),
114  NIV(0x45, "rail continuation info"),
115  NIV(0x46, "platform info and relative position from middle"),
116  NIV(0x47, "platform info and relative position from middle for individually built sections"),
117  NIV(0x48, "bitmask of accepted cargoes"),
118  NIV(0x49, "platform info and relative position of same-direction section"),
119  NIV(0x4A, "current animation frame"),
120  NIV(0x60, "amount of cargo waiting"),
121  NIV(0x61, "time since last cargo pickup"),
122  NIV(0x62, "rating of cargo"),
123  NIV(0x63, "time spent on route"),
124  NIV(0x64, "information about last vehicle picking cargo up"),
125  NIV(0x65, "amount of cargo acceptance"),
126  NIV(0x66, "animation frame of nearby tile"),
127  NIV(0x67, "land info of nearby tiles"),
128  NIV(0x68, "station info of nearby tiles"),
129  NIV(0x69, "information about cargo accepted in the past"),
130  NIV_END()
131 };
132 
133 class NIHStation : public NIHelper {
134  bool IsInspectable(uint index) const override { return GetStationSpec(index) != nullptr; }
135  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(index)->town->index); }
136  const void *GetInstance(uint index)const override { return nullptr; }
137  const void *GetSpec(uint index) const override { return GetStationSpec(index); }
138  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
139  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grffile->grfid : 0; }
140 
141  uint Resolve(uint index, uint var, uint param, bool *avail) const override
142  {
143  StationResolverObject ro(GetStationSpec(index), Station::GetByTile(index), index);
144  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
145  }
146 };
147 
148 static const NIFeature _nif_station = {
149  nullptr,
150  _nic_stations,
151  _niv_stations,
152  new NIHStation(),
153 };
154 
155 
156 /*** NewGRF house tiles ***/
157 
158 #define NICH(cb_id, bit) NIC(cb_id, HouseSpec, callback_mask, bit)
159 static const NICallback _nic_house[] = {
175  NIC_END()
176 };
177 
178 static const NIVariable _niv_house[] = {
179  NIV(0x40, "construction state of tile and pseudo-random value"),
180  NIV(0x41, "age of building in years"),
181  NIV(0x42, "town zone"),
182  NIV(0x43, "terrain type"),
183  NIV(0x44, "building counts"),
184  NIV(0x45, "town expansion bits"),
185  NIV(0x46, "current animation frame"),
186  NIV(0x47, "xy coordinate of the building"),
187  NIV(0x60, "other building counts (old house type)"),
188  NIV(0x61, "other building counts (new house type)"),
189  NIV(0x62, "land info of nearby tiles"),
190  NIV(0x63, "current animation frame of nearby house tile"),
191  NIV(0x64, "cargo acceptance history of nearby stations"),
192  NIV(0x65, "distance of nearest house matching a given criterion"),
193  NIV(0x66, "class and ID of nearby house tile"),
194  NIV(0x67, "GRFID of nearby house tile"),
195  NIV_END()
196 };
197 
198 class NIHHouse : public NIHelper {
199  bool IsInspectable(uint index) const override { return HouseSpec::Get(GetHouseType(index))->grf_prop.grffile != nullptr; }
200  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, GetTownIndex(index)); }
201  const void *GetInstance(uint index)const override { return nullptr; }
202  const void *GetSpec(uint index) const override { return HouseSpec::Get(GetHouseType(index)); }
203  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), index); }
204  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grffile->grfid : 0; }
205 
206  uint Resolve(uint index, uint var, uint param, bool *avail) const override
207  {
208  HouseResolverObject ro(GetHouseType(index), index, Town::GetByTile(index));
209  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
210  }
211 };
212 
213 static const NIFeature _nif_house = {
214  nullptr,
215  _nic_house,
216  _niv_house,
217  new NIHHouse(),
218 };
219 
220 
221 /*** NewGRF industry tiles ***/
222 
223 #define NICIT(cb_id, bit) NIC(cb_id, IndustryTileSpec, callback_mask, bit)
224 static const NICallback _nic_industrytiles[] = {
233  NIC_END()
234 };
235 
236 static const NIVariable _niv_industrytiles[] = {
237  NIV(0x40, "construction state of tile"),
238  NIV(0x41, "ground type"),
239  NIV(0x42, "current town zone in nearest town"),
240  NIV(0x43, "relative position"),
241  NIV(0x44, "animation frame"),
242  NIV(0x60, "land info of nearby tiles"),
243  NIV(0x61, "animation stage of nearby tiles"),
244  NIV(0x62, "get industry or airport tile ID at offset"),
245  NIV_END()
246 };
247 
248 class NIHIndustryTile : public NIHelper {
249  bool IsInspectable(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile != nullptr; }
250  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_INDUSTRIES, GetIndustryIndex(index)); }
251  const void *GetInstance(uint index)const override { return nullptr; }
252  const void *GetSpec(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index)); }
253  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); }
254  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile->grfid : 0; }
255 
256  uint Resolve(uint index, uint var, uint param, bool *avail) const override
257  {
259  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
260  }
261 };
262 
263 static const NIFeature _nif_industrytile = {
264  nullptr,
265  _nic_industrytiles,
266  _niv_industrytiles,
267  new NIHIndustryTile(),
268 };
269 
270 
271 /*** NewGRF industries ***/
272 
273 static const NIProperty _nip_industries[] = {
274  NIP(0x25, Industry, produced_cargo[ 0], NIT_CARGO, "produced cargo 0"),
275  NIP(0x25, Industry, produced_cargo[ 1], NIT_CARGO, "produced cargo 1"),
276  NIP(0x25, Industry, produced_cargo[ 2], NIT_CARGO, "produced cargo 2"),
277  NIP(0x25, Industry, produced_cargo[ 3], NIT_CARGO, "produced cargo 3"),
278  NIP(0x25, Industry, produced_cargo[ 4], NIT_CARGO, "produced cargo 4"),
279  NIP(0x25, Industry, produced_cargo[ 5], NIT_CARGO, "produced cargo 5"),
280  NIP(0x25, Industry, produced_cargo[ 6], NIT_CARGO, "produced cargo 6"),
281  NIP(0x25, Industry, produced_cargo[ 7], NIT_CARGO, "produced cargo 7"),
282  NIP(0x25, Industry, produced_cargo[ 8], NIT_CARGO, "produced cargo 8"),
283  NIP(0x25, Industry, produced_cargo[ 9], NIT_CARGO, "produced cargo 9"),
284  NIP(0x25, Industry, produced_cargo[10], NIT_CARGO, "produced cargo 10"),
285  NIP(0x25, Industry, produced_cargo[11], NIT_CARGO, "produced cargo 11"),
286  NIP(0x25, Industry, produced_cargo[12], NIT_CARGO, "produced cargo 12"),
287  NIP(0x25, Industry, produced_cargo[13], NIT_CARGO, "produced cargo 13"),
288  NIP(0x25, Industry, produced_cargo[14], NIT_CARGO, "produced cargo 14"),
289  NIP(0x25, Industry, produced_cargo[15], NIT_CARGO, "produced cargo 15"),
290  NIP(0x26, Industry, accepts_cargo[ 0], NIT_CARGO, "accepted cargo 0"),
291  NIP(0x26, Industry, accepts_cargo[ 1], NIT_CARGO, "accepted cargo 1"),
292  NIP(0x26, Industry, accepts_cargo[ 2], NIT_CARGO, "accepted cargo 2"),
293  NIP(0x26, Industry, accepts_cargo[ 3], NIT_CARGO, "accepted cargo 3"),
294  NIP(0x26, Industry, accepts_cargo[ 4], NIT_CARGO, "accepted cargo 4"),
295  NIP(0x26, Industry, accepts_cargo[ 5], NIT_CARGO, "accepted cargo 5"),
296  NIP(0x26, Industry, accepts_cargo[ 6], NIT_CARGO, "accepted cargo 6"),
297  NIP(0x26, Industry, accepts_cargo[ 7], NIT_CARGO, "accepted cargo 7"),
298  NIP(0x26, Industry, accepts_cargo[ 8], NIT_CARGO, "accepted cargo 8"),
299  NIP(0x26, Industry, accepts_cargo[ 9], NIT_CARGO, "accepted cargo 9"),
300  NIP(0x26, Industry, accepts_cargo[10], NIT_CARGO, "accepted cargo 10"),
301  NIP(0x26, Industry, accepts_cargo[11], NIT_CARGO, "accepted cargo 11"),
302  NIP(0x26, Industry, accepts_cargo[12], NIT_CARGO, "accepted cargo 12"),
303  NIP(0x26, Industry, accepts_cargo[13], NIT_CARGO, "accepted cargo 13"),
304  NIP(0x26, Industry, accepts_cargo[14], NIT_CARGO, "accepted cargo 14"),
305  NIP(0x26, Industry, accepts_cargo[15], NIT_CARGO, "accepted cargo 15"),
306  NIP_END()
307 };
308 
309 #define NICI(cb_id, bit) NIC(cb_id, IndustrySpec, callback_mask, bit)
310 static const NICallback _nic_industries[] = {
324  NIC_END()
325 };
326 
327 static const NIVariable _niv_industries[] = {
328  NIV(0x40, "waiting cargo 0"),
329  NIV(0x41, "waiting cargo 1"),
330  NIV(0x42, "waiting cargo 2"),
331  NIV(0x43, "distance to closest dry/land tile"),
332  NIV(0x44, "layout number"),
333  NIV(0x45, "player info"),
334  NIV(0x46, "industry construction date"),
335  NIV(0x60, "get industry tile ID at offset"),
336  NIV(0x61, "get random tile bits at offset"),
337  NIV(0x62, "land info of nearby tiles"),
338  NIV(0x63, "animation stage of nearby tiles"),
339  NIV(0x64, "distance on nearest industry with given type"),
340  NIV(0x65, "get town zone and Manhattan distance of closest town"),
341  NIV(0x66, "get square of Euclidean distance of closes town"),
342  NIV(0x67, "count of industry and distance of closest instance"),
343  NIV(0x68, "count of industry and distance of closest instance with layout filter"),
344  NIV_END()
345 };
346 
347 class NIHIndustry : public NIHelper {
348  bool IsInspectable(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile != nullptr; }
349  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
350  const void *GetInstance(uint index)const override { return Industry::Get(index); }
351  const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); }
352  void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
353  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; }
354 
355  uint Resolve(uint index, uint var, uint param, bool *avail) const override
356  {
357  Industry *i = Industry::Get(index);
359  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
360  }
361 
362  uint GetPSASize(uint index, uint32 grfid) const override { return cpp_lengthof(PersistentStorage, storage); }
363 
364  const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const override
365  {
366  const Industry *i = (const Industry *)this->GetInstance(index);
367  if (i->psa == nullptr) return nullptr;
368  return (int32 *)(&i->psa->storage);
369  }
370 };
371 
372 static const NIFeature _nif_industry = {
373  _nip_industries,
374  _nic_industries,
375  _niv_industries,
376  new NIHIndustry(),
377 };
378 
379 
380 /*** NewGRF objects ***/
381 
382 #define NICO(cb_id, bit) NIC(cb_id, ObjectSpec, callback_mask, bit)
383 static const NICallback _nic_objects[] = {
391  NIC_END()
392 };
393 
394 static const NIVariable _niv_objects[] = {
395  NIV(0x40, "relative position"),
396  NIV(0x41, "tile information"),
397  NIV(0x42, "construction date"),
398  NIV(0x43, "animation counter"),
399  NIV(0x44, "object founder"),
400  NIV(0x45, "get town zone and Manhattan distance of closest town"),
401  NIV(0x46, "get square of Euclidean distance of closes town"),
402  NIV(0x47, "colour"),
403  NIV(0x48, "view"),
404  NIV(0x60, "get object ID at offset"),
405  NIV(0x61, "get random tile bits at offset"),
406  NIV(0x62, "land info of nearby tiles"),
407  NIV(0x63, "animation stage of nearby tiles"),
408  NIV(0x64, "distance on nearest object with given type"),
409  NIV_END()
410 };
411 
412 class NIHObject : public NIHelper {
413  bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(index)->grf_prop.grffile != nullptr; }
414  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(index)->town->index); }
415  const void *GetInstance(uint index)const override { return Object::GetByTile(index); }
416  const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(index); }
417  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); }
418  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grffile->grfid : 0; }
419 
420  uint Resolve(uint index, uint var, uint param, bool *avail) const override
421  {
423  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
424  }
425 };
426 
427 static const NIFeature _nif_object = {
428  nullptr,
429  _nic_objects,
430  _niv_objects,
431  new NIHObject(),
432 };
433 
434 
435 /*** NewGRF rail types ***/
436 
437 static const NIVariable _niv_railtypes[] = {
438  NIV(0x40, "terrain type"),
439  NIV(0x41, "enhanced tunnels"),
440  NIV(0x42, "level crossing status"),
441  NIV(0x43, "construction date"),
442  NIV(0x44, "town zone"),
443  NIV_END()
444 };
445 
446 class NIHRailType : public NIHelper {
447  bool IsInspectable(uint index) const override { return true; }
448  uint GetParent(uint index) const override { return UINT32_MAX; }
449  const void *GetInstance(uint index)const override { return nullptr; }
450  const void *GetSpec(uint index) const override { return nullptr; }
451  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); }
452  uint32 GetGRFID(uint index) const override { return 0; }
453 
454  uint Resolve(uint index, uint var, uint param, bool *avail) const override
455  {
456  /* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
457  * However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
458  RailTypeResolverObject ro(nullptr, index, TCX_NORMAL, RTSG_END);
459  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
460  }
461 };
462 
463 static const NIFeature _nif_railtype = {
464  nullptr,
465  nullptr,
466  _niv_railtypes,
467  new NIHRailType(),
468 };
469 
470 
471 /*** NewGRF airport tiles ***/
472 
473 #define NICAT(cb_id, bit) NIC(cb_id, AirportTileSpec, callback_mask, bit)
474 static const NICallback _nic_airporttiles[] = {
479  NIC_END()
480 };
481 
482 class NIHAirportTile : public NIHelper {
483  bool IsInspectable(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile != nullptr; }
484  uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::GetByTile(index)->town->index); }
485  const void *GetInstance(uint index)const override { return nullptr; }
486  const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); }
487  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
488  uint32 GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile->grfid : 0; }
489 
490  uint Resolve(uint index, uint var, uint param, bool *avail) const override
491  {
493  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
494  }
495 };
496 
497 static const NIFeature _nif_airporttile = {
498  nullptr,
499  _nic_airporttiles,
500  _niv_industrytiles, // Yes, they share this (at least now)
501  new NIHAirportTile(),
502 };
503 
504 
505 /*** NewGRF towns ***/
506 
507 static const NIVariable _niv_towns[] = {
508  NIV(0x40, "larger town effect on this town"),
509  NIV(0x41, "town index"),
510  NIV(0x82, "population"),
511  NIV(0x94, "zone radius 0"),
512  NIV(0x96, "zone radius 1"),
513  NIV(0x98, "zone radius 2"),
514  NIV(0x9A, "zone radius 3"),
515  NIV(0x9C, "zone radius 4"),
516  NIV(0xB6, "number of buildings"),
517  NIV_END()
518 };
519 
520 class NIHTown : public NIHelper {
521  bool IsInspectable(uint index) const override { return Town::IsValidID(index); }
522  uint GetParent(uint index) const override { return UINT32_MAX; }
523  const void *GetInstance(uint index)const override { return Town::Get(index); }
524  const void *GetSpec(uint index) const override { return nullptr; }
525  void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_TOWN_NAME, index); }
526  uint32 GetGRFID(uint index) const override { return 0; }
527  bool PSAWithParameter() const override { return true; }
528  uint GetPSASize(uint index, uint32 grfid) const override { return cpp_lengthof(PersistentStorage, storage); }
529 
530  uint Resolve(uint index, uint var, uint param, bool *avail) const override
531  {
532  TownResolverObject ro(nullptr, Town::Get(index), true);
533  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
534  }
535 
536  const int32 *GetPSAFirstPosition(uint index, uint32 grfid) const override
537  {
538  Town *t = Town::Get(index);
539 
540  std::list<PersistentStorage *>::iterator iter;
541  for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) {
542  if ((*iter)->grfid == grfid) return (int32 *)(&(*iter)->storage[0]);
543  }
544 
545  return nullptr;
546  }
547 };
548 
549 static const NIFeature _nif_town = {
550  nullptr,
551  nullptr,
552  _niv_towns,
553  new NIHTown(),
554 };
555 
556 /*** NewGRF road types ***/
557 
558 static const NIVariable _niv_roadtypes[] = {
559  NIV(0x40, "terrain type"),
560  NIV(0x41, "enhanced tunnels"),
561  NIV(0x42, "level crossing status"),
562  NIV(0x43, "construction date"),
563  NIV(0x44, "town zone"),
564  NIV_END()
565 };
566 
567 class NIHRoadType : public NIHelper {
568  bool IsInspectable(uint index) const override { return true; }
569  uint GetParent(uint index) const override { return UINT32_MAX; }
570  const void *GetInstance(uint index) const override { return nullptr; }
571  const void *GetSpec(uint index) const override { return nullptr; }
572  void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); }
573  uint32 GetGRFID(uint index) const override { return 0; }
574 
575  uint Resolve(uint index, uint var, uint param, bool *avail) const override
576  {
577  /* There is no unique GRFFile for the tile. Multiple GRFs can define different parts of the railtype.
578  * However, currently the NewGRF Debug GUI does not display variables depending on the GRF (like 0x7F) anyway. */
579  RoadTypeResolverObject ro(nullptr, index, TCX_NORMAL, ROTSG_END);
580  return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
581  }
582 };
583 
584 static const NIFeature _nif_roadtype = {
585  nullptr,
586  nullptr,
587  _niv_roadtypes,
588  new NIHRoadType(),
589 };
590 
591 static const NIFeature _nif_tramtype = {
592  nullptr,
593  nullptr,
594  _niv_roadtypes,
595  new NIHRoadType(),
596 };
597 
599 static const NIFeature * const _nifeatures[] = {
600  &_nif_vehicle, // GSF_TRAINS
601  &_nif_vehicle, // GSF_ROADVEHICLES
602  &_nif_vehicle, // GSF_SHIPS
603  &_nif_vehicle, // GSF_AIRCRAFT
604  &_nif_station, // GSF_STATIONS
605  nullptr, // GSF_CANALS (no callbacks/action2 implemented)
606  nullptr, // GSF_BRIDGES (no callbacks/action2)
607  &_nif_house, // GSF_HOUSES
608  nullptr, // GSF_GLOBALVAR (has no "physical" objects)
609  &_nif_industrytile, // GSF_INDUSTRYTILES
610  &_nif_industry, // GSF_INDUSTRIES
611  nullptr, // GSF_CARGOES (has no "physical" objects)
612  nullptr, // GSF_SOUNDFX (has no "physical" objects)
613  nullptr, // GSF_AIRPORTS (feature not implemented)
614  nullptr, // GSF_SIGNALS (feature not implemented)
615  &_nif_object, // GSF_OBJECTS
616  &_nif_railtype, // GSF_RAILTYPES
617  &_nif_airporttile, // GSF_AIRPORTTILES
618  &_nif_roadtype, // GSF_ROADTYPES
619  &_nif_tramtype, // GSF_TRAMTYPES
620  &_nif_town, // GSF_FAKE_TOWNS
621 };
622 assert_compile(lengthof(_nifeatures) == GSF_FAKE_END);
Resolver of town properties.
Definition: newgrf_town.h:42
customize the cargoes the industry produces
initialise production level on construction
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
Called to determine if the given industry can be built on specific area.
Use callback to select a sprite layout to use.
Resolver object for rail types.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
decides next animation frame
decides accepted types
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
decides animation speed
Called to determine airport tile next animation frame.
const void * GetInstance(uint index) const override
Get the instance given an index.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
Called to determine more text in the fund object window.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
decides animation speed
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
static const AirportTileSpec * GetByTile(TileIndex tile)
Retrieve airport tile spec for the given airport tile.
Called to determine if one can alter the ground below a house tile.
const void * GetInstance(uint index) const override
Get the instance given an index.
Called to determine if the given industry tile can be built on specific tile.
void SetSimpleStringParameters(StringID string, uint32 index) const
Helper to make setting the strings easier.
Customize the input cargo types of a newly build industry.
static IndustryGfx GetIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile.
Definition: industry_map.h:137
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:60
Builds articulated engines for trains and RVs.
Representation on the NewGRF variables.
Called periodically to determine if a house should be destroyed.
Called to indicate how long the current animation frame should last.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
Return the vehicles this given vehicle can be "upgraded" to.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called monthly on production changes, so it can be adjusted more frequently.
Called for periodically starting or stopping the animation.
additional text in fund window
Called when the company (or AI) tries to start or stop a vehicle.
Vehicle data structure.
Definition: vehicle_base.h:210
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Defines the internal data of a functional industry.
Definition: industry.h:40
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
static uint GetInspectWindowNumber(GrfSpecFeature feature, uint index)
Get the window number for the inspect window given a feature and index.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
static StationGfx GetAirportGfx(TileIndex t)
Get the station graphics of this airport tile.
Definition: station_map.h:244
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
The property is a cargo.
Determine the next animation frame for a house.
Cargo capacity after refit.
check industry construction on given area
change animation when construction state changes
Resolver object to be used for houses (feature 07 spritegroups).
Definition: newgrf_house.h:51
Determine whether a wagon can be attached to an already existing train.
Called to determine whether a town building can be destroyed.
Called to determine which cargoes a town building should accept.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Visual effects and wagon power.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
Nothing special.
const void * GetInstance(uint index) const override
Get the instance given an index.
Called to indicate how long the current animation frame should last.
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Determine the cargo "suffixes" for each refit possibility of a cargo.
Callback done for each tile of an object to check the slope.
control special effects
Vehicle uses custom sound effects.
Use a custom next frame callback.
Determine whether a newstation should be made available to build.
decides animation speed
decides amount of cargo acceptance
const void * GetInstance(uint index) const override
Get the instance given an index.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called to determine more text in the fund industry window.
Representation of the available callbacks with information on when they actually apply.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called to determine the type (if any) of foundation to draw for house tile.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Callback done for each tile of a station to check the slope.
decides allowance of autosloping
Called to determine the colour of a town building.
const void * GetInstance(uint index) const override
Get the instance given an index.
Fake town GrfSpecFeature for NewGRF debugging (parent scope)
Definition: newgrf.h:89
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
static const NIFeature *const _nifeatures[]
Table with all NIFeatures.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
This callback is called from vehicle purchase lists.
Resolver for industry tiles.
Called on the Get Tile Description for an house tile.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
Customize the output cargo types of a newly build industry.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
Called when a cargo type specified in property 20 is accepted.
decides if default foundations need to be drawn
Called to indicate how long the current animation frame should last.
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:74
Customize the animation speed of the station.
Called to play a special sound effect.
Called to determine if the given industry type is available.
Resolver for tiles of an airport.
controls random production change
decides next animation frame
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:22
bool PSAWithParameter() const override
Used to decide if the PSA needs a parameter or not.
const void * GetInstance(uint index) const override
Get the instance given an index.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
decides if default foundations need to be drawn
Called to modify various vehicle properties.
Called to determine if industry can alter the ground below industry tile.
custom cargo production
Called to determine the type (if any) of foundation to draw for industry tile.
Resolver for a vehicle (chain)
Definition: newgrf_engine.h:47
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
trigger destruction of building
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
const int32 * GetPSAFirstPosition(uint index, uint32 grfid) const override
Gets the first position of the array containing the persistent storage.
Show suffix after cargo name.
Called to indicate how long the current animation frame should last.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
IndustryType type
type of industry.
Definition: industry.h:57
Vehicle length (trains and road vehicles)
decide the colour of the building
Called for periodically starting or stopping the animation.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
decides amount of cargo acceptance
void SetObjectAtStringParameters(StringID string, uint32 index, TileIndex tile) const
Helper to make setting the strings easier for objects at a specific tile.
TileArea location
Location of the industry.
Definition: industry.h:41
TYPE storage[SIZE]
Memory to for the storage array.
additional text in industry window
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
End of the fake features.
Definition: newgrf.h:90
Change colour mapping of vehicle.
Class for pooled persistent storage of data.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
decides allowance of autosloping
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:171
decides next animation frame
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
customize the cargoes the industry requires
additional text in fund window
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
decides animation speed
Called when building a station to customize the tile layout.
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
periodically start/stop the animation
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:140
const void * GetInstance(uint index) const override
Get the instance given an index.
Resolved object itself.
decide the colour of the building
decides accepted types
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
Called to determine if the industry can still accept or refuse more cargo arrival.
Add articulated engines (trains and road vehicles)
Called whenever the construction state of a house changes.
decides slope suitability
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called to determine the colour of an industry.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
industry availability/probability callback
controls monthly random production change
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
Called to determine which cargoes an industry should accept.
Determine whether the house can be built on the specified tile.
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
static const int CBM_NO_BIT
Mask to show no bit needs to be enabled for the callback.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
const void * GetInstance(uint index) const override
Get the instance given an index.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_house.h:59
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
Called for every vehicle every 32 days (not all on same date though).
Called to determine the type (if any) of foundation to draw for an airport tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
Determine the amount of cargo to load per unit of time when using gradual loading.
uint GetParent(uint index) const override
Get the parent "window_number" of a given instance.
Refit capacity, the passed vehicle needs to have its ->cargo_type set to the cargo we are refitting t...
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
Definition: stdafx.h:413
Called to determine industry tile next animation frame.
option out of accepting cargo
uint Resolve(uint index, uint var, uint param, bool *avail) const override
Resolve (action2) variable for a given index.
static HouseID GetHouseType(TileIndex t)
Get the type of this house, which is an index into the house spec array.
Definition: town_map.h:59
Called for periodically starting or stopping the animation.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
Helper class to wrap some functionality/queries in.
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
decides next animation frame
Availability of station in construction window.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
Called to determine station tile next animation frame.
uint GetPSASize(uint index, uint32 grfid) const override
Allows to know the size of the persistent storage.
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
Called to query the cargo acceptance of the industry tile.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
Town data structure.
Definition: town.h:53
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Resolver for industries.
Called to indicate how long the current animation frame should last.
cargo sub-type display
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_town.h:47
Resolver object for road types.
bool IsInspectable(uint index) const override
Is the item with the given index inspectable?
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
decides if default foundations need to be drawn
conditional protection
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:50
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
Called to determine text to display after cargo name.
A resolver object to be used with feature 0F spritegroups.
GRFFileProps grf_prop
Properties related the the grf file.
Definition: house.h:114
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:286
const struct GRFFile * grffile
grf file that introduced this entity
Station resolver.
Representation of the data from a NewGRF property.
Called for periodically starting or stopping the animation.
decides allowance of autosloping
Called to determine the colour of a town building.
Choose a sprite layout to draw, instead of the standard 0-7 range.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Called to determine more text in the industry window.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:113
Check slope of new station tiles.
Determine the next animation frame for a house.
uint32 GetGRFID(uint index) const override
Get the GRFID of the file that includes this item.
Called to determine if one can alter the ground below an object tile.
Called to determine how much cargo a town building produces.
const void * GetInstance(uint index) const override
Get the instance given an index.
Vehicle length, returns the amount of 1/8&#39;s the vehicle is shorter for trains and RVs...
decide whether the house can be built on a given tile
Called to decide how much cargo a town building can accept.
const int32 * GetPSAFirstPosition(uint index, uint32 grfid) const override
Gets the first position of the array containing the persistent storage.
Called to determine industry special effects.
Called when industry is built to set initial production level.
const void * GetSpec(uint index) const override
Get (NewGRF) specs given an index.
GRFFileProps grf_prop
properties related the the grf file
Container for all information for a given feature.
uint GetPSASize(uint index, uint32 grfid) const override
Allows to know the size of the persistent storage.
const void * GetInstance(uint index) const override
Get the instance given an index.
Called on production changes, so it can be adjusted.
Visual effects and wagon power (trains, road vehicles and ships)
Called for periodically starting or stopping the animation.
give a custom colour to newly build industries
decides slope suitability
void SetStringParameters(uint index) const override
Set the string parameters to write the right data for a STRINGn.
Resolve wagon overrides using TrainCache::cached_override.
Definition: newgrf_engine.h:52