tron@3101: /* $Id$ */ tron@3101: belugas@6393: /** @file rail_map.h Hides the direct accesses to the map array with map accessors */ belugas@6393: tron@3101: #ifndef RAIL_MAP_H tron@3101: #define RAIL_MAP_H tron@3101: rubidium@8138: #include "rail_type.h" rubidium@8138: #include "signal_func.h" rubidium@8100: #include "direction_func.h" rubidium@8101: #include "track_func.h" rubidium@8108: #include "tile_map.h" belugas@8761: #include "signal_type.h" rubidium@8775: #include "waypoint_type.h" tron@3239: tron@3239: rubidium@6540: /** Different types of Rail-related tiles */ rubidium@6248: enum RailTileType { rubidium@6540: RAIL_TILE_NORMAL = 0, ///< Normal rail tile without signals rubidium@6540: RAIL_TILE_SIGNALS = 1, ///< Normal rail tile with signals rubidium@6540: RAIL_TILE_WAYPOINT = 2, ///< Waypoint (X or Y direction) rubidium@6540: RAIL_TILE_DEPOT = 3, ///< Depot (one entrance) rubidium@6248: }; tron@3239: rubidium@6540: /** rubidium@6540: * Returns the RailTileType (normal with or without signals, rubidium@6540: * waypoint or depot). rubidium@6540: * @param t the tile to get the information from rubidium@6540: * @pre IsTileType(t, MP_RAILWAY) rubidium@6540: * @return the RailTileType rubidium@6540: */ tron@3239: static inline RailTileType GetRailTileType(TileIndex t) tron@3239: { tron@3239: assert(IsTileType(t, MP_RAILWAY)); rubidium@6172: return (RailTileType)GB(_m[t].m5, 6, 2); tron@3239: } tron@3239: tron@3772: /** tron@3772: * Returns whether this is plain rails, with or without signals. Iow, if this rubidium@3792: * tiles RailTileType is RAIL_TILE_NORMAL or RAIL_TILE_SIGNALS. rubidium@6540: * @param t the tile to get the information from rubidium@6540: * @pre IsTileType(t, MP_RAILWAY) rubidium@6540: * @return true if and only if the tile is normal rail (with or without signals) tron@3772: */ rubidium@6540: static inline bool IsPlainRailTile(TileIndex t) tron@3772: { rubidium@6540: RailTileType rtt = GetRailTileType(t); rubidium@3792: return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS; tron@3772: } tron@3772: tron@3772: /** tron@3772: * Checks if a rail tile has signals. rubidium@6540: * @param t the tile to get the information from rubidium@6540: * @pre IsTileType(t, MP_RAILWAY) rubidium@6540: * @return true if and only if the tile has signals tron@3772: */ rubidium@6540: static inline bool HasSignals(TileIndex t) tron@3772: { rubidium@6540: return GetRailTileType(t) == RAIL_TILE_SIGNALS; tron@3772: } tron@3772: tron@3772: /** rubidium@6172: * Add/remove the 'has signal' bit from the RailTileType rubidium@6540: * @param tile the tile to add/remove the signals to/from rubidium@6540: * @param signals whether the rail tile should have signals or not rubidium@6540: * @pre IsPlainRailTile(tile) tron@3772: */ rubidium@6172: static inline void SetHasSignals(TileIndex tile, bool signals) tron@3772: { rubidium@6172: assert(IsPlainRailTile(tile)); rubidium@6172: SB(_m[tile].m5, 6, 1, signals); tron@3772: } tron@3772: rubidium@6540: /** smatz@8954: * Is this rail tile a rail waypoint? smatz@8954: * @param t the tile to get the information from smatz@8954: * @pre IsTileType(t, MP_RAILWAY) smatz@8954: * @return true if and only if the tile is a rail waypoint smatz@8954: */ smatz@8954: static inline bool IsRailWaypoint(TileIndex t) smatz@8954: { smatz@8954: return GetRailTileType(t) == RAIL_TILE_WAYPOINT; smatz@8954: } smatz@8954: smatz@8954: /** smatz@10099: * Is this tile rail tile and a rail waypoint? smatz@10099: * @param t the tile to get the information from smatz@10099: * @return true if and only if the tile is a rail waypoint smatz@10099: */ smatz@10099: static inline bool IsRailWaypointTile(TileIndex t) smatz@10099: { smatz@10099: return IsTileType(t, MP_RAILWAY) && IsRailWaypoint(t); smatz@10099: } smatz@10099: smatz@10099: /** smatz@8954: * Is this rail tile a rail depot? rubidium@6540: * @param t the tile to get the information from rubidium@6540: * @pre IsTileType(t, MP_RAILWAY) rubidium@6540: * @return true if and only if the tile is a rail depot rubidium@6540: */ tron@4182: static inline bool IsRailDepot(TileIndex t) tron@4182: { rubidium@6172: return GetRailTileType(t) == RAIL_TILE_DEPOT; tron@4182: } tron@4182: rubidium@6540: /** smatz@8954: * Is this tile rail tile and a rail depot? rubidium@6540: * @param t the tile to get the information from smatz@8954: * @return true if and only if the tile is a rail depot rubidium@6540: */ smatz@8954: static inline bool IsRailDepotTile(TileIndex t) tron@4044: { smatz@8954: return IsTileType(t, MP_RAILWAY) && IsRailDepot(t); tron@4044: } tron@4044: rubidium@6540: /** rubidium@6540: * Gets the rail type of the given tile rubidium@6540: * @param t the tile to get the rail type from rubidium@6540: * @return the rail type of the tile rubidium@6540: */ tron@3239: static inline RailType GetRailType(TileIndex t) tron@3239: { tron@3239: return (RailType)GB(_m[t].m3, 0, 4); tron@3239: } tron@3239: rubidium@6540: /** glx@8632: * Sets the rail type of the given tile glx@8632: * @param t the tile to set the rail type of glx@8632: * @param r the new rail type for the tile rubidium@6540: */ tron@3242: static inline void SetRailType(TileIndex t, RailType r) tron@3242: { tron@3242: SB(_m[t].m3, 0, 4, r); tron@3242: } tron@3242: tron@3239: rubidium@6540: /** glx@8632: * Gets the track bits of the given tile glx@8632: * @param t the tile to get the track bits from glx@8632: * @return the track bits of the tile rubidium@6540: */ tron@3267: static inline TrackBits GetTrackBits(TileIndex tile) tron@3267: { tron@3267: return (TrackBits)GB(_m[tile].m5, 0, 6); tron@3267: } tron@3267: rubidium@6540: /** rubidium@6540: * Sets the track bits of the given tile rubidium@6540: * @param t the tile to set the track bits of rubidium@6540: * @param b the new track bits for the tile rubidium@6540: */ tron@3273: static inline void SetTrackBits(TileIndex t, TrackBits b) tron@3273: { tron@3273: SB(_m[t].m5, 0, 6, b); tron@3273: } tron@3273: tron@3772: /** rubidium@6540: * Returns whether the given track is present on the given tile. rubidium@6540: * @param tile the tile to check the track presence of rubidium@6540: * @param track the track to search for on the tile rubidium@6540: * @pre IsPlainRailTile(tile) rubidium@6540: * @return true if and only if the given track exists on the tile tron@3772: */ tron@3772: static inline bool HasTrack(TileIndex tile, Track track) tron@3772: { skidd13@7928: return HasBit(GetTrackBits(tile), track); tron@3772: } tron@3772: rubidium@6540: /** rubidium@6540: * Returns the direction the depot is facing to rubidium@6540: * @param t the tile to get the depot facing from rubidium@6540: * @pre IsRailDepotTile(t) rubidium@6540: * @return the direction the depot is facing rubidium@6540: */ tron@3185: static inline DiagDirection GetRailDepotDirection(TileIndex t) tron@3185: { tron@3185: return (DiagDirection)GB(_m[t].m5, 0, 2); tron@3185: } tron@3185: smatz@9224: /** smatz@9224: * Returns the track of a depot, ignoring direction smatz@9224: * @pre IsRailDepotTile(t) smatz@9224: * @param t the tile to get the depot track from smatz@9224: * @return the track of the depot smatz@9224: */ smatz@9224: static inline Track GetRailDepotTrack(TileIndex t) smatz@9224: { smatz@9224: return DiagDirToDiagTrack(GetRailDepotDirection(t)); smatz@9224: } smatz@9224: tron@4158: rubidium@6540: /** rubidium@6540: * Returns the axis of the waypoint rubidium@6540: * @param t the tile to get the waypoint axis from rubidium@6540: * @pre IsRailWaypointTile(t) rubidium@6540: * @return the axis of the waypoint rubidium@6540: */ tron@4158: static inline Axis GetWaypointAxis(TileIndex t) tron@4158: { tron@4474: return (Axis)GB(_m[t].m5, 0, 1); tron@4158: } tron@4158: rubidium@6540: /** rubidium@6540: * Returns the track of the waypoint rubidium@6540: * @param t the tile to get the waypoint track from rubidium@6540: * @pre IsRailWaypointTile(t) rubidium@6540: * @return the track of the waypoint rubidium@6540: */ celestar@3453: static inline Track GetRailWaypointTrack(TileIndex t) celestar@3448: { tron@4158: return AxisToTrack(GetWaypointAxis(t)); celestar@3448: } tron@3185: rubidium@6540: /** rubidium@6540: * Returns the track bits of the waypoint rubidium@6540: * @param t the tile to get the waypoint track bits from rubidium@6540: * @pre IsRailWaypointTile(t) rubidium@6540: * @return the track bits of the waypoint rubidium@6540: */ tron@3101: static inline TrackBits GetRailWaypointBits(TileIndex t) tron@3101: { tron@4158: return TrackToTrackBits(GetRailWaypointTrack(t)); celestar@3528: } celestar@3528: rubidium@6540: /** rubidium@6540: * Returns waypoint index (for the waypoint pool) rubidium@6540: * @param t the tile to get the waypoint index from rubidium@6540: * @pre IsRailWaypointTile(t) rubidium@6540: * @return the waypoint index rubidium@6540: */ rubidium@6182: static inline WaypointID GetWaypointIndex(TileIndex t) rubidium@6182: { rubidium@6182: return (WaypointID)_m[t].m2; rubidium@6182: } tron@3101: rubidium@9784: rubidium@9784: /** rubidium@9784: * Returns the reserved track bits of the tile rubidium@9784: * @pre IsPlainRailTile(t) rubidium@9784: * @param t the tile to query rubidium@9784: * @return the track bits rubidium@9784: */ rubidium@9784: static inline TrackBits GetTrackReservation(TileIndex t) rubidium@9784: { rubidium@9784: assert(IsPlainRailTile(t)); rubidium@9784: byte track_b = GB(_m[t].m2, 8, 3); rubidium@9784: Track track = (Track)(track_b - 1); // map array saves Track+1 rubidium@9784: if (track_b == 0) return TRACK_BIT_NONE; rubidium@9784: return (TrackBits)(TrackToTrackBits(track) | (HasBit(_m[t].m2, 11) ? TrackToTrackBits(TrackToOppositeTrack(track)) : 0)); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Sets the reserved track bits of the tile rubidium@9784: * @pre IsPlainRailTile(t) && !TracksOverlap(b) rubidium@9784: * @param t the tile to change rubidium@9784: * @param b the track bits rubidium@9784: */ rubidium@9784: static inline void SetTrackReservation(TileIndex t, TrackBits b) rubidium@9784: { rubidium@9784: assert(IsPlainRailTile(t)); rubidium@9784: assert(b != INVALID_TRACK_BIT); rubidium@9784: assert(!TracksOverlap(b)); rubidium@9784: Track track = RemoveFirstTrack(&b); rubidium@9784: SB(_m[t].m2, 8, 3, track == INVALID_TRACK ? 0 : track+1); rubidium@9784: SB(_m[t].m2, 11, 1, (byte)(b != TRACK_BIT_NONE)); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9787: * Try to reserve a specific track on a tile rubidium@9787: * @pre IsPlainRailTile(t) && HasTrack(tile, t) rubidium@9787: * @param tile the tile rubidium@9787: * @param t the rack to reserve rubidium@9787: * @return true if successful rubidium@9787: */ rubidium@9787: static inline bool TryReserveTrack(TileIndex tile, Track t) rubidium@9787: { rubidium@9787: assert(HasTrack(tile, t)); rubidium@9787: TrackBits bits = TrackToTrackBits(t); rubidium@9787: TrackBits res = GetTrackReservation(tile); rubidium@9787: if ((res & bits) != TRACK_BIT_NONE) return false; // already reserved rubidium@9787: res |= bits; rubidium@9787: if (TracksOverlap(res)) return false; // crossing reservation present rubidium@9787: SetTrackReservation(tile, res); rubidium@9787: return true; rubidium@9787: } rubidium@9787: rubidium@9787: /** rubidium@9787: * Lift the reservation of a specific track on a tile rubidium@9787: * @pre IsPlainRailTile(t) && HasTrack(tile, t) rubidium@9787: * @param tile the tile rubidium@9787: * @param t the track to free rubidium@9787: */ rubidium@9787: static inline void UnreserveTrack(TileIndex tile, Track t) rubidium@9787: { rubidium@9787: assert(HasTrack(tile, t)); rubidium@9787: TrackBits res = GetTrackReservation(tile); rubidium@9787: res &= ~TrackToTrackBits(t); rubidium@9787: SetTrackReservation(tile, res); rubidium@9787: } rubidium@9787: rubidium@9787: /** rubidium@9784: * Get the reservation state of the waypoint or depot rubidium@9784: * @note Works for both waypoints and rail depots rubidium@9784: * @pre IsRailWaypoint(t) || IsRailDepot(t) rubidium@9784: * @param t the waypoint/depot tile rubidium@9784: * @return reservation state rubidium@9784: */ rubidium@9784: static inline bool GetDepotWaypointReservation(TileIndex t) rubidium@9784: { rubidium@9784: assert(IsRailWaypoint(t) || IsRailDepot(t)); rubidium@9784: return HasBit(_m[t].m5, 4); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Set the reservation state of the waypoint or depot rubidium@9784: * @note Works for both waypoints and rail depots rubidium@9784: * @pre IsRailWaypoint(t) || IsRailDepot(t) rubidium@9784: * @param t the waypoint/depot tile rubidium@9784: * @param b the reservation state rubidium@9784: */ rubidium@9784: static inline void SetDepotWaypointReservation(TileIndex t, bool b) rubidium@9784: { rubidium@9784: assert(IsRailWaypoint(t) || IsRailDepot(t)); rubidium@9784: SB(_m[t].m5, 4, 1, (byte)b); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Get the reserved track bits for a waypoint rubidium@9784: * @pre IsRailWaypoint(t) rubidium@9784: * @param t the tile rubidium@9784: * @return reserved track bits rubidium@9784: */ rubidium@9784: static inline TrackBits GetRailWaypointReservation(TileIndex t) rubidium@9784: { rubidium@9784: return GetDepotWaypointReservation(t) ? GetRailWaypointBits(t) : TRACK_BIT_NONE; rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Get the reserved track bits for a depot rubidium@9784: * @pre IsRailDepot(t) rubidium@9784: * @param t the tile rubidium@9784: * @return reserved track bits rubidium@9784: */ rubidium@9784: static inline TrackBits GetRailDepotReservation(TileIndex t) rubidium@9784: { rubidium@9784: return GetDepotWaypointReservation(t) ? TrackToTrackBits(GetRailDepotTrack(t)) : TRACK_BIT_NONE; rubidium@9784: } rubidium@9784: rubidium@9784: rubidium@9790: static inline bool IsPbsSignal(SignalType s) rubidium@9790: { rubidium@9790: return s == SIGTYPE_PBS || s == SIGTYPE_PBS_ONEWAY; rubidium@9790: } rubidium@9790: glx@6770: static inline SignalType GetSignalType(TileIndex t, Track track) tron@3238: { rubidium@3792: assert(GetRailTileType(t) == RAIL_TILE_SIGNALS); glx@6770: byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0; rubidium@9790: return (SignalType)GB(_m[t].m2, pos, 3); tron@3238: } tron@3238: glx@6770: static inline void SetSignalType(TileIndex t, Track track, SignalType s) celestar@3521: { glx@6770: assert(GetRailTileType(t) == RAIL_TILE_SIGNALS); glx@6770: byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0; rubidium@9790: SB(_m[t].m2, pos, 3, s); rubidium@9790: if (track == INVALID_TRACK) SB(_m[t].m2, 4, 3, s); celestar@3521: } celestar@3521: glx@6770: static inline bool IsPresignalEntry(TileIndex t, Track track) celestar@3521: { glx@6770: return GetSignalType(t, track) == SIGTYPE_ENTRY || GetSignalType(t, track) == SIGTYPE_COMBO; glx@6770: } glx@6770: glx@6770: static inline bool IsPresignalExit(TileIndex t, Track track) glx@6770: { glx@6770: return GetSignalType(t, track) == SIGTYPE_EXIT || GetSignalType(t, track) == SIGTYPE_COMBO; celestar@3521: } celestar@3521: rubidium@9791: /** One-way signals can't be passed the 'wrong' way. */ rubidium@9791: static inline bool IsOnewaySignal(TileIndex t, Track track) rubidium@9791: { rubidium@9791: return GetSignalType(t, track) != SIGTYPE_PBS; rubidium@9791: } rubidium@9791: celestar@3522: static inline void CycleSignalSide(TileIndex t, Track track) celestar@3522: { celestar@3522: byte sig; glx@6770: byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 6; celestar@3522: celestar@3522: sig = GB(_m[t].m3, pos, 2); rubidium@9795: if (--sig == 0) sig = IsPbsSignal(GetSignalType(t, track)) ? 2 : 3; celestar@3522: SB(_m[t].m3, pos, 2, sig); celestar@3522: } celestar@3522: glx@6770: static inline SignalVariant GetSignalVariant(TileIndex t, Track track) tron@3237: { rubidium@9790: byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 7 : 3; glx@6770: return (SignalVariant)GB(_m[t].m2, pos, 1); tron@3237: } tron@3237: glx@6770: static inline void SetSignalVariant(TileIndex t, Track track, SignalVariant v) tron@3237: { rubidium@9790: byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 7 : 3; glx@6770: SB(_m[t].m2, pos, 1, v); rubidium@9790: if (track == INVALID_TRACK) SB(_m[t].m2, 7, 1, v); tron@3237: } tron@3237: celestar@3575: /** These are states in which a signal can be. Currently these are only two, so celestar@3575: * simple boolean logic will do. But do try to compare to this enum instead of celestar@3575: * normal boolean evaluation, since that will make future additions easier. celestar@3575: */ rubidium@6248: enum SignalState { rubidium@6540: SIGNAL_STATE_RED = 0, ///< The signal is red rubidium@6540: SIGNAL_STATE_GREEN = 1, ///< The signal is green rubidium@6248: }; celestar@3575: rubidium@6753: /** rubidium@6753: * Set the states of the signals (Along/AgainstTrackDir) rubidium@6753: * @param tile the tile to set the states for rubidium@6753: * @param state the new state rubidium@6753: */ rubidium@6753: static inline void SetSignalStates(TileIndex tile, uint state) rubidium@6753: { glx@6770: SB(_m[tile].m4, 4, 4, state); rubidium@6753: } rubidium@6753: rubidium@6753: /** rubidium@6753: * Set the states of the signals (Along/AgainstTrackDir) rubidium@6753: * @param tile the tile to set the states for rubidium@6753: * @param state the new state rubidium@6753: */ rubidium@6753: static inline uint GetSignalStates(TileIndex tile) rubidium@6753: { glx@6770: return GB(_m[tile].m4, 4, 4); rubidium@6753: } rubidium@6753: rubidium@6753: /** rubidium@6753: * Get the state of a single signal rubidium@6753: * @param t the tile to get the signal state for rubidium@6753: * @param signalbit the signal rubidium@6753: * @return the state of the signal rubidium@6753: */ celestar@3575: static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit) celestar@3575: { skidd13@7928: return (SignalState)HasBit(GetSignalStates(t), signalbit); celestar@3575: } celestar@3575: rubidium@6753: /** rubidium@6753: * Set whether the given signals are present (Along/AgainstTrackDir) rubidium@6753: * @param tile the tile to set the present signals for rubidium@6753: * @param signals the signals that have to be present rubidium@6753: */ rubidium@6753: static inline void SetPresentSignals(TileIndex tile, uint signals) rubidium@6753: { rubidium@6753: SB(_m[tile].m3, 4, 4, signals); rubidium@6753: } rubidium@6753: rubidium@6753: /** rubidium@6753: * Get whether the given signals are present (Along/AgainstTrackDir) rubidium@6753: * @param tile the tile to get the present signals for rubidium@6753: * @return the signals that are present rubidium@6753: */ rubidium@6753: static inline uint GetPresentSignals(TileIndex tile) rubidium@6753: { rubidium@6753: return GB(_m[tile].m3, 4, 4); rubidium@6753: } rubidium@6753: rubidium@6753: /** rubidium@6753: * Checks whether the given signals is present rubidium@6753: * @param t the tile to check on rubidium@6753: * @param signalbit the signal rubidium@6753: * @return true if and only if the signal is present rubidium@6753: */ rubidium@6753: static inline bool IsSignalPresent(TileIndex t, byte signalbit) rubidium@6753: { skidd13@7928: return HasBit(GetPresentSignals(t), signalbit); rubidium@6753: } tron@3237: tron@4041: /** tron@4041: * Checks for the presence of signals (either way) on the given track on the tron@4041: * given rail tile. tron@4041: */ tron@4041: static inline bool HasSignalOnTrack(TileIndex tile, Track track) tron@4041: { tron@4041: assert(IsValidTrack(track)); tron@4041: return tron@4041: GetRailTileType(tile) == RAIL_TILE_SIGNALS && rubidium@6753: (GetPresentSignals(tile) & SignalOnTrack(track)) != 0; tron@4041: } tron@4041: tron@4041: /** tron@4041: * Checks for the presence of signals along the given trackdir on the given tron@4041: * rail tile. tron@4041: * tron@4041: * Along meaning if you are currently driving on the given trackdir, this is tron@4041: * the signal that is facing us (for which we stop when it's red). tron@4041: */ tron@4041: static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir) tron@4041: { tron@4041: assert (IsValidTrackdir(trackdir)); tron@4041: return tron@4041: GetRailTileType(tile) == RAIL_TILE_SIGNALS && rubidium@6753: GetPresentSignals(tile) & SignalAlongTrackdir(trackdir); tron@4041: } tron@4041: tron@4041: /** tron@4041: * Gets the state of the signal along the given trackdir. tron@4041: * tron@4041: * Along meaning if you are currently driving on the given trackdir, this is tron@4041: * the signal that is facing us (for which we stop when it's red). tron@4041: */ tron@4041: static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir) tron@4041: { tron@4041: assert(IsValidTrackdir(trackdir)); tron@4041: assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir))); rubidium@6753: return GetSignalStates(tile) & SignalAlongTrackdir(trackdir) ? tron@4041: SIGNAL_STATE_GREEN : SIGNAL_STATE_RED; tron@4041: } tron@4041: smatz@8238: /** smatz@8238: * Sets the state of the signal along the given trackdir. smatz@8238: */ smatz@8238: static inline void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, SignalState state) smatz@8238: { smatz@8238: if (state == SIGNAL_STATE_GREEN) { // set 1 smatz@8238: SetSignalStates(tile, GetSignalStates(tile) | SignalAlongTrackdir(trackdir)); smatz@8238: } else { smatz@8238: SetSignalStates(tile, GetSignalStates(tile) & ~SignalAlongTrackdir(trackdir)); smatz@8238: } smatz@8238: } smatz@8238: rubidium@9790: /** rubidium@9790: * Is a pbs signal present along the trackdir? rubidium@9790: * @param tile the tile to check rubidium@9790: * @param td the trackdir to check rubidium@9790: */ rubidium@9790: static inline bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td) rubidium@9790: { rubidium@9790: return rubidium@9790: IsTileType(tile, MP_RAILWAY) && rubidium@9790: HasSignalOnTrackdir(tile, td) && rubidium@9790: IsPbsSignal(GetSignalType(tile, TrackdirToTrack(td))); rubidium@9790: } rubidium@9790: rubidium@9798: /** rubidium@9798: * Is a one-way signal blocking the trackdir? A one-way signal on the rubidium@9798: * trackdir against will block, but signals on both trackdirs won't. rubidium@9798: * @param tile the tile to check rubidium@9798: * @param td the trackdir to check rubidium@9798: */ rubidium@9798: static inline bool HasOnewaySignalBlockingTrackdir(TileIndex tile, Trackdir td) rubidium@9798: { rubidium@9798: return rubidium@9798: IsTileType(tile, MP_RAILWAY) && rubidium@9798: HasSignalOnTrackdir(tile, ReverseTrackdir(td)) && rubidium@9798: !HasSignalOnTrackdir(tile, td) && rubidium@9798: IsOnewaySignal(tile, TrackdirToTrack(td)); rubidium@9798: } rubidium@9798: tron@4041: tron@4041: /** tron@4041: * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile. tron@4041: */ tron@6154: RailType GetTileRailType(TileIndex tile); tron@4041: rubidium@6540: /** The ground 'under' the rail */ rubidium@6248: enum RailGroundType { rubidium@6540: RAIL_GROUND_BARREN = 0, ///< Nothing (dirt) rubidium@6540: RAIL_GROUND_GRASS = 1, ///< Grassy rubidium@6540: RAIL_GROUND_FENCE_NW = 2, ///< Grass with a fence at the NW edge rubidium@6540: RAIL_GROUND_FENCE_SE = 3, ///< Grass with a fence at the SE edge rubidium@6540: RAIL_GROUND_FENCE_SENW = 4, ///< Grass with a fence at the NW and SE edges rubidium@6540: RAIL_GROUND_FENCE_NE = 5, ///< Grass with a fence at the NE edge rubidium@6540: RAIL_GROUND_FENCE_SW = 6, ///< Grass with a fence at the SW edge rubidium@6540: RAIL_GROUND_FENCE_NESW = 7, ///< Grass with a fence at the NE and SW edges truelight@7307: RAIL_GROUND_FENCE_VERT1 = 8, ///< Grass with a fence at the eastern side truelight@7307: RAIL_GROUND_FENCE_VERT2 = 9, ///< Grass with a fence at the western side rubidium@6540: RAIL_GROUND_FENCE_HORIZ1 = 10, ///< Grass with a fence at the southern side rubidium@6540: RAIL_GROUND_FENCE_HORIZ2 = 11, ///< Grass with a fence at the northern side rubidium@6540: RAIL_GROUND_ICE_DESERT = 12, ///< Icy or sandy frosch@8414: RAIL_GROUND_WATER = 13, ///< Grass with a fence and shore or water on the free halftile smatz@8523: RAIL_GROUND_HALF_SNOW = 14, ///< Snow only on higher part of slope (steep or one corner raised) rubidium@6248: }; celestar@3523: celestar@3523: static inline void SetRailGroundType(TileIndex t, RailGroundType rgt) celestar@3523: { rubidium@6172: SB(_m[t].m4, 0, 4, rgt); celestar@3523: } celestar@3523: celestar@3523: static inline RailGroundType GetRailGroundType(TileIndex t) celestar@3523: { rubidium@6172: return (RailGroundType)GB(_m[t].m4, 0, 4); celestar@3523: } celestar@3523: celestar@3523: static inline bool IsSnowRailGround(TileIndex t) celestar@3523: { celestar@3523: return GetRailGroundType(t) == RAIL_GROUND_ICE_DESERT; celestar@3523: } celestar@3523: celestar@3523: tron@3101: static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r) tron@3101: { tron@3101: SetTileType(t, MP_RAILWAY); tron@3101: SetTileOwner(t, o); tron@3101: _m[t].m2 = 0; tron@3101: _m[t].m3 = r; tron@3101: _m[t].m4 = 0; rubidium@6172: _m[t].m5 = RAIL_TILE_NORMAL << 6 | b; tron@3101: } tron@3101: tron@3101: tron@3101: static inline void MakeRailDepot(TileIndex t, Owner o, DiagDirection d, RailType r) tron@3101: { tron@3101: SetTileType(t, MP_RAILWAY); tron@3101: SetTileOwner(t, o); tron@3101: _m[t].m2 = 0; tron@3101: _m[t].m3 = r; tron@3101: _m[t].m4 = 0; rubidium@6172: _m[t].m5 = RAIL_TILE_DEPOT << 6 | d; tron@3101: } tron@3101: tron@3101: tron@3101: static inline void MakeRailWaypoint(TileIndex t, Owner o, Axis a, RailType r, uint index) tron@3101: { tron@3101: SetTileType(t, MP_RAILWAY); tron@3101: SetTileOwner(t, o); tron@3101: _m[t].m2 = index; tron@3101: _m[t].m3 = r; tron@3101: _m[t].m4 = 0; rubidium@6172: _m[t].m5 = RAIL_TILE_WAYPOINT << 6 | a; tron@3101: } tron@3101: peter1138@4666: #endif /* RAIL_MAP_H */