Changeset - r8398:cf5cc32ab397
[Not reviewed]
master
0 18 1
smatz - 16 years ago 2008-01-23 22:34:04
smatz@openttd.org
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
19 files changed with 90 insertions and 98 deletions:
0 comments (0 inline, 0 general)
projects/openttd.vcproj
Show inline comments
 
@@ -709,6 +709,9 @@
 
				RelativePath=".\..\src\transparency_gui.h">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\tunnelbridge.h">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\variables.h">
 
			</File>
 
			<File
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -1176,6 +1176,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\tunnelbridge.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\variables.h"
 
				>
 
			</File>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -1173,6 +1173,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\tunnelbridge.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\variables.h"
 
				>
 
			</File>
source.list
Show inline comments
 
@@ -202,6 +202,7 @@ town.h
 
train.h
 
transparency.h
 
transparency_gui.h
 
tunnelbridge.h
 
variables.h
 
vehicle.h
 
vehicle_gui.h
src/ai/default/default.cpp
Show inline comments
 
@@ -31,6 +31,7 @@
 
#include "../../player_base.h"
 
#include "../../settings_type.h"
 
#include "default.h"
 
#include "../../tunnelbridge.h"
 

	
 
#include "../../table/ai_rail.h"
 

	
 
@@ -2173,7 +2174,7 @@ static void AiBuildRailConstruct(Player 
 

	
 
	if (arf.best_ptr[0] & 0x80) {
 
		int i;
 
		int32 bridge_len = GetBridgeLength(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a);
 
		int32 bridge_len = GetTunnelBridgeLength(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a);
 

	
 
		/* Figure out which (rail)bridge type to build
 
		 * start with best bridge, then go down to worse and worse bridges
 
@@ -3065,7 +3066,7 @@ do_some_terraform:
 
		int i;
 
		int32 bridge_len;
 
		_players_ai[p->index].cur_tile_a = arf.bridge_end_tile;
 
		bridge_len = GetBridgeLength(tile, _players_ai[p->index].cur_tile_a); // tile
 
		bridge_len = GetTunnelBridgeLength(tile, _players_ai[p->index].cur_tile_a); // tile
 

	
 
		/* Figure out what (road)bridge type to build
 
		 * start with best bridge, then go down to worse and worse bridges
src/ai/trolly/build.cpp
Show inline comments
 
@@ -15,6 +15,8 @@
 
#include "../../player_base.h"
 
#include "../../player_func.h"
 
#include "../ai.h"
 
#include "../../tunnelbridge.h"
 

	
 

	
 
// Build HQ
 
//  Params:
 
@@ -58,7 +60,7 @@ CommandCost AiNew_Build_Bridge(Player *p
 
	int bridge_type, bridge_len, type, type2;
 

	
 
	// Find a good bridgetype (the best money can buy)
 
	bridge_len = GetBridgeLength(tile_a, tile_b);
 
	bridge_len = GetTunnelBridgeLength(tile_a, tile_b);
 
	type = type2 = 0;
 
	for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) {
 
		if (CheckBridge_Stuff(bridge_type, bridge_len)) {
src/ai/trolly/pathfinder.cpp
Show inline comments
 
@@ -14,6 +14,7 @@
 
#include "../../variables.h"
 
#include "../../player_base.h"
 
#include "../../player_func.h"
 
#include "../../tunnelbridge.h"
 

	
 

	
 
#define TEST_STATION_NO_DIR 0xFF
 
@@ -320,7 +321,7 @@ static void AyStar_AiPathFinder_GetNeigh
 
				new_tile += TileOffsByDiagDir(dir);
 

	
 
				// Precheck, is the length allowed?
 
				if (!CheckBridge_Stuff(0, GetBridgeLength(tile, new_tile))) break;
 
				if (!CheckBridge_Stuff(0, GetTunnelBridgeLength(tile, new_tile))) break;
 

	
 
				// Check if we hit the station-tile.. we don't like that!
 
				if (TILES_BETWEEN(new_tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) break;
 
@@ -425,14 +426,14 @@ static int32 AyStar_AiPathFinder_Calcula
 
		int r;
 
		// Tunnels are very expensive when build on long routes..
 
		// Ironicly, we are using BridgeCode here ;)
 
		r = AI_PATHFINDER_TUNNEL_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
 
		r = AI_PATHFINDER_TUNNEL_PENALTY * GetTunnelBridgeLength(current->tile, parent->path.node.tile);
 
		res += r + (r >> 8);
 
	}
 

	
 
	// Are we part of a bridge?
 
	if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) {
 
		// That means for every length a penalty
 
		res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
 
		res += AI_PATHFINDER_BRIDGE_PENALTY * GetTunnelBridgeLength(current->tile, parent->path.node.tile);
 
		// Check if we are going up or down, first for the starting point
 
		// In user_data[0] is at the 8th bit the direction
 
		if (!HasBridgeFlatRamp(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1))) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
src/bridge.h
Show inline comments
 
@@ -43,7 +43,6 @@ static inline const Bridge *GetBridge(ui
 
void DrawBridgeMiddle(const TileInfo *ti);
 

	
 
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
 
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
 
int CalcBridgeLenCostFactor(int x);
 

	
 
#endif /* BRIDGE_H */
src/bridge_gui.cpp
Show inline comments
 
@@ -16,6 +16,7 @@
 
#include "map_func.h"
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "tunnelbridge.h"
 

	
 
#include "table/strings.h"
 

	
 
@@ -182,7 +183,7 @@ void ShowBuildBridgeWindow(TileIndex sta
 
		/* check which bridges can be built
 
		 * get absolute bridge length
 
		 * length of the middle parts of the bridge */
 
		const uint bridge_len = GetBridgeLength(start, end);
 
		const uint bridge_len = GetTunnelBridgeLength(start, end);
 
		/* total length of bridge */
 
		const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
 

	
src/elrail.cpp
Show inline comments
 
@@ -64,6 +64,7 @@
 
#include "tunnelbridge_map.h"
 
#include "vehicle_func.h"
 
#include "player_base.h"
 
#include "tunnelbridge.h"
 

	
 
#include "table/sprites.h"
 
#include "table/elrail_data.h"
 
@@ -383,8 +384,8 @@ static void DrawCatenaryOnBridge(const T
 
	TileIndex end = GetSouthernBridgeEnd(ti->tile);
 
	TileIndex start = GetOtherBridgeEnd(end);
 

	
 
	uint length = GetBridgeLength(start, end);
 
	uint num = DistanceMax(ti->tile, start);
 
	uint length = GetTunnelBridgeLength(start, end);
 
	uint num = GetTunnelBridgeLength(ti->tile, start) + 1;
 
	uint height;
 

	
 
	const SortableSpriteStruct *sss;
 
@@ -421,7 +422,7 @@ static void DrawCatenaryOnBridge(const T
 
	}
 

	
 
	/* need a pylon on the southern end of the bridge */
 
	if (DistanceMax(ti->tile, start) == length) {
 
	if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
 
		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
 
		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
 
		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
src/npf.cpp
Show inline comments
 
@@ -22,6 +22,7 @@
 
#include "functions.h"
 
#include "vehicle_base.h"
 
#include "settings_type.h"
 
#include "tunnelbridge.h"
 

	
 
static AyStar _npf_aystar;
 

	
 
@@ -176,9 +177,7 @@ static uint NPFTunnelCost(AyStarNode* cu
 
	if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(exitdir)) {
 
		/* We just popped out if this tunnel, since were
 
		 * facing the tunnel exit */
 
		FindLengthOfTunnelResult flotr;
 
		flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
 
		return flotr.length * NPF_TILE_LENGTH;
 
		return NPF_TILE_LENGTH * (GetTunnelBridgeLength(current->tile, GetOtherTunnelEnd(current->tile)) + 1);
 
		/* @todo: Penalty for tunnels? */
 
	} else {
 
		/* We are entering the tunnel, the enter tile is just a
 
@@ -189,7 +188,7 @@ static uint NPFTunnelCost(AyStarNode* cu
 

	
 
static inline uint NPFBridgeCost(AyStarNode *current)
 
{
 
	return NPF_TILE_LENGTH * GetBridgeLength(current->tile, GetOtherBridgeEnd(current->tile));
 
	return NPF_TILE_LENGTH * GetTunnelBridgeLength(current->tile, GetOtherBridgeEnd(current->tile));
 
}
 

	
 
static uint NPFSlopeCost(AyStarNode* current)
src/pathfind.cpp
Show inline comments
 
@@ -17,6 +17,7 @@
 
#include "depot.h"
 
#include "tunnelbridge_map.h"
 
#include "core/random_func.hpp"
 
#include "tunnelbridge.h"
 

	
 
/* remember which tiles we have already visited so we don't visit them again. */
 
static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir)
 
@@ -192,32 +193,6 @@ continue_here:
 

	
 
}
 

	
 

	
 
/* Returns the end tile and the length of a tunnel. The length does not
 
 * include the starting tile (entry), it does include the end tile (exit).
 
 */
 
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
 
{
 
	TileIndexDiff delta = TileOffsByDiagDir(dir);
 
	uint z = GetTileZ(tile);
 
	FindLengthOfTunnelResult flotr;
 

	
 
	flotr.length = 0;
 

	
 
	dir = ReverseDiagDir(dir);
 
	do {
 
		flotr.length++;
 
		tile += delta;
 
	} while(
 
		!IsTunnelTile(tile) ||
 
		GetTunnelBridgeDirection(tile) != dir ||
 
		GetTileZ(tile) != z
 
	);
 

	
 
	flotr.tile = tile;
 
	return flotr;
 
}
 

	
 
/**
 
 * Checks if any vehicle can enter/leave tile in given diagdir
 
 * Checks only for rail/road depots and road non-drivethrough stations
 
@@ -257,7 +232,7 @@ static void TPFMode1(TrackPathFinder* tp
 
		if (dir == direction) {
 
			TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
 

	
 
			tpf->rd.cur_length += DistanceManhattan(tile, endtile);
 
			tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1;
 

	
 
			TPFSetTileBit(tpf, tile, 14);
 
			TPFSetTileBit(tpf, endtile, 14);
 
@@ -665,8 +640,6 @@ start_at:
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			if (IsTunnel(tile)) {
 
				if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) {
 
					FindLengthOfTunnelResult flotr;
 

	
 
					/* We are not just driving out of the tunnel */
 
					if (GetTunnelBridgeDirection(tile) != direction ||
 
							GetTunnelBridgeTransportType(tile) != tpf->tracktype) {
 
@@ -677,9 +650,10 @@ start_at:
 
						bits = TRACK_BIT_NONE;
 
						break;
 
					}
 
					flotr = FindLengthOfTunnel(tile, direction);
 
					si.cur_length += flotr.length * DIAG_FACTOR;
 
					tile = flotr.tile;
 

	
 
					TileIndex endtile = GetOtherTunnelEnd(tile);
 
					si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1);
 
					tile = endtile;
 
					/* tile now points to the exit tile of the tunnel */
 
				}
 
			} else { // IsBridge(tile)
 
@@ -693,7 +667,7 @@ start_at:
 
					}
 
				}
 
				tile_end = GetOtherBridgeEnd(tile);
 
				si.cur_length += DistanceManhattan(tile, tile_end) * DIAG_FACTOR;
 
				si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, tile_end) + 1);
 
				tile = tile_end;
 
			}
 
		}
