tunnelbridge_cmd.c
changeset 3355 e414a0b104a6
parent 3301 79efd3144eba
child 3362 d30d8f9a37f0
equal deleted inserted replaced
3354:245157a5eafe 3355:e414a0b104a6
   797 		return CMD_ERROR;
   797 		return CMD_ERROR;
   798 }
   798 }
   799 
   799 
   800 
   800 
   801 // fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
   801 // fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
   802 static uint GetBridgeHeight(const TileInfo *ti)
   802 uint GetBridgeHeight(TileIndex t)
   803 {
   803 {
   804 	TileIndex tile = GetSouthernBridgeEnd(ti->tile);
   804 	TileIndex tile = GetSouthernBridgeEnd(t);
   805 
   805 
   806 	/* Return the height there (the height of the NORTH CORNER)
   806 	/* Return the height there (the height of the NORTH CORNER)
   807 	 * If the end of the bridge is on a tileh 7 (all raised, except north corner),
   807 	 * If the end of the bridge is on a tileh 7 (all raised, except north corner),
   808 	 * the z coordinate is 1 height level too low. Compensate for that */
   808 	 * the z coordinate is 1 height level too low. Compensate for that */
   809 	return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0);
   809 	return TilePixelHeight(tile) + (GetTileSlope(tile, NULL) == 7 ? 8 : 0);
   928 
   928 
   929 		if (ice) image += 32;
   929 		if (ice) image += 32;
   930 
   930 
   931 		image += GetTunnelDirection(ti->tile) * 2;
   931 		image += GetTunnelDirection(ti->tile) * 2;
   932 		DrawGroundSprite(image);
   932 		DrawGroundSprite(image);
       
   933 		if (GB(_m[ti->tile].m3, 0, 3) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   933 
   934 
   934 		AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z);
   935 		AddSortableSpriteToDraw(image+1, ti->x + 15, ti->y + 15, 1, 1, 8, (byte)ti->z);
   935 	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
   936 	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
   936 		int base_offset;
   937 		int base_offset;
   937 
   938 
   970 			if (!ice) {
   971 			if (!ice) {
   971 				DrawClearLandTile(ti, 3);
   972 				DrawClearLandTile(ti, 3);
   972 			} else {
   973 			} else {
   973 				DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
   974 				DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
   974 			}
   975 			}
       
   976 
       
   977 			if (GB(_m[ti->tile].m3, 0, 3) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   975 
   978 
   976 			// draw ramp
   979 			// draw ramp
   977 			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   980 			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   978 			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z);
   981 			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 7, ti->z);
   979 		} else {
   982 		} else {
  1027 			/*  base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */
  1030 			/*  base_offset needs to be 0 due to the structure of the sprite table see table/bridge_land.h */
  1028 			assert( (base_offset & 0x03) == 0x00);
  1031 			assert( (base_offset & 0x03) == 0x00);
  1029 			// get bridge sprites
  1032 			// get bridge sprites
  1030 			b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset;
  1033 			b = GetBridgeSpriteTable(GetBridgeType(ti->tile), GetBridgePiece(ti->tile)) + base_offset;
  1031 
  1034 
  1032 			z = GetBridgeHeight(ti) + 5;
  1035 			z = GetBridgeHeight(ti->tile) + 5;
  1033 
  1036 
  1034 			// draw rail or road component
  1037 			// draw rail or road component
  1035 			image = b[0];
  1038 			image = b[0];
  1036 			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
  1039 			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
  1037 			if (axis == AXIS_X) {
  1040 			if (axis == AXIS_X) {
  1051 				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 16, 1, 0x28, z);
  1054 				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 16, 1, 0x28, z);
  1052 			} else {
  1055 			} else {
  1053 				x += 12;
  1056 				x += 12;
  1054 				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
  1057 				if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
  1055 			}
  1058 			}
       
  1059 
       
  1060 			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC || GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
  1056 
  1061 
  1057 			if (ti->z + 5 == z) {
  1062 			if (ti->z + 5 == z) {
  1058 				// draw poles below for small bridges
  1063 				// draw poles below for small bridges
  1059 				image = b[2];
  1064 				image = b[2];
  1060 				if (image != 0) {
  1065 				if (image != 0) {
  1105 
  1110 
  1106 				// keep the same elevation because we're on the bridge?
  1111 				// keep the same elevation because we're on the bridge?
  1107 				if (_get_z_hint >= z + 8) return _get_z_hint;
  1112 				if (_get_z_hint >= z + 8) return _get_z_hint;
  1108 
  1113 
  1109 				// actually on the bridge, but not yet in the shared area.
  1114 				// actually on the bridge, but not yet in the shared area.
  1110 				if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti) + 8;
  1115 				if (!IS_INT_INSIDE(x, 5, 10 + 1)) return GetBridgeHeight(ti->tile) + 8;
  1111 
  1116 
  1112 				// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it.
  1117 				// in the shared area, assume that we're below the bridge, cause otherwise the hint would've caught it.
  1113 				// if rail or road below then it means it's possibly build on slope below the bridge.
  1118 				// if rail or road below then it means it's possibly build on slope below the bridge.
  1114 				if (IsTransportUnderBridge(ti->tile)) {
  1119 				if (IsTransportUnderBridge(ti->tile)) {
  1115 					uint f = _bridge_foundations[GetBridgeAxis(ti->tile)][tileh];
  1120 					uint f = _bridge_foundations[GetBridgeAxis(ti->tile)][tileh];