12 #include "../stdafx.h" 13 #include "../vehicle_func.h" 15 #include "../roadveh.h" 17 #include "../aircraft.h" 18 #include "../station_base.h" 19 #include "../effectvehicle_base.h" 20 #include "../company_base.h" 21 #include "../company_func.h" 22 #include "../disaster_vehicle.h" 28 #include "../safeguards.h" 39 v->other_multiheaded_part = NULL;
60 if (u->other_multiheaded_part != NULL)
continue;
62 if (u->IsMultiheaded()) {
72 if (sequential_matching) {
91 if (stack_pos == 0)
break;
98 w->other_multiheaded_part = u;
99 u->other_multiheaded_part = w;
121 for (
Train *u = t; u != NULL; u = u->
Next()) {
125 switch (u->subtype) {
134 u->SetArticulatedPart();
144 if (rvi->railveh_type ==
RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
171 FOR_ALL_STATIONS(st) {
272 std::map<Order*, OrderList*> mapping;
328 FOR_ALL_ROADVEHICLES(rv) {
367 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
376 assert(v->
first != NULL);
494 for (done = 0; done < diff; done++) {
498 if (next != NULL && done < diff && u->IsFrontEngine()) {
508 int r = CountVehiclesInChain(u) - 1;
520 for (moved = 0; moved < diff + 1; moved++) {
525 r = CountVehiclesInChain(u) - 1;
529 u->force_proceed = old_tfp;
533 if (moved < diff + 1)
break;
561 static uint8 _cargo_days;
562 static uint16 _cargo_source;
563 static uint32 _cargo_source_xy;
564 static uint16 _cargo_count;
565 static uint16 _cargo_paid_for;
566 static Money _cargo_feeder_share;
567 static uint32 _cargo_loaded_at_xy;
577 static const SaveLoad _common_veh_desc[] = {
618 SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6),
688 SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, 51, 64),
712 static const SaveLoad _train_desc[] = {
733 static const SaveLoad _roadveh_desc[] = {
753 static const SaveLoad _ship_desc[] = {
763 static const SaveLoad _aircraft_desc[] = {
786 static const SaveLoad _special_desc[] = {
801 SLE_VAR(
Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
816 static const SaveLoad _disaster_desc[] = {
841 SLE_VAR(
Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
858 static const SaveLoad *
const _veh_descs[] = {
868 return _veh_descs[vt];
877 SlSetArrayIndex(v->
index);
908 CargoPacket *cp =
new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
931 static void Ptrs_VEHS()
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
VehicleSettings vehicle
options for vehicles
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Vehicle is stopped by the player.
bool TrainController(Train *v, Vehicle *nomove, bool reverse=true)
Move a vehicle chain one movement stop forwards.
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
VehicleCargoList cargo
The cargo this vehicle is carrying.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void Save_VEHS()
Will be called when the vehicles need to be saved.
void ClearEngine()
Clear engine status.
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
void AfterLoadVehicles(bool part_of_load)
Called after load to update coordinates.
void Load_VEHS()
Will be called when vehicles need to be loaded.
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
Aircraft is about to leave the hangar.
DirectionByte direction
facing
Non-existing type of vehicle.
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame...
void SetFrontEngine()
Set front engine state.
int TicksToLeaveDepot(const Train *v)
Compute number of ticks when next wagon will leave a depot.
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
static Titem * Get(size_t index)
Returns Titem with given index.
void CopyWithoutPalette(const VehicleSpriteSeq &src)
Copy data from another sprite sequence, while dropping all recolouring information.
TrainForceProceeding
Modes for ignoring signals.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
uint16 cur_speed
current speed
uint16 cargo_age_counter
Ticks till cargo is aged next.
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
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...
Aircraft, helicopters, rotors and their shadows belong to this class.
static RoadTypes RoadTypeToRoadTypes(RoadType rt)
Maps a RoadType to the corresponding RoadTypes value.
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Tindex index
Index of this pool item.
Vehicle is flying in the air.
virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
A special vehicle is one of the following:
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
StationID last_station_visited
The last station we stopped at.
void UpdateViewport(bool dirty)
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
#define SLE_WRITEBYTE(base, variable, value)
Translate values ingame to different values in the savegame and vv.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
void GetAircraftFlightLevelBounds(const Vehicle *v, int *min, int *max)
Get the 'flight level' bounds, in pixels from 'z_pos' 0 for a particular vehicle for normal flight si...
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
#define SLE_CONDLST(base, variable, type, from, to)
Storage of a list in some savegame versions.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
CompanySettings settings
settings specific for each company
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Vehicle * next_shared
pointer to the next vehicle that shares the order
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
VehicleSpriteSeq sprite_seq
Vehicle appearance.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
byte subtype
subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes) ...
TextEffectID fill_percent_te_id
a text-effect id to a loading indicator object
Buses, trucks and trams belong to this class.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
void UpdateCache()
Update the caches of this ship.
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
uint8 type
The type of order + non-stop flags.
UnitID unitnumber
unit number, for display purposes only
int y
x and y position of the vehicle after moving
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
static size_t GetPoolSize()
Returns first unused index.
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
VehicleDefaultSettings vehicle
default settings for vehicles
void MakeDummy()
Makes this order a Dummy order.
allow control codes in the strings
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
VehicleType
Available vehicle types.
bool IsType(OrderType type) const
Check whether this order is of the given type.
T * Next() const
Get next vehicle in the chain.
simple wagon, not motorized
Container for cargo from the same location and time.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
uint8 flags
Load/unload types, depot order/action types.
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
Effect vehicle type (smoke, explosions, sparks, bubbles)
static void CheckValidVehicles()
Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includ...
Load/save a reference to an order.
Order * old
Only used during conversion of old save games.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
void Initialize(Order *chain, Vehicle *v)
Recomputes everything.
TileIndex tile
Current tile index.
void ReverseTrainDirection(Train *v)
Turn a train around.
static Track GetRailDepotTrack(TileIndex t)
Returns the track of a depot, ignoring direction.
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
#define SL_MAX_VERSION
Highest possible savegame version.
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Order * first
First order of the order list.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
void ReverseTrainSwapVeh(Train *v, int l, int r)
Swap vehicles l and r in consist v, and reverse their direction.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
All ships have this type.
Load/save a reference to a vehicle.
Handlers and description of chunk.
Information about a rail vehicle.
byte state
State of the airport.
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
uint16 last_speed
The last speed we did display, so we only have to redraw when this changes.
'Train' is either a loco or a wagon.
#define SLE_END()
End marker of a struct/class save or load.
int8 trip_occupancy
NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing...
void UpdatePosition()
Update the position of the vehicle.
void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Set aircraft position.
Load/save a reference to a cargo packet.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
uint16 EngineID
Unique identification number of an engine.
Vehicle * Next() const
Get the next vehicle of this vehicle.
Position information of a vehicle after it moved.
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
bool servint_ispercent
service intervals are in percents
void Free()
'Free' the order
Disasters, like submarines, skyrangers and their shadows, belong to this class.
OwnerByte owner
Which company owns the vehicle?
indicates a combination of two locomotives
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
virtual void UpdateDeltaXY(Direction direction)
Updates the x and y offsets and the size of the sprite used for this vehicle.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Vehicle * previous_shared
NOSAVE: pointer to the previous vehicle in the shared order chain.
T * GetNextVehicle() const
Get the next real (non-articulated part) vehicle in the consist.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
void FixupTrainLengths()
Fixup old train spacing.
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Vehicle * previous
NOSAVE: pointer to the previous vehicle in the chain.
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircrafts.
Ignore next signal, after the signal ignore being stuck.
Valid changes when loading a savegame. (Everything that is not stored in the save.)
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
Airport airport
Tile area the airport covers.
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
EngineID engine_type
The type of engine used for this vehicle.
void UpdateOldAircraft()
need to be called to load aircraft from old version
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
void ClearMultiheaded()
Clear multiheaded engine property.
void SetArticulatedPart()
Set a vehicle to be an articulated part.
Load/save a reference to an orderlist.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Road vehicle is a tram/light rail vehicle.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
VehicleCache vcache
Cache of often used vehicle values.
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.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
VehicleTypeByte type
Type of vehicle.
Valid changes while vehicle is driving, and possibly changing tracks.
Order current_order
The current order (+ status, like: loading)
GroupID group_id
Index of group Pool array.
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
GroundVehicleCache gcache
Cache of often calculated values.
Last chunk in this array.
void ConvertOldMultiheadToNew()
Converts all trains to the new subtype format introduced in savegame 16.2 It also links multiheaded e...