10 #ifndef VEHICLE_BASE_H 11 #define VEHICLE_BASE_H 134 return this->count == other.count && MemCmpT<PalSpriteID>(this->seq, other.seq, this->count) == 0;
147 return this->count != 0;
164 this->seq[0].
sprite = sprite;
165 this->seq[0].
pal = 0;
173 this->count = src.count;
174 for (uint i = 0; i < src.count; ++i) {
176 this->seq[i].
pal = 0;
180 void GetBounds(
Rect *bounds)
const;
181 void Draw(
int x,
int y,
PaletteID default_pal,
bool force_pal)
const;
206 cargo(cargo), capacity(capacity), remaining(remaining) {}
212 typedef std::list<RefitDesc> RefitList;
213 typedef std::map<CargoID, uint> CapacitiesMap;
332 void PreDestructor();
337 void CancelReservation(StationID next,
Station *st);
343 uint16 &GetGroundVehicleFlags();
344 const uint16 &GetGroundVehicleFlags()
const;
346 void DeleteUnreachedImplicitOrders();
348 void HandleLoading(
bool mode =
false);
352 uint GetConsistTotalCapacity()
const;
385 return (this->direction & 1) ? speed : speed * 3 / 4;
402 return speed * 3 / 4;
414 return (this->direction & 1) ? 192 : 256;
433 const Engine *GetEngine()
const;
443 uint32 GetGRFID()
const;
460 for (
Vehicle *u =
this; u !=
nullptr; u = u->
Next()) {
461 u->InvalidateNewGRFCache();
516 assert(
this == this->First());
518 if (this->IsPrimaryVehicle() && !(this->vehstatus &
VS_STOPPED))
return false;
519 return this->IsChainInDepot();
526 virtual bool Tick() {
return true; };
538 virtual uint Crash(
bool flooded =
false);
601 while (v->
Next() !=
nullptr) v = v->
Next();
612 while (v->
Next() !=
nullptr) v = v->
Next();
625 for (
int i = 0; i != n && v !=
nullptr; i--) v = v->
Previous();
627 for (
int i = 0; i != n && v !=
nullptr; i++) v = v->
Next();
641 for (
int i = 0; i != n && v !=
nullptr; i--) v = v->
Previous();
643 for (
int i = 0; i != n && v !=
nullptr; i++) v = v->
Next();
652 inline Order *
GetFirstOrder()
const {
return (this->orders.list ==
nullptr) ? nullptr : this->orders.list->GetFirstOrder(); }
654 void AddToShared(
Vehicle *shared_chain);
655 void RemoveFromShared();
673 inline Vehicle *
FirstShared()
const {
return (this->orders.list ==
nullptr) ? this->First() : this->orders.list->GetFirstSharedVehicle(); }
679 inline bool IsOrderListShared()
const {
return this->orders.list !=
nullptr && this->orders.list->IsShared(); }
699 return (this->orders.list ==
nullptr) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(
this);
702 void ResetRefitCaps();
712 this->CopyConsistPropertiesFrom(src);
724 bool HandleBreakdown();
726 bool NeedsAutorenewing(
const Company *c,
bool use_renew_setting =
true)
const;
728 bool NeedsServicing()
const;
729 bool NeedsAutomaticServicing()
const;
750 virtual void SetDestTile(
TileIndex tile) { this->dest_tile = tile; }
754 void UpdateVisualEffect(
bool allow_power_change =
true);
755 void ShowVisualEffect()
const;
757 void UpdatePosition();
758 void UpdateViewport(
bool dirty);
759 void UpdatePositionAndViewport();
762 inline uint16 GetServiceInterval()
const {
return this->service_interval; }
764 inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
781 if (this->GetNumManualOrders() > 0) {
784 this->cur_real_order_index++;
785 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
786 }
while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
788 this->cur_real_order_index = 0;
800 if (this->cur_implicit_order_index == this->cur_real_order_index) {
802 this->SkipToNextRealOrderIndex();
805 assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
809 this->cur_implicit_order_index++;
810 if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
811 }
while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
824 if (this->cur_implicit_order_index == this->cur_real_order_index) {
826 this->IncrementImplicitOrderIndex();
829 this->SkipToNextRealOrderIndex();
840 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
842 if (this->GetNumManualOrders() > 0) {
844 while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
845 this->cur_real_order_index++;
846 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
849 this->cur_real_order_index = 0;
860 return (this->orders.list ==
nullptr) ? nullptr : this->orders.list->GetOrderAt(index);
869 return (this->orders.list ==
nullptr) ? nullptr : this->orders.list->GetLastOrder();
872 bool IsEngineCountable()
const;
873 bool HasEngineType()
const;
874 bool HasDepotOrder()
const;
875 void HandlePathfindingResult(
bool path_found);
901 return this->Next() !=
nullptr && this->Next()->IsArticulatedPart();
911 assert(this->HasArticulatedPart());
978 template <
class T, VehicleType Type>
989 this->sprite_seq.count = 1;
1080 static inline T *Get(
size_t index)
1089 static inline T *GetIfValid(
size_t index)
1091 return IsValidID(index) ? Get(index) :
nullptr;
1101 assert(v->
type == Type);
1112 assert(v->
type == Type);
1113 return (
const T *)v;
1128 if (update_delta) ((T *)
this)->T::UpdateDeltaXY();
1130 ((T *)
this)->T::GetImage(this->direction,
EIT_ON_MAP, &seq);
1131 if (force_update || this->sprite_seq != seq) {
1132 this->sprite_seq = seq;
All types related to tracks.
Owner
Enum for all companies/owners.
Cached often queried (NewGRF) values.
This bit will be set if the NewGRF var 41 currently stored is valid.
uint32 PaletteID
The number of the palette.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Vehicle is stopped by the player.
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint32 motion_counter
counter to occasionally play a vehicle sound.
Money value
Value of the vehicle.
uint16 capacity
Capacity the vehicle will have.
This bit will be set if the NewGRF var 40 currently stored is valid.
virtual void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Direction direction
facing
Non-existing type of vehicle.
Minimal stack that uses a pool to avoid pointers.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
Vehicle * hash_tile_next
NOSAVE: Next vehicle in the tile location hash.
Vehicle * GetFirstEnginePart()
Get the first part of an articulated engine.
Vehicle has finished loading.
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
static Titem * Get(size_t index)
Returns Titem with given index.
Whether the vehicle has started running on the timetable yet.
Vehicle ** hash_viewport_prev
NOSAVE: Previous vehicle in the visual location hash.
Simulated cargo type and capacity for prediction of future links.
byte breakdown_delay
Counter for managing breakdown length.
Use default vehicle palette.
Vehicle is a shadow vehicle.
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
Vehicle drawn in viewport.
Trackdir
Enumeration for tracks and directions.
uint16 cur_speed
current speed
uint16 cached_cargo_age_period
Number of ticks before carried cargo is aged.
uint16 cargo_age_counter
Ticks till cargo is aged next.
Types related to engines.
Base types related to transport.
Leading engine of a consist.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
VehStatus
Vehicle status bits in Vehicle::vehstatus.
VehicleType
Available vehicle types.
OrderList * list
Pointer to the order list for this vehicle.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Vehicle ** hash_tile_prev
NOSAVE: Previous vehicle in the tile location hash.
TileIndex dest_tile
Heading for this tile.
Implementation of simple mapping class.
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI...
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
This bit will be set if the NewGRF var 43 currently stored is valid.
Combination of a palette sprite and a 'real' sprite.
void Clear()
Clear all information.
bool LoadOldVehicle(LoadgameState *ls, int num)
Load the vehicles of an old style savegame.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Functions related to orders.
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Cached often queried values common to all vehicles.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
Vehicle is unloading cargo.
Engine that can be front engine, but might be placed behind another engine (not used for road vehicle...
StationID last_station_visited
The last station we stopped at.
uint16 reliability_spd_dec
Reliability decrease speed.
uint32 position_consist_length
Cache for NewGRF var 40.
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
Common return value for all commands.
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Wagon (not used for road vehicles).
EngineImageType
Visualisation contexts of vehicles and engines.
Cached, frequently calculated values.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Generates sequence of free UnitID numbers.
Vehicle * next_shared
pointer to the next vehicle that shares the order
Use default from engine class.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Vehicle * hash_viewport_next
NOSAVE: Next vehicle in the visual location hash.
Types related to commands.
int8 x_bb_offs
x offset of vehicle bounding box
DepotCommand
Flags to add to p1 for goto depot commands.
Money profit_last_year
Profit last year << 8, low 8 bits are fract.
bool _network_dedicated
are we a dedicated server?
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Simple mapping class targeted for small sets of data.
void SkipToNextRealOrderIndex()
Advance cur_real_order_index to the next real order.
Value of offset corresponding to a position above the centre of the vehicle.
Vehicle ** hash_tile_current
NOSAVE: Cache of the current hash chain.
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
int8 y_bb_offs
y offset of vehicle bounding box
byte breakdown_ctr
Counter for managing breakdown events.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
Base class for cargo packets.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
uint16 cargo_cap
total capacity
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Money GetDisplayRunningCost() const
Gets the running cost of a vehicle that can be sent into SetDParam for string processing.
Class defining several overloaded accessors so we don't have to cast vehicle types that often...
Vehicle is a prototype (accepted as exclusive preview).
byte acceleration
used by train & aircraft
First bit used for the type of effect.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
UnitID unitnumber
unit number, for display purposes only
byte cargo_subtype
Used for livery refits (NewGRF variations)
bool operator!=(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Inverse of operator==().
bool IsValid() const
Check whether the sequence contains any sprites.
uint16 remaining
Capacity remaining from before the previous refit.
virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
int8 y_offs
y offset for vehicle sprite
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
Mark all viewports that display an area as dirty (in need of repaint).
Don't load anymore during the next load cycle.
UnitID maxid
maximum ID at the moment of constructor call
const Vehicle * GetFirstEnginePart() const
Get the first part of an articulated engine.
DoCommandFlag
List of flags for a command.
VisualEffectSpawnModel
Models for spawning visual effects.
virtual ExpensesType GetExpenseType(bool income) const
Sets the expense type associated to this vehicle type.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
byte x_extent
x-extent of vehicle bounding box
Pool< Vehicle, VehicleID, 512, 0xFF000 > VehiclePool
A vehicle pool for a little over 1 million vehicles.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Direction
Defines the 8 directions on the map.
Flag for an invalid trackdir.
Vehicle * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
NewGRFCacheValidValues
Bit numbers used to indicate which of the NewGRFCache values are valid.
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
uint16 GroupID
Type for all group identifiers.
uint32 position_same_id_length
Cache for NewGRF var 41.
byte z_extent
z-extent of vehicle bounding box
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Service interval is custom.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
bool operator==(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Compare two MultiMap iterators.
CargoID cargo_type
type of cargo this vehicle is carrying
Whether the vehicle should fill in the timetable automatically.
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for vehicle of this type.
Order * old
Only used during conversion of old save games.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Properties for front vehicles/consists.
TileIndex tile
Current tile index.
This bit will be set if the NewGRF var 42 currently stored is valid.
virtual void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
const Vehicle * Last() const
Get the last vehicle of this vehicle chain.
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
Basic functions/variables used all over the place.
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
int8 x_offs
x offset for vehicle sprite
Owner owner
Which company owns the vehicle?
Sprite sequence for a vehicle part.
Helper class to perform the cargo payment.
Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn't exists.
uint16 refit_cap
Capacity left over from before last refit.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
uint16 reliability
Reliability.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Vehicle's pathfinder is lost.
byte tick_counter
Increased by one for each tick.
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
UnitID curid
last ID returned; 0 if none
Base class for all PoolItems.
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=nullptr, bool *mirrored=nullptr)
Determines the next articulated part to attach.
Year build_year
Year the vehicle has been built.
Engine is multiheaded (not used for road vehicles).
Base class for all pools.
virtual Money GetRunningCost() const
Gets the running cost of a vehicle.
~FreeUnitIDGenerator()
Releases allocated memory.
byte breakdown_chance
Current chance of breakdowns.
This bit will be set if the NewGRF var 4D currently stored is valid.
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
Flag to disable visual effect.
uint32 company_information
Cache for NewGRF var 43.
Vehicle * GetPrevVehicle() const
Get the previous real (non-articulated part) vehicle in the consist.
Articulated part of an engine.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
byte subspeed
fractional speed
CargoList that is used for vehicles.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Vehicle * GetLastEnginePart()
Get the last part of an articulated engine.
uint16 EngineID
Unique identification number of an engine.
Number of bits used for the effect type.
uint32 TileIndex
The index/ID of a Tile.
VehiclePool _vehicle_pool
The pool with all our precious vehicles.
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Vehicle * Next() const
Get the next vehicle of this vehicle.
Date date_of_last_service
Last date the vehicle had a service at a depot.
CargoPayment * cargo_payment
The cargo payment we're currently in.
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
CargoID cargo
Cargo type the vehicle will be carrying.
uint32 consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
void FixOldVehicles()
Convert the old style vehicles into something that resembles the old new style savegames.
uint32 position_in_vehicle
Cache for NewGRF var 4D.
StationIDStack GetNextStoppingStation() const
Get the next station the vehicle will stop at.
Vehicle * GetNextArticulatedPart() const
Get the next part of an articulated engine.
SpecializedVehicle< T, Type > SpecializedVehicleBase
Our type.
GroundVehicleSubtypeFlags
Enum to handle ground vehicle subtypes.
VehicleType type
Type of vehicle.
Vehicle * next
pointer to the next vehicle in the chain
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
First in a wagon chain (in depot) (not used for road vehicles).
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
void CopyVehicleConfigAndStatistics(const Vehicle *src)
Copy certain configurations and statistics of a vehicle after successful autoreplace/renew The functi...
virtual void OnNewDay()
Calls the new day handler of the vehicle.
Default value to indicate that visual effect should be based on engine class.
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
uint16 UnitID
Type for the company global vehicle unit number.
bool * cache
array of occupied unit id numbers
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
static Pool::IterateWrapper< T > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
int32 Date
The type to store our dates in.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
byte running_ticks
Number of ticks this vehicle was not stopped this day.
virtual Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
byte y_extent
y-extent of vehicle bounding box
Flag to disable wagon power.
EngineID engine_type
The type of engine used for this vehicle.
byte cached_vis_effect
Visual effect to show (see VisualEffect)
virtual void PlayLeaveStationSound() const
Play the sound associated with leaving the station.
virtual bool Tick()
Calls the tick handler of the vehicle.
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const Vehicle * Move(int n) const
Get the vehicle at offset n of this vehicle chain.
uint8 cache_valid
Bitset that indicates which cache values are valid.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Whether non-destructive auto-fill should preserve waiting times.
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
virtual int GetDisplaySpeed() const
Gets the speed in km-ish/h that can be sent into SetDParam for string processing. ...
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Flag for advanced effects.
Vehicle * Last()
Get the last vehicle of this vehicle chain.
VehicleFlags
Bit numbers in Vehicle::vehicle_flags.
Functions related to text effects.
SpriteID sprite
The 'real' sprite.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
VehicleCache vcache
Cache of often used vehicle values.
Number of bits used for the offset.
VisualEffect
Meaning of the various bits of the visual effect.
Rect coord
NOSAVE: Graphical bounding box of the vehicle, i.e. what to redraw on moves.
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
ExpensesType
Types of expenses.
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
uint GetOldAdvanceSpeed(uint speed)
Determines the effective direction-specific vehicle movement speed.
byte day_counter
Increased by one for each day.
Order current_order
The current order (+ status, like: loading)
GroupID group_id
Index of group Pool array.
Vehicle is not clickable by the user (shadow vehicles).
SpriteID colourmap
NOSAVE: cached colour mapping.
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Service interval is percent.
Dynamic data of a loaded NewGRF.
PaletteID pal
The palette (use PAL_NONE) if not needed)