Changeset - r16232:444131f10b0a
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-10-16 15:34:59
frosch@openttd.org
(svn r20943) -Codechange: Name some magic constants. (Based on patch by uni657)
1 file changed with 13 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -37,24 +37,27 @@
 
#include "elrail_func.h"
 
#include "pbs.h"
 
#include "company_base.h"
 
#include "newgrf_railtype.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "table/bridge_land.h"
 

	
 
BridgeSpec _bridge[MAX_BRIDGES];
 
TileIndex _build_tunnel_endtile;
 

	
 
/* Z position of the bridge sprites relative to bridge height (downwards) */
 
static const int BRIDGE_Z_START = 3;
 

	
 
/** Reset the data been eventually changed by the grf loaded. */
 
void ResetBridges()
 
{
 
	/* First, free sprite table data */
 
	for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
 
		if (_bridge[i].sprite_table != NULL) {
 
			for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
 
			free(_bridge[i].sprite_table);
 
		}
 
	}
 

	
 
	/* Then, wipe out current bidges */
 
@@ -828,63 +831,67 @@ static CommandCost ClearTile_TunnelBridg
 
 * @param ti #TileInfo of current bridge-middle-tile.
 
 * @param axis Orientation of bridge.
 
 * @param drawfarpillar Whether to draw the pillar at the back
 
 * @param x Sprite X position of front pillar.
 
 * @param y Sprite Y position of front pillar.
 
 * @param z_bridge Absolute height of bridge bottom.
 
 */
 
static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
 
{
 
	/* Do not draw bridge pillars if they are invisible */
 
	if (IsInvisibilitySet(TO_BRIDGES)) return;
 

	
 
	static const int PILLAR_Z_OFFSET = TILE_HEIGHT - BRIDGE_Z_START; ///< Start offset of pillar wrt. bridge (downwards)
 
	static const int bounding_box_size[2]  = {16, 2}; ///< bounding box size of pillars along bridge direction
 
	static const int back_pillar_offset[2] = { 0, 9}; ///< sprite position offset of back facing pillar
 

	
 
	SpriteID image = psid->sprite;
 

	
 
	if (image != 0) {
 
		/* "side" specifies the side the pillars stand on.
 
		 * The length of the pillars is then set to the height of the bridge over the corners of this edge.
 
		 *
 
		 *                axis==AXIS_X  axis==AXIS_Y
 
		 *   side==false      SW            NW
 
		 *   side==true       NE            SE
 
		 *
 
		 * I have no clue, why this was done this way.
 
		 */
 
		bool side = HasBit(image, 0);
 

	
 
		/* "dir" means the edge the pillars stand on */
 
		DiagDirection dir = AxisToDiagDir(axis);
 
		if (side != (axis == AXIS_Y)) dir = ReverseDiagDir(dir);
 

	
 
		/* Determine ground height under pillars */
 
		int front_height = ti->z;
 
		int back_height = ti->z;
 
		GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height);
 

	
 
		/* x and y size of bounding-box of pillars */
 
		int w = (axis == AXIS_X ? 16 : 2);
 
		int h = (axis == AXIS_X ? 2 : 16);
 
		int w = bounding_box_size[axis];
 
		int h = bounding_box_size[OtherAxis(axis)];
 
		/* sprite position of back facing pillar */
 
		int x_back = x - (axis == AXIS_X ? 0 : 9);
 
		int y_back = y - (axis == AXIS_X ? 9 : 0);
 
		int x_back = x - back_pillar_offset[axis];
 
		int y_back = y - back_pillar_offset[OtherAxis(axis)];
 

	
 
		for (int cur_z = z_bridge; cur_z >= front_height || cur_z >= back_height; cur_z -= TILE_HEIGHT) {
 
			/* Draw front facing pillar */
 
			if (cur_z >= front_height) {
 
				AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
 
				AddSortableSpriteToDraw(image, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET);
 
			}
 

	
 
			/* Draw back facing pillar, but not the highest part directly under the bridge-floor */
 
			if (drawfarpillar && cur_z >= back_height && cur_z < z_bridge - (int)TILE_HEIGHT) {
 
				AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - 5, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -5);
 
				AddSortableSpriteToDraw(image, psid->pal, x_back, y_back, w, h, BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Draws the trambits over an already drawn (lower end) of a bridge.
 
 * @param x       the x of the bridge
 
 * @param y       the y of the bridge
 
 * @param z       the z of the bridge
 
 * @param offset  number representing whether to level or sloped and the direction
 
 * @param overlay do we want to still see the road?
 
@@ -1165,27 +1172,24 @@ void DrawBridgeMiddle(const TileInfo *ti
 
	 *  1     7     2                                4,5 = pillars under higher bridges
 
	 *  1 6 88888 6 2                                  6 = elrail-pylons
 
	 *  1 6 88888 6 2                                  7 = elrail-wire
 
	 *  1 6 88888 6 2  <- TILE_HEIGHT                  8 = rail-vehicle on bridge
 
	 *  3333333333333  <- BB_Z_SEPARATOR
 
	 *                 <- unused
 
	 *    4       5    <- BB_HEIGHT_UNDER_BRIDGE
 
	 *    4       5
 
	 *    4       5
 
	 *
 
	 */
 

	
 
	/* Z position of the bridge sprites relative to bridge height (downwards) */
 
	static const int BRIDGE_Z_START = 3;
 

	
 
	if (!IsBridgeAbove(ti->tile)) return;
 

	
 
	TileIndex rampnorth = GetNorthernBridgeEnd(ti->tile);
 
	TileIndex rampsouth = GetSouthernBridgeEnd(ti->tile);
 
	TransportType transport_type = GetTunnelBridgeTransportType(rampsouth);
 

	
 
	Axis axis = GetBridgeAxis(ti->tile);
 
	BridgePieces piece = CalcBridgePiece(
 
		GetTunnelBridgeLength(ti->tile, rampnorth) + 1,
 
		GetTunnelBridgeLength(ti->tile, rampsouth) + 1
 
	);
 

	
0 comments (0 inline, 0 general)