Changeset - r16234:63c5973c2988
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-10-16 15:36:13
frosch@openttd.org
(svn r20945) -Codechange: Add helper function to draw single pillar sprites. (based on patch by uni657)
1 file changed with 17 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -816,40 +816,54 @@ static CommandCost DoClearBridge(TileInd
 
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (IsTunnel(tile)) {
 
		if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST);
 
		return DoClearTunnel(tile, flags);
 
	} else { // IsBridge(tile)
 
		if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
		return DoClearBridge(tile, flags);
 
	}
 
}
 

	
 
/**
 
 * Draw a single pillar sprite.
 
 * @param psid      Pillarsprite
 
 * @param x         Pillar X
 
 * @param y         Pillar Y
 
 * @param z         Pillar Z
 
 * @param w         Bounding box size in X direction
 
 * @param h         Bounding box size in Y direction
 
 */
 
static inline void DrawPillar(const PalSpriteID *psid, int x, int y, int z, int w, int h)
 
{
 
	static const int PILLAR_Z_OFFSET = TILE_HEIGHT - BRIDGE_Z_START; ///< Start offset of pillar wrt. bridge (downwards)
 
	AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, w, h, BB_HEIGHT_UNDER_BRIDGE - PILLAR_Z_OFFSET, z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET);
 
}
 

	
 
/**
 
 * Draws the pillars under high bridges.
 
 *
 
 * @param psid Image and palette of a bridge pillar.
 
 * @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) return;
 

	
 
	/* "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
 
@@ -868,30 +882,30 @@ static void DrawBridgePillars(const PalS
 
	GetSlopeZOnEdge(ti->tileh, dir, &front_height, &back_height);
 

	
 
	/* x and y size of bounding-box of pillars */
 
	int w = bounding_box_size[axis];
 
	int h = bounding_box_size[OtherAxis(axis)];
 
	/* sprite position of back facing pillar */
 
	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 - PILLAR_Z_OFFSET, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET);
 
			DrawPillar(psid, x, y, cur_z, w, h);
 
		}
 

	
 
		/* 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 - PILLAR_Z_OFFSET, cur_z, IsTransparencySet(TO_BRIDGES), 0, 0, -PILLAR_Z_OFFSET);
 
			DrawPillar(psid, x_back, y_back, cur_z, w, h);
 
		}
 
	}
 
}
 

	
 
/**
 
 * 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?
 
 * @param head    are we drawing bridge head?
0 comments (0 inline, 0 general)