Changeset - r3184:028654b02189
[Not reviewed]
master
0 14 0
tron - 18 years ago 2006-03-12 15:04:03
tron@openttd.org
(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
14 files changed with 61 insertions and 68 deletions:
0 comments (0 inline, 0 general)
ai/default/default.c
Show inline comments
 
@@ -7,6 +7,7 @@
 
#include "../../road_map.h"
 
#include "../../tile.h"
 
#include "../../player.h"
 
#include "../../tunnel_map.h"
 
#include "../../vehicle.h"
 
#include "../../engine.h"
 
#include "../../command.h"
 
@@ -2147,7 +2148,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
	TileIndex tilenew;
 

	
 
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		if (!(_m[tile].m5 & 0x80)) {
 
		if (IsTunnel(tile)) {
 
			// Clear the tunnel and continue at the other side of it.
 
			if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
 
				return false;
ai/trolly/pathfinder.c
Show inline comments
 
@@ -43,8 +43,7 @@ static bool IsRoad(TileIndex tile)
 
		// MP_STREET, but not a road depot?
 
		(IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
 
		(IsTileType(tile, MP_TUNNELBRIDGE) && (
 
			// road tunnel?
 
			((_m[tile].m5 & 0x80) == 0 && (_m[tile].m5 & 0x4) == 0x4) ||
 
			(IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) ||
 
			// road bridge?
 
			((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2)
 
		));
 
@@ -232,12 +231,10 @@ static void AyStar_AiPathFinder_GetNeigh
 
			// If the next step is a bridge, we have to enter it the right way
 
			if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
 
				if (IsTileType(atile, MP_TUNNELBRIDGE)) {
 
					// An existing bridge... let's test the direction ;)
 
					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 (IsTunnel(atile)) {
 
						if (GetTunnelDirection(atile) != i) continue;
 
					} else {
 
						if ((_m[atile].m5 & 1U) != DiagDirToAxis(i)) continue;
 
					}
 
				}
 
			}
npf.c
Show inline comments
 
@@ -260,11 +260,11 @@ static int32 NPFRoadPathCost(AyStar* as,
 
	/* Determine base length */
 
	switch (GetTileType(tile)) {
 
		case MP_TUNNELBRIDGE:
 
			if (GB(_m[tile].m5, 4, 4) == 0) {
 
			if (IsTunnel(tile)) {
 
				cost = NPFTunnelCost(current);
 
				break;
 
			} else {
 
				cost = NPF_TILE_LENGTH;
 
			}
 
			cost = NPF_TILE_LENGTH;
 
			break;
 

	
 
		case MP_STREET:
 
@@ -306,7 +306,7 @@ static int32 NPFRailPathCost(AyStar* as,
 
	/* Determine base length */
 
	switch (GetTileType(tile)) {
 
		case MP_TUNNELBRIDGE:
 
			if (GB(_m[tile].m5, 4, 4) == 0) {
 
			if (IsTunnel(tile)) {
 
				cost = NPFTunnelCost(current);
 
				break;
 
			}
 
@@ -483,7 +483,7 @@ static bool VehicleMayEnterTile(Owner ow
 
			}
 
			/* if we were on a railway middle part, we are now at a railway bridge ending */
 
#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 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1))) { /* railway under bridge */
 
				return IsTileOwner(tile, owner);
 
@@ -517,9 +517,7 @@ static void NPFFollowTrack(AyStar* aysta
 
	DEBUG(npf, 4)("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
 

	
 
	/* Find dest tile */
 
	if (IsTileType(src_tile, MP_TUNNELBRIDGE) &&
 
			GB(_m[src_tile].m5, 4, 4) == 0 &&
 
			GetTunnelDirection(src_tile) == src_exitdir) {
 
	if (IsTunnelTile(src_tile) && GetTunnelDirection(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 */
 
@@ -565,8 +563,7 @@ static void NPFFollowTrack(AyStar* aysta
 
	/* 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
 
	 * 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 &&
 
			GetTileZ(dst_tile) < GetTileZ(src_tile)) {
 
	if (IsTunnelTile(dst_tile) && GetTileZ(dst_tile) < GetTileZ(src_tile)) {
 
		return;
 
	}
 

	
pathfind.c
Show inline comments
 
@@ -231,8 +231,7 @@ FindLengthOfTunnelResult FindLengthOfTun
 

	
 
		tile = TileVirtXY(x, y);
 

	
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) &&
 
				GB(_m[tile].m5, 4, 4) == 0 &&               // tunnel entrance/exit
 
		if (IsTunnelTile(tile) &&
 
				// GetTunnelTransportType(tile) == type &&  // rail/road-tunnel <-- This is not necesary to check, right?
 
				ReverseDiagDir(GetTunnelDirection(tile)) == direction &&
 
				GetSlopeZ(x + 8, y + 8) == z) {
 
@@ -283,7 +282,7 @@ static void TPFMode1(TrackPathFinder* tp
 
	RememberData rd;
 
	TileIndex tile_org = tile;
 

	
 
	if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) {
 
	if (IsTunnelTile(tile)) {
 
		if (GetTunnelDirection(tile) != direction ||
 
				GetTunnelTransportType(tile) != tpf->tracktype) {
 
			return;
 
@@ -716,21 +715,18 @@ callback_and_continue:
 
start_at:
 
		// 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.
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			if (GB(_m[tile].m5, 4, 4) == 0 &&
 
					GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
 
				/* This is a tunnel tile */
 
				/* We are not just driving out of the tunnel */
 
				if (GetTunnelDirection(tile) != direction ||
 
						GetTunnelTransportType(tile) != tpf->tracktype) {
 
					// 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
 
		if (IsTunnelTile(tile) &&
 
				GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
 
			/* We are not just driving out of the tunnel */
 
			if (GetTunnelDirection(tile) != direction ||
 
					GetTunnelTransportType(tile) != tpf->tracktype) {
 
				// 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
 
		}
 

	
 
		// This is a special loop used to go through
rail.c
Show inline comments
 
@@ -4,6 +4,7 @@
 
#include "openttd.h"
 
#include "rail.h"
 
#include "station.h"
 
#include "tunnel_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
 
@@ -123,8 +124,9 @@ RailType GetTileRailType(TileIndex tile,
 
				type = _m[tile].m3 & RAILTYPE_MASK;
 
			break;
 
		case MP_TUNNELBRIDGE:
 
			/* railway tunnel */
 
			if ((_m[tile].m5 & 0xFC) == 0) type = _m[tile].m3 & RAILTYPE_MASK;
 
			if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
				return _m[tile].m3 & RAILTYPE_MASK;
 
			}
 
			/* railway bridge ending */
 
			if ((_m[tile].m5 & 0xC6) == 0x80) type = _m[tile].m3 & RAILTYPE_MASK;
 
			/* on railway bridge */
rail_cmd.c
Show inline comments
 
@@ -1625,7 +1625,7 @@ static bool SignalVehicleCheck(TileIndex
 
	 * 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.
 
	 */
 
	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
 
		// because VehicleFromPos will not find the vihicle otherwise
 
		TileIndex end = GetOtherTunnelEnd(tile);
roadveh_cmd.c
Show inline comments
 
@@ -18,6 +18,7 @@
 
#include "player.h"
 
#include "sound.h"
 
#include "depot.h"
 
#include "tunnel_map.h"
 
#include "vehicle_gui.h"
 
#include "newgrf_engine.h"
 

	
 
@@ -1254,8 +1255,7 @@ static void RoadVehController(Vehicle *v
 
			return;
 
		}
 

	
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) &&
 
				GB(_m[gp.new_tile].m5, 4, 4) == 0 &&
 
		if (IsTunnelTile(gp.new_tile) &&
 
				VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) {
 
			//new_dir = RoadGetNewDirection(v, gp.x, gp.y)
 
			v->cur_image = GetRoadVehImage(v, v->direction);
smallmap_gui.c
Show inline comments
 
@@ -348,10 +348,10 @@ static inline TileType GetEffectiveTileT
 
	if (t == MP_TUNNELBRIDGE) {
 
		TransportType tt;
 

	
 
		if (_m[tile].m5 & 0x80) {
 
		if (IsTunnel(tile)) {
 
			tt = GetTunnelTransportType(tile);
 
		} else {
 
			tt = GB(_m[tile].m5, 1, 2);
 
		} else {
 
			tt = GetTunnelTransportType(tile);
 
		}
 
		switch (tt) {
 
			case TRANSPORT_RAIL: t = MP_RAILWAY; break;
tile.h
Show inline comments
 
@@ -79,10 +79,6 @@ static inline bool IsTileType(TileIndex 
 
	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)
 
{
town_cmd.c
Show inline comments
 
@@ -624,9 +624,7 @@ static void GrowTownInTile(TileIndex* ti
 
		int i;
 

	
 
		// Reached a tunnel? Then continue at the other side of it.
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) &&
 
				GB(_m[tile].m5, 4, 4) == 0 &&
 
				GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
 
		if (IsTunnelTile(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
 
			*tile_ptr = GetOtherTunnelEnd(tile);
 
			return;
 
		}
train_cmd.c
Show inline comments
 
@@ -2481,8 +2481,9 @@ static byte AfterSetTrainPos(Vehicle *v,
 
			TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
 

	
 
			// 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);
 
			}
 
		}
 
	}
 

	
tunnel_map.c
Show inline comments
 
@@ -15,8 +15,7 @@ TileIndex GetOtherTunnelEnd(TileIndex ti
 
	do {
 
		tile += delta;
 
	} while (
 
		!IsTileType(tile, MP_TUNNELBRIDGE) ||
 
		GB(_m[tile].m5, 4, 4) != 0 ||
 
		!IsTunnelTile(tile) ||
 
		GetTunnelDirection(tile) != dir ||
 
		GetTileZ(tile) != z
 
	);
 
@@ -37,8 +36,7 @@ static bool IsTunnelInWayDir(TileIndex t
 

	
 
	return
 
		z == height &&
 
		IsTileType(tile, MP_TUNNELBRIDGE) &&
 
		GB(_m[tile].m5, 4, 4) == 0 &&
 
		IsTunnelTile(tile) &&
 
		GetTunnelDirection(tile) == dir;
 
}
 

	
tunnel_map.h
Show inline comments
 
@@ -9,6 +9,18 @@
 
#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)
 
{
 
	return (DiagDirection)GB(_m[t].m5, 0, 2);
tunnelbridge_cmd.c
Show inline comments
 
@@ -525,8 +525,7 @@ TileIndex CheckTunnelBusy(TileIndex tile
 
		tile += delta;
 
		len++;
 
	} while (
 
		!IsTileType(tile, MP_TUNNELBRIDGE) ||
 
		GB(_m[tile].m5, 4, 4) != 0 ||
 
		!IsTunnelTile(tile) ||
 
		ReverseDiagDir(GetTunnelDirection(tile)) != dir ||
 
		GetTileZ(tile) != z
 
	);
 
@@ -742,7 +741,7 @@ static int32 ClearTile_TunnelBridge(Tile
 
{
 
	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);
 
		return DoClearTunnel(tile, flags);
 
	} else if (m5 & 0x80) {
 
@@ -759,8 +758,7 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
	uint length;
 
	Vehicle *v;
 

	
 
	if ((_m[tile].m5 & 0xFC) == 0x00) {
 
		// railway tunnel
 
	if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_RAIL) {
 
		if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
		if (GB(_m[tile].m3, 0, 4) == totype) return CMD_ERROR;
 
@@ -962,7 +960,7 @@ static void DrawTile_TunnelBridge(TileIn
 
	bool ice = _m[ti->tile].m4 & 0x80;
 

	
 
	// draw tunnel?
 
	if ((ti->map5 & 0xF0) == 0) {
 
	if (IsTunnel(ti->tile)) {
 
		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
 
			image = GetRailTypeInfo(GB(_m[ti->tile].m3, 0, 4))->base_sprites.tunnel;
 
		} else {
 
@@ -1229,7 +1227,7 @@ static const StringID _bridge_tile_str[(
 

	
 
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 
{
 
	if ((_m[tile].m5 & 0x80) == 0) {
 
	if (IsTunnel(tile)) {
 
		td->str = (GetTunnelTransportType(tile) == TRANSPORT_RAIL) ?
 
			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
 
	} else {
 
@@ -1291,8 +1289,7 @@ static uint32 GetTileTrackStatus_TunnelB
 
	uint32 result;
 
	byte m5 = _m[tile].m5;
 

	
 
	if ((m5 & 0xF0) == 0) {
 
		/* This is a tunnel */
 
	if (IsTunnel(tile)) {
 
		if (GetTunnelTransportType(tile) == mode) {
 
			return DiagDirToAxis(GetTunnelDirection(tile)) == AXIS_X ? 0x101 : 0x202;
 
		}
 
@@ -1371,7 +1368,7 @@ static const byte _tunnel_fractcoord_7[4
 

	
 
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;
 
		byte fc;
 
		DiagDirection dir;
 
@@ -1463,9 +1460,7 @@ TileIndex GetVehicleOutOfTunnelTile(cons
 
	byte z = v->z_pos;
 

	
 
	for (tile = v->tile;; tile += delta) {
 
		if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 &&
 
				GetTileZ(tile) == z)
 
			break;
 
		if (IsTunnelTile(tile) && GetTileZ(tile) == z) break;
 
	}
 
	return tile;
 
}
0 comments (0 inline, 0 general)