src/pathfind.h
Show inline comments
 
@@ -68,13 +68,6 @@ struct TrackPathFinder {
 
};
 

	
 
void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data);
 

	
 
struct FindLengthOfTunnelResult {
 
	TileIndex tile;
 
	int length;
 
};
 
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direction);
 

	
 
void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data);
 

	
 
#endif /* PATHFIND_H */
src/rail_cmd.cpp
Show inline comments
 
@@ -40,6 +40,7 @@
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "signal_func.h"
 
#include "tunnelbridge.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
@@ -939,7 +940,7 @@ static bool CheckSignalAutoFill(TileInde
 
			 * note that tile is a parameter by reference, so it must be updated */
 
			tile = GetOtherTunnelBridgeEnd(tile);
 

	
 
			signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
 
			signal_ctr += (GetTunnelBridgeLength(orig_tile, tile) + 2) * 2;
 
			return true;
 
		}
 

	
 
@@ -1294,7 +1295,7 @@ CommandCost CmdConvertRail(TileIndex til
 
						}
 
					}
 

	
 
					cost.AddCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(type, totype));
 
					cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));
 
				} break;
 

	
 
				default: // MP_STATION, MP_ROAD
src/road_cmd.cpp
Show inline comments
 
@@ -33,6 +33,7 @@
 
