OpenTTD Source: src/articulated_vehicles.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 EngineID::Invalid();
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 EngineID::Invalid();
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 EngineID::Invalid();
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 EngInfo(engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine);
67}
68
75uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
76{
77 if (!EngInfo(engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) 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 std::unique_ptr<Vehicle> v;
84 if (!purchase_window) {
85 v = std::make_unique<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.get()) == EngineID::Invalid()) break;
93 }
94
95 return i - 1;
96}
97
98
104 static inline std::pair<CargoType, uint16_t> GetVehicleDefaultCapacity(EngineID engine)
105{
106 const Engine *e = Engine::Get(engine);
107 CargoType cargo = e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO;
108 return {cargo, IsValidCargoType(cargo) ? e->GetDisplayDefaultCapacity() : 0};
109}
110
117 static inline CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
118{
119 const Engine *e = Engine::Get(engine);
120 if (!e->CanCarryCargo()) return 0;
121
122 CargoTypes cargoes = e->info.refit_mask;
123
124 if (include_initial_cargo_type) {
125 SetBit(cargoes, e->GetDefaultCargoType());
126 }
127
128 return cargoes;
129}
130
136 CargoArray GetCapacityOfArticulatedParts(EngineID engine)
137{
138 CargoArray capacity{};
139 const Engine *e = Engine::Get(engine);
140
141 if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoType(cargo)) {
142 capacity[cargo] = cap;
143 }
144
145 if (!e->IsGroundVehicle()) return capacity;
146
147 if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return capacity;
148
149 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
150 EngineID artic_engine = GetNextArticulatedPart(i, engine);
151 if (artic_engine == EngineID::Invalid()) break;
152
153 if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoType(cargo)) {
154 capacity[cargo] += cap;
155 }
156 }
157
158 return capacity;
159}
160
166CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
167{
168 CargoTypes cargoes = 0;
169 const Engine *e = Engine::Get(engine);
170
171 if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoType(cargo) && cap > 0) {
172 SetBit(cargoes, cargo);
173 }
174
175 if (!e->IsGroundVehicle()) return cargoes;
176
177 if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return cargoes;
178
179 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
180 EngineID artic_engine = GetNextArticulatedPart(i, engine);
181 if (artic_engine == EngineID::Invalid()) break;
182
183 if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoType(cargo) && cap > 0) {
184 SetBit(cargoes, cargo);
185 }
186 }
187
188 return cargoes;
189}
190
196 bool IsArticulatedVehicleRefittable(EngineID engine)
197{
198 if (IsEngineRefittable(engine)) return true;
199
200 const Engine *e = Engine::Get(engine);
201 if (!e->IsGroundVehicle()) return false;
202
203 if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return false;
204
205 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
206 EngineID artic_engine = GetNextArticulatedPart(i, engine);
207 if (artic_engine == EngineID::Invalid()) break;
208
209 if (IsEngineRefittable(artic_engine)) return true;
210 }
211
212 return false;
213}
214
222 void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
223{
224 const Engine *e = Engine::Get(engine);
225 CargoTypes veh_cargoes = GetAvailableVehicleCargoTypes(engine, include_initial_cargo_type);
226 *union_mask = veh_cargoes;
227 *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
228
229 if (!e->IsGroundVehicle()) return;
230 if (!e->info.callback_mask.Test(VehicleCallbackMask::ArticEngine)) return;
231
232 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
233 EngineID artic_engine = GetNextArticulatedPart(i, engine);
234 if (artic_engine == EngineID::Invalid()) break;
235
236 veh_cargoes = GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type);
237 *union_mask |= veh_cargoes;
238 if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
239 }
240}
241
248CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
249{
250 CargoTypes union_mask, intersection_mask;
251 GetArticulatedRefitMasks(engine, include_initial_cargo_type, &union_mask, &intersection_mask);
252 return union_mask;
253}
254
262CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoType *cargo_type)
263{
264 CargoTypes cargoes = 0;
265 CargoType first_cargo = INVALID_CARGO;
266
267 do {
268 if (IsValidCargoType(v->cargo_type) && v->GetEngine()->CanCarryCargo()) {
269 SetBit(cargoes, v->cargo_type);
270 if (!IsValidCargoType(first_cargo)) first_cargo = v->cargo_type;
271 if (first_cargo != v->cargo_type) {
272 if (cargo_type != nullptr) {
273 *cargo_type = INVALID_CARGO;
274 cargo_type = nullptr;
275 }
276 }
277 }
278
279 v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
280 } while (v != nullptr);
281
282 if (cargo_type != nullptr) *cargo_type = first_cargo;
283 return cargoes;
284}
285
294 void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
295{
296 const Engine *engine = v->GetEngine();
297
298 CargoTypes purchase_refit_union, purchase_refit_intersection;
299 GetArticulatedRefitMasks(v->engine_type, true, &purchase_refit_union, &purchase_refit_intersection);
300 CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type);
301
302 CargoTypes real_refit_union = 0;
303 CargoTypes real_refit_intersection = ALL_CARGOTYPES;
304 CargoTypes real_default_cargoes = 0;
305
306 do {
307 CargoTypes refit_mask = GetAvailableVehicleCargoTypes(v->engine_type, true);
308 real_refit_union |= refit_mask;
309 if (refit_mask != 0) real_refit_intersection &= refit_mask;
310
311 assert(v->cargo_type < NUM_CARGO);
312 if (v->cargo_cap > 0) SetBit(real_default_cargoes, v->cargo_type);
313
314 v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
315 } while (v != nullptr);
316
317 /* Check whether the vehicle carries more cargoes than expected */
318 bool carries_more = false;
319 for (CargoType cargo_type : SetCargoBitIterator(real_default_cargoes)) {
320 if (purchase_default_capacity[cargo_type] == 0) {
321 carries_more = true;
322 break;
323 }
324 }
325
326 /* show a warning once for each GRF after each game load */
327 if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
328 ShowNewGrfVehicleError(engine->index, STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ARTICULATED_CARGO, GRFBug::VehRefit, false);
329 }
330}
331
336 void AddArticulatedParts(Vehicle *first)
337{
338 VehicleType type = first->type;
339 if (!EngInfo(first->engine_type)->callback_mask.Test(VehicleCallbackMask::ArticEngine)) return;
340
341 Vehicle *v = first;
342 for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
343 bool flip_image;
344 EngineID engine_type = GetNextArticulatedPart(i, first->engine_type, first, &flip_image);
345 if (engine_type == EngineID::Invalid()) return;
346
347 /* In the (very rare) case the GRF reported wrong number of articulated parts
348 * and we run out of available vehicles, bail out. */
349 if (!Vehicle::CanAllocateItem()) return;
350
351 GroundVehicleCache *gcache = v->GetGroundVehicleCache();
352 gcache->first_engine = v->engine_type; // Needs to be set before first callback
353
354 const Engine *e_artic = Engine::Get(engine_type);
355 switch (type) {
356 default: NOT_REACHED();
357
358 case VEH_TRAIN: {
359 Train *front = Train::From(first);
360 Train *t = new Train();
361 v->SetNext(t);
362 v = t;
363
364 t->subtype = 0;
365 t->track = front->track;
366 t->railtypes = front->railtypes;
367
368 t->spritenum = e_artic->VehInfo<RailVehicleInfo>().image_index;
369 if (e_artic->CanCarryCargo()) {
370 t->cargo_type = e_artic->GetDefaultCargoType();
371 t->cargo_cap = e_artic->VehInfo<RailVehicleInfo>().capacity; // Callback 36 is called when the consist is finished
372 } else {
373 t->cargo_type = front->cargo_type; // Needed for livery selection
374 t->cargo_cap = 0;
375 }
376 t->refit_cap = 0;
377
378 t->SetArticulatedPart();
379 break;
380 }
381
382 case VEH_ROAD: {
383 RoadVehicle *front = RoadVehicle::From(first);
384 RoadVehicle *rv = new RoadVehicle();
385 v->SetNext(rv);
386 v = rv;
387
388 rv->subtype = 0;
389 gcache->cached_veh_length = VEHICLE_LENGTH; // Callback is called when the consist is finished
390 rv->state = RVSB_IN_DEPOT;
391
392 rv->roadtype = front->roadtype;
393 rv->compatible_roadtypes = front->compatible_roadtypes;
394
395 rv->spritenum = e_artic->VehInfo<RoadVehicleInfo>().image_index;
396 if (e_artic->CanCarryCargo()) {
397 rv->cargo_type = e_artic->GetDefaultCargoType();
398 assert(IsValidCargoType(rv->cargo_type));
399 rv->cargo_cap = e_artic->VehInfo<RoadVehicleInfo>().capacity; // Callback 36 is called when the consist is finished
400 } else {
401 rv->cargo_type = front->cargo_type; // Needed for livery selection
402 rv->cargo_cap = 0;
403 }
404 rv->refit_cap = 0;
405
406 rv->SetArticulatedPart();
407 break;
408 }
409 }
410
411 /* get common values from first engine */
412 v->direction = first->direction;
413 v->owner = first->owner;
414 v->tile = first->tile;
415 v->x_pos = first->x_pos;
416 v->y_pos = first->y_pos;
417 v->z_pos = first->z_pos;
418 v->date_of_last_service = first->date_of_last_service;
419 v->date_of_last_service_newgrf = first->date_of_last_service_newgrf;
420 v->build_year = first->build_year;
421 v->vehstatus = first->vehstatus;
422 v->vehstatus.Reset(VehState::Stopped);
423
424 v->cargo_subtype = 0;
425 v->max_age = CalendarTime::MIN_DATE;
426 v->engine_type = engine_type;
427 v->value = 0;
428 v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
429 v->random_bits = Random();
430
431 if (flip_image) v->spritenum++;
432
433 if (v->type == VEH_TRAIN) {
434 auto prob = TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed);
435 if (prob.has_value()) Train::From(v)->flags.Set(VehicleRailFlag::Flipped, prob.value());
436 }
437 v->UpdatePosition();
438 }
439}
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition articulated_vehicles.cpp:248
IsArticulatedEngine
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
Definition articulated_vehicles.cpp:64
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
AddArticulatedParts
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
Definition articulated_vehicles.cpp:336
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition articulated_vehicles.cpp:136
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition articulated_vehicles.cpp:196
GetCargoTypesOfArticulatedVehicle
CargoTypes GetCargoTypesOfArticulatedVehicle(const Vehicle *v, CargoType *cargo_type)
Get cargo mask of all cargoes carried by an articulated vehicle.
Definition articulated_vehicles.cpp:262
GetVehicleDefaultCapacity
static std::pair< CargoType, uint16_t > GetVehicleDefaultCapacity(EngineID engine)
Returns the default (non-refitted) cargo and capacity of a specific EngineID.
Definition articulated_vehicles.cpp:104
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:222
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:294
GetCargoTypesOfArticulatedParts
CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
Get the cargo mask of the parts of a given engine.
Definition articulated_vehicles.cpp:166
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
CountArticulatedParts
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
Definition articulated_vehicles.cpp:75
GetAvailableVehicleCargoTypes
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Definition articulated_vehicles.cpp:117
bitmath_func.hpp
Functions related to bit mathematics.
GB
static constexpr 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
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
NUM_CARGO
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
Engine
Definition engine_base.h:38
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition engine_base.h:166
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition engine_base.h:62
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:115
Engine::GetDefaultCargoType
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition engine_base.h:95
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition engine.cpp:167
Engine::IsGroundVehicle
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
Definition engine_base.h:156
TimerGameConst< struct Calendar >::MIN_DATE
static constexpr TimerGame< struct Calendar >::Date MIN_DATE
The date on January 1, year 0.
Definition timer_game_common.h:190
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition engine.cpp:1287
engine_func.h
Functions related to engines.
BorderFlag::Random
@ Random
Randomise borders.
GetNewEngineID
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Definition newgrf.cpp:296
newgrf.h
Base for the NewGRF implementation.
VehicleCallbackMask::ArticEngine
@ ArticEngine
Add articulated engines (trains and road vehicles)
CBID_VEHICLE_ARTIC_ENGINE
@ CBID_VEHICLE_ARTIC_ENGINE
Builds articulated engines for trains and RVs.
Definition newgrf_callbacks.h:53
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
GRFBug::VehRefit
@ VehRefit
Articulated vehicles carry different cargoes resp. are differently refittable than specified in purch...
TestVehicleBuildProbability
std::optional< bool > TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probability type.
Definition newgrf_engine.cpp:1251
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
Definition newgrf_engine.cpp:1198
random_func.hpp
Pseudo random number generator.
roadveh.h
Road vehicle states.
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition roadveh.h:38
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition vehicle_type.h:51
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
EngineInfo::callback_mask
VehicleCallbackMasks callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition engine_type.h:210
GroundVehicleCache
Cached, frequently calculated values.
Definition ground_vehicle.hpp:30
GroundVehicleCache::first_engine
EngineID first_engine
Cached EngineID of the front vehicle. EngineID::Invalid() for the front vehicle itself.
Definition ground_vehicle.hpp:44
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:45
GroundVehicle::SetArticulatedPart
void SetArticulatedPart()
Set a vehicle to be an articulated part.
Definition ground_vehicle.hpp:261
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition vehicle_base.h:162
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
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:357
RailVehicleInfo
Information about a rail vehicle.
Definition engine_type.h:74
RoadVehicleInfo
Information about a road vehicle.
Definition engine_type.h:146
RoadVehicle
Buses, trucks and trams belong to this class.
Definition roadveh.h:98
RoadVehicle::state
uint8_t state
Definition roadveh.h:100
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
Definition roadveh.h:110
RoadVehicle::roadtype
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:108
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:277
SpecializedVehicle::From
static T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition vehicle_base.h:1134
Train
'Train' is either a loco or a wagon.
Definition train.h:91
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition vehicle_base.h:130
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition vehicle_base.h:278
Vehicle::z_pos
int32_t z_pos
z coordinate.
Definition vehicle_base.h:267
Vehicle::direction
Direction direction
facing
Definition vehicle_base.h:268
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition vehicle.cpp:718
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition vehicle_base.h:941
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:256
Vehicle::cargo_cap
uint16_t cargo_cap
total capacity
Definition vehicle_base.h:299
Vehicle::subtype
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition vehicle_base.h:310
Vehicle::random_bits
uint16_t random_bits
Bits used for randomized variational spritegroups.
Definition vehicle_base.h:290
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition vehicle_base.h:931
Vehicle::vehstatus
VehStates vehstatus
Status.
Definition vehicle_base.h:309
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:257
Vehicle::cargo_type
CargoType cargo_type
type of cargo this vehicle is carrying
Definition vehicle_base.h:297
Vehicle::y_pos
int32_t y_pos
y coordinate.
Definition vehicle_base.h:266
Vehicle::x_pos
int32_t x_pos
x coordinate.
Definition vehicle_base.h:265
Vehicle::value
Money value
Value of the vehicle.
Definition vehicle_base.h:236
Vehicle::refit_cap
uint16_t refit_cap
Capacity left over from before last refit.
Definition vehicle_base.h:300
Vehicle::GetGroundVehicleCache
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
Definition vehicle.cpp:3143
Vehicle::spritenum
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition vehicle_base.h:276
Vehicle::cargo_subtype
uint8_t cargo_subtype
Used for livery refits (NewGRF variations)
Definition vehicle_base.h:298
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition vehicle.cpp:2927
Vehicle::max_age
TimerGameCalendar::Date max_age
Maximum age.
Definition vehicle_base.h:255
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition vehicle_base.h:323
Vehicle::tile
TileIndex tile
Current tile index.
Definition vehicle_base.h:225
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition vehicle.cpp:1662
Vehicle::build_year
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Definition vehicle_base.h:252
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition vehicle_base.h:270
train.h
Base for the train class.
Flipped
@ Flipped
Reverse the visible direction of the vehicle.
Definition train.h:28
ShowNewGrfVehicleError
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBug bug_type, bool critical)
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
Definition vehicle.cpp:328
VehState::Stopped
@ Stopped
Vehicle is stopped by the player.
vehicle_func.h
Functions related to vehicles.
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition vehicle_type.h:26
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition vehicle_type.h:65