src/tunnelbridge_cmd.cpp
changeset 5919 2b58160d667d
parent 5838 9c3129cb019b
child 6103 7fa3e01134cb
equal deleted inserted replaced
5918:602e158900a2 5919:2b58160d667d
    40 	     |  |   maximum length
    40 	     |  |   maximum length
    41 	     |  |   |    price
    41 	     |  |   |    price
    42 	     |  |   |    |    maximum speed
    42 	     |  |   |    |    maximum speed
    43 	     |  |   |    |    |  sprite to use in GUI                string with description
    43 	     |  |   |    |    |  sprite to use in GUI                string with description
    44 	     |  |   |    |    |  |                                   |                            */
    44 	     |  |   |    |    |  |                                   |                            */
    45 	{    0, 0, 16,  80,  32, 0xA24                             , STR_5012_WOODEN             , NULL, 0 },
    45 	{    0, 0, 16,  80,  32, 0xA24, PAL_NONE                  , STR_5012_WOODEN             , NULL, 0 },
    46 	{    0, 0,  2, 112,  48, 0xA26 | PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
    46 	{    0, 0,  2, 112,  48, 0xA26, PALETTE_TO_STRUCT_RED     , STR_5013_CONCRETE           , NULL, 0 },
    47 	{ 1930, 0,  5, 144,  64, 0xA25                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
    47 	{ 1930, 0,  5, 144,  64, 0xA25, PAL_NONE                  , STR_500F_GIRDER_STEEL       , NULL, 0 },
    48 	{    0, 2, 10, 168,  80, 0xA22 | PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
    48 	{    0, 2, 10, 168,  80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, STR_5011_SUSPENSION_CONCRETE, NULL, 0 },
    49 	{ 1930, 3, 16, 185,  96, 0xA22                             , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
    49 	{ 1930, 3, 16, 185,  96, 0xA22, PAL_NONE                  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
    50 	{ 1930, 3, 16, 192, 112, 0xA22 | PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
    50 	{ 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW  , STR_500E_SUSPENSION_STEEL   , NULL, 0 },
    51 	{ 1930, 3,  7, 224, 160, 0xA23                             , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    51 	{ 1930, 3,  7, 224, 160, 0xA23, PAL_NONE                  , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    52 	{ 1930, 3,  8, 232, 208, 0xA23 | PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    52 	{ 1930, 3,  8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN   , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    53 	{ 1930, 3,  9, 248, 240, 0xA23 | PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    53 	{ 1930, 3,  9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED     , STR_5010_CANTILEVER_STEEL   , NULL, 0 },
    54 	{ 1930, 0,  2, 240, 256, 0xA27                             , STR_500F_GIRDER_STEEL       , NULL, 0 },
    54 	{ 1930, 0,  2, 240, 256, 0xA27, PAL_NONE                  , STR_500F_GIRDER_STEEL       , NULL, 0 },
    55 	{ 1995, 2, 16, 255, 320, 0xA28                             , STR_5014_TUBULAR_STEEL      , NULL, 0 },
    55 	{ 1995, 2, 16, 255, 320, 0xA28, PAL_NONE                  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
    56 	{ 2005, 2, 32, 380, 512, 0xA28 | PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
    56 	{ 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW  , STR_5014_TUBULAR_STEEL      , NULL, 0 },
    57 	{ 2010, 2, 32, 510, 608, 0xA28 | PALETTE_TO_STRUCT_GREY    , STR_BRIDGE_TUBULAR_SILICON  , NULL, 0 }
    57 	{ 2010, 2, 32, 510, 608, 0xA28, PALETTE_TO_STRUCT_GREY    , STR_BRIDGE_TUBULAR_SILICON  , NULL, 0 }
    58 };
    58 };
    59 
    59 
    60 Bridge _bridge[MAX_BRIDGES];
    60 Bridge _bridge[MAX_BRIDGES];
    61 
    61 
    62 
    62 
   721 		return CMD_ERROR;
   721 		return CMD_ERROR;
   722 	}
   722 	}
   723 }
   723 }
   724 
   724 
   725 
   725 
   726 static void DrawBridgePillars(PalSpriteID image, const TileInfo* ti, Axis axis, uint type, int x, int y, int z)
   726 static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis axis, uint type, int x, int y, int z)
   727 {
   727 {
       
   728 	SpriteID image = psid->sprite;
   728 	if (image != 0) {
   729 	if (image != 0) {
   729 		bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0);
   730 		bool drawfarpillar = !HASBIT(GetBridgeFlags(type), 0);
   730 		int back_height, front_height;
   731 		int back_height, front_height;
   731 		int i = z;
   732 		int i = z;
   732 		const byte *p;
   733 		const byte *p;
       
   734 		SpriteID pal;
   733 
   735 
   734 		static const byte _tileh_bits[4][8] = {
   736 		static const byte _tileh_bits[4][8] = {
   735 			{ 2, 1, 8, 4,  16,  2, 0, 9 },
   737 			{ 2, 1, 8, 4,  16,  2, 0, 9 },
   736 			{ 1, 8, 4, 2,   2, 16, 9, 0 },
   738 			{ 1, 8, 4, 2,   2, 16, 9, 0 },
   737 			{ 4, 8, 1, 2,  16,  2, 0, 9 },
   739 			{ 4, 8, 1, 2,  16,  2, 0, 9 },
   738 			{ 2, 4, 8, 1,   2, 16, 9, 0 }
   740 			{ 2, 4, 8, 1,   2, 16, 9, 0 }
   739 		};
   741 		};
   740 
   742 
   741 		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   743 		if (_display_opt & DO_TRANS_BUILDINGS) {
       
   744 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   745 			pal = PALETTE_TO_TRANSPARENT;
       
   746 		} else {
       
   747 			pal = psid->pal;
       
   748 		}
   742 
   749 
   743 		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
   750 		p = _tileh_bits[(image & 1) * 2 + (axis == AXIS_X ? 0 : 1)];
   744 		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
   751 		front_height = ti->z + (ti->tileh & p[0] ? TILE_HEIGHT : 0);
   745 		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
   752 		back_height  = ti->z + (ti->tileh & p[1] ? TILE_HEIGHT : 0);
   746 
   753 
   752 		for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
   759 		for (; z >= front_height || z >= back_height; z -= TILE_HEIGHT) {
   753 			/* HACK set height of the BB of pillars to 1, because the origin of the
   760 			/* HACK set height of the BB of pillars to 1, because the origin of the
   754 			 * sprites is at the top
   761 			 * sprites is at the top
   755 			 */
   762 			 */
   756 			if (z >= front_height) { // front facing pillar
   763 			if (z >= front_height) { // front facing pillar
   757 				AddSortableSpriteToDraw(image, x, y, p[4], p[5], 1, z);
   764 				AddSortableSpriteToDraw(image, pal, x, y, p[4], p[5], 1, z);
   758 			}
   765 			}
   759 
   766 
   760 			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
   767 			if (drawfarpillar && z >= back_height && z < i - TILE_HEIGHT) { // back facing pillar
   761 				AddSortableSpriteToDraw(image, x - p[6], y - p[7], p[4], p[5], 1, z);
   768 				AddSortableSpriteToDraw(image, pal, x - p[6], y - p[7], p[4], p[5], 1, z);
   762 			}
   769 			}
   763 		}
   770 		}
   764 	}
   771 	}
   765 }
   772 }
   766 
   773 
   798  * </ul>
   805  * </ul>
   799  * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
   806  * Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3
   800  */
   807  */
   801 static void DrawTile_TunnelBridge(TileInfo *ti)
   808 static void DrawTile_TunnelBridge(TileInfo *ti)
   802 {
   809 {
   803 	uint32 image;
   810 	SpriteID image;
       
   811 	SpriteID pal;
   804 
   812 
   805 	if (IsTunnel(ti->tile)) {
   813 	if (IsTunnel(ti->tile)) {
   806 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
   814 		if (GetTunnelTransportType(ti->tile) == TRANSPORT_RAIL) {
   807 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
   815 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.tunnel;
   808 		} else {
   816 		} else {
   810 		}
   818 		}
   811 
   819 
   812 		if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
   820 		if (HasTunnelSnowOrDesert(ti->tile)) image += 32;
   813 
   821 
   814 		image += GetTunnelDirection(ti->tile) * 2;
   822 		image += GetTunnelDirection(ti->tile) * 2;
   815 		DrawGroundSprite(image);
   823 		DrawGroundSprite(image, PAL_NONE);
   816 		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   824 		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   817 
   825 
   818 		AddSortableSpriteToDraw(image+1, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z);
   826 		AddSortableSpriteToDraw(image+1, PAL_NONE, ti->x + TILE_SIZE - 1, ti->y + TILE_SIZE - 1, 1, 1, 8, (byte)ti->z);
   819 		DrawBridgeMiddle(ti);
   827 		DrawBridgeMiddle(ti);
   820 	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
   828 	} else if (IsBridge(ti->tile)) { // XXX is this necessary?
       
   829 		const PalSpriteID *psid;
   821 		int base_offset;
   830 		int base_offset;
   822 		bool ice = HasBridgeSnowOrDesert(ti->tile);
   831 		bool ice = HasBridgeSnowOrDesert(ti->tile);
   823 
   832 
   824 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
   833 		if (GetBridgeTransportType(ti->tile) == TRANSPORT_RAIL) {
   825 			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
   834 			base_offset = GetRailTypeInfo(GetRailType(ti->tile))->bridge_offset;
   840 		base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
   849 		base_offset += (6 - GetBridgeRampDirection(ti->tile)) % 4;
   841 
   850 
   842 		if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
   851 		if (ti->tileh == SLOPE_FLAT) base_offset += 4; // sloped bridge head
   843 
   852 
   844 		/* Table number 6 always refers to the bridge heads for any bridge type */
   853 		/* Table number 6 always refers to the bridge heads for any bridge type */
   845 		image = GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
   854 		psid = &GetBridgeSpriteTable(GetBridgeType(ti->tile), 6)[base_offset];
   846 
   855 
   847 		if (!ice) {
   856 		if (!ice) {
   848 			DrawClearLandTile(ti, 3);
   857 			DrawClearLandTile(ti, 3);
   849 		} else {
   858 		} else {
   850 			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh]);
   859 			DrawGroundSprite(SPR_FLAT_SNOWY_TILE + _tileh_to_sprite[ti->tileh], PAL_NONE);
   851 		}
   860 		}
   852 
   861 
   853 		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   862 		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   854 
   863 
       
   864 		image = psid->sprite;
       
   865 
   855 		// draw ramp
   866 		// draw ramp
   856 		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   867 		if (_display_opt & DO_TRANS_BUILDINGS) {
       
   868 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   869 			pal = PALETTE_TO_TRANSPARENT;
       
   870 		} else {
       
   871 			pal = psid->pal;
       
   872 		}
       
   873 
   857 		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
   874 		/* HACK set the height of the BB of a sloped ramp to 1 so a vehicle on
   858 		 * it doesn't disappear behind it
   875 		 * it doesn't disappear behind it
   859 		 */
   876 		 */
   860 		AddSortableSpriteToDraw(
   877 		AddSortableSpriteToDraw(
   861 			image, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 1 : 8, ti->z
   878 			image, pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 1 : 8, ti->z
   862 		);
   879 		);
   863 
   880 
   864 		DrawBridgeMiddle(ti);
   881 		DrawBridgeMiddle(ti);
   865 	}
   882 	}
   866 }
   883 }
   898 }
   915 }
   899 
   916 
   900 
   917 
   901 void DrawBridgeMiddle(const TileInfo* ti)
   918 void DrawBridgeMiddle(const TileInfo* ti)
   902 {
   919 {
   903 	const PalSpriteID* b;
   920 	const PalSpriteID* psid;
   904 	PalSpriteID image;
   921 	SpriteID image;
       
   922 	SpriteID pal;
   905 	uint base_offset;
   923 	uint base_offset;
   906 	TileIndex rampnorth;
   924 	TileIndex rampnorth;
   907 	TileIndex rampsouth;
   925 	TileIndex rampsouth;
   908 	Axis axis;
   926 	Axis axis;
   909 	uint piece;
   927 	uint piece;
   928 		base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
   946 		base_offset = GetRailTypeInfo(GetRailType(rampsouth))->bridge_offset;
   929 	} else {
   947 	} else {
   930 		base_offset = 8;
   948 		base_offset = 8;
   931 	}
   949 	}
   932 
   950 
   933 	b = base_offset + GetBridgeSpriteTable(type, piece);
   951 	psid = base_offset + GetBridgeSpriteTable(type, piece);
   934 	if (axis != AXIS_X) b += 4;
   952 	if (axis != AXIS_X) psid += 4;
   935 
   953 
   936 	x = ti->x;
   954 	x = ti->x;
   937 	y = ti->y;
   955 	y = ti->y;
   938 	z = GetBridgeHeight(rampsouth) - 3;
   956 	z = GetBridgeHeight(rampsouth) - 3;
   939 
   957 
   940 	image = b[0];
   958 	image = psid->sprite;
   941 	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   959 	if (_display_opt & DO_TRANS_BUILDINGS) {
       
   960 		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   961 		pal = PALETTE_TO_TRANSPARENT;
       
   962 	} else {
       
   963 		pal = psid->pal;
       
   964 	}
       
   965 
   942 	if (axis == AXIS_X) {
   966 	if (axis == AXIS_X) {
   943 		AddSortableSpriteToDraw(image, x, y, 16, 11, 1, z);
   967 		AddSortableSpriteToDraw(image, pal, x, y, 16, 11, 1, z);
   944 	} else {
   968 	} else {
   945 		AddSortableSpriteToDraw(image, x, y, 11, 16, 1, z);
   969 		AddSortableSpriteToDraw(image, pal, x, y, 11, 16, 1, z);
   946 	}
   970 	}
   947 
   971 
   948 	image = b[1];
   972 	psid++;
   949 	if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   973 	image = psid->sprite;
       
   974 	if (_display_opt & DO_TRANS_BUILDINGS) {
       
   975 		SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   976 		pal = PALETTE_TO_TRANSPARENT;
       
   977 	} else {
       
   978 		pal = psid->pal;
       
   979 	}
   950 
   980 
   951 	// draw roof, the component of the bridge which is logically between the vehicle and the camera
   981 	// draw roof, the component of the bridge which is logically between the vehicle and the camera
   952 	if (axis == AXIS_X) {
   982 	if (axis == AXIS_X) {
   953 		y += 12;
   983 		y += 12;
   954 		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 16, 1, 0x28, z);
   984 		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 16, 1, 0x28, z);
   955 	} else {
   985 	} else {
   956 		x += 12;
   986 		x += 12;
   957 		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, x, y, 1, 16, 0x28, z);
   987 		if (image & SPRITE_MASK) AddSortableSpriteToDraw(image, pal, x, y, 1, 16, 0x28, z);
   958 	}
   988 	}
   959 
   989 
   960 	if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   990 	if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
   961 
   991 
       
   992 	psid++;
   962 	if (ti->z + 5 == z) {
   993 	if (ti->z + 5 == z) {
   963 		// draw poles below for small bridges
   994 		// draw poles below for small bridges
   964 		image = b[2];
   995 		if (psid->sprite != 0) {
   965 		if (image != 0) {
   996 			image = psid->sprite;
   966 			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
   997 			if (_display_opt & DO_TRANS_BUILDINGS) {
   967 			DrawGroundSpriteAt(image, x, y, z);
   998 				SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
   999 				pal = PALETTE_TO_TRANSPARENT;
       
  1000 			} else {
       
  1001 				pal = psid->pal;
       
  1002 			}
       
  1003 
       
  1004 			DrawGroundSpriteAt(image, pal, x, y, z);
   968 		}
  1005 		}
   969 	} else if (_patches.bridge_pillars) {
  1006 	} else if (_patches.bridge_pillars) {
   970 		// draw pillars below for high bridges
  1007 		// draw pillars below for high bridges
   971 		DrawBridgePillars(b[2], ti, axis, type, x, y, z);
  1008 		DrawBridgePillars(psid, ti, axis, type, x, y, z);
   972 	}
  1009 	}
   973 }
  1010 }
   974 
  1011 
   975 
  1012 
   976 uint SetSpeedLimitOnBridge(Vehicle *v)
  1013 uint SetSpeedLimitOnBridge(Vehicle *v)