46 e->overrides =
ReallocT(e->overrides, e->overrides_count);
48 wo = &e->overrides[e->overrides_count - 1];
52 wo->train_id = MallocT<EngineID>(trains);
53 memcpy(wo->train_id, train_id, trains *
sizeof *train_id);
60 for (uint i = 0; i < e->overrides_count; i++) {
63 if (wo->cargo != cargo && wo->cargo != CT_DEFAULT)
continue;
65 for (uint j = 0; j < wo->trains; j++) {
66 if (wo->train_id[j] == overriding_engine)
return wo->group;
77 for (uint i = 0; i < e->overrides_count; i++) {
82 e->overrides_count = 0;
83 e->overrides =
nullptr;
93 grfmsg(6,
"SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
112 static int MapOldSubType(
const Vehicle *v)
124 default: NOT_REACHED();
130 enum TTDPAircraftMovementStates {
136 AMS_TTDP_TO_ENTRY_2_AND_3,
137 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
138 AMS_TTDP_TO_JUNCTION,
139 AMS_TTDP_LEAVE_RUNWAY,
147 AMS_TTDP_FLIGHT_APPROACH,
148 AMS_TTDP_UNUSED_0x11,
149 AMS_TTDP_FLIGHT_TO_TOWER,
150 AMS_TTDP_UNUSED_0x13,
151 AMS_TTDP_FLIGHT_FINAL,
152 AMS_TTDP_FLIGHT_DESCENT,
154 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
155 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
156 AMS_TTDP_HELI_LAND_AIRPORT,
157 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
158 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
159 AMS_TTDP_HELI_LAND_HELIPORT,
170 if (st ==
nullptr)
return AMS_TTDP_FLIGHT_TO_TOWER;
187 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
194 return AMS_TTDP_TO_HANGAR;
197 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD1;
198 return AMS_TTDP_TO_JUNCTION;
201 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD2;
202 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
211 if (amdflag & AMED_EXACTPOS)
return AMS_TTDP_TO_PAD3;
212 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
218 if (amdflag & AMED_HELI_LOWER)
return AMS_TTDP_HELI_LAND_AIRPORT;
219 if (amdflag & AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
220 return AMS_TTDP_TO_JUNCTION;
223 return AMS_TTDP_TO_OUTWAY;
226 return AMS_TTDP_TAKEOFF;
229 return AMS_TTDP_CLIMBING;
234 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
236 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
240 return amdflag &
AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
243 return AMS_TTDP_FLIGHT_DESCENT;
246 if (amdflag &
AMED_BRAKE)
return AMS_TTDP_BRAKING;
248 return AMS_TTDP_TO_INWAY;
252 if (amdflag & AMED_HELI_LOWER) {
254 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
256 return AMS_TTDP_FLIGHT_TO_TOWER;
260 return AMS_TTDP_HANGAR;
266 enum TTDPAircraftMovementActions {
271 AMA_TTDP_HANGAR_TO_PAD1,
272 AMA_TTDP_HANGAR_TO_PAD2,
273 AMA_TTDP_HANGAR_TO_PAD3,
274 AMA_TTDP_LANDING_TO_PAD1,
275 AMA_TTDP_LANDING_TO_PAD2,
276 AMA_TTDP_LANDING_TO_PAD3,
277 AMA_TTDP_PAD1_TO_HANGAR,
278 AMA_TTDP_PAD2_TO_HANGAR,
279 AMA_TTDP_PAD3_TO_HANGAR,
280 AMA_TTDP_PAD1_TO_TAKEOFF,
281 AMA_TTDP_PAD2_TO_TAKEOFF,
282 AMA_TTDP_PAD3_TO_TAKEOFF,
283 AMA_TTDP_HANGAR_TO_TAKOFF,
284 AMA_TTDP_LANDING_TO_HANGAR,
298 return (v->
cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
302 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
306 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
315 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
322 return AMA_TTDP_PAD1_TO_TAKEOFF;
325 return AMA_TTDP_IN_FLIGHT;
333 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
336 return AMA_TTDP_IN_HANGAR;
343 return this->v ==
nullptr ? 0 : this->v->
random_bits;
358 int32 count =
GB(relative, 0, 4);
359 if (this->self_scope.v !=
nullptr && (relative != this->cached_relative_count || count == 0)) {
365 switch (
GB(relative, 6, 2)) {
366 default: NOT_REACHED();
368 v = this->self_scope.v;
371 v = this->self_scope.v;
375 v = this->parent_scope.v;
378 const Vehicle *
self = this->self_scope.v;
380 if (u->engine_type != self->engine_type) {
383 if (v ==
nullptr) v = u;
386 if (v ==
nullptr) v =
self;
390 this->relative_scope.SetVehicle(v->
Move(count));
392 return &this->relative_scope;
433 byte chain_before = 0;
434 byte chain_after = 0;
436 for (u = v->
First(); u != v; u = u->
Next()) {
446 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
473 byte cargo_classes = 0;
475 uint8 common_subtypes[256];
476 byte user_def_data = 0;
478 uint8 common_subtype = 0xFF;
481 memset(common_cargoes, 0,
sizeof(common_cargoes));
482 memset(common_subtypes, 0,
sizeof(common_subtypes));
484 for (u = v; u !=
nullptr; u = u->
Next()) {
495 uint common_cargo_best_amount = 0;
497 if (common_cargoes[cargo] > common_cargo_best_amount) {
498 common_cargo_best_amount = common_cargoes[cargo];
499 common_cargo_type = cargo;
504 for (u = v; u !=
nullptr; u = u->
Next()) {
512 uint common_subtype_best_amount = 0;
513 for (uint i = 0; i <
lengthof(common_subtypes); i++) {
514 if (common_subtypes[i] > common_subtype_best_amount) {
515 common_subtype_best_amount = common_subtypes[i];
537 const GRFFile *grffile =
object->ro.grffile;
538 uint8 common_bitnum = (common_cargo_type ==
CT_INVALID) ? 0xFF :
565 return (
Clamp(altitude, 0, 0xFF) << 8) | airporttype;
635 byte artic_before = 0;
637 byte artic_after = 0;
650 for (; v !=
nullptr; v = v->
Next()) {
667 if (u ==
nullptr)
return 0;
669 if (parameter == 0x5F) {
673 return VehicleGetVariable(u,
object, parameter,
GetRegister(0x10E), available);
690 if (u ==
nullptr)
return 0;
693 bool prev = (int8)parameter < 0;
714 const Train *u = is_powered_wagon ? t->
First() : t;
716 bool powered = t->
IsEngine() || is_powered_wagon;
719 if (powered && has_power)
SetBit(modflags, 5);
720 if (powered && !has_power)
SetBit(modflags, 6);
726 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
731 switch (variable - 0x80) {
732 case 0x00:
return v->
type + 0x10;
733 case 0x01:
return MapOldSubType(v);
734 case 0x04:
return v->
index;
735 case 0x05:
return GB(v->
index, 8, 8);
749 default: ticks = 0;
break;
752 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
756 case 0x14:
return v->GetServiceInterval();
757 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
772 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
774 case 0x1A:
return v->
x_pos;
775 case 0x1B:
return GB(v->
x_pos, 8, 8);
776 case 0x1C:
return v->
y_pos;
777 case 0x1D:
return GB(v->
y_pos, 8, 8);
778 case 0x1E:
return v->
z_pos;
838 switch (variable - 0x80) {
839 case 0x62:
return t->track;
840 case 0x66:
return t->railtype;
855 switch (variable - 0x80) {
856 case 0x62:
return rv->
state;
857 case 0x64:
return rv->blocked_ctr;
858 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
869 switch (variable - 0x80) {
870 case 0x62:
return s->
state;
877 switch (variable - 0x80) {
888 DEBUG(grf, 1,
"Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->
type);
896 if (this->v ==
nullptr) {
906 return (cs->
classes << 16) | (cs->
weight << 8) | this->ro.grffile->cargo_map[cargo_type];
911 case 0x48:
return Engine::Get(this->self_type)->flags;
913 case 0x4B:
return _date;
925 return VehicleGetVariable(const_cast<Vehicle*>(this->v),
this, variable, parameter, available);
931 const Vehicle *v = this->self_scope.v;
943 if (totalsets == 0)
return nullptr;
946 set =
min(
set, totalsets - 1);
959 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
973 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
975 self_scope(*this, engine_type, v, info_view),
976 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
977 relative_scope(*this, engine_type, v, info_view),
978 cached_relative_count(0)
980 if (wagon_override ==
WO_SELF) {
981 this->
root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1013 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1014 for (uint stack = 0; stack < max_stack; ++stack) {
1015 object.ResetState();
1016 object.callback_param1 = image_type | (stack << 8);
1018 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1019 if (group !=
nullptr && group->GetNumResults() != 0) {
1020 result->seq[result->count].
sprite = group->GetResult() + (direction % group->GetNumResults());
1021 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1024 if (!
HasBit(reg100, 31))
break;
1039 uint rotor_pos = v ==
nullptr || info_view ? 0 : v->
Next()->
Next()->
state;
1042 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1043 for (uint stack = 0; stack < max_stack; ++stack) {
1044 object.ResetState();
1045 object.callback_param1 = image_type | (stack << 8);
1047 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1048 if (group !=
nullptr && group->GetNumResults() != 0) {
1049 result->seq[result->count].
sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1050 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1053 if (!
HasBit(reg100, 31))
break;
1066 return Train::From(v)->tcache.cached_override !=
nullptr;
1081 return object.ResolveCallback();
1097 object.parent_scope.SetVehicle(parent);
1098 return object.ResolveCallback();
1105 return GetEngineProperty(v->
engine_type, property, orig_value, v);
1118 static void DoTriggerVehicle(
Vehicle *v, VehicleTrigger trigger, byte base_random_bits,
bool first)
1121 assert(v !=
nullptr);
1128 if (group ==
nullptr)
return;
1134 byte new_random_bits = Random();
1135 uint32
reseed =
object.GetReseedSum();
1137 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1140 case VEHICLE_TRIGGER_NEW_CARGO:
1149 DoTriggerVehicle(v->
First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits,
false);
1152 case VEHICLE_TRIGGER_DEPOT:
1156 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, 0,
true);
1159 case VEHICLE_TRIGGER_EMPTY:
1164 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1167 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1171 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits,
false);
1174 case VEHICLE_TRIGGER_CALLBACK_32:
1180 void TriggerVehicle(
Vehicle *v, VehicleTrigger trigger)
1182 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1188 DoTriggerVehicle(v, trigger, 0,
true);
1199 static std::vector<ListOrderChange> _list_order_changes;
1210 _list_order_changes.push_back({engine, target});
1240 std::vector<EngineID> ordering;
1242 FOR_ALL_ENGINES(e) {
1243 ordering.push_back(e->
index);
1250 uint local_target = it.target;
1253 if (id_source->
internal_id == local_target)
continue;
1258 int source_index =
find_index(ordering, source);
1259 int target_index =
find_index(ordering, target);
1261 assert(source_index >= 0 && target_index >= 0);
1262 assert(source_index != target_index);
1265 if (source_index < target_index) {
1267 for (
int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1268 list[target_index] = source;
1270 for (
int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1271 list[target_index] = source;
1277 for (
const EngineID &eid : ordering) {
1283 _list_order_changes.clear();
1284 _list_order_changes.shrink_to_fit();
1296 static const int cache_entries[][2] = {
1306 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.
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.