Rework the trip history window layout.
[openttd-joker.git] / src / logic_signals.h
blob8cece2c5618eae9452dc00bca72e023f3c168df0
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"
14 #include "core/smallvec_type.hpp"
15 #include "tile_type.h"
16 #include "track_type.h"
17 #include "signal_type.h"
18 #include <list>
19 #include <map>
21 /**
22 * Operators which logic signals can use when evaluating inputs.
24 enum SignalOperator {
25 SIGNAL_OP_OR,
26 SIGNAL_OP_AND,
27 SIGNAL_OP_NAND,
28 SIGNAL_OP_XOR,
29 SIGNAL_OP_END
31 /** Helper for saveload stuff. */
32 template <> struct EnumPropsT<SignalOperator> : MakeEnumPropsT<SignalOperator, byte, SIGNAL_OP_OR, SIGNAL_OP_END, SIGNAL_OP_END, 2> {};
33 typedef TinyEnumT<SignalOperator> SignalOperatorByte;
35 /**
36 * The definition of a signal program reference.
38 * The first 22 bits (0 to 21) is the TileIndex and 3 bits 22 to 24 is the Track.
39 * This will stop working if maps larger than 2048 x 2048 are used.
41 typedef uint32 SignalReference;
43 /**
44 * A simple container used to store multiple signal references.
46 typedef SmallVector<SignalReference, 4> SignalReferenceList;
48 /**
49 * The main class of a signal program.
51 class SignalProgram {
52 private:
53 SignalReferenceList linked_signals;
55 public:
56 TileIndex tile;
57 TrackByte track;
59 SignalStateByte own_default_state;
60 SignalStateByte trigger_state;
61 SignalOperatorByte signal_op;
63 bool blocked_by_train;
65 SignalProgram();
66 SignalProgram(TileIndex t, Track tr);
67 void AddLink(TileIndex tile, Track track, bool remove_first);
68 void RemoveLink(TileIndex tile, Track track);
69 void ClearAllLinks();
70 const std::list<SignalReference> GetSignalReferences() const;
71 uint LinkCount();
72 void InputChanged(int depth);
73 SignalState Evaluate();
76 // Global variables
77 typedef std::map<SignalReference, SignalProgram*> SignalProgramList;
78 typedef std::map<SignalReference, SignalReference> SignalLinkList;
79 extern SignalProgramList _signal_program_list;
80 extern SignalLinkList _signal_link_list;
82 // Global functions in logic_signals.cpp
83 extern void FreeAllSignalPrograms();
84 extern SignalState DetermineSignalState(TileIndex tile, Track track);
85 extern void SetSignalStateForTrack(TileIndex tile, Track track, SignalState state);
86 extern Track SignalTrackFromTile(TileIndex tile);
87 extern SignalReference GetSignalReference(TileIndex tile, Track track);
88 extern TileIndex GetTileFromSignalReference(SignalReference key);
89 extern Track GetTrackFromSignalReference(SignalReference key);
90 extern SignalProgram * FindSignalProgram(TileIndex tile, Track track);
91 extern void RemoveSignalLink(TileIndex tile, Track track);
92 extern SignalProgram * CreateSignalProgram(TileIndex tile, Track track);
93 extern void DeleteSignalProgram(TileIndex tile, Track track);
94 extern void SignalTypeChanged(TileIndex tile, Track track, SignalType old_type, SignalType new_type);
95 extern void SignalStateChanged(TileIndex tile, Track track, int depth);
97 // Global functions in logic_signals_gui.cpp
98 extern void ShowSignalProgramWindow(SignalProgram *program);
100 #endif /* LOGIC_SIGNALS_H */