OpenTTD Source  12.0-beta2
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 "train.h"
12 #include "roadveh.h"
13 #include "vehicle_func.h"
14 #include "engine_func.h"
15 #include "company_func.h"
16 #include "newgrf.h"
17 
18 #include "table/strings.h"
19 
20 #include "safeguards.h"
21 
22 static const uint MAX_ARTICULATED_PARTS = 100;
23 
32 static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front = nullptr, bool *mirrored = nullptr)
33 {
34  assert(front == nullptr || front->engine_type == front_type);
35 
36  const Engine *front_engine = Engine::Get(front_type);
37 
38  uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, index, 0, front_type, front);
39  if (callback == CALLBACK_FAILED) return INVALID_ENGINE;
40 
41  if (front_engine->GetGRF()->grf_version < 8) {
42  /* 8 bits, bit 7 for mirroring */
43  callback = GB(callback, 0, 8);
44  if (callback == 0xFF) return INVALID_ENGINE;
45  if (mirrored != nullptr) *mirrored = HasBit(callback, 7);
46  callback = GB(callback, 0, 7);
47  } else {
48  /* 15 bits, bit 14 for mirroring */
49  if (callback == 0x7FFF) return INVALID_ENGINE;
50  if (mirrored != nullptr) *mirrored = HasBit(callback, 14);
51  callback = GB(callback, 0, 14);
52  }
53 
54  return GetNewEngineID(front_engine->GetGRF(), front_engine->type, callback);
55 }
56 
62 bool IsArticulatedEngine(EngineID engine_type)
63 {
64  return HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE);
65 }
66 
73 uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
74 {
75  if (!HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return 0;
76 
77  /* If we can't allocate a vehicle now, we can't allocate it in the command
78  * either, so it doesn't matter how many articulated parts there are. */
79  if (!Vehicle::CanAllocateItem()) return 0;
80 
81  Vehicle *v = nullptr;
82  if (!purchase_window) {
83  v = new Vehicle();
84  v->engine_type = engine_type;
86  }
87 
88  uint i;
89  for (i = 1; i < MAX_ARTICULATED_PARTS; i++) {
90  if (GetNextArticulatedPart(i, engine_type, v) == INVALID_ENGINE) break;
91  }
92 
93  delete v;
94 
95  return i - 1;
96 }
97 
98 
105 static inline uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
106 {
107  const Engine *e = Engine::Get(engine);
109  if (cargo_type != nullptr) *cargo_type = cargo;
110  if (cargo == CT_INVALID) return 0;
111  return e->GetDisplayDefaultCapacity();
112 }
113 
120 static inline CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
121 {
122  const Engine *e = Engine::Get(engine);
123  if (!e->CanCarryCargo()) return 0;
124 
125  CargoTypes cargoes = e->info.refit_mask;
126 
127  if (include_initial_cargo_type) {
128  SetBit(cargoes, e->GetDefaultCargoType());
129  }
130 
131  return cargoes;
132 }
133 
140 {
141  CargoArray capacity;
142  const Engine *e = Engine::Get(engine);
143 
144  CargoID cargo_type;
145  uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
146  if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
147 
148  if (!e->IsGroundVehicle()) return capacity;
149 
150  if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return capacity;
151 
152  for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
153  EngineID artic_engine = GetNextArticulatedPart(i, engine);
154  if (artic_engine == INVALID_ENGINE) break;
155 
156  cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
157  if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
158  }
159 
160  return capacity;
161 }
162 
172 void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity)
173 {
174  cargoes->Clear();
175  *refits = 0;
176 
177  const Engine *e = Engine::Get(engine);
178 
179  if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
180  (*cargoes)[cargo_type] += cargo_capacity;
181  if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type);
182  }
183 
184  if (!e->IsGroundVehicle() || !HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
185 
186  for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
187  EngineID artic_engine = GetNextArticulatedPart(i, engine);
188  if (artic_engine == INVALID_ENGINE) break;
189 
190  cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
191  if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
192  (*cargoes)[cargo_type] += cargo_capacity;
193  if (IsEngineRefittable(artic_engine)) SetBit(*refits, cargo_type);
194  }
195  }
196 }
197 
204 {
205  if (IsEngineRefittable(engine)) return true;
206 
207  const Engine *e = Engine::Get(engine);
208  if (!e->IsGroundVehicle()) return false;
209 
210  if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return false;
211 
212  for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
213  EngineID artic_engine = GetNextArticulatedPart(i, engine);
214  if (artic_engine == INVALID_ENGINE) break;
215 
216  if (IsEngineRefittable(artic_engine)) return true;
217  }
218 
219  return false;
220 }
221 
229 void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, CargoTypes *union_mask, CargoTypes *intersection_mask)
230 {
231  const Engine *e = Engine::Get(engine);
232  CargoTypes veh_cargoes = GetAvailableVehicleCargoTypes(engine, include_initial_cargo_type);
233  *union_mask = veh_cargoes;
234  *intersection_mask = (veh_cargoes != 0) ? veh_cargoes : ALL_CARGOTYPES;
235 
236  if (!e->IsGroundVehicle()) return;
237  if (!HasBit(e->info.callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
238 
239  for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
240  EngineID artic_engine = GetNextArticulatedPart(i, engine);
241  if (artic_engine == INVALID_ENGINE) break;
242 
243  veh_cargoes = GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type);
244  *union_mask |= veh_cargoes;
245  if (veh_cargoes != 0) *intersection_mask &= veh_cargoes;
246  }
247 }
248 
255 CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
256 {
257  CargoTypes union_mask, intersection_mask;
258  GetArticulatedRefitMasks(engine, include_initial_cargo_type, &union_mask, &intersection_mask);
259  return union_mask;
260 }
261 
268 CargoTypes GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
269 {
270  CargoTypes union_mask, intersection_mask;
271  GetArticulatedRefitMasks(engine, include_initial_cargo_type, &union_mask, &intersection_mask);
272  return intersection_mask;
273 }
274 
275 
284 {
285  CargoID first_cargo = CT_INVALID;
286 
287  do {
288  if (v->cargo_type != CT_INVALID && v->GetEngine()->CanCarryCargo()) {
289  if (first_cargo == CT_INVALID) first_cargo = v->cargo_type;
290  if (first_cargo != v->cargo_type) {
291  if (cargo_type != nullptr) *cargo_type = CT_INVALID;
292  return true;
293  }
294  }
295 
296  v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
297  } while (v != nullptr);
298 
299  if (cargo_type != nullptr) *cargo_type = first_cargo;
300  return false;
301 }
302 
312 {
313  const Engine *engine = v->GetEngine();
314 
315  CargoTypes purchase_refit_union, purchase_refit_intersection;
316  GetArticulatedRefitMasks(v->engine_type, true, &purchase_refit_union, &purchase_refit_intersection);
317  CargoArray purchase_default_capacity = GetCapacityOfArticulatedParts(v->engine_type);
318 
319  CargoTypes real_refit_union = 0;
320  CargoTypes real_refit_intersection = ALL_CARGOTYPES;
321  CargoArray real_default_capacity;
322 
323  do {
324  CargoTypes refit_mask = GetAvailableVehicleCargoTypes(v->engine_type, true);
325  real_refit_union |= refit_mask;
326  if (refit_mask != 0) real_refit_intersection &= refit_mask;
327 
328  assert(v->cargo_type < NUM_CARGO);
329  real_default_capacity[v->cargo_type] += v->cargo_cap;
330 
331  v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
332  } while (v != nullptr);
333 
334  /* Check whether the vehicle carries more cargoes than expected */
335  bool carries_more = false;
336  for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
337  if (real_default_capacity[cid] != 0 && purchase_default_capacity[cid] == 0) {
338  carries_more = true;
339  break;
340  }
341  }
342 
343  /* show a warning once for each GRF after each game load */
344  if (real_refit_union != purchase_refit_union || real_refit_intersection != purchase_refit_intersection || carries_more) {
345  ShowNewGrfVehicleError(engine->index, STR_NEWGRF_BUGGY, STR_NEWGRF_BUGGY_ARTICULATED_CARGO, GBUG_VEH_REFIT, false);
346  }
347 }
348 
354 {
355  VehicleType type = first->type;
356  if (!HasBit(EngInfo(first->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return;
357 
358  Vehicle *v = first;
359  for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) {
360  bool flip_image;
361  EngineID engine_type = GetNextArticulatedPart(i, first->engine_type, first, &flip_image);
362  if (engine_type == INVALID_ENGINE) return;
363 
364  /* In the (very rare) case the GRF reported wrong number of articulated parts
365  * and we run out of available vehicles, bail out. */
366  if (!Vehicle::CanAllocateItem()) return;
367 
369  gcache->first_engine = v->engine_type; // Needs to be set before first callback
370 
371  const Engine *e_artic = Engine::Get(engine_type);
372  switch (type) {
373  default: NOT_REACHED();
374 
375  case VEH_TRAIN: {
376  Train *front = Train::From(first);
377  Train *t = new Train();
378  v->SetNext(t);
379  v = t;
380 
381  t->subtype = 0;
382  t->track = front->track;
383  t->railtype = front->railtype;
384 
385  t->spritenum = e_artic->u.rail.image_index;
386  if (e_artic->CanCarryCargo()) {
387  t->cargo_type = e_artic->GetDefaultCargoType();
388  t->cargo_cap = e_artic->u.rail.capacity; // Callback 36 is called when the consist is finished
389  } else {
390  t->cargo_type = front->cargo_type; // Needed for livery selection
391  t->cargo_cap = 0;
392  }
393  t->refit_cap = 0;
394 
395  t->SetArticulatedPart();
396  break;
397  }
398 
399  case VEH_ROAD: {
400  RoadVehicle *front = RoadVehicle::From(first);
401  RoadVehicle *rv = new RoadVehicle();
402  v->SetNext(rv);
403  v = rv;
404 
405  rv->subtype = 0;
406  gcache->cached_veh_length = VEHICLE_LENGTH; // Callback is called when the consist is finished
407  rv->state = RVSB_IN_DEPOT;
408 
409  rv->roadtype = front->roadtype;
411 
412  rv->spritenum = e_artic->u.road.image_index;
413  if (e_artic->CanCarryCargo()) {
414  rv->cargo_type = e_artic->GetDefaultCargoType();
415  rv->cargo_cap = e_artic->u.road.capacity; // Callback 36 is called when the consist is finished
416  } else {
417  rv->cargo_type = front->cargo_type; // Needed for livery selection
418  rv->cargo_cap = 0;
419  }
420  rv->refit_cap = 0;
421 
422  rv->SetArticulatedPart();
423  break;
424  }
425  }
426 
427  /* get common values from first engine */
428  v->direction = first->direction;
429  v->owner = first->owner;
430  v->tile = first->tile;
431  v->x_pos = first->x_pos;
432  v->y_pos = first->y_pos;
433  v->z_pos = first->z_pos;
435  v->build_year = first->build_year;
436  v->vehstatus = first->vehstatus & ~VS_STOPPED;
437 
438  v->cargo_subtype = 0;
439  v->max_age = 0;
440  v->engine_type = engine_type;
441  v->value = 0;
442  v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
444 
445  if (flip_image) v->spritenum++;
446 
447  v->UpdatePosition();
448  }
449 }
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:2891
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:103
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:175
RoadVehicle::state
byte state
Definition: roadveh.h:109
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
Vehicle::y_pos
int32 y_pos
y coordinate.
Definition: vehicle_base.h:281
MutableSpriteCache::sprite_seq
VehicleSpriteSeq sprite_seq
Vehicle appearance.
Definition: vehicle_base.h:194
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:253
Vehicle::x_pos
int32 x_pos
x coordinate.
Definition: vehicle_base.h:280
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
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
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:311
GetAvailableVehicleCargoTypes
static CargoTypes GetAvailableVehicleCargoTypes(EngineID engine, bool include_initial_cargo_type)
Returns all cargoes a vehicle can carry.
Definition: articulated_vehicles.cpp:120
Vehicle::z_pos
int32 z_pos
z coordinate.
Definition: vehicle_base.h:282
VehicleSpriteSeq::Set
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Definition: vehicle_base.h:162
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:229
GetCapacityOfArticulatedParts
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
Definition: articulated_vehicles.cpp:139
Vehicle::random_bits
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Definition: vehicle_base.h:310
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:328
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
Vehicle::SetNext
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
Definition: vehicle.cpp:2726
AddArticulatedParts
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
Definition: articulated_vehicles.cpp:353
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Vehicle::GetNextArticulatedPart
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
Definition: vehicle_base.h:925
RoadVehicle::roadtype
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:117
Engine
Definition: engine_base.h:27
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:221
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:83
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:285
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1155
CBM_VEHICLE_ARTIC_ENGINE
@ CBM_VEHICLE_ARTIC_ENGINE
Add articulated engines (trains and road vehicles)
Definition: newgrf_callbacks.h:293
CountArticulatedParts
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
Count the number of articulated parts of an engine.
Definition: articulated_vehicles.cpp:73
CargoArray::Clear
void Clear()
Reset all entries.
Definition: cargo_type.h:94
Engine::GetGRF
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
Definition: engine_base.h:142
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
GroundVehicleCache
Cached, frequently calculated values.
Definition: ground_vehicle.hpp:29
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:255
EngineInfo::callback_mask
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition: engine_type.h:144
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:242
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:299
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
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:271
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:32
GetIntersectionOfArticulatedRefitMasks
CargoTypes GetIntersectionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ands the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:268
IsArticulatedVehicleCarryingDifferentCargoes
bool IsArticulatedVehicleCarryingDifferentCargoes(const Vehicle *v, CargoID *cargo_type)
Tests if all parts of an articulated vehicle are refitted to the same cargo.
Definition: articulated_vehicles.cpp:283
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
safeguards.h
Train
'Train' is either a loco or a wagon.
Definition: train.h:86
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:118
GetNewEngineID
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
Return the ID of a new engine.
Definition: newgrf.cpp:707
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:297
Vehicle::sprite_cache
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
Definition: vehicle_base.h:343
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:203
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:283
Engine::IsGroundVehicle
bool IsGroundVehicle() const
Check if the engine is a ground vehicle.
Definition: engine_base.h:132
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
VEHICLE_LENGTH
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
Definition: vehicle_type.h:76
Vehicle::cargo_cap
uint16 cargo_cap
total capacity
Definition: vehicle_base.h:318
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:158
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1164
GroundVehicle::SetArticulatedPart
void SetArticulatedPart()
Set a vehicle to be an articulated part.
Definition: ground_vehicle.hpp:259
VehicleRandomBits
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
Definition: vehicle.cpp:363
newgrf.h
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:915
Vehicle::build_year
Year build_year
Year the vehicle has been built.
Definition: vehicle_base.h:269
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:307
company_func.h
Vehicle::subtype
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Definition: vehicle_base.h:338
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
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:32
IsArticulatedEngine
bool IsArticulatedEngine(EngineID engine_type)
Does a NewGRF report that this should be an articulated vehicle?
Definition: articulated_vehicles.cpp:62
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:316
Vehicle::spritenum
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Definition: vehicle_base.h:291
Vehicle::cargo_subtype
byte cargo_subtype
Used for livery refits (NewGRF variations)
Definition: vehicle_base.h:317
IsEngineRefittable
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1156
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:53
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
GetArticulatedVehicleCargoesAndRefits
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity)
Get the default cargoes and refits of an articulated vehicle.
Definition: articulated_vehicles.cpp:172
Vehicle::UpdatePosition
void UpdatePosition()
Update the position of the vehicle.
Definition: vehicle.cpp:1596
GetVehicleDefaultCapacity
static uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
Returns the default (non-refitted) capacity of a specific EngineID.
Definition: articulated_vehicles.cpp:105
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
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:22
RVSB_IN_DEPOT
@ RVSB_IN_DEPOT
The vehicle is in a depot.
Definition: roadveh.h:39
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:46
Vehicle::refit_cap
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:319
Vehicle::date_of_last_service
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:272
engine_func.h
roadveh.h