12 #include "../newgrf_house.h" 
   13 #include "../newgrf_engine.h" 
   16 #define NIP(prop, base, variable, type, name) { name, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), prop, type } 
   17 #define NIP_END() { NULL, 0, 0, 0, 0 } 
   20 #define NIC(cb_id, base, variable, bit) { #cb_id, (ptrdiff_t)cpp_offsetof(base, variable), cpp_sizeof(base, variable), bit, cb_id } 
   21 #define NIC_END() { NULL, 0, 0, 0, 0 } 
   24 #define NIV(var, name) { name, var } 
   25 #define NIV_END() { NULL, 0 } 
   30 #define NICV(cb_id, bit) NIC(cb_id, Engine, info.callback_mask, bit) 
   51   NIV(0x40, 
"position in consist and length"),
 
   52   NIV(0x41, 
"position and length of chain of same vehicles"),
 
   53   NIV(0x42, 
"transported cargo types"),
 
   54   NIV(0x43, 
"player info"),
 
   55   NIV(0x44, 
"aircraft info"),
 
   56   NIV(0x45, 
"curvature info"),
 
   57   NIV(0x46, 
"motion counter"),
 
   58   NIV(0x47, 
"vehicle cargo info"),
 
   59   NIV(0x48, 
"vehicle type info"),
 
   60   NIV(0x49, 
"year of construction"),
 
   61   NIV(0x4A, 
"current rail type info"),
 
   62   NIV(0x4B, 
"long date of last service"),
 
   63   NIV(0x4C, 
"current max speed"),
 
   64   NIV(0x4D, 
"position in articulated vehicle"),
 
   65   NIV(0x60, 
"count vehicle id occurrences"),
 
   67   NIV(0x62, 
"Curvature/position difference to other vehicle"),
 
   72   bool IsInspectable(uint index)
 const                 { 
return Vehicle::Get(index)->GetGRF() != NULL; }
 
   74   const void *GetInstance(uint index)
const             { 
return Vehicle::Get(index); }
 
   75   const void *GetSpec(uint index)
 const                { 
return Vehicle::Get(index)->GetEngine(); }
 
   77   uint32 GetGRFID(uint index)
 const                    { 
return Vehicle::Get(index)->GetGRFID(); }
 
   79    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
   97 #define NICS(cb_id, bit) NIC(cb_id, StationSpec, callback_mask, bit) 
  110   NIV(0x40, 
"platform info and relative position"),
 
  111   NIV(0x41, 
"platform info and relative position for individually built sections"),
 
  112   NIV(0x42, 
"terrain and track type"),
 
  113   NIV(0x43, 
"player info"),
 
  114   NIV(0x44, 
"path signalling info"),
 
  115   NIV(0x45, 
"rail continuation info"),
 
  116   NIV(0x46, 
"platform info and relative position from middle"),
 
  117   NIV(0x47, 
"platform info and relative position from middle for individually built sections"),
 
  118   NIV(0x48, 
"bitmask of accepted cargoes"),
 
  119   NIV(0x49, 
"platform info and relative position of same-direction section"),
 
  120   NIV(0x4A, 
"current animation frame"),
 
  121   NIV(0x60, 
"amount of cargo waiting"),
 
  122   NIV(0x61, 
"time since last cargo pickup"),
 
  123   NIV(0x62, 
"rating of cargo"),
 
  124   NIV(0x63, 
"time spent on route"),
 
  125   NIV(0x64, 
"information about last vehicle picking cargo up"),
 
  126   NIV(0x65, 
"amount of cargo acceptance"),
 
  127   NIV(0x66, 
"animation frame of nearby tile"),
 
  128   NIV(0x67, 
"land info of nearby tiles"),
 
  129   NIV(0x68, 
"station info of nearby tiles"),
 
  130   NIV(0x69, 
"information about cargo accepted in the past"),
 
  135   bool IsInspectable(uint index)
 const                 { 
return GetStationSpec(index) != NULL; }
 
  137   const void *GetInstance(uint index)
