(svn r13926) -Add [YAPP]: Add map accessors for path reservations. (michi_cc)

This commit is contained in:
rubidium 2008-08-02 22:47:20 +00:00
parent ea570c8160
commit ec7cc49825
7 changed files with 254 additions and 8 deletions

View File

@ -407,6 +407,39 @@
<li>m4 bits 7..4: bit clear = signal 3..0 shows red</li> <li>m4 bits 7..4: bit clear = signal 3..0 shows red</li>
</ul> </ul>
</li> </li>
<li>m2 bits 8..10: track reserved for pbs
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>not reserved</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>X direction</td>
</tr>
<tr>
<td><tt>2</tt>&nbsp; </td>
<td>Y direction</td>
</tr>
<tr>
<td><tt>3</tt>&nbsp; </td>
<td>north corner (W-E)</td>
</tr>
<tr>
<td><tt>4</tt>&nbsp; </td>
<td>south corner (W-E)</td>
</tr>
<tr>
<td><tt>5</tt>&nbsp; </td>
<td>west corner (N-S)</td>
</tr>
<tr>
<td><tt>6</tt>&nbsp; </td>
<td>east corner (N-S)</td>
</tr>
</table>
</li>
<li>m2 bit 11: opposite track is reserved, too</li>
</ul> </ul>
</li> </li>
<li>m5 bit 7 set, bit 6 clear: checkpoint <li>m5 bit 7 set, bit 6 clear: checkpoint
@ -425,6 +458,7 @@
</tr> </tr>
</table> </table>
</li> </li>
<li>m5 bit 4: pbs reservation state</li>
</ul> </ul>
</li> </li>
<li>m5 bit 7 set, bit 6 set: railway depot <li>m5 bit 7 set, bit 6 set: railway depot
@ -452,6 +486,7 @@
</tr> </tr>
</table> </table>
</li> </li>
<li>m5 bit 4: pbs reservation state</li>
</ul> </ul>
</li> </li>
<li>m6 bits 7..6 : Possibility of a bridge above, in the <a href="#bridge_direction">direction specified</a></li> <li>m6 bits 7..6 : Possibility of a bridge above, in the <a href="#bridge_direction">direction specified</a></li>
@ -582,6 +617,7 @@
</li> </li>
<li>m4 bit 5: set if crossing lights are on</li> <li>m4 bit 5: set if crossing lights are on</li>
<li>m4 bits 4..0: <a href="#OwnershipInfo">owner</a> of the road type 0 (normal road)</li> <li>m4 bits 4..0: <a href="#OwnershipInfo">owner</a> of the road type 0 (normal road)</li>
<li>m5 bit 4: pbs reservation state</li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -898,6 +934,7 @@
</li> </li>
<li>m6 bits 5..3: the station type (rail, airport, truck, bus, oilrig, dock, buoy)</li> <li>m6 bits 5..3: the station type (rail, airport, truck, bus, oilrig, dock, buoy)</li>
<li>m6 bit 2: 1 when a drive through road stop is built over a town owned road, otherwise 0</li> <li>m6 bit 2: 1 when a drive through road stop is built over a town owned road, otherwise 0</li>
<li>m6 bit 2: pbs reservation state for railway stations</li>
<li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li> <li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li>
<li>m7: animation frame</li> <li>m7: animation frame</li>
</ul> </ul>
@ -1370,6 +1407,7 @@
<li>m3 bits 3..0: <a href="#TrackType">track type</a> for railway</li> <li>m3 bits 3..0: <a href="#TrackType">track type</a> for railway</li>
<li>m3 bits 2..0: present road types for road</li> <li>m3 bits 2..0: present road types for road</li>
<li>m4 bit 7 set = on snow or desert</li> <li>m4 bit 7 set = on snow or desert</li>
<li>m5 bit 4: pbs reservation state for railway</li>
<li>m5 bits 7 clear: tunnel entrance/exit</li> <li>m5 bits 7 clear: tunnel entrance/exit</li>
<li>m5 bit 7 set: bridge ramp <li>m5 bit 7 set: bridge ramp
<ul> <ul>

View File