#include "vehicle_base.h"
 
#include "sound_func.h"
 
#include "road_func.h"
 
#include "tunnelbridge.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
@@ -159,7 +160,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
 
		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
			TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
 
			/* Pay for *every* tile of the bridge or tunnel */
 
			cost.AddCost((DistanceManhattan(other_end, tile) + 1) * _price.remove_road);
 
			cost.AddCost((GetTunnelBridgeLength(other_end, tile) + 2) * _price.remove_road);
 
			if (flags & DC_EXEC) {
 
				SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
 
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
 
@@ -551,7 +552,7 @@ do_clear:;
 
	cost.AddCost(CountBits(pieces) * _price.build_road);
 
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		/* Pay for *every* tile of the bridge or tunnel */
 
		cost.MultiplyCost(DistanceManhattan(GetOtherTunnelBridgeEnd(tile), tile) + 1);
 
		cost.MultiplyCost(GetTunnelBridgeLength(GetOtherTunnelBridgeEnd(tile), tile) + 2);
 
	}
 

	
 
	if (flags & DC_EXEC) {
src/tunnelbridge.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file tunnelbridge.h Header file for things common for tunnels and bridges */
 

	
 
#ifndef TUNNELBRIDGE_H
 
#define TUNNELBRIDGE_H
 

	
 
#include "tile_type.h"
 
#include "map_func.h"
 
#include "tunnelbridge_map.h"
 

	
 
/**
 
 * Calculates the length of a tunnel or a bridge (without end tiles)
 
 * @return length of bridge/tunnel middle
 
 */
 
static inline uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
 
{
 
	int x1 = TileX(begin);
 
	int y1 = TileY(begin);
 
	int x2 = TileX(end);
 
	int y2 = TileY(end);
 

	
 
	return abs(x2 + y2 - x1 - y1) - 1;
 
}
 

	
 
#endif /* TUNNELBRIDGE_H */
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -32,6 +32,7 @@
 
#include "vehicle_func.h"
 
#include "sound_func.h"
 
#include "signal_func.h"
 
#include "tunnelbridge.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
@@ -160,17 +161,6 @@ static CommandCost CheckBridgeSlopeSouth
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
}
 

	
 

	
 
