OpenTTD Source  12.0-beta2
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 <http://www.gnu.org/licenses/>.
6  */
7 
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 "safeguards.h"
20 
21 
23 static const uint SIG_TBU_SIZE = 64;
24 static const uint SIG_TBD_SIZE = 256;
25 static const uint SIG_GLOB_SIZE = 128;
26 static const uint SIG_GLOB_UPDATE = 64;
27 
28 static_assert(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
29 
36 };
37 
44 };
45 
51 template <typename Tdir, uint items>
52 struct SmallSet {
53 private:
54  uint n; // actual number of units
55  bool overflowed; // did we try to overflow the set?
56  const char *name; // name, used for debugging purposes...
57 
59  struct SSdata {
60  TileIndex tile;
61  Tdir dir;
62  } data[items];
63 
64 public:
66  SmallSet(const char *name) : n(0), overflowed(false), name(name) { }
67 
69  void Reset()
70  {
71  this->n = 0;
72  this->overflowed = false;
73  }
74 
79  bool Overflowed()
80  {
81  return this->overflowed;
82  }
83 
88  bool IsEmpty()
89  {
90  return this->n == 0;
91  }
92 
97  bool IsFull()
98  {
99  return this->n == lengthof(data);
100  }
101 
106  uint Items()
107  {
108  return this->n;
109  }
110 
111 
118  bool Remove(TileIndex tile, Tdir dir)
119  {
120  for (uint i = 0; i < this->n; i++) {
121  if (this->data[i].tile == tile && this->data[i].dir == dir) {
122  this->data[i] = this->data[--this->n];
123  return true;
124  }
125  }
126 
127  return false;
128  }
129 
136  bool IsIn(TileIndex tile, Tdir dir)
137  {
138  for (uint i = 0; i < this->n; i++) {
139  if (this->data[i].tile == tile && this->data[i].dir == dir) return true;
140  }
141 
142  return false;
143  }
144 
152  bool Add(TileIndex tile, Tdir dir)
153  {
154  if (this->IsFull()) {
155  overflowed = true;
156  Debug(misc, 0, "SignalSegment too complex. Set {} is full (maximum {})", name, items);
157  return false; // set is full
158  }
159 
160  this->data[this->n].tile = tile;
161  this->data[this->n].dir = dir;
162  this->n++;
163 
164  return true;
165  }
166 
173  bool Get(TileIndex *tile, Tdir *dir)
174  {
175  if (this->n == 0) return false;
176 
177  this->n--;
178  *tile = this->data[this->n].tile;
179  *dir = this->data[this->n].dir;
180 
181  return true;
182  }
183 };
184 
185 static SmallSet<Trackdir, SIG_TBU_SIZE> _tbuset("_tbuset");
188 
189 
191 static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
192 {
193  if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return nullptr;
194 
195  return v;
196 }
197 
198 
213 {
214  _globset.Remove(t1, d1); // it can be in Global but not in Todo
215  _globset.Remove(t2, d2); // remove in all cases
216 
217  assert(!_tbdset.IsIn(t1, d1)); // it really shouldn't be there already
218 
219  return !_tbdset.Remove(t2, d2);
220 }
221 
222 
237 {
238  if (!CheckAddToTodoSet(t1, d1, t2, d2)) return true;
239 
240  return _tbdset.Add(t1, d1);
241 }
242 
243 
245 enum SigFlags {
246  SF_NONE = 0,
247  SF_TRAIN = 1 << 0,
248  SF_EXIT = 1 << 1,
249  SF_EXIT2 = 1 << 2,
250  SF_GREEN = 1 << 3,
251  SF_GREEN2 = 1 << 4,
252  SF_FULL = 1 << 5,
253  SF_PBS = 1 << 6,
254 };
255 
257 
258 
259 
266 {
267  SigFlags flags = SF_NONE;
268 
269  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
270  DiagDirection enterdir = INVALID_DIAGDIR;
271 
272  while (_tbdset.Get(&tile, &enterdir)) { // tile and enterdir are initialized here, unless I'm mistaken.
273  TileIndex oldtile = tile; // tile we are leaving
274  DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
275 
276  switch (GetTileType(tile)) {
277  case MP_RAILWAY: {
278  if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
279 
280  if (IsRailDepot(tile)) {
281  if (enterdir == INVALID_DIAGDIR) { // from 'inside' - train just entered or left the depot
282  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
283  exitdir = GetRailDepotDirection(tile);
284  tile += TileOffsByDiagDir(exitdir);
285  enterdir = ReverseDiagDir(exitdir);
286  break;
287  } else if (enterdir == GetRailDepotDirection(tile)) { // entered a depot
288  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
289  continue;
290  } else {
291  continue;
292  }
293  }
294 
295  assert(IsValidDiagDirection(enterdir));
296  TrackBits tracks = GetTrackBits(tile); // trackbits of tile
297  TrackBits tracks_masked = (TrackBits)(tracks & _enterdir_to_trackbits[enterdir]); // only incidating trackbits
298 
299  if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
300  tracks = tracks_masked;
301  /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
302  if (!(flags & SF_TRAIN) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags |= SF_TRAIN;
303  } else {
304  if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
305  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
306  }
307 
308  if (HasSignals(tile)) { // there is exactly one track - not zero, because there is exit from this tile
309  Track track = TrackBitsToTrack(tracks_masked); // mask TRACK_BIT_X and Y too
310  if (HasSignalOnTrack(tile, track)) { // now check whole track, not trackdir
311  SignalType sig = GetSignalType(tile, track);
312  Trackdir trackdir = (Trackdir)FindFirstBit((tracks * 0x101) & _enterdir_to_trackdirbits[enterdir]);
313  Trackdir reversedir = ReverseTrackdir(trackdir);
314  /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
315  * ANY conventional signal in REVERSE direction
316  * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
317  if (HasSignalOnTrackdir(tile, reversedir)) {
318  if (IsPbsSignal(sig)) {
319  flags |= SF_PBS;
320  } else if (!_tbuset.Add(tile, reversedir)) {
321  return flags | SF_FULL;
322  }
323  }
324  if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags |= SF_PBS;
325 
326  /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
327  if (!(flags & SF_GREEN2) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
328  if (flags & SF_EXIT) flags |= SF_EXIT2; // found two (or more) exits
329  flags |= SF_EXIT; // found at least one exit - allow for compiler optimizations
330  if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
331  if (flags & SF_GREEN) flags |= SF_GREEN2;
332  flags |= SF_GREEN;
333  }
334  }
335 
336  continue;
337  }
338  }
339 
340  for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
341  if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
342  TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
343  DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
344  if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SF_FULL;
345  }
346  }
347 
348  continue; // continue the while() loop
349  }
350 
351  case MP_STATION:
352  if (!HasStationRail(tile)) continue;
353  if (GetTileOwner(tile) != owner) continue;
354  if (DiagDirToAxis(enterdir) != GetRailStationAxis(tile)) continue; // different axis
355  if (IsStationTileBlocked(tile)) continue; // 'eye-candy' station tile
356 
357  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
358  tile += TileOffsByDiagDir(exitdir);
359  break;
360 
361  case MP_ROAD:
362  if (!IsLevelCrossing(tile)) continue;
363  if (GetTileOwner(tile) != owner) continue;
364  if (DiagDirToAxis(enterdir) == GetCrossingRoadAxis(tile)) continue; // different axis
365 
366  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
367  tile += TileOffsByDiagDir(exitdir);
368  break;
369 
370  case MP_TUNNELBRIDGE: {
371  if (GetTileOwner(tile) != owner) continue;
372  if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
374 
375  if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
376  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
377  enterdir = dir;
378  exitdir = ReverseDiagDir(dir);
379  tile += TileOffsByDiagDir(exitdir); // just skip to next tile
380  } else { // NOT incoming from the wormhole!
381  if (ReverseDiagDir(enterdir) != dir) continue;
382  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
383  tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
384  enterdir = INVALID_DIAGDIR;
385  exitdir = INVALID_DIAGDIR;
386  }
387  }
388  break;
389 
390  default:
391  continue; // continue the while() loop
392  }
393 
394  if (!MaybeAddToTodoSet(tile, enterdir, oldtile, exitdir)) return flags | SF_FULL;
395  }
396 
397  return flags;
398 }
399 
400 
407 {
408  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
409  Trackdir trackdir = INVALID_TRACKDIR;
410 
411  while (_tbuset.Get(&tile, &trackdir)) {
412  assert(HasSignalOnTrackdir(tile, trackdir));
413 
414  SignalType sig = GetSignalType(tile, TrackdirToTrack(trackdir));
415  SignalState newstate = SIGNAL_STATE_GREEN;
416 
417  /* determine whether the new state is red */
418  if (flags & SF_TRAIN) {
419  /* train in the segment */
420  newstate = SIGNAL_STATE_RED;
421  } else {
422  /* is it a bidir combo? - then do not count its other signal direction as exit */
423  if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
424  /* at least one more exit */
425  if ((flags & SF_EXIT2) &&
426  /* no green exit */
427  (!(flags & SF_GREEN) ||
428  /* only one green exit, and it is this one - so all other exits are red */
429  (!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
430  newstate = SIGNAL_STATE_RED;
431  }
432  } else { // entry, at least one exit, no green exit
433  if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && (flags & SF_EXIT) && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
434  }
435  }
436 
437  /* only when the state changes */
438  if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
439  if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
440  /* for pre-signal exits, add block to the global set */
441  DiagDirection exitdir = TrackdirToExitdir(ReverseTrackdir(trackdir));
442  _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
443  }
444  SetSignalStateByTrackdir(tile, trackdir, newstate);
445  MarkTileDirtyByTile(tile);
446  }
447  }
448 
449 }
450 
451 
453 static inline void ResetSets()
454 {
455  _tbuset.Reset();
456  _tbdset.Reset();
457  _globset.Reset();
458 }
459 
460 
469 {
470  assert(Company::IsValidID(owner));
471 
472  bool first = true; // first block?
473  SigSegState state = SIGSEG_FREE; // value to return
474 
475  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
477 
478  while (_globset.Get(&tile, &dir)) {
479  assert(_tbuset.IsEmpty());
480  assert(_tbdset.IsEmpty());
481 
482  /* After updating signal, data stored are always MP_RAILWAY with signals.
483  * Other situations happen when data are from outside functions -
484  * modification of railbits (including both rail building and removal),
485  * train entering/leaving block, train leaving depot...
486  */
487  switch (GetTileType(tile)) {
488  case MP_TUNNELBRIDGE:
489  /* 'optimization assert' - do not try to update signals when it is not needed */
491  assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
492  _tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
494  break;
495 
496  case MP_RAILWAY:
497  if (IsRailDepot(tile)) {
498  /* 'optimization assert' do not try to update signals in other cases */
499  assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
500  _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
501  break;
502  }
503  FALLTHROUGH;
504 
505  case MP_STATION:
506  case MP_ROAD:
508  /* only add to set when there is some 'interesting' track */
509  _tbdset.Add(tile, dir);
510  _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
511  break;
512  }
513  FALLTHROUGH;
514 
515  default:
516  /* jump to next tile */
517  tile = tile + TileOffsByDiagDir(dir);
518  dir = ReverseDiagDir(dir);
520  _tbdset.Add(tile, dir);
521  break;
522  }
523  /* happens when removing a rail that wasn't connected at one or both sides */
524  continue; // continue the while() loop
525  }
526 
527  assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
528  assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
529 
530  SigFlags flags = ExploreSegment(owner);
531 
532  if (first) {
533  first = false;
534  /* SIGSEG_FREE is set by default */
535  if (flags & SF_PBS) {
536  state = SIGSEG_PBS;
537  } else if ((flags & SF_TRAIN) || ((flags & SF_EXIT) && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
538  state = SIGSEG_FULL;
539  }
540  }
541 
542  /* do not do anything when some buffer was full */
543  if (flags & SF_FULL) {
544  ResetSets(); // free all sets
545  break;
546  }
547 
549  }
550 
551  return state;
552 }
553 
554 
556 
557 
563 {
564  if (!_globset.IsEmpty()) {
566  _last_owner = INVALID_OWNER; // invalidate
567  }
568 }
569 
570 
578 void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
579 {
580  static const DiagDirection _search_dir_1[] = {
582  };
583  static const DiagDirection _search_dir_2[] = {
585  };
586 
587  /* do not allow signal updates for two companies in one run */
588  assert(_globset.IsEmpty() || owner == _last_owner);
589 
590  _last_owner = owner;
591 
592  _globset.Add(tile, _search_dir_1[track]);
593  _globset.Add(tile, _search_dir_2[track]);
594 
595  if (_globset.Items() >= SIG_GLOB_UPDATE) {
596  /* too many items, force update */
599  }
600 }
601 
602 
611 {
612  /* do not allow signal updates for two companies in one run */
613  assert(_globset.IsEmpty() || owner == _last_owner);
614 
615  _last_owner = owner;
616 
617  _globset.Add(tile, side);
618 
619  if (_globset.Items() >= SIG_GLOB_UPDATE) {
620  /* too many items, force update */
623  }
624 }
625 
637 {
638  assert(_globset.IsEmpty());
639  _globset.Add(tile, side);
640 
641  return UpdateSignalsInBuffer(owner);
642 }
643 
644 
654 void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
655 {
656  assert(_globset.IsEmpty());
657 
658  AddTrackToSignalBuffer(tile, track, owner);
659  UpdateSignalsInBuffer(owner);
660 }
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:80
UpdateSignalsAroundSegment
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
Definition: signal.cpp:406
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
TRACKDIR_BIT_UPPER_W
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
Definition: track_type.h:112
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
TRACK_BIT_3WAY_SW
@ TRACK_BIT_3WAY_SW
"Arrow" to the south-west
Definition: track_type.h:51
train.h
UpdateSignalsInBuffer
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:468
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
HasSignalOnTrack
static bool HasSignalOnTrack(TileIndex tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
Definition: rail_map.h:413
SIG_GLOB_UPDATE
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
Definition: signal.cpp:26
HasVehicleOnPos
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:513
SF_EXIT
@ SF_EXIT
exitsignal found
Definition: signal.cpp:248
company_base.h
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
tunnelbridge_map.h
ResetSets
static void ResetSets()
Reset all sets after one set overflowed.
Definition: signal.cpp:453
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
SIGNAL_STATE_GREEN
@ SIGNAL_STATE_GREEN
The signal is green.
Definition: signal_type.h:46
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:47
IsValidDiagDirection
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
SignalState
SignalState
These are states in which a signal can be.
Definition: signal_type.h:44
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
_enterdir_to_trackbits
static const TrackBits _enterdir_to_trackbits[DIAGDIR_END]
incidating trackbits with given enterdir
Definition: signal.cpp:31
UpdateSignalsOnSegment
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:636
HasSignals
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:72
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:82
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:221
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
MaybeAddToTodoSet
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:236
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:48
TrainOnTileEnum
static Vehicle * TrainOnTileEnum(Vehicle *v, void *)
Check whether there is a train on rail, not in a depot.
Definition: signal.cpp:191
IsRailDepot
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
SmallSet::SmallSet
SmallSet(const char *name)
Constructor - just set default values and 'name'.
Definition: signal.cpp:66
SIG_TBU_SIZE
static const uint SIG_TBU_SIZE
these are the maximums used for updating signal blocks
Definition: signal.cpp:23
SmallSet::Add
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:152
IsLevelCrossing
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:84
GetRailDepotDirection
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
Definition: rail_map.h:171
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:590
SignalType
SignalType
Type of signal, i.e.
Definition: signal_type.h:23
SetSignalsOnBothDir
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:654
SmallSet::Items
uint Items()
Reads the number of items.
Definition: signal.cpp:106
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition: track_type.h:48
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:81
TrackBitsToTrack
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:192
SF_EXIT2
@ SF_EXIT2
two or more exits found
Definition: signal.cpp:249
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition: track_type.h:103
TRACKDIR_BIT_LOWER_E
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
Definition: track_type.h:106
HasStationRail
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:135
SIG_TBD_SIZE
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
Definition: signal.cpp:24
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:362
SIGNAL_STATE_RED
@ SIGNAL_STATE_RED
The signal is red.
Definition: signal_type.h:45
TrackdirToExitdir
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:438
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
SIGTYPE_COMBO
@ SIGTYPE_COMBO
presignal inter-block
Definition: signal_type.h:27
HasSignalOnTrackdir
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Definition: rail_map.h:426
SIG_GLOB_SIZE
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
Definition: signal.cpp:25
_enterdir_to_trackdirbits
static const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END]
incidating trackdirbits with given enterdir
Definition: signal.cpp:39
SetSignalStateByTrackdir
static void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, SignalState state)
Sets the state of the signal along the given trackdir.
Definition: rail_map.h:449
safeguards.h
TRACKDIR_BIT_LOWER_W
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
Definition: track_type.h:113
SIGSEG_PBS
@ SIGSEG_PBS
Segment is a PBS segment.
Definition: signal_func.h:52
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition: track_type.h:104
TRACKDIR_BIT_LEFT_S
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
Definition: track_type.h:107
TRACKDIR_BIT_RIGHT_S
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
Definition: track_type.h:108
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:84
TRACKDIR_BIT_LEFT_N
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
Definition: track_type.h:114
SmallSet::Get
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
Definition: signal.cpp:173
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:55
SigFlags
SigFlags
Current signal block state flags.
Definition: signal.cpp:245
_tbuset
static SmallSet< Trackdir, SIG_TBU_SIZE > _tbuset("_tbuset")
set of signals that will be updated
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:89
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
SigSegState
SigSegState
State of the signal segment.
Definition: signal_func.h:49
SmallSet::SSdata
Element of set.
Definition: signal.cpp:59
SmallSet::IsIn
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
Definition: signal.cpp:136
stdafx.h
IsOnewaySignal
static bool IsOnewaySignal(TileIndex t, Track track)
One-way signals can't be passed the 'wrong' way.
Definition: rail_map.h:319
viewport_func.h
GetTunnelBridgeDirection
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
TRACK_BIT_DEPOT
@ TRACK_BIT_DEPOT
Bitflag for a depot.
Definition: track_type.h:56
SF_PBS
@ SF_PBS
pbs signal found
Definition: signal.cpp:253
ExploreSegment
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Definition: signal.cpp:265
SmallSet::IsEmpty
bool IsEmpty()
Checks for empty set.
Definition: signal.cpp:88
IsStationTileBlocked
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Definition: newgrf_station.cpp:867
SF_FULL
@ SF_FULL
some of buffers was full, do not continue
Definition: signal.cpp:252
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition: track_type.h:47
vehicle_func.h
EnsureNoTrainOnTrackBits
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
Definition: vehicle.cpp:601
TRACK_BIT_3WAY_NE
@ TRACK_BIT_3WAY_NE
"Arrow" to the north-east
Definition: track_type.h:49
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1164
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition: track_type.h:111
_last_owner
static Owner _last_owner
last owner whose track was put into _globset
Definition: signal.cpp:555
SmallSet::IsFull
bool IsFull()
Checks for full set.
Definition: signal.cpp:97
GetSignalStateByTrackdir
static SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
Definition: rail_map.h:438
SF_GREEN2
@ SF_GREEN2
two or more green exits found
Definition: signal.cpp:251
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1987
AddSideToSignalBuffer
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition: signal.cpp:610
SmallSet
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slow...
Definition: signal.cpp:52
TRACK_BIT_3WAY_SE
@ TRACK_BIT_3WAY_SE
"Arrow" to the south-east
Definition: track_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:51
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
SF_TRAIN
@ SF_TRAIN
train found in segment
Definition: signal.cpp:247
SmallSet::Overflowed
bool Overflowed()
Returns value of 'overflowed'.
Definition: signal.cpp:79
AddTrackToSignalBuffer
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
Definition: signal.cpp:578
SIGSEG_FULL
@ SIGSEG_FULL
Occupied by a train.
Definition: signal_func.h:51
SF_GREEN
@ SF_GREEN
green exitsignal found
Definition: signal.cpp:250
_globset
static SmallSet< DiagDirection, SIG_GLOB_SIZE > _globset("_globset")
set of places to be updated in following runs
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
SmallSet::Reset
void Reset()
Reset variables to default values.
Definition: signal.cpp:69
station_map.h
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
GetCrossingRoadAxis
static Axis GetCrossingRoadAxis(TileIndex t)
Get the road axis of a level crossing.
Definition: road_map.h:325
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition: track_type.h:110
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:246
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
SmallSet::Remove
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
Definition: signal.cpp:118
_tbdset
static SmallSet< DiagDirection, SIG_TBD_SIZE > _tbdset("_tbdset")
set of open nodes in current signal block
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
TRACKDIR_BIT_RIGHT_N
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
Definition: track_type.h:115
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
TRACK_BIT_3WAY_NW
@ TRACK_BIT_3WAY_NW
"Arrow" to the north-west
Definition: track_type.h:52
TRACKDIR_BIT_UPPER_E
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
Definition: track_type.h:105
CheckAddToTodoSet
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:212
SIGSEG_FREE
@ SIGSEG_FREE
Free and has no pre-signal exits or at least one green exit.
Definition: signal_func.h:50
FindFirstBit
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
Definition: bitmath_func.cpp:37
TrackdirToTrack
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:261
debug.h