Codechange: make use of Tile in for all direct map accesses

This commit is contained in:
Rubidium
2023-01-21 16:40:28 +01:00
committed by rubidium42
parent 7a6452d3ef
commit 580d0a6343
30 changed files with 963 additions and 946 deletions

View File

@@ -33,10 +33,10 @@ enum RailTileType {
* @pre IsTileType(t, MP_RAILWAY)
* @return the RailTileType
*/
debug_inline static RailTileType GetRailTileType(TileIndex t)
debug_inline static RailTileType GetRailTileType(Tile t)
{
assert(IsTileType(t, MP_RAILWAY));
return (RailTileType)GB(_m[t].m5, 6, 2);
return (RailTileType)GB(t.m5(), 6, 2);
}
/**
@@ -46,7 +46,7 @@ debug_inline static RailTileType GetRailTileType(TileIndex t)
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile is normal rail (with or without signals)
*/
debug_inline static bool IsPlainRail(TileIndex t)
debug_inline static bool IsPlainRail(Tile t)
{
RailTileType rtt = GetRailTileType(t);
return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS;
@@ -57,7 +57,7 @@ debug_inline static bool IsPlainRail(TileIndex t)
* @param t the tile to get the information from
* @return true if and only if the tile is normal rail (with or without signals)
*/
debug_inline static bool IsPlainRailTile(TileIndex t)
debug_inline static bool IsPlainRailTile(Tile t)
{
return IsTileType(t, MP_RAILWAY) && IsPlainRail(t);
}
@@ -69,7 +69,7 @@ debug_inline static bool IsPlainRailTile(TileIndex t)
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile has signals
*/
static inline bool HasSignals(TileIndex t)
static inline bool HasSignals(Tile t)
{
return GetRailTileType(t) == RAIL_TILE_SIGNALS;
}
@@ -80,10 +80,10 @@ static inline bool HasSignals(TileIndex t)
* @param signals whether the rail tile should have signals or not
* @pre IsPlainRailTile(tile)
*/
static inline void SetHasSignals(TileIndex tile, bool signals)
static inline void SetHasSignals(Tile tile, bool signals)
{
assert(IsPlainRailTile(tile));
SB(_m[tile].m5, 6, 1, signals);
SB(tile.m5(), 6, 1, signals);
}
/**
@@ -92,7 +92,7 @@ static inline void SetHasSignals(TileIndex tile, bool signals)
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile is a rail depot
*/
debug_inline static bool IsRailDepot(TileIndex t)
debug_inline static bool IsRailDepot(Tile t)
{
return GetRailTileType(t) == RAIL_TILE_DEPOT;
}
@@ -102,7 +102,7 @@ debug_inline static bool IsRailDepot(TileIndex t)
* @param t the tile to get the information from
* @return true if and only if the tile is a rail depot
*/
debug_inline static bool IsRailDepotTile(TileIndex t)
debug_inline static bool IsRailDepotTile(Tile t)
{
return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
}
@@ -112,9 +112,9 @@ debug_inline static bool IsRailDepotTile(TileIndex t)
* @param t the tile to get the rail type from
* @return the rail type of the tile
*/
static inline RailType GetRailType(TileIndex t)
static inline RailType GetRailType(Tile t)
{
return (RailType)GB(_me[t].m8, 0, 6);
return (RailType)GB(t.m8(), 0, 6);
}
/**
@@ -122,9 +122,9 @@ static inline RailType GetRailType(TileIndex t)
* @param t the tile to set the rail type of
* @param r the new rail type for the tile
*/
static inline void SetRailType(TileIndex t, RailType r)
static inline void SetRailType(Tile t, RailType r)
{
SB(_me[t].m8, 0, 6, r);
SB(t.m8(), 0, 6, r);
}
@@ -133,10 +133,10 @@ static inline void SetRailType(TileIndex t, RailType r)
* @param tile the tile to get the track bits from
* @return the track bits of the tile
*/
static inline TrackBits GetTrackBits(TileIndex tile)
static inline TrackBits GetTrackBits(Tile tile)
{
assert(IsPlainRailTile(tile));
return (TrackBits)GB(_m[tile].m5, 0, 6);
return (TrackBits)GB(tile.m5(), 0, 6);
}
/**
@@ -144,10 +144,10 @@ static inline TrackBits GetTrackBits(TileIndex tile)
* @param t the tile to set the track bits of
* @param b the new track bits for the tile
*/
static inline void SetTrackBits(TileIndex t, TrackBits b)
static inline void SetTrackBits(Tile t, TrackBits b)
{
assert(IsPlainRailTile(t));
SB(_m[t].m5, 0, 6, b);
SB(t.m5(), 0, 6, b);
}
/**
@@ -157,7 +157,7 @@ static inline void SetTrackBits(TileIndex t, TrackBits b)
* @pre IsPlainRailTile(tile)
* @return true if and only if the given track exists on the tile
*/
static inline bool HasTrack(TileIndex tile, Track track)
static inline bool HasTrack(Tile tile, Track track)
{
return HasBit(GetTrackBits(tile), track);
}
@@ -168,9 +168,9 @@ static inline bool HasTrack(TileIndex tile, Track track)
* @pre IsRailDepotTile(t)
* @return the direction the depot is facing
*/
static inline DiagDirection GetRailDepotDirection(TileIndex t)
static inline DiagDirection GetRailDepotDirection(Tile t)
{
return (DiagDirection)GB(_m[t].m5, 0, 2);
return (DiagDirection)GB(t.m5(), 0, 2);
}
/**
@@ -179,7 +179,7 @@ static inline DiagDirection GetRailDepotDirection(TileIndex t)
* @param t the tile to get the depot track from
* @return the track of the depot
*/
static inline Track GetRailDepotTrack(TileIndex t)
static inline Track GetRailDepotTrack(Tile t)
{
return DiagDirToDiagTrack(GetRailDepotDirection(t));
}
@@ -191,13 +191,13 @@ static inline Track GetRailDepotTrack(TileIndex t)
* @param t the tile to query
* @return the track bits
*/
static inline TrackBits GetRailReservationTrackBits(TileIndex t)
static inline TrackBits GetRailReservationTrackBits(Tile t)
{
assert(IsPlainRailTile(t));
byte track_b = GB(_m[t].m2, 8, 3);
byte track_b = GB(t.m2(), 8, 3);
Track track = (Track)(track_b - 1); // map array saves Track+1
if (track_b == 0) return TRACK_BIT_NONE;
return (TrackBits)(TrackToTrackBits(track) | (HasBit(_m[t].m2, 11) ? TrackToTrackBits(TrackToOppositeTrack(track)) : 0));
return (TrackBits)(TrackToTrackBits(track) | (HasBit(t.m2(), 11) ? TrackToTrackBits(TrackToOppositeTrack(track)) : 0));
}
/**
@@ -206,14 +206,14 @@ static inline TrackBits GetRailReservationTrackBits(TileIndex t)
* @param t the tile to change
* @param b the track bits
*/
static inline void SetTrackReservation(TileIndex t, TrackBits b)
static inline void SetTrackReservation(Tile t, TrackBits b)
{
assert(IsPlainRailTile(t));
assert(b != INVALID_TRACK_BIT);
assert(!TracksOverlap(b));
Track track = RemoveFirstTrack(&b);
SB(_m[t].m2, 8, 3, track == INVALID_TRACK ? 0 : track + 1);
SB(_m[t].m2, 11, 1, (byte)(b != TRACK_BIT_NONE));
SB(t.m2(), 8, 3, track == INVALID_TRACK ? 0 : track + 1);
SB(t.m2(), 11, 1, (byte)(b != TRACK_BIT_NONE));
}
/**
@@ -223,7 +223,7 @@ static inline void SetTrackReservation(TileIndex t, TrackBits b)
* @param t the rack to reserve
* @return true if successful
*/
static inline bool TryReserveTrack(TileIndex tile, Track t)
static inline bool TryReserveTrack(Tile tile, Track t)
{
assert(HasTrack(tile, t));
TrackBits bits = TrackToTrackBits(t);
@@ -241,7 +241,7 @@ static inline bool TryReserveTrack(TileIndex tile, Track t)
* @param tile the tile
* @param t the track to free
*/
static inline void UnreserveTrack(TileIndex tile, Track t)
static inline void UnreserveTrack(Tile tile, Track t)
{
assert(HasTrack(tile, t));
TrackBits res = GetRailReservationTrackBits(tile);
@@ -255,10 +255,10 @@ static inline void UnreserveTrack(TileIndex tile, Track t)
* @param t the depot tile
* @return reservation state
*/
static inline bool HasDepotReservation(TileIndex t)
static inline bool HasDepotReservation(Tile t)
{
assert(IsRailDepot(t));
return HasBit(_m[t].m5, 4);
return HasBit(t.m5(), 4);
}
/**
@@ -267,10 +267,10 @@ static inline bool HasDepotReservation(TileIndex t)
* @param t the depot tile
* @param b the reservation state
*/
static inline void SetDepotReservation(TileIndex t, bool b)
static inline void SetDepotReservation(Tile t, bool b)
{
assert(IsRailDepot(t));
SB(_m[t].m5, 4, 1, (byte)b);
SB(t.m5(), 4, 1, (byte)b);
}
/**
@@ -279,7 +279,7 @@ static inline void SetDepotReservation(TileIndex t, bool b)
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetDepotReservationTrackBits(TileIndex t)
static inline TrackBits GetDepotReservationTrackBits(Tile t)
{
return HasDepotReservation(t) ? TrackToTrackBits(GetRailDepotTrack(t)) : TRACK_BIT_NONE;
}
@@ -290,58 +290,58 @@ static inline bool IsPbsSignal(SignalType s)
return s == SIGTYPE_PBS || s == SIGTYPE_PBS_ONEWAY;
}
static inline SignalType GetSignalType(TileIndex t, Track track)
static inline SignalType GetSignalType(Tile t, Track track)
{
assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
return (SignalType)GB(_m[t].m2, pos, 3);
return (SignalType)GB(t.m2(), pos, 3);
}
static inline void SetSignalType(TileIndex t, Track track, SignalType s)
static inline void SetSignalType(Tile t, Track track, SignalType s)
{
assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);
byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0;
SB(_m[t].m2, pos, 3, s);
if (track == INVALID_TRACK) SB(_m[t].m2, 4, 3, s);
SB(t.m2(), pos, 3, s);
if (track == INVALID_TRACK) SB(t.m2(), 4, 3, s);
}
static inline bool IsPresignalEntry(TileIndex t, Track track)
static inline bool IsPresignalEntry(Tile t, Track track)
{
return GetSignalType(t, track) == SIGTYPE_ENTRY || GetSignalType(t, track) == SIGTYPE_COMBO;
}
static inline bool IsPresignalExit(TileIndex t, Track track)
static inline bool IsPresignalExit(Tile t, Track track)
{
return GetSignalType(t, track) == SIGTYPE_EXIT || GetSignalType(t, track) == SIGTYPE_COMBO;
}
/** One-way signals can't be passed the 'wrong' way. */
static inline bool IsOnewaySignal(TileIndex t, Track track)
static inline bool IsOnewaySignal(Tile t, Track track)
{
return GetSignalType(t, track) != SIGTYPE_PBS;
}
static inline void CycleSignalSide(TileIndex t, Track track)
static inline void CycleSignalSide(Tile t, Track track)
{
byte sig;
byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 6;
sig = GB(_m[t].m3, pos, 2);
sig = GB(t.m3(), pos, 2);
if (--sig == 0) sig = IsPbsSignal(GetSignalType(t, track)) ? 2 : 3;
SB(_m[t].m3, pos, 2, sig);
SB(t.m3(), pos, 2, sig);
}
static inline SignalVariant GetSignalVariant(TileIndex t, Track track)
static inline SignalVariant GetSignalVariant(Tile t, Track track)
{
byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 7 : 3;
return (SignalVariant)GB(_m[t].m2, pos, 1);
return (SignalVariant)GB(t.m2(), pos, 1);
}
static inline void SetSignalVariant(TileIndex t, Track track, SignalVariant v)
static inline void SetSignalVariant(Tile t, Track track, SignalVariant v)
{
byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 7 : 3;
SB(_m[t].m2, pos, 1, v);
if (track == INVALID_TRACK) SB(_m[t].m2, 7, 1, v);
SB(t.m2(), pos, 1, v);
if (track == INVALID_TRACK) SB(t.m2(), 7, 1, v);
}
/**
@@ -349,9 +349,9 @@ static inline void SetSignalVariant(TileIndex t, Track track, SignalVariant v)
* @param tile the tile to set the states for
* @param state the new state
*/
static inline void SetSignalStates(TileIndex tile, uint state)
static inline void SetSignalStates(Tile tile, uint state)
{
SB(_m[tile].m4, 4, 4, state);
SB(tile.m4(), 4, 4, state);
}
/**
@@ -359,9 +359,9 @@ static inline void SetSignalStates(TileIndex tile, uint state)
* @param tile the tile to set the states for
* @return the state of the signals
*/
static inline uint GetSignalStates(TileIndex tile)
static inline uint GetSignalStates(Tile tile)
{
return GB(_m[tile].m4, 4, 4);
return GB(tile.m4(), 4, 4);
}
/**
@@ -370,7 +370,7 @@ static inline uint GetSignalStates(TileIndex tile)
* @param signalbit the signal
* @return the state of the signal
*/
static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit)
static inline SignalState GetSingleSignalState(Tile t, byte signalbit)
{
return (SignalState)HasBit(GetSignalStates(t), signalbit);
}
@@ -380,9 +380,9 @@ static inline SignalState GetSingleSignalState(TileIndex t, byte signalbit)
* @param tile the tile to set the present signals for
* @param signals the signals that have to be present
*/
static inline void SetPresentSignals(TileIndex tile, uint signals)
static inline void SetPresentSignals(Tile tile, uint signals)
{
SB(_m[tile].m3, 4, 4, signals);
SB(tile.m3(), 4, 4, signals);
}
/**
@@ -390,9 +390,9 @@ static inline void SetPresentSignals(TileIndex tile, uint signals)
* @param tile the tile to get the present signals for
* @return the signals that are present
*/
static inline uint GetPresentSignals(TileIndex tile)
static inline uint GetPresentSignals(Tile tile)
{
return GB(_m[tile].m3, 4, 4);
return GB(tile.m3(), 4, 4);
}
/**
@@ -401,7 +401,7 @@ static inline uint GetPresentSignals(TileIndex tile)
* @param signalbit the signal
* @return true if and only if the signal is present
*/
static inline bool IsSignalPresent(TileIndex t, byte signalbit)
static inline bool IsSignalPresent(Tile t, byte signalbit)
{
return HasBit(GetPresentSignals(t), signalbit);
}
@@ -410,7 +410,7 @@ static inline bool IsSignalPresent(TileIndex t, byte signalbit)
* Checks for the presence of signals (either way) on the given track on the
* given rail tile.
*/
static inline bool HasSignalOnTrack(TileIndex tile, Track track)
static inline bool HasSignalOnTrack(Tile tile, Track track)
{
assert(IsValidTrack(track));
return GetRailTileType(tile) == RAIL_TILE_SIGNALS && (GetPresentSignals(tile) & SignalOnTrack(track)) != 0;
@@ -423,7 +423,7 @@ static inline bool HasSignalOnTrack(TileIndex tile, Track track)
* Along meaning if you are currently driving on the given trackdir, this is
* the signal that is facing us (for which we stop when it's red).
*/
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
static inline bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
{
assert (IsValidTrackdir(trackdir));
return GetRailTileType(tile) == RAIL_TILE_SIGNALS && GetPresentSignals(tile) & SignalAlongTrackdir(trackdir);
@@ -435,7 +435,7 @@ static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
* Along meaning if you are currently driving on the given trackdir, this is
* the signal that is facing us (for which we stop when it's red).
*/
static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
static inline SignalState GetSignalStateByTrackdir(Tile tile, Trackdir trackdir)
{
assert(IsValidTrackdir(trackdir));
assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir)));
@@ -446,7 +446,7 @@ static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trac
/**
* Sets the state of the signal along the given trackdir.
*/
static inline void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, SignalState state)
static inline void SetSignalStateByTrackdir(Tile tile, Trackdir trackdir, SignalState state)
{
if (state == SIGNAL_STATE_GREEN) { // set 1
SetSignalStates(tile, GetSignalStates(tile) | SignalAlongTrackdir(trackdir));
@@ -460,7 +460,7 @@ static inline void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, S
* @param tile the tile to check
* @param td the trackdir to check
*/
static inline bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
static inline bool HasPbsSignalOnTrackdir(Tile tile, Trackdir td)
{
return IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, td) &&
IsPbsSignal(GetSignalType(tile, TrackdirToTrack(td)));
@@ -472,14 +472,14 @@ static inline bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
* @param tile the tile to check
* @param td the trackdir to check
*/
static inline bool HasOnewaySignalBlockingTrackdir(TileIndex tile, Trackdir td)
static inline bool HasOnewaySignalBlockingTrackdir(Tile tile, Trackdir td)
{
return IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, ReverseTrackdir(td)) &&
!HasSignalOnTrackdir(tile, td) && IsOnewaySignal(tile, TrackdirToTrack(td));
}
RailType GetTileRailType(TileIndex tile);
RailType GetTileRailType(Tile tile);
/** The ground 'under' the rail */
enum RailGroundType {
@@ -500,49 +500,49 @@ enum RailGroundType {
RAIL_GROUND_HALF_SNOW = 14, ///< Snow only on higher part of slope (steep or one corner raised)
};
static inline void SetRailGroundType(TileIndex t, RailGroundType rgt)
static inline void SetRailGroundType(Tile t, RailGroundType rgt)
{
SB(_m[t].m4, 0, 4, rgt);
SB(t.m4(), 0, 4, rgt);
}
static inline RailGroundType GetRailGroundType(TileIndex t)
static inline RailGroundType GetRailGroundType(Tile t)
{
return (RailGroundType)GB(_m[t].m4, 0, 4);
return (RailGroundType)GB(t.m4(), 0, 4);
}
static inline bool IsSnowRailGround(TileIndex t)
static inline bool IsSnowRailGround(Tile t)
{
return GetRailGroundType(t) == RAIL_GROUND_ICE_DESERT;
}
static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r)
static inline void MakeRailNormal(Tile t, Owner o, TrackBits b, RailType r)
{
SetTileType(t, MP_RAILWAY);
SetTileOwner(t, o);
SetDockingTile(t, false);
_m[t].m2 = 0;
_m[t].m3 = 0;
_m[t].m4 = 0;
_m[t].m5 = RAIL_TILE_NORMAL << 6 | b;
SB(_me[t].m6, 2, 4, 0);
_me[t].m7 = 0;
_me[t].m8 = r;
t.m2() = 0;
t.m3() = 0;
t.m4() = 0;
t.m5() = RAIL_TILE_NORMAL << 6 | b;
SB(t.m6(), 2, 4, 0);
t.m7() = 0;
t.m8() = r;
}
static inline void MakeRailDepot(TileIndex t, Owner o, DepotID did, DiagDirection d, RailType r)
static inline void MakeRailDepot(Tile t, Owner o, DepotID did, DiagDirection d, RailType r)
{
SetTileType(t, MP_RAILWAY);
SetTileOwner(t, o);
SetDockingTile(t, false);
_m[t].m2 = did;
_m[t].m3 = 0;
_m[t].m4 = 0;
_m[t].m5 = RAIL_TILE_DEPOT << 6 | d;
SB(_me[t].m6, 2, 4, 0);
_me[t].m7 = 0;
_me[t].m8 = r;
t.m2() = did;
t.m3() = 0;
t.m4() = 0;
t.m5() = RAIL_TILE_DEPOT << 6 | d;
SB(t.m6(), 2, 4, 0);
t.m7() = 0;
t.m8() = r;
}
#endif /* RAIL_MAP_H */