@ -90,7 +90,7 @@ the array so you can quickly see what is used and what is not.
<td class="caption">rail</td> <td class="caption">rail</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td> <td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO</span> XXXX <span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td> <td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td> <td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
@ -101,7 +101,7 @@ the array so you can quickly see what is used and what is not.
<td class="caption">rail with signals</td> <td class="caption">rail with signals</td>
<td class="bits">-inherit-</td> <td class="bits">-inherit-</td>
<td class="bits">-inherit-</td> <td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO O</span>XXX <span class="free">O</span>XXX</td> <td class="bits"><span class="free">OOOO</span> XXXX <span class="free">O</span>XXX <span class="free">O</span>XXX</td>
<td class="bits">XXXX <span class="option">~~</span>XX</td> <td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
<td class="bits">-inherit-</td> <td class="bits">-inherit-</td>
@ -115,7 +115,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td> <td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td> <td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">O</span>X <span class="free">O</span>XXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span></td>
</tr> </tr>
@ -126,7 +126,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits">XXXX XXXX XXXX XXXX</td> <td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td> <td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td> <td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XX<span class="free">OO OOO</span>X</td> <td class="bits">XX<span class="free">O</span>X <span class="free">OOO</span>X</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span></td>
</tr> </tr>
@ -149,7 +149,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits">-inherit-</td> <td class="bits">-inherit-</td>
<td class="bits">XXXX <span class="option">~~</span>XX</td> <td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">O</span>XXX XXXX</td> <td class="bits"><span class="free">O</span>XXX XXXX</td>
<td class="bits">XX<span class="free">OO</span> XXXX</td> <td class="bits">XX<span class="free">O</span>X XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">-inherit-</td> <td class="bits">-inherit-</td>
</tr> </tr>
@ -197,7 +197,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits">XXXX <span class="option">~~</span>XX</td> <td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td> <td class="bits"><span class="free">OO</span>XX XXXX</td>
<td class="bits">XXXX XXXX</td> <td class="bits">XXXX XXXX</td>
</tr> </tr>
<tr> <tr>
@ -310,7 +310,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td> <td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td> <td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">X<span class="free">OOO</span> <span class="option">~</span>XXX</td> <td class="bits">X<span class="free">OO</span>X <span class="option">~</span>XXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span></td>
</tr> </tr>
@ -321,7 +321,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="free">OOOO OOOO</span> XXXX <span class="free">OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span> XXXX <span class="free">OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td> <td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td> <td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">X<span class="free">OOO</span> <span class="option">~</span>XXX</td> <td class="bits">X<span class="free">OO</span>X <span class="option">~</span>XXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span></td>
</tr> </tr>

View File

