summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-03-25 12:10:13 +0000
committerpeter1138 <peter1138@openttd.org>2008-03-25 12:10:13 +0000
commitf0e39a7953a3a9509890cfdb381d161c605040df (patch)
tree392b944dd605681e9d28644848a5e1dc2b253c6e /src
parent8669c771434def105040ce4a650c9043116f120f (diff)
downloadopenttd-f0e39a7953a3a9509890cfdb381d161c605040df.tar.xz
(svn r12410) -Codechange: abstract out the test for catenary on electric rails
Diffstat (limited to 'src')
-rw-r--r--src/elrail.cpp14
-rw-r--r--src/rail.h11
-rw-r--r--src/rail_cmd.cpp4
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp6
6 files changed, 25 insertions, 14 deletions
diff --git a/src/elrail.cpp b/src/elrail.cpp
index 7dd9eab0c..c14908564 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -84,7 +84,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
{
switch (GetTileType(t)) {
case MP_RAILWAY:
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+ if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
switch (GetRailTileType(t)) {
case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS:
return GetTrackBits(t);
@@ -96,7 +96,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
break;
case MP_TUNNELBRIDGE:
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+ if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
*override = 1 << GetTunnelBridgeDirection(t);
}
@@ -104,12 +104,12 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
case MP_ROAD:
if (!IsLevelCrossing(t)) return TRACK_BIT_NONE;
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+ if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
return GetCrossingRailBits(t);
case MP_STATION:
if (!IsRailwayStation(t)) return TRACK_BIT_NONE;
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+ if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE;
return TrackToTrackBits(GetRailStationTrack(t));
@@ -179,7 +179,7 @@ void DrawCatenaryOnTunnel(const TileInfo *ti)
{ 1, 0, 15, 16 }, // NW
};
- if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
+ if (!HasCatenary(GetRailType(ti->tile)) || _patches.disable_elrails) return;
DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
@@ -282,7 +282,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
/* Read the foundataions if they are present, and adjust the tileh */
- if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
+ if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && HasCatenary(GetRailType(neighbour))) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
if (IsBridgeTile(neighbour)) {
foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
}
@@ -436,7 +436,7 @@ void DrawCatenary(const TileInfo *ti)
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
TileIndex head = GetNorthernBridgeEnd(ti->tile);
- if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
+ if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && HasCatenary(GetRailType(head))) {
DrawCatenaryOnBridge(ti);
}
}
diff --git a/src/rail.h b/src/rail.h
index eb31bb4ab..53b3a1337 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -183,6 +183,17 @@ void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
int TicksToLeaveDepot(const Vehicle *v);
+
+/**
+ * Test if a rail type has catenary
+ * @param rt Rail type to test
+ */
+static inline bool HasCatenary(RailType rt)
+{
+ return rt == RAILTYPE_ELECTRIC;
+}
+
+
/**
* Draws overhead wires and pylons for electric railways.
* @param ti The TileInfo struct of the tile being drawn
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 724a7213d..1292a6523 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1761,7 +1761,7 @@ static void DrawTile_Track(TileInfo *ti)
if (HasBit(_display_opt, DO_FULL_DETAIL)) DrawTrackDetails(ti);
- if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+ if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
} else {
@@ -1835,7 +1835,7 @@ default_waypoint:
DrawGroundSprite(image, PAL_NONE);
- if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+ if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
foreach_draw_tile_seq(dtss, dts->seq) {
SpriteID image = dtss->image.sprite;
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 0f321dfb6..58c2621c7 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1111,7 +1111,7 @@ static void DrawTile_Road(TileInfo *ti)
DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
}
- if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
+ if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
break;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index c7c0ec537..5ad63954f 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2177,7 +2177,7 @@ static void DrawTile_Station(TileInfo *ti)
DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
}
- if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
+ if (HasCatenary(GetRailType(ti->tile)) && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
if (HasBit(roadtypes, ROADTYPE_TRAM)) {
Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 94693732e..b65be5fb6 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -859,7 +859,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
StartSpriteCombine();
AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
}
- } else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
+ } else if (HasCatenary(GetRailType(ti->tile))) {
DrawCatenary(ti);
catenary = true;
@@ -935,7 +935,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD));
}
EndSpriteCombine();
- } else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
+ } else if (HasCatenary(GetRailType(ti->tile))) {
DrawCatenary(ti);
}
@@ -1061,7 +1061,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
EndSpriteCombine();
StartSpriteCombine();
}
- } else if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) {
+ } else if (HasCatenary(GetRailType(rampsouth))) {
DrawCatenary(ti);
}