OpenTTD Source  1.11.0-beta1
newgrf_engine.cpp
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 "stdafx.h"
11 #include "debug.h"
12 #include "train.h"
13 #include "roadveh.h"
14 #include "company_func.h"
15 #include "newgrf_cargo.h"
16 #include "newgrf_spritegroup.h"
17 #include "date_func.h"
18 #include "vehicle_func.h"
19 #include "core/random_func.hpp"
20 #include "aircraft.h"
21 #include "station_base.h"
22 #include "company_base.h"
23 #include "newgrf_railtype.h"
24 #include "newgrf_roadtype.h"
25 #include "ship.h"
26 
27 #include "safeguards.h"
28 
29 struct WagonOverride {
30  EngineID *train_id;
31  uint trains;
32  CargoID cargo;
33  const SpriteGroup *group;
34 };
35 
36 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
37 {
38  Engine *e = Engine::Get(engine);
39  WagonOverride *wo;
40 
41  assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargoes.
42 
43  e->overrides_count++;
44  e->overrides = ReallocT(e->overrides, e->overrides_count);
45 
46  wo = &e->overrides[e->overrides_count - 1];
47  wo->group = group;
48  wo->cargo = cargo;
49  wo->trains = trains;
50  wo->train_id = MallocT<EngineID>(trains);
51  memcpy(wo->train_id, train_id, trains * sizeof *train_id);
52 }
53 
54 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine)
55 {
56  const Engine *e = Engine::Get(engine);
57 
58  for (uint i = 0; i < e->overrides_count; i++) {
59  const WagonOverride *wo = &e->overrides[i];
60 
61  if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue;
62 
63  for (uint j = 0; j < wo->trains; j++) {
64  if (wo->train_id[j] == overriding_engine) return wo->group;
65  }
66  }
67  return nullptr;
68 }
69 
74 {
75  for (uint i = 0; i < e->overrides_count; i++) {
76  WagonOverride *wo = &e->overrides[i];
77  free(wo->train_id);
78  }
79  free(e->overrides);
80  e->overrides_count = 0;
81  e->overrides = nullptr;
82 }
83 
84 
85 void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group)
86 {
87  Engine *e = Engine::Get(engine);
88  assert(cargo < lengthof(e->grf_prop.spritegroup));
89 
90  if (e->grf_prop.spritegroup[cargo] != nullptr) {
91  grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
92  }
93  e->grf_prop.spritegroup[cargo] = group;
94 }
95 
96 
103 void SetEngineGRF(EngineID engine, const GRFFile *file)
104 {
105  Engine *e = Engine::Get(engine);
106  e->grf_prop.grffile = file;
107 }
108 
109 
110 static int MapOldSubType(const Vehicle *v)
111 {
112  switch (v->type) {
113  case VEH_TRAIN:
114  if (Train::From(v)->IsEngine()) return 0;
115  if (Train::From(v)->IsFreeWagon()) return 4;
116  return 2;
117  case VEH_ROAD:
118  case VEH_SHIP: return 0;
119  case VEH_AIRCRAFT:
120  case VEH_DISASTER: return v->subtype;
121  case VEH_EFFECT: return v->subtype << 1;
122  default: NOT_REACHED();
123  }
124 }
125 
126 
127 /* TTDP style aircraft movement states for GRF Action 2 Var 0xE2 */
128 enum TTDPAircraftMovementStates {
129  AMS_TTDP_HANGAR,
130  AMS_TTDP_TO_HANGAR,
131  AMS_TTDP_TO_PAD1,
132  AMS_TTDP_TO_PAD2,
133  AMS_TTDP_TO_PAD3,
134  AMS_TTDP_TO_ENTRY_2_AND_3,
135  AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
136  AMS_TTDP_TO_JUNCTION,
137  AMS_TTDP_LEAVE_RUNWAY,
138  AMS_TTDP_TO_INWAY,
139  AMS_TTDP_TO_RUNWAY,
140  AMS_TTDP_TO_OUTWAY,
141  AMS_TTDP_WAITING,
142  AMS_TTDP_TAKEOFF,
143  AMS_TTDP_TO_TAKEOFF,
144  AMS_TTDP_CLIMBING,
145  AMS_TTDP_FLIGHT_APPROACH,
146  AMS_TTDP_UNUSED_0x11,
147  AMS_TTDP_FLIGHT_TO_TOWER,
148  AMS_TTDP_UNUSED_0x13,
149  AMS_TTDP_FLIGHT_FINAL,
150  AMS_TTDP_FLIGHT_DESCENT,
151  AMS_TTDP_BRAKING,
152  AMS_TTDP_HELI_TAKEOFF_AIRPORT,
153  AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
154  AMS_TTDP_HELI_LAND_AIRPORT,
155  AMS_TTDP_HELI_TAKEOFF_HELIPORT,
156  AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
157  AMS_TTDP_HELI_LAND_HELIPORT,
158 };
159 
160 
165 static byte MapAircraftMovementState(const Aircraft *v)
166 {
167  const Station *st = GetTargetAirportIfValid(v);
168  if (st == nullptr) return AMS_TTDP_FLIGHT_TO_TOWER;
169 
170  const AirportFTAClass *afc = st->airport.GetFTA();
171  uint16 amdflag = afc->MovingData(v->pos)->flag;
172 
173  switch (v->state) {
174  case HANGAR:
175  /* The international airport is a special case as helicopters can land in
176  * front of the hangar. Helicopters also change their air.state to
177  * AMED_HELI_LOWER some time before actually descending. */
178 
179  /* This condition only occurs for helicopters, during descent,
180  * to a landing by the hangar of an international airport. */
181  if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT;
182 
183  /* This condition only occurs for helicopters, before starting descent,
184  * to a landing by the hangar of an international airport. */
185  if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER;
186 
187  /* The final two conditions apply to helicopters or aircraft.
188  * Has reached hangar? */
189  if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR;
190 
191  /* Still moving towards hangar. */
192  return AMS_TTDP_TO_HANGAR;
193 
194  case TERM1:
195  if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD1;
196  return AMS_TTDP_TO_JUNCTION;
197 
198  case TERM2:
199  if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD2;
200  return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
201 
202  case TERM3:
203  case TERM4:
204  case TERM5:
205  case TERM6:
206  case TERM7:
207  case TERM8:
208  /* TTDPatch only has 3 terminals, so treat these states the same */
209  if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD3;
210  return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
211 
212  case HELIPAD1:
213  case HELIPAD2:
214  case HELIPAD3:
215  /* Will only occur for helicopters.*/
216  if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending.
217  if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent.
218  return AMS_TTDP_TO_JUNCTION; // On the ground.
219 
220  case TAKEOFF: // Moving to takeoff position.
221  return AMS_TTDP_TO_OUTWAY;
222 
223  case STARTTAKEOFF: // Accelerating down runway.
224  return AMS_TTDP_TAKEOFF;
225 
226  case ENDTAKEOFF: // Ascent
227  return AMS_TTDP_CLIMBING;
228 
229  case HELITAKEOFF: // Helicopter is moving to take off position.
230  if (afc->delta_z == 0) {
231  return amdflag & AMED_HELI_RAISE ?
232  AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
233  } else {
234  return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
235  }
236 
237  case FLYING:
238  return amdflag & AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
239 
240  case LANDING: // Descent
241  return AMS_TTDP_FLIGHT_DESCENT;
242 
243  case ENDLANDING: // On the runway braking
244  if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING;
245  /* Landed - moving off runway */
246  return AMS_TTDP_TO_INWAY;
247 
248  case HELILANDING:
249  case HELIENDLANDING: // Helicoptor is descending.
250  if (amdflag & AMED_HELI_LOWER) {
251  return afc->delta_z == 0 ?
252  AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
253  } else {
254  return AMS_TTDP_FLIGHT_TO_TOWER;
255  }
256 
257  default:
258  return AMS_TTDP_HANGAR;
259  }
260 }
261 
262 
263 /* TTDP style aircraft movement action for GRF Action 2 Var 0xE6 */
264 enum TTDPAircraftMovementActions {
265  AMA_TTDP_IN_HANGAR,
266  AMA_TTDP_ON_PAD1,
267  AMA_TTDP_ON_PAD2,
268  AMA_TTDP_ON_PAD3,
269  AMA_TTDP_HANGAR_TO_PAD1,
270  AMA_TTDP_HANGAR_TO_PAD2,
271  AMA_TTDP_HANGAR_TO_PAD3,
272  AMA_TTDP_LANDING_TO_PAD1,
273  AMA_TTDP_LANDING_TO_PAD2,
274  AMA_TTDP_LANDING_TO_PAD3,
275  AMA_TTDP_PAD1_TO_HANGAR,
276  AMA_TTDP_PAD2_TO_HANGAR,
277  AMA_TTDP_PAD3_TO_HANGAR,
278  AMA_TTDP_PAD1_TO_TAKEOFF,
279  AMA_TTDP_PAD2_TO_TAKEOFF,
280  AMA_TTDP_PAD3_TO_TAKEOFF,
281  AMA_TTDP_HANGAR_TO_TAKOFF,
282  AMA_TTDP_LANDING_TO_HANGAR,
283  AMA_TTDP_IN_FLIGHT,
284 };
285 
286 
292 static byte MapAircraftMovementAction(const Aircraft *v)
293 {
294  switch (v->state) {
295  case HANGAR:
296  return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
297 
298  case TERM1:
299  case HELIPAD1:
300  return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
301 
302  case TERM2:
303  case HELIPAD2:
304  return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
305 
306  case TERM3:
307  case TERM4:
308  case TERM5:
309  case TERM6:
310  case TERM7:
311  case TERM8:
312  case HELIPAD3:
313  return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
314 
315  case TAKEOFF: // Moving to takeoff position
316  case STARTTAKEOFF: // Accelerating down runway
317  case ENDTAKEOFF: // Ascent
318  case HELITAKEOFF:
319  /* @todo Need to find which terminal (or hangar) we've come from. How? */
320  return AMA_TTDP_PAD1_TO_TAKEOFF;
321 
322  case FLYING:
323  return AMA_TTDP_IN_FLIGHT;
324 
325  case LANDING: // Descent
326  case ENDLANDING: // On the runway braking
327  case HELILANDING:
328  case HELIENDLANDING:
329  /* @todo Need to check terminal we're landing to. Is it known yet? */
330  return (v->current_order.IsType(OT_GOTO_DEPOT)) ?
331  AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
332 
333  default:
334  return AMA_TTDP_IN_HANGAR;
335  }
336 }
337 
338 
339 /* virtual */ uint32 VehicleScopeResolver::GetRandomBits() const
340 {
341  return this->v == nullptr ? 0 : this->v->random_bits;
342 }
343 
344 /* virtual */ uint32 VehicleScopeResolver::GetTriggers() const
345 {
346  return this->v == nullptr ? 0 : this->v->waiting_triggers;
347 }
348 
349 
351 {
352  switch (scope) {
353  case VSG_SCOPE_SELF: return &this->self_scope;
354  case VSG_SCOPE_PARENT: return &this->parent_scope;
355  case VSG_SCOPE_RELATIVE: {
356  int32 count = GB(relative, 0, 4);
357  if (this->self_scope.v != nullptr && (relative != this->cached_relative_count || count == 0)) {
358  /* Note: This caching only works as long as the VSG_SCOPE_RELATIVE cannot be used in
359  * VarAct2 with procedure calls. */
360  if (count == 0) count = GetRegister(0x100);
361 
362  const Vehicle *v = nullptr;
363  switch (GB(relative, 6, 2)) {
364  default: NOT_REACHED();
365  case 0x00: // count back (away from the engine), starting at this vehicle
366  v = this->self_scope.v;
367  break;
368  case 0x01: // count forward (toward the engine), starting at this vehicle
369  v = this->self_scope.v;
370  count = -count;
371  break;
372  case 0x02: // count back, starting at the engine
373  v = this->parent_scope.v;
374  break;
375  case 0x03: { // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41
376  const Vehicle *self = this->self_scope.v;
377  for (const Vehicle *u = self->First(); u != self; u = u->Next()) {
378  if (u->engine_type != self->engine_type) {
379  v = nullptr;
380  } else {
381  if (v == nullptr) v = u;
382  }
383  }
384  if (v == nullptr) v = self;
385  break;
386  }
387  }
388  this->relative_scope.SetVehicle(v->Move(count));
389  }
390  return &this->relative_scope;
391  }
392  default: return ResolverObject::GetScope(scope, relative);
393  }
394 }
395 
405 static const Livery *LiveryHelper(EngineID engine, const Vehicle *v)
406 {
407  const Livery *l;
408 
409  if (v == nullptr) {
410  if (!Company::IsValidID(_current_company)) return nullptr;
411  l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, nullptr, LIT_ALL);
412  } else if (v->IsGroundVehicle()) {
414  } else {
416  }
417 
418  return l;
419 }
420 
428 static uint32 PositionHelper(const Vehicle *v, bool consecutive)
429 {
430  const Vehicle *u;
431  byte chain_before = 0;
432  byte chain_after = 0;
433 
434  for (u = v->First(); u != v; u = u->Next()) {
435  chain_before++;
436  if (consecutive && u->engine_type != v->engine_type) chain_before = 0;
437  }
438 
439  while (u->Next() != nullptr && (!consecutive || u->Next()->engine_type == v->engine_type)) {
440  chain_after++;
441  u = u->Next();
442  }
443 
444  return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
445 }
446 
447 static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, byte variable, uint32 parameter, bool *available)
448 {
449  /* Calculated vehicle parameters */
450  switch (variable) {
451  case 0x25: // Get engine GRF ID
452  return v->GetGRFID();
453 
454  case 0x40: // Get length of consist
458  }
460 
461  case 0x41: // Get length of same consecutive wagons
465  }
467 
468  case 0x42: { // Consist cargo information
470  const Vehicle *u;
471  byte cargo_classes = 0;
472  uint8 common_cargoes[NUM_CARGO];
473  uint8 common_subtypes[256];
474  byte user_def_data = 0;
475  CargoID common_cargo_type = CT_INVALID;
476  uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
477 
478  /* Reset our arrays */
479  memset(common_cargoes, 0, sizeof(common_cargoes));
480  memset(common_subtypes, 0, sizeof(common_subtypes));
481 
482  for (u = v; u != nullptr; u = u->Next()) {
483  if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
484 
485  /* Skip empty engines */
486  if (!u->GetEngine()->CanCarryCargo()) continue;
487 
488  cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
489  common_cargoes[u->cargo_type]++;
490  }
491 
492  /* Pick the most common cargo type */
493  uint common_cargo_best_amount = 0;
494  for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
495  if (common_cargoes[cargo] > common_cargo_best_amount) {
496  common_cargo_best_amount = common_cargoes[cargo];
497  common_cargo_type = cargo;
498  }
499  }
500 
501  /* Count subcargo types of common_cargo_type */
502  for (u = v; u != nullptr; u = u->Next()) {
503  /* Skip empty engines and engines not carrying common_cargo_type */
504  if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo()) continue;
505 
506  common_subtypes[u->cargo_subtype]++;
507  }
508 
509  /* Pick the most common subcargo type*/
510  uint common_subtype_best_amount = 0;
511  for (uint i = 0; i < lengthof(common_subtypes); i++) {
512  if (common_subtypes[i] > common_subtype_best_amount) {
513  common_subtype_best_amount = common_subtypes[i];
514  common_subtype = i;
515  }
516  }
517 
518  /* Note: We have to store the untranslated cargotype in the cache as the cache can be read by different NewGRFs,
519  * which will need different translations */
520  v->grf_cache.consist_cargo_information = cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
522  }
523 
524  /* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
525  CargoID common_cargo_type = (v->grf_cache.consist_cargo_information >> 8) & 0xFF;
526 
527  /* Note:
528  * - Unlike everywhere else the cargo translation table is only used since grf version 8, not 7.
529  * - For translating the cargo type we need to use the GRF which is resolving the variable, which
530  * is object->ro.grffile.
531  * In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
532  * - The grffile == nullptr case only happens if this function is called for default vehicles.
533  * And this is only done by CheckCaches().
534  */
535  const GRFFile *grffile = object->ro.grffile;
536  uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
537  (grffile == nullptr || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
538 
539  return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
540  }
541 
542  case 0x43: // Company information
546  }
547  return v->grf_cache.company_information;
548 
549  case 0x44: // Aircraft information
550  if (v->type != VEH_AIRCRAFT || !Aircraft::From(v)->IsNormalAircraft()) return UINT_MAX;
551 
552  {
553  const Vehicle *w = v->Next();
554  uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height
555  byte airporttype = ATP_TTDP_LARGE;
556 
558 
559  if (st != nullptr && st->airport.tile != INVALID_TILE) {
560  airporttype = st->airport.GetSpec()->ttd_airport_type;
561  }
562 
563  return (Clamp(altitude, 0, 0xFF) << 8) | airporttype;
564  }
565 
566  case 0x45: { // Curvature info
567  /* Format: xxxTxBxF
568  * F - previous wagon to current wagon, 0 if vehicle is first
569  * B - current wagon to next wagon, 0 if wagon is last
570  * T - previous wagon to next wagon, 0 in an S-bend
571  */
572  if (!v->IsGroundVehicle()) return 0;
573 
574  const Vehicle *u_p = v->Previous();
575  const Vehicle *u_n = v->Next();
576  DirDiff f = (u_p == nullptr) ? DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
577  DirDiff b = (u_n == nullptr) ? DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
578  DirDiff t = ChangeDirDiff(f, b);
579 
580  return ((t > DIRDIFF_REVERSE ? t | 8 : t) << 16) |
581  ((b > DIRDIFF_REVERSE ? b | 8 : b) << 8) |
582  ( f > DIRDIFF_REVERSE ? f | 8 : f);
583  }
584 
585  case 0x46: // Motion counter
586  return v->motion_counter;
587 
588  case 0x47: { // Vehicle cargo info
589  /* Format: ccccwwtt
590  * tt - the cargo type transported by the vehicle,
591  * translated if a translation table has been installed.
592  * ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
593  * cccc - the cargo class value of the cargo transported by the vehicle.
594  */
595  const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
596 
597  /* Note:
598  * For translating the cargo type we need to use the GRF which is resolving the variable, which
599  * is object->ro.grffile.
600  * In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
601  */
602  return (cs->classes << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type];
603  }
604 
605  case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
606  case 0x49: return v->build_year;
607 
608  case 0x4A:
609  switch (v->type) {
610  case VEH_TRAIN: {
611  RailType rt = GetTileRailType(v->tile);
612  const RailtypeInfo *rti = GetRailTypeInfo(rt);
613  return ((rti->flags & RTFB_CATENARY) ? 0x200 : 0) |
614  (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) |
616  }
617 
618  case VEH_ROAD: {
619  RoadType rt = GetRoadType(v->tile, GetRoadTramType(RoadVehicle::From(v)->roadtype));
620  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
621  return ((rti->flags & ROTFB_CATENARY) ? 0x200 : 0) |
622  0x100 |
624  }
625 
626  default:
627  return 0;
628  }
629 
630  case 0x4B: // Long date of last service
631  return v->date_of_last_service;
632 
633  case 0x4C: // Current maximum speed in NewGRF units
634  if (!v->IsPrimaryVehicle()) return 0;
635  return v->GetCurrentMaxSpeed();
636 
637  case 0x4D: // Position within articulated vehicle
639  byte artic_before = 0;
640  for (const Vehicle *u = v; u->IsArticulatedPart(); u = u->Previous()) artic_before++;
641  byte artic_after = 0;
642  for (const Vehicle *u = v; u->HasArticulatedPart(); u = u->Next()) artic_after++;
643  v->grf_cache.position_in_vehicle = artic_before | artic_after << 8;
645  }
646  return v->grf_cache.position_in_vehicle;
647 
648  /* Variables which use the parameter */
649  case 0x60: // Count consist's engine ID occurrence
650  if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
651 
652  {
653  uint count = 0;
654  for (; v != nullptr; v = v->Next()) {
655  if (v->GetEngine()->grf_prop.local_id == parameter) count++;
656  }
657  return count;
658  }
659 
660  case 0x61: // Get variable of n-th vehicle in chain [signed number relative to vehicle]
661  if (!v->IsGroundVehicle() || parameter == 0x61) {
662  /* Not available */
663  break;
664  }
665 
666  /* Only allow callbacks that don't change properties to avoid circular dependencies. */
670  Vehicle *u = v->Move((int32)GetRegister(0x10F));
671  if (u == nullptr) return 0; // available, but zero
672 
673  if (parameter == 0x5F) {
674  /* This seems to be the only variable that makes sense to access via var 61, but is not handled by VehicleGetVariable */
675  return (u->random_bits << 8) | u->waiting_triggers;
676  } else {
677  return VehicleGetVariable(u, object, parameter, GetRegister(0x10E), available);
678  }
679  }
680  /* Not available */
681  break;
682 
683  case 0x62: { // Curvature/position difference for n-th vehicle in chain [signed number relative to vehicle]
684  /* Format: zzyyxxFD
685  * zz - Signed difference of z position between the selected and this vehicle.
686  * yy - Signed difference of y position between the selected and this vehicle.
687  * xx - Signed difference of x position between the selected and this vehicle.
688  * F - Flags, bit 7 corresponds to VS_HIDDEN.
689  * D - Dir difference, like in 0x45.
690  */
691  if (!v->IsGroundVehicle()) return 0;
692 
693  const Vehicle *u = v->Move((int8)parameter);
694  if (u == nullptr) return 0;
695 
696  /* Get direction difference. */
697  bool prev = (int8)parameter < 0;
698  uint32 ret = prev ? DirDifference(u->direction, v->direction) : DirDifference(v->direction, u->direction);
699  if (ret > DIRDIFF_REVERSE) ret |= 0x08;
700 
701  if (u->vehstatus & VS_HIDDEN) ret |= 0x80;
702 
703  /* Get position difference. */
704  ret |= ((prev ? u->x_pos - v->x_pos : v->x_pos - u->x_pos) & 0xFF) << 8;
705  ret |= ((prev ? u->y_pos - v->y_pos : v->y_pos - u->y_pos) & 0xFF) << 16;
706  ret |= ((prev ? u->z_pos - v->z_pos : v->z_pos - u->z_pos) & 0xFF) << 24;
707 
708  return ret;
709  }
710 
711  case 0x63:
712  /* Tile compatibility wrt. arbitrary track-type
713  * Format:
714  * bit 0: Type 'parameter' is known.
715  * bit 1: Engines with type 'parameter' are compatible with this tile.
716  * bit 2: Engines with type 'parameter' are powered on this tile.
717  * bit 3: This tile has type 'parameter' or it is considered equivalent (alternate labels).
718  */
719  switch (v->type) {
720  case VEH_TRAIN: {
721  RailType param_type = GetRailTypeTranslation(parameter, object->ro.grffile);
722  if (param_type == INVALID_RAILTYPE) return 0x00;
723  RailType tile_type = GetTileRailType(v->tile);
724  if (tile_type == param_type) return 0x0F;
725  return (HasPowerOnRail(param_type, tile_type) ? 0x04 : 0x00) |
726  (IsCompatibleRail(param_type, tile_type) ? 0x02 : 0x00) |
727  0x01;
728  }
729  case VEH_ROAD: {
730  RoadTramType rtt = GetRoadTramType(RoadVehicle::From(v)->roadtype);
731  RoadType param_type = GetRoadTypeTranslation(rtt, parameter, object->ro.grffile);
732  if (param_type == INVALID_ROADTYPE) return 0x00;
733  RoadType tile_type = GetRoadType(v->tile, rtt);
734  if (tile_type == param_type) return 0x0F;
735  return (HasPowerOnRoad(param_type, tile_type) ? 0x06 : 0x00) |
736  0x01;
737  }
738  default: return 0x00;
739  }
740 
741  case 0xFE:
742  case 0xFF: {
743  uint16 modflags = 0;
744 
745  if (v->type == VEH_TRAIN) {
746  const Train *t = Train::From(v);
747  bool is_powered_wagon = HasBit(t->flags, VRF_POWEREDWAGON);
748  const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype)
749  RailType railtype = GetRailType(v->tile);
750  bool powered = t->IsEngine() || is_powered_wagon;
751  bool has_power = HasPowerOnRail(u->railtype, railtype);
752 
753  if (powered && has_power) SetBit(modflags, 5);
754  if (powered && !has_power) SetBit(modflags, 6);
755  if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8);
756  }
757  if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING)) SetBit(modflags, 1);
758  if (HasBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE)) SetBit(modflags, 10);
759 
760  return variable == 0xFE ? modflags : GB(modflags, 8, 8);
761  }
762  }
763 
764  /* General vehicle properties */
765  switch (variable - 0x80) {
766  case 0x00: return v->type + 0x10;
767  case 0x01: return MapOldSubType(v);
768  case 0x04: return v->index;
769  case 0x05: return GB(v->index, 8, 8);
770  case 0x0A: return v->current_order.MapOldOrder();
771  case 0x0B: return v->current_order.GetDestination();
772  case 0x0C: return v->GetNumOrders();
773  case 0x0D: return v->cur_real_order_index;
774  case 0x10:
775  case 0x11: {
776  uint ticks;
777  if (v->current_order.IsType(OT_LOADING)) {
778  ticks = v->load_unload_ticks;
779  } else {
780  switch (v->type) {
781  case VEH_TRAIN: ticks = Train::From(v)->wait_counter; break;
782  case VEH_AIRCRAFT: ticks = Aircraft::From(v)->turn_counter; break;
783  default: ticks = 0; break;
784  }
785  }
786  return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8);
787  }
788  case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF);
789  case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
790  case 0x14: return v->GetServiceInterval();
791  case 0x15: return GB(v->GetServiceInterval(), 8, 8);
792  case 0x16: return v->last_station_visited;
793  case 0x17: return v->tick_counter;
794  case 0x18:
795  case 0x19: {
796  uint max_speed;
797  switch (v->type) {
798  case VEH_AIRCRAFT:
799  max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
800  break;
801 
802  default:
803  max_speed = v->vcache.cached_max_speed;
804  break;
805  }
806  return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
807  }
808  case 0x1A: return v->x_pos;
809  case 0x1B: return GB(v->x_pos, 8, 8);
810  case 0x1C: return v->y_pos;
811  case 0x1D: return GB(v->y_pos, 8, 8);
812  case 0x1E: return v->z_pos;
813  case 0x1F: return object->info_view ? DIR_W : v->direction;
814  case 0x28: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
815  case 0x29: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
816  case 0x32: return v->vehstatus;
817  case 0x33: return 0; // non-existent high byte of vehstatus
818  case 0x34: return v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed;
819  case 0x35: return GB(v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 8);
820  case 0x36: return v->subspeed;
821  case 0x37: return v->acceleration;
822  case 0x39: return v->cargo_type;
823  case 0x3A: return v->cargo_cap;
824  case 0x3B: return GB(v->cargo_cap, 8, 8);
825  case 0x3C: return ClampToU16(v->cargo.StoredCount());
826  case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8);
827  case 0x3E: return v->cargo.Source();
828  case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
829  case 0x40: return ClampToU16(v->age);
830  case 0x41: return GB(ClampToU16(v->age), 8, 8);
831  case 0x42: return ClampToU16(v->max_age);
832  case 0x43: return GB(ClampToU16(v->max_age), 8, 8);
834  case 0x45: return v->unitnumber;
835  case 0x46: return v->GetEngine()->grf_prop.local_id;
836  case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
837  case 0x48:
838  if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
839  return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
840 
841  case 0x49: return v->day_counter;
842  case 0x4A: return v->breakdowns_since_last_service;
843  case 0x4B: return v->breakdown_ctr;
844  case 0x4C: return v->breakdown_delay;
845  case 0x4D: return v->breakdown_chance;
846  case 0x4E: return v->reliability;
847  case 0x4F: return GB(v->reliability, 8, 8);
848  case 0x50: return v->reliability_spd_dec;
849  case 0x51: return GB(v->reliability_spd_dec, 8, 8);
850  case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
851  case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24);
852  case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
853  case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8);
854  case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
855  case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24);
856  case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
857  case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8);
858  case 0x5A: return v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index;
859  case 0x5C: return ClampToI32(v->value);
860  case 0x5D: return GB(ClampToI32(v->value), 8, 24);
861  case 0x5E: return GB(ClampToI32(v->value), 16, 16);
862  case 0x5F: return GB(ClampToI32(v->value), 24, 8);
863  case 0x72: return v->cargo_subtype;
864  case 0x7A: return v->random_bits;
865  case 0x7B: return v->waiting_triggers;
866  }
867 
868  /* Vehicle specific properties */
869  switch (v->type) {
870  case VEH_TRAIN: {
871  Train *t = Train::From(v);
872  switch (variable - 0x80) {
873  case 0x62: return t->track;
874  case 0x66: return t->railtype;
875  case 0x73: return 0x80 + VEHICLE_LENGTH - t->gcache.cached_veh_length;
876  case 0x74: return t->gcache.cached_power;
877  case 0x75: return GB(t->gcache.cached_power, 8, 24);
878  case 0x76: return GB(t->gcache.cached_power, 16, 16);
879  case 0x77: return GB(t->gcache.cached_power, 24, 8);
880  case 0x7C: return t->First()->index;
881  case 0x7D: return GB(t->First()->index, 8, 8);
882  case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
883  }
884  break;
885  }
886 
887  case VEH_ROAD: {
889  switch (variable - 0x80) {
890  case 0x62: return rv->state;
891  case 0x64: return rv->blocked_ctr;
892  case 0x65: return GB(rv->blocked_ctr, 8, 8);
893  case 0x66: return rv->overtaking;
894  case 0x67: return rv->overtaking_ctr;
895  case 0x68: return rv->crashed_ctr;
896  case 0x69: return GB(rv->crashed_ctr, 8, 8);
897  }
898  break;
899  }
900 
901  case VEH_SHIP: {
902  Ship *s = Ship::From(v);
903  switch (variable - 0x80) {
904  case 0x62: return s->state;
905  }
906  break;
907  }
908 
909  case VEH_AIRCRAFT: {
910  Aircraft *a = Aircraft::From(v);
911  switch (variable - 0x80) {
912  case 0x62: return MapAircraftMovementState(a); // Current movement state
913  case 0x63: return a->targetairport; // Airport to which the action refers
914  case 0x66: return MapAircraftMovementAction(a); // Current movement action
915  }
916  break;
917  }
918 
919  default: break;
920  }
921 
922  DEBUG(grf, 1, "Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->type);
923 
924  *available = false;
925  return UINT_MAX;
926 }
927 
928 /* virtual */ uint32 VehicleScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
929 {
930  if (this->v == nullptr) {
931  /* Vehicle does not exist, so we're in a purchase list */
932  switch (variable) {
933  case 0x43: return GetCompanyInfo(_current_company, LiveryHelper(this->self_type, nullptr)); // Owner information
934  case 0x46: return 0; // Motion counter
935  case 0x47: { // Vehicle cargo info
936  const Engine *e = Engine::Get(this->self_type);
937  CargoID cargo_type = e->GetDefaultCargoType();
938  if (cargo_type != CT_INVALID) {
939  const CargoSpec *cs = CargoSpec::Get(cargo_type);
940  return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
941  } else {
942  return 0x000000FF;
943  }
944  }
945  case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
946  case 0x49: return _cur_year; // 'Long' format build year
947  case 0x4B: return _date; // Long date of last service
948  case 0x92: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service
949  case 0x93: return GB(Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
950  case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
951  case 0xDA: return INVALID_VEHICLE; // Next vehicle
952  case 0xF2: return 0; // Cargo subtype
953  }
954 
955  *available = false;
956  return UINT_MAX;
957  }
958 
959  return VehicleGetVariable(const_cast<Vehicle*>(this->v), this, variable, parameter, available);
960 }
961 
962 
963 /* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup *group) const
964 {
965  const Vehicle *v = this->self_scope.v;
966 
967  if (v == nullptr) {
968  if (group->num_loading > 0) return group->loading[0];
969  if (group->num_loaded > 0) return group->loaded[0];
970  return nullptr;
971  }
972 
973  bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
974 
975  uint totalsets = in_motion ? group->num_loaded : group->num_loading;
976 
977  if (totalsets == 0) return nullptr;
978 
979  uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16>(1u, v->cargo_cap);
980  set = std::min(set, totalsets - 1);
981 
982  return in_motion ? group->loaded[set] : group->loading[set];
983 }
984 
986 {
987  switch (Engine::Get(this->self_scope.self_type)->type) {
988  case VEH_TRAIN: return GSF_TRAINS;
989  case VEH_ROAD: return GSF_ROADVEHICLES;
990  case VEH_SHIP: return GSF_SHIPS;
991  case VEH_AIRCRAFT: return GSF_AIRCRAFT;
992  default: return GSF_INVALID;
993  }
994 }
995 
997 {
998  return Engine::Get(this->self_scope.self_type)->grf_prop.local_id;
999 }
1000 
1006 static const GRFFile *GetEngineGrfFile(EngineID engine_type)
1007 {
1008  const Engine *e = Engine::Get(engine_type);
1009  return (e != nullptr) ? e->GetGRF() : nullptr;
1010 }
1011 
1022 VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view,
1023  CallbackID callback, uint32 callback_param1, uint32 callback_param2)
1024  : ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
1025  self_scope(*this, engine_type, v, info_view),
1026  parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
1027  relative_scope(*this, engine_type, v, info_view),
1028  cached_relative_count(0)
1029 {
1030  if (wagon_override == WO_SELF) {
1031  this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1032  } else {
1033  if (wagon_override != WO_NONE && v != nullptr && v->IsGroundVehicle()) {
1034  assert(v->engine_type == engine_type); // overrides make little sense with fake scopes
1035 
1036  /* For trains we always use cached value, except for callbacks because the override spriteset
1037  * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
1038  * as v->cargo_type is temporary changed to the new type */
1039  if (wagon_override == WO_CACHED && v->type == VEH_TRAIN) {
1040  this->root_spritegroup = Train::From(v)->tcache.cached_override;
1041  } else {
1042  this->root_spritegroup = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
1043  }
1044  }
1045 
1046  if (this->root_spritegroup == nullptr) {
1047  const Engine *e = Engine::Get(engine_type);
1048  CargoID cargo = v != nullptr ? v->cargo_type : CT_PURCHASE;
1049  assert(cargo < lengthof(e->grf_prop.spritegroup));
1050  this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
1051  }
1052  }
1053 }
1054 
1055 
1056 
1057 void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result)
1058 {
1060  result->Clear();
1061 
1062  bool sprite_stack = HasBit(EngInfo(engine)->misc_flags, EF_SPRITE_STACK);
1063  uint max_stack = sprite_stack ? lengthof(result->seq) : 1;
1064  for (uint stack = 0; stack < max_stack; ++stack) {
1065  object.ResetState();
1066  object.callback_param1 = image_type | (stack << 8);
1067  const SpriteGroup *group = object.Resolve();
1068  uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
1069  if (group != nullptr && group->GetNumResults() != 0) {
1070  result->seq[result->count].sprite = group->GetResult() + (direction % group->GetNumResults());
1071  result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
1072  result->count++;
1073  }
1074  if (!HasBit(reg100, 31)) break;
1075  }
1076 }
1077 
1078 
1079 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result)
1080 {
1081  const Engine *e = Engine::Get(engine);
1082 
1083  /* Only valid for helicopters */
1084  assert(e->type == VEH_AIRCRAFT);
1085  assert(!(e->u.air.subtype & AIR_CTOL));
1086 
1088  result->Clear();
1089  uint rotor_pos = v == nullptr || info_view ? 0 : v->Next()->Next()->state;
1090 
1091  bool sprite_stack = HasBit(e->info.misc_flags, EF_SPRITE_STACK);
1092  uint max_stack = sprite_stack ? lengthof(result->seq) : 1;
1093  for (uint stack = 0; stack < max_stack; ++stack) {
1094  object.ResetState();
1095  object.callback_param1 = image_type | (stack << 8);
1096  const SpriteGroup *group = object.Resolve();
1097  uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
1098  if (group != nullptr && group->GetNumResults() != 0) {
1099  result->seq[result->count].sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1100  result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
1101  result->count++;
1102  }
1103  if (!HasBit(reg100, 31)) break;
1104  }
1105 }
1106 
1107 
1114 {
1115  assert(v->type == VEH_TRAIN);
1116  return Train::From(v)->tcache.cached_override != nullptr;
1117 }
1118 
1128 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
1129 {
1130  VehicleResolverObject object(engine, v, VehicleResolverObject::WO_UNCACHED, false, callback, param1, param2);
1131  return object.ResolveCallback();
1132 }
1133 
1144 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
1145 {
1146  VehicleResolverObject object(engine, v, VehicleResolverObject::WO_NONE, false, callback, param1, param2);
1147  object.parent_scope.SetVehicle(parent);
1148  return object.ResolveCallback();
1149 }
1150 
1151 
1152 /* Callback 36 handlers */
1153 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
1154 {
1155  return GetEngineProperty(v->engine_type, property, orig_value, v);
1156 }
1157 
1158 
1159 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v)
1160 {
1161  uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
1162  if (callback != CALLBACK_FAILED) return callback;
1163 
1164  return orig_value;
1165 }
1166 
1167 
1168 static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
1169 {
1170  /* We can't trigger a non-existent vehicle... */
1171  assert(v != nullptr);
1172 
1174  object.waiting_triggers = v->waiting_triggers | trigger;
1175  v->waiting_triggers = object.waiting_triggers; // store now for var 5F
1176 
1177  const SpriteGroup *group = object.Resolve();
1178  if (group == nullptr) return;
1179 
1180  /* Store remaining triggers. */
1181  v->waiting_triggers = object.GetRemainingTriggers();
1182 
1183  /* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
1184  byte new_random_bits = Random();
1185  uint32 reseed = object.GetReseedSum();
1186  v->random_bits &= ~reseed;
1187  v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1188 
1189  switch (trigger) {
1190  case VEHICLE_TRIGGER_NEW_CARGO:
1191  /* All vehicles in chain get ANY_NEW_CARGO trigger now.
1192  * So we call it for the first one and they will recurse.
1193  * Indexing part of vehicle random bits needs to be
1194  * same for all triggered vehicles in the chain (to get
1195  * all the random-cargo wagons carry the same cargo,
1196  * i.e.), so we give them all the NEW_CARGO triggered
1197  * vehicle's portion of random bits. */
1198  assert(first);
1199  DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
1200  break;
1201 
1202  case VEHICLE_TRIGGER_DEPOT:
1203  /* We now trigger the next vehicle in chain recursively.
1204  * The random bits portions may be different for each
1205  * vehicle in chain. */
1206  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, 0, true);
1207  break;
1208 
1209  case VEHICLE_TRIGGER_EMPTY:
1210  /* We now trigger the next vehicle in chain
1211  * recursively. The random bits portions must be same
1212  * for each vehicle in chain, so we give them all
1213  * first chained vehicle's portion of random bits. */
1214  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false);
1215  break;
1216 
1217  case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1218  /* Now pass the trigger recursively to the next vehicle
1219  * in chain. */
1220  assert(!first);
1221  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
1222  break;
1223 
1224  case VEHICLE_TRIGGER_CALLBACK_32:
1225  /* Do not do any recursion */
1226  break;
1227  }
1228 }
1229 
1230 void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
1231 {
1232  if (trigger == VEHICLE_TRIGGER_DEPOT) {
1233  /* store that the vehicle entered a depot this tick */
1235  }
1236 
1238  DoTriggerVehicle(v, trigger, 0, true);
1240 }
1241 
1242 /* Functions for changing the order of vehicle purchase lists */
1243 
1245  EngineID engine;
1246  uint target;
1247 };
1248 
1249 static std::vector<ListOrderChange> _list_order_changes;
1250 
1257 void AlterVehicleListOrder(EngineID engine, uint target)
1258 {
1259  /* Add the list order change to a queue */
1260  _list_order_changes.push_back({engine, target});
1261 }
1262 
1269 static bool EnginePreSort(const EngineID &a, const EngineID &b)
1270 {
1271  const EngineIDMapping &id_a = _engine_mngr.at(a);
1272  const EngineIDMapping &id_b = _engine_mngr.at(b);
1273 
1274  /* 1. Sort by engine type */
1275  if (id_a.type != id_b.type) return (int)id_a.type < (int)id_b.type;
1276 
1277  /* 2. Sort by scope-GRFID */
1278  if (id_a.grfid != id_b.grfid) return id_a.grfid < id_b.grfid;
1279 
1280  /* 3. Sort by local ID */
1281  return (int)id_a.internal_id < (int)id_b.internal_id;
1282 }
1283 
1288 {
1289  /* Pre-sort engines by scope-grfid and local index */
1290  std::vector<EngineID> ordering;
1291  for (const Engine *e : Engine::Iterate()) {
1292  ordering.push_back(e->index);
1293  }
1294  std::sort(ordering.begin(), ordering.end(), EnginePreSort);
1295 
1296  /* Apply Insertion-Sort operations */
1297  for (const ListOrderChange &it : _list_order_changes) {
1298  EngineID source = it.engine;
1299  uint local_target = it.target;
1300 
1301  const EngineIDMapping *id_source = _engine_mngr.data() + source;
1302  if (id_source->internal_id == local_target) continue;
1303 
1304  EngineID target = _engine_mngr.GetID(id_source->type, local_target, id_source->grfid);
1305  if (target == INVALID_ENGINE) continue;
1306 
1307  int source_index = find_index(ordering, source);
1308  int target_index = find_index(ordering, target);
1309 
1310  assert(source_index >= 0 && target_index >= 0);
1311  assert(source_index != target_index);
1312 
1313  EngineID *list = ordering.data();
1314  if (source_index < target_index) {
1315  --target_index;
1316  for (int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1317  list[target_index] = source;
1318  } else {
1319  for (int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1320  list[target_index] = source;
1321  }
1322  }
1323 
1324  /* Store final sort-order */
1325  uint index = 0;
1326  for (const EngineID &eid : ordering) {
1327  Engine::Get(eid)->list_position = index;
1328  ++index;
1329  }
1330 
1331  /* Clear out the queue */
1332  _list_order_changes.clear();
1333  _list_order_changes.shrink_to_fit();
1334 }
1335 
1341 {
1343 
1344  /* These variables we have to check; these are the ones with a cache. */
1345  static const int cache_entries[][2] = {
1346  { 0x40, NCVV_POSITION_CONSIST_LENGTH },
1347  { 0x41, NCVV_POSITION_SAME_ID_LENGTH },
1349  { 0x43, NCVV_COMPANY_INFORMATION },
1350  { 0x4D, NCVV_POSITION_IN_VEHICLE },
1351  };
1352  static_assert(NCVV_END == lengthof(cache_entries));
1353 
1354  /* Resolve all the variables, so their caches are set. */
1355  for (size_t i = 0; i < lengthof(cache_entries); i++) {
1356  /* Only resolve when the cache isn't valid. */
1357  if (HasBit(v->grf_cache.cache_valid, cache_entries[i][1])) continue;
1358  bool stub;
1359  ro.GetScope(VSG_SCOPE_SELF)->GetVariable(cache_entries[i][0], 0, &stub);
1360  }
1361 
1362  /* Make sure really all bits are set. */
1363  assert(v->grf_cache.cache_valid == (1 << NCVV_END) - 1);
1364 }
RoadVehicle::overtaking
byte overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
Definition: roadveh.h:112
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
RoadTypeInfo::flags
RoadTypeFlags flags
Bit mask of road type flags.
Definition: road.h:124
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:2883
VRF_TOGGLE_REVERSE
@ VRF_TOGGLE_REVERSE
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
Definition: train.h:31
Aircraft::targetairport
StationID targetairport
Airport to go to next.
Definition: aircraft.h:78
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:174
HELILANDING
@ HELILANDING
Helicopter wants to land.
Definition: airport.h:78
VehicleResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition: newgrf_engine.cpp:963
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:351
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
RoadTypeInfo
Definition: road.h:75
RoadVehicle::state
byte state
Definition: roadveh.h:109
GetEngineLivery
const Livery * GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
Determines the livery for a vehicle.
Definition: vehicle.cpp:1953
VehicleResolverObject::WO_CACHED
@ WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
Definition: newgrf_engine.h:52
WagonOverride
Definition: newgrf_engine.cpp:29
RealSpriteGroup::loaded
const SpriteGroup ** loaded
List of loaded groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:92
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:141
DIRDIFF_REVERSE
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
Definition: direction_type.h:66
VehicleResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_engine.cpp:985
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
ENDTAKEOFF
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
Definition: airport.h:73
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:279
EngineIDMapping::grfid
uint32 grfid
The GRF ID of the file the entity belongs to.
Definition: engine_base.h:164
VehicleScopeResolver::GetRandomBits
uint32 GetRandomBits() const override
Get a few random bits.
Definition: newgrf_engine.cpp:339
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:251
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:278
train.h
AircraftVehicleInfo::subtype
byte subtype
Type of aircraft.
Definition: engine_type.h:101
CargoList::DaysInTransit
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
Definition: cargopacket.h:255
CBID_VEHICLE_START_STOP_CHECK
@ CBID_VEHICLE_START_STOP_CHECK
Called when the company (or AI) tries to start or stop a vehicle.
Definition: newgrf_callbacks.h:141
ListOrderChange
Definition: newgrf_engine.cpp:1244
Vehicle::Previous
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition: vehicle_base.h:599
ListOrderChange::target
uint target
local ID
Definition: newgrf_engine.cpp:1246
GroundVehicleCache::first_engine
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Definition: ground_vehicle.hpp:43
company_base.h
grfmsg
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
Definition: newgrf.cpp:379
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:592
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:25
SpecializedVehicle::Next
T * Next() const
Get next vehicle in the chain.
Definition: vehicle_base.h:1077
HELIENDLANDING
@ HELIENDLANDING
Helicopter wants to finish landing.
Definition: airport.h:79
DIRDIFF_SAME
@ DIRDIFF_SAME
Both directions faces to the same direction.
Definition: direction_type.h:63
Station
Station data structure.
Definition: station_base.h:450
CBID_VEHICLE_MODIFY_PROPERTY
@ CBID_VEHICLE_MODIFY_PROPERTY
Called to modify various vehicle properties.
Definition: newgrf_callbacks.h:159
RealSpriteGroup::num_loaded
byte num_loaded
Number of loaded groups.
Definition: newgrf_spritegroup.h:90
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:94
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:280
Vehicle::load_unload_ticks
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
Definition: vehicle_base.h:334
VehicleSpriteSeq::Clear
void Clear()
Clear all information.
Definition: vehicle_base.h:153
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
ChangeDirDiff
static DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
Applies two differences together.
Definition: direction_func.h:88
NewGRFCache::position_same_id_length
uint32 position_same_id_length
Cache for NewGRF var 41.
Definition: vehicle_base.h:68
Vehicle::random_bits
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:308
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
Vehicle::grf_cache
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition: vehicle_base.h:338
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
VRF_POWEREDWAGON
@ VRF_POWEREDWAGON
Wagon is powered.
Definition: train.h:27
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
Vehicle::acceleration
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:304
HasPowerOnRail
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Definition: rail.h:332
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:315
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ship.h
TERM1
@ TERM1
Heading for terminal 1.
Definition: airport.h:63
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:343
RoadVehicle::overtaking_ctr
byte overtaking_ctr
The length of the current overtake attempt.
Definition: roadveh.h:113
TrainCache::user_def_data
byte user_def_data
Cached property 0x25. Can be set by Callback 0x36.
Definition: train.h:76
NewGRFCache::cache_valid
uint8 cache_valid
Bitset that indicates which cache values are valid.
Definition: vehicle_base.h:72
ENDLANDING
@ ENDLANDING
Airplane wants to finish landing.
Definition: airport.h:77
aircraft.h
DirDifference
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Definition: direction_func.h:68
GetRegister
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
VehicleResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_engine.cpp:996
GetReverseRoadTypeTranslation
uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
Definition: newgrf_roadtype.cpp:172
ORIGINAL_BASE_YEAR
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: date_type.h:49
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition: newgrf.h:92
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:85
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:104
Engine
Definition: engine_base.h:21
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:302
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
EngineIDMapping::internal_id
uint16 internal_id
The internal ID within the GRF file.
Definition: engine_base.h:165
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:444
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:482
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:79
VehicleScopeResolver::self_type
EngineID self_type
Type of the vehicle.
Definition: newgrf_engine.h:24
VehicleResolverObject::relative_scope
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
Definition: newgrf_engine.h:59
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
EnginePreSort
static bool EnginePreSort(const EngineID &a, const EngineID &b)
Comparator function to sort engines via scope-GRFID and local ID.
Definition: newgrf_engine.cpp:1269
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1128
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:296
EngineOverrideManager::GetID
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Definition: engine.cpp:507
GetTargetAirportIfValid
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
Definition: aircraft_cmd.cpp:2122
HANGAR
@ HANGAR
Heading for hangar.
Definition: airport.h:62
Vehicle::breakdowns_since_last_service
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:275
NCVV_POSITION_IN_VEHICLE
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
Definition: vehicle_base.h:60
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
VehicleResolverObject::WO_NONE
@ WO_NONE
Resolve no wagon overrides.
Definition: newgrf_engine.h:50
TERM7
@ TERM7
Heading for terminal 7.
Definition: airport.h:80
CargoSpec::bitnum
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
Definition: cargotype.h:56
TERM3
@ TERM3
Heading for terminal 3.
Definition: airport.h:65
Vehicle::IsArticulatedPart
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Definition: vehicle_base.h:904
AMED_EXACTPOS
@ AMED_EXACTPOS
Go exactly to the destination coordinates.
Definition: airport.h:52
Airport::GetFTA
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Definition: station_base.h:332
GetEngineGrfFile
static const GRFFile * GetEngineGrfFile(EngineID engine_type)
Get the grf file associated with an engine type.
Definition: newgrf_engine.cpp:1006
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:138
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
RealSpriteGroup::loading
const SpriteGroup ** loading
List of loading groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:93
RTFB_CATENARY
@ RTFB_CATENARY
Value for drawing a catenary.
Definition: rail.h:34
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:273
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:30
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Vehicle::GetDisplayProfitThisYear
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:577
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:27
VehicleScopeResolver::GetTriggers
uint32 GetTriggers() const override
Get the triggers.
Definition: newgrf_engine.cpp:344
Vehicle::GetCurrentMaxSpeed
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: vehicle_base.h:503
AMED_SLOWTURN
@ AMED_SLOWTURN
Turn slowly (mostly used in the air).
Definition: airport.h:50
AirportMovingData::flag
uint16 flag
special flags when moving towards the destination.
Definition: airport.h:134
LIT_ALL
static const byte LIT_ALL
Show the liveries of all companies.
Definition: livery.h:17
NewGRFCache::consist_cargo_information
uint32 consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
Definition: vehicle_base.h:69
Aircraft::turn_counter
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
Definition: aircraft.h:82
VF_CARGO_UNLOADING
@ VF_CARGO_UNLOADING
Vehicle is unloading cargo.
Definition: vehicle_base.h:43
NCVV_POSITION_CONSIST_LENGTH
@ NCVV_POSITION_CONSIST_LENGTH
This bit will be set if the NewGRF var 40 currently stored is valid.
Definition: vehicle_base.h:56
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
GroundVehicleCache::cached_veh_length
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
Definition: ground_vehicle.hpp:44
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:344
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:128
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:311
AMED_HOLD
@ AMED_HOLD
Holding pattern movement (above the airport).
Definition: airport.h:56
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:318
find_index
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: smallvec_type.hpp:44
CBID_VEHICLE_SPAWN_VISUAL_EFFECT
@ CBID_VEHICLE_SPAWN_VISUAL_EFFECT
Called to spawn visual effects for vehicles.
Definition: newgrf_callbacks.h:281
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:327
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:269
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:464
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
VEH_EFFECT
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:31
Vehicle::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
Definition: vehicle.cpp:761
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition: newgrf_airport.h:112
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
safeguards.h
Vehicle::reliability_spd_dec
uint16 reliability_spd_dec
Reliability decrease speed.
Definition: vehicle_base.h:272
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
VehicleResolverObject::WO_SELF
@ WO_SELF
Resolve self-override (helicopter rotors and such).
Definition: newgrf_engine.h:53
CargoSpec::weight
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
Definition: cargotype.h:60
GetVehicleCallbackParent
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
Definition: newgrf_engine.cpp:1144
VRF_REVERSE_DIRECTION
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
Definition: train.h:28
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:153
ROTFB_CATENARY
@ ROTFB_CATENARY
Value for drawing a catenary.
Definition: road.h:46
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition: airport.h:143
DirDiff
DirDiff
Enumeration for the difference between two directions.
Definition: direction_type.h:62
EngineIDMapping
Definition: engine_base.h:163
LiveryHelper
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
Definition: newgrf_engine.cpp:405
date_func.h
stdafx.h
TERM5
@ TERM5
Heading for terminal 5.
Definition: airport.h:67
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:31
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
NewGRFCache::company_information
uint32 company_information
Cache for NewGRF var 43.
Definition: vehicle_base.h:70
HELIPAD3
@ HELIPAD3
Heading for helipad 3.
Definition: airport.h:82
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:142
Vehicle::waiting_triggers
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition: vehicle_base.h:309
NewGRFCache::position_in_vehicle
uint32 position_in_vehicle
Cache for NewGRF var 4D.
Definition: vehicle_base.h:71
PropertyID
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
Definition: newgrf_properties.h:18
VF_BUILT_AS_PROTOTYPE
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
Definition: vehicle_base.h:44
PositionHelper
static uint32 PositionHelper(const Vehicle *v, bool consecutive)
Helper to get the position of a vehicle within a chain of vehicles.
Definition: newgrf_engine.cpp:428
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:281
newgrf_spritegroup.h
TERM2
@ TERM2
Heading for terminal 2.
Definition: airport.h:64
VehicleEnteredDepotThisTick
void VehicleEnteredDepotThisTick(Vehicle *v)
Adds a vehicle to the list of vehicles that visited a depot this tick.
Definition: vehicle.cpp:892
AirportFTAClass::delta_z
byte delta_z
Z adjustment for helicopter pads.
Definition: airport.h:183
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
VehicleScopeResolver::v
const struct Vehicle * v
The vehicle being resolved.
Definition: newgrf_engine.h:23
CBID_VEHICLE_COLOUR_MAPPING
@ CBID_VEHICLE_COLOUR_MAPPING
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
Definition: newgrf_callbacks.h:126
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
Vehicle::Move
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Definition: vehicle_base.h:634
Train::wait_counter
uint16 wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
Definition: train.h:100
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
NCVV_CONSIST_CARGO_INFORMATION
@ NCVV_CONSIST_CARGO_INFORMATION
This bit will be set if the NewGRF var 42 currently stored is valid.
Definition: vehicle_base.h:58
UnloadWagonOverrides
void UnloadWagonOverrides(Engine *e)
Unload all wagon override sprite groups.
Definition: newgrf_engine.cpp:73
IsCompatibleRail
static bool IsCompatibleRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType can drive on a tile with a given RailType.
Definition: rail.h:319
Vehicle::vcache
VehicleCache vcache
Cache of often used vehicle values.
Definition: vehicle_base.h:339
Ship
All ships have this type.
Definition: ship.h:26
Vehicle::motion_counter
uint32 motion_counter
counter to occasionally play a vehicle sound.
Definition: vehicle_base.h:305
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:46
ORIGINAL_MAX_YEAR
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
Definition: date_type.h:53
vehicle_func.h
RailtypeInfo::flags
RailTypeFlags flags
Bit mask of rail type flags.
Definition: rail.h:208
station_base.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:76
Pool::PoolItem<&_engine_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:321
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:605
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:323
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:316
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:169
newgrf_roadtype.h
VehicleResolverObject::WO_UNCACHED
@ WO_UNCACHED
Resolve wagon overrides.
Definition: newgrf_engine.h:51
GroundVehicleCache::cached_power
uint32 cached_power
Total power of the consist (valid only for the first engine).
Definition: ground_vehicle.hpp:38
FillNewGRFVehicleCache
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
Definition: newgrf_engine.cpp:1340
NCVV_POSITION_SAME_ID_LENGTH
@ NCVV_POSITION_SAME_ID_LENGTH
This bit will be set if the NewGRF var 41 currently stored is valid.
Definition: vehicle_base.h:57
Vehicle::subspeed
byte subspeed
fractional speed
Definition: vehicle_base.h:303
GetRoadTypeTranslation
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8 tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
Definition: newgrf_roadtype.cpp:142
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
VehicleResolverObject::self_scope
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
Definition: newgrf_engine.h:56
Vehicle::InvalidateNewGRFCacheOfChain
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
Definition: vehicle_base.h:471
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
MapAircraftMovementState
static byte MapAircraftMovementState(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2)
Definition: newgrf_engine.cpp:165
Order::MapOldOrder
uint16 MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
Definition: order_cmd.cpp:207
Aircraft::IsNormalAircraft
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
Definition: aircraft.h:121
GroundVehicle::IsEngine
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
Definition: ground_vehicle.hpp:316
VehicleResolverObject::parent_scope
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
Definition: newgrf_engine.h:57
Ship::state
TrackBits state
The "track" the ship is following.
Definition: ship.h:27
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
AlterVehicleListOrder
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
Definition: newgrf_engine.cpp:1257
CargoSpec::classes
uint16 classes
Classes of this cargo type.
Definition: cargotype.h:78
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:268
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:913
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:267
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:127
UsesWagonOverride
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
Definition: newgrf_engine.cpp:1113
HELIPAD1
@ HELIPAD1
Heading for helipad 1.
Definition: airport.h:69
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:333
Vehicle::breakdown_chance
byte breakdown_chance
Current chance of breakdowns.
Definition: vehicle_base.h:276
CommitVehicleListOrderChanges
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
Definition: newgrf_engine.cpp:1287
HELITAKEOFF
@ HELITAKEOFF
Helicopter wants to leave the airport.
Definition: airport.h:74
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
RoadVehicle::crashed_ctr
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
Definition: roadveh.h:114
VehicleResolverObject
Resolver for a vehicle (chain)
Definition: newgrf_engine.h:47
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:300
VSG_SCOPE_RELATIVE
@ VSG_SCOPE_RELATIVE
Relative position (vehicles only)
Definition: newgrf_spritegroup.h:105
ScopeResolver::GetVariable
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_spritegroup.cpp:123
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:322
VehicleCache::cached_max_speed
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Definition: vehicle_base.h:121
company_func.h
GetRailTypeTranslation
RailType GetRailTypeTranslation(uint8 railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
Definition: newgrf_railtype.cpp:147
NCVV_END
@ NCVV_END
End of the bits.
Definition: vehicle_base.h:61
ReallocT
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
Definition: alloc_func.hpp:111
EF_SPRITE_STACK
@ EF_SPRITE_STACK
Draw vehicle by stacking multiple sprites.
Definition: engine_type.h:161
GetReverseRailTypeTranslation
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
Definition: newgrf_railtype.cpp:169
VEH_DISASTER
@ VEH_DISASTER
Disaster vehicle type.
Definition: vehicle_type.h:32
Vehicle::breakdown_delay
byte breakdown_delay
Counter for managing breakdown length.
Definition: vehicle_base.h:274
GetCompanyInfo
uint32 GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Definition: newgrf_commons.cpp:467
Aircraft::pos
byte pos
Next desired position of the aircraft.
Definition: aircraft.h:76
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition: engine_type.h:92
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:336
Vehicle::day_counter
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:322
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:377
random_func.hpp
STARTTAKEOFF
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
Definition: airport.h:72
RealSpriteGroup::num_loading
byte num_loading
Number of loading groups.
Definition: newgrf_spritegroup.h:91
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
ClampToU16
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
Definition: math_func.hpp:153
HasPowerOnRoad
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition: road.h:239
CBID_VEHICLE_32DAY_CALLBACK
@ CBID_VEHICLE_32DAY_CALLBACK
Called for every vehicle every 32 days (not all on same date though).
Definition: newgrf_callbacks.h:144
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
GetTileRailType
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Definition: rail.cpp:155
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:314
ATP_TTDP_LARGE
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Definition: newgrf_airport.h:83
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:289
Engine::grf_prop
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Definition: engine_base.h:58
AMED_HELI_RAISE
@ AMED_HELI_RAISE
Helicopter take-off.
Definition: airport.h:54
NCVV_COMPANY_INFORMATION
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
Definition: vehicle_base.h:59
LANDING
@ LANDING
Airplane wants to land.
Definition: airport.h:76
GRFFilePropsBase::local_id
uint16 local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:319
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
Aircraft::state
byte state
State of the airport.
Definition: aircraft.h:79
TERM6
@ TERM6
Heading for terminal 6.
Definition: airport.h:68
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:315
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition: newgrf_callbacks.h:25
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:297
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
MapAircraftMovementAction
static byte MapAircraftMovementAction(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This...
Definition: newgrf_engine.cpp:292
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:320
Vehicle::reliability
uint16 reliability
Reliability.
Definition: vehicle_base.h:271
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition: vehicle_base.h:1059
TERM8
@ TERM8
Heading for terminal 8.
Definition: airport.h:81
EngineIDMapping::type
VehicleType type
The engine type.
Definition: engine_base.h:166
VehicleResolverObject::VehicleResolverObject
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view=false, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Resolver of a vehicle (chain).
Definition: newgrf_engine.cpp:1022
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:33
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:320
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:469
NewGRFCache::position_consist_length
uint32 position_consist_length
Cache for NewGRF var 40.
Definition: vehicle_base.h:67
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:68
TAKEOFF
@ TAKEOFF
Airplane wants to leave the airport.
Definition: airport.h:71
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
VehicleScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
Definition: newgrf_engine.cpp:928
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:698
AirportFTAClass::MovingData
const AirportMovingData * MovingData(byte position) const
Get movement data at a position.
Definition: airport.h:170
HELIPAD2
@ HELIPAD2
Heading for helipad 2.
Definition: airport.h:70
Livery
Information about a particular livery.
Definition: livery.h:78
newgrf_cargo.h
VehicleResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_engine.cpp:350
Vehicle::GetDisplayProfitLastYear
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:583
SpriteGroup
Definition: newgrf_spritegroup.h:57
FLYING
@ FLYING
Vehicle is flying in the air.
Definition: airport.h:75
AMED_HELI_LOWER
@ AMED_HELI_LOWER
Helicopter landing.
Definition: airport.h:55
newgrf_railtype.h
SetEngineGRF
void SetEngineGRF(EngineID engine, const GRFFile *file)
Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game.
Definition: newgrf_engine.cpp:103
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
VehicleScopeResolver
Resolver for a vehicle scope.
Definition: newgrf_engine.h:22
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:40
debug.h
DAYS_TILL_ORIGINAL_BASE_YEAR
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR,...
Definition: date_type.h:80
Vehicle::date_of_last_service
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:270
AMED_BRAKE
@ AMED_BRAKE
Taxiing at the airport.
Definition: airport.h:53
TERM4
@ TERM4
Heading for terminal 4.
Definition: airport.h:66
CBID_TRAIN_ALLOW_WAGON_ATTACH
@ CBID_TRAIN_ALLOW_WAGON_ATTACH
Determine whether a wagon can be attached to an already existing train.
Definition: newgrf_callbacks.h:72
roadveh.h
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34