signal_func.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #ifndef SIGNAL_FUNC_H
00013 #define SIGNAL_FUNC_H
00014 
00015 #include "signal_type.h"
00016 #include "track_type.h"
00017 #include "tile_type.h"
00018 #include "direction_type.h"
00019 #include "company_type.h"
00020 #include "debug.h"
00021 
00026 static inline byte SignalAlongTrackdir(Trackdir trackdir)
00027 {
00028   extern const byte _signal_along_trackdir[TRACKDIR_END];
00029   return _signal_along_trackdir[trackdir];
00030 }
00031 
00036 static inline byte SignalAgainstTrackdir(Trackdir trackdir)
00037 {
00038   extern const byte _signal_against_trackdir[TRACKDIR_END];
00039   return _signal_against_trackdir[trackdir];
00040 }
00041 
00046 static inline byte SignalOnTrack(Track track)
00047 {
00048   extern const byte _signal_on_track[TRACK_END];
00049   return _signal_on_track[track];
00050 }
00051 
00053 static inline bool IsEntrySignal(SignalType type)
00054 {
00055   return type == SIGTYPE_ENTRY || type == SIGTYPE_COMBO || type == SIGTYPE_PROG;
00056 }
00057 
00059 static inline bool IsExitSignal(SignalType type)
00060 {
00061   return type == SIGTYPE_EXIT || type == SIGTYPE_COMBO || type == SIGTYPE_PROG;
00062 }
00063 
00065 static inline bool IsComboSignal(SignalType type)
00066 {
00067   return type == SIGTYPE_COMBO || type == SIGTYPE_PROG;
00068 }
00069 
00071 static inline bool IsPbsSignal(SignalType type)
00072 {
00073   return type == SIGTYPE_PBS || type == SIGTYPE_PBS_ONEWAY;
00074 }
00075 
00077 static inline bool IsProgrammableSignal(SignalType type)
00078 {
00079   return type == SIGTYPE_PROG;
00080 }
00081 
00083 static inline bool IsSpeedSignal(SignalType type)
00084 {
00085   return type == SIGTYPE_SPEED;
00086 }
00087 
00089 static inline bool IsSignalSpritePBS(SignalType type)
00090 {
00091   return type >= SIGTYPE_FIRST_PBS_SPRITE;
00092 }
00093 
00094 static inline SignalType NextSignalType(SignalType cur, uint which_signals)
00095 {
00096   bool pbs   = (which_signals != 0);
00097   bool block = (which_signals != 1);
00098   
00099   switch(cur) {
00100     case SIGTYPE_NORMAL:     return block ? SIGTYPE_ENTRY      : SIGTYPE_PBS;
00101     case SIGTYPE_ENTRY:      return block ? SIGTYPE_EXIT       : SIGTYPE_PBS;
00102     case SIGTYPE_EXIT:       return block ? SIGTYPE_COMBO      : SIGTYPE_PBS;
00103     case SIGTYPE_COMBO:      return block ? SIGTYPE_PROG       : SIGTYPE_PBS;
00104     case SIGTYPE_PROG:       return pbs   ? SIGTYPE_PBS        : SIGTYPE_NORMAL;
00105     case SIGTYPE_SPEED:      return SIGTYPE_SPEED;
00106     case SIGTYPE_PBS:        return pbs   ? SIGTYPE_PBS_ONEWAY : SIGTYPE_NORMAL;
00107     case SIGTYPE_PBS_ONEWAY: return block ? SIGTYPE_NORMAL     : SIGTYPE_PBS;
00108     default: 
00109       DEBUG(map, 0, "Attempt to cycle from signal type %d", cur);
00110       return SIGTYPE_NORMAL; // Fortunately mostly harmless
00111   }
00112 }
00113 
00115 enum SigSegState {
00116   SIGSEG_FREE,    
00117   SIGSEG_FULL,    
00118   SIGSEG_PBS,     
00119 };
00120 
00126 void CheckRemoveSignalsFromTile(TileIndex tile);
00127 
00133 void CheckRemoveSignal(TileIndex tile, Track track);
00134 
00140 void AddSignalDependency(SignalReference on, SignalReference dep);
00141 
00143 void RemoveSignalDependency(SignalReference on, SignalReference dep);
00144 
00146 void FreeSignalDependencies();
00147 
00148 SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner);
00149 void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner);
00150 void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner);
00151 void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner);
00152 void UpdateSignalsInBuffer();
00153 
00154 #endif /* SIGNAL_FUNC_H */