const             { 
return NULL; }
 
  138   const void *GetSpec(uint index)
 const                { 
return GetStationSpec(index); }
 
  140   uint32 GetGRFID(uint index)
 const                    { 
return (this->IsInspectable(index)) ? GetStationSpec(index)->
grf_prop.
grffile->grfid : 0; }
 
  142    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  159 #define NICH(cb_id, bit) NIC(cb_id, HouseSpec, callback_mask, bit) 
  180   NIV(0x40, 
"construction state of tile and pseudo-random value"),
 
  181   NIV(0x41, 
"age of building in years"),
 
  182   NIV(0x42, 
"town zone"),
 
  183   NIV(0x43, 
"terrain type"),
 
  184   NIV(0x44, 
"building counts"),
 
  185   NIV(0x45, 
"town expansion bits"),
 
  186   NIV(0x46, 
"current animation frame"),
 
  187   NIV(0x47, 
"xy coordinate of the building"),
 
  188   NIV(0x60, 
"other building counts (old house type)"),
 
  189   NIV(0x61, 
"other building counts (new house type)"),
 
  190   NIV(0x62, 
"land info of nearby tiles"),
 
  191   NIV(0x63, 
"current animation frame of nearby house tile"),
 
  192   NIV(0x64, 
"cargo acceptance history of nearby stations"),
 
  193   NIV(0x65, 
"distance of nearest house matching a given criterion"),
 
  194   NIV(0x66, 
"class and ID of nearby house tile"),
 
  195   NIV(0x67, 
"GRFID of nearby house tile"),
 
  202   const void *GetInstance(uint index)
