OpenTTD Source 20260311-master-g511d3794ce
signal.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "debug.h"
12#include "station_map.h"
13#include "tunnelbridge_map.h"
14#include "vehicle_func.h"
15#include "viewport_func.h"
16#include "train.h"
17#include "company_base.h"
18#include "pbs.h"
19
20#include "table/signal_data.h"
21
22#include "safeguards.h"
23
24
26static const uint SIG_TBU_SIZE = 64;
27static const uint SIG_TBD_SIZE = 256;
28static const uint SIG_GLOB_SIZE = 128;
29static const uint SIG_GLOB_UPDATE = 64;
30
31static_assert(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
32
40
48
54template <typename Tdir, uint items>
55struct SmallSet {
56private:
57 uint n = 0;
58 bool overflowed = false;
59 const std::string_view name;
60
62 struct SSdata {
63 TileIndex tile;
64 Tdir dir;
65 } data[items];
66
67public:
72 SmallSet(std::string_view name) : name(name) { }
73
75 void Reset()
76 {
77 this->n = 0;
78 this->overflowed = false;
79 }
80
86 {
87 return this->overflowed;
88 }
89
94 bool IsEmpty()
95 {
96 return this->n == 0;
97 }
98
103 bool IsFull()
104 {
105 return this->n == lengthof(data);
106 }
107
112 uint Items()
113 {
114 return this->n;
115 }
116
117
124 bool Remove(TileIndex tile, Tdir dir)
125 {
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];
129 return true;
130 }
131 }
132
133 return false;
134 }
135
142 bool IsIn(TileIndex tile, Tdir dir)
143 {
144 for (uint i = 0; i < this->n; i++) {
145 if (this->data[i].tile == tile && this->data[i].dir == dir) return true;
146 }
147
148 return false;
149 }
150
158 bool Add(TileIndex tile, Tdir dir)
159 {
160 if (this->IsFull()) {
161 overflowed = true;
162 Debug(misc, 0, "SignalSegment too complex. Set {} is full (maximum {})", name, items);
163 return false; // set is full
164 }
165
166 this->data[this->n].tile = tile;
167 this->data[this->n].dir = dir;
168 this->n++;
169
170 return true;
171 }
172
179 bool Get(TileIndex *tile, Tdir *dir)
180 {
181 if (this->n == 0) return false;
182
183 this->n--;
184 *tile = this->data[this->n].tile;
185 *dir = this->data[this->n].dir;
186
187 return true;
188 }
189};
190
194
195
201static bool IsTrainAndNotInDepot(const Vehicle *v)
202{
203 return v->type == VEH_TRAIN && Train::From(v)->track != TRACK_BIT_DEPOT;
204}
205
206
221{
222 _globset.Remove(t1, d1); // it can be in Global but not in Todo
223 _globset.Remove(t2, d2); // remove in all cases
224
225 assert(!_tbdset.IsIn(t1, d1)); // it really shouldn't be there already
226
227 return !_tbdset.Remove(t2, d2);
228}
229
230
245{
246 if (!CheckAddToTodoSet(t1, d1, t2, d2)) return true;
247
248 return _tbdset.Add(t1, d1);
249}
250
251
265using SigFlags = EnumBitSet<SigFlag, uint16_t>;
266
273static SigFlags ExploreSegment(Owner owner)
274{
275 SigFlags flags{};
276
277 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
279
280 while (_tbdset.Get(&tile, &enterdir)) { // tile and enterdir are initialized here, unless I'm mistaken.
281 TileIndex oldtile = tile; // tile we are leaving
282 DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
283
284 switch (GetTileType(tile)) {
285 case TileType::Railway: {
286 if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
287
288 if (IsRailDepot(tile)) {
289 if (enterdir == INVALID_DIAGDIR) { // from 'inside' - train just entered or left the depot
291 exitdir = GetRailDepotDirection(tile);
292 tile += TileOffsByDiagDir(exitdir);
293 enterdir = ReverseDiagDir(exitdir);
294 break;
295 } else if (enterdir == GetRailDepotDirection(tile)) { // entered a depot
297 continue;
298 } else {
299 continue;
300 }
301 }
302
303 assert(IsValidDiagDirection(enterdir));
304 TrackBits tracks = GetTrackBits(tile); // trackbits of tile
305 TrackBits tracks_masked = (TrackBits)(tracks & _enterdir_to_trackbits[enterdir]); // only incidating trackbits
306
307 if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
308 tracks = tracks_masked;
309 /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
310 if (!flags.Test(SigFlag::Train) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags. Set(SigFlag::Train);
311 } else {
312 if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
314 }
315
316 /* Is this a track merge or split? */
317 if (!HasAtMostOneBit(tracks)) flags.Set(SigFlag::Split);
318
319 if (HasSignals(tile)) { // there is exactly one track - not zero, because there is exit from this tile
320 Track track = TrackBitsToTrack(tracks_masked); // mask TRACK_BIT_X and Y too
321 if (HasSignalOnTrack(tile, track)) { // now check whole track, not trackdir
322 SignalType sig = GetSignalType(tile, track);
323 Trackdir trackdir = (Trackdir)FindFirstBit((tracks * 0x101U) & _enterdir_to_trackdirbits[enterdir]);
324 Trackdir reversedir = ReverseTrackdir(trackdir);
325 /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
326 * ANY conventional signal in REVERSE direction
327 * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
328 if (HasSignalOnTrackdir(tile, reversedir)) {
329 if (IsPbsSignal(sig)) flags.Set(SigFlag::Pbs);
330 if (flags.Test(SigFlag::Enter)) flags.Set(SigFlag::MultiEnter);
331 flags.Set(SigFlag::Enter);
332
333 if (!_tbuset.Add(tile, reversedir)) return flags | SigFlag::Full;
334 }
335 if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags.Set(SigFlag::Pbs);
336
337 /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
338 if (!flags.Test(SigFlag::MultiGreen) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
339 if (flags.Test(SigFlag::Exit)) flags.Set(SigFlag::MultiExit); // found two (or more) exits
340 flags.Set(SigFlag::Exit); // found at least one exit - allow for compiler optimizations
341 if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
342 if (flags.Test(SigFlag::Green)) flags.Set(SigFlag::MultiGreen);
343 flags.Set(SigFlag::Green);
344 }
345 }
346
347 continue;
348 }
349 }
350
351 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
352 if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
353 TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
354 DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
355 if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SigFlag::Full;
356 }
357 }
358
359 continue; // continue the while() loop
360 }
361
363 if (!HasStationRail(tile)) continue;
364 if (GetTileOwner(tile) != owner) continue;
365 if (DiagDirToAxis(enterdir) != GetRailStationAxis(tile)) continue; // different axis
366 if (IsStationTileBlocked(tile)) continue; // 'eye-candy' station tile
367
369 tile += TileOffsByDiagDir(exitdir);
370 break;
371
372 case TileType::Road:
373 if (!IsLevelCrossing(tile)) continue;
374 if (GetTileOwner(tile) != owner) continue;
375 if (DiagDirToAxis(enterdir) == GetCrossingRoadAxis(tile)) continue; // different axis
376
378 tile += TileOffsByDiagDir(exitdir);
379 break;
380
382 if (GetTileOwner(tile) != owner) continue;
383 if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
385
386 if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
388 enterdir = dir;
389 exitdir = ReverseDiagDir(dir);
390 tile += TileOffsByDiagDir(exitdir); // just skip to next tile
391 } else { // NOT incoming from the wormhole!
392 if (ReverseDiagDir(enterdir) != dir) continue;
394 tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
395 enterdir = INVALID_DIAGDIR;
396 exitdir = INVALID_DIAGDIR;
397 }
398 }
399 break;
400
401 default:
402 continue; // continue the while() loop
403 }
404
405 if (!MaybeAddToTodoSet(tile, enterdir, oldtile, exitdir)) return flags | SigFlag::Full;
406 }
407
408 return flags;
409}
410
411
417static void UpdateSignalsAroundSegment(SigFlags flags)
418{
419 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
420 Trackdir trackdir = INVALID_TRACKDIR;
421
422 while (_tbuset.Get(&tile, &trackdir)) {
423 assert(HasSignalOnTrackdir(tile, trackdir));
424
425 Track track = TrackdirToTrack(trackdir);
426 SignalType sig = GetSignalType(tile, track);
428
429 /* Signal state of reserved path signals is handled by the reserve/unreserve process. */
430 if (IsPbsSignal(sig) && (GetRailReservationTrackBits(tile) & TrackToTrackBits(track)) != TRACK_BIT_NONE) continue;
431
432 /* determine whether the new state is red */
433 if (flags.Test(SigFlag::Train)) {
434 /* train in the segment */
435 newstate = SIGNAL_STATE_RED;
436 } else if (IsPbsSignal(sig) && flags.Any({SigFlag::Split, SigFlag::MultiEnter})) {
437 /* Turn path signals red if the segment has a junction or more than one way in. */
438 newstate = SIGNAL_STATE_RED;
439 } else {
440 /* is it a bidir combo? - then do not count its other signal direction as exit */
441 if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
442 /* at least one more exit */
443 if (flags.Test(SigFlag::MultiExit) &&
444 /* no green exit */
445 (!flags.Test(SigFlag::Green) ||
446 /* only one green exit, and it is this one - so all other exits are red */
448 newstate = SIGNAL_STATE_RED;
449 }
450 } else { // entry, at least one exit, no green exit
451 if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && flags.Test(SigFlag::Exit) && !flags.Test(SigFlag::Green)) newstate = SIGNAL_STATE_RED;
452 }
453 }
454
455 /* only when the state changes */
456 if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
457 if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
458 /* for pre-signal exits, add block to the global set */
460 _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
461 }
462 SetSignalStateByTrackdir(tile, trackdir, newstate);
464 }
465 }
466
467}
468
469
471static inline void ResetSets()
472{
473 _tbuset.Reset();
474 _tbdset.Reset();
475 _globset.Reset();
476}
477
478
487{
488 assert(Company::IsValidID(owner));
489
490 bool first = true; // first block?
491 SigSegState state = SIGSEG_FREE; // value to return
492
493 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
495
496 while (_globset.Get(&tile, &dir)) {
497 assert(_tbuset.IsEmpty());
498 assert(_tbdset.IsEmpty());
499
500 /* After updating signal, data stored are always TileType::Railway with signals.
501 * Other situations happen when data are from outside functions -
502 * modification of railbits (including both rail building and removal),
503 * train entering/leaving block, train leaving depot...
504 */
505 switch (GetTileType(tile)) {
507 /* 'optimization assert' - do not try to update signals when it is not needed */
509 assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
510 _tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
512 break;
513
515 if (IsRailDepot(tile)) {
516 /* 'optimization assert' do not try to update signals in other cases */
517 assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
518 _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
519 break;
520 }
521 [[fallthrough]];
522
524 case TileType::Road:
526 /* only add to set when there is some 'interesting' track */
527 _tbdset.Add(tile, dir);
528 _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
529 break;
530 }
531 [[fallthrough]];
532
533 default:
534 /* jump to next tile */
535 tile = tile + TileOffsByDiagDir(dir);
536 dir = ReverseDiagDir(dir);
538 _tbdset.Add(tile, dir);
539 break;
540 }
541 /* happens when removing a rail that wasn't connected at one or both sides */
542 continue; // continue the while() loop
543 }
544
545 assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
546 assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
547
548 SigFlags flags = ExploreSegment(owner);
549
550 if (first) {
551 first = false;
552 /* SIGSEG_FREE is set by default */
553 if (flags.Test(SigFlag::Pbs)) {
554 state = SIGSEG_PBS;
555 } else if (flags.Test(SigFlag::Train) || (flags.Test(SigFlag::Exit) && !flags.Test(SigFlag::Green)) || flags.Test(SigFlag::Full)) {
556 state = SIGSEG_FULL;
557 }
558 }
559
560 /* do not do anything when some buffer was full */
561 if (flags.Test(SigFlag::Full)) {
562 ResetSets(); // free all sets
563 break;
564 }
565
567 }
568
569 return state;
570}
571
572
574
575
581{
582 if (!_globset.IsEmpty()) {
584 _last_owner = INVALID_OWNER; // invalidate
585 }
586}
587
588
596void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
597{
598 static const DiagDirection _search_dir_1[] = {
600 };
601 static const DiagDirection _search_dir_2[] = {
603 };
604
605 /* do not allow signal updates for two companies in one run */
606 assert(_globset.IsEmpty() || owner == _last_owner);
607
608 _last_owner = owner;
609
610 _globset.Add(tile, _search_dir_1[track]);
611 _globset.Add(tile, _search_dir_2[track]);
612
613 if (_globset.Items() >= SIG_GLOB_UPDATE) {
614 /* too many items, force update */
617 }
618}
619
620
628void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
629{
630 /* do not allow signal updates for two companies in one run */
631 assert(_globset.IsEmpty() || owner == _last_owner);
632
633 _last_owner = owner;
634
635 _globset.Add(tile, side);
636
637 if (_globset.Items() >= SIG_GLOB_UPDATE) {
638 /* too many items, force update */
641 }
642}
643
655{
656 assert(_globset.IsEmpty());
657 _globset.Add(tile, side);
658
659 return UpdateSignalsInBuffer(owner);
660}
661
662
672void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
673{
674 assert(_globset.IsEmpty());
675
676 AddTrackToSignalBuffer(tile, track, owner);
678}
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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Enum-as-bit-set wrapper.
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.
Definition debug.h:37
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_NW
Northwest.
@ DIAGDIR_SE
Southeast.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ DIAGDIR_SW
Southwest.
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.
Definition map_func.h:574
PBS support routines.
bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Definition rail_map.h:491
static bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
Definition rail_map.h:95
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
bool IsPbsSignal(SignalType s)
Checks whether the given signal is a path based signal.
Definition rail_map.h:292
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
Definition rail_map.h:171
void SetSignalStateByTrackdir(Tile tile, Trackdir trackdir, SignalState state)
Sets the state of the signal along the given trackdir.
Definition rail_map.h:520
bool HasSignalOnTrack(Tile tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
Definition rail_map.h:475
bool IsOnewaySignal(Tile t, Track track)
Is the signal at the given track on a tile a one way signal?
Definition rail_map.h:358
bool IsPresignalExit(Tile t, Track track)
Is the signal at the given track on a tile a presignal exit signal?
Definition rail_map.h:345
SignalType GetSignalType(Tile t, Track track)
Get the signal type for a track on a tile.
Definition rail_map.h:304
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
Definition rail_map.h:194
bool HasSignals(Tile t)
Checks if a rail tile has signals.
Definition rail_map.h:72
SignalState GetSignalStateByTrackdir(Tile tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
Definition rail_map.h:506
bool IsPresignalEntry(Tile t, Track track)
Is the signal at the given track on a tile a presignal entry signal?
Definition rail_map.h:333
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
Definition road_map.h:335
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
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.
Definition signal.cpp:201
static Owner _last_owner
last owner whose track was put into _globset
Definition signal.cpp:573
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...
Definition signal.cpp:244
static const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END]
incidating trackdirbits with given enterdir
Definition signal.cpp:42
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.
Definition signal.cpp:596
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.
Definition signal.cpp:654
void UpdateSignalsInBuffer()
Update signals in buffer Called from 'outside'.
Definition signal.cpp:580
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
Definition signal.cpp:27
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition signal.cpp:628
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
Definition signal.cpp:28
static void ResetSets()
Reset all sets after one set overflowed.
Definition signal.cpp:471
SigFlag
Current signal block state flags.
Definition signal.cpp:253
@ MultiGreen
two or more green exits found
Definition signal.cpp:258
@ MultiExit
two or more exits found
Definition signal.cpp:256
@ Pbs
pbs signal found
Definition signal.cpp:260
@ MultiEnter
two or more signals entering the block found
Definition signal.cpp:263
@ Split
track merge/split found
Definition signal.cpp:261
@ Full
some of buffers was full, do not continue
Definition signal.cpp:259
@ Green
green exitsignal found
Definition signal.cpp:257
@ Train
train found in segment
Definition signal.cpp:254
@ Enter
signal entering the block found
Definition signal.cpp:262
@ Exit
exitsignal found
Definition signal.cpp:255
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
Definition signal.cpp:26
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
Definition signal.cpp:417
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
Update signals at segments that are at both ends of given (existent or non-existent) track.
Definition signal.cpp:672
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
Definition signal.cpp:29
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...
Definition signal.cpp:220
static const TrackBits _enterdir_to_trackbits[DIAGDIR_END]
incidating trackbits with given enterdir
Definition signal.cpp:34
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Definition signal.cpp:273
Data related to rail signals.
SigSegState
State of the signal segment.
Definition signal_func.h:55
@ SIGSEG_PBS
Segment is a PBS segment.
Definition signal_func.h:58
@ SIGSEG_FREE
Free and has no pre-signal exits or at least one green exit.
Definition signal_func.h:56
@ SIGSEG_FULL
Occupied by a train.
Definition signal_func.h:57
SignalType
Type of signal, i.e.
Definition signal_type.h:23
@ SIGTYPE_COMBO
presignal inter-block
Definition signal_type.h:27
SignalState
These are states in which a signal can be.
Definition signal_type.h:42
@ SIGNAL_STATE_RED
The signal is red.
Definition signal_type.h:43
@ SIGNAL_STATE_GREEN
The signal is green.
Definition signal_type.h:44
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.
Definition stdafx.h:271
VehicleType type
Type of vehicle.
Element of set.
Definition signal.cpp:62
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slow...
Definition signal.cpp:55
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.
Definition signal.cpp:158
SmallSet(std::string_view name)
Constructor - just set default values and 'name'.
Definition signal.cpp:72
uint n
Actual number of units.
Definition signal.cpp:57
const std::string_view name
Name, used for debugging purposes...
Definition signal.cpp:59
bool Overflowed()
Returns value of 'overflowed'.
Definition signal.cpp:85
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
Definition signal.cpp:124
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
Definition signal.cpp:179
void Reset()
Reset variables to default values.
Definition signal.cpp:75
uint Items()
Reads the number of items.
Definition signal.cpp:112
bool overflowed
Did we try to overflow the set?
Definition signal.cpp:58
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
Definition signal.cpp:142
bool IsEmpty()
Checks for empty set.
Definition signal.cpp:94
bool IsFull()
Checks for full set.
Definition signal.cpp:103
static Train * From(Vehicle *v)
'Train' is either a loco or a wagon.
Definition train.h:97
TrackBits track
On which track the train currently is.
Definition train.h:110
Vehicle data structure.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
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.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Railway
A tile with railway.
Definition tile_type.h:50
@ Road
A tile with road and/or tram tracks.
Definition tile_type.h:51
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition track_func.h:262
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition track_func.h:77
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition track_func.h:193
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition track_func.h:247
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition track_func.h:365
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition track_func.h:441
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition track_type.h:53
@ TRACK_BIT_HORZ
Upper and lower track.
Definition track_type.h:44
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
@ TRACK_BIT_3WAY_NW
"Arrow" to the north-west
Definition track_type.h:49
@ TRACK_BIT_3WAY_NE
"Arrow" to the north-east
Definition track_type.h:46
@ TRACK_BIT_3WAY_SW
"Arrow" to the south-west
Definition track_type.h:48
@ TRACK_BIT_VERT
Left and right track.
Definition track_type.h:45
@ TRACK_BIT_3WAY_SE
"Arrow" to the south-east
Definition track_type.h:47
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
TrackdirBits
Allow incrementing of Trackdir variables.
Definition track_type.h:97
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
Definition track_type.h:103
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition track_type.h:107
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
Definition track_type.h:101
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition track_type.h:99
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
Definition track_type.h:102
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
Definition track_type.h:110
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
Definition track_type.h:104
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition track_type.h:100
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
Definition track_type.h:111
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
Definition track_type.h:108
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
Definition track_type.h:109
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition track_type.h:106
Track
These are used to specify a single track.
Definition track_type.h:19
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.
Definition vehicle.cpp:604
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.
@ VEH_TRAIN
Train vehicle type.
Functions related to (drawing on) viewports.