10 #include "../stdafx.h" 11 #include "../vehicle_func.h" 13 #include "../roadveh.h" 15 #include "../aircraft.h" 16 #include "../station_base.h" 17 #include "../effectvehicle_base.h" 18 #include "../company_base.h" 19 #include "../company_func.h" 20 #include "../disaster_vehicle.h" 26 #include "../safeguards.h" 35 v->other_multiheaded_part =
nullptr;
39 if (v->IsFrontEngine() || v->IsFreeWagon()) {
53 bool sequential_matching = v->IsFrontEngine();
56 if (u->other_multiheaded_part !=
nullptr)
continue;
58 if (u->IsMultiheaded()) {
68 if (sequential_matching) {
87 if (stack_pos == 0)
break;
94 w->other_multiheaded_part = u;
95 u->other_multiheaded_part = w;
115 if (
HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
116 for (
Train *u = t; u !=
nullptr; u = u->
Next()) {
120 switch (u->subtype) {
129 u->SetArticulatedPart();
139 if (rvi->railveh_type ==
RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
166 st->airport.flags = 0;
172 if (a->IsNormalAircraft()) {
174 if ((a->vehstatus &
VS_STOPPED) && a->state == 0) {
182 a->cur_speed = a->vcache.cached_max_speed;
183 if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
185 a->current_order.MakeDummy();
193 if (a->subtype ==
AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
226 if (v->engine_type >= total_engines || v->type != v->GetEngine()->type) {
227 v->engine_type = first_engine[v->type];
244 if (v->Next() !=
nullptr) v->Next()->previous = v;
245 if (v->NextShared() !=
nullptr) v->NextShared()->previous_shared = v;
247 if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
249 if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine =
INVALID_ENGINE;
261 std::map<Order*, OrderList*> mapping;
264 if (v->orders.old !=
nullptr) {
266 if (mapping[v->orders.old] ==
nullptr) {
273 v->orders.list = mapping[v->orders.old] =
new OrderList(v->orders.old, v);
275 v->orders.list = mapping[v->orders.old];
278 v->AddToShared(v->orders.list->GetFirstSharedVehicle());
282 if (v->PreviousShared() ==
nullptr) {
283 v->orders.list->Initialize(v->orders.list->first, v);
292 if (v->Previous() ==
nullptr) {
293 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
303 if (v->First() != v || v->orders.list !=
nullptr || v->previous_shared !=
nullptr || v->next_shared ==
nullptr)
continue;
307 v->orders.list =
new OrderList(
nullptr, v);
309 u->orders.list = v->orders.list;
317 if (rv->subtype == 0) {
319 rv->SetFrontEngine();
320 }
else if (rv->subtype == 1) {
323 rv->SetArticulatedPart();
333 if (!v->IsPrimaryVehicle() && v->type !=
VEH_DISASTER) {
334 v->current_order.Free();
350 if (!v->IsPrimaryVehicle())
continue;
355 v->SetServiceIntervalIsCustom(v->GetServiceInterval() != interval);
363 s->rotation = s->direction;
367 if (s->rotation == s->direction)
continue;
372 s->rotation_x_pos = s->x_pos;
373 s->rotation_y_pos = s->y_pos;
381 assert(v->first !=
nullptr);
448 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_seq);
453 v->GetImage(v->direction,
EIT_ON_MAP, &v->sprite_seq);
474 v->UpdateViewport(
false);
500 for (done = 0; done < diff; done++) {
504 if (next !=
nullptr && done < diff && u->IsFrontEngine()) {
514 int r = CountVehiclesInChain(u) - 1;
526 for (moved = 0; moved < diff + 1; moved++) {
531 r = CountVehiclesInChain(u) - 1;
535 u->force_proceed = old_tfp;
539 if (moved < diff + 1)
break;
567 static uint8 _cargo_days;
568 static uint16 _cargo_source;
569 static uint32 _cargo_source_xy;
570 static uint16 _cargo_count;
571 static uint16 _cargo_paid_for;
572 static Money _cargo_feeder_share;
573 static uint32 _cargo_loaded_at_xy;
583 static const SaveLoad _common_veh_desc[] = {
718 static const SaveLoad _train_desc[] = {
739 static const SaveLoad _roadveh_desc[] = {
761 static const SaveLoad _ship_desc[] = {
773 static const SaveLoad _aircraft_desc[] = {
796 static const SaveLoad _special_desc[] = {
811 SLE_VAR(
Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
826 static const SaveLoad _disaster_desc[] = {
851 SLE_VAR(
Vehicle, sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32),
868 static const SaveLoad *
const _veh_descs[] = {
878 return _veh_descs[vt];
886 SlSetArrayIndex(v->
index);
917 CargoPacket *cp =
new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share);
940 static void Ptrs_VEHS()
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
VehicleSettings vehicle
options for vehicles
#define SLE_CONDDEQUE(base, variable, type, from, to)
Storage of a deque in some savegame versions.
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.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Non-existing type of vehicle.
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.
204 PR#7065 Add extra rotation stages for ships.
void ConnectMultiheadedTrains()
Link front and rear multiheaded engines to each other This is done when loading a savegame...
2.0 0.3.0 2.1 0.3.1, 0.3.2
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.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Vehicle drawn in viewport.
uint16 cur_speed
current speed
#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...
VehicleType
Available vehicle types.
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.
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.
A special vehicle is one of the following:
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
bool IsMultiheaded() const
Check if the vehicle is a multiheaded engine.
StationID last_station_visited
The last station we stopped at.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
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...
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.
CompanySettings settings
settings specific for each company
Ignore next signal, after the signal ignore being stuck.
Vehicle * next_shared
pointer to the next vehicle that shares the order
VehicleSpriteSeq sprite_seq
Vehicle appearance.
static const int32 INVALID_COORD
Sentinel for an invalid coordinate.
Buses, trucks and trams belong to this class.
RoadType roadtype
Roadtype of this vehicle.
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
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.
uint8 type
The type of order + non-stop flags.
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power ...
int y
x and y position of the vehicle after moving
Highest possible saveload version.
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
allow control codes in the strings
5.0 1429 5.1 1440 5.2 1525 0.3.6
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.
#define SLE_WRITEBYTE(base, variable)
Translate values ingame to different values in the savegame and vv.
TrainForceProceeding
Modes for ignoring signals.
uint8 flags
Load/unload types, depot order/action types.
static void CheckValidVehicles()
Check all vehicles to ensure their engine type is valid for the currently loaded NewGRFs (that includ...
211 PR#7261 Add path cache for road vehicles.
Load/save a reference to an order.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
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.
byte SlReadByte()
Wrapper for reading a byte from the buffer.
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.
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
#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.
Effect vehicle type (smoke, explosions, sparks, bubbles)
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 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.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
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.
bool servint_ispercent
service intervals are in percents
Disasters, like submarines, skyrangers and their shadows, belong to this class.
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.
VehicleType type
Type of vehicle.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
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() ...
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
void FixupTrainLengths()
Fixup old train spacing.
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Valid changes when loading a savegame. (Everything that is not stored in the save.)
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
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.
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.
203 PR#7072 Add path cache for ships
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
182 25115 FS#5492, r25259, r25296 Goal status
byte _age_cargo_skip_counter
Skip aging of cargo? Used before savegame version 162.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
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...
static Pool::IterateWrapper< Engine > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.