src/tunnelbridge_cmd.cpp
branchnoai
changeset 9694 e72987579514
parent 9686 d3c195c226f9
child 9701 d1ac22c62f64
--- a/src/tunnelbridge_cmd.cpp	Fri Aug 03 19:16:36 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Fri Aug 03 22:09:42 2007 +0000
@@ -388,7 +388,7 @@
 				if (!IsPlainRailTile(tile)) goto not_valid_below;
 				break;
 
-			case MP_STREET:
+			case MP_ROAD:
 				if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) goto not_valid_below;
 				break;
 
@@ -504,6 +504,8 @@
 	int tiles_coef = 3;
 	/** Number of tiles from start of tunnel */
 	int tiles = 0;
+	/** Number of tiles at which the cost increase coefficient per tile is halved */
+	int tiles_bump = 25;
 
 	for (;;) {
 		end_tile += delta;
@@ -516,7 +518,10 @@
 		}
 
 		tiles++;
-		if (tiles == 25 || tiles == 50 || tiles == 100 || tiles == 200 || tiles == 400 || tiles == 800) tiles_coef++;
+		if (tiles == tiles_bump) {
+			tiles_coef++;
+			tiles_bump *= 2;
+		}
 
 		cost.AddCost(_price.build_tunnel);
 		cost.AddCost(cost.GetCost() >> tiles_coef); // add a multiplier for longer tunnels
@@ -825,7 +830,6 @@
 		int back_height, front_height;
 		int i = z;
 		const byte *p;
-		SpriteID pal;
 
 		static const byte _tileh_bits[4][8] = {
 			{ 2, 1, 8, 4,  16,  2, 0, 9 },
@@ -834,13 +838,6 @@
 			{ 2, 4, 8, 1,   2, 16, 9, 0 }
 		};
 
-		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = psid->pal;
-		}
-
 		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
 		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
 		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
@@ -855,36 +852,21 @@
 			 * sprites is at the top
 			 */
 			if (z >= front_height) { // front facing pillar
-				AddSortableSpriteToDraw(image, pal, x, y, p[4], p[5], 1, z);
+				AddSortableSpriteToDraw(image, psid->pal, x, y, p[4], p[5], 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 			}
 
 			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
-				AddSortableSpriteToDraw(image, pal, x - p[6], y - p[7], p[4], p[5], 1, z);
+				AddSortableSpriteToDraw(image, psid->pal, x - p[6], y - p[7], p[4], p[5], 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 			}
 		}
 	}
 }
 
-uint GetBridgeFoundation(Slope tileh, Axis axis)
+Foundation GetBridgeFoundation(Slope tileh, Axis axis)
 {
-	uint i;
-
-	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return tileh;
-
-	/* inclined sloped building */
-	switch (tileh) {
-		case SLOPE_W:
-		case SLOPE_STEEP_W: i = 0; break;
-		case SLOPE_S:
-		case SLOPE_STEEP_S: i = 2; break;
-		case SLOPE_E:
-		case SLOPE_STEEP_E: i = 4; break;
-		case SLOPE_N:
-		case SLOPE_STEEP_N: i = 6; break;
-		default: return 0;
-	}
-	if (axis != AXIS_X) ++i;
-	return i + 15;
+	if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) return FOUNDATION_NONE;
+	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) return FlatteningFoundation(tileh);
+	return InclinedFoundation(axis);
 }
 
 /**
@@ -904,20 +886,11 @@
 	static const uint size_x[6] = { 11, 16, 16, 16, 16, 16 };
 	static const uint size_y[6] = { 16, 11, 16, 16, 16, 16 };
 
-	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 1 : 0, z);
+	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 1 : 0, z, HASBIT(_transparent_opt, TO_BRIDGES));
 
-	SpriteID front = SPR_TRAMWAY_BASE + front_offsets[offset];
-	SpriteID back  = SPR_TRAMWAY_BASE + back_offsets[offset];
-	SpriteID pal   = PAL_NONE;
-	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
-		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
-		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	}
-
-	AddSortableSpriteToDraw(back,  pal, x, y, size_x[offset], size_y[offset], 0, z);
+	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset],  PAL_NONE, x, y, size_x[offset], size_y[offset], 0, z, HASBIT(_transparent_opt, TO_BUILDINGS));
 	/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
-	AddSortableSpriteToDraw(front, pal, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z);
+	AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], offset >= 2 ? 0x30 : 0x10, z, HASBIT(_transparent_opt, TO_BUILDINGS));
 }
 
 /**
@@ -936,7 +909,6 @@
 static void DrawTile_TunnelBridge(TileInfo *ti)
 {
 	SpriteID image;
-	SpriteID pal;
 
 	if (IsTunnel(ti->tile)) {
 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
@@ -980,10 +952,7 @@
 		/* as the lower 3 bits are used for other stuff, make sure they are clear */
 		assert( (base_offset & 0x07) == 0x00);
 
-		if (!HASBIT(BRIDGE_NO_FOUNDATION, ti->tileh)) {
-			int f = GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile)));
-			if (f != 0) DrawFoundation(ti, f);
-		}
+		DrawFoundation(ti, GetBridgeFoundation(ti->tileh, DiagDirToAxis(GetBridgeRampDirection(ti->tile))));
 
 		/* HACK Wizardry to convert the bridge ramp direction into a sprite offset */
 		base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
