(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
authortron
Fri, 17 Mar 2006 06:26:37 +0000
changeset 3238 a100405fe221
parent 3237 985399d4099d
child 3239 45396b9950aa
(svn r3912) Move the signal type enum and GetSignalType() to rail_map.h; also add SetSignalType() and use the functions
npf.c
rail.h
rail_cmd.c
rail_map.h
--- a/npf.c	Thu Mar 16 21:44:58 2006 +0000
+++ b/npf.c	Fri Mar 17 06:26:37 2006 +0000
@@ -348,7 +348,7 @@
 				 * encounter, if it is red */
 
 				/* Is this a presignal exit or combo? */
-				SignalType sigtype = GetSignalType(tile, TrackdirToTrack(trackdir));
+				SignalType sigtype = GetSignalType(tile);
 				if (sigtype == SIGTYPE_EXIT || sigtype == SIGTYPE_COMBO) {
 					/* Penalise exit and combo signals differently (heavier) */
 					cost += _patches.npf_rail_firstred_exit_penalty;
--- a/rail.h	Thu Mar 16 21:44:58 2006 +0000
+++ b/rail.h	Fri Mar 17 06:26:37 2006 +0000
@@ -42,15 +42,6 @@
 	RAIL_SUBTYPE_MASK     = 0x3C,
 } RailTileSubtype;
 
-typedef enum SignalTypes {
-	/* Stored in m4[0..1] for MP_RAILWAY */
-	SIGTYPE_NORMAL  = 0,        // normal signal
-	SIGTYPE_ENTRY   = 1,        // presignal block entry
-	SIGTYPE_EXIT    = 2,        // presignal block exit
-	SIGTYPE_COMBO   = 3,        // presignal inter-block
-	SIGTYPE_END,
-	SIGTYPE_MASK    = 3,
-} SignalType;
 
 typedef enum RailTypes {
 	RAILTYPE_RAIL   = 0,
@@ -514,20 +505,6 @@
 		SIGNAL_STATE_GREEN : SIGNAL_STATE_RED;
 }
 
-/**
- * Gets the type of signal on a given track on a given rail tile with signals.
- *
- * Note that currently, the track argument is not used, since
- * signal types cannot be mixed. This function is trying to be
- * future-compatible, though.
- */
-static inline SignalType GetSignalType(TileIndex tile, Track track)
-{
-	assert(IsValidTrack(track));
-	assert(GetRailTileType(tile) == RAIL_TYPE_SIGNALS);
-	return (SignalType)(_m[tile].m4 & SIGTYPE_MASK);
-}
-
 
 /**
  * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
--- a/rail_cmd.c	Thu Mar 16 21:44:58 2006 +0000
+++ b/rail_cmd.c	Fri Mar 17 06:26:37 2006 +0000
@@ -745,8 +745,9 @@
 			} else {
 				if (pre_signal) {
 					// cycle between normal -> pre -> exit -> combo -> ...
-					byte type = (GetSignalType(tile, track) + 1) % SIGTYPE_END;
-					SB(_m[tile].m4, 0, 2, type);
+					SignalType type = GetSignalType(tile);
+
+					SetSignalType(tile, type == SIGTYPE_COMBO ? SIGTYPE_NORMAL : type + 1);
 				} else {
 					// cycle between two-way -> one-way -> one-way -> ...
 					/* TODO: Rewrite switch into something more general */
@@ -2035,7 +2036,7 @@
 				STR_RAILROAD_TRACK_WITH_COMBOSIGNALS
 			};
 
-			td->str = signal_type[GB(_m[tile].m4, 0, 2)];
+			td->str = signal_type[GetSignalType(tile)];
 			break;
 		}
 
--- a/rail_map.h	Thu Mar 16 21:44:58 2006 +0000
+++ b/rail_map.h	Fri Mar 17 06:26:37 2006 +0000
@@ -20,6 +20,26 @@
 }
 
 
+typedef enum SignalType {
+	SIGTYPE_NORMAL  = 0, // normal signal
+	SIGTYPE_ENTRY   = 1, // presignal block entry
+	SIGTYPE_EXIT    = 2, // presignal block exit
+	SIGTYPE_COMBO   = 3  // presignal inter-block
+} SignalType;
+
+static inline SignalType GetSignalType(TileIndex t)
+{
+	assert(GetRailTileType(t) == RAIL_TYPE_SIGNALS);
+	return (SignalType)GB(_m[t].m4, 0, 2);
+}
+
+static inline void SetSignalType(TileIndex t, SignalType s)
+{
+	assert(GetRailTileType(t) == RAIL_TYPE_SIGNALS);
+	SB(_m[t].m4, 0, 2, s);
+}
+
+
 typedef enum SignalVariant {
 	SIG_ELECTRIC  = 0,
 	SIG_SEMAPHORE = 1