Changeset - r24100:c2d839fb3157
[Not reviewed]
master
0 1 0
Niels Martin Hansen - 4 years ago 2020-02-09 19:10:32
nielsm@indvikleren.dk
Codechange: Refactor road bridge catenary drawing
1 file changed with 28 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1102,12 +1102,38 @@ static void DrawBridgePillars(const PalS
 
		if (z_back_north < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][0]);
 
		if (z_back_south < z_back) DrawPillar(psid, x_back, y_back, bottom_z, w, h, &half_pillar_sub_sprite[axis][1]);
 
	}
 
}
 

	
 
/**
 
 * Retrieve the sprites required for catenary on a road/tram bridge.
 
 * @param rti              RoadTypeInfo for the road or tram type to get catenary for
 
 * @param head_tile        Bridge head tile with roadtype information
 
 * @param offset           Sprite offset identifying flat to sloped bridge tiles
 
 * @param head             Are we drawing bridge head?
 
 * @param[out] spr_back    Back catenary sprite to use
 
 * @param[out] spr_front   Front catenary sprite to use
 
 */
 
static void GetBridgeRoadCatenary(const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
 
{
 
	static const SpriteID back_offsets[6]  = { 95,  96,  99, 102, 100, 101 };
 
	static const SpriteID front_offsets[6] = { 97,  98, 103, 106, 104, 105 };
 

	
 
	/* Simplified from DrawRoadTypeCatenary() to remove all the special cases required for regular ground road */
 
	spr_back = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
	spr_front = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
	if (spr_back == 0 || spr_front == 0) {
 
		spr_back = SPR_TRAMWAY_BASE + back_offsets[offset];
 
		spr_front = SPR_TRAMWAY_BASE + front_offsets[offset];
 
	} else {
 
		spr_back += 23 + offset;
 
		spr_front += 23 + offset;
 
	}
 
}
 

	
 
/**
 
 * Draws the road and trambits over an already drawn (lower end) of a bridge.
 
 * @param head_tile    bridge head tile with roadtype information
 
 * @param x            the x of the bridge
 
 * @param y            the y of the bridge
 
 * @param z            the z of the bridge
 
 * @param offset       sprite offset identifying flat to sloped bridge tiles
 
@@ -1123,15 +1149,12 @@ static void DrawBridgeRoadBits(TileIndex
 
	SpriteID seq_back[4] = { 0 };
 
	bool trans_back[4] = { false };
 
	SpriteID seq_front[4] = { 0 };
 
	bool trans_front[4] = { false };
 

	
 
	static const SpriteID overlay_offsets[6] = {   0,   1,  11,  12,  13,  14 };
 
	static const SpriteID back_offsets[6]    = {  95,  96,  99, 102, 100, 101 };
 
	static const SpriteID front_offsets[6]   = {  97,  98, 103, 106, 104, 105 };
 

	
 
	if (head || !IsInvisibilitySet(TO_BRIDGES)) {
 
		/* Road underlay takes precedence over tram */
 
		trans_back[0] = !head && IsTransparencySet(TO_BRIDGES);
 
		if (road_rti != nullptr) {
 
			if (road_rti->UsesOverlay()) {
 
				seq_back[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
 
@@ -1165,31 +1188,15 @@ static void DrawBridgeRoadBits(TileIndex
 
		}
 

	
 
		/* Road catenary takes precedence over tram */
 
		trans_back[3] = IsTransparencySet(TO_CATENARY);
 
		trans_front[0] = IsTransparencySet(TO_CATENARY);
 
		if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
 
			seq_back[3] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
			seq_front[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
			if (seq_back[3] == 0 || seq_front[0] == 0) {
 
				seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
 
				seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
 
			} else {
 
				seq_back[3] += 23 + offset;
 
				seq_front[0] += 23 + offset;
 
			}
 
			GetBridgeRoadCatenary(road_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
 
		} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
 
			seq_back[3] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
			seq_front[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
 
			if (seq_back[3] == 0 || seq_front[0] == 0) {
 
				seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
 
				seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
 
			} else {
 
				seq_back[3] += 23 + offset;
 
				seq_front[0] += 23 + offset;
 
			}
 
			GetBridgeRoadCatenary(tram_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
 
		}
 
	}
 

	
 
	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 };
0 comments (0 inline, 0 general)