OpenTTD Source: src/articulated_vehicles.cpp Source File

OpenTTD Source 14.0-beta1

articulated_vehicles.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 "core/bitmath_func.hpp"
12 #include "core/random_func.hpp"
13 #include "train.h"
14 #include "roadveh.h"
15 #include "vehicle_func.h"
16 #include "engine_func.h"
17 #include "company_func.h"
18 #include "newgrf.h"
19
20 #include "table/strings.h"
21
22 #include "safeguards.h"
23
24 static const uint MAX_ARTICULATED_PARTS = 100;
25
34 static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front = nullptr, bool *mirrored = nullptr)
35 {
36 assert(front == nullptr || front->engine_type == front_type);
37
38 const Engine *front_engine = Engine::Get(front_type);
39
40 uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, index, 0, front_type, front);
41 if (callback == CALLBACK_FAILED) return INVALID_ENGINE;
42
43 if (front_engine->GetGRF()->grf_version < 8) {
44 /* 8 bits, bit 7 for mirroring */
45 callback = GB(callback, 0, 8);
46 if (callback == 0xFF) return INVALID_ENGINE;
47 if (mirrored != nullptr) *mirrored = HasBit(callback, 7);
48 callback = GB(callback, 0, 7);
49 } else {
50 /* 15 bits, bit 14 for mirroring */
51 if (callback == 0x7FFF) return INVALID_ENGINE;
52 if (mirrored != nullptr) *mirrored = HasBit(callback, 14);
53 callback = GB(callback, 0, 14);
54 }
55
56 return GetNewEngineID(front_engine->GetGRF(), front_engine->type, callback);
57 }
58
64 bool IsArticulatedEngine(EngineID engine_type)
65 {
66 return HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE);
67 }
68
75 uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
76 {
77 if (!HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return 0;
78
79 /* If we can't allocate a vehicle now, we can't allocate it in the command
80 * either, so it doesn't matter how many articulated parts there are. */
81 if (!Vehicle::CanAllocateItem()) return 0;
82
83 Vehicle *v = nullptr;
84 if (!purchase_window) {
85 v = new Vehicle();
86 v->engine_type = engine_type;
87 v->owner = _current_company;
88 }
89
90 uint i;
91 for (i = 1; i < MAX_ARTICULATED_PARTS; i++) {
92 if (GetNextArticulatedPart(i, engine_type, v) == INVALID_ENGINE) break;
93 }
94
95 delete v;
96
97 return i - 1;
98 }
99
100
107 static inline uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
108 {
109 const Engine *e = Engine::Get(engine);
110 CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
111 if (cargo_type != nullptr) *cargo_type = cargo;
112 if (!IsValidCargoID(cargo)) return 0;
113 return e->GetDisplayDefaultCapacity();
114 }
115
122 static inline CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
123 {
124 const Engine *e = Engine::Get(engine);
125 if (!e->CanCarryCargo()) return 0;
126
127 CargoTypes cargoes = e->info.refit_mask;
128
129 if (include_initial_cargo_type) {
130 SetBit(cargoes, e->GetDefaultCargoType());
131 }
132
133 return cargoes;
134 }
135
141 CargoArray GetCapacityOfArticulatedParts(EngineID engine)
142 {
143 CargoArray capacity{};
144 const Engine *e = Engine::Get(engine);
145
146 CargoID cargo_type;
147 uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
148 if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
149
150 if (!e->IsGroundVehicle()) return capacity;
151
152 if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;
153
154 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
155 EngineID artic_engine = GetNextArticulatedPart(i, engine);
156 if (artic_engine == INVALID_ENGINE) break;
157
158 cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
159 if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
160 }
161
162 return capacity;
163 }
164
170 CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
171 {
172 CargoTypes cargoes = 0;
173 const Engine *e = Engine::Get(engine);
174
175 CargoID cargo_type;
176 uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
177 if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
178
179 if (!e->IsGroundVehicle()) return cargoes;
180
181 if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return cargoes;
182
183 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
184 EngineID artic_engine = GetNextArticulatedPart(i, engine);
185 if (artic_engine == INVALID_ENGINE) break;
186
187 cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
188 if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
189 }
190
191 return cargoes;
192 }
193
199 bool IsArticulatedVehicleRefittable(EngineID engine)
200 {
201 if (IsEngineRefittable(engine)) return true;
202
203 const Engine *e = Engine::Get(engine);
204 if (!e->IsGroundVehicle()) return false;
205
206 if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return false;
207
208 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
209 EngineID artic_engine = GetNextArticulatedPart(i, engine);
210 if (artic_engine == INVALID_ENGINE) break;
211
212 if (IsEngineRefittable(artic_engine)) return true;
213 }
214
215 return false;
216 }
217
225 void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
226 {
227 const Engine *e = Engine::Get(engine);
228 CargoTypes veh_cargoes = GetAvailableVehicleCargoTypes(engine, include_initial_cargo_type);
229 *union_mask = veh_cargoes;
230 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
231
232 if (!e->IsGroundVehicle()) return;
233 if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
234
235 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
236 EngineID artic_engine = GetNextArticulatedPart(i, engine);
237 if (artic_engine == INVALID_ENGINE) break;
238
239 veh_cargoes = GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type);
240 *union_mask |= veh_cargoes;
241 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
242 }
243 }
244
251 CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
252 {
253 CargoTypes union_mask, intersection_mask;
254 GetArticulatedRefitMasks(engine, include_initial_cargo_type, &union_mask, &intersection_mask);
255 return union_mask;
256 }
257
265 CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoID *cargo_type)
266 {
267 CargoTypes cargoes = 0;
268 CargoID first_cargo = INVALID_CARGO;
269
270 do {
271 if (IsValidCargoID(v->cargo_type) && v->GetEngine()->CanCarryCargo()) {
272 SetBit(cargoes, v->cargo_type);
273 if (!IsValidCargoID(first_cargo)) first_cargo = v->cargo_type;
274 if (first_cargo != v->cargo_type) {
275 if (cargo_type != nullptr) {
276 *cargo_type = INVALID_CARGO;
277 cargo_type = nullptr;
278 }
279 }
280 }
281
282 v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
283 } while (v != nullptr);
284
285 if (cargo_type != nullptr) *cargo_type = first_cargo;
286 return cargoes;
287 }
288
297 void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
298 {
299 const Engine *engine = v->GetEngine();
300
301 CargoTypes purchase_refit_union, purchase_refit_intersection;
302 GetArticulatedRefitMasks(v->engine_type, true, &purchase_refit_union, &purchase_refit_intersection);
303 CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type);
304
305 CargoTypes real_refit_union = 0;
306 CargoTypes real_refit_intersection = ALL_CARGOTYPES;
307 CargoTypes real_default_cargoes = 0;
308
309 do {
310 CargoTypes refit_mask = GetAvailableVehicleCargoTypes(v->engine_type, true);
311 real_refit_union |= refit_mask;
312 if (refit_mask != 0) real_refit_intersection &= refit_mask;
313
314 assert(v->cargo_type < NUM_CARGO);
315 if (v->cargo_cap > 0) SetBit(real_default_cargoes, v->cargo_type);
316
317 v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
318 } while (v != nullptr);
319
320 /* Check whether the vehicle carries more cargoes than expected */
321 bool carries_more = false;
322 for (CargoID cid : SetCargoBitIterator(real_default_cargoes)) {
323 if (purchase_default_capacity[cid] == 0) {
324 carries_more = true;
325 break;
326 }
327 }
328
329 /* show a warning once for each GRF after each game load */
330 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
331 ShowNewGrfVehicleError(engine->index, STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ARTICULATED_CARGO, GBUG_VEH_REFIT, false);
332 }
333 }
334
339 void AddArticulatedParts(Vehicle *first)
340 {
341 VehicleType type = first->type;
342 if (!HasBit(EngInfo(first->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
343
344 Vehicle *v = first;
345 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
346 bool flip_image;
347 EngineID engine_type = GetNextArticulatedPart(i, first->engine_type, first, &flip_image);
348 if (engine_type == INVALID_ENGINE) return;
349
350 /* In the (very rare) case the GRF reported wrong number of articulated parts
351 * and we run out of available vehicles, bail out. */
352 if (!Vehicle::CanAllocateItem()) return;
353
354 GroundVehicleCache *gcache = v->GetGroundVehicleCache();
355 gcache->first_engine = v->engine_type; // Needs to be set before first callback
356
357 const Engine *e_artic = Engine::Get(engine_type);
358 switch (type) {
359 default: NOT_REACHED();
360
361 case VEH_TRAIN: {
362 Train *front = Train::From(first);
363 Train *t = new Train();
364 v->SetNext(t);
365 v = t;
366
367 t->subtype = 0;
368 t->track = front->track;
369 t->railtype = front->railtype;
370
371 t->spritenum = e_artic->u.rail.image_index;
372 if (e_artic->CanCarryCargo()) {
373 t->cargo_type = e_artic->GetDefaultCargoType();
374 t->cargo_cap = e_artic->u.rail.capacity; // Callback 36 is called when the consist is finished
375 } else {
376 t->cargo_type = front->cargo_type; // Needed for livery selection
377 t->cargo_cap = 0;
378 }
379 t->refit_cap = 0;
380
381 t->SetArticulatedPart();
382 break;
383 }
384
385 case VEH_ROAD: {
386 RoadVehicle *front = RoadVehicle::From(first);
387 RoadVehicle *rv = new RoadVehicle();
388 v->SetNext(rv);
389 v = rv;
390
391 rv->subtype = 0;
392 gcache->cached_veh_length = VEHICLE_LENGTH; // Callback is called when the consist is finished
393 rv->state = RVSB_IN_DEPOT;
394
395 rv->roadtype = front->roadtype;
396 rv->compatible_roadtypes = front->compatible_roadtypes;
397
398 rv->spritenum = e_artic->u.road.image_index;
399 if (e_artic->CanCarryCargo()) {
400 rv->cargo_type = e_artic->GetDefaultCargoType();
401 rv->cargo_cap = e_artic->u.road.capacity; // Callback 36 is called when the consist is finished
402 } else {
403 rv->cargo_type = front->cargo_type; // Needed for livery selection
404 rv->cargo_cap = 0;
405 }
406 rv->refit_cap = 0;
407
408 rv->SetArticulatedPart();
409 break;
410 }
411 }
412
413 /* get common values from first engine */
414 v->direction = first->direction;
415 v->owner = first->owner;
416 v->tile = first->tile;
417 v->x_pos = first->x_pos;
418 v->y_pos = first->y_pos;
419 v->z_pos = first->z_pos;
420 v->date_of_last_service = first->date_of_last_service;
421 v->date_of_last_service_newgrf = first->date_of_last_service_newgrf;
422 v->build_year = first->build_year;
423 v->vehstatus = first->vehstatus & ~VS_STOPPED;
424
425 v->cargo_subtype = 0;
426 v->max_age = 0;
427 v->engine_type = engine_type;
428 v->value = 0;
429 v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
430 v->random_bits = Random();
431
432 if (flip_image) v->spritenum++;
433
434 if (v->type == VEH_TRAIN && TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION);
435 v->UpdatePosition();
436 }
437 }
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:106
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition: vehicle.cpp:3077
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:205
RoadVehicle::state
byte state
Definition: roadveh.h:108
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:196
Vehicle::value
Money value
Value of the vehicle.
Definition: vehicle_base.h:271
train.h
GBUG_VEH_REFIT
@ GBUG_VEH_REFIT
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
Definition: newgrf_config.h:45
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition: vehicle_base.h:338
CBID_VEHICLE_ARTIC_ENGINE
@ CBID_VEHICLE_ARTIC_ENGINE
Builds articulated engines for trains and RVs.
Definition: newgrf_callbacks.h:51
GroundVehicleCache::first_engine
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Definition: ground_vehicle.hpp:43
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:116
CheckConsistencyOfArticulatedVehicle
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
Definition: articulated_vehicles.cpp:297
GetAvailableVehicleCargoTypes
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Definition: articulated_vehicles.cpp:122
GetCargoTypesOfArticulatedVehicle
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoID *cargo_type)
Get cargo mask of all cargoes carried by an articulated vehicle.
Definition: articulated_vehicles.cpp:265
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:164
GetArticulatedRefitMasks
void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
Merges the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:225
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition: articulated_vehicles.cpp:141
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:348
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition: vehicle.cpp:2859
GetVehicleDefaultCapacity
static uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
Returns the default (non-refitted) capacity of a specific EngineID.
Definition: articulated_vehicles.cpp:107
AddArticulatedParts
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
Definition: articulated_vehicles.cpp:339
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:97
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:959
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:116
Engine
Definition: engine_base.h:37
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:96
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:304
CBM_VEHICLE_ARTIC_ENGINE
@ CBM_VEHICLE_ARTIC_ENGINE
Add articulated engines (trains and road vehicles)
Definition: newgrf_callbacks.h:299
CountArticulatedParts
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
Definition: articulated_vehicles.cpp:75
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition: vehicle_base.h:299
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:167
Vehicle::date_of_last_service
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
Definition: vehicle_base.h:290
bitmath_func.hpp
EngineInfo::callback_mask
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:155
GroundVehicleCache
Cached, frequently calculated values.
Definition: ground_vehicle.hpp:29
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:251
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:260
Vehicle::random_bits
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition: vehicle_base.h:329
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:318
TestVehicleBuildProbability
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probablity type.
Definition: newgrf_engine.cpp:1201
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:287
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:34
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:747
safeguards.h
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
VRF_REVERSE_DIRECTION
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
Definition: train.h:28
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:117
stdafx.h
ShowNewGrfVehicleError
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical)
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
Definition: vehicle.cpp:317
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:363
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition: articulated_vehicles.cpp:199
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition: vehicle_base.h:301
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:302
Engine::IsGroundVehicle
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
Definition: engine_base.h:157
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:76
Vehicle::max_age
TimerGameCalendar::Date max_age
Maximum age.
Definition: vehicle_base.h:289
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:168
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1201
GroundVehicle::SetArticulatedPart
void SetArticulatedPart()
Set a vehicle to be an articulated part.
Definition: ground_vehicle.hpp:258
Vehicle::date_of_last_service_newgrf
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
Definition: vehicle_base.h:291
GetNewEngineID
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Definition: newgrf.cpp:690
newgrf.h
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:949
Pool::PoolItem<&_vehicle_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:305
company_func.h
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition: vehicle_base.h:300
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:358
GetNextArticulatedPart
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
Definition: articulated_vehicles.cpp:34
random_func.hpp
IsArticulatedEngine
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
Definition: articulated_vehicles.cpp:64
GetCargoTypesOfArticulatedParts
CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
Get the cargo mask of the parts of a given engine.
Definition: articulated_vehicles.cpp:170
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:336
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:90
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:310
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:337
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1257
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
RailVehicleInfo::capacity
byte capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
Definition: engine_type.h:54
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:51
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1668
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1149
MAX_ARTICULATED_PARTS
static const uint MAX_ARTICULATED_PARTS
Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback...
Definition: articulated_vehicles.cpp:24
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition: roadveh.h:38
GroundVehicleCache::cached_veh_length
uint8_t 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
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:56
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:339
engine_func.h
roadveh.h
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103