54template <
typename Tdir, u
int items>
59 const std::string_view
name;
78 this->overflowed =
false;
87 return this->overflowed;
126 for (uint i = 0; i < this->n; i++) {
127 if (this->data[i].tile == tile && this->data[i].dir == dir) {
128 this->data[i] = this->data[--this->n];
144 for (uint i = 0; i < this->n; i++) {
145 if (this->data[i].tile == tile && this->data[i].dir == dir)
return true;
162 Debug(misc, 0,
"SignalSegment too complex. Set {} is full (maximum {})",
name, items);
166 this->data[this->n].tile = tile;
167 this->data[this->n].dir = dir;
181 if (this->n == 0)
return false;
184 *tile = this->data[this->n].tile;
185 *dir = this->data[this->n].dir;
227 return !
_tbdset.Remove(t2, d2);
282 while (
_tbdset.Get(&tile, &enterdir)) {
310 tracks = tracks_masked;
314 if (tracks_masked.
None())
continue;
424 while (
_tbuset.Get(&tile, &trackdir)) {
438 }
else if (
IsPbsSignal(sig) && flags.
Any({SigFlag::Split, SigFlag::MultiEnter})) {
uint Count() const
Count the number of set bits.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Iterate a range of enum values.
Definition of stuff that is very close to a company, like the company struct itself.
static constexpr Owner INVALID_OWNER
An invalid owner.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
DiagDirection
Enumeration for diagonal directions.
@ Invalid
Flag for an invalid DiagDirection.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
static bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
bool IsPbsSignal(SignalType s)
Checks whether the given signal is a path based signal.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
void SetSignalStateByTrackdir(Tile tile, Trackdir trackdir, SignalState state)
Sets the state of the signal along the given trackdir.
bool HasSignalOnTrack(Tile tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
bool IsOnewaySignal(Tile t, Track track)
Is the signal at the given track on a tile a one way signal?
bool IsPresignalExit(Tile t, Track track)
Is the signal at the given track on a tile a presignal exit signal?
SignalType GetSignalType(Tile t, Track track)
Get the signal type for a track on a tile.
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
bool HasSignals(Tile t)
Checks if a rail tile has signals.
SignalState GetSignalStateByTrackdir(Tile tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
bool IsPresignalEntry(Tile t, Track track)
Is the signal at the given track on a tile a presignal entry signal?
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
A number of safeguards to prevent using unsafe methods.
static bool IsTrainAndNotInDepot(const Vehicle *v)
Check whether there is a train on rail, not in a depot.
static Owner _last_owner
last owner whose track was put into _globset
static bool MaybeAddToTodoSet(TileIndex t1, DiagDirection d1, TileIndex t2, DiagDirection d2)
Perform some operations before adding data into Todo set The new and reverse direction is removed fro...
static constexpr DiagDirectionIndexArray< TrackdirBits > _enterdir_to_trackdirbits
Accessible TrackdirBits from a given enter direction.
static SmallSet< Trackdir, SIG_TBU_SIZE > _tbuset("_tbuset")
set of signals that will be updated
static SmallSet< DiagDirection, SIG_GLOB_SIZE > _globset("_globset")
set of places to be updated in following runs
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
Update signals, starting at one side of a tile Will check tile next to this at opposite side too.
void UpdateSignalsInBuffer()
Update signals in buffer Called from 'outside'.
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
EnumBitSet< SigFlag, uint16_t > SigFlags
Bitset of SigFlag elements.
static void ResetSets()
Reset all sets after one set overflowed.
SigFlag
Current signal block state flags.
@ MultiGreen
two or more green exits found
@ MultiExit
two or more exits found
@ MultiEnter
two or more signals entering the block found
@ Split
track merge/split found
@ Full
some of buffers was full, do not continue
@ Green
green exitsignal found
@ Train
train found in segment
@ Enter
signal entering the block found
static SmallSet< DiagDirection, SIG_TBD_SIZE > _tbdset("_tbdset")
set of open nodes in current signal block
static const uint SIG_TBU_SIZE
these are the maximums used for updating signal blocks
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
Update signals at segments that are at both ends of given (existent or non-existent) track.
static constexpr DiagDirectionIndexArray< TrackBits > _enterdir_to_trackbits
Accessible TrackBits from a given enter direction.
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
static bool CheckAddToTodoSet(TileIndex t1, DiagDirection d1, TileIndex t2, DiagDirection d2)
Perform some operations before adding data into Todo set The new and reverse direction is removed fro...
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Data related to rail signals.
SigSegState
State of the signal segment.
@ Path
Segment is a path segment.
@ Free
Free and has no pre-signal exits or at least one green exit.
@ Full
Occupied by a train.
SignalType
Type of signal, i.e.
@ Combo
presignal inter-block.
SignalState
These are states in which a signal can be.
@ Green
The signal is green.
Maps accessors for stations.
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
bool HasStationRail(Tile t)
Has this station tile a rail?
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
VehicleType type
Type of vehicle.
static bool IsValidID(auto index)
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slow...
bool Add(TileIndex tile, Tdir dir)
Adds tile & dir into the set, checks for full set Sets the 'overflowed' flag if the set was full.
SmallSet(std::string_view name)
Constructor - just set default values and 'name'.
uint n
Actual number of units.
const std::string_view name
Name, used for debugging purposes...
bool Overflowed()
Returns value of 'overflowed'.
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
void Reset()
Reset variables to default values.
uint Items()
Reads the number of items.
bool overflowed
Did we try to overflow the set?
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
bool IsEmpty()
Checks for empty set.
bool IsFull()
Checks for full set.
static Train * From(Vehicle *v)
'Train' is either a loco or a wagon.
TrackBits track
On which track the train currently is.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ TunnelBridge
Tunnel entry/exit and bridge heads.
@ Station
A tile of a station or airport.
@ Railway
A tile with railway.
@ Road
A tile with road and/or tram tracks.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
static constexpr TrackBits TRACK_BIT_3WAY_NE
"Arrow" to the north-east
static constexpr TrackBits TRACK_BIT_HORZ
Upper and lower track.
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Trackdir
Enumeration for tracks and directions.
@ Right_N
Right track and direction to north.
@ X_NE
X-axis and direction to north-east.
@ Right_S
Right track and direction to south.
@ Left_S
Left track and direction to south.
@ Lower_E
Lower track and direction to east.
@ X_SW
X-axis and direction to south-west.
@ Invalid
Flag for an invalid trackdir.
@ Y_SE
Y-axis and direction to south-east.
@ Y_NW
Y-axis and direction to north-west.
@ Upper_W
Upper track and direction to west.
@ Upper_E
Upper track and direction to east.
@ Left_N
Left track and direction to north.
@ Lower_W
Lower track and direction to west.
static constexpr TrackBits TRACK_BIT_VERT
Left and right track.
static constexpr TrackBits TRACK_BIT_3WAY_SW
"Arrow" to the south-west
static constexpr TrackBits TRACK_BIT_3WAY_SE
"Arrow" to the south-east
static constexpr TrackBits TRACK_BIT_3WAY_NW
"Arrow" to the north-west
Track
These are used to specify a single track.
@ Depot
Special flag indicating a vehicle is inside a depot.
Base for the train class.
@ TRANSPORT_RAIL
Transport by train.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
Functions related to vehicles.
bool HasVehicleOnTile(TileIndex tile, UnaryPred &&predicate)
Loop over vehicles on a tile, and check whether a predicate is true for any of them.
@ Train
Train vehicle type.
Functions related to (drawing on) viewports.