OpenTTD Source 20261112-master-gbcbec5e63f
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
19#include "table/signal_data.h"
20
21#include "safeguards.h"
22
23
25static const uint SIG_TBU_SIZE = 64;
26static const uint SIG_TBD_SIZE = 256;
27static const uint SIG_GLOB_SIZE = 128;
28static const uint SIG_GLOB_UPDATE = 64;
29
30static_assert(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
31
39
47
53template <typename Tdir, uint items>
54struct SmallSet {
55private:
56 uint n = 0;
57 bool overflowed = false;
58 const std::string_view name;
59
61 struct SSdata {
62 TileIndex tile;
63 Tdir dir;
64 } data[items];
65
66public:
71 SmallSet(std::string_view name) : name(name) { }
72
74 void Reset()
75 {
76 this->n = 0;
77 this->overflowed = false;
78 }
79
85 {
86 return this->overflowed;
87 }
88
93 bool IsEmpty()
94 {
95 return this->n == 0;
96 }
97
102 bool IsFull()
103 {
104 return this->n == lengthof(data);
105 }
106
111 uint Items()
112 {
113 return this->n;
114 }
115
116
123 bool Remove(TileIndex tile, Tdir dir)
124 {
125 for (uint i = 0; i < this->n; i++) {
126 if (this->data[i].tile == tile && this->data[i].dir == dir) {
127 this->data[i] = this->data[--this->n];
128 return true;
129 }
130 }
131
132 return false;
133 }
134
141 bool IsIn(TileIndex tile, Tdir dir)
142 {
143 for (uint i = 0; i < this->n; i++) {
144 if (this->data[i].tile == tile && this->data[i].dir == dir) return true;
145 }
146
147 return false;
148 }
149
157 bool Add(TileIndex tile, Tdir dir)
158 {
159 if (this->IsFull()) {
160 overflowed = true;
161 Debug(Facility::Misc, Severity::Critical, "SignalSegment too complex. Set {} is full (maximum {})", name, items);
162 return false; // set is full
163 }
164
165 this->data[this->n].tile = tile;
166 this->data[this->n].dir = dir;
167 this->n++;
168
169 return true;
170 }
171
178 bool Get(TileIndex *tile, Tdir *dir)
179 {
180 if (this->n == 0) return false;
181
182 this->n--;
183 *tile = this->data[this->n].tile;
184 *dir = this->data[this->n].dir;
185
186 return true;
187 }
188};
189
193
194
200static bool IsTrainAndNotInDepot(const Vehicle *v)
201{
203}
204
205
220{
221 _globset.Remove(t1, d1); // it can be in Global but not in Todo
222 _globset.Remove(t2, d2); // remove in all cases
223
224 assert(!_tbdset.IsIn(t1, d1)); // it really shouldn't be there already
225
226 return !_tbdset.Remove(t2, d2);
227}
228
229
244{
245 if (!CheckAddToTodoSet(t1, d1, t2, d2)) return true;
246
247 return _tbdset.Add(t1, d1);
248}
249
250
264
267
274static SigFlags ExploreSegment(Owner owner)
275{
276 SigFlags flags{};
277
278 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
280
281 while (_tbdset.Get(&tile, &enterdir)) { // tile and enterdir are initialized here, unless I'm mistaken.
282 TileIndex oldtile = tile; // tile we are leaving
283 DiagDirection exitdir = enterdir == DiagDirection::Invalid ? DiagDirection::Invalid : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
284
285 switch (GetTileType(tile)) {
286 case TileType::Railway: {
287 if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
288
289 if (IsRailDepot(tile)) {
290 if (enterdir == DiagDirection::Invalid) { // from 'inside' - train just entered or left the depot
292 exitdir = GetRailDepotDirection(tile);
293 tile += TileOffsByDiagDir(exitdir);
294 enterdir = ReverseDiagDir(exitdir);
295 break;
296 } else if (enterdir == GetRailDepotDirection(tile)) { // entered a depot
298 continue;
299 } else {
300 continue;
301 }
302 }
303
304 assert(IsValidDiagDirection(enterdir));
305 TrackBits tracks = GetTrackBits(tile); // trackbits of tile
306 TrackBits tracks_masked = tracks & _enterdir_to_trackbits[enterdir]; // only accessible trackbits
307
308 if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one accessible track, no need to check
309 tracks = tracks_masked;
310 /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
311 if (!flags.Test(SigFlag::Train) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags. Set(SigFlag::Train);
312 } else {
313 if (tracks_masked.None()) continue; // no accessible track
315 }
316
317 /* Is this a track merge or split? */
318 if (tracks.Count() > 1) flags.Set(SigFlag::Split);
319
320 if (HasSignals(tile)) { // there is exactly one track - not zero, because there is exit from this tile
321 Track track = TrackBitsToTrack(tracks_masked); // mask TRACK_BIT_X and Y too
322 if (HasSignalOnTrack(tile, track)) { // now check whole track, not trackdir
323 SignalType sig = GetSignalType(tile, track);
324 Trackdir trackdir = (TrackBitsToTrackdirBits(tracks) & _enterdir_to_trackdirbits[enterdir]).GetNthSetBit(0).value();
325 Trackdir reversedir = ReverseTrackdir(trackdir);
326 /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
327 * ANY conventional signal in REVERSE direction
328 * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
329 if (HasSignalOnTrackdir(tile, reversedir)) {
330 if (IsPbsSignal(sig)) flags.Set(SigFlag::Pbs);
331 if (flags.Test(SigFlag::Enter)) flags.Set(SigFlag::MultiEnter);
332 flags.Set(SigFlag::Enter);
333
334 if (!_tbuset.Add(tile, reversedir)) return flags | SigFlag::Full;
335 }
336 if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags.Set(SigFlag::Pbs);
337
338 /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
339 if (!flags.Test(SigFlag::MultiGreen) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
340 if (flags.Test(SigFlag::Exit)) flags.Set(SigFlag::MultiExit); // found two (or more) exits
341 flags.Set(SigFlag::Exit); // found at least one exit - allow for compiler optimizations
342 if (GetSignalStateByTrackdir(tile, trackdir) == SignalState::Green) { // found green presignal exit
343 if (flags.Test(SigFlag::Green)) flags.Set(SigFlag::MultiGreen);
344 flags.Set(SigFlag::Green);
345 }
346 }
347
348 continue;
349 }
350 }
351
352 for (DiagDirection dir : EnumRange(DiagDirection::End)) { // test all possible exit directions
353 if (dir != enterdir && tracks.Any(_enterdir_to_trackbits[dir])) { // any accessible track?
354 TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
355 DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
356 if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SigFlag::Full;
357 }
358 }
359
360 continue; // continue the while() loop
361 }
362
364 if (!HasStationRail(tile)) continue;
365 if (GetTileOwner(tile) != owner) continue;
366 if (DiagDirToAxis(enterdir) != GetRailStationAxis(tile)) continue; // different axis
367 if (IsStationTileBlocked(tile)) continue; // 'eye-candy' station tile
368
370 tile += TileOffsByDiagDir(exitdir);
371 break;
372
373 case TileType::Road:
374 if (!IsLevelCrossing(tile)) continue;
375 if (GetTileOwner(tile) != owner) continue;
376 if (DiagDirToAxis(enterdir) == GetCrossingRoadAxis(tile)) continue; // different axis
377
379 tile += TileOffsByDiagDir(exitdir);
380 break;
381
383 if (GetTileOwner(tile) != owner) continue;
386
387 if (enterdir == DiagDirection::Invalid) { // incoming from the wormhole
389 enterdir = dir;
390 exitdir = ReverseDiagDir(dir);
391 tile += TileOffsByDiagDir(exitdir); // just skip to next tile
392 } else { // NOT incoming from the wormhole!
393 if (ReverseDiagDir(enterdir) != dir) continue;
395 tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
396 enterdir = DiagDirection::Invalid;
397 exitdir = DiagDirection::Invalid;
398 }
399 }
400 break;
401
402 default:
403 continue; // continue the while() loop
404 }
405
406 if (!MaybeAddToTodoSet(tile, enterdir, oldtile, exitdir)) return flags | SigFlag::Full;
407 }
408
409 return flags;
410}
411
412
419{
420 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
421 Trackdir trackdir = Trackdir::Invalid;
422
423 while (_tbuset.Get(&tile, &trackdir)) {
424 assert(HasSignalOnTrackdir(tile, trackdir));
425
426 Track track = TrackdirToTrack(trackdir);
427 SignalType sig = GetSignalType(tile, track);
429
430 /* Signal state of reserved path signals is handled by the reserve/unreserve process. */
431 if (IsPbsSignal(sig) && GetRailReservationTrackBits(tile).Test(track)) continue;
432
433 /* determine whether the new state is red */
434 if (flags.Test(SigFlag::Train)) {
435 /* train in the segment */
436 newstate = SignalState::Red;
437 } else if (IsPbsSignal(sig) && flags.Any({SigFlag::Split, SigFlag::MultiEnter})) {
438 /* Turn path signals red if the segment has a junction or more than one way in. */
439 newstate = SignalState::Red;
440 } else {
441 /* is it a bidir combo? - then do not count its other signal direction as exit */
442 if (sig == SignalType::Combo && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
443 /* at least one more exit */
444 if (flags.Test(SigFlag::MultiExit) &&
445 /* no green exit */
446 (!flags.Test(SigFlag::Green) ||
447 /* only one green exit, and it is this one - so all other exits are red */
449 newstate = SignalState::Red;
450 }
451 } else { // entry, at least one exit, no green exit
452 if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && flags.Test(SigFlag::Exit) && !flags.Test(SigFlag::Green)) newstate = SignalState::Red;
453 }
454 }
455
456 /* only when the state changes */
457 if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
458 if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
459 /* for pre-signal exits, add block to the global set */
461 _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
462 }
463 SetSignalStateByTrackdir(tile, trackdir, newstate);
465 }
466 }
467
468}
469
470
472static inline void ResetSets()
473{
474 _tbuset.Reset();
475 _tbdset.Reset();
476 _globset.Reset();
477}
478
479
488{
489 assert(Company::IsValidID(owner));
490
491 bool first = true; // first block?
492 SigSegState state = SigSegState::Free; // value to return
493
494 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
496
497 while (_globset.Get(&tile, &dir)) {
498 assert(_tbuset.IsEmpty());
499 assert(_tbdset.IsEmpty());
500
501 /* After updating signal, data stored are always TileType::Railway with signals.
502 * Other situations happen when data are from outside functions -
503 * modification of railbits (including both rail building and removal),
504 * train entering/leaving block, train leaving depot...
505 */
506 switch (GetTileType(tile)) {
508 /* 'optimization assert' - do not try to update signals when it is not needed */
510 assert(dir == DiagDirection::Invalid || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
511 _tbdset.Add(tile, DiagDirection::Invalid); // we can safely start from wormhole centre
513 break;
514
516 if (IsRailDepot(tile)) {
517 /* 'optimization assert' do not try to update signals in other cases */
518 assert(dir == DiagDirection::Invalid || dir == GetRailDepotDirection(tile));
519 _tbdset.Add(tile, DiagDirection::Invalid); // start from depot inside
520 break;
521 }
522 [[fallthrough]];
523
525 case TileType::Road:
527 /* only add to set when there is some 'interesting' track */
528 _tbdset.Add(tile, dir);
529 _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
530 break;
531 }
532 [[fallthrough]];
533
534 default:
535 /* jump to next tile */
536 tile = tile + TileOffsByDiagDir(dir);
537 dir = ReverseDiagDir(dir);
539 _tbdset.Add(tile, dir);
540 break;
541 }
542 /* happens when removing a rail that wasn't connected at one or both sides */
543 continue; // continue the while() loop
544 }
545
546 assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
547 assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
548
549 SigFlags flags = ExploreSegment(owner);
550
551 if (first) {
552 first = false;
553 /* SigSegState::Free is set by default */
554 if (flags.Test(SigFlag::Pbs)) {
555 state = SigSegState::Path;
556 } else if (flags.Test(SigFlag::Train) || (flags.Test(SigFlag::Exit) && !flags.Test(SigFlag::Green)) || flags.Test(SigFlag::Full)) {
557 state = SigSegState::Full;
558 }
559 }
560
561 /* do not do anything when some buffer was full */
562 if (flags.Test(SigFlag::Full)) {
563 ResetSets(); // free all sets
564 break;
565 }
566
568 }
569
570 return state;
571}
572
573
575
576
582{
583 if (!_globset.IsEmpty()) {
585 _last_owner = INVALID_OWNER; // invalidate
586 }
587}
588
589
597void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
598{
599 static const DiagDirection _search_dir_1[] = {
601 };
602 static const DiagDirection _search_dir_2[] = {
604 };
605
606 /* do not allow signal updates for two companies in one run */
607 assert(_globset.IsEmpty() || owner == _last_owner);
608
609 _last_owner = owner;
610
611 _globset.Add(tile, _search_dir_1[to_underlying(track)]);
612 _globset.Add(tile, _search_dir_2[to_underlying(track)]);
613
614 if (_globset.Items() >= SIG_GLOB_UPDATE) {
615 /* too many items, force update */
618 }
619}
620
621
629void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
630{
631 /* do not allow signal updates for two companies in one run */
632 assert(_globset.IsEmpty() || owner == _last_owner);
633
634 _last_owner = owner;
635
636 _globset.Add(tile, side);
637
638 if (_globset.Items() >= SIG_GLOB_UPDATE) {
639 /* too many items, force update */
642 }
643}
644
656{
657 assert(_globset.IsEmpty());
658 _globset.Add(tile, side);
659
660 return UpdateSignalsInBuffer(owner);
661}
662
663
673void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
674{
675 assert(_globset.IsEmpty());
676
677 AddTrackToSignalBuffer(tile, track, owner);
679}
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.
Enum-as-bit-set wrapper.
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(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Misc
Misc message facility.
Definition debug_type.h:32
@ Critical
Critical, user should know about this.
Definition debug_type.h:15
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.
@ SW
Southwest.
@ NW
Northwest.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
@ SE
Southeast.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
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.
Definition map_func.h:574
@ Any
Use first found.
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:490
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:291
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:519
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:474
bool IsOnewaySignal(Tile t, Track track)
Is the signal at the given track on a tile a one way signal?
Definition rail_map.h:357
bool IsPresignalExit(Tile t, Track track)
Is the signal at the given track on a tile a presignal exit signal?
Definition rail_map.h:344
SignalType GetSignalType(Tile t, Track track)
Get the signal type for a track on a tile.
Definition rail_map.h:303
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:505
bool IsPresignalEntry(Tile t, Track track)
Is the signal at the given track on a tile a presignal entry signal?
Definition rail_map.h:332
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
Definition road_map.h:346
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
@ Invalid
Invalid marker.
Definition road_type.h:42
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:200
static Owner _last_owner
last owner whose track was put into _globset
Definition signal.cpp:574
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:243
static constexpr DiagDirectionIndexArray< TrackdirBits > _enterdir_to_trackdirbits
Accessible TrackdirBits from a given enter direction.
Definition signal.cpp:41
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:597
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:655
void UpdateSignalsInBuffer()
Update signals in buffer Called from 'outside'.
Definition signal.cpp:581
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
Definition signal.cpp:26
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition signal.cpp:629
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
Definition signal.cpp:27
EnumBitSet< SigFlag, uint16_t > SigFlags
Bitset of SigFlag elements.
Definition signal.cpp:266
static void ResetSets()
Reset all sets after one set overflowed.
Definition signal.cpp:472
SigFlag
Current signal block state flags.
Definition signal.cpp:252
@ MultiGreen
two or more green exits found
Definition signal.cpp:257
@ MultiExit
two or more exits found
Definition signal.cpp:255
@ Pbs
pbs signal found
Definition signal.cpp:259
@ MultiEnter
two or more signals entering the block found
Definition signal.cpp:262
@ Split
track merge/split found
Definition signal.cpp:260
@ Full
some of buffers was full, do not continue
Definition signal.cpp:258
@ Green
green exitsignal found
Definition signal.cpp:256
@ Train
train found in segment
Definition signal.cpp:253
@ Enter
signal entering the block found
Definition signal.cpp:261
@ Exit
exitsignal found
Definition signal.cpp:254
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:25
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
Definition signal.cpp:418
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:673
static constexpr DiagDirectionIndexArray< TrackBits > _enterdir_to_trackbits
Accessible TrackBits from a given enter direction.
Definition signal.cpp:33
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
Definition signal.cpp:28
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:219
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Definition signal.cpp:274
Data related to rail signals.
SigSegState
State of the signal segment.
Definition signal_func.h:55
@ Path
Segment is a path segment.
Definition signal_func.h:58
@ Free
Free and has no pre-signal exits or at least one green exit.
Definition signal_func.h:56
@ Full
Occupied by a train.
Definition signal_func.h:57
SignalType
Type of signal, i.e.
Definition signal_type.h:22
@ Combo
presignal inter-block.
Definition signal_type.h:26
SignalState
These are states in which a signal can be.
Definition signal_type.h:38
@ Green
The signal is green.
Definition signal_type.h:40
@ Red
The signal is red.
Definition signal_type.h:39
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:261
VehicleType type
Type of vehicle.
Element of set.
Definition signal.cpp:61
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slow...
Definition signal.cpp:54
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:157
SmallSet(std::string_view name)
Constructor - just set default values and 'name'.
Definition signal.cpp:71
uint n
Actual number of units.
Definition signal.cpp:56
const std::string_view name
Name, used for debugging purposes...
Definition signal.cpp:58
bool Overflowed()
Returns value of 'overflowed'.
Definition signal.cpp:84
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
Definition signal.cpp:123
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
Definition signal.cpp:178
void Reset()
Reset variables to default values.
Definition signal.cpp:74
uint Items()
Reads the number of items.
Definition signal.cpp:111
bool overflowed
Did we try to overflow the set?
Definition signal.cpp:57
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
Definition signal.cpp:141
bool IsEmpty()
Checks for empty set.
Definition signal.cpp:93
bool IsFull()
Checks for full set.
Definition signal.cpp:102
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:235
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition track_func.h:292
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition track_func.h:166
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition track_func.h:220
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition track_func.h:343
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition track_func.h:281
static constexpr TrackBits TRACK_BIT_3WAY_NE
"Arrow" to the north-east
Definition track_type.h:48
static constexpr TrackBits TRACK_BIT_HORZ
Upper and lower track.
Definition track_type.h:46
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Definition track_type.h:43
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:63
@ Right_N
Right track and direction to north.
Definition track_type.h:77
@ X_NE
X-axis and direction to north-east.
Definition track_type.h:64
@ Right_S
Right track and direction to south.
Definition track_type.h:69
@ Left_S
Left track and direction to south.
Definition track_type.h:68
@ Lower_E
Lower track and direction to east.
Definition track_type.h:67
@ X_SW
X-axis and direction to south-west.
Definition track_type.h:72
@ Invalid
Flag for an invalid trackdir.
Definition track_type.h:82
@ Y_SE
Y-axis and direction to south-east.
Definition track_type.h:65
@ Y_NW
Y-axis and direction to north-west.
Definition track_type.h:73
@ Upper_W
Upper track and direction to west.
Definition track_type.h:74
@ Upper_E
Upper track and direction to east.
Definition track_type.h:66
@ Left_N
Left track and direction to north.
Definition track_type.h:76
@ Lower_W
Lower track and direction to west.
Definition track_type.h:75
static constexpr TrackBits TRACK_BIT_VERT
Left and right track.
Definition track_type.h:47
static constexpr TrackBits TRACK_BIT_3WAY_SW
"Arrow" to the south-west
Definition track_type.h:50
static constexpr TrackBits TRACK_BIT_3WAY_SE
"Arrow" to the south-east
Definition track_type.h:49
static constexpr TrackBits TRACK_BIT_3WAY_NW
"Arrow" to the north-west
Definition track_type.h:51
Track
These are used to specify a single track.
Definition track_type.h:19
@ Depot
Special flag indicating a vehicle is inside a depot.
Definition track_type.h:30
Base for the train class.
@ 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:607
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.