@ -224,6 +224,87 @@ static inline WaypointID GetWaypointIndex(TileIndex t)
return (WaypointID)_m[t].m2; return (WaypointID)_m[t].m2;
} }
/**
* Returns the reserved track bits of the tile
* @pre IsPlainRailTile(t)
* @param t the tile to query
* @return the track bits
*/
static inline TrackBits GetTrackReservation(TileIndex t)
{
assert(IsPlainRailTile(t));
byte track_b = GB(_m[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));
}
/**
* Sets the reserved track bits of the tile
* @pre IsPlainRailTile(t) && !TracksOverlap(b)
* @param t the tile to change
* @param b the track bits
*/
static inline void SetTrackReservation(TileIndex 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));
}
/**
* Get the reservation state of the waypoint or depot
* @note Works for both waypoints and rail depots
* @pre IsRailWaypoint(t) || IsRailDepot(t)
* @param t the waypoint/depot tile
* @return reservation state
*/
static inline bool GetDepotWaypointReservation(TileIndex t)
{
assert(IsRailWaypoint(t) || IsRailDepot(t));
return HasBit(_m[t].m5, 4);
}
/**
* Set the reservation state of the waypoint or depot
* @note Works for both waypoints and rail depots
* @pre IsRailWaypoint(t) || IsRailDepot(t)
* @param t the waypoint/depot tile
* @param b the reservation state
*/
static inline void SetDepotWaypointReservation(TileIndex t, bool b)
{
assert(IsRailWaypoint(t) || IsRailDepot(t));
SB(_m[t].m5, 4, 1, (byte)b);
}
/**
* Get the reserved track bits for a waypoint
* @pre IsRailWaypoint(t)
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetRailWaypointReservation(TileIndex t)
{
return GetDepotWaypointReservation(t) ? GetRailWaypointBits(t) : TRACK_BIT_NONE;
}
/**
* Get the reserved track bits for a depot
* @pre IsRailDepot(t)
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetRailDepotReservation(TileIndex t)
{
return GetDepotWaypointReservation(t) ? TrackToTrackBits(GetRailDepotTrack(t)) : TRACK_BIT_NONE;
}
static inline SignalType GetSignalType(TileIndex t, Track track) static inline SignalType GetSignalType(TileIndex t, Track track)
{ {
assert(GetRailTileType(t) == RAIL_TILE_SIGNALS); assert(GetRailTileType(t) == RAIL_TILE_SIGNALS);

View File

@ -253,6 +253,43 @@ static inline TrackBits GetCrossingRailBits(TileIndex tile)
return AxisToTrackBits(GetCrossingRailAxis(tile)); return AxisToTrackBits(GetCrossingRailAxis(tile));
} }
/**
* Get the reservation state of the rail crossing
* @pre IsLevelCrossingTile(t)
* @param t the crossing tile
* @return reservation state
*/
static inline bool GetCrossingReservation(TileIndex t)
{
assert(IsLevelCrossingTile(t));
return HasBit(_m[t].m5, 4);
}
/**
* Set the reservation state of the rail crossing
* @note Works for both waypoints and rail depots
* @pre IsLevelCrossingTile(t)
* @param t the crossing tile
* @param b the reservation state
*/
static inline void SetCrossingReservation(TileIndex t, bool b)
{
assert(IsLevelCrossingTile(t));
SB(_m[t].m5, 4, 1, b ? 1 : 0);
}
/**
* Get the reserved track bits for a rail crossing
* @pre IsLevelCrossingTile(t)
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetRailCrossingReservation(TileIndex t)
{
return GetCrossingReservation(t) ? GetCrossingRailBits(t) : TRACK_BIT_NONE;
}
static inline bool IsCrossingBarred(TileIndex t) static inline bool IsCrossingBarred(TileIndex t)
{ {
assert(IsLevelCrossing(t)); assert(IsLevelCrossing(t));

View File

@ -204,6 +204,41 @@ static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
!IsStationTileBlocked(t1); !IsStationTileBlocked(t1);
} }
/**
* Get the reservation state of the rail station
* @pre IsRailwayStationTile(t)
* @param t the station tile
* @return reservation state
*/
static inline bool GetRailwayStationReservation(TileIndex t)
{
assert(IsRailwayStationTile(t));
return HasBit(_m[t].m6, 2);
}
/**
* Set the reservation state of the rail station
* @pre IsRailwayStationTile(t)
* @param t the station tile
* @param b the reservation state
*/
static inline void SetRailwayStationReservation(TileIndex t, bool b)
{
assert(IsRailwayStationTile(t));
SB(_m[t].m6, 2, 1, b ? 1 : 0);
}
/**
* Get the reserved track bits for a waypoint
* @pre IsRailwayStationTile(t)
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetRailStationReservation(TileIndex t)
{
return GetRailwayStationReservation(t) ? AxisToTrackBits(GetRailStationAxis(t)) : TRACK_BIT_NONE;
}
static inline DiagDirection GetDockDirection(TileIndex t) static inline DiagDirection GetDockDirection(TileIndex t)
{ {
@ -277,6 +312,7 @@ static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a,
{ {
MakeStation(t, o, sid, STATION_RAIL, section + a); MakeStation(t, o, sid, STATION_RAIL, section + a);
SetRailType(t, rt); SetRailType(t, rt);
SetRailwayStationReservation(t, false);
} }
static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d) static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)

View File

@ -197,6 +197,21 @@ static inline bool IsValidTrackdir(Trackdir trackdir)
* TrackdirBits, Direction and DiagDirections. * TrackdirBits, Direction and DiagDirections.
*/ */
/**
* Find the opposite track to a given track.
*
* TRACK_LOWER -> TRACK_UPPER and vice versa, likewise for left/right.
* TRACK_X is mapped to TRACK_Y and reversed.
*
* @param t the track to convert
* @return the opposite track
*/
static inline Track TrackToOppositeTrack(Track t)
{
assert(t != INVALID_TRACK);
return (Track)(t ^ 1);
}
/** /**
* Maps a trackdir to the reverse trackdir. * Maps a trackdir to the reverse trackdir.
* *

View File

@ -11,6 +11,7 @@
#include "bridge_map.h" #include "bridge_map.h"
#include "tunnel_map.h" #include "tunnel_map.h"
#include "transport_type.h" #include "transport_type.h"
#include "track_func.h"
/** /**
@ -80,4 +81,42 @@ static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t); return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
} }
/**
* Get the reservation state of the rail tunnel/bridge
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
* @param t the tile
* @return reservation state
*/
static inline bool GetTunnelBridgeReservation(TileIndex t)
{
assert(IsTileType(t, MP_TUNNELBRIDGE));
assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
return HasBit(_m[t].m5, 4);
}
/**
* Set the reservation state of the rail tunnel/bridge
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
* @param t the tile
* @param b the reservation state
*/
static inline void SetTunnelBridgeReservation(TileIndex t, bool b)
{
assert(IsTileType(t, MP_TUNNELBRIDGE));
assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
SB(_m[t].m5, 4, 1, b ? 1 : 0);
}
/**
* Get the reserved track bits for a rail tunnel/bridge
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
* @param t the tile
* @return reserved track bits
*/
static inline TrackBits GetRailTunnelBridgeReservation(TileIndex t)
{
return GetTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
}
#endif /* TUNNELBRIDGE_MAP_H */ #endif /* TUNNELBRIDGE_MAP_H */