44 e->overrides =
ReallocT(e->overrides, e->overrides_count);
46 wo = &e->overrides[e->overrides_count - 1];
50 wo->train_id = MallocT<EngineID>(trains);
51 memcpy(wo->train_id, train_id, trains *
sizeof *train_id);
58 for (uint i = 0; i < e->overrides_count; i++) {
61 if (wo->cargo != cargo && wo->cargo != CT_DEFAULT)
continue;
63 for (uint j = 0; j < wo->trains; j++) {
64 if (wo->train_id[j] == overriding_engine)
return wo->group;
75 for (uint i = 0; i < e->overrides_count; i++) {
80 e->overrides_count = 0;
81 e->overrides =
nullptr;
91 grfmsg(6,
"SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
110 static int MapOldSubType(
const Vehicle *v)
122 default: NOT_REACHED();
128 enum TTDPAircraftMovementStates {
134 AMS_TTDP_TO_ENTRY_2_AND_3,
135 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
136 AMS_TTDP_TO_JUNCTION,
137 AMS_TTDP_LEAVE_RUNWAY,
145 AMS_TTDP_FLIGHT_APPROACH,
146 AMS_TTDP_UNUSED_0x11,
147 AMS_TTDP_FLIGHT_TO_TOWER,
148 AMS_TTDP_UNUSED_0x13,
149 AMS_TTDP_FLIGHT_FINAL,
150 AMS_TTDP_FLIGHT_DESCENT,
152 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
153 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
154 AMS_TTDP_HELI_LAND_AIRPORT,
155 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
156 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
157 AMS_TTDP_HELI_LAND_HELIPORT,
168 if (st ==
nullptr)
return AMS_TTDP_FLIGHT_TO_TOWER;
185 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
192 return AMS_TTDP_TO_HANGAR;
195 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD1;
196 return AMS_TTDP_TO_JUNCTION;
199 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD2;
200 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
209 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD3;
210 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
216 if (amdflag & AMED_HELI_LOWER)
return AMS_TTDP_HELI_LAND_AIRPORT;
217 if (amdflag & AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
218 return AMS_TTDP_TO_JUNCTION;
221 return AMS_TTDP_TO_OUTWAY;
224 return AMS_TTDP_TAKEOFF;
227 return AMS_TTDP_CLIMBING;
232 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
234 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
238 return amdflag &
AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
241 return AMS_TTDP_FLIGHT_DESCENT;
244 if (amdflag &
AMED_BRAKE)
return AMS_TTDP_BRAKING;
246 return AMS_TTDP_TO_INWAY;
250 if (amdflag & AMED_HELI_LOWER) {
252 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
254 return AMS_TTDP_FLIGHT_TO_TOWER;
258 return AMS_TTDP_HANGAR;
264 enum TTDPAircraftMovementActions {
269 AMA_TTDP_HANGAR_TO_PAD1,
270 AMA_TTDP_HANGAR_TO_PAD2,
271 AMA_TTDP_HANGAR_TO_PAD3,
272 AMA_TTDP_LANDING_TO_PAD1,
273 AMA_TTDP_LANDING_TO_PAD2,
274 AMA_TTDP_LANDING_TO_PAD3,
275 AMA_TTDP_PAD1_TO_HANGAR,
276 AMA_TTDP_PAD2_TO_HANGAR,
277 AMA_TTDP_PAD3_TO_HANGAR,
278 AMA_TTDP_PAD1_TO_TAKEOFF,
279 AMA_TTDP_PAD2_TO_TAKEOFF,
280 AMA_TTDP_PAD3_TO_TAKEOFF,
281 AMA_TTDP_HANGAR_TO_TAKOFF,
282 AMA_TTDP_LANDING_TO_HANGAR,
296 return (v->
cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
300 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
304 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
313 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
320 return AMA_TTDP_PAD1_TO_TAKEOFF;
323 return AMA_TTDP_IN_FLIGHT;
331 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
334 return AMA_TTDP_IN_HANGAR;
341 return this->v ==
nullptr ? 0 : this->v->
random_bits;
356 int32 count =
GB(relative, 0, 4);
357 if (this->self_scope.v !=
nullptr && (relative != this->cached_relative_count || count == 0)) {
363 switch (
GB(relative, 6, 2)) {
364 default: NOT_REACHED();
366 v = this->self_scope.v;
369 v = this->self_scope.v;
373 v = this->parent_scope.v;
376 const Vehicle *
self = this->self_scope.v;
378 if (u->engine_type != self->engine_type) {
381 if (v ==
nullptr) v = u;
384 if (v ==
nullptr) v =
self;
388 this->relative_scope.SetVehicle(v->
Move(count));
390 return &this->relative_scope;
431 byte chain_before = 0;
432 byte chain_after = 0;
434 for (u = v->
First(); u != v; u = u->
Next()) {
444 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
471 byte cargo_classes = 0;
473 uint8 common_subtypes[256];
474 byte user_def_data = 0;
476 uint8 common_subtype = 0xFF;
479 memset(common_cargoes, 0,
sizeof(common_cargoes));
480 memset(common_subtypes, 0,
sizeof(common_subtypes));
482 for (u = v; u !=
nullptr; u = u->
Next()) {
493 uint common_cargo_best_amount = 0;
495 if (common_cargoes[cargo] > common_cargo_best_amount) {
496 common_cargo_best_amount = common_cargoes[cargo];
497 common_cargo_type = cargo;
502 for (u = v; u !=
nullptr; u = u->
Next()) {
510 uint common_subtype_best_amount = 0;
511 for (uint i = 0; i <
lengthof(common_subtypes); i++) {
512 if (common_subtypes[i] > common_subtype_best_amount) {
513 common_subtype_best_amount = common_subtypes[i];
535 const GRFFile *grffile =
object->ro.grffile;
536 uint8 common_bitnum = (common_cargo_type ==
CT_INVALID) ? 0xFF :
563 return (
Clamp(altitude, 0, 0xFF) << 8) | airporttype;
633 byte artic_before = 0;
635 byte artic_after = 0;
648 for (; v !=
nullptr; v = v->
Next()) {
665 if (u ==
nullptr)
return 0;
667 if (parameter == 0x5F) {
671 return VehicleGetVariable(u,
object, parameter,
GetRegister(0x10E), available);
688 if (u ==
nullptr)
return 0;
691 bool prev = (int8)parameter < 0;
712 const Train *u = is_powered_wagon ? t->
First() : t;
714 bool powered = t->
IsEngine() || is_powered_wagon;
717 if (powered && has_power)
SetBit(modflags, 5);
718 if (powered && !has_power)
SetBit(modflags, 6);
724 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
729 switch (variable - 0x80) {
730 case 0x00:
return v->
type + 0x10;
731 case 0x01:
return MapOldSubType(v);
732 case 0x04:
return v->
index;
733 case 0x05:
return GB(v->
index, 8, 8);
747 default: ticks = 0;
break;
750 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
754 case 0x14:
return v->GetServiceInterval();
755 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
770 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
772 case 0x1A:
return v->
x_pos;
773 case 0x1B:
return GB(v->
x_pos, 8, 8);
774 case 0x1C:
return v->
y_pos;
775 case 0x1D:
return GB(v->
y_pos, 8, 8);
776 case 0x1E:
return v->
z_pos;
836 switch (variable - 0x80) {
837 case 0x62:
return t->track;
838 case 0x66:
return t->railtype;
853 switch (variable - 0x80) {
854 case 0x62:
return rv->
state;
855 case 0x64:
return rv->blocked_ctr;
856 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
867 switch (variable - 0x80) {
868 case 0x62:
return s->
state;
875 switch (variable - 0x80) {
886 DEBUG(grf, 1,
"Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->
type);
894 if (this->v ==
nullptr) {
904 return (cs->
classes << 16) | (cs->
weight << 8) | this->ro.grffile->cargo_map[cargo_type];
909 case 0x48:
return Engine::Get(this->self_type)->flags;
911 case 0x4B:
return _date;
923 return VehicleGetVariable(const_cast<Vehicle*>(this->v),
this, variable, parameter, available);
929 const Vehicle *v = this->self_scope.v;
941 if (totalsets == 0)
return nullptr;
944 set =
min(
set, totalsets - 1);
957 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
971 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
973 self_scope(*this, engine_type, v, info_view),
974 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
975 relative_scope(*this, engine_type, v, info_view),
976 cached_relative_count(0)
978 if (wagon_override ==
WO_SELF) {
979 this->
root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1011 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1012 for (uint stack = 0; stack < max_stack; ++stack) {
1013 object.ResetState();
1014 object.callback_param1 = image_type | (stack << 8);
1016 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1017 if (group !=
nullptr && group->GetNumResults() != 0) {
1018 result->seq[result->count].
sprite = group->GetResult() + (direction % group->GetNumResults());
1019 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1022 if (!
HasBit(reg100, 31))
break;
1037 uint rotor_pos = v ==
nullptr || info_view ? 0 : v->
Next()->
Next()->
state;
1040 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1041 for (uint stack = 0; stack < max_stack; ++stack) {
1042 object.ResetState();
1043 object.callback_param1 = image_type | (stack << 8);
1045 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1046 if (group !=
nullptr && group->GetNumResults() != 0) {
1047 result->seq[result->count].
sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1048 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1051 if (!
HasBit(reg100, 31))
break;
1064 return Train::From(v)->tcache.cached_override !=
nullptr;
1079 return object.ResolveCallback();
1095 object.parent_scope.SetVehicle(parent);
1096 return object.ResolveCallback();
1103 return GetEngineProperty(v->
engine_type, property, orig_value, v);
1116 static void DoTriggerVehicle(
Vehicle *v, VehicleTrigger trigger, byte base_random_bits,
bool first)
1119 assert(v !=
nullptr);
1126 if (group ==
nullptr)
return;
1132 byte new_random_bits = Random();
1133 uint32
reseed =
object.GetReseedSum();
1135 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1138 case VEHICLE_TRIGGER_NEW_CARGO:
1147 DoTriggerVehicle(v->
First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits,
false);
1150 case VEHICLE_TRIGGER_DEPOT:
1154 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, 0,
true);
1157 case VEHICLE_TRIGGER_EMPTY:
1162 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1165 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1169 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits,
false);
1172 case VEHICLE_TRIGGER_CALLBACK_32:
1178 void TriggerVehicle(
Vehicle *v, VehicleTrigger trigger)
1180 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1186 DoTriggerVehicle(v, trigger, 0,
true);
1197 static std::vector<ListOrderChange> _list_order_changes;
1208 _list_order_changes.push_back({engine, target});
1238 std::vector<EngineID> ordering;
1240 ordering.push_back(e->index);
1247 uint local_target = it.target;
1250 if (id_source->
internal_id == local_target)
continue;
1255 int source_index =
find_index(ordering, source);
1256 int target_index =
find_index(ordering, target);
1258 assert(source_index >= 0 && target_index >= 0);
1259 assert(source_index != target_index);
1262 if (source_index < target_index) {
1264 for (
int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1265 list[target_index] = source;
1267 for (
int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1268 list[target_index] = source;
1274 for (
const EngineID &eid : ordering) {
1280 _list_order_changes.clear();
1281 _list_order_changes.shrink_to_fit();
1293 static const int cache_entries[][2] = {
1303 for (
size_t i = 0; i <
lengthof(cache_entries); i++) {
StationID Source() const
Returns source of the first cargo packet in this list.
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
This bit will be set if the NewGRF var 41 currently stored is valid.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
Airplane wants to leave the airport.
VehicleCargoList cargo
The cargo this vehicle is carrying.
Resolver for a vehicle scope.
Definition of stuff that is very close to a company, like the company struct itself.
uint32 motion_counter
counter to occasionally play a vehicle sound.
Money value
Value of the vehicle.
Airplane has reached end-point of the take-off runway.
NewGRF handling of rail types.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Finite sTate mAchine (FTA) of an airport.
This bit will be set if the NewGRF var 40 currently stored is valid.
Direction direction
facing
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
StationID targetairport
Airport to go to next.
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
void UnloadWagonOverrides(Engine *e)
Unload all wagon override sprite groups.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
uint32 grfid
The GRF ID of the file the entity belongs to.
ResolverObject & ro
Surrounding resolver object.
uint32 GetTriggers() const override
Get the triggers.
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'.
static const GRFFile * GetEngineGrfFile(EngineID engine_type)
Get the grf file associated with an engine type.
static Titem * Get(size_t index)
Returns Titem with given index.
bool CanCarryCargo() const
Determines whether an engine can carry something.
Functions related to dates.
uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
Conventional Take Off and Landing, i.e. planes.
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
byte breakdown_delay
Counter for managing breakdown length.
Base for the train class.
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Called to spawn visual effects for vehicles.
byte pos
Next desired position of the aircraft.
uint16 cur_speed
current speed
Interface for SpriteGroup-s to access the gamestate.
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
Maximal number of cargo types in a game.
static byte MapAircraftMovementState(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2) ...
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Both directions faces to the same direction.
Specification of a cargo type.
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
uint16 wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
Functions related to vehicles.
Aircraft, helicopters, rotors and their shadows belong to this class.
This bit will be set if the NewGRF var 43 currently stored is valid.
Called when the company (or AI) tries to start or stop a vehicle.
const Livery * GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
Determines the livery for a vehicle.
void Clear()
Clear all information.
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
Set when using the callback resolve system, but not to resolve a callback.
Tindex index
Index of this pool item.
Vehicle is flying in the air.
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
T * First() const
Get the first vehicle in the chain.
Vehicle is unloading cargo.
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
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.
byte user_def_data
Cached property 0x25. Can be set by Callback 0x36.
Determine whether a wagon can be attached to an already existing train.
Relative position (vehicles only)
byte num_loaded
Number of loaded groups.
uint32 cached_power
Total power of the consist (valid only for the first engine).
uint32 reseed[VSG_END]
Collects bits to rerandomise while triggering triggers.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
RoadType
The different roadtypes we support.
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
uint16 classes
Classes of this cargo type.
EngineImageType
Visualisation contexts of vehicles and engines.
byte flags
Flags of the engine.
Year _cur_year
Current year, starting at 0.
Helicopter wants to land.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
uint32 GetRandomBits() const override
Get a few random bits.
byte overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
Go exactly to the destination coordinates.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Holding pattern movement (above the airport).
Pseudo random number generator.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
byte breakdown_ctr
Counter for managing breakdown events.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
Buses, trucks and trams belong to this class.
uint16 cargo_cap
total capacity
Vehicle is a prototype (accepted as exclusive preview).
Turn slowly (mostly used in the air).
byte acceleration
used by train & aircraft
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Resolve no wagon overrides.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
uint16 internal_id
The internal ID within the GRF file.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
UnitID unitnumber
unit number, for display purposes only
const SpriteGroup ** loaded
List of loaded groups (can be SpriteIDs or Callback results)
byte cargo_subtype
Used for livery refits (NewGRF variations)
byte subtype
Type of aircraft.
static byte MapAircraftMovementAction(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This...
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
bool IsType(OrderType type) const
Check whether this order is of the given type.
Called to modify various vehicle properties.
Resolver for a vehicle (chain)
T * Next() const
Get next vehicle in the chain.
Draw vehicle by stacking multiple sprites.
Definition of base types and functions in a cross-platform compatible way.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
A number of safeguards to prevent using unsafe methods.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
Direction
Defines the 8 directions on the map.
void VehicleEnteredDepotThisTick(Vehicle *v)
Adds a vehicle to the list of vehicles that visited a depot this tick.
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
DirDiff
Enumeration for the difference between two directions.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
uint32 position_same_id_length
Cache for NewGRF var 41.
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
CargoID cargo_type
type of cargo this vehicle is carrying
Information about a particular livery.
NewGRF handling of road types.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type...
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
static const byte LIT_ALL
Show the liveries of all companies.
byte misc_flags
Miscellaneous flags.
TileIndex tile
Current tile index.
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view=false, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Resolver of a vehicle (chain).
This bit will be set if the NewGRF var 42 currently stored is valid.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
const SpriteGroup ** loading
List of loading groups (can be SpriteIDs or Callback results)
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Owner owner
Which company owns the vehicle?
Sprite sequence for a vehicle part.
static bool EnginePreSort(const EngineID &a, const EngineID &b)
Comparator function to sort engines via scope-GRFID and local ID.
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
Airplane has arrived at a runway for take-off.
#define lengthof(x)
Return the length of an fixed size array.
const AirportMovingData * MovingData(byte position) const
Get movement data at a position.
static T min(const T a, const T b)
Returns the minimum of two values.
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.
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
byte tick_counter
Increased by one for each tick.
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
All ships have this type.
Year build_year
Year the vehicle has been built.
byte state
State of the airport.
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
#define DEBUG(name, level,...)
Output a line of debugging information.
'Train' is either a loco or a wagon.
VehicleType type
The engine type.
TileIndex tile
The base tile of the area.
byte breakdown_chance
Current chance of breakdowns.
This bit will be set if the NewGRF var 4D currently stored is valid.
byte num_loading
Number of loading groups.
Effect vehicle type (smoke, explosions, sparks, bubbles)
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Functions related to companies.
uint32 company_information
Cache for NewGRF var 43.
Called for every vehicle every 32 days (not all on same date though).
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
TrackBits state
The "track" the ship is following.
RailType
Enumeration for all possible railtypes.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
DestinationID GetDestination() const
Gets the destination of this order.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
byte subspeed
fractional speed
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
uint16 EngineID
Unique identification number of an engine.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Cargo support for NewGRFs.
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.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
uint32 consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
Related object of the resolved one.
Resolve self-override (helicopter rotors and such).
uint32 position_in_vehicle
Cache for NewGRF var 4D.
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
CallbackID callback
Callback being resolved.
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.
uint32 GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Reverse the visible direction of the vehicle.
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
CompanyID _current_company
Company currently doing an action.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
uint16 local_id
id defined by the grf file for this entity
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
Airport airport
Tile area the airport covers.
static DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
Applies two differences together.
EngineID engine_type
The type of engine used for this vehicle.
const struct GRFFile * grffile
grf file that introduced this entity
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
CallbackID
List of implemented NewGRF callbacks.
Helicopter wants to finish landing.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Set when calling a randomizing trigger (almost undocumented).
uint8 cache_valid
Bitset that indicates which cache values are valid.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
uint16 flag
special flags when moving towards the destination.
byte CargoID
Cargo slots to indicate a cargo type within a game.
One direction is the opposite of the other one.
static uint32 PositionHelper(const Vehicle *v, bool consecutive)
Helper to get the position of a vehicle within a chain of vehicles.
SpriteID sprite
The 'real' sprite.
Base classes/functions for stations.
VehicleCache vcache
Cache of often used vehicle values.
Date _date
Current date in days (day counter)
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Airplane wants to finish landing.
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
byte day_counter
Increased by one for each day.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
byte delta_z
Z adjustment for helicopter pads.
Order current_order
The current order (+ status, like: loading)
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
GroundVehicleCache gcache
Cache of often calculated values.
byte overtaking_ctr
The length of the current overtake attempt.
Dynamic data of a loaded NewGRF.
Helicopter wants to leave the airport.
PaletteID pal
The palette (use PAL_NONE) if not needed)
void SetEngineGRF(EngineID engine, const GRFFile *file)
Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game...
Resolve wagon overrides using TrainCache::cached_override.