52 template <
typename Tdir, u
int items>
67 SmallSet(
const char *name) : n(0), overflowed(false), name(name) { }
73 this->overflowed =
false;
82 return this->overflowed;
121 for (uint i = 0; i < this->n; i++) {
122 if (this->data[i].tile == tile && this->data[i].dir == dir) {
123 this->data[i] = this->data[--this->n];
139 for (uint i = 0; i < this->n; i++) {
140 if (this->data[i].tile == tile && this->data[i].dir == dir)
return true;
157 Debug(misc, 0,
"SignalSegment too complex. Set {} is full (maximum {})", name, items);
161 this->data[this->n].tile = tile;
162 this->data[this->n].dir = dir;
176 if (this->n == 0)
return false;
179 *tile = this->data[this->n].tile;
180 *dir = this->data[this->n].dir;
220 return !
_tbdset.Remove(t2, d2);
276 while (
_tbdset.Get(&tile, &enterdir)) {
304 tracks = tracks_masked;
325 if (IsPbsSignal(sig)) flags |=
SF_PBS;
418 while (
_tbuset.Get(&tile, &trackdir)) {
606 _globset.Add(tile, _search_dir_1[track]);
607 _globset.Add(tile, _search_dir_2[track]);
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
bool Failed() const
Did this command fail?
Definition of stuff that is very close to a company, like the company struct itself.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Owner
Enum for all companies/owners.
@ INVALID_OWNER
An invalid owner.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut 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.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
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, uint 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.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
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)
One-way signals can't be passed the 'wrong' way.
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
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.
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 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 SmallSet< Trackdir, SIG_TBU_SIZE > _tbuset("_tbuset")
set of signals that will be updated
static const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END]
incidating trackdirbits with given enterdir
static SmallSet< DiagDirection, SIG_GLOB_SIZE > _globset("_globset")
set of places to be updated in following runs
static Vehicle * TrainOnTileEnum(Vehicle *v, void *)
Check whether there is a train on rail, not in a depot.
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.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
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)
static void ResetSets()
Reset all sets after one set overflowed.
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.
static SmallSet< DiagDirection, SIG_TBD_SIZE > _tbdset("_tbdset")
set of open nodes in current signal block
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
Update signals at segments that are at both ends of given (existent or non-existent) track.
SigFlags
Current signal block state flags.
@ SF_SPLIT
track merge/split found
@ SF_GREEN2
two or more green exits found
@ SF_EXIT2
two or more exits found
@ SF_ENTER2
two or more signals entering the block found
@ SF_GREEN
green exitsignal found
@ SF_ENTER
signal entering the block found
@ SF_EXIT
exitsignal found
@ SF_FULL
some of buffers was full, do not continue
@ SF_TRAIN
train found in segment
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 const TrackBits _enterdir_to_trackbits[DIAGDIR_END]
incidating trackbits with given enterdir
static SigFlags ExploreSegment(Owner owner)
Search signal block.
SigSegState
State of the signal segment.
@ SIGSEG_PBS
Segment is a PBS segment.
@ SIGSEG_FREE
Free and has no pre-signal exits or at least one green exit.
@ SIGSEG_FULL
Occupied by a train.
SignalType
Type of signal, i.e.
@ SIGTYPE_COMBO
presignal inter-block
SignalState
These are states in which a signal can be.
@ SIGNAL_STATE_RED
The signal is red.
@ SIGNAL_STATE_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? In other words, is this station tile a rail station or rail waypoint?
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(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
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.
bool Overflowed()
Returns value of 'overflowed'.
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
SmallSet(const char *name)
Constructor - just set default values and 'name'.
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 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 T * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_ROAD
A tile with road (or tram tracks)
@ MP_STATION
A tile of a station.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
TrackBits
Allow incrementing of Track variables.
@ TRACK_BIT_DEPOT
Bitflag for a depot.
@ TRACK_BIT_HORZ
Upper and lower track.
@ TRACK_BIT_NONE
No track.
@ TRACK_BIT_3WAY_NW
"Arrow" to the north-west
@ TRACK_BIT_3WAY_NE
"Arrow" to the north-east
@ TRACK_BIT_3WAY_SW
"Arrow" to the south-west
@ TRACK_BIT_VERT
Left and right track.
@ TRACK_BIT_3WAY_SE
"Arrow" to the south-east
Trackdir
Enumeration for tracks and directions.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
TrackdirBits
Allow incrementing of Trackdir variables.
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Track
These are used to specify a single track.
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.
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Functions related to vehicles.
@ VEH_TRAIN
Train vehicle type.
Functions related to (drawing on) viewports.