@@ -999,21 +968,13 @@
 			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
 		}
 
-		image = psid->sprite;
-
 		/* draw ramp */
-		if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-			pal = PALETTE_TO_TRANSPARENT;
-		} else {
-			pal = psid->pal;
-		}
 
 		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
 		 * it doesn't disappear behind it
 		 */
 		AddSortableSpriteToDraw(
-			image, pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z
+			psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z, HASBIT(_transparent_opt, TO_BRIDGES)
 		);
 
 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_ROAD) {
@@ -1076,8 +1037,6 @@
 void DrawBridgeMiddle(const TileInfo* ti)
 {
 	const PalSpriteID* psid;
-	SpriteID image;
-	SpriteID pal;
 	uint base_offset;
 	TileIndex rampnorth;
 	TileIndex rampsouth;
@@ -1114,28 +1073,13 @@
 	uint bridge_z = GetBridgeHeight(rampsouth);
 	z = bridge_z - 3;
 
-	image = psid->sprite;
-	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
+	if (axis == AXIS_X) {
+		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 11, 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	} else {
-		pal = psid->pal;
-	}
-
-	if (axis == AXIS_X) {
-		AddSortableSpriteToDraw(image, pal, x, y, 16, 11, 1, z);
-	} else {
-		AddSortableSpriteToDraw(image, pal, x, y, 11, 16, 1, z);
+		AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 11, 16, 1, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	}
 
 	psid++;
-	image = psid->sprite;
-	if (HASBIT(_transparent_opt, TO_BRIDGES)) {
-		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
-		pal = PALETTE_TO_TRANSPARENT;
-	} else {
-		pal = psid->pal;
-	}
 
 	if (GetBridgeTransportType(rampsouth) == TRANSPORT_ROAD) {
 		RoadTypes rts = GetRoadTypes(rampsouth);
@@ -1150,22 +1094,21 @@
 	/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
 	if (axis == AXIS_X) {
 		y += 12;
-		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 16, 1, 0x28, z);
+		if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 16, 1, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	} else {
 		x += 12;
-		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 1, 16, 0x28, z);
+		if (psid->sprite & SPRITE_MASK) AddSortableSpriteToDraw(psid->sprite, psid->pal, x, y, 1, 16, 0x28, z, HASBIT(_transparent_opt, TO_BRIDGES));
 	}
 
 	psid++;
 	if (ti->z + 5 == z) {
 		/* draw poles below for small bridges */
 		if (psid->sprite != 0) {
-			image = psid->sprite;
+			SpriteID image = psid->sprite;
+			SpriteID pal   = psid->pal;
 			if (HASBIT(_transparent_opt, TO_BRIDGES)) {
 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
 				pal = PALETTE_TO_TRANSPARENT;
-			} else {
-				pal = psid->pal;
 			}
 
 			DrawGroundSpriteAt(image, pal, x, y, z);
@@ -1194,14 +1137,14 @@
 		DiagDirection dir = GetBridgeRampDirection(tile);
 		uint pos = (DiagDirToAxis(dir) == AXIS_X ? y : x);
 
+		z += ApplyFoundationToSlope(GetBridgeFoundation(tileh, DiagDirToAxis(dir)), &tileh);
+
 		/* On the bridge ramp? */
 		if (5 <= pos && pos <= 10) {
 			uint delta;
 
-			if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
 			if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
 
-			if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
 			switch (dir) {
 				default: NOT_REACHED();
 				case DIAGDIR_NE: delta = (TILE_SIZE - 1 - x) / 2; break;
@@ -1210,38 +1153,15 @@
 				case DIAGDIR_NW: delta = (TILE_SIZE - 1 - y) / 2; break;
 			}
 			return z + 1 + delta;
-		} else {
-			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
-
-			if (f != 0) {
-				if (IsSteepSlope(tileh)) {
-					z += TILE_HEIGHT;
-				} else if (f < 15) {
-					return z + TILE_HEIGHT;
-				}
-				tileh = (Slope)_inclined_tileh[f - 15];
-			}
 		}
 	}
 
 	return z + GetPartialZ(x, y, tileh);
 }
 
-static Slope GetSlopeTileh_TunnelBridge(TileIndex tile, Slope tileh)
+static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
 {
-	if (IsTunnel(tile)) {
-		return tileh;
-	} else {
-		if (HASBIT(BRIDGE_NO_FOUNDATION, tileh)) {
-			return tileh;
-		} else {
-			uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
-
-			if (f == 0) return tileh;
-			if (f < 15) return SLOPE_FLAT;
-			return (Slope)_inclined_tileh[f - 15];
-		}
-	}
+	return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(tile)));
 }
 
 
@@ -1513,5 +1433,5 @@
 	ChangeTileOwner_TunnelBridge,    /* change_tile_owner_clear */
 	NULL,                            /* get_produced_cargo_proc */
 	VehicleEnter_TunnelBridge,       /* vehicle_enter_tile_proc */
-	GetSlopeTileh_TunnelBridge,      /* get_slope_tileh_proc */
+	GetFoundation_TunnelBridge,      /* get_foundation_proc */
 };