Make it possible to stop road vehicles from slowing down in curves so "diagonal"...
[openttd-joker.git] / src / logic_signals.h
blob790ae52f555565e45f287f3246a4e72ecdfd174f
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 */
8 /** @file logic_signals.h Header file for the Logic Signals patch. */
10 #ifndef LOGIC_SIGNALS_H
11 #define LOGIC_SIGNALS_H
13 #include "stdafx.h"
15 #include "signal_type.h"
16 #include "tile_type.h"
17 #include "track_type.h"
19 #include <list>
20 #include <map>
22 /**
23 * Operators which logic signals can use when evaluating inputs.
25 enum SignalOperator
27 SIGNAL_OP_OR,
28 SIGNAL_OP_AND,
29 SIGNAL_OP_NAND,
30 SIGNAL_OP_XOR,
31 SIGNAL_OP_END
34 /** Helper for saveload stuff. */
35 template <>
36 struct EnumPropsT<SignalOperator> : MakeEnumPropsT<SignalOperator, byte, SIGNAL_OP_OR, SIGNAL_OP_END, SIGNAL_OP_END, 2> {};
38 typedef TinyEnumT<SignalOperator> SignalOperatorByte;
40 /**
41 * The definition of a signal program reference.
43 * The first 32 bits (0 to 31) is the TileIndex and 3 bits 32 to 34 is the Track.
45 typedef uint64 SignalReference;
47 /**
48 * A simple container used to store multiple signal references.
50 typedef std::list<SignalReference> SignalReferenceList;
52 /**
53 * The main class of a signal program.
55 class SignalProgram
57 SignalReferenceList linked_signals;
59 public:
60 TileIndex tile{};
61 TrackByte track{};
62 SignalStateByte own_default_state{};
63 SignalStateByte trigger_state{};
64 SignalOperatorByte signal_op{};
65 bool blocked_by_train{};
67 SignalProgram() = default;
68 SignalProgram(TileIndex tile, Track track);
69 void AddLink(TileIndex tile, Track track);
70 void RemoveLink(TileIndex tile, Track track);
71 void ClearAllLinks();
72 const std::list<SignalReference>& GetSignalReferences() const;
73 size_t LinkCount() const;
74 void InputChanged(int depth);
75 SignalState Evaluate();
78 // Global variables
79 typedef std::map<SignalReference, SignalProgram*> SignalProgramList;
80 typedef std::vector<std::pair<SignalReference, SignalReference>> SignalLinkList;
81 extern SignalProgramList _signal_program_list;
82 extern SignalLinkList _signal_link_list;
84 // Global functions in logic_signals.cpp
85 extern void FreeAllSignalPrograms();
86 extern SignalState DetermineSignalState(TileIndex tile, Track track);
87 extern void SetSignalStateForTrack(TileIndex tile, Track track, SignalState state);
88 extern Track SignalTrackFromTile(TileIndex tile);
89 extern SignalReference GetSignalReference(TileIndex tile, Track track);
90 extern TileIndex GetTileFromSignalReference(SignalReference key);
91 extern Track GetTrackFromSignalReference(SignalReference key);
92 extern SignalProgram* FindSignalProgram(TileIndex tile, Track track);
93 extern void RemoveSignalLink(TileIndex tile, Track track);
94 extern SignalProgram* CreateSignalProgram(TileIndex tile, Track track);
95 extern void DeleteSignalProgram(TileIndex tile, Track track);
96 extern void SignalTypeChanged(TileIndex tile, Track track, SignalType old_type, SignalType new_type);
97 extern void SignalStateChanged(TileIndex tile, Track track, int depth);
99 // Global functions in logic_signals_gui.cpp
100 extern void ShowSignalProgramWindow(SignalProgram* program);
102 #endif /* LOGIC_SIGNALS_H */