OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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;
196 return AMS_TTDP_TO_JUNCTION;
200 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
210 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
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;
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();
378 if (u->engine_type != self->engine_type) {
381 if (v ==
nullptr) v = u;
384 if (v ==
nullptr) v =
self;
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;
639 byte artic_before = 0;
641 byte artic_after = 0;
654 for (; v !=
nullptr; v = v->
Next()) {
671 if (u ==
nullptr)
return 0;
673 if (parameter == 0x5F) {
677 return VehicleGetVariable(u,
object, parameter,
GetRegister(0x10E), available);
694 if (u ==
nullptr)
return 0;
697 bool prev = (int8)parameter < 0;
724 if (tile_type == param_type)
return 0x0F;
734 if (tile_type == param_type)
return 0x0F;
738 default:
return 0x00;
748 const Train *u = is_powered_wagon ? t->
First() : t;
750 bool powered = t->
IsEngine() || is_powered_wagon;
753 if (powered && has_power)
SetBit(modflags, 5);
754 if (powered && !has_power)
SetBit(modflags, 6);
760 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
770 switch (variable - 0x80) {
771 case 0x00:
return v->
type + 0x10;
772 case 0x01:
return MapOldSubType(v);
775 case 0x04:
return v->
index;
776 case 0x05:
return GB(v->
index, 8, 8);
796 default: ticks = 0;
break;
799 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
803 case 0x14:
return v->GetServiceInterval();
804 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
819 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
821 case 0x1A:
return v->
x_pos;
822 case 0x1B:
return GB(v->
x_pos, 8, 8);
823 case 0x1C:
return v->
y_pos;
824 case 0x1D:
return GB(v->
y_pos, 8, 8);
825 case 0x1E:
return v->
z_pos;
932 switch (variable - 0x80) {
933 case 0x62:
return t->track;
934 case 0x66:
return t->railtype;
949 switch (variable - 0x80) {
950 case 0x62:
return rv->
state;
951 case 0x64:
return rv->blocked_ctr;
952 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
963 switch (variable - 0x80) {
964 case 0x62:
return s->
state;
971 switch (variable - 0x80) {
982 DEBUG(grf, 1,
"Unhandled vehicle variable 0x%X, type 0x%X", variable, (uint)v->
type);
990 if (this->v ==
nullptr) {
1007 case 0x4B:
return _date;
1012 case 0xF2:
return 0;
1019 return VehicleGetVariable(
const_cast<Vehicle*
>(this->v),
this, variable, parameter, available);
1037 if (totalsets == 0)
return nullptr;
1040 set = std::min(set, totalsets - 1);
1042 return in_motion ? group->
loaded[set] : group->
loading[set];
1049 case VEH_ROAD:
return GSF_ROADVEHICLES;
1069 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
1083 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
1085 self_scope(*this, engine_type, v, info_view),
1086 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
1087 relative_scope(*this, engine_type, v, info_view),
1088 cached_relative_count(0)
1090 if (wagon_override ==
WO_SELF) {
1091 this->
root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1123 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1124 for (uint stack = 0; stack < max_stack; ++stack) {
1125 object.ResetState();
1126 object.callback_param1 = image_type | (stack << 8);
1128 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1129 if (group !=
nullptr && group->GetNumResults() != 0) {
1130 result->seq[result->count].
sprite = group->GetResult() + (direction % group->GetNumResults());
1131 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1134 if (!
HasBit(reg100, 31))
break;
1149 uint rotor_pos = v ==
nullptr || info_view ? 0 : v->
Next()->
Next()->
state;
1152 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1153 for (uint stack = 0; stack < max_stack; ++stack) {
1154 object.ResetState();
1155 object.callback_param1 = image_type | (stack << 8);
1157 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1158 if (group !=
nullptr && group->GetNumResults() != 0) {
1159 result->seq[result->count].
sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1160 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1163 if (!
HasBit(reg100, 31))
break;
1176 return Train::From(v)->tcache.cached_override !=
nullptr;
1191 return object.ResolveCallback();
1207 object.parent_scope.SetVehicle(parent);
1208 return object.ResolveCallback();
1215 return GetEngineProperty(v->
engine_type, property, orig_value, v);
1228 static void DoTriggerVehicle(
Vehicle *v, VehicleTrigger trigger,
byte base_random_bits,
bool first)
1231 assert(v !=
nullptr);
1238 if (group ==
nullptr)
return;
1244 byte new_random_bits = Random();
1245 uint32 reseed =
object.GetReseedSum();
1247 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1250 case VEHICLE_TRIGGER_NEW_CARGO:
1259 DoTriggerVehicle(v->
First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits,
false);
1262 case VEHICLE_TRIGGER_DEPOT:
1266 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, 0,
true);
1269 case VEHICLE_TRIGGER_EMPTY:
1274 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1277 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1281 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits,
false);
1284 case VEHICLE_TRIGGER_CALLBACK_32:
1290 void TriggerVehicle(
Vehicle *v, VehicleTrigger trigger)
1292 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1298 DoTriggerVehicle(v, trigger, 0,
true);
1309 static std::vector<ListOrderChange> _list_order_changes;
1320 _list_order_changes.push_back({engine, target});
1350 std::vector<EngineID> ordering;
1352 ordering.push_back(e->
index);
1359 uint local_target = it.target;
1362 if (id_source->
internal_id == local_target)
continue;
1367 int source_index =
find_index(ordering, source);
1368 int target_index =
find_index(ordering, target);
1370 assert(source_index >= 0 && target_index >= 0);
1371 assert(source_index != target_index);
1374 if (source_index < target_index) {
1376 for (
int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1377 list[target_index] = source;
1379 for (
int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1380 list[target_index] = source;
1386 for (
const EngineID &eid : ordering) {
1392 _list_order_changes.clear();
1393 _list_order_changes.shrink_to_fit();
1405 static const int cache_entries[][2] = {
1415 for (
size_t i = 0; i <
lengthof(cache_entries); i++) {
byte overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
@ VEH_AIRCRAFT
Aircraft vehicle type.
RoadTypeFlags flags
Bit mask of road type flags.
Buses, trucks and trams belong to this class.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
@ VRF_TOGGLE_REVERSE
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
StationID targetairport
Airport to go to next.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
@ HELILANDING
Helicopter wants to land.
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
const Livery * GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting)
Determines the livery for a vehicle.
@ WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
const SpriteGroup ** loaded
List of loaded groups (can be SpriteIDs or Callback results)
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
bool IsType(OrderType type) const
Check whether this order is of the given type.
static Titem * Get(size_t index)
Returns Titem with given index.
Direction
Defines the 8 directions on the map.
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
uint32 grfid
The GRF ID of the file the entity belongs to.
uint32 GetRandomBits() const override
Get a few random bits.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Money value
Value of the vehicle.
byte subtype
Type of aircraft.
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
@ CBID_VEHICLE_START_STOP_CHECK
Called when the company (or AI) tries to start or stop a vehicle.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
Vehicle * Next() const
Get the next vehicle of this vehicle.
Year _cur_year
Current year, starting at 0.
T * Next() const
Get next vehicle in the chain.
@ HELIENDLANDING
Helicopter wants to finish landing.
@ DIRDIFF_SAME
Both directions faces to the same direction.
@ CBID_VEHICLE_MODIFY_PROPERTY
Called to modify various vehicle properties.
byte num_loaded
Number of loaded groups.
DestinationID GetDestination() const
Gets the destination of this order.
uint16 load_unload_ticks
Ticks to wait before starting next cycle.
void Clear()
Clear all information.
@ INVALID_ROADTYPE
flag for invalid roadtype
static DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
Applies two differences together.
uint32 position_same_id_length
Cache for NewGRF var 41.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
Tindex index
Index of this pool item.
@ VRF_POWEREDWAGON
Wagon is powered.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
byte acceleration
used by train & aircraft
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
SpriteID sprite
The 'real' sprite.
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Interface for SpriteGroup-s to access the gamestate.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ TERM1
Heading for terminal 1.
This struct contains all the info that is needed to draw and construct tracks.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
byte overtaking_ctr
The length of the current overtake attempt.
byte user_def_data
Cached property 0x25. Can be set by Callback 0x36.
uint8 cache_valid
Bitset that indicates which cache values are valid.
@ ENDLANDING
Airplane wants to finish landing.
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Specification of a cargo type.
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
uint8 GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
@ GSF_INVALID
An invalid spec feature.
CallbackID
List of implemented NewGRF callbacks.
EngineImageType
Visualisation contexts of vehicles and engines.
@ VSG_SCOPE_PARENT
Related object of the resolved one.
@ VEH_ROAD
Road vehicle type.
uint16 cur_speed
current speed
uint16 internal_id
The internal ID within the GRF file.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
EngineID self_type
Type of the vehicle.
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
Owner owner
Which company owns the vehicle?
static bool EnginePreSort(const EngineID &a, const EngineID &b)
Comparator function to sort engines via scope-GRFID and local ID.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
@ HANGAR
Heading for hangar.
byte breakdowns_since_last_service
Counter for the amount of breakdowns.
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
@ VSG_SCOPE_SELF
Resolved object itself.
@ WO_NONE
Resolve no wagon overrides.
@ TERM7
Heading for terminal 7.
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
@ TERM3
Heading for terminal 3.
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
@ AMED_EXACTPOS
Go exactly to the destination coordinates.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
static const GRFFile * GetEngineGrfFile(EngineID engine_type)
Get the grf file associated with an engine type.
Aircraft, helicopters, rotors and their shadows belong to this class.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
const SpriteGroup ** loading
List of loading groups (can be SpriteIDs or Callback results)
@ RTFB_CATENARY
Value for drawing a catenary.
byte breakdown_ctr
Counter for managing breakdown events.
@ VS_HIDDEN
Vehicle is not visible.
uint16 EngineID
Unique identification number of an engine.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
RailType
Enumeration for all possible railtypes.
Date _date
Current date in days (day counter)
uint32 GetTriggers() const override
Get the triggers.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
@ AMED_SLOWTURN
Turn slowly (mostly used in the air).
uint16 flag
special flags when moving towards the destination.
static const byte LIT_ALL
Show the liveries of all companies.
uint32 consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
byte turn_counter
Ticks between each turn to prevent > 45 degree turns.
@ VF_CARGO_UNLOADING
Vehicle is unloading cargo.
@ NCVV_POSITION_CONSIST_LENGTH
This bit will be set if the NewGRF var 40 currently stored is valid.
TileIndex tile
Current tile index.
#define DEBUG(name, level,...)
Output a line of debugging information.
static const VehicleID INVALID_VEHICLE
Constant representing a non-existing vehicle.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
EngineID engine_type
The type of engine used for this vehicle.
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Sprite sequence for a vehicle part.
StationID last_station_visited
The last station we stopped at.
@ AMED_HOLD
Holding pattern movement (above the airport).
VehicleCargoList cargo
The cargo this vehicle is carrying.
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_...
@ CBID_VEHICLE_SPAWN_VISUAL_EFFECT
Called to spawn visual effects for vehicles.
Order current_order
The current order (+ status, like: loading)
Airport airport
Tile area the airport covers.
GroundVehicleCache gcache
Cache of often calculated values.
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
uint16 reliability_spd_dec
Reliability decrease speed.
'Train' is either a loco or a wagon.
@ WO_SELF
Resolve self-override (helicopter rotors and such).
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
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.
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
@ ROTFB_CATENARY
Value for drawing a catenary.
Finite sTate mAchine (FTA) of an airport.
DirDiff
Enumeration for the difference between two directions.
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
@ TERM5
Heading for terminal 5.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
RoadType
The different roadtypes we support.
uint32 company_information
Cache for NewGRF var 43.
@ HELIPAD3
Heading for helipad 3.
byte misc_flags
Miscellaneous flags.
byte waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
uint32 position_in_vehicle
Cache for NewGRF var 4D.
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
static uint32 PositionHelper(const Vehicle *v, bool consecutive)
Helper to get the position of a vehicle within a chain of vehicles.
Direction direction
facing
@ TERM2
Heading for terminal 2.
void VehicleEnteredDepotThisTick(Vehicle *v)
Adds a vehicle to the list of vehicles that visited a depot this tick.
byte delta_z
Z adjustment for helicopter pads.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
const struct Vehicle * v
The vehicle being resolved.
@ CBID_VEHICLE_COLOUR_MAPPING
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
uint16 wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ NCVV_CONSIST_CARGO_INFORMATION
This bit will be set if the NewGRF var 42 currently stored is valid.
void UnloadWagonOverrides(Engine *e)
Unload all wagon override sprite groups.
static bool IsCompatibleRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType can drive on a tile with a given RailType.
VehicleCache vcache
Cache of often used vehicle values.
All ships have this type.
uint32 motion_counter
counter to occasionally play a vehicle sound.
CompanyID _current_company
Company currently doing an action.
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
RailTypeFlags flags
Bit mask of rail type flags.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Vehicle * First() const
Get the first vehicle of this vehicle chain.
byte tick_counter
Increased by one for each tick.
uint16 cargo_cap
total capacity
bool CanCarryCargo() const
Determines whether an engine can carry something.
@ WO_UNCACHED
Resolve wagon overrides.
uint32 cached_power
Total power of the consist (valid only for the first engine).
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
@ NCVV_POSITION_SAME_ID_LENGTH
This bit will be set if the NewGRF var 41 currently stored is valid.
byte subspeed
fractional speed
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8 tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
TileIndex tile
The base tile of the area.
static byte MapAircraftMovementState(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2)
uint16 MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow.
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
TrackBits state
The "track" the ship is following.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
uint16 classes
Classes of this cargo type.
@ NUM_CARGO
Maximal number of cargo types in a game.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Year build_year
Year the vehicle has been built.
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
@ HELIPAD1
Heading for helipad 1.
CallbackID callback
Callback being resolved.
byte breakdown_chance
Current chance of breakdowns.
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
@ HELITAKEOFF
Helicopter wants to leave the airport.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
Resolver for a vehicle (chain)
UnitID unitnumber
unit number, for display purposes only
@ VSG_SCOPE_RELATIVE
Relative position (vehicles only)
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
StationID Source() const
Returns source of the first cargo packet in this list.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
RailType GetRailTypeTranslation(uint8 railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
@ NCVV_END
End of the bits.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
@ EF_SPRITE_STACK
Draw vehicle by stacking multiple sprites.
uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
@ VEH_DISASTER
Disaster vehicle type.
byte breakdown_delay
Counter for managing breakdown length.
uint32 GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
byte pos
Next desired position of the aircraft.
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
byte subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
byte day_counter
Increased by one for each day.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#define lengthof(x)
Return the length of an fixed size array.
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
byte num_loading
Number of loading groups.
byte CargoID
Cargo slots to indicate a cargo type within a game.
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
@ CBID_VEHICLE_32DAY_CALLBACK
Called for every vehicle every 32 days (not all on same date though).
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
CargoID cargo_type
type of cargo this vehicle is carrying
@ ATP_TTDP_LARGE
Same as AT_LARGE.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
@ AMED_HELI_RAISE
Helicopter take-off.
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
@ LANDING
Airplane wants to land.
uint16 local_id
id defined by the grf file for this entity
PaletteID pal
The palette (use PAL_NONE) if not needed)
byte state
State of the airport.
@ TERM6
Heading for terminal 6.
byte cargo_subtype
Used for livery refits (NewGRF variations)
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
ResolverObject & ro
Surrounding resolver object.
VehicleType type
Type of vehicle.
static byte MapAircraftMovementAction(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This...
const struct GRFFile * grffile
grf file that introduced this entity
uint16 reliability
Reliability.
T * First() const
Get the first vehicle in the chain.
@ TERM8
Heading for terminal 8.
VehicleType type
The engine type.
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).
byte flags
Flags of the engine.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint32 position_consist_length
Cache for NewGRF var 40.
@ CT_INVALID
Invalid cargo type.
@ TAKEOFF
Airplane wants to leave the airport.
@ VEH_SHIP
Ship vehicle type.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
const AirportMovingData * MovingData(byte position) const
Get movement data at a position.
@ HELIPAD2
Heading for helipad 2.
Information about a particular livery.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
@ FLYING
Vehicle is flying in the air.
@ AMED_HELI_LOWER
Helicopter landing.
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.
Dynamic data of a loaded NewGRF.
Resolver for a vehicle scope.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR,...
Date date_of_last_service
Last date the vehicle had a service at a depot.
@ AMED_BRAKE
Taxiing at the airport.
@ TERM4
Heading for terminal 4.
@ CBID_TRAIN_ALLOW_WAGON_ATTACH
Determine whether a wagon can be attached to an already existing train.
@ INVALID_RAILTYPE
Flag for invalid railtype.