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/>.
8 /** @file logic_signals.h Header file for the Logic Signals patch. */
10 #ifndef LOGIC_SIGNALS_H
11 #define LOGIC_SIGNALS_H
15 #include "signal_type.h"
16 #include "tile_type.h"
17 #include "track_type.h"
23 * Operators which logic signals can use when evaluating inputs.
34 /** Helper for saveload stuff. */
36 struct EnumPropsT
<SignalOperator
> : MakeEnumPropsT
<SignalOperator
, byte
, SIGNAL_OP_OR
, SIGNAL_OP_END
, SIGNAL_OP_END
, 2> {};
38 typedef TinyEnumT
<SignalOperator
> SignalOperatorByte
;
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
;
48 * A simple container used to store multiple signal references.
50 typedef std::list
<SignalReference
> SignalReferenceList
;
53 * The main class of a signal program.
57 SignalReferenceList linked_signals
;
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
);
72 const std::list
<SignalReference
>& GetSignalReferences() const;
73 size_t LinkCount() const;
74 void InputChanged(int depth
);
75 SignalState
Evaluate();
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 */