(svn r5624) Use {IsPlainRailTile,IsRailDepot,IsRailWaypoint,HasSignals}() instead of GetRailTile{T,Subt}ype() - this is more concise and a bit more flexible if/when the rail tile encoding changes

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
tron 18 years ago
parent b0d5005cad
commit 2bb9fd3901

@ -361,7 +361,7 @@ void DrawCatenary(const TileInfo *ti)
{
switch (GetTileType(ti->tile)) {
case MP_RAILWAY:
if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT && GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
if (IsRailDepot(ti->tile)) {
const SortableSpriteStruct *sss = &CatenarySpriteData[WIRE_DEPOT_SW + ReverseDiagDir(GetRailDepotDirection(ti->tile))];
AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x, ti->y) + sss->z_offset);

@ -253,8 +253,7 @@ static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool ch
if (waypoint) {
if (!IsTileType(new_tile, MP_RAILWAY)) break;
if (GetRailTileType(new_tile) != RAIL_TILE_DEPOT_WAYPOINT) break;
if (GetRailTileSubtype(new_tile) != RAIL_SUBTYPE_WAYPOINT) break;
if (!IsRailWaypoint(new_tile)) break;
if (check_axis && GetWaypointAxis(new_tile) != orig_axis) break;
} else {
if (!IsRailwayStationTile(new_tile)) break;

@ -200,8 +200,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT &&
GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
if (IsRailDepot(tile)) {
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS;
order.station = GetDepotByTile(tile)->index;

@ -73,13 +73,11 @@ void ShowTrainDepotWindow(TileIndex tile);
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
{
RailTileType type = GetRailTileType(tile);
TrackBits current; /* The current track layout */
TrackBits future; /* The track layout we want to build */
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
if (type != RAIL_TILE_NORMAL && type != RAIL_TILE_SIGNALS)
return false; /* Cannot build anything on depots and checkpoints */
if (!IsPlainRailTile(tile)) return false;
/* So, we have a tile with tracks on it (and possibly signals). Let's see
* what tracks first */
@ -94,7 +92,7 @@ static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags
}
/* Let's see if we may build this */
if ((flags & DC_NO_RAIL_OVERLAP) || type == RAIL_TILE_SIGNALS) {
if (flags & DC_NO_RAIL_OVERLAP || HasSignals(tile)) {
/* If we are not allowed to overlap (flag is on for ai players or we have
* signals on the tile), check that */
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
@ -670,7 +668,7 @@ int32 CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
if (flags & DC_EXEC) {
if (GetRailTileType(tile) != RAIL_TILE_SIGNALS) {
if (!HasSignals(tile)) {
// there are no signals at all on this tile yet
_m[tile].m5 |= RAIL_TILE_SIGNALS; // change into signals
_m[tile].m2 |= 0xF0; // all signals are on
@ -748,7 +746,7 @@ static int32 CmdSignalTrackHelper(TileIndex tile, uint32 flags, uint32 p1, uint3
track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */
// copy the signal-style of the first rail-piece if existing
if (GetRailTileType(tile) == RAIL_TILE_SIGNALS && GetTrackBits(tile) != 0) { /* XXX: GetTrackBits check useless? */
if (HasSignals(tile)) {
signals = _m[tile].m3 & SignalOnTrack(track);
if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */
@ -980,14 +978,14 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
m5 = _m[tile].m5;
if (flags & DC_AUTO) {
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) {
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
}
if (!IsTileOwner(tile, _current_player))
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
if (IsPlainRailTile(tile)) {
return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
} else {
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
}
}
cost = 0;
@ -1303,15 +1301,14 @@ static void DrawTile_Track(TileInfo *ti)
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)));
if (GetRailTileType(ti->tile) != RAIL_TILE_DEPOT_WAYPOINT) {
if (IsPlainRailTile(ti->tile)) {
TrackBits rails = GetTrackBits(ti->tile);
DrawTrackBits(ti, rails);
if (_display_opt & DO_FULL_DETAIL) DrawTrackDetails(ti);
/* draw signals also? */
if (GetRailTileType(ti->tile) == RAIL_TILE_SIGNALS) DrawSignals(ti->tile, rails);
if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
} else {
/* draw depots / waypoints */
const DrawTrackSeqStruct *drss;
@ -1724,9 +1721,7 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
uint z = ti->z;
if (tileh == SLOPE_FLAT) return z;
if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT) {
return z + TILE_HEIGHT;
} else {
if (IsPlainRailTile(ti->tile)) {
uint f = GetRailFoundation(ti->tileh, GetTrackBits(ti->tile));
if (f != 0) {
@ -1734,20 +1729,22 @@ static uint GetSlopeZ_Track(const TileInfo* ti)
tileh = _inclined_tileh[f - 15]; // inclined foundation
}
return z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, tileh);
} else {
return z + TILE_HEIGHT;
}
}
static Slope GetSlopeTileh_Track(TileIndex tile, Slope tileh)
{
if (tileh == SLOPE_FLAT) return SLOPE_FLAT;
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) {
return SLOPE_FLAT;
} else {
if (IsPlainRailTile(tile)) {
uint f = GetRailFoundation(tileh, GetTrackBits(tile));
if (f == 0) return tileh;
if (f < 15) return SLOPE_FLAT; // leveled foundation
return _inclined_tileh[f - 15]; // inclined foundation
} else {
return SLOPE_FLAT;
}
}
@ -1790,8 +1787,7 @@ static void TileLoop_Track(TileIndex tile)
if (quick_return) return;
// Don't continue tile loop for depots
if (GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT) return;
if (!IsPlainRailTile(tile)) return;
new_ground = RAIL_GROUND_GRASS;
@ -1888,15 +1884,11 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
if (mode != TRANSPORT_RAIL) return 0;
if (GetRailTileType(tile) != RAIL_TILE_DEPOT_WAYPOINT) {
if (IsPlainRailTile(tile)) {
TrackBits rails = GetTrackBits(tile);
uint32 ret = rails * 0x101;
if (GetRailTileType(tile) != RAIL_TILE_SIGNALS) {
if (rails == TRACK_BIT_CROSS) ret |= 0x40;
} else {
/* has_signals */
if (HasSignals(tile)) {
a = _m[tile].m3;
b = _m[tile].m2;
@ -1913,6 +1905,8 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
if ((b & 0x40) == 0) ret |= 0x07100000;
if ((b & 0x20) == 0) ret |= 0x20080000;
if ((b & 0x10) == 0) ret |= 0x08200000;
} else {
if (rails == TRACK_BIT_CROSS) ret |= 0x40;
}
return ret;
} else {

@ -60,6 +60,14 @@ static inline RailTileSubtype GetRailTileSubtype(TileIndex tile)
}
static inline bool IsRailDepot(TileIndex t)
{
return
GetRailTileType(t) == RAIL_TILE_DEPOT_WAYPOINT &&
GetRailTileSubtype(t) == RAIL_SUBTYPE_DEPOT;
}
static inline bool IsRailWaypoint(TileIndex t)
{
return

@ -1830,8 +1830,7 @@ static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int trac
{
if (IsTileType(tile, MP_RAILWAY) &&
IsTileOwner(tile, tfdd->owner) &&
GetRailTileType(tile) == RAIL_TILE_DEPOT_WAYPOINT &&
GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
IsRailDepot(tile)) {
tfdd->best_length = length;
tfdd->tile = tile;
return true;

Loading…
Cancel
Save