const             { 
return NULL; }
 
  203   const void *GetSpec(uint index)
 const                { 
return HouseSpec::Get(
GetHouseType(index)); }
 
  205   uint32 GetGRFID(uint index)
 const                    { 
return (this->IsInspectable(index)) ? HouseSpec::Get(
GetHouseType(index))->
grf_prop.
grffile->grfid : 0; }
 
  207    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  224 #define NICIT(cb_id, bit) NIC(cb_id, IndustryTileSpec, callback_mask, bit) 
  225 static const NICallback _nic_industrytiles[] = {
 
  237 static const NIVariable _niv_industrytiles[] = {
 
  238   NIV(0x40, 
"construction state of tile"),
 
  239   NIV(0x41, 
"ground type"),
 
  240   NIV(0x42, 
"current town zone in nearest town"),
 
  241   NIV(0x43, 
"relative position"),
 
  242   NIV(0x44, 
"animation frame"),
 
  243   NIV(0x60, 
"land info of nearby tiles"),
 
  244   NIV(0x61, 
"animation stage of nearby tiles"),
 
  245   NIV(0x62, 
"get industry or airport tile ID at offset"),
 
  252   const void *GetInstance(uint index)
const             { 
return NULL; }
 
  257    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  264 static const NIFeature _nif_industrytile = {
 
  283 #define NICI(cb_id, bit) NIC(cb_id, IndustrySpec, callback_mask, bit) 
  302   NIV(0x40, 
"waiting cargo 0"),
 
  303   NIV(0x41, 
"waiting cargo 1"),
 
  304   NIV(0x42, 
"waiting cargo 2"),
 
  305   NIV(0x43, 
"distance to closest dry/land tile"),
 
  306   NIV(0x44, 
"layout number"),
 
  307   NIV(0x45, 
"player info"),
 
  308   NIV(0x46, 
"industry construction date"),
 
  309   NIV(0x60, 
"get industry tile ID at offset"),
 
  310   NIV(0x61, 
"get random tile bits at offset"),
 
  311   NIV(0x62, 
"land info of nearby tiles"),
 
  312   NIV(0x63, 
"animation stage of nearby tiles"),
 
  313   NIV(0x64, 
"distance on nearest industry with given type"),
 
  314   NIV(0x65, 
"get town zone and Manhattan distance of closest town"),
 
  315   NIV(0x66, 
"get square of Euclidean distance of closes town"),
 
  316   NIV(0x67, 
"count of industry and distance of closest instance"),
 
  317   NIV(0x68, 
"count of industry and distance of closest instance with layout filter"),
 
  324   const void *GetInstance(uint index)
const             { 
return Industry::Get(index); }
 
  329    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  338   const int32 *GetPSAFirstPosition(uint index, uint32 grfid)
 const 
  341     if (i->
psa == NULL) 
return NULL;
 
  356 #define NICO(cb_id, bit) NIC(cb_id, ObjectSpec, callback_mask, bit) 
  369   NIV(0x40, 
"relative position"),
 
  370   NIV(0x41, 
"tile information"),
 
  371   NIV(0x42, 
"construction date"),
 
  372   NIV(0x43, 
"animation counter"),
 
  373   NIV(0x44, 
"object founder"),
 
  374   NIV(0x45, 
"get town zone and Manhattan distance of closest town"),
 
  375   NIV(0x46, 
"get square of Euclidean distance of closes town"),
 
  378   NIV(0x60, 
"get object ID at offset"),
 
  379   NIV(0x61, 
"get random tile bits at offset"),
 
  380   NIV(0x62, 
"land info of nearby tiles"),
 
  381   NIV(0x63, 
"animation stage of nearby tiles"),
 
  382   NIV(0x64, 
"distance on nearest object with given type"),
 
  394    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  412   NIV(0x40, 
"terrain type"),
 
  413   NIV(0x41, 
"enhanced tunnels"),
 
  414   NIV(0x42, 
"level crossing status"),
 
  415   NIV(0x43, 
"construction date"),
 
  416   NIV(0x44, 
"town zone"),
 
  421   bool IsInspectable(uint index)
 const                 { 
return true; }
 
  422   uint GetParent(uint index)
 const                     { 
return UINT32_MAX; }
 
  423   const void *GetInstance(uint index)
const             { 
return NULL; }
 
  424   const void *GetSpec(uint index)
 const                { 
return NULL; }
 
  426   uint32 GetGRFID(uint index)
 const                    { 
return 0; }
 
  428    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  447 #define NICAT(cb_id, bit) NIC(cb_id, AirportTileSpec, callback_mask, bit) 
  448 static const NICallback _nic_airporttiles[] = {
 
  459   const void *GetInstance(uint index)
const             { 
return NULL; }
 
  464    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  471 static const NIFeature _nif_airporttile = {
 
  482   NIV(0x40, 
"larger town effect on this town"),
 
  483   NIV(0x41, 
"town index"),
 
  484   NIV(0x82, 
"population"),
 
  485   NIV(0x94, 
"zone radius 0"),
 
  486   NIV(0x96, 
"zone radius 1"),
 
  487   NIV(0x98, 
"zone radius 2"),
 
  488   NIV(0x9A, 
"zone radius 3"),
 
  489   NIV(0x9C, 
"zone radius 4"),
 
  490   NIV(0xB6, 
"number of buildings"),
 
  495   bool IsInspectable(uint index)
 const                 { 
return Town::IsValidID(index); }
 
  496   uint GetParent(uint index)
 const                     { 
return UINT32_MAX; }
 
  497   const void *GetInstance(uint index)
const             { 
return Town::Get(index); }
 
  498   const void *GetSpec(uint index)
 const                { 
return NULL; }
 
  500   uint32 GetGRFID(uint index)
 const                    { 
return 0; }
 
  501   bool PSAWithParameter()
 const                        { 
return true; }
 
  504    uint Resolve(uint index, uint var, uint param, 
bool *avail)
 const 
  510   const int32 *GetPSAFirstPosition(uint index, uint32 grfid)
 const 
  514     std::list<PersistentStorage *>::iterator iter;
 
  515     for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) {
 
  516       if ((*iter)->grfid == grfid) 
return (int32 *)(&(*iter)->storage[0]);