OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
38 wo->engines.assign(train_id, train_id + trains);
46 if (wo.cargo != cargo && wo.cargo != CT_DEFAULT)
continue;
47 if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end())
return wo.group;
58 grfmsg(6,
"SetCustomEngineSprites: engine %d cargo %d already has group -- replacing", engine, cargo);
77 static int MapOldSubType(
const Vehicle *v)
89 default: NOT_REACHED();
95 enum TTDPAircraftMovementStates {
101 AMS_TTDP_TO_ENTRY_2_AND_3,
102 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
103 AMS_TTDP_TO_JUNCTION,
104 AMS_TTDP_LEAVE_RUNWAY,
112 AMS_TTDP_FLIGHT_APPROACH,
113 AMS_TTDP_UNUSED_0x11,
114 AMS_TTDP_FLIGHT_TO_TOWER,
115 AMS_TTDP_UNUSED_0x13,
116 AMS_TTDP_FLIGHT_FINAL,
117 AMS_TTDP_FLIGHT_DESCENT,
119 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
120 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
121 AMS_TTDP_HELI_LAND_AIRPORT,
122 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
123 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
124 AMS_TTDP_HELI_LAND_HELIPORT,
135 if (st ==
nullptr)
return AMS_TTDP_FLIGHT_TO_TOWER;
152 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
159 return AMS_TTDP_TO_HANGAR;
163 return AMS_TTDP_TO_JUNCTION;
167 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
177 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
184 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
185 return AMS_TTDP_TO_JUNCTION;
188 return AMS_TTDP_TO_OUTWAY;
191 return AMS_TTDP_TAKEOFF;
194 return AMS_TTDP_CLIMBING;
199 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
201 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
205 return amdflag &
AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
208 return AMS_TTDP_FLIGHT_DESCENT;
211 if (amdflag &
AMED_BRAKE)
return AMS_TTDP_BRAKING;
213 return AMS_TTDP_TO_INWAY;
219 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
221 return AMS_TTDP_FLIGHT_TO_TOWER;
225 return AMS_TTDP_HANGAR;
231 enum TTDPAircraftMovementActions {
236 AMA_TTDP_HANGAR_TO_PAD1,
237 AMA_TTDP_HANGAR_TO_PAD2,
238 AMA_TTDP_HANGAR_TO_PAD3,
239 AMA_TTDP_LANDING_TO_PAD1,
240 AMA_TTDP_LANDING_TO_PAD2,
241 AMA_TTDP_LANDING_TO_PAD3,
242 AMA_TTDP_PAD1_TO_HANGAR,
243 AMA_TTDP_PAD2_TO_HANGAR,
244 AMA_TTDP_PAD3_TO_HANGAR,
245 AMA_TTDP_PAD1_TO_TAKEOFF,
246 AMA_TTDP_PAD2_TO_TAKEOFF,
247 AMA_TTDP_PAD3_TO_TAKEOFF,
248 AMA_TTDP_HANGAR_TO_TAKOFF,
249 AMA_TTDP_LANDING_TO_HANGAR,
263 return (v->
cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
267 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
271 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
280 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
287 return AMA_TTDP_PAD1_TO_TAKEOFF;
290 return AMA_TTDP_IN_FLIGHT;
298 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
301 return AMA_TTDP_IN_HANGAR;
308 return this->v ==
nullptr ? 0 : this->v->
random_bits;
323 int32 count =
GB(relative, 0, 4);
324 if (this->
self_scope.
v !=
nullptr && (relative != this->cached_relative_count || count == 0)) {
330 switch (
GB(relative, 6, 2)) {
331 default: NOT_REACHED();
345 if (u->engine_type != self->engine_type) {
348 if (v ==
nullptr) v = u;
351 if (v ==
nullptr) v =
self;
398 byte chain_before = 0;
399 byte chain_after = 0;
401 for (u = v->
First(); u != v; u = u->
Next()) {
411 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
438 byte cargo_classes = 0;
440 uint8 common_subtypes[256];
441 byte user_def_data = 0;
443 uint8 common_subtype = 0xFF;
446 memset(common_cargoes, 0,
sizeof(common_cargoes));
447 memset(common_subtypes, 0,
sizeof(common_subtypes));
449 for (u = v; u !=
nullptr; u = u->
Next()) {
460 uint common_cargo_best_amount = 0;
462 if (common_cargoes[cargo] > common_cargo_best_amount) {
463 common_cargo_best_amount = common_cargoes[cargo];
464 common_cargo_type = cargo;
469 for (u = v; u !=
nullptr; u = u->
Next()) {
477 uint common_subtype_best_amount = 0;
478 for (uint i = 0; i <
lengthof(common_subtypes); i++) {
479 if (common_subtypes[i] > common_subtype_best_amount) {
480 common_subtype_best_amount = common_subtypes[i];
502 const GRFFile *grffile =
object->ro.grffile;
503 uint8 common_bitnum = (common_cargo_type ==
CT_INVALID) ? 0xFF :
530 return (
Clamp(altitude, 0, 0xFF) << 8) | airporttype;
606 byte artic_before = 0;
608 byte artic_after = 0;
621 for (; v !=
nullptr; v = v->
Next()) {
638 if (u ==
nullptr)
return 0;
640 if (parameter == 0x5F) {
644 return VehicleGetVariable(u,
object, parameter,
GetRegister(0x10E), available);
661 if (u ==
nullptr)
return 0;
664 bool prev = (int8)parameter < 0;
691 if (tile_type == param_type)
return 0x0F;
701 if (tile_type == param_type)
return 0x0F;
705 default:
return 0x00;
715 const Train *u = is_powered_wagon ? t->
First() : t;
717 bool powered = t->
IsEngine() || is_powered_wagon;
720 if (powered && has_power)
SetBit(modflags, 5);
721 if (powered && !has_power)
SetBit(modflags, 6);
727 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
737 switch (variable - 0x80) {
738 case 0x00:
return v->
type + 0x10;
739 case 0x01:
return MapOldSubType(v);
742 case 0x04:
return v->
index;
743 case 0x05:
return GB(v->
index, 8, 8);
763 default: ticks = 0;
break;
766 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
770 case 0x14:
return v->GetServiceInterval();
771 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
786 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
788 case 0x1A:
return v->
x_pos;
789 case 0x1B:
return GB(v->
x_pos, 8, 8);
790 case 0x1C:
return v->
y_pos;
791 case 0x1D:
return GB(v->
y_pos, 8, 8);
792 case 0x1E:
return v->
z_pos;
899 switch (variable - 0x80) {
900 case 0x62:
return t->track;
901 case 0x66:
return t->railtype;
916 switch (variable - 0x80) {
917 case 0x62:
return rv->
state;
918 case 0x64:
return rv->blocked_ctr;
919 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
930 switch (variable - 0x80) {
931 case 0x62:
return s->
state;
938 switch (variable - 0x80) {
949 Debug(grf, 1,
"Unhandled vehicle variable 0x{:X}, type 0x{:X}", variable, (uint)v->
type);
957 if (this->v ==
nullptr) {
974 case 0x4B:
return _date;
986 return VehicleGetVariable(
const_cast<Vehicle*
>(this->v),
this, variable, parameter, available);
1002 uint totalsets = in_motion ? (uint)group->
loaded.size() : (uint)group->
loading.size();
1004 if (totalsets == 0)
return nullptr;
1007 set = std::min(set, totalsets - 1);
1009 return in_motion ? group->
loaded[set] : group->
loading[set];
1016 case VEH_ROAD:
return GSF_ROADVEHICLES;
1036 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
1050 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
1052 self_scope(*this, engine_type, v, info_view),
1053 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), info_view),
1054 relative_scope(*this, engine_type, v, info_view),
1055 cached_relative_count(0)
1057 if (wagon_override ==
WO_SELF) {
1058 this->
root_spritegroup = GetWagonOverrideSpriteSet(engine_type, CT_DEFAULT, engine_type);
1090 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1091 for (uint stack = 0; stack < max_stack; ++stack) {
1092 object.ResetState();
1093 object.callback_param1 = image_type | (stack << 8);
1095 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1096 if (group !=
nullptr && group->GetNumResults() != 0) {
1097 result->seq[result->count].
sprite = group->GetResult() + (direction % group->GetNumResults());
1098 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1101 if (!
HasBit(reg100, 31))
break;
1116 uint rotor_pos = v ==
nullptr || info_view ? 0 : v->
Next()->
Next()->
state;
1119 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1120 for (uint stack = 0; stack < max_stack; ++stack) {
1121 object.ResetState();
1122 object.callback_param1 = image_type | (stack << 8);
1124 uint32 reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1125 if (group !=
nullptr && group->GetNumResults() != 0) {
1126 result->seq[result->count].
sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1127 result->seq[result->count].
pal =
GB(reg100, 0, 16);
1130 if (!
HasBit(reg100, 31))
break;
1143 return Train::From(v)->tcache.cached_override !=
nullptr;
1158 return object.ResolveCallback();
1174 object.parent_scope.SetVehicle(parent);
1175 return object.ResolveCallback();
1180 int GetVehicleProperty(
const Vehicle *v,
PropertyID property,
int orig_value,
bool is_signed)
1182 return GetEngineProperty(v->
engine_type, property, orig_value, v, is_signed);
1192 return static_cast<int16
>(callback << 1) / 2;
1202 static void DoTriggerVehicle(
Vehicle *v, VehicleTrigger trigger,
byte base_random_bits,
bool first)
1205 assert(v !=
nullptr);
1212 if (group ==
nullptr)
return;
1218 byte new_random_bits = Random();
1219 uint32 reseed =
object.GetReseedSum();
1221 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1224 case VEHICLE_TRIGGER_NEW_CARGO:
1233 DoTriggerVehicle(v->
First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits,
false);
1236 case VEHICLE_TRIGGER_DEPOT:
1240 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, 0,
true);
1243 case VEHICLE_TRIGGER_EMPTY:
1248 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1251 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1255 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits,
false);
1258 case VEHICLE_TRIGGER_CALLBACK_32:
1264 void TriggerVehicle(
Vehicle *v, VehicleTrigger trigger)
1266 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1272 DoTriggerVehicle(v, trigger, 0,
true);
1283 static std::vector<ListOrderChange> _list_order_changes;
1294 _list_order_changes.push_back({engine, target});
1324 std::vector<EngineID> ordering;
1326 ordering.push_back(e->
index);
1333 uint local_target = it.target;
1336 if (id_source->
internal_id == local_target)
continue;
1341 int source_index =
find_index(ordering, source);
1342 int target_index =
find_index(ordering, target);
1344 assert(source_index >= 0 && target_index >= 0);
1345 assert(source_index != target_index);
1348 if (source_index < target_index) {
1350 for (
int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1351 list[target_index] = source;
1353 for (
int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1354 list[target_index] = source;
1360 for (
const EngineID &eid : ordering) {
1366 _list_order_changes.clear();
1367 _list_order_changes.shrink_to_fit();
1379 static const int cache_entries[][2] = {
1389 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.
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.
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.
@ RTFB_CATENARY
Value for drawing a catenary.
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
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.
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.
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
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.
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.
@ 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.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
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 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.
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.