Changeset - r8390:ef5ec525d36d
[Not reviewed]
master
0 8 0
smatz - 17 years ago 2008-01-23 14:51:36
smatz@openttd.org
(svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
8 files changed with 23 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -2225,13 +2225,13 @@ static bool AiRemoveTileAndGoForward(Pla
 
		if (IsTunnel(tile)) {
 
			// Clear the tunnel and continue at the other side of it.
 
			if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
 
				return false;
 
			_players_ai[p->index].cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
 
			return true;
 
		} else {
 
		} else { // IsBridge(tile)
 
			// Check if the bridge points in the right direction.
 
			// This is not really needed the first place AiRemoveTileAndGoForward is called.
 
			if (DiagDirToAxis(GetTunnelBridgeDirection(tile)) != (_players_ai[p->index].cur_dir_a & 1)) return false;
 

	
 
			tile = GetOtherBridgeEnd(tile);
 

	
src/openttd.cpp
Show inline comments
 
@@ -1664,14 +1664,14 @@ bool AfterLoadGame()
 
				case MP_STATION:
 
					if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
 
					break;
 

	
 
				case MP_TUNNELBRIDGE:
 
					/* Middle part of "old" bridges */
 
					if (old_bridge && IsBridgeTile(t) && HasBit(_m[t].m5, 6)) break;
 
					if ((IsTunnel(t) ? GetTunnelBridgeTransportType(t) : (old_bridge ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t))) == TRANSPORT_ROAD) {
 
					if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
 
					if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
 
						SetRoadTypes(t, ROADTYPES_ROAD);
 
					}
 
					break;
 

	
 
				default: break;
 
			}
src/pathfind.cpp
Show inline comments
 
@@ -310,13 +310,13 @@ static void TPFMode1(TrackPathFinder* tp
 
				tile = SkipToEndOfTunnel(tpf, tile, direction);
 
			} else if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
 
				/* We don't support moving through the sides of a tunnel
 
				 * entrance :-) */
 
				return;
 
			}
 
		} else {
 
		} else { // IsBridge(tile)
 
			TileIndex tile_end;
 
			if (GetTunnelBridgeDirection(tile) != direction ||
 
					GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
 
				return;
 
			}
 
			//fprintf(stderr, "%s: Planning over bridge\n", __func__);
 
@@ -730,13 +730,13 @@ start_at:
 
					}
 
					flotr = FindLengthOfTunnel(tile, direction);
 
					si.cur_length += flotr.length * DIAG_FACTOR;
 
					tile = flotr.tile;
 
					/* tile now points to the exit tile of the tunnel */
 
				}
 
			} else {
 
			} else { // IsBridge(tile)
 
				TileIndex tile_end;
 
				if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
 
					/* We are not just leaving the bridge */
 
					if (GetTunnelBridgeDirection(tile) != direction ||
 
							GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
 
						/* Not entering the bridge or not compatible */
src/road_cmd.cpp
Show inline comments
 
@@ -129,16 +129,15 @@ CommandCost CmdRemoveRoad(TileIndex tile
 
		case MP_STATION:
 
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			{
 
				if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
				if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
 
			} break;
 
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
 
			break;
 

	
 
		default:
 
			return CMD_ERROR;
 
	}
 

	
 
	RoadBits pieces = Extract<RoadBits, 0>(p1);
 
@@ -495,24 +494,22 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
			return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
 
		}
 

	
 
		case MP_STATION:
 
			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
 
			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
 
			/* Don't allow "upgrading" the roadstop when vehicles are already driving on it */
 
			/* Don't allow adding roadtype to the roadstop when vehicles are already driving on it */
 
			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			{
 
				if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
				if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
 

	
 
				/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
 
				if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
 
			} break;
 
			if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
			if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
 
			/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
 
			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
 
			break;
 

	
 
		default:
 
do_clear:;
 
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			cost.AddCost(ret);
 
@@ -669,13 +666,13 @@ CommandCost CmdBuildLongRoad(TileIndex e
 
			if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
				if (IsBridge(tile)) {
 
					if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
 
						cost.AddCost(ret);
 
					}
 
					had_bridge = true;
 
				} else {
 
				} else { // IsTunnel(tile)
 
					if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
 
						cost.AddCost(ret);
 
					}
 
					had_tunnel = true;
 
				}
 
			} else {
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1517,13 +1517,13 @@ static bool IndividualRoadVehicleControl
 
			if (u != NULL) {
 
				v->cur_speed = u->First()->cur_speed;
 
				return false;
 
			}
 
		}
 

	
 
		if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			/* Vehicle has just entered a bridge or tunnel */
 
			v->cur_image = v->GetImage(v->direction);
 
			v->UpdateDeltaXY(v->direction);
 
			SetRoadVehPosition(v,gp.x,gp.y);
 
			return true;
 
		}
src/train_cmd.cpp
Show inline comments
 
