41 wo->engines.assign(engine_ids.begin(), engine_ids.end());
50 if (std::ranges::find(wo.engines, overriding_engine) != wo.engines.end())
return wo.group;
60 GrfMsg(6,
"SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
79static int MapOldSubType(
const Vehicle *v)
91 default: NOT_REACHED();
103 AMS_TTDP_TO_ENTRY_2_AND_3,
104 AMS_TTDP_TO_ENTRY_2_AND_3_AND_H,
105 AMS_TTDP_TO_JUNCTION,
106 AMS_TTDP_LEAVE_RUNWAY,
114 AMS_TTDP_FLIGHT_APPROACH,
115 AMS_TTDP_UNUSED_0x11,
116 AMS_TTDP_FLIGHT_TO_TOWER,
117 AMS_TTDP_UNUSED_0x13,
118 AMS_TTDP_FLIGHT_FINAL,
119 AMS_TTDP_FLIGHT_DESCENT,
121 AMS_TTDP_HELI_TAKEOFF_AIRPORT,
122 AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT,
123 AMS_TTDP_HELI_LAND_AIRPORT,
124 AMS_TTDP_HELI_TAKEOFF_HELIPORT,
125 AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
126 AMS_TTDP_HELI_LAND_HELIPORT,
139 if (st ==
nullptr)
return AMS_TTDP_FLIGHT_TO_TOWER;
163 return AMS_TTDP_TO_HANGAR;
167 return AMS_TTDP_TO_JUNCTION;
171 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
181 return AMS_TTDP_TO_ENTRY_2_AND_3_AND_H;
189 return AMS_TTDP_TO_JUNCTION;
192 return AMS_TTDP_TO_OUTWAY;
195 return AMS_TTDP_TAKEOFF;
198 return AMS_TTDP_CLIMBING;
203 AMS_TTDP_HELI_TAKEOFF_AIRPORT : AMS_TTDP_TO_JUNCTION;
205 return AMS_TTDP_HELI_TAKEOFF_HELIPORT;
212 return AMS_TTDP_FLIGHT_DESCENT;
217 return AMS_TTDP_TO_INWAY;
223 AMS_TTDP_HELI_LAND_AIRPORT : AMS_TTDP_HELI_LAND_HELIPORT;
225 return AMS_TTDP_FLIGHT_TO_TOWER;
229 return AMS_TTDP_HANGAR;
240 AMA_TTDP_HANGAR_TO_PAD1,
241 AMA_TTDP_HANGAR_TO_PAD2,
242 AMA_TTDP_HANGAR_TO_PAD3,
243 AMA_TTDP_LANDING_TO_PAD1,
244 AMA_TTDP_LANDING_TO_PAD2,
245 AMA_TTDP_LANDING_TO_PAD3,
246 AMA_TTDP_PAD1_TO_HANGAR,
247 AMA_TTDP_PAD2_TO_HANGAR,
248 AMA_TTDP_PAD3_TO_HANGAR,
249 AMA_TTDP_PAD1_TO_TAKEOFF,
250 AMA_TTDP_PAD2_TO_TAKEOFF,
251 AMA_TTDP_PAD3_TO_TAKEOFF,
252 AMA_TTDP_HANGAR_TO_TAKEOFF,
253 AMA_TTDP_LANDING_TO_HANGAR,
269 return (v->
cur_speed > 0) ? AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_IN_HANGAR;
273 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD1 : AMA_TTDP_LANDING_TO_PAD1;
277 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD2 : AMA_TTDP_LANDING_TO_PAD2;
286 return (v->
current_order.
IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
293 return AMA_TTDP_PAD1_TO_TAKEOFF;
296 return AMA_TTDP_IN_FLIGHT;
304 AMA_TTDP_LANDING_TO_HANGAR : AMA_TTDP_LANDING_TO_PAD1;
307 return AMA_TTDP_IN_HANGAR;
314 return this->v ==
nullptr ? 0 : this->v->
random_bits;
329 int32_t count =
GB(relative, 0, 4);
330 if (this->
self_scope.v !=
nullptr && (relative != this->cached_relative_count || count == 0)) {
336 switch (
GB(relative, 6, 2)) {
337 default: NOT_REACHED();
354 if (v ==
nullptr) v = u;
357 if (v ==
nullptr) v = self;
404 uint8_t chain_before = 0;
405 uint8_t chain_after = 0;
407 for (u = v->
First(); u != v; u = u->
Next()) {
417 return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16;
420static uint32_t VehicleGetVariable(
Vehicle *v,
const VehicleScopeResolver *
object, uint8_t variable, uint32_t parameter,
bool &available)
443 std::array<uint8_t, NUM_CARGO> common_cargoes{};
444 uint8_t cargo_classes = 0;
445 uint8_t user_def_data = 0;
447 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
451 if (!u->GetEngine()->CanCarryCargo())
continue;
454 common_cargoes[u->cargo_type]++;
458 auto cargo_it = std::max_element(std::begin(common_cargoes), std::end(common_cargoes));
460 CargoType common_cargo_type = (*cargo_it == 0) ? INVALID_CARGO : static_cast<
CargoType>(std::distance(std::begin(common_cargoes), cargo_it));
463 std::array<uint8_t, UINT8_MAX + 1> common_subtypes{};
464 for (
const Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
466 if (u->cargo_type != common_cargo_type || !u->GetEngine()->CanCarryCargo())
continue;
468 common_subtypes[u->cargo_subtype]++;
472 auto subtype_it = std::max_element(std::begin(common_subtypes), std::end(common_subtypes));
474 uint8_t common_subtype = (*subtype_it == 0) ? UINT8_MAX : static_cast<uint8_t>(std::distance(std::begin(common_subtypes), subtype_it));
493 const GRFFile *grffile =
object->ro.grffile;
494 uint8_t common_bitnum = (common_cargo_type == INVALID_CARGO) ? 0xFF :
495 (grffile == nullptr || grffile->grf_version < 8) ?
CargoSpec::Get(common_cargo_type)->bitnum : grffile->cargo_map[common_cargo_type];
512 assert(w !=
nullptr);
598 uint8_t artic_before = 0;
600 uint8_t artic_after = 0;
613 for (; v !=
nullptr; v = v->
Next()) {
630 if (u ==
nullptr)
return 0;
632 if (parameter == 0x5F) {
636 return VehicleGetVariable(u,
object, parameter, object->
ro.
GetRegister(0x10E), available);
652 const Vehicle *u = v->
Move(
static_cast<int8_t
>(parameter));
653 if (u ==
nullptr)
return 0;
656 bool prev =
static_cast<int8_t
>(parameter) < 0;
684 if (tile_type == param_type)
return 0x0F;
694 if (tile_type == param_type)
return 0x0F;
698 default:
return 0x00;
706 BadgeID index =
object->ro.grffile->badge_list[parameter];
710 for (; v !=
nullptr; v = v->
Next()) {
711 const auto &badges = v->
GetEngine()->badges;
712 if (std::ranges::find(badges, index) != std::end(badges)) count++;
733 uint16_t modflags = 0;
738 const Train *u = is_powered_wagon ? t->
First() : t;
740 bool powered = t->
IsEngine() || is_powered_wagon;
743 if (powered && has_power)
SetBit(modflags, 5);
744 if (powered && !has_power)
SetBit(modflags, 6);
751 return variable == 0xFE ? modflags :
GB(modflags, 8, 8);
761 switch (variable - 0x80) {
763 case 0x01:
return MapOldSubType(v);
766 case 0x04:
return v->index.base();
767 case 0x05:
return GB(v->index.base(), 8, 8);
787 default: ticks = 0;
break;
790 return (variable - 0x80) == 0x10 ? ticks :
GB(ticks, 8, 8);
794 case 0x14:
return v->GetServiceInterval();
795 case 0x15:
return GB(v->GetServiceInterval(), 8, 8);
810 return (variable - 0x80) == 0x18 ? max_speed :
GB(max_speed, 8, 8);
812 case 0x1A:
return v->
x_pos;
813 case 0x1B:
return GB(v->
x_pos, 8, 8);
814 case 0x1C:
return v->
y_pos;
815 case 0x1D:
return GB(v->
y_pos, 8, 8);
816 case 0x1E:
return v->
z_pos;
879 case 0x5A:
return (v->
Next() ==
nullptr ? VehicleID::Invalid() : v->
Next()->index).base();
923 switch (variable - 0x80) {
931 case 0x7C:
return t->
First()->index.base();
932 case 0x7D:
return GB(t->
First()->index.base(), 8, 8);
940 switch (variable - 0x80) {
941 case 0x62:
return rv->
state;
942 case 0x64:
return rv->blocked_ctr;
943 case 0x65:
return GB(rv->blocked_ctr, 8, 8);
954 switch (variable - 0x80) {
962 switch (variable - 0x80) {
973 Debug(grf, 1,
"Unhandled vehicle variable 0x{:X}, type 0x{:X}", variable, (uint)v->
type);
981 if (this->v ==
nullptr) {
991 return (cs->
classes.
base() << 16) | (cs->
weight << 8) | this->
ro.grffile->cargo_map[cargo_type];
1007 case 0xDA:
return VehicleID::Invalid().base();
1008 case 0xF2:
return 0;
1015 return VehicleGetVariable(
const_cast<Vehicle*
>(this->v),
this, variable, parameter, available);
1031 bool in_motion = !order.
IsType(OT_LOADING) || not_loading;
1033 uint totalsets =
static_cast<uint
>(in_motion ? group.
loaded.size() : group.
loading.size());
1035 if (totalsets == 0)
return nullptr;
1038 set = std::min(set, totalsets - 1);
1067 return (e !=
nullptr) ? e->
GetGRF() :
nullptr;
1083 self_scope(*this, engine_type, v, rotor_in_gui),
1084 parent_scope(*this, engine_type, ((v != nullptr) ? v->
First() : v), rotor_in_gui),
1118 uint max_stack = sprite_stack ?
static_cast<uint
>(std::size(result->seq)) : 1;
1119 for (uint stack = 0; stack < max_stack; ++stack) {
1120 object.callback_param1 =
to_underlying(image_type) | (stack << 8);
1122 int32_t reg100 = sprite_stack ?
object.GetRegister(0x100) : 0;
1123 if (group !=
nullptr && group->num_sprites != 0) {
1124 result->seq[result->count].sprite = group->sprite + (
to_underlying(direction) % group->num_sprites);
1125 result->seq[result->count].pal =
GB(reg100, 0, 16);
1128 if (!
HasBit(reg100, 31))
break;
1134 GetCustomEngineSprite(v->
engine_type, v, direction, image_type, result);
1139 GetCustomEngineSprite(engine,
nullptr, direction, image_type, result);
1157 uint rotor_pos = v ==
nullptr || rotor_in_gui ? 0 : v->
Next()->
Next()->
state;
1160 uint max_stack = sprite_stack ?
static_cast<uint
>(std::size(result->seq)) : 1;
1161 for (uint stack = 0; stack < max_stack; ++stack) {
1162 object.callback_param1 =
to_underlying(image_type) | (stack << 8);
1164 int32_t reg100 = sprite_stack ?
object.GetRegister(0x100) : 0;
1165 if (group !=
nullptr && group->num_sprites != 0) {
1166 result->seq[result->count].sprite = group->sprite + (rotor_pos % group->num_sprites);
1167 result->seq[result->count].pal =
GB(reg100, 0, 16);
1170 if (!
HasBit(reg100, 31))
break;
1176 GetRotorOverrideSprite(v->
engine_type, v, image_type, result);
1181 GetRotorOverrideSprite(engine,
nullptr, image_type, result);
1208 return object.ResolveCallback(regs100);
1225 object.parent_scope.SetVehicle(parent);
1226 return object.ResolveCallback(regs100);
1231int GetVehicleProperty(
const Vehicle *v,
PropertyID property,
int orig_value,
bool is_signed)
1233 return GetEngineProperty(v->
engine_type, property, orig_value, v, is_signed);
1243 return static_cast<int16_t
>(callback << 1) / 2;
1263 const uint16_t PROBABILITY_RANGE = 100;
1264 return p +
RandomRange(PROBABILITY_RANGE) >= PROBABILITY_RANGE;
1270 assert(v !=
nullptr);
1276 object.ResolveRerandomisation();
1282 uint16_t new_random_bits = Random();
1283 uint32_t reseed =
object.GetReseedSum();
1285 v->
random_bits |= (first ? new_random_bits : base_random_bits) & reseed;
1304 if (v->
Next() !=
nullptr) DoTriggerVehicleRandomisation(v->
Next(), trigger, 0,
true);
1312 if (v->
Next() !=
nullptr) DoTriggerVehicleRandomisation(v->
Next(), trigger, first ? new_random_bits : base_random_bits,
false);
1319 if (v->
Next() !=
nullptr) DoTriggerVehicleRandomisation(v->
Next(), trigger, base_random_bits,
false);
1331 DoTriggerVehicleRandomisation(v, trigger, 0,
true);
1337struct ListOrderChange {
1344static std::vector<ListOrderChange> _list_order_changes;
1355 _list_order_changes.emplace_back(engine, target);
1370 if (engine_a.
type != engine_b.
type)
return static_cast<int>(engine_a.
type) <
static_cast<int>(engine_b.
type);
1386 std::iota(std::begin(ordering), std::end(ordering), EngineID::Begin());
1399 if (target == EngineID::Invalid())
continue;
1401 auto it_source = std::ranges::find(ordering, source);
1402 auto it_target = std::ranges::find(ordering, target);
1404 assert(it_source != std::end(ordering) && it_target != std::end(ordering));
1405 assert(it_source != it_target);
1408 Slide(it_source, std::next(it_source), it_target);
1412 for (uint16_t index = 0;
const EngineID &eid : ordering) {
1418 _list_order_changes.clear();
1419 _list_order_changes.shrink_to_fit();
1431 static const int cache_entries[][2] = {
1441 for (
const auto &cache_entry : cache_entries) {
Station * GetTargetAirportIfValid(const Aircraft *v)
Returns aircraft's target station if v->target_airport is a valid station with airport.
@ HeliRaise
Helicopter take-off.
@ HeliLower
Helicopter landing.
@ SlowTurn
Turn slowly (mostly used in the air).
@ Brake
Taxiing at the airport.
@ Hold
Holding pattern movement (above the airport).
@ ExactPosition
Go exactly to the destination coordinates.
EnumBitSet< AirportMovingDataFlag, uint16_t > AirportMovingDataFlags
Bitset of AirportMovingDataFlag elements.
@ HELITAKEOFF
Helicopter wants to leave the airport.
@ TERM4
Heading for terminal 4.
@ STARTTAKEOFF
Airplane has arrived at a runway for take-off.
@ HELIPAD2
Heading for helipad 2.
@ ENDTAKEOFF
Airplane has reached end-point of the take-off runway.
@ TERM5
Heading for terminal 5.
@ TERM6
Heading for terminal 6.
@ TERM3
Heading for terminal 3.
@ TERM8
Heading for terminal 8.
@ HELIPAD3
Heading for helipad 3.
@ HELIPAD1
Heading for helipad 1.
@ TERM2
Heading for terminal 2.
@ HANGAR
Heading for hangar.
@ FLYING
Vehicle is flying in the air.
@ TAKEOFF
Airplane wants to leave the airport.
@ HELILANDING
Helicopter wants to land.
@ ENDLANDING
Airplane wants to finish landing.
@ HELIENDLANDING
Helicopter wants to finish landing.
@ TERM1
Heading for terminal 1.
@ LANDING
Airplane wants to land.
@ TERM7
Heading for terminal 7.
@ BuiltAsPrototype
Vehicle is a prototype (accepted as exclusive preview).
@ CargoUnloading
Vehicle is unloading cargo.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
CargoType
Cargo slots to indicate a cargo type within a game.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
CargoGRFFileProps grf_prop
Link to NewGRF.
EngineFlags flags
Flags of the engine.
VehicleType type
Vehicle type, ie VehicleType::Road, VehicleType::Train, etc.
CargoType GetDefaultCargoType() const
Determines the default cargo type of an engine.
This struct contains all the info that is needed to draw and construct tracks.
RailTypeFlags flags
Bit mask of rail type flags.
RoadTypeFlags flags
Bit mask of road type flags.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_MAX_YEAR
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Some simple functions to help with accessing containers.
auto Slide(TIter first, TIter last, TIter position) -> std::pair< TIter, TIter >
Move elements between first and last to a new position, rotating elements in between as necessary.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
Applies two differences together.
DirDiff
Enumeration for the difference between two directions.
@ Reverse
One direction is the opposite of the other one.
@ Same
Both directions faces to the same direction.
Direction
Defines the 8 directions on the map.
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
@ SpriteStack
Draw vehicle by stacking multiple sprites.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
static const uint8_t LIT_ALL
Show the liveries of all companies.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
@ First
The first client ID.
Base for the NewGRF implementation.
constexpr uint32_t FlattenNewGRFLabel(T label)
Flatten a NewGRF related label to a 32 bits integer.
@ RoadVehicles
Road vehicles feature.
@ Invalid
An invalid spec feature.
@ Aircraft
Aircraft feature.
@ ATP_TTDP_LARGE
Same as AT_LARGE.
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Functions related to NewGRF badges.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_VEHICLE_BUILD_PROBABILITY
Called to determine probability during build.
@ CBID_VEHICLE_SPAWN_VISUAL_EFFECT
Called to spawn visual effects for vehicles.
@ CBID_VEHICLE_COLOUR_MAPPING
Called to determine if a specific colour map should be used for a vehicle instead of the default live...
@ CBID_VEHICLE_32DAY_CALLBACK
Called for every vehicle every 32 days (not all on same date though).
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
@ CBID_VEHICLE_START_STOP_CHECK
Called when the company (or AI) tries to start or stop a vehicle.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
@ CBID_TRAIN_ALLOW_WAGON_ATTACH
Determine whether a wagon can be attached to an already existing train.
@ CBID_VEHICLE_MODIFY_PROPERTY
Called to modify various vehicle properties.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Cargo support for NewGRFs.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
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.
static uint32_t PositionHelper(const Vehicle *v, bool consecutive)
Helper to get the position of a vehicle within a chain of vehicles.
static bool EnginePreSort(const EngineID &a, const EngineID &b)
Comparator function to sort engines via scope-GRFID and local ID.
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
uint16_t GetVehicleCallbackParent(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
TTDPAircraftMovementStates
TTDP style aircraft movement states for GRF Action 2 Var 0xE2.
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
static const Livery * LiveryHelper(EngineID engine, const Vehicle *v)
Determines the livery of an engine.
static uint8_t MapAircraftMovementState(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2).
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
TTDPAircraftMovementActions
TTDP style aircraft movement action for GRF Action 2 Var 0xE6.
static uint8_t MapAircraftMovementAction(const Aircraft *v)
Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This...
std::optional< bool > TestVehicleBuildProbability(Vehicle *v, BuildProbabilityType type)
Test for vehicle build probability type.
void CommitVehicleListOrderChanges()
Determine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
static const GRFFile * GetEngineGrfFile(EngineID engine_type)
Get the grf file associated with an engine type.
void AlterVehicleListOrder(EngineID engine, uint16_t target)
Record a vehicle ListOrderChange.
BuildProbabilityType
Different types of modifications during the purchase of a vehicle to request the chance for using a N...
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
Translate an index to the GRF-local railtype-translation table into a RailType.
NewGRF handling of rail types.
uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile)
Perform a reverse roadtype lookup to get the GRF internal ID.
RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8_t tracktype, const GRFFile *grffile)
Translate an index to the GRF-local road/tramtype-translation table into a RoadType.
NewGRF handling of road types.
VarSpriteGroupScope
Shared by deterministic and random groups.
@ Relative
Relative position (vehicles only).
@ Parent
Related object of the resolved one.
@ Self
Resolved object itself.
@ NoUnload
Totally no unloading will be done.
@ NoLoad
Do not load anything.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
bool IsCompatibleRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType can drive on a tile with a given RailType.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ Catenary
Bit number for drawing a catenary.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
Pseudo random number generator.
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.
bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
@ Catenary
Bit number for adding catenary.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType GetRoadType(Tile t, RoadTramType rtt)
Get the road type for the given RoadTramType.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
RoadTramType
The different types of road type.
A number of safeguards to prevent using unsafe methods.
Base classes/functions for stations.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Information about a aircraft vehicle.
uint8_t subtype
Type of aircraft.
Aircraft, helicopters, rotors and their shadows belong to this class.
uint8_t pos
Next desired position of the aircraft.
uint8_t state
State of the airport.
uint8_t turn_counter
Ticks between each turn to prevent > 45 degree turns.
StationID targetairport
Airport to go to next.
Finite sTate mAchine (FTA) of an airport.
const AirportMovingData * MovingData(uint8_t position) const
Get movement data at a position.
uint8_t delta_z
Z adjustment for helicopter pads.
AirportMovingDataFlags flags
special flags when moving towards the destination.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
VehicleType type
Type of vehicle.
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
Specification of a cargo type.
CargoClasses classes
Classes of this cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
uint8_t weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
EngineMiscFlags misc_flags
Miscellaneous flags.
GrfID grfid
grfid that introduced this entity.
uint16_t local_id
id defined by the grf file for this entity
void SetGRFFile(const struct GRFFile *grffile)
Set the NewGRF file, and its grfid, associated with grf props.
Dynamic data of a loaded NewGRF.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID).
std::vector< BadgeID > badge_list
Badge translation table (local index -> global index).
EngineID first_engine
Cached EngineID of the front vehicle. EngineID::Invalid() for the front vehicle itself.
uint32_t cached_power
Total power of the consist (valid only for the first engine).
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...
GroundVehicleCache gcache
Cache of often calculated values.
bool IsEngine() const
Check if a vehicle is an engine (can be first in a consist).
uint16_t target
GRF-local ID.
EngineID engine
Engine ID.
Information about a particular livery.
uint32_t position_in_vehicle
Cache for NewGRF var 4D.
uint32_t position_consist_length
Cache for NewGRF var 40.
uint32_t consist_cargo_information
Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF ...
uint8_t cache_valid
Bitset that indicates which cache values are valid.
uint32_t company_information
Cache for NewGRF var 43.
uint32_t position_same_id_length
Cache for NewGRF var 41.
If you change this, keep in mind that it is also saved in 2 other places:
uint16_t MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
DestinationID GetDestination() const
Gets the destination of this order.
bool IsType(OrderType type) const
Check whether this order is of the given type.
OrderUnloadType GetUnloadType() const
How must the consist be unloaded?
OrderLoadType GetLoadType() const
How must the consist be loaded?
TileIndex tile
The base tile of the area.
static Engine * Get(auto index)
static size_t GetNumItems()
static bool IsValidID(auto index)
'Real' sprite groups contain a list of other result or callback sprite groups.
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results).
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results).
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
uint32_t callback_param2
Second parameter (var 18) of the callback.
int32_t GetRegister(uint i) const
Gets the value of a so-called newgrf "register".
CallbackID callback
Callback being resolved.
uint32_t callback_param1
First parameter (var 10) of the callback.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0)
Get a resolver for the scope.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
A result sprite group returns the first SpriteID and the number of sprites in the set.
Buses, trucks and trams belong to this class.
uint16_t crashed_ctr
Animation counter when the vehicle has crashed.
uint8_t overtaking_ctr
The length of the current overtake attempt.
uint8_t overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
virtual uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const
Get a variable value.
ResolverObject & ro
Surrounding resolver object.
All ships have this type.
TrackBits state
The "track" the ship is following.
Specialization of ResolverObject with type-safe access to RandomTriggers.
T * Next() const
Get next vehicle in the chain.
static Train * From(Vehicle *v)
T * First() const
Get the first vehicle in the chain.
Common wrapper for all the different sprite group types.
virtual ResolverResult Resolve(ResolverObject &object) const =0
Resolves a callback or rerandomisation callback to a NewGRF.
Airport airport
Tile area the airport covers.
const struct SpriteGroup * cached_override
Cached wagon override spritegroup.
uint8_t user_def_data
Cached property 0x25. Can be set by Callback 0x36.
'Train' is either a loco or a wagon.
RailTypes railtypes
On which rail types the train can run.
TrackBits track
On which track the train currently is.
VehicleRailFlags flags
Which flags has this train currently set.
TrainCache tcache
Set of cached variables, recalculated on load and each time a vehicle is added to/removed from the co...
uint16_t wait_counter
Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through sign...
const struct SpriteGroup * GetFirstSpriteGroupOf(std::initializer_list< Tkey > indices) const
Get the first existing SpriteGroup from a list of options.
const SpriteGroup * GetSpriteGroup(Tkey index) const
Get the SpriteGroup at the specified index.
void SetSpriteGroup(Tkey index, const SpriteGroup *spritegroup)
Set the SpriteGroup at the specified index.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
Resolver for a vehicle (chain).
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0) override
Get a resolver for the scope.
WagonOverride
Application of 'wagon overrides'.
@ Cached
Resolve wagon overrides using TrainCache::cached_override.
@ None
Resolve no wagon overrides.
@ Uncached
Resolve wagon overrides.
@ Self
Resolve self-override (helicopter rotors and such).
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
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).
const SpriteGroup * ResolveReal(const RealSpriteGroup &group) const override
Get the real sprites of the grf.
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
uint8_t cached_relative_count
Relative position of the other vehicle.
Resolver for a vehicle scope.
uint32_t GetRandomTriggers() const override
Get the triggers.
bool rotor_in_gui
Helicopter rotor is drawn in GUI.
EngineID self_type
Type of the vehicle.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
uint32_t GetRandomBits() const override
Get a few random bits.
Sprite sequence for a vehicle part.
void Clear()
Clear all information.
Money GetDisplayProfitThisYear() const
Gets the profit vehicle had this year.
EngineID engine_type
The type of engine used for this vehicle.
int32_t z_pos
z coordinate.
Direction direction
facing
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
VehicleCargoList cargo
The cargo this vehicle is carrying.
uint16_t cargo_cap
total capacity
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
uint8_t subtype
subtype (Filled with values from AircraftSubType/DisasterSubType/EffectVehicleType/GroundVehicleSubty...
uint16_t random_bits
Bits used for randomized variational spritegroups.
uint8_t day_counter
Increased by one for each day.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
uint8_t breakdown_ctr
Counter for managing breakdown events.
uint8_t breakdown_delay
Counter for managing breakdown length.
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
VehStates vehstatus
Status.
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...
uint8_t subspeed
fractional speed
bool IsArticulatedPart() const
Check if the vehicle is an articulated part of an engine.
Vehicle * Move(int n)
Get the vehicle at offset n of this vehicle chain.
CargoType cargo_type
type of cargo this vehicle is carrying
uint8_t acceleration
used by train & aircraft
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Order current_order
The current order (+ status, like: loading).
Vehicle * Next() const
Get the next vehicle of this vehicle.
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
Money value
Value of the vehicle.
VehicleRandomTriggers waiting_random_triggers
Triggers to be yet matched before rerandomizing the random bits.
VehicleCache vcache
Cache of often used vehicle values.
uint32_t motion_counter
counter to occasionally play a vehicle sound.
NewGRFCache grf_cache
Cache of often used calculated NewGRF values.
GroundVehicleCache * GetGroundVehicleCache()
Access the ground vehicle cache of the vehicle.
virtual int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
uint16_t load_unload_ticks
Ticks to wait before starting next cycle.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
uint16_t cur_speed
current speed
uint8_t cargo_subtype
Used for livery refits (NewGRF variations).
TimerGameCalendar::Date age
Age in calendar days.
uint8_t breakdowns_since_last_service
Counter for the amount of breakdowns.
TimerGameCalendar::Date max_age
Maximum age.
uint16_t reliability
Reliability.
Vehicle * Previous() const
Get the previous vehicle of this vehicle.
uint16_t reliability_spd_dec
Reliability decrease speed.
uint8_t tick_counter
Increased by one for each tick.
TileIndex tile
Current tile index.
StationID last_station_visited
The last station we stopped at.
bool IsDrivingBackwards() const
Is this vehicle moving backwards?
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle).
uint8_t breakdown_chance
Current chance of breakdowns.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
Owner owner
Which company owns the vehicle?
UnitID unitnumber
unit number, for display purposes only
GrfID GetGRFID() const
Retrieve the GRF ID of the NewGRF the vehicle is tied to.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the game-calendar-timer.
Base for the train class.
@ Reversed
Used for vehicle var 0xFE bit 8 (toggled each time the train is reversed, accurate for first vehicle ...
@ PoweredWagon
Wagon is powered.
@ Flipped
Reverse the visible direction of the vehicle.
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.
@ Hidden
Vehicle is not visible.
@ NCVV_COMPANY_INFORMATION
This bit will be set if the NewGRF var 43 currently stored is valid.
@ NCVV_CONSIST_CARGO_INFORMATION
This bit will be set if the NewGRF var 42 currently stored is valid.
@ NCVV_POSITION_CONSIST_LENGTH
This bit will be set if the NewGRF var 40 currently stored is valid.
@ NCVV_POSITION_SAME_ID_LENGTH
This bit will be set if the NewGRF var 41 currently stored is valid.
@ NCVV_POSITION_IN_VEHICLE
This bit will be set if the NewGRF var 4D currently stored is valid.
@ NCVV_END
End of the bits.
Functions related to vehicles.
@ CUSTOM_VEHICLE_SPRITENUM
Vehicle sprite from NewGRF.
@ CUSTOM_VEHICLE_SPRITENUM_REVERSED
Vehicle sprite from NewGRF with reverse driving direction (from articulation callback).
EnumBitSet< VehicleRandomTrigger, uint8_t > VehicleRandomTriggers
Bitset of VehicleRandomTrigger elements.
EngineImageType
Visualisation contexts of vehicles and engines.
@ OnMap
Vehicle drawn in viewport.
@ Effect
Effect vehicle type (smoke, explosions, sparks, bubbles).
@ Aircraft
Aircraft vehicle type.
@ Disaster
Disaster vehicle type.
@ Train
Train vehicle type.
VehicleRandomTrigger
Randomisation triggers for vehicles.
@ Callback32
All vehicles in consist: 32 day callback requested rerandomisation.
@ NewCargo
Affected vehicle only: Vehicle is loaded with cargo, after it was empty.
@ Depot
Front vehicle only: Consist arrived in depot.
@ AnyNewCargo
All vehicles in consist: Any vehicle in the consist received new cargo.
@ Empty
Front vehicle only: Entire consist is empty.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.