OpenTTD Source  1.11.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 %s is full (maximum %d)", 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  if (_tbdset.Remove(t2, d2)) return false;
220 
221  return true;
222 }
223 
224 
239 {
240  if (!CheckAddToTodoSet(t1, d1, t2, d2)) return true;
241 
242  return _tbdset.Add(t1, d1);
243 }
244 
245 
247 enum SigFlags {
248  SF_NONE = 0,
249  SF_TRAIN = 1 << 0,
250  SF_EXIT = 1 << 1,
251  SF_EXIT2 = 1 << 2,
252  SF_GREEN = 1 << 3,
253  SF_GREEN2 = 1 << 4,
254  SF_FULL = 1 << 5,
255  SF_PBS = 1 << 6,
256 };
257 
259 
260 
261 
268 {
269  SigFlags flags = SF_NONE;
270 
271  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
272  DiagDirection enterdir = INVALID_DIAGDIR;
273 
274  while (_tbdset.Get(&tile, &enterdir)) { // tile and enterdir are initialized here, unless I'm mistaken.
275  TileIndex oldtile = tile; // tile we are leaving
276  DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
277 
278  switch (GetTileType(tile)) {
279  case MP_RAILWAY: {
280  if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
281 
282  if (IsRailDepot(tile)) {
283  if (enterdir == INVALID_DIAGDIR) { // from 'inside' - train just entered or left the depot
284  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
285  exitdir = GetRailDepotDirection(tile);
286  tile += TileOffsByDiagDir(exitdir);
287  enterdir = ReverseDiagDir(exitdir);
288  break;
289  } else if (enterdir == GetRailDepotDirection(tile)) { // entered a depot
290  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
291  continue;
292  } else {
293  continue;
294  }
295  }
296 
297  assert(IsValidDiagDirection(enterdir));
298  TrackBits tracks = GetTrackBits(tile); // trackbits of tile
299  TrackBits tracks_masked = (TrackBits)(tracks & _enterdir_to_trackbits[enterdir]); // only incidating trackbits
300 
301  if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
302  tracks = tracks_masked;
303  /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
304  if (!(flags & SF_TRAIN) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags |= SF_TRAIN;
305  } else {
306  if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
307  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
308  }
309 
310  if (HasSignals(tile)) { // there is exactly one track - not zero, because there is exit from this tile
311  Track track = TrackBitsToTrack(tracks_masked); // mask TRACK_BIT_X and Y too
312  if (HasSignalOnTrack(tile, track)) { // now check whole track, not trackdir
313  SignalType sig = GetSignalType(tile, track);
314  Trackdir trackdir = (Trackdir)FindFirstBit((tracks * 0x101) & _enterdir_to_trackdirbits[enterdir]);
315  Trackdir reversedir = ReverseTrackdir(trackdir);
316  /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
317  * ANY conventional signal in REVERSE direction
318  * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
319  if (HasSignalOnTrackdir(tile, reversedir)) {
320  if (IsPbsSignal(sig)) {
321  flags |= SF_PBS;
322  } else if (!_tbuset.Add(tile, reversedir)) {
323  return flags | SF_FULL;
324  }
325  }
326  if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags |= SF_PBS;
327 
328  /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
329  if (!(flags & SF_GREEN2) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
330  if (flags & SF_EXIT) flags |= SF_EXIT2; // found two (or more) exits
331  flags |= SF_EXIT; // found at least one exit - allow for compiler optimizations
332  if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
333  if (flags & SF_GREEN) flags |= SF_GREEN2;
334  flags |= SF_GREEN;
335  }
336  }
337 
338  continue;
339  }
340  }
341 
342  for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
343  if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
344  TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
345  DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
346  if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SF_FULL;
347  }
348  }
349 
350  continue; // continue the while() loop
351  }
352 
353  case MP_STATION:
354  if (!HasStationRail(tile)) continue;
355  if (GetTileOwner(tile) != owner) continue;
356  if (DiagDirToAxis(enterdir) != GetRailStationAxis(tile)) continue; // different axis
357  if (IsStationTileBlocked(tile)) continue; // 'eye-candy' station tile
358 
359  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
360  tile += TileOffsByDiagDir(exitdir);
361  break;
362 
363  case MP_ROAD:
364  if (!IsLevelCrossing(tile)) continue;
365  if (GetTileOwner(tile) != owner) continue;
366  if (DiagDirToAxis(enterdir) == GetCrossingRoadAxis(tile)) continue; // different axis
367 
368  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
369  tile += TileOffsByDiagDir(exitdir);
370  break;
371 
372  case MP_TUNNELBRIDGE: {
373  if (GetTileOwner(tile) != owner) continue;
374  if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
376 
377  if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
378  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
379  enterdir = dir;
380  exitdir = ReverseDiagDir(dir);
381  tile += TileOffsByDiagDir(exitdir); // just skip to next tile
382  } else { // NOT incoming from the wormhole!
383  if (ReverseDiagDir(enterdir) != dir) continue;
384  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
385  tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
386  enterdir = INVALID_DIAGDIR;
387  exitdir = INVALID_DIAGDIR;
388  }
389  }
390  break;
391 
392  default:
393  continue; // continue the while() loop
394  }
395 
396  if (!MaybeAddToTodoSet(tile, enterdir, oldtile, exitdir)) return flags | SF_FULL;
397  }
398 
399  return flags;
400 }
401 
402 
409 {
410  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
411  Trackdir trackdir = INVALID_TRACKDIR;
412 
413  while (_tbuset.Get(&tile, &trackdir)) {
414  assert(HasSignalOnTrackdir(tile, trackdir));
415 
416  SignalType sig = GetSignalType(tile, TrackdirToTrack(trackdir));
417  SignalState newstate = SIGNAL_STATE_GREEN;
418 
419  /* determine whether the new state is red */
420  if (flags & SF_TRAIN) {
421  /* train in the segment */
422  newstate = SIGNAL_STATE_RED;
423  } else {
424  /* is it a bidir combo? - then do not count its other signal direction as exit */
425  if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
426  /* at least one more exit */
427  if ((flags & SF_EXIT2) &&
428  /* no green exit */
429  (!(flags & SF_GREEN) ||
430  /* only one green exit, and it is this one - so all other exits are red */
431  (!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
432  newstate = SIGNAL_STATE_RED;
433  }
434  } else { // entry, at least one exit, no green exit
435  if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && (flags & SF_EXIT) && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
436  }
437  }
438 
439  /* only when the state changes */
440  if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
441  if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
442  /* for pre-signal exits, add block to the global set */
443  DiagDirection exitdir = TrackdirToExitdir(ReverseTrackdir(trackdir));
444  _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
445  }
446  SetSignalStateByTrackdir(tile, trackdir, newstate);
447  MarkTileDirtyByTile(tile);
448  }
449  }
450 
451 }
452 
453 
455 static inline void ResetSets()
456 {
457  _tbuset.Reset();
458  _tbdset.Reset();
459  _globset.Reset();
460 }
461 
462 
471 {
472  assert(Company::IsValidID(owner));
473 
474  bool first = true; // first block?
475  SigSegState state = SIGSEG_FREE; // value to return
476 
477  TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
479 
480  while (_globset.Get(&tile, &dir)) {
481  assert(_tbuset.IsEmpty());
482  assert(_tbdset.IsEmpty());
483 
484  /* After updating signal, data stored are always MP_RAILWAY with signals.
485  * Other situations happen when data are from outside functions -
486  * modification of railbits (including both rail building and removal),
487  * train entering/leaving block, train leaving depot...
488  */
489  switch (GetTileType(tile)) {
490  case MP_TUNNELBRIDGE:
491  /* 'optimization assert' - do not try to update signals when it is not needed */
493  assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
494  _tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
496  break;
497 
498  case MP_RAILWAY:
499  if (IsRailDepot(tile)) {
500  /* 'optimization assert' do not try to update signals in other cases */
501  assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
502  _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
503  break;
504  }
505  FALLTHROUGH;
506 
507  case MP_STATION:
508  case MP_ROAD:
510  /* only add to set when there is some 'interesting' track */
511  _tbdset.Add(tile, dir);
512  _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
513  break;
514  }
515  FALLTHROUGH;
516 
517  default:
518  /* jump to next tile */
519  tile = tile + TileOffsByDiagDir(dir);
520  dir = ReverseDiagDir(dir);
522  _tbdset.Add(tile, dir);
523  break;
524  }
525  /* happens when removing a rail that wasn't connected at one or both sides */
526  continue; // continue the while() loop
527  }
528 
529  assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
530  assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
531 
532  SigFlags flags = ExploreSegment(owner);
533 
534  if (first) {
535  first = false;
536  /* SIGSEG_FREE is set by default */
537  if (flags & SF_PBS) {
538  state = SIGSEG_PBS;
539  } else if ((flags & SF_TRAIN) || ((flags & SF_EXIT) && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
540  state = SIGSEG_FULL;
541  }
542  }
543 
544  /* do not do anything when some buffer was full */
545  if (flags & SF_FULL) {
546  ResetSets(); // free all sets
547  break;
548  }
549 
551  }
552 
553  return state;
554 }
555 
556 
558 
559 
565 {
566  if (!_globset.IsEmpty()) {
568  _last_owner = INVALID_OWNER; // invalidate
569  }
570 }
571 
572 
580 void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
581 {
582  static const DiagDirection _search_dir_1[] = {
584  };
585  static const DiagDirection _search_dir_2[] = {
587  };
588 
589  /* do not allow signal updates for two companies in one run */
590  assert(_globset.IsEmpty() || owner == _last_owner);
591 
592  _last_owner = owner;
593 
594  _globset.Add(tile, _search_dir_1[track]);
595  _globset.Add(tile, _search_dir_2[track]);
596 
597  if (_globset.Items() >= SIG_GLOB_UPDATE) {
598  /* too many items, force update */
601  }
602 }
603 
604 
613 {
614  /* do not allow signal updates for two companies in one run */
615  assert(_globset.IsEmpty() || owner == _last_owner);
616 
617  _last_owner = owner;
618 
619  _globset.Add(tile, side);
620 
621  if (_globset.Items() >= SIG_GLOB_UPDATE) {
622  /* too many items, force update */
625  }
626 }
627 
639 {
640  assert(_globset.IsEmpty());
641  _globset.Add(tile, side);
642 
643  return UpdateSignalsInBuffer(owner);
644 }
645 
646 
656 void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
657 {
658  assert(_globset.IsEmpty());
659 
660  AddTrackToSignalBuffer(tile, track, owner);
661  UpdateSignalsInBuffer(owner);
662 }
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:408
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
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:470
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:250
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:455
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:42
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:638
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:222
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:238
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:43
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:589
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:656
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:201
SF_EXIT2
@ SF_EXIT2
two or more exits found
Definition: signal.cpp:251
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
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
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:447
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:50
SigFlags
SigFlags
Current signal block state flags.
Definition: signal.cpp:247
_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:255
ExploreSegment
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Definition: signal.cpp:267
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:869
SF_FULL
@ SF_FULL
some of buffers was full, do not continue
Definition: signal.cpp:254
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:1162
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:557
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:253
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:1985
AddSideToSignalBuffer
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition: signal.cpp:612
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:46
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
SF_TRAIN
@ SF_TRAIN
train found in segment
Definition: signal.cpp:249
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:580
SIGSEG_FULL
@ SIGSEG_FULL
Occupied by a train.
Definition: signal_func.h:51
SF_GREEN
@ SF_GREEN
green exitsignal found
Definition: signal.cpp:252
_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
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
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:255
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:318
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:270
debug.h