uint32 GetBridgeLength(TileIndex begin, TileIndex end)
 
{
 
	int x1 = TileX(begin);
 
	int y1 = TileY(begin);
 
	int x2 = TileX(end);
 
	int y2 = TileY(end);
 

	
 
	return abs(x2 + y2 - x1 - y1) - 1;
 
}
 

	
 
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
 
{
 
	const Bridge *b = &_bridge[bridge_type];
 
@@ -633,7 +623,7 @@ static CommandCost DoClearTunnel(TileInd
 
			DoClearSquare(endtile);
 
		}
 
	}
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (DistanceManhattan(tile, endtile) + 1));
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_tunnel * (GetTunnelBridgeLength(tile, endtile) + 2));
 
}
 

	
 

	
 
@@ -693,7 +683,7 @@ static CommandCost DoClearBridge(TileInd
 
		}
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, (DistanceManhattan(tile, endtile) + 1) * _price.clear_bridge);
 
	return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * _price.clear_bridge);
 
}
 

	
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, byte flags)
 
@@ -1018,8 +1008,8 @@ void DrawBridgeMiddle(const TileInfo* ti
 

	
 
	axis = GetBridgeAxis(ti->tile);
 
	piece = CalcBridgePiece(
 
		DistanceManhattan(ti->tile, rampnorth),
 
		DistanceManhattan(ti->tile, rampsouth)
 
		GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
 
		GetTunnelBridgeLength(ti->tile, rampsouth) + 1
 
	);
 
	type = GetBridgeType(rampsouth);
 

	
src/yapf/follow_track.hpp
Show inline comments
 
@@ -76,32 +76,22 @@ protected:
 
		m_is_station = m_is_bridge = m_is_tunnel = false;
 
		m_tiles_skipped = 0;
 

	
 
		// extra handling for tunnels in our direction
 
		if (IsTunnelTile(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);
 
				m_new_tile = flotr.tile;
 
				m_is_tunnel = true;
 
				m_tiles_skipped = flotr.length - 1;
 
		// extra handling for tunnels and bridges in our direction
 
		if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
 
			DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
 
			if (enterdir == m_exitdir) {
 
				// we are entering the tunnel / bridge
 
				if (IsTunnel(m_old_tile)) {
 
					m_is_tunnel = true;
 
					m_new_tile = GetOtherTunnelEnd(m_old_tile);
 
				} else { // IsBridge(m_old_tile)
 
					m_is_bridge = true;
 
					m_new_tile = GetOtherBridgeEnd(m_old_tile);
 
				}
 
				m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
 
				return;
 
			}
 
			assert(ReverseDiagDir(tunnel_enterdir) == m_exitdir);
 
		}
 

	
 
		// extra handling for bridge ramp in our direction
 
		if (IsBridgeTile(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);
 
				uint32 bridge_length = GetBridgeLength(m_old_tile, m_new_tile);
 
				m_tiles_skipped = bridge_length;
 
				m_is_bridge = true;
 
				return;
 
			}
 
			assert(ReverseDiagDir(bridge_enterdir) == m_exitdir);
 
			assert(ReverseDiagDir(enterdir) == m_exitdir);
 
		}
 

	
 
		// normal or station tile, do one step
src/yapf/yapf.hpp
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include "../waypoint.h"
 
#include "../debug.h"
 
#include "../settings_type.h"
 
#include "../tunnelbridge.h"
 

	
 
extern uint64 _rdtsc();
 

	
0 comments (0 inline, 0 general)