OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
39 wo->engines.assign(engine_ids.begin(), engine_ids.end());
48 if (std::find(wo.engines.begin(), wo.engines.end(), overriding_engine) != wo.engines.end())
return wo.group;
59 GrfMsg(6,
"SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
78 static int MapOldSubType(
const Vehicle *v)
90 default: NOT_REACHED();
96 enum TTDPAircraftMovementStates {
102 AMS_TTDP_TO_ENTRY_2_AND_3,
103 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
104 AMS_TTDP_TO_JUNCTION,
105 AMS_TTDP_LEAVE_RUNWAY,
113 AMS_TTDP_FLIGHT_APPROACH,
114 AMS_TTDP_UNUSED_0x11,
115 AMS_TTDP_FLIGHT_TO_TOWER,
116 AMS_TTDP_UNUSED_0x13,
117 AMS_TTDP_FLIGHT_FINAL,
118 AMS_TTDP_FLIGHT_DESCENT,
120 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
121 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
122 AMS_TTDP_HELI_LAND_AIRPORT,
123 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
124 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
125 AMS_TTDP_HELI_LAND_HELIPORT,
136 if (st ==
nullptr)
return AMS_TTDP_FLIGHT_TO_TOWER;
153 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
160 return AMS_TTDP_TO_HANGAR;
164 return AMS_TTDP_TO_JUNCTION;
168 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
178 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
185 if (amdflag &
AMED_SLOWTURN)
return AMS_TTDP_FLIGHT_TO_TOWER;
186 return AMS_TTDP_TO_JUNCTION;
189 return AMS_TTDP_TO_OUTWAY;
192 return AMS_TTDP_TAKEOFF;
195 return AMS_TTDP_CLIMBING;
200 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
202 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
206 return amdflag &
AMED_HOLD ? AMS_TTDP_FLIGHT_APPROACH : AMS_TTDP_FLIGHT_TO_TOWER;
209 return AMS_TTDP_FLIGHT_DESCENT;
212 if (amdflag &
AMED_BRAKE)
return AMS_TTDP_BRAKING;
214 return AMS_TTDP_TO_INWAY;
220 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
222 return AMS_TTDP_FLIGHT_TO_TOWER;
226 return AMS_TTDP_HANGAR;
232 enum TTDPAircraftMovementActions {
237 AMA_TTDP_HANGAR_TO_PAD1,
238 AMA_TTDP_HANGAR_TO_PAD2,
239 AMA_TTDP_HANGAR_TO_PAD3,
240 AMA_TTDP_LANDING_TO_PAD1,
241 AMA_TTDP_LANDING_TO_PAD2,
242 AMA_TTDP_LANDING_TO_PAD3,
243 AMA_TTDP_PAD1_TO_HANGAR,
244 AMA_TTDP_PAD2_TO_HANGAR,
245 AMA_TTDP_PAD3_TO_HANGAR,
246 AMA_TTDP_PAD1_TO_TAKEOFF,
247 AMA_TTDP_PAD2_TO_TAKEOFF,
248 AMA_TTDP_PAD3_TO_TAKEOFF,
249 AMA_TTDP_HANGAR_TO_TAKOFF,
250 AMA_TTDP_LANDING_TO_HANGAR,
264 return (v->
cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
268 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
272 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
281 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
288 return AMA_TTDP_PAD1_TO_TAKEOFF;
291 return AMA_TTDP_IN_FLIGHT;
299 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
302 return AMA_TTDP_IN_HANGAR;
309 return this->v ==
nullptr ? 0 : this->v->
random_bits;
324 int32_t count =
GB(relative, 0, 4);
325 if (this->
self_scope.
v !=
nullptr && (relative != this->cached_relative_count || count == 0)) {
331 switch (
GB(relative, 6, 2)) {
332 default: NOT_REACHED();
346 if (u->engine_type != self->engine_type) {
349 if (v ==
nullptr) v = u;
352 if (v ==
nullptr) v =
self;
399 uint8_t chain_before = 0;
400 uint8_t chain_after = 0;
402 for (u = v->
First(); u != v; u = u->
Next()) {
412 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
415 static uint32_t VehicleGetVariable(
Vehicle *v,
const VehicleScopeResolver *
object, uint8_t variable, uint32_t parameter,
bool &available)
438 std::array<uint8_t, NUM_CARGO> common_cargoes{};
439 uint8_t cargo_classes = 0;
440 uint8_t user_def_data = 0;
442 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
446 if (!u->GetEngine()->CanCarryCargo())
continue;
449 common_cargoes[u->cargo_type]++;
453 auto cargo_it = std::max_element(std::begin(common_cargoes), std::end(common_cargoes));
455 CargoID common_cargo_type = (*cargo_it == 0) ? INVALID_CARGO :
static_cast<CargoID>(std::distance(std::begin(common_cargoes), cargo_it));
458 std::array<uint8_t, UINT8_MAX + 1> common_subtypes{};
459 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
461 if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo())
continue;
463 common_subtypes[u->cargo_subtype]++;
467 auto subtype_it = std::max_element(std::begin(common_subtypes), std::end(common_subtypes));
469 uint8_t common_subtype = (*subtype_it == 0) ? UINT8_MAX :
static_cast<uint8_t
>(std::distance(std::begin(common_subtypes), subtype_it));
488 const GRFFile *grffile =
object->ro.grffile;
489 uint8_t common_bitnum = (common_cargo_type == INVALID_CARGO) ? 0xFF :
507 assert(w !=
nullptr);
508 uint16_t altitude = ClampTo<uint16_t>(v->
z_pos - w->
z_pos);
517 return (ClampTo<uint8_t>(altitude) << 8) | airporttype;
593 uint8_t artic_before = 0;
595 uint8_t artic_after = 0;
608 for (; v !=
nullptr; v = v->
Next()) {
625 if (u ==
nullptr)
return 0;
627 if (parameter == 0x5F) {
631 return VehicleGetVariable(u,
object, parameter,
GetRegister(0x10E), available);
648 if (u ==
nullptr)
return 0;
651 bool prev = (int8_t)parameter < 0;
678 if (tile_type == param_type)
return 0x0F;
688 if (tile_type == param_type)
return 0x0F;
692 default:
return 0x00;
697 uint16_t modflags = 0;
702 const Train *u = is_powered_wagon ? t->
First() : t;
704 bool powered = t->
IsEngine() || is_powered_wagon;
707 if (powered && has_power)
SetBit(modflags, 5);
708 if (powered && !has_power)
SetBit(modflags, 6);
714 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
724 switch (variable - 0x80) {
725 case 0x00:
return v->
type + 0x10;
726 case 0x01:
return MapOldSubType(v);
729 case 0x04:
return v->
index;
730 case 0x05:
return GB(v->
index, 8, 8);
750 default: ticks = 0;
break;
753 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
757 case 0x14:
return v->GetServiceInterval();
758 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
773 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
775 case 0x1A:
return v->
x_pos;
776 case 0x1B:
return GB(v->
x_pos, 8, 8);
777 case 0x1C:
return v->
y_pos;
778 case 0x1D:
return GB(v->
y_pos, 8, 8);
779 case 0x1E:
return v->
z_pos;
813 case 0x40:
return ClampTo<uint16_t>(v->
age);
814 case 0x41:
return GB(ClampTo<uint16_t>(v->
age), 8, 8);
815 case 0x42:
return ClampTo<uint16_t>(v->
max_age);
816 case 0x43:
return GB(ClampTo<uint16_t>(v->
max_age), 8, 8);
844 case 0x5C:
return ClampTo<int32_t>(v->
value);
845 case 0x5D:
return GB(ClampTo<int32_t>(v->
value), 8, 24);
846 case 0x5E:
return GB(ClampTo<int32_t>(v->
value), 16, 16);
847 case 0x5F:
return GB(ClampTo<int32_t>(v->
value), 24, 8);
886 switch (variable - 0x80) {
887 case 0x62:
return t->track;
888 case 0x66:
return t->railtype;
903 switch (variable - 0x80) {
904 case 0x62:
return rv->
state;
905 case 0x64:
return rv->blocked_ctr;
906 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
917 switch (variable - 0x80) {
918 case 0x62:
return s->
state;
925 switch (variable - 0x80) {
936 Debug(grf, 1,
"Unhandled vehicle variable 0x{:X}, type 0x{:X}", variable, (uint)v->
type);
944 if (this->v ==
nullptr) {
975 return VehicleGetVariable(
const_cast<Vehicle*
>(this->v),
this, variable, parameter, available);
991 uint totalsets = in_motion ? (uint)group->
loaded.size() : (uint)group->
loading.size();
993 if (totalsets == 0)
return nullptr;
996 set = std::min(set, totalsets - 1);
1005 case VEH_ROAD:
return GSF_ROADVEHICLES;
1025 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
1039 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
1041 self_scope(*this, engine_type, v, rotor_in_gui),
1042 parent_scope(*this, engine_type, ((v != nullptr) ? v->First() : v), rotor_in_gui),
1043 relative_scope(*this, engine_type, v, rotor_in_gui),
1044 cached_relative_count(0)
1046 if (wagon_override ==
WO_SELF) {
1079 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1080 for (uint stack = 0; stack < max_stack; ++stack) {
1081 object.ResetState();
1082 object.callback_param1 = image_type | (stack << 8);
1084 uint32_t reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1085 if (group !=
nullptr && group->GetNumResults() != 0) {
1086 result->seq[result->count].sprite = group->GetResult() + (direction % group->GetNumResults());
1087 result->seq[result->count].pal =
GB(reg100, 0, 16);
1090 if (!
HasBit(reg100, 31))
break;
1107 bool rotor_in_gui = image_type !=
EIT_ON_MAP;
1110 uint rotor_pos = v ==
nullptr || rotor_in_gui ? 0 : v->
Next()->
Next()->
state;
1113 uint max_stack = sprite_stack ?
lengthof(result->seq) : 1;
1114 for (uint stack = 0; stack < max_stack; ++stack) {
1115 object.ResetState();
1116 object.callback_param1 = image_type | (stack << 8);
1118 uint32_t reg100 = sprite_stack ?
GetRegister(0x100) : 0;
1119 if (group !=
nullptr && group->GetNumResults() != 0) {
1120 result->seq[result->count].sprite = group->GetResult() + (rotor_pos % group->GetNumResults());
1121 result->seq[result->count].pal =
GB(reg100, 0, 16);
1124 if (!
HasBit(reg100, 31))
break;
1137 return Train::From(v)->tcache.cached_override !=
nullptr;
1152 return object.ResolveCallback();
1168 object.parent_scope.SetVehicle(parent);
1169 return object.ResolveCallback();
1174 int GetVehicleProperty(
const Vehicle *v,
PropertyID property,
int orig_value,
bool is_signed)
1176 return GetEngineProperty(v->
engine_type, property, orig_value, v, is_signed);
1186 return static_cast<int16_t
>(callback << 1) / 2;
1206 const uint16_t PROBABILITY_RANGE = 100;
1207 return p +
RandomRange(PROBABILITY_RANGE) >= PROBABILITY_RANGE;
1210 static void DoTriggerVehicle(
Vehicle *v, VehicleTrigger trigger, uint16_t base_random_bits,
bool first)
1213 assert(v !=
nullptr);
1220 if (group ==
nullptr)
return;
1226 uint16_t new_random_bits = Random();
1227 uint32_t reseed =
object.GetReseedSum();
1229 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1232 case VEHICLE_TRIGGER_NEW_CARGO:
1241 DoTriggerVehicle(v->
First(), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits,
false);
1244 case VEHICLE_TRIGGER_DEPOT:
1248 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, 0,
true);
1251 case VEHICLE_TRIGGER_EMPTY:
1256 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1259 case VEHICLE_TRIGGER_ANY_NEW_CARGO:
1263 if (v->
Next() !=
nullptr) DoTriggerVehicle(v->
Next(), VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits,
false);
1266 case VEHICLE_TRIGGER_CALLBACK_32:
1272 void TriggerVehicle(
Vehicle *v, VehicleTrigger trigger)
1274 if (trigger == VEHICLE_TRIGGER_DEPOT) {
1280 DoTriggerVehicle(v, trigger, 0,
true);
1291 static std::vector<ListOrderChange> _list_order_changes;
1302 _list_order_changes.push_back({engine, target});
1332 std::vector<EngineID> ordering;
1334 ordering.push_back(e->
index);
1341 uint local_target = it.target;
1344 if (id_source->
internal_id == local_target)
continue;
1349 int source_index =
find_index(ordering, source);
1350 int target_index =
find_index(ordering, target);
1352 assert(source_index >= 0 && target_index >= 0);
1353 assert(source_index != target_index);
1356 if (source_index < target_index) {
1358 for (
int i = source_index; i < target_index; ++i) list[i] = list[i + 1];
1359 list[target_index] = source;
1361 for (
int i = source_index; i > target_index; --i) list[i] = list[i - 1];
1362 list[target_index] = source;
1368 for (
const EngineID &eid : ordering) {
1374 _list_order_changes.clear();
1375 _list_order_changes.shrink_to_fit();
1387 static const int cache_entries[][2] = {
1397 for (
const auto &cache_entry : cache_entries) {
@ INVALID_RAILTYPE
Flag for invalid railtype.
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.
uint8_t misc_flags
Miscellaneous flags.
@ 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).
@ WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
@ RTFB_CATENARY
Value for drawing a catenary.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
uint8_t breakdown_chance
Current chance of breakdowns.
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.
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
static uint8_t MapAircraftMovementState(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2)
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
uint16_t reliability_spd_dec
Reliability decrease speed.
Money value
Value of the vehicle.
uint32_t GetRandomBits() const override
Get a few random bits.
@ CBID_VEHICLE_START_STOP_CHECK
Called when the company (or AI) tries to start or stop a vehicle.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
uint16_t cargo_cap
total capacity
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
uint8_t overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Vehicle * Next() const
Get the next vehicle of this vehicle.
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.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
RailType
Enumeration for all possible railtypes.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
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.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
@ VEH_TRAIN
Train vehicle type.
Interface for SpriteGroup-s to access the gamestate.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ TERM1
Heading for terminal 1.
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
This struct contains all the info that is needed to draw and construct tracks.
@ ENDLANDING
Airplane wants to finish landing.
@ VEH_ROAD
Road vehicle type.
Specification of a cargo type.
uint16_t GetVehicleCallbackParent(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
uint32_t position_in_vehicle
Cache for NewGRF var 4D.
@ GSF_INVALID
An invalid spec feature.
CallbackID
List of implemented NewGRF callbacks.
EngineImageType
Visualisation contexts of vehicles and engines.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
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.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
debug_inline bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
uint32_t motion_counter
counter to occasionally play a vehicle sound.
@ HANGAR
Heading for hangar.
uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
uint8_t subspeed
fractional speed
uint32_t GetTriggers() const override
Get the triggers.
@ WO_NONE
Resolve no wagon overrides.
@ TERM7
Heading for terminal 7.
int32_t x_pos
x coordinate.
@ 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.
int find_index(Container const &container, typename Container::const_reference item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
uint8_t flags
Flags of the engine.
Aircraft, helicopters, rotors and their shadows belong to this class.
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_BUILD_PROBABILITY
Called to determine probability during build.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
uint32_t position_consist_length
Cache for NewGRF var 40.
@ VSG_SCOPE_SELF
Resolved object itself.
@ VS_HIDDEN
Vehicle is not visible.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
CargoClasses classes
Classes of this cargo type.
uint8_t subtype
Type of aircraft.
@ VEH_DISASTER
Disaster vehicle type.
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8_t tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
@ AMED_SLOWTURN
Turn slowly (mostly used in the air).
uint8_t weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
@ 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.
uint8_t pos
Next desired position of the aircraft.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
@ EIT_ON_MAP
Vehicle drawn in viewport.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
uint16_t random_bits
Bits used for randomized variational spritegroups.
EngineID engine_type
The type of engine used for this vehicle.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probablity type.
uint32_t grfid
The GRF ID of the file the entity belongs to.
Sprite sequence for a vehicle part.
StationID last_station_visited
The last station we stopped at.
@ AMED_HOLD
Holding pattern movement (above the airport).
@ ROTFB_CATENARY
Value for drawing a catenary.
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui=false, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Resolver of a vehicle (chain).
VehicleCargoList cargo
The cargo this vehicle is carrying.
@ CBID_VEHICLE_SPAWN_VISUAL_EFFECT
Called to spawn visual effects for vehicles.
Order current_order
The current order (+ status, like: loading)
@ VEH_SHIP
Ship vehicle type.
Airport airport
Tile area the airport covers.
uint32_t consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
GroundVehicleCache gcache
Cache of often calculated values.
static constexpr CargoID SG_DEFAULT
Default type used when no more-specific cargo matches.
uint16_t cur_speed
current speed
const Livery * GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, uint8_t livery_setting)
Determines the livery for a vehicle.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
RoadType
The different roadtypes we support.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
#define lengthof(array)
Return the length of an fixed size array.
'Train' is either a loco or a wagon.
@ WO_SELF
Resolve self-override (helicopter rotors and such).
RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
bool IsCompatibleRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType can drive on a tile with a given RailType.
@ VRF_REVERSE_DIRECTION
Reverse the visible direction of the vehicle.
uint8_t overtaking_ctr
The length of the current overtake attempt.
@ INVALID_ROADTYPE
flag for invalid roadtype
Finite sTate mAchine (FTA) of an airport.
DirDiff
Allow incrementing of Direction variables.
uint8_t bitnum
Cargo bit number, is INVALID_CARGO_BITNUM for a non-used spec.
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
@ TERM5
Heading for terminal 5.
@ HELIPAD3
Heading for helipad 3.
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
int32_t z_pos
z coordinate.
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
uint16_t local_id
id defined by the grf file for this entity
Direction direction
facing
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
@ TERM2
Heading for terminal 2.
void VehicleEnteredDepotThisTick(Vehicle *v)
Adds a vehicle to the list of vehicles that visited a depot this tick.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
uint8_t tick_counter
Increased by one for each tick.
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...
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
uint8_t acceleration
used by train & aircraft
static uint32_t PositionHelper(const Vehicle *v, bool consecutive)
Helper to get the position of a vehicle within a chain of vehicles.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
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.
VehicleCache vcache
Cache of often used vehicle values.
All ships have this type.
CompanyID _current_company
Company currently doing an action.
uint32_t position_same_id_length
Cache for NewGRF var 41.
uint8_t breakdown_delay
Counter for managing breakdown length.
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.
Vehicle * First() const
Get the first vehicle of this vehicle chain.
uint8_t day_counter
Increased by one for each day.
TimerGameCalendar::Date max_age
Maximum age.
uint16_t internal_id
The internal ID within the GRF file.
@ WO_UNCACHED
Resolve wagon overrides.
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
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.
uint8_t state
State of the airport.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
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.
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).
uint16_t MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
static uint8_t MapAircraftMovementAction(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This...
@ VSG_SCOPE_PARENT
Related object of the resolved one.
uint16_t reliability
Reliability.
EngineID GetID(VehicleType type, uint16_t grf_local_id, uint32_t grfid)
Looks up an EngineID in the EngineOverrideManager.
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
static constexpr CargoID SG_PURCHASE
Used in purchase lists before an item exists.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
TrackBits state
The "track" the ship is following.
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
TimerGameCalendar::Date age
Age in calendar days.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
const AirportMovingData * MovingData(uint8_t position) const
Get movement data at a position.
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
@ HELIPAD1
Heading for helipad 1.
uint8_t turn_counter
Ticks between each turn to prevent > 45 degree turns.
CallbackID callback
Callback being resolved.
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
@ HELITAKEOFF
Helicopter wants to leave the airport.
uint8_t delta_z
Z adjustment for helicopter pads.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Resolver for a vehicle (chain)
Direction
Defines the 8 directions on the map.
UnitID unitnumber
unit number, for display purposes only
@ NCVV_END
End of the bits.
uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override
Get a variable value.
@ EF_SPRITE_STACK
Draw vehicle by stacking multiple sprites.
int32_t y_pos
y coordinate.
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
uint8_t user_def_data
Cached property 0x25. Can be set by Callback 0x36.
DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
Applies two differences together.
uint32_t company_information
Cache for NewGRF var 43.
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
@ CBID_VEHICLE_32DAY_CALLBACK
Called for every vehicle every 32 days (not all on same date though).
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
RailTypeFlags flags
Bit mask of rail type flags.
CargoID cargo_type
type of cargo this vehicle is carrying
@ ATP_TTDP_LARGE
Same as AT_LARGE.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
uint16_t crashed_ctr
Animation counter when the vehicle has crashed.
@ AMED_HELI_RAISE
Helicopter take-off.
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
uint8_t waiting_triggers
Triggers to be yet matched before rerandomizing the random bits.
@ LANDING
Airplane wants to land.
static Date date
Current date in days (day counter).
@ TERM6
Heading for terminal 6.
uint16_t EngineID
Unique identification number of an engine.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
uint8_t cache_valid
Bitset that indicates which cache values are valid.
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.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
const struct GRFFile * grffile
grf file that introduced this entity
T * First() const
Get the first vehicle in the chain.
@ TERM8
Heading for terminal 8.
VehicleType type
The engine type.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
uint8_t cargo_subtype
Used for livery refits (NewGRF variations)
@ TAKEOFF
Airplane wants to leave the airport.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
uint8_t cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
uint16_t wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
static const uint8_t LIT_ALL
Show the liveries of all companies.
@ HELIPAD2
Heading for helipad 2.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
Information about a particular livery.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
@ 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.
uint16_t flag
special flags when moving towards the destination.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
@ VSG_SCOPE_RELATIVE
Relative position (vehicles only)
@ 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.
virtual uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
Get a variable value.
static Year year
Current year, starting at 0.
uint8_t breakdown_ctr
Counter for managing breakdown events.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.