OpenTTD Source  1.11.0-beta2
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  /*
765  * General vehicle properties
766  *
767  * Some parts of the TTD Vehicle structure are omitted for various reasons
768  * (see http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#_VehicleArray)
769  */
770  switch (variable - 0x80) {
771  case 0x00: return v->type + 0x10;
772  case 0x01: return MapOldSubType(v);
773  case 0x02: break; // not implemented
774  case 0x03: break; // not implemented
775  case 0x04: return v->index;
776  case 0x05: return GB(v->index, 8, 8);
777  case 0x06: break; // not implemented
778  case 0x07: break; // not implemented
779  case 0x08: break; // not implemented
780  case 0x09: break; // not implemented
781  case 0x0A: return v->current_order.MapOldOrder();
782  case 0x0B: return v->current_order.GetDestination();
783  case 0x0C: return v->GetNumOrders();
784  case 0x0D: return v->cur_real_order_index;
785  case 0x0E: break; // not implemented
786  case 0x0F: break; // not implemented
787  case 0x10:
788  case 0x11: {
789  uint ticks;
790  if (v->current_order.IsType(OT_LOADING)) {
791  ticks = v->load_unload_ticks;
792  } else {
793  switch (v->type) {
794  case VEH_TRAIN: ticks = Train::From(v)->wait_counter; break;
795  case VEH_AIRCRAFT: ticks = Aircraft::From(v)->turn_counter; break;
796  default: ticks = 0; break;
797  }
798  }
799  return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8);
800  }
801  case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF);
802  case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
803  case 0x14: return v->GetServiceInterval();
804  case 0x15: return GB(v->GetServiceInterval(), 8, 8);
805  case 0x16: return v->last_station_visited;
806  case 0x17: return v->tick_counter;
807  case 0x18:
808  case 0x19: {
809  uint max_speed;
810  switch (v->type) {
811  case VEH_AIRCRAFT:
812  max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
813  break;
814 
815  default:
816  max_speed = v->vcache.cached_max_speed;
817  break;
818  }
819  return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
820  }
821  case 0x1A: return v->x_pos;
822  case 0x1B: return GB(v->x_pos, 8, 8);
823  case 0x1C: return v->y_pos;
824  case 0x1D: return GB(v->y_pos, 8, 8);
825  case 0x1E: return v->z_pos;
826  case 0x1F: return object->info_view ? DIR_W : v->direction;
827  case 0x20: break; // not implemented
828  case 0x21: break; // not implemented
829  case 0x22: break; // not implemented
830  case 0x23: break; // not implemented
831  case 0x24: break; // not implemented
832  case 0x25: break; // not implemented
833  case 0x26: break; // not implemented
834  case 0x27: break; // not implemented
835  case 0x28: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
836  case 0x29: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
837  case 0x2A: break; // not implemented
838  case 0x2B: break; // not implemented
839  case 0x2C: break; // not implemented
840  case 0x2D: break; // not implemented
841  case 0x2E: break; // not implemented
842  case 0x2F: break; // not implemented
843  case 0x30: break; // not implemented
844  case 0x31: break; // not implemented
845  case 0x32: return v->vehstatus;
846  case 0x33: return 0; // non-existent high byte of vehstatus
847  case 0x34: return v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed;
848  case 0x35: return GB(v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 8);
849  case 0x36: return v->subspeed;
850  case 0x37: return v->acceleration;
851  case 0x38: break; // not implemented
852  case 0x39: return v->cargo_type;
853  case 0x3A: return v->cargo_cap;
854  case 0x3B: return GB(v->cargo_cap, 8, 8);
855  case 0x3C: return ClampToU16(v->cargo.StoredCount());
856  case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8);
857  case 0x3E: return v->cargo.Source();
858  case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
859  case 0x40: return ClampToU16(v->age);
860  case 0x41: return GB(ClampToU16(v->age), 8, 8);
861  case 0x42: return ClampToU16(v->max_age);
862  case 0x43: return GB(ClampToU16(v->max_age), 8, 8);
864  case 0x45: return v->unitnumber;
865  case 0x46: return v->GetEngine()->grf_prop.local_id;
866  case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
867  case 0x48:
868  if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
869  return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
870 
871  case 0x49: return v->day_counter;
872  case 0x4A: return v->breakdowns_since_last_service;
873  case 0x4B: return v->breakdown_ctr;
874  case 0x4C: return v->breakdown_delay;
875  case 0x4D: return v->breakdown_chance;
876  case 0x4E: return v->reliability;
877  case 0x4F: return GB(v->reliability, 8, 8);
878  case 0x50: return v->reliability_spd_dec;
879  case 0x51: return GB(v->reliability_spd_dec, 8, 8);
880  case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
881  case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24);
882  case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
883  case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8);
884  case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
885  case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24);
886  case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
887  case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8);
888  case 0x5A: return v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index;
889  case 0x5B: break; // not implemented
890  case 0x5C: return ClampToI32(v->value);
891  case 0x5D: return GB(ClampToI32(v->value), 8, 24);
892  case 0x5E: return GB(ClampToI32(v->value), 16, 16);
893  case 0x5F: return GB(ClampToI32(v->value), 24, 8);
894  case 0x60: break; // not implemented
895  case 0x61: break; // not implemented
896  case 0x62: break; // vehicle specific, see below
897  case 0x63: break; // not implemented
898  case 0x64: break; // vehicle specific, see below
899  case 0x65: break; // vehicle specific, see below
900  case 0x66: break; // vehicle specific, see below
901  case 0x67: break; // vehicle specific, see below
902  case 0x68: break; // vehicle specific, see below
903  case 0x69: break; // vehicle specific, see below
904  case 0x6A: break; // not implemented
905  case 0x6B: break; // not implemented
906  case 0x6C: break; // not implemented
907  case 0x6D: break; // not implemented
908  case 0x6E: break; // not implemented
909  case 0x6F: break; // not implemented
910  case 0x70: break; // not implemented
911  case 0x71: break; // not implemented
912  case 0x72: return v->cargo_subtype;
913  case 0x73: break; // vehicle specific, see below
914  case 0x74: break; // vehicle specific, see below
915  case 0x75: break; // vehicle specific, see below
916  case 0x76: break; // vehicle specific, see below
917  case 0x77: break; // vehicle specific, see below
918  case 0x78: break; // not implemented
919  case 0x79: break; // not implemented
920  case 0x7A: return v->random_bits;
921  case 0x7B: return v->waiting_triggers;
922  case 0x7C: break; // vehicle specific, see below
923  case 0x7D: break; // vehicle specific, see below
924  case 0x7E: break; // not implemented
925  case 0x7F: break; // vehicle specific, see below
926  }
927 
928  /* Vehicle specific properties */
929  switch (v->type) {
930  case VEH_TRAIN: {
931  Train *t = Train::From(v);
932  switch (variable - 0x80) {
933  case 0x62: return t->track;
934  case 0x66: return t->railtype;
935  case 0x73: return 0x80 + VEHICLE_LENGTH - t->gcache.cached_veh_length;
936  case 0x74: return t->gcache.cached_power;
937  case 0x75: return GB(t->gcache.cached_power, 8, 24);
938  case 0x76: return GB(t->gcache.cached_power, 16, 16);
939  case 0x77: return GB(t->gcache.cached_power, 24, 8);
940  case 0x7C: return t->First()->index;
941  case 0x7D: return GB(t->First()->index, 8, 8);
942  case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
943  }
944  break;
945  }
946 
947  case VEH_ROAD: {
949  switch (variable - 0x80) {
950  case 0x62: return rv->state;
951  case 0x64: return rv->blocked_ctr;
952  case 0x65: return GB(rv->blocked_ctr, 8, 8);
953  case 0x66: return rv->overtaking;
954  case 0x67: return rv->overtaking_ctr;
955  case 0x68: return rv->crashed_ctr;
956  case 0x69: return GB(rv->crashed_ctr, 8, 8);
957  }
958  break;
959  }
960 
961  case VEH_SHIP: {
962  Ship *s = Ship::From(v);
963  switch (variable - 0x80) {
964  case 0x62: return s->state;
965  }
966  break;
967  }
968 
969  case VEH_AIRCRAFT: {
970  Aircraft *a = Aircraft::From(v);
971  switch (variable - 0x80) {
972  case 0x62: return MapAircraftMovementState(a); // Current movement state
973  case 0x63: return a->targetairport; // Airport to which the action refers
974  case 0x66: return MapAircraftMovementAction(a); // Current movement action
975  }
976  break;
977  }
978 
979  default: break;
980  }
981 
982  DEBUG(grf, 1, "Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->type);
983 
984  *available = false;
985  return UINT_MAX;
986 }
987 
988 /* virtual */ uint32 VehicleScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
989 {
990  if (this->v == nullptr) {
991  /* Vehicle does not exist, so we're in a purchase list */
992  switch (variable) {
993  case 0x43: return GetCompanyInfo(_current_company, LiveryHelper(this->self_type, nullptr)); // Owner information
994  case 0x46: return 0; // Motion counter
995  case 0x47: { // Vehicle cargo info
996  const Engine *e = Engine::Get(this->self_type);
997  CargoID cargo_type = e->GetDefaultCargoType();
998  if (cargo_type != CT_INVALID) {
999  const CargoSpec *cs = CargoSpec::Get(cargo_type);
1000  return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
1001  } else {
1002  return 0x000000FF;
1003  }
1004  }
1005  case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
1006  case 0x49: return _cur_year; // 'Long' format build year
1007  case 0x4B: return _date; // Long date of last service
1008  case 0x92: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service
1009  case 0x93: return GB(Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
1010  case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
1011  case 0xDA: return INVALID_VEHICLE; // Next vehicle
1012  case 0xF2: return 0; // Cargo subtype
1013  }
1014 
1015  *available = false;
1016  return UINT_MAX;
1017  }
1018 
1019  return VehicleGetVariable(const_cast<Vehicle*>(this->v), this, variable, parameter, available);
1020 }
1021 
1022 
1023 /* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup *group) const
1024 {
1025  const Vehicle *v = this->self_scope.v;
1026 
1027  if (v == nullptr) {
1028  if (group->num_loading > 0) return group->loading[0];
1029  if (group->num_loaded > 0) return group->loaded[0];
1030  return nullptr;
1031  }
1032 
1033  bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
1034 
1035  uint totalsets = in_motion ? group->num_loaded : group->num_loading;
1036 
1037  if (totalsets == 0) return nullptr;
1038 
1039  uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16>(1u, v->cargo_cap);
1040  set = std::min(set, totalsets - 1);
1041 
1042  return in_motion ? group->loaded[set] : group->loading[set];
1043 }
1044 
1046 {
1047  switch (Engine::Get(this->self_scope.self_type)->type) {
1048  case VEH_TRAIN: return GSF_TRAINS;
1049  case VEH_ROAD: return GSF_ROADVEHICLES;
1050  case VEH_SHIP: return GSF_SHIPS;
1051  case VEH_AIRCRAFT: return GSF_AIRCRAFT;
1052  default: return GSF_INVALID;
1053  }
1054 }
1055 
1057 {
1058  return Engine::Get(this->self_scope.self_type)->grf_prop.local_id;
1059 }
1060 
1066 static const GRFFile *GetEngineGrfFile(EngineID engine_type)
1067 {
1068  const Engine *e = Engine::Get(engine_type);
1069  return (e != nullptr) ? e->GetGRF() : nullptr;
1070 }
1071 
1082 VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view,
1083  CallbackID callback, uint32 callback_param1, uint32 callback_param2)
1084  : ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
1085  self_scope(*this, engine_type, v, info_view),
1086  parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
1087  relative_scope(*this, engine_type, v, info_view),
1088  cached_relative_count(0)
1089 {
1090  if (wagon_override == WO_SELF) {
1091  this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1092  } else {
1093  if (wagon_override != WO_NONE && v != nullptr && v->IsGroundVehicle()) {
1094  assert(v->engine_type == engine_type); // overrides make little sense with fake scopes
1095 
1096  /* For trains we always use cached value, except for callbacks because the override spriteset
1097  * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
1098  * as v->cargo_type is temporary changed to the new type */
1099  if (wagon_override == WO_CACHED && v->type == VEH_TRAIN) {
1100  this->root_spritegroup = Train::From(v)->tcache.cached_override;
1101  } else {
1102  this->root_spritegroup = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
1103  }
1104  }
1105 
1106  if (this->root_spritegroup == nullptr) {
1107  const Engine *e = Engine::Get(engine_type);
1108  CargoID cargo = v != nullptr ? v->cargo_type : CT_PURCHASE;
1109  assert(cargo < lengthof(e->grf_prop.spritegroup));
1110  this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
1111  }
1112  }
1113 }
1114 
1115 
1116 
1117 void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result)
1118 {
1120  result->Clear();
1121 
1122  bool sprite_stack = HasBit(EngInfo(engine)->misc_flags, EF_SPRITE_STACK);
1123  uint max_stack = sprite_stack ? lengthof(result->seq) : 1;
1124  for (uint stack = 0; stack < max_stack; ++stack) {
1125  object.ResetState();
1126  object.callback_param1 = image_type | (stack << 8);
1127  const SpriteGroup *group = object.Resolve();
1128  uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
1129  if (group != nullptr && group->GetNumResults() != 0) {
1130  result->seq[result->count].sprite = group->GetResult() + (direction % group->GetNumResults());
1131  result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
1132  result->count++;
1133  }
1134  if (!HasBit(reg100, 31)) break;
1135  }
1136 }
1137 
1138 
1139 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result)
1140 {
1141  const Engine *e = Engine::Get(engine);
1142 
1143  /* Only valid for helicopters */
1144  assert(e->type == VEH_AIRCRAFT);
1145  assert(!(e->u.air.subtype & AIR_CTOL));
1146 
1148  result->Clear();
1149  uint rotor_pos = v == nullptr || info_view ? 0 : v->Next()->Next()->state;
1150 
1151  bool sprite_stack = HasBit(e->info.misc_flags, EF_SPRITE_STACK);
1152  uint max_stack = sprite_stack ? lengthof(result->seq) : 1;
1153  for (uint stack = 0; stack < max_stack; ++stack) {
1154  object.ResetState();
1155  object.callback_param1 = image_type | (stack << 8);
1156  const SpriteGroup *group = object.Resolve();
1157  uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
1158  if (group != nullptr && group->GetNumResults() != 0) {
1159  result->seq[result->count].sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1160  result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
1161  result->count++;
1162  }
1163  if (!HasBit(reg100, 31)) break;
1164  }
1165 }
1166 
1167 
1174 {
1175  assert(v->type == VEH_TRAIN);
1176  return Train::From(v)->tcache.cached_override != nullptr;
1177 }
1178 
1188 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
1189 {
1190  VehicleResolverObject object(engine, v, VehicleResolverObject::WO_UNCACHED, false, callback, param1, param2);
1191  return object.ResolveCallback();
1192 }
1193 
1204 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
1205 {
1206  VehicleResolverObject object(engine, v, VehicleResolverObject::WO_NONE, false, callback, param1, param2);
1207  object.parent_scope.SetVehicle(parent);
1208  return object.ResolveCallback();
1209 }
1210 
1211 
1212 /* Callback 36 handlers */
1213 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value)
1214 {
1215  return GetEngineProperty(v->engine_type, property, orig_value, v);
1216 }
1217 
1218 
1219 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v)
1220 {
1221  uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
1222  if (callback != CALLBACK_FAILED) return callback;
1223 
1224  return orig_value;
1225 }
1226 
1227 
1228 static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
1229 {
1230  /* We can't trigger a non-existent vehicle... */
1231  assert(v != nullptr);
1232 
1234  object.waiting_triggers = v->waiting_triggers | trigger;
1235  v->waiting_triggers = object.waiting_triggers; // store now for var 5F
1236 
1237  const SpriteGroup *group = object.Resolve();
1238  if (group == nullptr) return;
1239 
1240  /* Store remaining triggers. */
1241  v->waiting_triggers = object.GetRemainingTriggers();
1242 
1243  /* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
1244  byte new_random_bits = Random();
1245  uint32 reseed = object.GetReseedSum();
1246  v->random_bits &= ~reseed;
1247  v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1248 
1249  switch (trigger) {
1250  case VEHICLE_TRIGGER_NEW_CARGO:
1251  /* All vehicles in chain get ANY_NEW_CARGO trigger now.
1252  * So we call it for the first one and they will recurse.
1253  * Indexing part of vehicle random bits needs to be
1254  * same for all triggered vehicles in the chain (to get
1255  * all the random-cargo wagons carry the same cargo,
1256  * i.e.), so we give them all the NEW_CARGO triggered
1257  * vehicle's portion of random bits. */
1258  assert(first);
1259  DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
1260  break;
1261 
1262  case VEHICLE_TRIGGER_DEPOT:
1263  /* We now trigger the next vehicle in chain recursively.
1264  * The random bits portions may be different for each
1265  * vehicle in chain. */
1266  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, 0, true);
1267  break;
1268 
1269  case VEHICLE_TRIGGER_EMPTY:
1270  /* We now trigger the next vehicle in chain
1271  * recursively. The random bits portions must be same
1272  * for each vehicle in chain, so we give them all
1273  * first chained vehicle's portion of random bits. */
1274  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false);
1275  break;
1276 
1277  case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1278  /* Now pass the trigger recursively to the next vehicle
1279  * in chain. */
1280  assert(!first);
1281  if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
1282  break;
1283 
1284  case VEHICLE_TRIGGER_CALLBACK_32:
1285  /* Do not do any recursion */
1286  break;
1287  }
1288 }
1289 
1290 void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
1291 {
1292  if (trigger == VEHICLE_TRIGGER_DEPOT) {
1293  /* store that the vehicle entered a depot this tick */
1295  }
1296 
1298  DoTriggerVehicle(v, trigger, 0, true);
1300 }
1301 
1302 /* Functions for changing the order of vehicle purchase lists */
1303 
1305  EngineID engine;
1306  uint target;
1307 };
1308 
1309 static std::vector<ListOrderChange> _list_order_changes;
1310 
1317 void AlterVehicleListOrder(EngineID engine, uint target)
1318 {
1319  /* Add the list order change to a queue */
1320  _list_order_changes.push_back({engine, target});
1321 }
1322 
1329 static bool EnginePreSort(const EngineID &a, const EngineID &b)
1330 {
1331  const EngineIDMapping &id_a = _engine_mngr.at(a);
1332  const EngineIDMapping &id_b = _engine_mngr.at(b);
1333 
1334  /* 1. Sort by engine type */
1335  if (id_a.type != id_b.type) return (int)id_a.type < (int)id_b.type;
1336 
1337  /* 2. Sort by scope-GRFID */
1338  if (id_a.grfid != id_b.grfid) return id_a.grfid < id_b.grfid;
1339 
1340  /* 3. Sort by local ID */
1341  return (int)id_a.internal_id < (int)id_b.internal_id;
1342 }
1343 
1348 {
1349  /* Pre-sort engines by scope-grfid and local index */
1350  std::vector<EngineID> ordering;
1351  for (const Engine *e : Engine::Iterate()) {
1352  ordering.push_back(e->index);
1353  }
1354  std::sort(ordering.begin(), ordering.end(), EnginePreSort);
1355 
1356  /* Apply Insertion-Sort operations */
1357  for (const ListOrderChange &it : _list_order_changes) {
1358  EngineID source = it.engine;
1359  uint local_target = it.target;
1360 
1361  const EngineIDMapping *id_source = _engine_mngr.data() + source;
1362  if (id_source->internal_id == local_target) continue;
1363 
1364  EngineID target = _engine_mngr.GetID(id_source->type, local_target, id_source->grfid);
1365  if (target == INVALID_ENGINE) continue;
1366 
1367  int source_index = find_index(ordering, source);
1368  int target_index = find_index(ordering, target);
1369 
1370  assert(source_index >= 0 && target_index >= 0);
1371  assert(source_index != target_index);
1372 
1373  EngineID *list = ordering.data();
1374  if (source_index < target_index) {
1375  --target_index;
1376  for (int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1377  list[target_index] = source;
1378  } else {
1379  for (int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1380  list[target_index] = source;
1381  }
1382  }
1383 
1384  /* Store final sort-order */
1385  uint index = 0;
1386  for (const EngineID &eid : ordering) {
1387  Engine::Get(eid)->list_position = index;
1388  ++index;
1389  }
1390 
1391  /* Clear out the queue */
1392  _list_order_changes.clear();
1393  _list_order_changes.shrink_to_fit();
1394 }
1395 
1401 {
1403 
1404  /* These variables we have to check; these are the ones with a cache. */
1405  static const int cache_entries[][2] = {
1406  { 0x40, NCVV_POSITION_CONSIST_LENGTH },
1407  { 0x41, NCVV_POSITION_SAME_ID_LENGTH },
1409  { 0x43, NCVV_COMPANY_INFORMATION },
1410  { 0x4D, NCVV_POSITION_IN_VEHICLE },
1411  };
1412  static_assert(NCVV_END == lengthof(cache_entries));
1413 
1414  /* Resolve all the variables, so their caches are set. */
1415  for (size_t i = 0; i < lengthof(cache_entries); i++) {
1416  /* Only resolve when the cache isn't valid. */
1417  if (HasBit(v->grf_cache.cache_valid, cache_entries[i][1])) continue;
1418  bool stub;
1419  ro.GetScope(VSG_SCOPE_SELF)->GetVariable(cache_entries[i][0], 0, &stub);
1420  }
1421 
1422  /* Make sure really all bits are set. */
1423  assert(v->grf_cache.cache_valid == (1 << NCVV_END) - 1);
1424 }
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:1023
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:1045
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:1304
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:1306
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:26
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:1056
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:1329
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1188
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:1066
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:28
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:1204
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:47
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:1400
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:1317
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:1173
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:1347
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:367
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:1082
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:454
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:988
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