OpenTTD Source: src/newgrf_engine.cpp Source File

OpenTTD Source 13.2.1

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 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
30 {
31 Engine *e = Engine::Get(engine);
32
33 assert(cargo < NUM_CARGO + 2); // Include CT_DEFAULT and CT_PURCHASE pseudo cargoes.
34
35 WagonOverride *wo = &e->overrides.emplace_back();
36 wo->group = group;
37 wo->cargo = cargo;
38 wo->engines.assign(train_id, train_id + trains);
39 }
40
41 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine)
42 {
43 const Engine *e = Engine::Get(engine);
44
45 for (const WagonOverride &wo : e->overrides) {
46 if (wo.cargo != cargo && wo.cargo != CT_DEFAULT) continue;
47 if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end()) return wo.group;
48 }
49 return nullptr;
50 }
51
52 void SetCustomEngineSprites(EngineID engine, byte cargo, const SpriteGroup *group)
53 {
54 Engine *e = Engine::Get(engine);
55 assert(cargo < lengthof(e->grf_prop.spritegroup));
56
57 if (e->grf_prop.spritegroup[cargo] != nullptr) {
58 grfmsg(6, "SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
59 }
60 e->grf_prop.spritegroup[cargo] = group;
61 }
62
63
70 void SetEngineGRF(EngineID engine, const GRFFile *file)
71 {
72 Engine *e = Engine::Get(engine);
73 e->grf_prop.grffile = file;
74 }
75
76
77 static int MapOldSubType(const Vehicle *v)
78 {
79 switch (v->type) {
80 case VEH_TRAIN:
81 if (Train::From(v)->IsEngine()) return 0;
82 if (Train::From(v)->IsFreeWagon()) return 4;
83 return 2;
84 case VEH_ROAD:
85 case VEH_SHIP: return 0;
86 case VEH_AIRCRAFT:
87 case VEH_DISASTER: return v->subtype;
88 case VEH_EFFECT: return v->subtype << 1;
89 default: NOT_REACHED();
90 }
91 }
92
93
94 /* TTDP style aircraft movement states for GRF Action 2 Var 0xE2 */
95 enum TTDPAircraftMovementStates {
96 AMS_TTDP_HANGAR,
97 AMS_TTDP_TO_HANGAR,
98 AMS_TTDP_TO_PAD1,
99 AMS_TTDP_TO_PAD2,
100 AMS_TTDP_TO_PAD3,
101 AMS_TTDP_TO_ENTRY_2_AND_3,
102 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
103 AMS_TTDP_TO_JUNCTION,
104 AMS_TTDP_LEAVE_RUNWAY,
105 AMS_TTDP_TO_INWAY,
106 AMS_TTDP_TO_RUNWAY,
107 AMS_TTDP_TO_OUTWAY,
108 AMS_TTDP_WAITING,
109 AMS_TTDP_TAKEOFF,
110 AMS_TTDP_TO_TAKEOFF,
111 AMS_TTDP_CLIMBING,
112 AMS_TTDP_FLIGHT_APPROACH,
113 AMS_TTDP_UNUSED_0x11,
114 AMS_TTDP_FLIGHT_TO_TOWER,
115 AMS_TTDP_UNUSED_0x13,
116 AMS_TTDP_FLIGHT_FINAL,
117 AMS_TTDP_FLIGHT_DESCENT,
118 AMS_TTDP_BRAKING,
119 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
120 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
121 AMS_TTDP_HELI_LAND_AIRPORT,
122 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
123 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
124 AMS_TTDP_HELI_LAND_HELIPORT,
125 };
126
127
132 static byte MapAircraftMovementState(const Aircraft *v)
133 {
134 const Station *st = GetTargetAirportIfValid(v);
135 if (st == nullptr) return AMS_TTDP_FLIGHT_TO_TOWER;
136
137 const AirportFTAClass *afc = st->airport.GetFTA();
138 uint16 amdflag = afc->MovingData(v->pos)->flag;
139
140 switch (v->state) {
141 case HANGAR:
142 /* The international airport is a special case as helicopters can land in
143 * front of the hangar. Helicopters also change their air.state to
144 * AMED_HELI_LOWER some time before actually descending. */
145
146 /* This condition only occurs for helicopters, during descent,
147 * to a landing by the hangar of an international airport. */
148 if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT;
149
150 /* This condition only occurs for helicopters, before starting descent,
151 * to a landing by the hangar of an international airport. */
152 if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER;
153
154 /* The final two conditions apply to helicopters or aircraft.
155 * Has reached hangar? */
156 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_HANGAR;
157
158 /* Still moving towards hangar. */
159 return AMS_TTDP_TO_HANGAR;
160
161 case TERM1:
162 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD1;
163 return AMS_TTDP_TO_JUNCTION;
164
165 case TERM2:
166 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD2;
167 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
168
169 case TERM3:
170 case TERM4:
171 case TERM5:
172 case TERM6:
173 case TERM7:
174 case TERM8:
175 /* TTDPatch only has 3 terminals, so treat these states the same */
176 if (amdflag & AMED_EXACTPOS) return AMS_TTDP_TO_PAD3;
177 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
178
179 case HELIPAD1:
180 case HELIPAD2:
181 case HELIPAD3:
182 /* Will only occur for helicopters.*/
183 if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending.
184 if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent.
185 return AMS_TTDP_TO_JUNCTION; // On the ground.
186
187 case TAKEOFF: // Moving to takeoff position.
188 return AMS_TTDP_TO_OUTWAY;
189
190 case STARTTAKEOFF: // Accelerating down runway.
191 return AMS_TTDP_TAKEOFF;
192
193 case ENDTAKEOFF: // Ascent
194 return AMS_TTDP_CLIMBING;
195
196 case HELITAKEOFF: // Helicopter is moving to take off position.
197 if (afc->delta_z == 0) {
198 return amdflag & AMED_HELI_RAISE ?
199 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
200 } else {
201 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
202 }
203
204 case FLYING:
205 return amdflag & AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
206
207 case LANDING: // Descent
208 return AMS_TTDP_FLIGHT_DESCENT;
209
210 case ENDLANDING: // On the runway braking
211 if (amdflag & AMED_BRAKE) return AMS_TTDP_BRAKING;
212 /* Landed - moving off runway */
213 return AMS_TTDP_TO_INWAY;
214
215 case HELILANDING:
216 case HELIENDLANDING: // Helicoptor is descending.
217 if (amdflag & AMED_HELI_LOWER) {
218 return afc->delta_z == 0 ?
219 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
220 } else {
221 return AMS_TTDP_FLIGHT_TO_TOWER;
222 }
223
224 default:
225 return AMS_TTDP_HANGAR;
226 }
227 }
228
229
230 /* TTDP style aircraft movement action for GRF Action 2 Var 0xE6 */
231 enum TTDPAircraftMovementActions {
232 AMA_TTDP_IN_HANGAR,
233 AMA_TTDP_ON_PAD1,
234 AMA_TTDP_ON_PAD2,
235 AMA_TTDP_ON_PAD3,
236 AMA_TTDP_HANGAR_TO_PAD1,
237 AMA_TTDP_HANGAR_TO_PAD2,
238 AMA_TTDP_HANGAR_TO_PAD3,
239 AMA_TTDP_LANDING_TO_PAD1,
240 AMA_TTDP_LANDING_TO_PAD2,
241 AMA_TTDP_LANDING_TO_PAD3,
242 AMA_TTDP_PAD1_TO_HANGAR,
243 AMA_TTDP_PAD2_TO_HANGAR,
244 AMA_TTDP_PAD3_TO_HANGAR,
245 AMA_TTDP_PAD1_TO_TAKEOFF,
246 AMA_TTDP_PAD2_TO_TAKEOFF,
247 AMA_TTDP_PAD3_TO_TAKEOFF,
248 AMA_TTDP_HANGAR_TO_TAKOFF,
249 AMA_TTDP_LANDING_TO_HANGAR,
250 AMA_TTDP_IN_FLIGHT,
251 };
252
253
259 static byte MapAircraftMovementAction(const Aircraft *v)
260 {
261 switch (v->state) {
262 case HANGAR:
263 return (v->cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
264
265 case TERM1:
266 case HELIPAD1:
267 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
268
269 case TERM2:
270 case HELIPAD2:
271 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
272
273 case TERM3:
274 case TERM4:
275 case TERM5:
276 case TERM6:
277 case TERM7:
278 case TERM8:
279 case HELIPAD3:
280 return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
281
282 case TAKEOFF: // Moving to takeoff position
283 case STARTTAKEOFF: // Accelerating down runway
284 case ENDTAKEOFF: // Ascent
285 case HELITAKEOFF:
286 /* @todo Need to find which terminal (or hangar) we've come from. How? */
287 return AMA_TTDP_PAD1_TO_TAKEOFF;
288
289 case FLYING:
290 return AMA_TTDP_IN_FLIGHT;
291
292 case LANDING: // Descent
293 case ENDLANDING: // On the runway braking
294 case HELILANDING:
295 case HELIENDLANDING:
296 /* @todo Need to check terminal we're landing to. Is it known yet? */
297 return (v->current_order.IsType(OT_GOTO_DEPOT)) ?
298 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
299
300 default:
301 return AMA_TTDP_IN_HANGAR;
302 }
303 }
304
305
306 /* virtual */ uint32 VehicleScopeResolver::GetRandomBits() const
307 {
308 return this->v == nullptr ? 0 : this->v->random_bits;
309 }
310
311 /* virtual */ uint32 VehicleScopeResolver::GetTriggers() const
312 {
313 return this->v == nullptr ? 0 : this->v->waiting_triggers;
314 }
315
316
317 /* virtual */ ScopeResolver *VehicleResolverObject::GetScope(VarSpriteGroupScope scope, byte relative)
318 {
319 switch (scope) {
320 case VSG_SCOPE_SELF: return &this->self_scope;
321 case VSG_SCOPE_PARENT: return &this->parent_scope;
322 case VSG_SCOPE_RELATIVE: {
323 int32 count = GB(relative, 0, 4);
324 if (this->self_scope.v != nullptr && (relative != this->cached_relative_count || count == 0)) {
325 /* Note: This caching only works as long as the VSG_SCOPE_RELATIVE cannot be used in
326 * VarAct2 with procedure calls. */
327 if (count == 0) count = GetRegister(0x100);
328
329 const Vehicle *v = nullptr;
330 switch (GB(relative, 6, 2)) {
331 default: NOT_REACHED();
332 case 0x00: // count back (away from the engine), starting at this vehicle
333 v = this->self_scope.v;
334 break;
335 case 0x01: // count forward (toward the engine), starting at this vehicle
336 v = this->self_scope.v;
337 count = -count;
338 break;
339 case 0x02: // count back, starting at the engine
340 v = this->parent_scope.v;
341 break;
342 case 0x03: { // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41
343 const Vehicle *self = this->self_scope.v;
344 for (const Vehicle *u = self->First(); u != self; u = u->Next()) {
345 if (u->engine_type != self->engine_type) {
346 v = nullptr;
347 } else {
348 if (v == nullptr) v = u;
349 }
350 }
351 if (v == nullptr) v = self;
352 break;
353 }
354 }
355 this->relative_scope.SetVehicle(v->Move(count));
356 }
357 return &this->relative_scope;
358 }
359 default: return ResolverObject::GetScope(scope, relative);
360 }
361 }
362
372 static const Livery *LiveryHelper(EngineID engine, const Vehicle *v)
373 {
374 const Livery *l;
375
376 if (v == nullptr) {
377 if (!Company::IsValidID(_current_company)) return nullptr;
378 l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, nullptr, LIT_ALL);
379 } else if (v->IsGroundVehicle()) {
380 l = GetEngineLivery(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v, LIT_ALL);
381 } else {
382 l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v, LIT_ALL);
383 }
384
385 return l;
386 }
387
395 static uint32 PositionHelper(const Vehicle *v, bool consecutive)
396 {
397 const Vehicle *u;
398 byte chain_before = 0;
399 byte chain_after = 0;
400
401 for (u = v->First(); u != v; u = u->Next()) {
402 chain_before++;
403 if (consecutive && u->engine_type != v->engine_type) chain_before = 0;
404 }
405
406 while (u->Next() != nullptr && (!consecutive || u->Next()->engine_type == v->engine_type)) {
407 chain_after++;
408 u = u->Next();
409 }
410
411 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
412 }
413
414 static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, byte variable, uint32 parameter, bool *available)
415 {
416 /* Calculated vehicle parameters */
417 switch (variable) {
418 case 0x25: // Get engine GRF ID
419 return v->GetGRFID();
420
421 case 0x40: // Get length of consist
422 if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_CONSIST_LENGTH)) {
423 v->grf_cache.position_consist_length = PositionHelper(v, false);
424 SetBit(v->grf_cache.cache_valid, NCVV_POSITION_CONSIST_LENGTH);
425 }
426 return v->grf_cache.position_consist_length;
427
428 case 0x41: // Get length of same consecutive wagons
429 if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_SAME_ID_LENGTH)) {
430 v->grf_cache.position_same_id_length = PositionHelper(v, true);
431 SetBit(v->grf_cache.cache_valid, NCVV_POSITION_SAME_ID_LENGTH);
432 }
433 return v->grf_cache.position_same_id_length;
434
435 case 0x42: { // Consist cargo information
436 if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
437 const Vehicle *u;
438 byte cargo_classes = 0;
439 uint8 common_cargoes[NUM_CARGO];
440 uint8 common_subtypes[256];
441 byte user_def_data = 0;
442 CargoID common_cargo_type = CT_INVALID;
443 uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
444
445 /* Reset our arrays */
446 memset(common_cargoes, 0, sizeof(common_cargoes));
447 memset(common_subtypes, 0, sizeof(common_subtypes));
448
449 for (u = v; u != nullptr; u = u->Next()) {
450 if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
451
452 /* Skip empty engines */
453 if (!u->GetEngine()->CanCarryCargo()) continue;
454
455 cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
456 common_cargoes[u->cargo_type]++;
457 }
458
459 /* Pick the most common cargo type */
460 uint common_cargo_best_amount = 0;
461 for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
462 if (common_cargoes[cargo] > common_cargo_best_amount) {
463 common_cargo_best_amount = common_cargoes[cargo];
464 common_cargo_type = cargo;
465 }
466 }
467
468 /* Count subcargo types of common_cargo_type */
469 for (u = v; u != nullptr; u = u->Next()) {
470 /* Skip empty engines and engines not carrying common_cargo_type */
471 if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo()) continue;
472
473 common_subtypes[u->cargo_subtype]++;
474 }
475
476 /* Pick the most common subcargo type*/
477 uint common_subtype_best_amount = 0;
478 for (uint i = 0; i < lengthof(common_subtypes); i++) {
479 if (common_subtypes[i] > common_subtype_best_amount) {
480 common_subtype_best_amount = common_subtypes[i];
481 common_subtype = i;
482 }
483 }
484
485 /* Note: We have to store the untranslated cargotype in the cache as the cache can be read by different NewGRFs,
486 * which will need different translations */
487 v->grf_cache.consist_cargo_information = cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
488 SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION);
489 }
490
491 /* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
492 CargoID common_cargo_type = (v->grf_cache.consist_cargo_information >> 8) & 0xFF;
493
494 /* Note:
495 * - Unlike everywhere else the cargo translation table is only used since grf version 8, not 7.
496 * - For translating the cargo type we need to use the GRF which is resolving the variable, which
497 * is object->ro.grffile.
498 * In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
499 * - The grffile == nullptr case only happens if this function is called for default vehicles.
500 * And this is only done by CheckCaches().
501 */
502 const GRFFile *grffile = object->ro.grffile;
503 uint8 common_bitnum = (common_cargo_type == CT_INVALID) ? 0xFF :
504 (grffile == nullptr || grffile->grf_version < 8) ? CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
505
506 return (v->grf_cache.consist_cargo_information & 0xFFFF00FF) | common_bitnum << 8;
507 }
508
509 case 0x43: // Company information
510 if (!HasBit(v->grf_cache.cache_valid, NCVV_COMPANY_INFORMATION)) {
511 v->grf_cache.company_information = GetCompanyInfo(v->owner, LiveryHelper(v->engine_type, v));
512 SetBit(v->grf_cache.cache_valid, NCVV_COMPANY_INFORMATION);
513 }
514 return v->grf_cache.company_information;
515
516 case 0x44: // Aircraft information
517 if (v->type != VEH_AIRCRAFT || !Aircraft::From(v)->IsNormalAircraft()) return UINT_MAX;
518
519 {
520 const Vehicle *w = v->Next();
521 uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height
522 byte airporttype = ATP_TTDP_LARGE;
523
524 const Station *st = GetTargetAirportIfValid(Aircraft::From(v));
525
526 if (st != nullptr && st->airport.tile != INVALID_TILE) {
527 airporttype = st->airport.GetSpec()->ttd_airport_type;
528 }
529
530 return (Clamp(altitude, 0, 0xFF) << 8) | airporttype;
531 }
532
533 case 0x45: { // Curvature info
534 /* Format: xxxTxBxF
535 * F - previous wagon to current wagon, 0 if vehicle is first
536 * B - current wagon to next wagon, 0 if wagon is last
537 * T - previous wagon to next wagon, 0 in an S-bend
538 */
539 if (!v->IsGroundVehicle()) return 0;
540
541 const Vehicle *u_p = v->Previous();
542 const Vehicle *u_n = v->Next();
543 DirDiff f = (u_p == nullptr) ? DIRDIFF_SAME : DirDifference(u_p->direction, v->direction);
544 DirDiff b = (u_n == nullptr) ? DIRDIFF_SAME : DirDifference(v->direction, u_n->direction);
545 DirDiff t = ChangeDirDiff(f, b);
546
547 return ((t > DIRDIFF_REVERSE ? t | 8 : t) << 16) |
548 ((b > DIRDIFF_REVERSE ? b | 8 : b) << 8) |
549 ( f > DIRDIFF_REVERSE ? f | 8 : f);
550 }
551
552 case 0x46: // Motion counter
553 return v->motion_counter;
554
555 case 0x47: { // Vehicle cargo info
556 /* Format: ccccwwtt
557 * tt - the cargo type transported by the vehicle,
558 * translated if a translation table has been installed.
559 * ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
560 * cccc - the cargo class value of the cargo transported by the vehicle.
561 */
562 const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
563
564 /* Note:
565 * For translating the cargo type we need to use the GRF which is resolving the variable, which
566 * is object->ro.grffile.
567 * In case of CBID_TRAIN_ALLOW_WAGON_ATTACH this is not the same as v->GetGRF().
568 */
569 return (cs->classes << 16) | (cs->weight << 8) | object->ro.grffile->cargo_map[v->cargo_type];
570 }
571
572 case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
573 case 0x49: return v->build_year;
574
575 case 0x4A:
576 switch (v->type) {
577 case VEH_TRAIN: {
578 RailType rt = GetTileRailType(v->tile);
579 const RailtypeInfo *rti = GetRailTypeInfo(rt);
580 return ((rti->flags & RTFB_CATENARY) ? 0x200 : 0) |
581 (HasPowerOnRail(Train::From(v)->railtype, rt) ? 0x100 : 0) |
582 GetReverseRailTypeTranslation(rt, object->ro.grffile);
583 }
584
585 case VEH_ROAD: {
586 RoadType rt = GetRoadType(v->tile, GetRoadTramType(RoadVehicle::From(v)->roadtype));
587 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
588 return ((rti->flags & ROTFB_CATENARY) ? 0x200 : 0) |
589 0x100 |
590 GetReverseRoadTypeTranslation(rt, object->ro.grffile);
591 }
592
593 default:
594 return 0;
595 }
596
597 case 0x4B: // Long date of last service
598 return v->date_of_last_service;
599
600 case 0x4C: // Current maximum speed in NewGRF units
601 if (!v->IsPrimaryVehicle()) return 0;
602 return v->GetCurrentMaxSpeed();
603
604 case 0x4D: // Position within articulated vehicle
605 if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_IN_VEHICLE)) {
606 byte artic_before = 0;
607 for (const Vehicle *u = v; u->IsArticulatedPart(); u = u->Previous()) artic_before++;
608 byte artic_after = 0;
609 for (const Vehicle *u = v; u->HasArticulatedPart(); u = u->Next()) artic_after++;
610 v->grf_cache.position_in_vehicle = artic_before | artic_after << 8;
611 SetBit(v->grf_cache.cache_valid, NCVV_POSITION_IN_VEHICLE);
612 }
613 return v->grf_cache.position_in_vehicle;
614
615 /* Variables which use the parameter */
616 case 0x60: // Count consist's engine ID occurrence
617 if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
618
619 {
620 uint count = 0;
621 for (; v != nullptr; v = v->Next()) {
622 if (v->GetEngine()->grf_prop.local_id == parameter) count++;
623 }
624 return count;
625 }
626
627 case 0x61: // Get variable of n-th vehicle in chain [signed number relative to vehicle]
628 if (!v->IsGroundVehicle() || parameter == 0x61) {
629 /* Not available */
630 break;
631 }
632
633 /* Only allow callbacks that don't change properties to avoid circular dependencies. */
634 if (object->ro.callback == CBID_NO_CALLBACK || object->ro.callback == CBID_RANDOM_TRIGGER || object->ro.callback == CBID_TRAIN_ALLOW_WAGON_ATTACH ||
635 object->ro.callback == CBID_VEHICLE_START_STOP_CHECK || object->ro.callback == CBID_VEHICLE_32DAY_CALLBACK || object->ro.callback == CBID_VEHICLE_COLOUR_MAPPING ||
636 object->ro.callback == CBID_VEHICLE_SPAWN_VISUAL_EFFECT) {
637 Vehicle *u = v->Move((int32)GetRegister(0x10F));
638 if (u == nullptr) return 0; // available, but zero
639
640 if (parameter == 0x5F) {
641 /* This seems to be the only variable that makes sense to access via var 61, but is not handled by VehicleGetVariable */
642 return (u->random_bits << 8) | u->waiting_triggers;
643 } else {
644 return VehicleGetVariable(u, object, parameter, GetRegister(0x10E), available);
645 }
646 }
647 /* Not available */
648 break;
649
650 case 0x62: { // Curvature/position difference for n-th vehicle in chain [signed number relative to vehicle]
651 /* Format: zzyyxxFD
652 * zz - Signed difference of z position between the selected and this vehicle.
653 * yy - Signed difference of y position between the selected and this vehicle.
654 * xx - Signed difference of x position between the selected and this vehicle.
655 * F - Flags, bit 7 corresponds to VS_HIDDEN.
656 * D - Dir difference, like in 0x45.
657 */
658 if (!v->IsGroundVehicle()) return 0;
659
660 const Vehicle *u = v->Move((int8)parameter);
661 if (u == nullptr) return 0;
662
663 /* Get direction difference. */
664 bool prev = (int8)parameter < 0;
665 uint32 ret = prev ? DirDifference(u->direction, v->direction) : DirDifference(v->direction, u->direction);
666 if (ret > DIRDIFF_REVERSE) ret |= 0x08;
667
668 if (u->vehstatus & VS_HIDDEN) ret |= 0x80;
669
670 /* Get position difference. */
671 ret |= ((prev ? u->x_pos - v->x_pos : v->x_pos - u->x_pos) & 0xFF) << 8;
672 ret |= ((prev ? u->y_pos - v->y_pos : v->y_pos - u->y_pos) & 0xFF) << 16;
673 ret |= ((prev ? u->z_pos - v->z_pos : v->z_pos - u->z_pos) & 0xFF) << 24;
674
675 return ret;
676 }
677
678 case 0x63:
679 /* Tile compatibility wrt. arbitrary track-type
680 * Format:
681 * bit 0: Type 'parameter' is known.
682 * bit 1: Engines with type 'parameter' are compatible with this tile.
683 * bit 2: Engines with type 'parameter' are powered on this tile.
684 * bit 3: This tile has type 'parameter' or it is considered equivalent (alternate labels).
685 */
686 switch (v->type) {
687 case VEH_TRAIN: {
688 RailType param_type = GetRailTypeTranslation(parameter, object->ro.grffile);
689 if (param_type == INVALID_RAILTYPE) return 0x00;
690 RailType tile_type = GetTileRailType(v->tile);
691 if (tile_type == param_type) return 0x0F;
692 return (HasPowerOnRail(param_type, tile_type) ? 0x04 : 0x00) |
693 (IsCompatibleRail(param_type, tile_type) ? 0x02 : 0x00) |
694 0x01;
695 }
696 case VEH_ROAD: {
697 RoadTramType rtt = GetRoadTramType(RoadVehicle::From(v)->roadtype);
698 RoadType param_type = GetRoadTypeTranslation(rtt, parameter, object->ro.grffile);
699 if (param_type == INVALID_ROADTYPE) return 0x00;
700 RoadType tile_type = GetRoadType(v->tile, rtt);
701 if (tile_type == param_type) return 0x0F;
702 return (HasPowerOnRoad(param_type, tile_type) ? 0x06 : 0x00) |
703 0x01;
704 }
705 default: return 0x00;
706 }
707
708 case 0xFE:
709 case 0xFF: {
710 uint16 modflags = 0;
711
712 if (v->type == VEH_TRAIN) {
713 const Train *t = Train::From(v);
714 bool is_powered_wagon = HasBit(t->flags, VRF_POWEREDWAGON);
715 const Train *u = is_powered_wagon ? t->First() : t; // for powered wagons the engine defines the type of engine (i.e. railtype)
716 RailType railtype = GetRailType(v->tile);
717 bool powered = t->IsEngine() || is_powered_wagon;
718 bool has_power = HasPowerOnRail(u->railtype, railtype);
719
720 if (powered && has_power) SetBit(modflags, 5);
721 if (powered && !has_power) SetBit(modflags, 6);
722 if (HasBit(t->flags, VRF_TOGGLE_REVERSE)) SetBit(modflags, 8);
723 }
724 if (HasBit(v->vehicle_flags, VF_CARGO_UNLOADING)) SetBit(modflags, 1);
725 if (HasBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE)) SetBit(modflags, 10);
726
727 return variable == 0xFE ? modflags : GB(modflags, 8, 8);
728 }
729 }
730
731 /*
732 * General vehicle properties
733 *
734 * Some parts of the TTD Vehicle structure are omitted for various reasons
735 * (see http://marcin.ttdpatch.net/sv1codec/TTD-locations.html#_VehicleArray)
736 */
737 switch (variable - 0x80) {
738 case 0x00: return v->type + 0x10;
739 case 0x01: return MapOldSubType(v);
740 case 0x02: break; // not implemented
741 case 0x03: break; // not implemented
742 case 0x04: return v->index;
743 case 0x05: return GB(v->index, 8, 8);
744 case 0x06: break; // not implemented
745 case 0x07: break; // not implemented
746 case 0x08: break; // not implemented
747 case 0x09: break; // not implemented
748 case 0x0A: return v->current_order.MapOldOrder();
749 case 0x0B: return v->current_order.GetDestination();
750 case 0x0C: return v->GetNumOrders();
751 case 0x0D: return v->cur_real_order_index;
752 case 0x0E: break; // not implemented
753 case 0x0F: break; // not implemented
754 case 0x10:
755 case 0x11: {
756 uint ticks;
757 if (v->current_order.IsType(OT_LOADING)) {
758 ticks = v->load_unload_ticks;
759 } else {
760 switch (v->type) {
761 case VEH_TRAIN: ticks = Train::From(v)->wait_counter; break;
762 case VEH_AIRCRAFT: ticks = Aircraft::From(v)->turn_counter; break;
763 default: ticks = 0; break;
764 }
765 }
766 return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8);
767 }
768 case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF);
769 case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
770 case 0x14: return v->GetServiceInterval();
771 case 0x15: return GB(v->GetServiceInterval(), 8, 8);
772 case 0x16: return v->last_station_visited;
773 case 0x17: return v->tick_counter;
774 case 0x18:
775 case 0x19: {
776 uint max_speed;
777 switch (v->type) {
778 case VEH_AIRCRAFT:
779 max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
780 break;
781
782 default:
783 max_speed = v->vcache.cached_max_speed;
784 break;
785 }
786 return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
787 }
788 case 0x1A: return v->x_pos;
789 case 0x1B: return GB(v->x_pos, 8, 8);
790 case 0x1C: return v->y_pos;
791 case 0x1D: return GB(v->y_pos, 8, 8);
792 case 0x1E: return v->z_pos;
793 case 0x1F: return object->rotor_in_gui ? DIR_W : v->direction; // for rotors the spriteset contains animation frames, so NewGRF need a different way to tell the helicopter orientation.
794 case 0x20: break; // not implemented
795 case 0x21: break; // not implemented
796 case 0x22: break; // not implemented
797 case 0x23: break; // not implemented
798 case 0x24: break; // not implemented
799 case 0x25: break; // not implemented
800 case 0x26: break; // not implemented
801 case 0x27: break; // not implemented
802 case 0x28: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
803 case 0x29: return 0; // cur_image is a potential desyncer due to Action1 in static NewGRFs.
804 case 0x2A: break; // not implemented
805 case 0x2B: break; // not implemented
806 case 0x2C: break; // not implemented
807 case 0x2D: break; // not implemented
808 case 0x2E: break; // not implemented
809 case 0x2F: break; // not implemented
810 case 0x30: break; // not implemented
811 case 0x31: break; // not implemented
812 case 0x32: return v->vehstatus;
813 case 0x33: return 0; // non-existent high byte of vehstatus
814 case 0x34: return v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed;
815 case 0x35: return GB(v->type == VEH_AIRCRAFT ? (v->cur_speed * 10) / 128 : v->cur_speed, 8, 8);
816 case 0x36: return v->subspeed;
817 case 0x37: return v->acceleration;
818 case 0x38: break; // not implemented
819 case 0x39: return v->cargo_type;
820 case 0x3A: return v->cargo_cap;
821 case 0x3B: return GB(v->cargo_cap, 8, 8);
822 case 0x3C: return ClampToU16(v->cargo.StoredCount());
823 case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8);
824 case 0x3E: return v->cargo.Source();
825 case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF);
826 case 0x40: return ClampToU16(v->age);
827 case 0x41: return GB(ClampToU16(v->age), 8, 8);
828 case 0x42: return ClampToU16(v->max_age);
829 case 0x43: return GB(ClampToU16(v->max_age), 8, 8);
830 case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
831 case 0x45: return v->unitnumber;
832 case 0x46: return v->GetEngine()->grf_prop.local_id;
833 case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
834 case 0x48:
835 if (v->type != VEH_TRAIN || v->spritenum != 0xFD) return v->spritenum;
836 return HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION) ? 0xFE : 0xFD;
837
838 case 0x49: return v->day_counter;
839 case 0x4A: return v->breakdowns_since_last_service;
840 case 0x4B: return v->breakdown_ctr;
841 case 0x4C: return v->breakdown_delay;
842 case 0x4D: return v->breakdown_chance;
843 case 0x4E: return v->reliability;
844 case 0x4F: return GB(v->reliability, 8, 8);
845 case 0x50: return v->reliability_spd_dec;
846 case 0x51: return GB(v->reliability_spd_dec, 8, 8);
847 case 0x52: return ClampToI32(v->GetDisplayProfitThisYear());
848 case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24);
849 case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16);
850 case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8);
851 case 0x56: return ClampToI32(v->GetDisplayProfitLastYear());
852 case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24);
853 case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16);
854 case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8);
855 case 0x5A: return v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index;
856 case 0x5B: break; // not implemented
857 case 0x5C: return ClampToI32(v->value);
858 case 0x5D: return GB(ClampToI32(v->value), 8, 24);
859 case 0x5E: return GB(ClampToI32(v->value), 16, 16);
860 case 0x5F: return GB(ClampToI32(v->value), 24, 8);
861 case 0x60: break; // not implemented
862 case 0x61: break; // not implemented
863 case 0x62: break; // vehicle specific, see below
864 case 0x63: break; // not implemented
865 case 0x64: break; // vehicle specific, see below
866 case 0x65: break; // vehicle specific, see below
867 case 0x66: break; // vehicle specific, see below
868 case 0x67: break; // vehicle specific, see below
869 case 0x68: break; // vehicle specific, see below
870 case 0x69: break; // vehicle specific, see below
871 case 0x6A: break; // not implemented
872 case 0x6B: break; // not implemented
873 case 0x6C: break; // not implemented
874 case 0x6D: break; // not implemented
875 case 0x6E: break; // not implemented
876 case 0x6F: break; // not implemented
877 case 0x70: break; // not implemented
878 case 0x71: break; // not implemented
879 case 0x72: return v->cargo_subtype;
880 case 0x73: break; // vehicle specific, see below
881 case 0x74: break; // vehicle specific, see below
882 case 0x75: break; // vehicle specific, see below
883 case 0x76: break; // vehicle specific, see below
884 case 0x77: break; // vehicle specific, see below
885 case 0x78: break; // not implemented
886 case 0x79: break; // not implemented
887 case 0x7A: return v->random_bits;
888 case 0x7B: return v->waiting_triggers;
889 case 0x7C: break; // vehicle specific, see below
890 case 0x7D: break; // vehicle specific, see below
891 case 0x7E: break; // not implemented
892 case 0x7F: break; // vehicle specific, see below
893 }
894
895 /* Vehicle specific properties */
896 switch (v->type) {
897 case VEH_TRAIN: {
898 Train *t = Train::From(v);
899 switch (variable - 0x80) {
900 case 0x62: return t->track;
901 case 0x66: return t->railtype;
902 case 0x73: return 0x80 + VEHICLE_LENGTH - t->gcache.cached_veh_length;
903 case 0x74: return t->gcache.cached_power;
904 case 0x75: return GB(t->gcache.cached_power, 8, 24);
905 case 0x76: return GB(t->gcache.cached_power, 16, 16);
906 case 0x77: return GB(t->gcache.cached_power, 24, 8);
907 case 0x7C: return t->First()->index;
908 case 0x7D: return GB(t->First()->index, 8, 8);
909 case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
910 }
911 break;
912 }
913
914 case VEH_ROAD: {
915 RoadVehicle *rv = RoadVehicle::From(v);
916 switch (variable - 0x80) {
917 case 0x62: return rv->state;
918 case 0x64: return rv->blocked_ctr;
919 case 0x65: return GB(rv->blocked_ctr, 8, 8);
920 case 0x66: return rv->overtaking;
921 case 0x67: return rv->overtaking_ctr;
922 case 0x68: return rv->crashed_ctr;
923 case 0x69: return GB(rv->crashed_ctr, 8, 8);
924 }
925 break;
926 }
927
928 case VEH_SHIP: {
929 Ship *s = Ship::From(v);
930 switch (variable - 0x80) {
931 case 0x62: return s->state;
932 }
933 break;
934 }
935
936 case VEH_AIRCRAFT: {
937 Aircraft *a = Aircraft::From(v);
938 switch (variable - 0x80) {
939 case 0x62: return MapAircraftMovementState(a); // Current movement state
940 case 0x63: return a->targetairport; // Airport to which the action refers
941 case 0x66: return MapAircraftMovementAction(a); // Current movement action
942 }
943 break;
944 }
945
946 default: break;
947 }
948
949 Debug(grf, 1, "Unhandled vehicle variable 0x{:X}, type 0x{:X}", variable, (uint)v->type);
950
951 *available = false;
952 return UINT_MAX;
953 }
954
955 /* virtual */ uint32 VehicleScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
956 {
957 if (this->v == nullptr) {
958 /* Vehicle does not exist, so we're in a purchase list */
959 switch (variable) {
960 case 0x43: return GetCompanyInfo(_current_company, LiveryHelper(this->self_type, nullptr)); // Owner information
961 case 0x46: return 0; // Motion counter
962 case 0x47: { // Vehicle cargo info
963 const Engine *e = Engine::Get(this->self_type);
964 CargoID cargo_type = e->GetDefaultCargoType();
965 if (cargo_type != CT_INVALID) {
966 const CargoSpec *cs = CargoSpec::Get(cargo_type);
967 return (cs->classes << 16) | (cs->weight << 8) | this->ro.grffile->cargo_map[cargo_type];
968 } else {
969 return 0x000000FF;
970 }
971 }
972 case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
973 case 0x49: return _cur_year; // 'Long' format build year
974 case 0x4B: return _date; // Long date of last service
975 case 0x92: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service
976 case 0x93: return GB(Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8);
977 case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
978 case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id;
979 case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8);
980 case 0xDA: return INVALID_VEHICLE; // Next vehicle
981 case 0xF2: return 0; // Cargo subtype
982 }
983
984 *available = false;
985 return UINT_MAX;
986 }
987
988 return VehicleGetVariable(const_cast<Vehicle*>(this->v), this, variable, parameter, available);
989 }
990
991
992 /* virtual */ const SpriteGroup *VehicleResolverObject::ResolveReal(const RealSpriteGroup *group) const
993 {
994 const Vehicle *v = this->self_scope.v;
995
996 if (v == nullptr) {
997 if (!group->loading.empty()) return group->loading[0];
998 if (!group->loaded.empty()) return group->loaded[0];
999 return nullptr;
1000 }
1001
1002 bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
1003
1004 uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
1005
1006 if (totalsets == 0) return nullptr;
1007
1008 uint set = (v->cargo.StoredCount() * totalsets) / std::max<uint16>(1u, v->cargo_cap);
1009 set = std::min(set, totalsets - 1);
1010
1011 return in_motion ? group->loaded[set] : group->loading[set];
1012 }
1013
1014 GrfSpecFeature VehicleResolverObject::GetFeature() const
1015 {
1016 switch (Engine::Get(this->self_scope.self_type)->type) {
1017 case VEH_TRAIN: return GSF_TRAINS;
1018 case VEH_ROAD: return GSF_ROADVEHICLES;
1019 case VEH_SHIP: return GSF_SHIPS;
1020 case VEH_AIRCRAFT: return GSF_AIRCRAFT;
1021 default: return GSF_INVALID;
1022 }
1023 }
1024
1025 uint32 VehicleResolverObject::GetDebugID() const
1026 {
1027 return Engine::Get(this->self_scope.self_type)->grf_prop.local_id;
1028 }
1029
1035 static const GRFFile *GetEngineGrfFile(EngineID engine_type)
1036 {
1037 const Engine *e = Engine::Get(engine_type);
1038 return (e != nullptr) ? e->GetGRF() : nullptr;
1039 }
1040
1051 VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui,
1052 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
1053 : ResolverObject(GetEngineGrfFile(engine_type), callback, callback_param1, callback_param2),
1054 self_scope(*this, engine_type, v, rotor_in_gui),
1055 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), rotor_in_gui),
1056 relative_scope(*this, engine_type, v, rotor_in_gui),
1057 cached_relative_count(0)
1058 {
1059 if (wagon_override == WO_SELF) {
1060 this->root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1061 } else {
1062 if (wagon_override != WO_NONE && v != nullptr && v->IsGroundVehicle()) {
1063 assert(v->engine_type == engine_type); // overrides make little sense with fake scopes
1064
1065 /* For trains we always use cached value, except for callbacks because the override spriteset
1066 * to use may be different than the one cached. It happens for callback 0x15 (refit engine),
1067 * as v->cargo_type is temporary changed to the new type */
1068 if (wagon_override == WO_CACHED && v->type == VEH_TRAIN) {
1069 this->root_spritegroup = Train::From(v)->tcache.cached_override;
1070 } else {
1071 this->root_spritegroup = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
1072 }
1073 }
1074
1075 if (this->root_spritegroup == nullptr) {
1076 const Engine *e = Engine::Get(engine_type);
1077 CargoID cargo = v != nullptr ? v->cargo_type : CT_PURCHASE;
1078 assert(cargo < lengthof(e->grf_prop.spritegroup));
1079 this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
1080 }
1081 }
1082 }
1083
1084
1085
1086 void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result)
1087 {
1088 VehicleResolverObject object(engine, v, VehicleResolverObject::WO_CACHED, false, CBID_NO_CALLBACK);
1089 result->Clear();
1090
1091 bool sprite_stack = HasBit(EngInfo(engine)->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() + (direction % 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
1108 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result)
1109 {
1110 const Engine *e = Engine::Get(engine);
1111
1112 /* Only valid for helicopters */
1113 assert(e->type == VEH_AIRCRAFT);
1114 assert(!(e->u.air.subtype & AIR_CTOL));
1115
1116 /* We differ from TTDPatch by resolving the sprite using the primary vehicle 'v', and not using the rotor vehicle 'v->Next()->Next()'.
1117 * TTDPatch copies some variables between the vehicles each time, to somehow synchronize the rotor vehicle with the primary vehicle.
1118 * We use 'rotor_in_gui' to replicate when the variables differ.
1119 * But some other variables like 'rotor state' and 'rotor speed' are not available in OpenTTD, while they are in TTDPatch. */
1120 bool rotor_in_gui = image_type != EIT_ON_MAP;
1121 VehicleResolverObject object(engine, v, VehicleResolverObject::WO_SELF, rotor_in_gui, CBID_NO_CALLBACK);
1122 result->Clear();
1123 uint rotor_pos = v == nullptr || rotor_in_gui ? 0 : v->Next()->Next()->state;
1124
1125 bool sprite_stack = HasBit(e->info.misc_flags, EF_SPRITE_STACK);
1126 uint max_stack = sprite_stack ? lengthof(result->seq) : 1;
1127 for (uint stack = 0; stack < max_stack; ++stack) {
1128 object.ResetState();
1129 object.callback_param1 = image_type | (stack << 8);
1130 const SpriteGroup *group = object.Resolve();
1131 uint32 reg100 = sprite_stack ? GetRegister(0x100) : 0;
1132 if (group != nullptr && group->GetNumResults() != 0) {
1133 result->seq[result->count].sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1134 result->seq[result->count].pal = GB(reg100, 0, 16); // zero means default recolouring
1135 result->count++;
1136 }
1137 if (!HasBit(reg100, 31)) break;
1138 }
1139 }
1140
1141
1147 bool UsesWagonOverride(const Vehicle *v)
1148 {
1149 assert(v->type == VEH_TRAIN);
1150 return Train::From(v)->tcache.cached_override != nullptr;
1151 }
1152
1162 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
1163 {
1164 VehicleResolverObject object(engine, v, VehicleResolverObject::WO_UNCACHED, false, callback, param1, param2);
1165 return object.ResolveCallback();
1166 }
1167
1178 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
1179 {
1180 VehicleResolverObject object(engine, v, VehicleResolverObject::WO_NONE, false, callback, param1, param2);
1181 object.parent_scope.SetVehicle(parent);
1182 return object.ResolveCallback();
1183 }
1184
1185
1186 /* Callback 36 handlers */
1187 int GetVehicleProperty(const Vehicle *v, PropertyID property, int orig_value, bool is_signed)
1188 {
1189 return GetEngineProperty(v->engine_type, property, orig_value, v, is_signed);
1190 }
1191
1192
1193 int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, const Vehicle *v, bool is_signed)
1194 {
1195 uint16 callback = GetVehicleCallback(CBID_VEHICLE_MODIFY_PROPERTY, property, 0, engine, v);
1196 if (callback != CALLBACK_FAILED) {
1197 if (is_signed) {
1198 /* Sign extend 15 bit integer */
1199 return static_cast<int16>(callback << 1) / 2;
1200 } else {
1201 return callback;
1202 }
1203 }
1204
1205 return orig_value;
1206 }
1207
1208
1209 static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
1210 {
1211 /* We can't trigger a non-existent vehicle... */
1212 assert(v != nullptr);
1213
1214 VehicleResolverObject object(v->engine_type, v, VehicleResolverObject::WO_CACHED, false, CBID_RANDOM_TRIGGER);
1215 object.waiting_triggers = v->waiting_triggers | trigger;
1216 v->waiting_triggers = object.waiting_triggers; // store now for var 5F
1217
1218 const SpriteGroup *group = object.Resolve();
1219 if (group == nullptr) return;
1220
1221 /* Store remaining triggers. */
1222 v->waiting_triggers = object.GetRemainingTriggers();
1223
1224 /* Rerandomise bits. Scopes other than SELF are invalid for rerandomisation. For bug-to-bug-compatibility with TTDP we ignore the scope. */
1225 byte new_random_bits = Random();
1226 uint32 reseed = object.GetReseedSum();
1227 v->random_bits &= ~reseed;
1228 v->random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1229
1230 switch (trigger) {
1231 case VEHICLE_TRIGGER_NEW_CARGO:
1232 /* All vehicles in chain get ANY_NEW_CARGO trigger now.
1233 * So we call it for the first one and they will recurse.
1234 * Indexing part of vehicle random bits needs to be
1235 * same for all triggered vehicles in the chain (to get
1236 * all the random-cargo wagons carry the same cargo,
1237 * i.e.), so we give them all the NEW_CARGO triggered
1238 * vehicle's portion of random bits. */
1239 assert(first);
1240 DoTriggerVehicle(v->First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false);
1241 break;
1242
1243 case VEHICLE_TRIGGER_DEPOT:
1244 /* We now trigger the next vehicle in chain recursively.
1245 * The random bits portions may be different for each
1246 * vehicle in chain. */
1247 if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, 0, true);
1248 break;
1249
1250 case VEHICLE_TRIGGER_EMPTY:
1251 /* We now trigger the next vehicle in chain
1252 * recursively. The random bits portions must be same
1253 * for each vehicle in chain, so we give them all
1254 * first chained vehicle's portion of random bits. */
1255 if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), trigger, first ? new_random_bits : base_random_bits, false);
1256 break;
1257
1258 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1259 /* Now pass the trigger recursively to the next vehicle
1260 * in chain. */
1261 assert(!first);
1262 if (v->Next() != nullptr) DoTriggerVehicle(v->Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false);
1263 break;
1264
1265 case VEHICLE_TRIGGER_CALLBACK_32:
1266 /* Do not do any recursion */
1267 break;
1268 }
1269 }
1270
1271 void TriggerVehicle(Vehicle *v, VehicleTrigger trigger)
1272 {
1273 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1274 /* store that the vehicle entered a depot this tick */
1275 VehicleEnteredDepotThisTick(v);
1276 }
1277
1278 v->InvalidateNewGRFCacheOfChain();
1279 DoTriggerVehicle(v, trigger, 0, true);
1280 v->InvalidateNewGRFCacheOfChain();
1281 }
1282
1283 /* Functions for changing the order of vehicle purchase lists */
1284
1285 struct ListOrderChange {
1286 EngineID engine;
1287 uint target;
1288 };
1289
1290 static std::vector<ListOrderChange> _list_order_changes;
1291
1298 void AlterVehicleListOrder(EngineID engine, uint target)
1299 {
1300 /* Add the list order change to a queue */
1301 _list_order_changes.push_back({engine, target});
1302 }
1303
1310 static bool EnginePreSort(const EngineID &a, const EngineID &b)
1311 {
1312 const EngineIDMapping &id_a = _engine_mngr.at(a);
1313 const EngineIDMapping &id_b = _engine_mngr.at(b);
1314
1315 /* 1. Sort by engine type */
1316 if (id_a.type != id_b.type) return (int)id_a.type < (int)id_b.type;
1317
1318 /* 2. Sort by scope-GRFID */
1319 if (id_a.grfid != id_b.grfid) return id_a.grfid < id_b.grfid;
1320
1321 /* 3. Sort by local ID */
1322 return (int)id_a.internal_id < (int)id_b.internal_id;
1323 }
1324
1328 void CommitVehicleListOrderChanges()
1329 {
1330 /* Pre-sort engines by scope-grfid and local index */
1331 std::vector<EngineID> ordering;
1332 for (const Engine *e : Engine::Iterate()) {
1333 ordering.push_back(e->index);
1334 }
1335 std::sort(ordering.begin(), ordering.end(), EnginePreSort);
1336
1337 /* Apply Insertion-Sort operations */
1338 for (const ListOrderChange &it : _list_order_changes) {
1339 EngineID source = it.engine;
1340 uint local_target = it.target;
1341
1342 const EngineIDMapping *id_source = _engine_mngr.data() + source;
1343 if (id_source->internal_id == local_target) continue;
1344
1345 EngineID target = _engine_mngr.GetID(id_source->type, local_target, id_source->grfid);
1346 if (target == INVALID_ENGINE) continue;
1347
1348 int source_index = find_index(ordering, source);
1349 int target_index = find_index(ordering, target);
1350
1351 assert(source_index >= 0 && target_index >= 0);
1352 assert(source_index != target_index);
1353
1354 EngineID *list = ordering.data();
1355 if (source_index < target_index) {
1356 --target_index;
1357 for (int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1358 list[target_index] = source;
1359 } else {
1360 for (int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1361 list[target_index] = source;
1362 }
1363 }
1364
1365 /* Store final sort-order */
1366 uint index = 0;
1367 for (const EngineID &eid : ordering) {
1368 Engine::Get(eid)->list_position = index;
1369 ++index;
1370 }
1371
1372 /* Clear out the queue */
1373 _list_order_changes.clear();
1374 _list_order_changes.shrink_to_fit();
1375 }
1376
1381 void FillNewGRFVehicleCache(const Vehicle *v)
1382 {
1383 VehicleResolverObject ro(v->engine_type, v, VehicleResolverObject::WO_NONE);
1384
1385 /* These variables we have to check; these are the ones with a cache. */
1386 static const int cache_entries[][2] = {
1387 { 0x40, NCVV_POSITION_CONSIST_LENGTH },
1388 { 0x41, NCVV_POSITION_SAME_ID_LENGTH },
1389 { 0x42, NCVV_CONSIST_CARGO_INFORMATION },
1390 { 0x43, NCVV_COMPANY_INFORMATION },
1391 { 0x4D, NCVV_POSITION_IN_VEHICLE },
1392 };
1393 static_assert(NCVV_END == lengthof(cache_entries));
1394
1395 /* Resolve all the variables, so their caches are set. */
1396 for (size_t i = 0; i < lengthof(cache_entries); i++) {
1397 /* Only resolve when the cache isn't valid. */
1398 if (HasBit(v->grf_cache.cache_valid, cache_entries[i][1])) continue;
1399 bool stub;
1400 ro.GetScope(VSG_SCOPE_SELF)->GetVariable(cache_entries[i][0], 0, &stub);
1401 }
1402
1403 /* Make sure really all bits are set. */
1404 assert(v->grf_cache.cache_valid == (1 << NCVV_END) - 1);
1405 }
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:125
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:2906
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:203
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:992
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:352
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:97
RoadTypeInfo
Definition: road.h:76
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:1974
VehicleResolverObject::WO_CACHED
@ WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
Definition: newgrf_engine.h:52
WagonOverride
Definition: engine_base.h:18
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:167
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:1014
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
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:284
EngineIDMapping::grfid
uint32 grfid
The GRF ID of the file the entity belongs to.
Definition: engine_base.h:180
VehicleScopeResolver::GetRandomBits
uint32 GetRandomBits() const override
Get a few random bits.
Definition: newgrf_engine.cpp:306
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:256
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:283
train.h
AircraftVehicleInfo::subtype
byte subtype
Type of aircraft.
Definition: engine_type.h:103
CargoList::DaysInTransit
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
Definition: cargopacket.h:256
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:1285
Vehicle::Previous
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Definition: vehicle_base.h:617
ListOrderChange::target
uint target
local ID
Definition: newgrf_engine.cpp:1287
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:391
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:610
_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:1098
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:454
CBID_VEHICLE_MODIFY_PROPERTY
@ CBID_VEHICLE_MODIFY_PROPERTY
Called to modify various vehicle properties.
Definition: newgrf_callbacks.h:159
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:104
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:285
Vehicle::load_unload_ticks
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
Definition: vehicle_base.h:340
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:72
Vehicle::random_bits
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:313
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
Vehicle::grf_cache
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Definition: vehicle_base.h:344
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
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:118
Vehicle::acceleration
byte acceleration
used by train & aircraft
Definition: vehicle_base.h:309
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
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:148
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
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
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
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:335
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:80
NewGRFCache::cache_valid
uint8 cache_valid
Bitset that indicates which cache values are valid.
Definition: vehicle_base.h:76
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:57
VehicleResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_engine.cpp:1025
GetReverseRoadTypeTranslation
uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
Definition: newgrf_roadtype.cpp:152
ORIGINAL_BASE_YEAR
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Definition: date_type.h:50
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:86
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:101
Engine
Definition: engine_base.h:36
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:307
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
EngineIDMapping::internal_id
uint16 internal_id
The internal ID within the GRF file.
Definition: engine_base.h:181
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:460
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:498
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:95
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:288
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:1310
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1162
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:288
EngineOverrideManager::GetID
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Definition: engine.cpp:502
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:2129
HANGAR
@ HANGAR
Heading for hangar.
Definition: airport.h:62
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
Vehicle::breakdowns_since_last_service
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
Definition: vehicle_base.h:280
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:64
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
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:58
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:922
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:329
GetEngineGrfFile
static const GRFFile * GetEngineGrfFile(EngineID engine_type)
Get the grf file associated with an engine type.
Definition: newgrf_engine.cpp:1035
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:154
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
RTFB_CATENARY
@ RTFB_CATENARY
Value for drawing a catenary.
Definition: rail.h:34
RealSpriteGroup::loading
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:90
Vehicle::breakdown_ctr
byte breakdown_ctr
Counter for managing breakdown events.
Definition: vehicle_base.h:278
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
VehicleResolverObject::VehicleResolverObject
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui=false, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Resolver of a vehicle (chain).
Definition: newgrf_engine.cpp:1051
Vehicle::GetDisplayProfitThisYear
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Definition: vehicle_base.h:595
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:311
Vehicle::GetCurrentMaxSpeed
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Definition: vehicle_base.h:519
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:73
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:47
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:60
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:245
INVALID_VEHICLE
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
Definition: vehicle_type.h:55
EIT_ON_MAP
@ EIT_ON_MAP
Vehicle drawn in viewport.
Definition: vehicle_type.h:87
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:302
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:336
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:132
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:316
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:324
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:333
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:274
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:468
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:277
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
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:62
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:1178
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:139
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:179
LiveryHelper
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
Definition: newgrf_engine.cpp:372
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
NewGRFCache::company_information
uint32 company_information
Cache for NewGRF var 43.
Definition: vehicle_base.h:74
HELIPAD3
@ HELIPAD3
Heading for helipad 3.
Definition: airport.h:82
EngineInfo::misc_flags
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:153
Vehicle::waiting_triggers
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
Definition: vehicle_base.h:314
RealSpriteGroup::loaded
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:89
NewGRFCache::position_in_vehicle
uint32 position_in_vehicle
Cache for NewGRF var 4D.
Definition: vehicle_base.h:75
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:48
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:395
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:286
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:906
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:652
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:104
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:408
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:62
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:345
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:310
_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:54
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:77
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:386
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:623
Vehicle::tick_counter
byte tick_counter
Increased by one for each tick.
Definition: vehicle_base.h:329
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:322
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:164
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:1381
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:61
Vehicle::subspeed
byte subspeed
fractional speed
Definition: vehicle_base.h:308
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:122
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1183
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:487
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
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:132
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:208
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:1298
CargoSpec::classes
uint16 classes
Classes of this cargo type.
Definition: cargotype.h:79
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:273
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:931
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:272
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:128
UsesWagonOverride
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
Definition: newgrf_engine.cpp:1147
HELIPAD1
@ HELIPAD1
Heading for helipad 1.
Definition: airport.h:69
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:325
Vehicle::breakdown_chance
byte breakdown_chance
Current chance of breakdowns.
Definition: vehicle_base.h:281
CommitVehicleListOrderChanges
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
Definition: newgrf_engine.cpp:1328
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:225
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
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:305
VSG_SCOPE_RELATIVE
@ VSG_SCOPE_RELATIVE
Relative position (vehicles only)
Definition: newgrf_spritegroup.h:102
ScopeResolver::GetVariable
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_spritegroup.cpp:106
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:323
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:125
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:140
NCVV_END
@ NCVV_END
End of the bits.
Definition: vehicle_base.h:65
EF_SPRITE_STACK
@ EF_SPRITE_STACK
Draw vehicle by stacking multiple sprites.
Definition: engine_type.h:174
GetReverseRailTypeTranslation
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
Definition: newgrf_railtype.cpp:162
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:279
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:94
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:342
Vehicle::day_counter
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:328
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
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:386
random_func.hpp
STARTTAKEOFF
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
Definition: airport.h:72
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:179
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:240
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
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:320
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:294
Engine::grf_prop
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Definition: engine_base.h:76
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:63
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
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:321
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:326
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
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:259
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:276
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition: vehicle_base.h:1080
TERM8
@ TERM8
Heading for terminal 8.
Definition: airport.h:81
EngineIDMapping::type
VehicleType type
The engine type.
Definition: engine_base.h:182
Engine::flags
byte flags
Flags of the engine.
Definition: engine_base.h:48
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:317
NewGRFCache::position_consist_length
uint32 position_consist_length
Cache for NewGRF var 40.
Definition: vehicle_base.h:71
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
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:955
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:716
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:317
Vehicle::GetDisplayProfitLastYear
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
Definition: vehicle_base.h:601
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:70
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:106
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:55
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:81
Vehicle::date_of_last_service
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:275
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