/** * Lift the reservation of a specific track on a tile * @pre IsPlainRailTile(t) && HasTrack(tile, t) * @param tile the tile * @param t the track to free */ public static void UnreserveTrack(TileIndex tile, Track t) { Debug.Assert(HasTrack(tile, t)); TrackBits res = GetRailReservationTrackBits(tile); res &= ~TrackToTrackBits(t); SetTrackReservation(tile, res); }
/** * Sets the reserved track bits of the tile * @pre IsPlainRailTile(t) && !TracksOverlap(b) * @param t the tile to change * @param b the track bits */ public static void SetTrackReservation(this TileIndex t, TrackBits b) { Debug.Assert(IsPlainRailTile(t)); Debug.Assert(b != TrackBits.INVALID_TRACK_BIT); Debug.Assert(!TracksOverlap(b)); Track track = RemoveFirstTrack(&b); BitMath.SB(Map._m[t].m2, 8, 3, track == Track.INVALID_TRACK ? 0 : track + 1); BitMath.SB(Map._m[t].m2, 11, 1, (byte)(b != TrackBits.TRACK_BIT_NONE)); }
public static void MakeRailNormal(this TileIndex t, Owner o, TrackBits b, RailType r) { TileMap.SetTileType(t, TileType.MP_RAILWAY); TileMap.SetTileOwner(t, o); Map._m[t].m2 = 0; Map._m[t].m3 = (byte)r; Map._m[t].m4 = 0; Map._m[t].m5 = (byte)((int)RailTileType.RAIL_TILE_NORMAL << 6 | b); BitMath.SB(Map._me[t].m6, 2, 4, 0); Map._me[t].m7 = 0; }
/** * Try to reserve a specific track on a tile * @pre IsPlainRailTile(t) && HasTrack(tile, t) * @param tile the tile * @param t the rack to reserve * @return true if successful */ public static bool TryReserveTrack(TileIndex tile, Track t) { Debug.Assert(HasTrack(tile, t)); TrackBits bits = TrackToTrackBits(t); TrackBits res = GetRailReservationTrackBits(tile); if ((res & bits) != TrackBits.TRACK_BIT_NONE) { return(false); // already reserved } res |= bits; if (TracksOverlap(res)) { return(false); // crossing reservation present } SetTrackReservation(tile, res); return(true); }
/** * Sets the track bits of the given tile * @param t the tile to set the track bits of * @param b the new track bits for the tile */ public static void SetTrackBits(this TileIndex t, TrackBits b) { Debug.Assert(IsPlainRailTile(t)); BitMath.SB(Map._m[t].m5, 0, 6, b); }