(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does

This commit is contained in:
tron 2006-03-12 15:04:03 +00:00
parent b394f72fa9
commit 78083f0da7
14 changed files with 61 additions and 68 deletions

View File

@ -7,6 +7,7 @@
#include "../../road_map.h" #include "../../road_map.h"
#include "../../tile.h" #include "../../tile.h"
#include "../../player.h" #include "../../player.h"
#include "../../tunnel_map.h"
#include "../../vehicle.h" #include "../../vehicle.h"
#include "../../engine.h" #include "../../engine.h"
#include "../../command.h" #include "../../command.h"
@ -2147,7 +2148,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
TileIndex tilenew; TileIndex tilenew;
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (!(_m[tile].m5 & 0x80)) { if (IsTunnel(tile)) {
// Clear the tunnel and continue at the other side of it. // Clear the tunnel and continue at the other side of it.
if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
return false; return false;

View File

@ -43,8 +43,7 @@ static bool IsRoad(TileIndex tile)
// MP_STREET, but not a road depot? // MP_STREET, but not a road depot?
(IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) || (IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
(IsTileType(tile, MP_TUNNELBRIDGE) && ( (IsTileType(tile, MP_TUNNELBRIDGE) && (
// road tunnel? (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) ||
((_m[tile].m5 & 0x80) == 0 && (_m[tile].m5 & 0x4) == 0x4) ||
// road bridge? // road bridge?
((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2) ((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2)
)); ));
@ -232,12 +231,10 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
// If the next step is a bridge, we have to enter it the right way // If the next step is a bridge, we have to enter it the right way
if (!PathFinderInfo->rail_or_road && IsRoad(atile)) { if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
if (IsTileType(atile, MP_TUNNELBRIDGE)) { if (IsTileType(atile, MP_TUNNELBRIDGE)) {
// An existing bridge... let's test the direction ;) if (IsTunnel(atile)) {
if ((_m[atile].m5 & 1U) != (i & 1)) continue;
// This problem only is valid for tunnels:
// When the last tile was not yet a tunnel, check if we enter from the right side..
if ((_m[atile].m5 & 0x80) == 0) {
if (GetTunnelDirection(atile) != i) continue; if (GetTunnelDirection(atile) != i) continue;
} else {
if ((_m[atile].m5 & 1U) != DiagDirToAxis(i)) continue;
} }
} }
} }

17
npf.c
View File

@ -260,11 +260,11 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */ /* Determine base length */
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (GB(_m[tile].m5, 4, 4) == 0) { if (IsTunnel(tile)) {
cost = NPFTunnelCost(current); cost = NPFTunnelCost(current);
break; } else {
cost = NPF_TILE_LENGTH;
} }
cost = NPF_TILE_LENGTH;
break; break;
case MP_STREET: case MP_STREET:
@ -306,7 +306,7 @@ static int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Determine base length */ /* Determine base length */
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
if (GB(_m[tile].m5, 4, 4) == 0) { if (IsTunnel(tile)) {
cost = NPFTunnelCost(current); cost = NPFTunnelCost(current);
break; break;
} }
@ -483,7 +483,7 @@ static bool VehicleMayEnterTile(Owner owner, TileIndex tile, DiagDirection enter
} }
/* if we were on a railway middle part, we are now at a railway bridge ending */ /* if we were on a railway middle part, we are now at a railway bridge ending */
#endif #endif
if ((_m[tile].m5 & 0xFC) == 0 || /* railway tunnel */ if ((IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) ||
(_m[tile].m5 & 0xC6) == 0x80 || /* railway bridge ending */ (_m[tile].m5 & 0xC6) == 0x80 || /* railway bridge ending */
((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1))) { /* railway under bridge */ ((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1))) { /* railway under bridge */
return IsTileOwner(tile, owner); return IsTileOwner(tile, owner);
@ -517,9 +517,7 @@ 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); DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
/* Find dest tile */ /* Find dest tile */
if (IsTileType(src_tile, MP_TUNNELBRIDGE) && if (IsTunnelTile(src_tile) && GetTunnelDirection(src_tile) == src_exitdir) {
GB(_m[src_tile].m5, 4, 4) == 0 &&
GetTunnelDirection(src_tile) == src_exitdir) {
/* This is a tunnel. We know this tunnel is our type, /* This is a tunnel. We know this tunnel is our type,
* otherwise we wouldn't have got here. It is also facing us, * otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */ * so we should skip it's body */
@ -565,8 +563,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note /* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note
* that I can enter the tunnel from a tile below the tunnel entrance. This * that I can enter the tunnel from a tile below the tunnel entrance. This
* solves the problem of vehicles wanting to drive off a tunnel entrance */ * solves the problem of vehicles wanting to drive off a tunnel entrance */
if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && GB(_m[dst_tile].m5, 4, 4) == 0 && if (IsTunnelTile(dst_tile) && GetTileZ(dst_tile) < GetTileZ(src_tile)) {
GetTileZ(dst_tile) < GetTileZ(src_tile)) {
return; return;
} }

View File

@ -231,8 +231,7 @@ FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direct
tile = TileVirtXY(x, y); tile = TileVirtXY(x, y);
if (IsTileType(tile, MP_TUNNELBRIDGE) && if (IsTunnelTile(tile) &&
GB(_m[tile].m5, 4, 4) == 0 && // tunnel entrance/exit
// GetTunnelTransportType(tile) == type && // rail/road-tunnel <-- This is not necesary to check, right? // GetTunnelTransportType(tile) == type && // rail/road-tunnel <-- This is not necesary to check, right?
ReverseDiagDir(GetTunnelDirection(tile)) == direction && ReverseDiagDir(GetTunnelDirection(tile)) == direction &&
GetSlopeZ(x + 8, y + 8) == z) { GetSlopeZ(x + 8, y + 8) == z) {
@ -283,7 +282,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
RememberData rd; RememberData rd;
TileIndex tile_org = tile; TileIndex tile_org = tile;
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { if (IsTunnelTile(tile)) {
if (GetTunnelDirection(tile) != direction || if (GetTunnelDirection(tile) != direction ||
GetTunnelTransportType(tile) != tpf->tracktype) { GetTunnelTransportType(tile) != tpf->tracktype) {
return; return;
@ -716,21 +715,18 @@ callback_and_continue:
start_at: start_at:
// If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, // If the tile is the entry tile of a tunnel, and we're not going out of the tunnel,
// need to find the exit of the tunnel. // need to find the exit of the tunnel.
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTunnelTile(tile) &&
if (GB(_m[tile].m5, 4, 4) == 0 && GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
GetTunnelDirection(tile) != ReverseDiagDir(direction)) { /* We are not just driving out of the tunnel */
/* This is a tunnel tile */ if (GetTunnelDirection(tile) != direction ||
/* We are not just driving out of the tunnel */ GetTunnelTransportType(tile) != tpf->tracktype) {
if (GetTunnelDirection(tile) != direction || // We are not driving into the tunnel, or it is an invalid tunnel
GetTunnelTransportType(tile) != tpf->tracktype) { continue;
// We are not driving into the tunnel, or it is an invalid tunnel
continue;
}
flotr = FindLengthOfTunnel(tile, direction);
si.cur_length += flotr.length * DIAG_FACTOR;
tile = flotr.tile;
// tile now points to the exit tile of the tunnel
} }
flotr = FindLengthOfTunnel(tile, direction);
si.cur_length += flotr.length * DIAG_FACTOR;
tile = flotr.tile;
// tile now points to the exit tile of the tunnel
} }
// This is a special loop used to go through // This is a special loop used to go through

6
rail.c
View File

@ -4,6 +4,7 @@
#include "openttd.h" #include "openttd.h"
#include "rail.h" #include "rail.h"
#include "station.h" #include "station.h"
#include "tunnel_map.h"
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */ /* 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 /* Maps a trackdir to the bit that stores its status in the map arrays, in the
@ -123,8 +124,9 @@ RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
type = _m[tile].m3 & RAILTYPE_MASK; type = _m[tile].m3 & RAILTYPE_MASK;
break; break;
case MP_TUNNELBRIDGE: case MP_TUNNELBRIDGE:
/* railway tunnel */ if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
if ((_m[tile].m5 & 0xFC) == 0) type = _m[tile].m3 & RAILTYPE_MASK; return _m[tile].m3 & RAILTYPE_MASK;
}
/* railway bridge ending */ /* railway bridge ending */
if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK; if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK;
/* on railway bridge */ /* on railway bridge */

View File

@ -1625,7 +1625,7 @@ static bool SignalVehicleCheck(TileIndex tile, uint track)
* is some kind of invisible black hole, and there is some special magic going * is some kind of invisible black hole, and there is some special magic going
* on in there. This 'workaround' can be removed once the maprewrite is done. * on in there. This 'workaround' can be removed once the maprewrite is done.
*/ */
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) { if (IsTunnelTile(tile)) {
// It is a tunnel we're checking, we need to do some special stuff // It is a tunnel we're checking, we need to do some special stuff
// because VehicleFromPos will not find the vihicle otherwise // because VehicleFromPos will not find the vihicle otherwise
TileIndex end = GetOtherTunnelEnd(tile); TileIndex end = GetOtherTunnelEnd(tile);

View File

@ -18,6 +18,7 @@
#include "player.h" #include "player.h"
#include "sound.h" #include "sound.h"
#include "depot.h" #include "depot.h"
#include "tunnel_map.h"
#include "vehicle_gui.h" #include "vehicle_gui.h"
#include "newgrf_engine.h" #include "newgrf_engine.h"
@ -1254,8 +1255,7 @@ static void RoadVehController(Vehicle *v)
return; return;
} }
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && if (IsTunnelTile(gp.new_tile) &&
GB(_m[gp.new_tile].m5, 4, 4) == 0 &&
VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) {
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) //new_dir = RoadGetNewDirection(v, gp.x, gp.y)
v->cur_image = GetRoadVehImage(v, v->direction); v->cur_image = GetRoadVehImage(v, v->direction);

View File

@ -348,10 +348,10 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
if (t == MP_TUNNELBRIDGE) { if (t == MP_TUNNELBRIDGE) {
TransportType tt; TransportType tt;
if (_m[tile].m5 & 0x80) { if (IsTunnel(tile)) {
tt = GB(_m[tile].m5, 1, 2);
} else {
tt = GetTunnelTransportType(tile); tt = GetTunnelTransportType(tile);
} else {
tt = GB(_m[tile].m5, 1, 2);
} }
switch (tt) { switch (tt) {
case TRANSPORT_RAIL: t = MP_RAILWAY; break; case TRANSPORT_RAIL: t = MP_RAILWAY; break;

4
tile.h
View File

@ -79,10 +79,6 @@ static inline bool IsTileType(TileIndex tile, TileType type)
return GetTileType(tile) == type; return GetTileType(tile) == type;
} }
static inline bool IsTunnelTile(TileIndex tile)
{
return IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0;
}
static inline Owner GetTileOwner(TileIndex tile) static inline Owner GetTileOwner(TileIndex tile)
{ {

View File

@ -624,9 +624,7 @@ static void GrowTownInTile(TileIndex* tile_ptr, RoadBits mask, int block, Town*
int i; int i;
// Reached a tunnel? Then continue at the other side of it. // Reached a tunnel? Then continue at the other side of it.
if (IsTileType(tile, MP_TUNNELBRIDGE) && if (IsTunnelTile(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
GB(_m[tile].m5, 4, 4) == 0 &&
GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
*tile_ptr = GetOtherTunnelEnd(tile); *tile_ptr = GetOtherTunnelEnd(tile);
return; return;
} }

View File

@ -2481,8 +2481,9 @@ static byte AfterSetTrainPos(Vehicle *v, bool new_tile)
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
// XXX workaround, whole UP/DOWN detection needs overhaul // XXX workaround, whole UP/DOWN detection needs overhaul
if (!IsTileType(tile, MP_TUNNELBRIDGE) || (_m[tile].m5 & 0x80) != 0) if (!IsTunnelTile(tile)) {
SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN); SETBIT(v->u.rail.flags, (new_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN);
}
} }
} }

View File

@ -15,8 +15,7 @@ TileIndex GetOtherTunnelEnd(TileIndex tile)
do { do {
tile += delta; tile += delta;
} while ( } while (
!IsTileType(tile, MP_TUNNELBRIDGE) || !IsTunnelTile(tile) ||
GB(_m[tile].m5, 4, 4) != 0 ||
GetTunnelDirection(tile) != dir || GetTunnelDirection(tile) != dir ||
GetTileZ(tile) != z GetTileZ(tile) != z
); );
@ -37,8 +36,7 @@ static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir)
return return
z == height && z == height &&
IsTileType(tile, MP_TUNNELBRIDGE) && IsTunnelTile(tile) &&
GB(_m[tile].m5, 4, 4) == 0 &&
GetTunnelDirection(tile) == dir; GetTunnelDirection(tile) == dir;
} }

View File

@ -9,6 +9,18 @@
#include "rail.h" #include "rail.h"
static inline bool IsTunnel(TileIndex t)
{
return !HASBIT(_m[t].m5, 7);
}
static inline bool IsTunnelTile(TileIndex t)
{
return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
}
static inline DiagDirection GetTunnelDirection(TileIndex t) static inline DiagDirection GetTunnelDirection(TileIndex t)
{ {
return (DiagDirection)GB(_m[t].m5, 0, 2); return (DiagDirection)GB(_m[t].m5, 0, 2);

View File

@ -525,8 +525,7 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
tile += delta; tile += delta;
len++; len++;
} while ( } while (
!IsTileType(tile, MP_TUNNELBRIDGE) || !IsTunnelTile(tile) ||
GB(_m[tile].m5, 4, 4) != 0 ||
ReverseDiagDir(GetTunnelDirection(tile)) != dir || ReverseDiagDir(GetTunnelDirection(tile)) != dir ||
GetTileZ(tile) != z GetTileZ(tile) != z
); );
@ -742,7 +741,7 @@ static int32 ClearTile_TunnelBridge(TileIndex tile, byte flags)
{ {
byte m5 = _m[tile].m5; byte m5 = _m[tile].m5;
if ((m5 & 0xF0) == 0) { if (IsTunnel(tile)) {
if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST); if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
return DoClearTunnel(tile, flags); return DoClearTunnel(tile, flags);
} else if (m5 & 0x80) { } else if (m5 & 0x80) {
@ -759,8 +758,7 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, uint totype, bool exec)
uint length; uint length;
Vehicle *v; Vehicle *v;
if ((_m[tile].m5 & 0xFC) == 0x00) { if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
// railway tunnel
if (!CheckTileOwnership(tile)) return CMD_ERROR; if (!CheckTileOwnership(tile)) return CMD_ERROR;
if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR; if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
@ -962,7 +960,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
bool ice = _m[ti->tile].m4 & 0x80; bool ice = _m[ti->tile].m4 & 0x80;
// draw tunnel? // draw tunnel?
if ((ti->map5 & 0xF0) == 0) { if (IsTunnel(ti->tile)) {
if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) { if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel; image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel;
} else { } else {
@ -1229,7 +1227,7 @@ static const StringID _bridge_tile_str[(MAX_BRIDGES + 3) + (MAX_BRIDGES + 3)] =
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td) static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
{ {
if ((_m[tile].m5 & 0x80) == 0) { if (IsTunnel(tile)) {
td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ? td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL; STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
} else { } else {
@ -1291,8 +1289,7 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode
uint32 result; uint32 result;
byte m5 = _m[tile].m5; byte m5 = _m[tile].m5;
if ((m5 & 0xF0) == 0) { if (IsTunnel(tile)) {
/* This is a tunnel */
if (GetTunnelTransportType(tile) == mode) { if (GetTunnelTransportType(tile) == mode) {
return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202; return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202;
} }
@ -1371,7 +1368,7 @@ static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
{ {
if (GB(_m[tile].m5, 4, 4) == 0) { if (IsTunnel(tile)) {
int z = GetSlopeZ(x, y) - v->z_pos; int z = GetSlopeZ(x, y) - v->z_pos;
byte fc; byte fc;
DiagDirection dir; DiagDirection dir;
@ -1463,9 +1460,7 @@ TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
byte z = v->z_pos; byte z = v->z_pos;
for (tile = v->tile;; tile += delta) { for (tile = v->tile;; tile += delta) {
if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 && if (IsTunnelTile(tile) && GetTileZ(tile) == z) break;
GetTileZ(tile) == z)
break;
} }
return tile; return tile;
} }