12 #ifndef VEHICLE_BASE_H 13 #define VEHICLE_BASE_H 136 return this->count == other.count && MemCmpT<PalSpriteID>(this->seq, other.seq, this->count) == 0;
149 return this->count != 0;
166 this->seq[0].
sprite = sprite;
167 this->seq[0].
pal = 0;
175 this->count = src.count;
176 for (uint i = 0; i < src.count; ++i) {
178 this->seq[i].
pal = 0;
182 void GetBounds(
Rect *bounds)
const;
183 void Draw(
int x,
int y,
PaletteID default_pal,
bool force_pal)
const;
208 cargo(cargo), capacity(capacity), remaining(remaining) {}
214 typedef std::list<RefitDesc> RefitList;
215 typedef std::map<CargoID, uint> CapacitiesMap;
334 void PreDestructor();
339 void CancelReservation(StationID next,
Station *st);
345 uint16 &GetGroundVehicleFlags();
346 const uint16 &GetGroundVehicleFlags()
const;
348 void DeleteUnreachedImplicitOrders();
350 void HandleLoading(
bool mode =
false);
354 uint GetConsistTotalCapacity()
const;
388 return (this->direction & 1) ? speed : speed * 3 / 4;
405 return speed * 3 / 4;
417 return (this->direction & 1) ? 192 : 256;
436 const Engine *GetEngine()
const;
446 uint32 GetGRFID()
const;
463 for (
Vehicle *u =
this; u != NULL; u = u->
Next()) {
464 u->InvalidateNewGRFCache();
519 assert(
this == this->First());
521 if (this->IsPrimaryVehicle() && !(this->vehstatus &
VS_STOPPED))
return false;
522 return this->IsChainInDepot();
529 virtual bool Tick() {
return true; };
541 virtual uint Crash(
bool flooded =
false);
604 while (v->
Next() != NULL) v = v->
Next();
615 while (v->
Next() != NULL) v = v->
Next();
628 for (
int i = 0; i != n && v != NULL; i--) v = v->
Previous();
630 for (
int i = 0; i != n && v != NULL; i++) v = v->
Next();
644 for (
int i = 0; i != n && v != NULL; i--) v = v->
Previous();
646 for (
int i = 0; i != n && v != NULL; i++) v = v->
Next();
655 inline Order *
GetFirstOrder()
const {
return (this->orders.list == NULL) ? NULL : this->orders.list->GetFirstOrder(); }
657 void AddToShared(
Vehicle *shared_chain);
658 void RemoveFromShared();
676 inline Vehicle *
FirstShared()
const {
return (this->orders.list == NULL) ? this->First() : this->orders.list->GetFirstSharedVehicle(); }
682 inline bool IsOrderListShared()
const {
return this->orders.list != NULL && this->orders.list->IsShared(); }
702 return (this->orders.list == NULL) ? INVALID_STATION : this->orders.list->GetNextStoppingStation(
this);
705 void ResetRefitCaps();
715 this->CopyConsistPropertiesFrom(src);
727 bool HandleBreakdown();
729 bool NeedsAutorenewing(
const Company *c,
bool use_renew_setting =
true)
const;
731 bool NeedsServicing()
const;
732 bool NeedsAutomaticServicing()
const;
755 void UpdateVisualEffect(
bool allow_power_change =
true);
756 void ShowVisualEffect()
const;
758 void UpdatePosition();
759 void UpdateViewport(
bool dirty);
760 void UpdatePositionAndViewport();
763 inline uint16 GetServiceInterval()
const {
return this->service_interval; }
765 inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
782 if (this->GetNumManualOrders() > 0) {
785 this->cur_real_order_index++;
786 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
787 }
while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT));
789 this->cur_real_order_index = 0;
801 if (this->cur_implicit_order_index == this->cur_real_order_index) {
803 this->SkipToNextRealOrderIndex();
806 assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders());
810 this->cur_implicit_order_index++;
811 if (this->cur_implicit_order_index >= this->GetNumOrders()) this->cur_implicit_order_index = 0;
812 }
while (this->cur_implicit_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_implicit_order_index)->IsType(OT_IMPLICIT));
825 if (this->cur_implicit_order_index == this->cur_real_order_index) {
827 this->IncrementImplicitOrderIndex();
830 this->SkipToNextRealOrderIndex();
841 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
843 if (this->GetNumManualOrders() > 0) {
845 while (this->GetOrder(this->cur_real_order_index)->IsType(OT_IMPLICIT)) {
846 this->cur_real_order_index++;
847 if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0;
850 this->cur_real_order_index = 0;
861 return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index);
870 return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
873 bool IsEngineCountable()
const;
874 bool HasEngineType()
const;
875 bool HasDepotOrder()
const;
876 void HandlePathfindingResult(
bool path_found);
902 return this->Next() != NULL && this->Next()->IsArticulatedPart();
912 assert(this->HasArticulatedPart());
980 #define FOR_ALL_VEHICLES_FROM(var, start) FOR_ALL_ITEMS_FROM(Vehicle, vehicle_index, var, start) 986 #define FOR_ALL_VEHICLES(var) FOR_ALL_VEHICLES_FROM(var, 0) 992 template <
class T, VehicleType Type>
1003 this->sprite_seq.count = 1;
1094 static inline T *Get(
size_t index)
1103 static inline T *GetIfValid(
size_t index)
1105 return IsValidID(index) ? Get(index) : NULL;
1115 assert(v->
type == Type);
1126 assert(v->
type == Type);
1127 return (
const T *)v;
1142 if (update_delta) ((T *)
this)->T::UpdateDeltaXY(this->direction);
1144 ((T *)
this)->T::GetImage(this->direction,
EIT_ON_MAP, &seq);
1145 if (force_update || this->sprite_seq != seq) {
1146 this->sprite_seq = seq;
1157 #define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE) All types related to tracks.
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.
Minimal stack that uses a pool to avoid pointers.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
DirectionByte direction
facing
Non-existing type of vehicle.
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.
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.
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.
Direction
Defines the 8 directions on the map.
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 #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
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
VehicleType
Available vehicle types.
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) ...
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
Trackdir
Enumeration for tracks and directions.
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.
ExpensesType
Types of expenses.
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
Sprite sequence for a vehicle part.
Helper class to perform the cargo payment.
Order * GetLastOrder() const
Returns the last order of a vehicle, or NULL 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.
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).
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front=NULL, bool *mirrored=NULL)
Determines the next articulated part to attach.
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.
OwnerByte owner
Which company owns the vehicle?
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.
virtual void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this 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-NULL) 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 NULL when it doesn't exists.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
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.
Owner
Enum for all companies/owners.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
Flag for advanced effects.
Flag for an invalid trackdir.
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.
VehicleTypeByte type
Type of vehicle.
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)