summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2007-12-16 15:38:51 +0000
committersmatz <smatz@openttd.org>2007-12-16 15:38:51 +0000
commit926fe5c9e9e9fc3fd1b8ed9779812d54ee128adf (patch)
tree3adebd2b8c9a10a6d993c67b0b5920b3598f2bce
parent8ce9c5f29b52cc9625bdda47594b4fad9e3dd242 (diff)
downloadopenttd-926fe5c9e9e9fc3fd1b8ed9779812d54ee128adf.tar.xz
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
-rw-r--r--projects/openttd.vcproj3
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--projects/openttd_vs90.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/ai/default/default.cpp8
-rw-r--r--src/ai/trolly/pathfinder.cpp10
-rw-r--r--src/bridge_map.cpp7
-rw-r--r--src/bridge_map.h55
-rw-r--r--src/elrail.cpp22
-rw-r--r--src/npf.cpp15
-rw-r--r--src/openttd.cpp9
-rw-r--r--src/pathfind.cpp33
-rw-r--r--src/rail.cpp6
-rw-r--r--src/rail_cmd.cpp10
-rw-r--r--src/rail_gui.cpp6
-rw-r--r--src/road_cmd.cpp18
-rw-r--r--src/road_map.cpp9
-rw-r--r--src/roadveh_cmd.cpp10
-rw-r--r--src/smallmap_gui.cpp6
-rw-r--r--src/town_cmd.cpp6
-rw-r--r--src/train_cmd.cpp6
-rw-r--r--src/tunnel_map.cpp8
-rw-r--r--src/tunnel_map.h54
-rw-r--r--src/tunnelbridge_cmd.cpp97
-rw-r--r--src/tunnelbridge_map.h68
-rw-r--r--src/yapf/follow_track.hpp8
-rw-r--r--src/yapf/yapf.hpp1
-rw-r--r--src/yapf/yapf_costbase.hpp2
28 files changed, 245 insertions, 241 deletions
diff --git a/projects/openttd.vcproj b/projects/openttd.vcproj
index a13a668ba..24de684bb 100644
--- a/projects/openttd.vcproj
+++ b/projects/openttd.vcproj
@@ -1198,6 +1198,9 @@
RelativePath=".\..\src\tunnel_map.h">
</File>
<File
+ RelativePath=".\..\src\tunnelbridge_map.h">
+ </File>
+ <File
RelativePath=".\..\src\unmovable_map.h">
</File>
<File
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 44b7abe27..3ae5f7653 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -1816,6 +1816,10 @@
>
</File>
<File
+ RelativePath=".\..\src\tunnelbridge_map.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\unmovable_map.h"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 722c27812..c9702b081 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -1813,6 +1813,10 @@
>
</File>
<File
+ RelativePath=".\..\src\tunnelbridge_map.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\unmovable_map.h"
>
</File>
diff --git a/source.list b/source.list
index c04f283c8..edd9ad5c5 100644
--- a/source.list
+++ b/source.list
@@ -373,6 +373,7 @@ town_map.h
tree_map.h
tunnel_map.cpp
tunnel_map.h
+tunnelbridge_map.h
unmovable_map.h
void_map.h
water_map.h
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index e84217ddc..671f6a07e 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -28,8 +28,10 @@
#include "../../bridge.h"
#include "../../date.h"
#include "../../helpers.hpp"
+#include "../../tunnelbridge_map.h"
#include "default.h"
+
// remove some day perhaps?
static uint _ai_service_interval;
@@ -2233,7 +2235,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
} else {
// Check if the bridge points in the right direction.
// This is not really needed the first place AiRemoveTileAndGoForward is called.
- if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1)) return false;
+ if (DiagDirToAxis(GetTunnelBridgeDirection(tile)) != (p->ai.cur_dir_a & 1)) return false;
tile = GetOtherBridgeEnd(tile);
@@ -3733,13 +3735,13 @@ pos_3:
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (!IsTileOwner(tile, _current_player) ||
!IsBridge(tile) ||
- GetBridgeTransportType(tile) != TRANSPORT_RAIL) {
+ GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) {
return;
}
rails = TRACK_BIT_NONE;
- switch (GetBridgeRampDirection(tile)) {
+ switch (GetTunnelBridgeDirection(tile)) {
default:
case DIAGDIR_NE: goto pos_2;
case DIAGDIR_SE: goto pos_3;
diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp
index bd243dd31..33383a560 100644
--- a/src/ai/trolly/pathfinder.cpp
+++ b/src/ai/trolly/pathfinder.cpp
@@ -12,8 +12,10 @@
#include "../../depot.h"
#include "../../tunnel_map.h"
#include "../../bridge.h"
+#include "../../tunnelbridge_map.h"
#include "../ai.h"
+
#define TEST_STATION_NO_DIR 0xFF
// Tests if a station can be build on the given spot
@@ -44,8 +46,8 @@ static bool IsRoad(TileIndex tile)
// MP_ROAD, but not a road depot?
(IsTileType(tile, MP_ROAD) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
(IsTileType(tile, MP_TUNNELBRIDGE) && (
- (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) ||
- (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_ROAD)
+ (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) ||
+ (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD)
));
}
@@ -235,9 +237,9 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
if (IsTileType(atile, MP_TUNNELBRIDGE)) {
if (IsTunnel(atile)) {
- if (GetTunnelDirection(atile) != i) continue;
+ if (GetTunnelBridgeDirection(atile) != i) continue;
} else {
- if (GetBridgeRampDirection(atile) != i) continue;
+ if (GetTunnelBridgeDirection(atile) != i) continue;
}
}
}
diff --git a/src/bridge_map.cpp b/src/bridge_map.cpp
index 318249a4f..8509f305f 100644
--- a/src/bridge_map.cpp
+++ b/src/bridge_map.cpp
@@ -8,6 +8,7 @@
#include "bridge.h"
#include "variables.h"
#include "landscape.h"
+#include "tunnelbridge_map.h"
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
@@ -17,7 +18,7 @@ TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
dir = ReverseDiagDir(dir);
do {
tile += delta;
- } while (!IsBridgeTile(tile) || GetBridgeRampDirection(tile) != dir);
+ } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir);
return tile;
}
@@ -38,14 +39,14 @@ TileIndex GetSouthernBridgeEnd(TileIndex t)
TileIndex GetOtherBridgeEnd(TileIndex tile)
{
assert(IsBridgeTile(tile));
- return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
+ return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
}
uint GetBridgeHeight(TileIndex t)
{
uint h;
Slope tileh = GetTileSlope(t, &h);
- Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
+ Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
/* one height level extra for the ramp */
return h + TILE_HEIGHT + ApplyFoundationToSlope(f, &tileh);
diff --git a/src/bridge_map.h b/src/bridge_map.h
index b7f24ff83..3a329d93b 100644
--- a/src/bridge_map.h
+++ b/src/bridge_map.h
@@ -64,7 +64,6 @@ static inline bool IsBridgeAbove(TileIndex t)
return GB(_m[t].m6, 6, 2) != 0;
}
-
/**
* Determines the type of bridge on a tile
* @param t The tile to analyze
@@ -77,20 +76,6 @@ static inline uint GetBridgeType(TileIndex t)
return GB(_m[t].m2, 4, 4);
}
-
-/**
- * Get the direction pointing onto the bridge
- * @param t The tile to analyze
- * @pre IsBridgeTile(t)
- * @return the above mentionned direction
- */
-static inline DiagDirection GetBridgeRampDirection(TileIndex t)
-{
- assert(IsBridgeTile(t));
- return (DiagDirection)GB(_m[t].m5, 0, 2);
-}
-
-
/**
* Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
* @param t The tile to analyze
@@ -103,45 +88,6 @@ static inline Axis GetBridgeAxis(TileIndex t)
return (Axis)(GB(_m[t].m6, 6, 2) - 1);
}
-
-/**
- * Get the transport type of the bridge's ramp.
- * @param t The ramp tile to analyze
- * @pre IsBridgeTile(t)
- * @return the transport type of the bridge
- */
-static inline TransportType GetBridgeTransportType(TileIndex t)
-{
- assert(IsBridgeTile(t));
- return (TransportType)GB(_m[t].m5, 2, 2);
-}
-
-
-/**
- * Does the bridge ramp lie in a snow or desert area?
- * @param t The ramp tile to analyze
- * @pre IsBridgeTile(t)
- * @return true if and only if in a snow or desert area
- */
-static inline bool HasBridgeSnowOrDesert(TileIndex t)
-{
- assert(IsBridgeTile(t));
- return HasBit(_m[t].m4, 7);
-}
-
-
-/**
- * Sets whether the bridge ramp lies in a snow or desert area.
- * @param t The ramp tile to set (un)make a snow/desert area
- * @param snow_or_desert Make (true) or unmake the tile a snow/desert area
- * @pre IsBridgeTile(t)
- */
-static inline void SetBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
-{
- assert(IsBridgeTile(t));
- SB(_m[t].m4, 7, 1, snow_or_desert);
-}
-
/**
* Finds the end of a bridge in the specified direction starting at a middle tile
* @param t the bridge tile to find the bridge ramp for
@@ -187,7 +133,6 @@ static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
ClrBit(_m[t].m6, 6 + a);
}
-
/**
* Removes bridges from the given, that is bridges along the X and Y axis.
* @param t the tile to remove the bridge from
diff --git a/src/elrail.cpp b/src/elrail.cpp
index ffd567f89..fd6e47fec 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -66,6 +66,8 @@
#include "train.h"
#include "gui.h"
#include "transparency.h"
+#include "tunnelbridge_map.h"
+
static inline TLG GetTLG(TileIndex t)
{
@@ -93,14 +95,14 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
case MP_TUNNELBRIDGE:
if (IsTunnel(t)) {
if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
- if (override != NULL) *override = 1 << GetTunnelDirection(t);
- return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t)));
+ if (override != NULL) *override = 1 << GetTunnelBridgeDirection(t);
+ return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
} else {
if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
- *override = 1 << GetBridgeRampDirection(t);
+ *override = 1 << GetTunnelBridgeDirection(t);
}
- return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
+ return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
}
case MP_ROAD:
@@ -131,7 +133,7 @@ static void AdjustTileh(TileIndex tile, Slope *tileh)
} else if (*tileh != SLOPE_FLAT) {
*tileh = SLOPE_FLAT;
} else {
- switch (GetBridgeRampDirection(tile)) {
+ switch (GetTunnelBridgeDirection(tile)) {
case DIAGDIR_NE: *tileh = SLOPE_NE; break;
case DIAGDIR_SE: *tileh = SLOPE_SE; break;
case DIAGDIR_SW: *tileh = SLOPE_SW; break;
@@ -188,7 +190,7 @@ void DrawCatenaryOnTunnel(const TileInfo *ti)
if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
- DiagDirection dir = GetTunnelDirection(ti->tile);
+ DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
const int *BB_data = _tunnel_wire_BB[dir];
@@ -247,7 +249,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
* existing foundataions, so we do have to do that manually later on.*/
tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
- if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
+ if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
/* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
* we have to draw all pillars on the current tile. */
@@ -264,7 +266,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
IsBridgeTile(neighbour) &&
- GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
+ GetTunnelBridgeDirection(neighbour) == ReverseDiagDir(i)) {
continue;
}
@@ -291,7 +293,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
/* 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 (IsBridgeTile(neighbour)) {
- foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
+ foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
}
ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
@@ -443,7 +445,7 @@ void DrawCatenary(const TileInfo *ti)
if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
TileIndex head = GetNorthernBridgeEnd(ti->tile);
- if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
+ if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
DrawCatenaryOnBridge(ti);
}
}
diff --git a/src/npf.cpp b/src/npf.cpp
index 8fdc97fe8..696484e03 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -19,6 +19,7 @@
#include "tunnel_map.h"
#include "network/network.h"
#include "water_map.h"
+#include "tunnelbridge_map.h"
static AyStar _npf_aystar;
@@ -170,7 +171,7 @@ static uint NPFTunnelCost(AyStarNode* current)
{
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
TileIndex tile = current->tile;
- if (GetTunnelDirection(tile) == ReverseDiagDir(exitdir)) {
+ if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
/* We just popped out if this tunnel, since were
* facing the tunnel exit */
FindLengthOfTunnelResult flotr;
@@ -480,8 +481,8 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
break;
case MP_TUNNELBRIDGE:
- if ((IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) ||
- (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL)) {
+ if ((IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ||
+ (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL)) {
return IsTileOwner(tile, owner);
}
break;
@@ -533,13 +534,13 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
DEBUG(npf, 4, "Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
/* Find dest tile */
- if (IsTunnelTile(src_tile) && GetTunnelDirection(src_tile) == src_exitdir) {
+ if (IsTunnelTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) {
/* This is a tunnel. We know this tunnel is our type,
* otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */
dst_tile = GetOtherTunnelEnd(src_tile);
override_dst_check = true;
- } else if (IsBridgeTile(src_tile) && GetBridgeRampDirection(src_tile) == src_exitdir) {
+ } else if (IsBridgeTile(src_tile) && GetTunnelBridgeDirection(src_tile) == src_exitdir) {
dst_tile = GetOtherBridgeEnd(src_tile);
override_dst_check = true;
} else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) {
@@ -592,9 +593,9 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
if (!override_dst_check) {
if (IsTileType(dst_tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(dst_tile)) {
- if (GetTunnelDirection(dst_tile) != src_exitdir) return;
+ if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return;
} else {
- if (GetBridgeRampDirection(dst_tile) != src_exitdir) return;
+ if (GetTunnelBridgeDirection(dst_tile) != src_exitdir) return;
}
}
}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 7d841f0bb..46f46c594 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -77,6 +77,7 @@
#include "industry_map.h"
#include "unmovable_map.h"
#include "tree_map.h"
+#include "tunnelbridge_map.h"
#include <stdarg.h>
@@ -1639,7 +1640,7 @@ bool AfterLoadGame()
case MP_TUNNELBRIDGE:
/* Middle part of "old" bridges */
if (old_bridge && IsBridgeTile(t) && HasBit(_m[t].m5, 6)) break;
- if ((IsTunnel(t) ? GetTunnelTransportType(t) : (old_bridge ? (TransportType)GB(_m[t].m5, 1, 2) : GetBridgeTransportType(t))) == TRANSPORT_ROAD) {
+ if ((IsTunnel(t) ? GetTunnelBridgeTransportType(t) : (old_bridge ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t))) == TRANSPORT_ROAD) {
SetRoadTypes(t, ROADTYPES_ROAD);
}
break;
@@ -1699,7 +1700,7 @@ bool AfterLoadGame()
FOR_ALL_VEHICLES(v) {
if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
if (IsBridgeTile(v->tile)) {
- DiagDirection dir = GetBridgeRampDirection(v->tile);
+ DiagDirection dir = GetTunnelBridgeDirection(v->tile);
if (dir != DirToDiagDir(v->direction)) continue;
switch (dir) {
@@ -1757,11 +1758,11 @@ bool AfterLoadGame()
case MP_TUNNELBRIDGE:
if (IsTunnel(t)) {
- if (GetTunnelTransportType(t) == TRANSPORT_RAIL) {
+ if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
}
} else {
- if (GetBridgeTransportType(t) == TRANSPORT_RAIL) {
+ if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
}
}
diff --git a/src/pathfind.cpp b/src/pathfind.cpp
index 2588c1c76..4cefc7125 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -17,6 +17,7 @@
#include "tunnel_map.h"
#include "variables.h"
#include "depot.h"
+#include "tunnelbridge_map.h"
/* remember which tiles we have already visited so we don't visit them again. */
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir)
@@ -210,7 +211,7 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
tile += delta;
} while(
!IsTunnelTile(tile) ||
- GetTunnelDirection(tile) != dir ||
+ GetTunnelBridgeDirection(tile) != dir ||
GetTileZ(tile) != z
);
@@ -260,13 +261,13 @@ static inline void TPFMode1_NormalCase(TrackPathFinder* tpf, TileIndex tile, Til
* and transport type match */
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(tile)) {
- if (GetTunnelDirection(tile) != direction ||
- GetTunnelTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
return;
}
} else if (IsBridge(tile)) {
- if (GetBridgeRampDirection(tile) != direction ||
- GetBridgeTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
return;
}
}
@@ -307,23 +308,23 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
return;
}
/* Only skip through the tunnel if heading inwards. We can
* be headed outwards if our starting position was in a
* tunnel and we're pathfinding backwards */
- if (GetTunnelDirection(tile) == direction) {
+ if (GetTunnelBridgeDirection(tile) == direction) {
tile = SkipToEndOfTunnel(tpf, tile, direction);
- } else if (GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
+ } else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
/* We don't support moving through the sides of a tunnel
* entrance :-) */
return;
}
} else {
TileIndex tile_end;
- if (GetBridgeRampDirection(tile) != direction ||
- GetBridgeTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
return;
}
//fprintf(stderr, "%s: Planning over bridge\n", __func__);
@@ -722,12 +723,12 @@ start_at:
* need to find the exit of the tunnel. */
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(tile)) {
- if (GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
+ if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
FindLengthOfTunnelResult flotr;
/* We are not just driving out of the tunnel */
- if (GetTunnelDirection(tile) != direction ||
- GetTunnelTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
/* We are not driving into the tunnel, or it is an invalid tunnel */
continue;
}
@@ -742,10 +743,10 @@ start_at:
}
} else {
TileIndex tile_end;
- if (GetBridgeRampDirection(tile) != ReverseDiagDir(direction)) {
+ if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
/* We are not just leaving the bridge */
- if (GetBridgeRampDirection(tile) != direction ||
- GetBridgeTransportType(tile) != tpf->tracktype) {
+ if (GetTunnelBridgeDirection(tile) != direction ||
+ GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
/* Not entering the bridge or not compatible */
continue;
}
diff --git a/src/rail.cpp b/src/rail.cpp
index 8bf83a36a..f3f62175f 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -8,6 +8,8 @@
#include "rail.h"
#include "station_map.h"
#include "tunnel_map.h"
+#include "tunnelbridge_map.h"
+
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
@@ -131,9 +133,9 @@ RailType GetTileRailType(TileIndex tile)
case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
+ if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
} else {
- if (GetBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
+ if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) return GetRailType(tile);
}
break;
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index b29f63538..793d9363f 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -42,6 +42,8 @@
#include "autoslope.h"
#include "transparency.h"
#include "water.h"
+#include "tunnelbridge_map.h"
+
const byte _track_sloped_sprites[14] = {
14, 15, 22, 13,
@@ -927,12 +929,12 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
TileIndex orig_tile = tile;
/* Skip to end of tunnel or bridge */
if (IsBridge(tile)) {
- if (GetBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
- if (GetBridgeRampDirection(tile) != TrackdirToExitdir(trackdir)) return false;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
+ if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
tile = GetOtherBridgeEnd(tile);
} else {
- if (GetTunnelTransportType(tile) != TRANSPORT_RAIL) return false;
- if (GetTunnelDirection(tile) != TrackdirToExitdir(trackdir)) return false;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) return false;
+ if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(trackdir)) return false;
tile = GetOtherTunnelEnd(tile);
}
signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index af2a8f25e..6b80ab81b 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -32,6 +32,8 @@
#include "road_map.h"
#include "station_map.h"
#include "tunnel_map.h"
+#include "tunnelbridge_map.h"
+
static RailType _cur_railtype;
static bool _remove_button_clicked;
@@ -1523,8 +1525,8 @@ void SetDefaultRailGui()
if (IsTileType(t, MP_RAILWAY) ||
IsLevelCrossingTile(t) ||
IsRailwayStationTile(t) ||
- (IsTunnelTile(t) && GetTunnelTransportType(t) == TRANSPORT_RAIL) ||
- (IsBridgeTile(t) && GetBridgeTransportType(t) == TRANSPORT_RAIL)
+ (IsTunnelTile(t) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) ||
+ (IsBridgeTile(t) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)
) {
count[GetRailType(t)]++;
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index b3b38e02c..df4404a05 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -34,6 +34,8 @@
#include "misc/autoptr.hpp"
#include "autoslope.h"
#include "transparency.h"
+#include "tunnelbridge_map.h"
+
#define M(x) (1 << (x))
/* Level crossings may only be built on these slopes */
@@ -133,10 +135,10 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex endtile;
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherTunnelEnd(tile);
} else {
- if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherBridgeEnd(tile);
}
@@ -175,7 +177,7 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(other_end);
if (IsBridge(tile)) {
- TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
+ TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
}
@@ -514,10 +516,10 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex endtile;
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherTunnelEnd(tile);
} else {
- if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
endtile = GetOtherBridgeEnd(tile);
}
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
@@ -576,7 +578,7 @@ do_clear:;
MarkTileDirtyByTile(other_end);
MarkTileDirtyByTile(tile);
if (IsBridge(tile)) {
- TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
+ TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
}
@@ -691,12 +693,12 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
/* Only pay for the upgrade on one side of the bridges and tunnels */
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsBridge(tile)) {
- if ((!had_bridge || GetBridgeRampDirection(tile) == DIAGDIR_SE || GetBridgeRampDirection(tile) == DIAGDIR_SW)) {
+ if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
cost.AddCost(ret);
}
had_bridge = true;
} else {
- if ((!had_tunnel || GetTunnelDirection(tile) == DIAGDIR_SE || GetTunnelDirection(tile) == DIAGDIR_SW)) {
+ if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
cost.AddCost(ret);
}
had_tunnel = true;
diff --git a/src/road_map.cpp b/src/road_map.cpp
index 7dc26f079..0bdf66dfe 100644
--- a/src/road_map.cpp
+++ b/src/road_map.cpp
@@ -12,6 +12,7 @@
#include "tunnel_map.h"
#include "station_map.h"
#include "depot.h"
+#include "tunnelbridge_map.h"
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt)
@@ -34,11 +35,11 @@ RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt)
case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
- return DiagDirToRoadBits(ReverseDiagDir(GetTunnelDirection(tile)));
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
+ return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
} else {
- if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
- return DiagDirToRoadBits(ReverseDiagDir(GetBridgeRampDirection(tile)));
+ if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return ROAD_NONE;
+ return DiagDirToRoadBits(ReverseDiagDir(GetTunnelBridgeDirection(tile)));
}
default: return ROAD_NONE;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 7ce4a9c7a..2850b2d7c 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -37,6 +37,8 @@
#include "yapf/yapf.h"
#include "date.h"
#include "cargotype.h"
+#include "tunnelbridge_map.h"
+
static const uint16 _roadveh_images[63] = {
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
@@ -549,8 +551,8 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (IsTileType(v->tile, MP_ROAD) && GetRoadTileType(v->tile) == ROAD_TILE_NORMAL && GetDisallowedRoadDirections(v->tile) != DRD_NONE) return CMD_ERROR;
- if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelDirection(v->tile)) return CMD_ERROR;
- if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetBridgeRampDirection(v->tile)) return CMD_ERROR;
+ if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
+ if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180;
@@ -1406,9 +1408,9 @@ static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev,
DiagDirection diag_dir = INVALID_DIAGDIR;
if (IsTunnelTile(tile)) {
- diag_dir = GetTunnelDirection(tile);
+ diag_dir = GetTunnelBridgeDirection(tile);
} else if (IsBridgeTile(tile)) {
- diag_dir = GetBridgeRampDirection(tile);
+ diag_dir = GetTunnelBridgeDirection(tile);
} else if (IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_DEPOT) {
diag_dir = ReverseDiagDir(GetRoadDepotDirection(tile));
}
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index bb2ee28bb..638a43322 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -28,6 +28,8 @@
#include "sound.h"
#include "variables.h"
#include "blitter/factory.hpp"
+#include "tunnelbridge_map.h"
+
static const Widget _smallmap_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
@@ -340,9 +342,9 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
TransportType tt;
if (IsTunnel(tile)) {
- tt = GetTunnelTransportType(tile);
+ tt = GetTunnelBridgeTransportType(tile);
} else {
- tt = GetBridgeTransportType(tile);
+ tt = GetTunnelBridgeTransportType(tile);
}
switch (tt) {
case TRANSPORT_RAIL: t = MP_RAILWAY; break;
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 6dcac49d4..302146081 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -44,6 +44,8 @@
#include "autoslope.h"
#include "waypoint.h"
#include "transparency.h"
+#include "tunnelbridge_map.h"
+
/* Initialize the town-pool */
DEFINE_OLD_POOL_GENERIC(Town, Town)
@@ -1062,9 +1064,9 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
/* Reached a tunnel/bridge? Then continue at the other side of it. */
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
+ if (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
*tile_ptr = GetOtherTunnelEnd(tile);
- } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_ROAD) {
+ } else if (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
*tile_ptr = GetOtherBridgeEnd(tile);
}
return;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 8264b0fa3..a3f551ec7 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -42,6 +42,8 @@
#include "cargotype.h"
#include "group.h"
#include "table/sprites.h"
+#include "tunnelbridge_map.h"
+
static bool TrainCheckIfLineEnds(Vehicle *v);
static void TrainController(Vehicle *v, bool update_image);
@@ -3057,7 +3059,7 @@ static void DeleteLastWagon(Vehicle *v)
if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy
- DiagDirection dir = IsTunnel(v->tile) ? GetTunnelDirection(v->tile) : GetBridgeRampDirection(v->tile);
+ DiagDirection dir = IsTunnel(v->tile) ? GetTunnelBridgeDirection(v->tile) : GetTunnelBridgeDirection(v->tile);
/* v->direction is "random", so it cannot be used to determine the direction of the track */
UpdateSignalsOnSegment(v->tile, dir);
@@ -3174,7 +3176,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
TileIndex tile = v->tile;
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- DiagDirection dir = IsTunnel(tile) ? GetTunnelDirection(tile) : GetBridgeRampDirection(tile);
+ DiagDirection dir = IsTunnel(tile) ? GetTunnelBridgeDirection(tile) : GetTunnelBridgeDirection(tile);
if (DiagDirToDir(dir) == v->direction) return true;
}
diff --git a/src/tunnel_map.cpp b/src/tunnel_map.cpp
index 593d3fe6b..ac7255155 100644
--- a/src/tunnel_map.cpp
+++ b/src/tunnel_map.cpp
@@ -6,6 +6,8 @@
#include "openttd.h"
#include "tile.h"
#include "tunnel_map.h"
+#include "tunnelbridge_map.h"
+
/**
* Gets the other end of the tunnel. Where a vehicle would reappear when it
@@ -15,7 +17,7 @@
*/
TileIndex GetOtherTunnelEnd(TileIndex tile)
{
- DiagDirection dir = GetTunnelDirection(tile);
+ DiagDirection dir = GetTunnelBridgeDirection(tile);
TileIndexDiff delta = TileOffsByDiagDir(dir);
uint z = GetTileZ(tile);
@@ -24,7 +26,7 @@ TileIndex GetOtherTunnelEnd(TileIndex tile)
tile += delta;
} while (
!IsTunnelTile(tile) ||
- GetTunnelDirection(tile) != dir ||
+ GetTunnelBridgeDirection(tile) != dir ||
GetTileZ(tile) != z
);
@@ -52,7 +54,7 @@ bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
return
z == height &&
IsTunnelTile(tile) &&
- GetTunnelDirection(tile) == dir;
+ GetTunnelBridgeDirection(tile) == dir;
}
/**
diff --git a/src/tunnel_map.h b/src/tunnel_map.h
index e4092cf15..921137a6e 100644
--- a/src/tunnel_map.h
+++ b/src/tunnel_map.h
@@ -11,6 +11,7 @@
#include "rail.h"
#include "road.h"
+
/**
* Is this a tunnel (entrance)?
* @param t the tile that might be a tunnel
@@ -23,7 +24,6 @@ static inline bool IsTunnel(TileIndex t)
return !HasBit(_m[t].m5, 7);
}
-
/**
* Is this a tunnel (entrance)?
* @param t the tile that might be a tunnel
@@ -34,62 +34,10 @@ static inline bool IsTunnelTile(TileIndex t)
return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
}
-/**
- * Gets the direction facing out of the tunnel
- * @param t the tile to get the tunnel facing direction of
- * @pre IsTunnelTile(t)
- * @return the direction the tunnel is facing
- */
-static inline DiagDirection GetTunnelDirection(TileIndex t)
-{
- assert(IsTunnelTile(t));
- return (DiagDirection)GB(_m[t].m5, 0, 2);
-}
-
-/**
- * Gets the transport type of the tunnel (road or rail)
- * @param t the tunnel entrance tile to get the type of
- * @pre IsTunnelTile(t)
- * @return the transport type in the tunnel
- */
-static inline TransportType GetTunnelTransportType(TileIndex t)
-{
- assert(IsTunnelTile(t));
- return (TransportType)GB(_m[t].m5, 2, 2);
-}
-
-/**
- * Is this tunnel entrance in a snowy or desert area?
- * @param t the tunnel entrance tile
- * @pre IsTunnelTile(t)
- * @return true if and only if the tunnel entrance is in a snowy/desert area
- */
-static inline bool HasTunnelSnowOrDesert(TileIndex t)
-{
- assert(IsTunnelTile(t));
- return HasBit(_m[t].m4, 7);
-}
-
-/**
- * Places this tunnel entrance in a snowy or desert area,
- * or takes it out of there.
- * @param t the tunnel entrance tile
- * @param snow_or_desert is the entrance in snow or desert (true), when
- * not in snow and not in desert false
- * @pre IsTunnelTile(t)
- */
-static inline void SetTunnelSnowOrDesert(TileIndex t, bool snow_or_desert)
-{
- assert(IsTunnelTile(t));
- SB(_m[t].m4, 7, 1, snow_or_desert);
-}
-
-
TileIndex GetOtherTunnelEnd(TileIndex);
bool IsTunnelInWay(TileIndex, uint z);
bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir);
-
/**
* Makes a road tunnel entrance
* @param t the entrance of the tunnel
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 272d1bca6..14304e624 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -34,9 +34,10 @@
#include "newgrf_sound.h"
#include "autoslope.h"
#include "transparency.h"
-
+#include "tunnelbridge_map.h"
#include "table/bridge_land.h"
+
const Bridge orig_bridge[] = {
/*
year of availablity
@@ -266,7 +267,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
GetOtherBridgeEnd(tile_start) == tile_end &&
- GetBridgeTransportType(tile_start) == transport_type) {
+ GetTunnelBridgeTransportType(tile_start) == transport_type) {
/* Replace a current bridge. */
/* If this is a railway bridge, make sure the railtypes match. */
@@ -391,7 +392,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
case MP_TUNNELBRIDGE:
if (IsTunnel(tile)) break;
if (replace_bridge) break;
- if (direction == DiagDirToAxis(GetBridgeRampDirection(tile))) goto not_valid_below;
+ if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
break;
@@ -602,7 +603,7 @@ static CommandCost DoClearTunnel(TileIndex tile, uint32 flags)
if (flags & DC_EXEC) {
/* We first need to request the direction before calling DoClearSquare
* else the direction is always 0.. dah!! ;) */
- DiagDirection dir = GetTunnelDirection(tile);
+ DiagDirection dir = GetTunnelBridgeDirection(tile);
Track track;
/* Adjust the town's player rating. Do this before removing the tile owner info. */
@@ -636,7 +637,7 @@ static CommandCost DoClearBridge(TileIndex tile, uint32 flags)
if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
- direction = GetBridgeRampDirection(tile);
+ direction = GetTunnelBridgeDirection(tile);
delta = TileOffsByDiagDir(direction);
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
@@ -701,7 +702,7 @@ static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
*/
CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec)
{
- if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
+ if (IsTunnel(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
TileIndex endtile = GetOtherTunnelEnd(tile);
/* If not coverting rail <-> el. rail, any vehicle cannot be in tunnel */
@@ -716,7 +717,7 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
- Track track = AxisToTrack(DiagDirToAxis(GetTunnelDirection(tile)));
+ Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
@@ -726,7 +727,7 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec
}
return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype));
- } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_RAIL) {
+ } else if (IsBridge(tile) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
TileIndex endtile = GetOtherBridgeEnd(tile);
if (!IsCompatibleRail(GetRailType(tile), totype) &&
@@ -740,8 +741,8 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec
MarkTileDirtyByTile(tile);
MarkTileDirtyByTile(endtile);
- Track track = AxisToTrack(DiagDirToAxis(GetBridgeRampDirection(tile)));
- TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
+ Track track = AxisToTrack(DiagDirToAxis(GetTunnelBridgeDirection(tile)));
+ TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
@@ -894,22 +895,22 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
{ 1, 0, -15, -14, 0, 15, 16, 1, 0, 1, 16, 15 }, // SW
{ 0, 1, -14, -15, 15, 0, 1, 16, 1, 0, 15, 16 }, // NW
};
- const int *BB_data = _tunnel_BB[GetTunnelDirection(ti->tile)];
+ const int *BB_data = _tunnel_BB[GetTunnelBridgeDirection(ti->tile)];
bool catenary = false;
- if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
+ if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
} else {
image = SPR_TUNNEL_ENTRY_REAR_ROAD;
}
- if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
+ if (HasTunnelBridgeSnowOrDesert(ti->tile)) image += 32;
- image += GetTunnelDirection(ti->tile) * 2;
+ image += GetTunnelBridgeDirection(ti->tile) * 2;
DrawGroundSprite(image, PAL_NONE);
- if (GetTunnelTransportType(ti->tile) == TRANSPORT_ROAD) {
- DiagDirection dir = GetTunnelDirection(ti->tile);
+ if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
+ DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
RoadTypes rts = GetRoadTypes(ti->tile);
if (HasBit(rts, ROADTYPE_TRAM)) {
@@ -941,9 +942,9 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
} else if (IsBridge(ti->tile)) { // XXX is this necessary?
const PalSpriteID *psid;
int base_offset;
- bool ice = HasBridgeSnowOrDesert(ti->tile);
+ bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
- if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
+ if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
assert(base_offset != 8); // This one is used for roads
} else {
@@ -953,10 +954,10 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
/* as the lower 3 bits are used for other stuff, make sure they are clear */
assert( (base_offset & 0x07) == 0x00);
- DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile))));
+ DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetTunnelBridgeDirection(ti->tile))));
/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
- base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
+ base_offset += (6 - GetTunnelBridgeDirection(ti->tile)) % 4;
if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
@@ -972,7 +973,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
/* draw ramp */
/* Draw Trambits as SpriteCombine */
- if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) StartSpriteCombine();
+ if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) StartSpriteCombine();
/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
* it doesn't disappear behind it
@@ -981,11 +982,11 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, IsTransparencySet(TO_BRIDGES)
);
- if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
+ if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
RoadTypes rts = GetRoadTypes(ti->tile);
if (HasBit(rts, ROADTYPE_TRAM)) {
- uint offset = GetBridgeRampDirection(ti->tile);
+ uint offset = GetTunnelBridgeDirection(ti->tile);
uint z = ti->z;
if (ti->tileh != SLOPE_FLAT) {
offset = (offset + 1) & 1;
@@ -1084,7 +1085,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
);
type = GetBridgeType(rampsouth);
- if (GetBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
+ if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_RAIL) {
base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
} else {
base_offset = 8;
@@ -1102,7 +1103,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, x, y, 16, 16, 1, bridge_z - TILE_HEIGHT + BB_Z_SEPARATOR);
/* Draw Trambits as SpriteCombine */
- if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) StartSpriteCombine();
+ if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) StartSpriteCombine();
/* Draw floor and far part of bridge*/
if (axis == AXIS_X) {
@@ -1113,7 +1114,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
psid++;
- if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
+ if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
RoadTypes rts = GetRoadTypes(rampsouth);
if (HasBit(rts, ROADTYPE_TRAM)) {
@@ -1137,7 +1138,7 @@ void DrawBridgeMiddle(const TileInfo* ti)
}
/* Draw TramFront as SpriteCombine */
- if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) EndSpriteCombine();
+ if (GetTunnelBridgeTransportType(rampsouth) == TRANSPORT_ROAD) EndSpriteCombine();
psid++;
if (ti->z + 5 == z) {
@@ -1168,12 +1169,12 @@ static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
y &= 0xF;
if (IsTunnel(tile)) {
- uint pos = (DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? y : x);
+ uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
/* In the tunnel entrance? */
if (5 <= pos && pos <= 10) return z;
} else {
- DiagDirection dir = GetBridgeRampDirection(tile);
+ DiagDirection dir = GetTunnelBridgeDirection(tile);
uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
@@ -1200,7 +1201,7 @@ static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y)
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
{
- return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
+ return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
}
@@ -1244,10 +1245,10 @@ static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] =
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
{
if (IsTunnel(tile)) {
- td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
+ td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
} else {
- td->str = _bridge_tile_str[GetBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
+ td->str = _bridge_tile_str[GetTunnelBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
}
td->owner = GetTileOwner(tile);
}
@@ -1260,14 +1261,14 @@ static void AnimateTile_TunnelBridge(TileIndex tile)
static void TileLoop_TunnelBridge(TileIndex tile)
{
- bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelSnowOrDesert(tile) : HasBridgeSnowOrDesert(tile);
+ bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelBridgeSnowOrDesert(tile) : HasTunnelBridgeSnowOrDesert(tile);
switch (_opt.landscape) {
case LT_ARCTIC:
if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
if (IsTunnelTile(tile)) {
- SetTunnelSnowOrDesert(tile, !snow_or_desert);
+ SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
} else {
- SetBridgeSnowOrDesert(tile, !snow_or_desert);
+ SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert);
}
MarkTileDirtyByTile(tile);
}
@@ -1276,9 +1277,9 @@ static void TileLoop_TunnelBridge(TileIndex tile)
case LT_TROPIC:
if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) {
if (IsTunnelTile(tile)) {
- SetTunnelSnowOrDesert(tile, true);
+ SetTunnelBridgeSnowOrDesert(tile, true);
} else {
- SetBridgeSnowOrDesert(tile, true);
+ SetTunnelBridgeSnowOrDesert(tile, true);
}
MarkTileDirtyByTile(tile);
}
@@ -1295,13 +1296,13 @@ static void ClickTile_TunnelBridge(TileIndex tile)
static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode)
{
if (IsTunnel(tile)) {
- if (GetTunnelTransportType(tile) != mode) return 0;
- if (GetTunnelTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
- return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(tile))) * 0x101;
+ if (GetTunnelBridgeTransportType(tile) != mode) return 0;
+ if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
+ return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
} else {
- if (GetBridgeTransportType(tile) != mode) return 0;
- if (GetBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
- return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(tile))) * 0x101;
+ if (GetTunnelBridgeTransportType(tile) != mode) return 0;
+ if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0) return 0;
+ return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101;
}
}
@@ -1317,7 +1318,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, Pl
* the bridge/tunnel. As all *our* vehicles are already removed, they
* must be of another owner. Therefor this must be a road bridge/tunnel.
* In that case we can safely reassign the ownership to OWNER_NONE. */
- assert((IsTunnel(tile) ? GetTunnelTransportType(tile) : GetBridgeTransportType(tile)) == TRANSPORT_ROAD);
+ assert((IsTunnel(tile) ? GetTunnelBridgeTransportType(tile) : GetTunnelBridgeTransportType(tile)) == TRANSPORT_ROAD);
SetTileOwner(tile, OWNER_NONE);
}
}
@@ -1354,7 +1355,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
if (v->type == VEH_TRAIN) {
fc = (x & 0xF) + (y << 4);
- dir = GetTunnelDirection(tile);
+ dir = GetTunnelBridgeDirection(tile);
vdir = DirToDiagDir(v->direction);
if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
@@ -1382,7 +1383,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
}
} else if (v->type == VEH_ROAD) {
fc = (x & 0xF) + (y << 4);
- dir = GetTunnelDirection(tile);
+ dir = GetTunnelBridgeDirection(tile);
vdir = DirToDiagDir(v->direction);
/* Enter tunnel? */
@@ -1422,7 +1423,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
if (v->cur_speed > spd) v->cur_speed = spd;
}
- dir = GetBridgeRampDirection(tile);
+ dir = GetTunnelBridgeDirection(tile);
if (DirToDiagDir(v->direction) == dir) {
switch (dir) {
default: NOT_REACHED();
@@ -1462,7 +1463,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
{
if (_patches.build_on_slopes && AutoslopeEnabled() && IsBridge(tile)) {
- DiagDirection direction = GetBridgeRampDirection(tile);
+ DiagDirection direction = GetTunnelBridgeDirection(tile);
Axis axis = DiagDirToAxis(direction);
CommandCost res;
diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h
new file mode 100644
index 000000000..dda1cc258
--- /dev/null
+++ b/src/tunnelbridge_map.h
@@ -0,0 +1,68 @@
+/* $Id$ */
+
+/** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */
+
+#ifndef TUNNELBRIDGE_MAP_H
+#define TUNNELBRIDGE_MAP_H
+
+#include "direction.h" /* DiagDirection */
+#include "core/bitmath_func.hpp" /* GB, HasBit, SB */
+#include "map.h" /* Tile, TileIndex */
+#include "tile.h" /* TileType, IsTileType */
+#include "openttd.h" /* TransportType */
+
+
+/**
+ * Tunnel: Get the direction facing out of the tunnel
+ * Bridge: Get the direction pointing onto the bridge
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return the above mentionned direction
+ */
+static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return (DiagDirection)GB(_m[t].m5, 0, 2);
+}
+
+/**
+ * Tunnel: Get the transport type of the tunnel (road or rail)
+ * Bridge: Get the transport type of the bridge's ramp
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return the transport type in the tunnel/bridge
+ */
+static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return (TransportType)GB(_m[t].m5, 2, 2);
+}
+
+/**
+ * Tunnel: Is this tunnel entrance in a snowy or desert area?
+ * Bridge: Does the bridge ramp lie in a snow or desert area?
+ * @param t The tile to analyze
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return true if and only if the tile is in a snowy/desert area
+ */
+static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return HasBit(_m[t].m4, 7);
+}
+
+/**
+ * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
+ * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
+ * @param t the tunnel entrance / bridge ramp tile
+ * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
+ * not in snow and not in desert false
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ */
+static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ SB(_m[t].m4, 7, 1, snow_or_desert);
+}
+
+#endif /* TUNNELBRIDGE_MAP_H */
diff --git a/src/yapf/follow_track.hpp b/src/yapf/follow_track.hpp
index 75fff5109..1b1fc2bfb 100644
--- a/src/yapf/follow_track.hpp
+++ b/src/yapf/follow_track.hpp
@@ -78,7 +78,7 @@ protected:
// extra handling for tunnels in our direction
if (IsTunnelTile(m_old_tile)) {
- DiagDirection tunnel_enterdir = GetTunnelDirection(m_old_tile);
+ DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_old_tile);
if (tunnel_enterdir == m_exitdir) {
// we are entering the tunnel
FindLengthOfTunnelResult flotr = FindLengthOfTunnel(m_old_tile, m_exitdir);
@@ -92,7 +92,7 @@ protected:
// extra handling for bridge ramp in our direction
if (IsBridgeTile(m_old_tile)) {
- DiagDirection bridge_enterdir = GetBridgeRampDirection(m_old_tile);
+ DiagDirection bridge_enterdir = GetTunnelBridgeDirection(m_old_tile);
if (bridge_enterdir == m_exitdir) {
// we are entering the bridge ramp
m_new_tile = GetOtherBridgeEnd(m_old_tile);
@@ -208,7 +208,7 @@ protected:
if (!IsWaterTT() && IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
if (IsTunnel(m_new_tile)) {
if (!m_is_tunnel) {
- DiagDirection tunnel_enterdir = GetTunnelDirection(m_new_tile);
+ DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
if (tunnel_enterdir != m_exitdir) {
m_err = EC_NO_WAY;
return false;
@@ -216,7 +216,7 @@ protected:
}
} else if (IsBridge(m_new_tile)) {
if (!m_is_bridge) {
- DiagDirection ramp_enderdir = GetBridgeRampDirection(m_new_tile);
+ DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
if (ramp_enderdir != m_exitdir) {
m_err = EC_NO_WAY;
return false;
diff --git a/src/yapf/yapf.hpp b/src/yapf/yapf.hpp
index f98a7c607..2bbbc0a7a 100644
--- a/src/yapf/yapf.hpp
+++ b/src/yapf/yapf.hpp
@@ -12,6 +12,7 @@
#include "../road_map.h"
#include "../tunnel_map.h"
#include "../bridge_map.h"
+#include "../tunnelbridge_map.h"
#include "../bridge.h"
#include "../station.h"
#include "../station_map.h"
diff --git a/src/yapf/yapf_costbase.hpp b/src/yapf/yapf_costbase.hpp
index df4d9e787..2793aab9f 100644
--- a/src/yapf/yapf_costbase.hpp
+++ b/src/yapf/yapf_costbase.hpp
@@ -11,7 +11,7 @@ struct CYapfCostBase {
if (IsDiagonalTrackdir(td)) {
if (IsBridgeTile(tile)) {
// it is bridge ramp, check if we are entering the bridge
- if (GetBridgeRampDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
+ if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
// we are entering the bridge
// if the tile slope is downwards, then bridge ramp has not upward slope
uint tile_slope = GetTileSlope(tile, NULL) & 0x0F;