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
 
@@ -804,106 +804,120 @@ static CommandCost DoClearBridge(TileInd
 
		}
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, (GetTunnelBridgeLength(tile, endtile) + 2) * base_cost);
 
}
 

	
 
/**
 
 * Remove a tunnel or a bridge from the game.
 
 * @param tile Tile containing one of the endpoints.
 
 * @param flags Command flags.
 
 * @return Succeeded or failed command.
 
 */
 
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
 
	 *
 
	 * 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 = 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?
 
 */
 
static void DrawBridgeTramBits(int x, int y, byte z, int offset, bool overlay, bool head)
 
{
 
	static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
 
	static const SpriteID back_offsets[6]    =   {  95,  96,  99, 102, 100, 101 };
 
	static const SpriteID front_offsets[6]   =   {  97,  98, 103, 106, 104, 105 };
 

	
 
	static const uint size_x[6] = {  1, 16, 16,  1, 16,  1 };
 
	static const uint size_y[6] = { 16,  1,  1, 16,  1, 16 };
 
	static const uint front_bb_offset_x[6] = { 15,  0,  0, 15,  0, 15 };
 
	static const uint front_bb_offset_y[6] = {  0, 15, 15,  0, 15,  0 };
 

	
0 comments (0 inline, 0 general)