@@ -3132,13 +3132,13 @@ static void TrainController(Vehicle *v, 
 
			 * - for bridges, only the middle part - without the bridge heads */
 
			if (!(v->vehstatus & VS_HIDDEN)) {
 
				v->cur_speed =
 
					min(v->cur_speed, GetBridge(GetBridgeType(v->tile))->speed);
 
			}
 

	
 
			if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
				v->x_pos = gp.x;
 
				v->y_pos = gp.y;
 
				VehiclePositionChanged(v);
 
				if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v);
 
				continue;
 
			}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -698,13 +698,13 @@ static CommandCost DoClearBridge(TileInd
 

	
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
{
 
	if (IsTunnel(tile)) {
 
		if (flags & DC_AUTO) return_cmd_error(STR_5006_MUST_DEMOLISH_TUNNEL_FIRST);
 
		return DoClearTunnel(tile, flags);
 
	} else if (IsBridge(tile)) { // XXX Is this necessary?
 
	} else { // IsBridge(tile)
 
		if (flags & DC_AUTO) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 
		return DoClearBridge(tile, flags);
 
	}
 

	
 
	return CMD_ERROR;
 
}
 
@@ -876,13 +876,13 @@ static void DrawTile_TunnelBridge(TileIn
 

	
 
		/* Add helper BB for sprite sorting, that separate the tunnel from things beside of it */
 
		AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x             , ti->y             , BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
 
		AddSortableSpriteToDraw(SPR_EMPTY_BOUNDING_BOX, PAL_NONE, ti->x + BB_data[4], ti->y + BB_data[5], BB_data[6], BB_data[7], TILE_HEIGHT, ti->z);
 

	
 
		DrawBridgeMiddle(ti);
 
	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
 
	} else { // IsBridge(ti->tile)
 
		const PalSpriteID *psid;
 
		int base_offset;
 
		bool ice = HasTunnelBridgeSnowOrDesert(ti->tile);
 

	
 
		if (GetTunnelBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
 
			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
 
@@ -940,14 +940,12 @@ static void DrawTile_TunnelBridge(TileIn
 
			EndSpriteCombine();
 
		} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
 
			DrawCatenary(ti);
 
		}
 

	
 
		DrawBridgeMiddle(ti);
 
	} else {
 
		NOT_REACHED();
 
	}
 
}
 

	
 

	
 
/** Compute bridge piece. Computes the bridge piece to display depending on the position inside the bridge.
 
 * bridges pieces sequence (middle parts)
 
@@ -1110,13 +1108,13 @@ static uint GetSlopeZ_TunnelBridge(TileI
 

	
 
	if (IsTunnel(tile)) {
 
		uint pos = (DiagDirToAxis(GetTunnelBridgeDirection(tile)) == AXIS_X ? y : x);
 

	
 
		/* In the tunnel entrance? */
 
		if (5 <= pos && pos <= 10) return z;
 
	} else {
 
	} else { // IsBridge(tile)
 
		DiagDirection dir = GetTunnelBridgeDirection(tile);
 
		uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
 

	
 
		z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
 

	
 
		/* On the bridge ramp? */
 
@@ -1184,13 +1182,13 @@ static const StringID _bridge_tile_str[(
 

	
 
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 
{
 
	if (IsTunnel(tile)) {
 
		td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
 
			STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
 
	} else {
 
	} else { // IsBridge(tile)
 
		td->str = _bridge_tile_str[GetTunnelBridgeTransportType(tile) << 4 | GetBridgeType(tile)];
 
	}
 
	td->owner = GetTileOwner(tile);
 
}
 

	
 

	
 
@@ -1338,13 +1336,13 @@ static VehicleEnterTileStatus VehicleEnt
 
				v->u.road.state = _road_exit_tunnel_state[dir];
 
				v->u.road.frame = _road_exit_tunnel_frame[dir];
 
				v->vehstatus &= ~VS_HIDDEN;
 
				return VETSB_ENTERED_WORMHOLE;
 
			}
 
		}
 
	} else if (IsBridge(tile)) { // XXX is this necessary?
 
	} else { // IsBridge(tile)
 
		DiagDirection dir;
 

	
 
		if (v->IsPrimaryVehicle()) {
 
			/* modify speed of vehicle */
 
			uint16 spd = _bridge[GetBridgeType(tile)].speed;
 

	
src/yapf/follow_track.hpp
Show inline comments
 
@@ -211,13 +211,13 @@ protected:
 
					DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
 
					if (tunnel_enterdir != m_exitdir) {
 
						m_err = EC_NO_WAY;
 
						return false;
 
					}
 
				}
 
			} else if (IsBridge(m_new_tile)) {
 
			} else { // IsBridge(m_new_tile)
 
				if (!m_is_bridge) {
 
					DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
 
					if (ramp_enderdir != m_exitdir) {
 
						m_err = EC_NO_WAY;
 
						return false;
 
					}
0 comments (0 inline, 0 general)