diff --git a/npf.c b/npf.c index 474022a7ec..96daea2c83 100644 --- a/npf.c +++ b/npf.c @@ -348,7 +348,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare * 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; diff --git a/rail.h b/rail.h index 8c7cb8a42c..bbb27ecedd 100644 --- a/rail.h +++ b/rail.h @@ -42,15 +42,6 @@ typedef enum RailTileSubtypes { 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 @@ static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir) 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. diff --git a/rail_cmd.c b/rail_cmd.c index a9913c7ceb..f7d6d22b3a 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -745,8 +745,9 @@ int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) } 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 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td) STR_RAILROAD_TRACK_WITH_COMBOSIGNALS }; - td->str = signal_type[GB(_m[tile].m4, 0, 2)]; + td->str = signal_type[GetSignalType(tile)]; break; } diff --git a/rail_map.h b/rail_map.h index 0ad2241317..ab09db4eda 100644 --- a/rail_map.h +++ b/rail_map.h @@ -20,6 +20,26 @@ static inline TrackBits GetRailWaypointBits(TileIndex t) } +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