src/road_cmd.cpp
branchnoai
changeset 9694 e72987579514
parent 9686 d3c195c226f9
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
    29 #include "yapf/yapf.h"
    29 #include "yapf/yapf.h"
    30 #include "depot.h"
    30 #include "depot.h"
    31 #include "newgrf.h"
    31 #include "newgrf.h"
    32 #include "station_map.h"
    32 #include "station_map.h"
    33 #include "tunnel_map.h"
    33 #include "tunnel_map.h"
       
    34 #include "misc/autoptr.hpp"
    34 
    35 
    35 
    36 
    36 static uint CountRoadBits(RoadBits r)
    37 static uint CountRoadBits(RoadBits r)
    37 {
    38 {
    38 	uint count = 0;
    39 	uint count = 0;
   122 	RoadType rt = (RoadType)GB(p1, 4, 2);
   123 	RoadType rt = (RoadType)GB(p1, 4, 2);
   123 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   124 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   124 
   125 
   125 	Town *t = NULL;
   126 	Town *t = NULL;
   126 	switch (GetTileType(tile)) {
   127 	switch (GetTileType(tile)) {
   127 		case MP_STREET:
   128 		case MP_ROAD:
   128 			if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
   129 			if (_game_mode != GM_EDITOR && GetRoadOwner(tile, rt) == OWNER_TOWN) t = GetTownByTile(tile);
   129 			break;
   130 			break;
   130 
   131 
   131 		case MP_STATION:
   132 		case MP_STATION:
   132 			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
   133 			if (!IsDriveThroughStopTile(tile)) return CMD_ERROR;
   152 
   153 
   153 	/* check if you're allowed to remove the street owned by a town
   154 	/* check if you're allowed to remove the street owned by a town
   154 	 * removal allowance depends on difficulty setting */
   155 	 * removal allowance depends on difficulty setting */
   155 	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
   156 	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR;
   156 
   157 
   157 	if (!IsTileType(tile, MP_STREET)) {
   158 	if (!IsTileType(tile, MP_ROAD)) {
   158 		/* If it's the last roadtype, just clear the whole tile */
   159 		/* If it's the last roadtype, just clear the whole tile */
   159 		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   160 		if (rts == RoadTypeToRoadTypes(rt)) return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   160 
   161 
   161 		CommandCost cost;
   162 		CommandCost cost;
   162 		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   163 		if (IsTileType(tile, MP_TUNNELBRIDGE)) {
   296 static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
   297 static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing)
   297 {
   298 {
   298 	RoadBits road_bits;
   299 	RoadBits road_bits;
   299 
   300 
   300 	if (IsSteepSlope(tileh)) {
   301 	if (IsSteepSlope(tileh)) {
   301 		if (existing == 0) {
   302 		/* force full pieces. */
   302 			/* force full pieces. */
   303 		*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
   303 			*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
   304 		*pieces |= (RoadBits)((*pieces & 0x3) << 2);
   304 			*pieces |= (RoadBits)((*pieces & 0x3) << 2);
   305 
       
   306 		if (existing == 0 || existing == *pieces) {
   305 			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   307 			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   306 		}
   308 		}
   307 		return CMD_ERROR;
   309 		return CMD_ERROR;
   308 	}
   310 	}
   309 	road_bits = *pieces | existing;
   311 	road_bits = *pieces | existing;
   318 	/* foundation is used. Whole tile is leveled up */
   320 	/* foundation is used. Whole tile is leveled up */
   319 	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
   321 	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
   320 		return CommandCost(existing != 0 ? 0 : _price.terraform);
   322 		return CommandCost(existing != 0 ? 0 : _price.terraform);
   321 	}
   323 	}
   322 
   324 
       
   325 	*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
       
   326 	*pieces |= (RoadBits)((*pieces & 0x3) << 2);
       
   327 
   323 	/* partly leveled up tile, only if there's no road on that tile */
   328 	/* partly leveled up tile, only if there's no road on that tile */
   324 	if (existing == 0 && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
   329 	if ((existing == 0 || existing == *pieces) && (tileh == SLOPE_W || tileh == SLOPE_S || tileh == SLOPE_E || tileh == SLOPE_N)) {
   325 		/* force full pieces. */
   330 		/* force full pieces. */
   326 		*pieces |= (RoadBits)((*pieces & 0xC) >> 2);
       
   327 		*pieces |= (RoadBits)((*pieces & 0x3) << 2);
       
   328 		if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   331 		if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
   329 	}
   332 	}
   330 	return CMD_ERROR;
   333 	return CMD_ERROR;
   331 }
   334 }
   332 
   335 
   360 	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
   363 	DisallowedRoadDirections toggle_drd = (DisallowedRoadDirections)GB(p1, 6, 2);
   361 
   364 
   362 	tileh = GetTileSlope(tile, NULL);
   365 	tileh = GetTileSlope(tile, NULL);
   363 
   366 
   364 	switch (GetTileType(tile)) {
   367 	switch (GetTileType(tile)) {
   365 		case MP_STREET:
   368 		case MP_ROAD:
   366 			switch (GetRoadTileType(tile)) {
   369 			switch (GetRoadTileType(tile)) {
   367 				case ROAD_TILE_NORMAL: {
   370 				case ROAD_TILE_NORMAL: {
   368 					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
   371 					if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
   369 					if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
   372 					if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
   370 
   373 
   477 			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   480 			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   478 		}
   481 		}
   479 		cost.AddCost(ret);
   482 		cost.AddCost(ret);
   480 	}
   483 	}
   481 
   484 
   482 	if (IsTileType(tile, MP_STREET)) {
   485 	if (IsTileType(tile, MP_ROAD)) {
   483 		/* Don't put the pieces that already exist */
   486 		/* Don't put the pieces that already exist */
   484 		pieces &= ComplementRoadBits(existing);
   487 		pieces &= ComplementRoadBits(existing);
   485 	}
   488 	}
   486 
   489 
   487 	cost.AddCost(CountRoadBits(pieces) * _price.build_road);
   490 	cost.AddCost(CountRoadBits(pieces) * _price.build_road);
   490 		cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
   493 		cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
   491 	}
   494 	}
   492 
   495 
   493 	if (flags & DC_EXEC) {
   496 	if (flags & DC_EXEC) {
   494 		switch (GetTileType(tile)) {
   497 		switch (GetTileType(tile)) {
   495 			case MP_STREET: {
   498 			case MP_ROAD: {
   496 				RoadTileType rtt = GetRoadTileType(tile);
   499 				RoadTileType rtt = GetRoadTileType(tile);
   497 				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
   500 				if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
   498 					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
   501 					SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
   499 					SetRoadOwner(tile, rt, _current_player);
   502 					SetRoadOwner(tile, rt, _current_player);
   500 					if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
   503 					if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
   525 			default:
   528 			default:
   526 				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
   529 				MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
   527 				break;
   530 				break;
   528 		}
   531 		}
   529 
   532 
   530 		if (rt != ROADTYPE_TRAM && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
   533 		if (rt != ROADTYPE_TRAM && IsTileType(tile, MP_ROAD) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
   531 			existing |= pieces;
   534 			existing |= pieces;
   532 			SetDisallowedRoadDirections(tile, (existing == ROAD_X || existing == ROAD_Y) ?
   535 			SetDisallowedRoadDirections(tile, (existing == ROAD_X || existing == ROAD_Y) ?
   533 					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
   536 					GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE);
   534 		}
   537 		}
   535 
   538 
   717  * distingush between "Flat land required" and "land sloped in wrong direction"
   720  * distingush between "Flat land required" and "land sloped in wrong direction"
   718  */
   721  */
   719 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   722 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   720 {
   723 {
   721 	CommandCost cost;
   724 	CommandCost cost;
   722 	Depot *dep;
       
   723 	Slope tileh;
   725 	Slope tileh;
   724 
   726 
   725 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   727 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   726 
   728 
   727 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   729 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   741 	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   743 	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   742 	if (CmdFailed(cost)) return CMD_ERROR;
   744 	if (CmdFailed(cost)) return CMD_ERROR;
   743 
   745 
   744 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   746 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   745 
   747 
   746 	dep = AllocateDepot();
   748 	Depot *dep = new Depot(tile);
   747 	if (dep == NULL) return CMD_ERROR;
   749 	if (dep == NULL) return CMD_ERROR;
       
   750 	AutoPtrT<Depot> d_auto_delete = dep;
   748 
   751 
   749 	if (flags & DC_EXEC) {
   752 	if (flags & DC_EXEC) {
   750 		dep->xy = tile;
       
   751 		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
   753 		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
   752 
   754 
   753 		MakeRoadDepot(tile, _current_player, dir, rt);
   755 		MakeRoadDepot(tile, _current_player, dir, rt);
   754 		MarkTileDirtyByTile(tile);
   756 		MarkTileDirtyByTile(tile);
       
   757 		d_auto_delete.Detach();
   755 	}
   758 	}
   756 	return cost.AddCost(_price.build_road_depot);
   759 	return cost.AddCost(_price.build_road_depot);
   757 }
   760 }
   758 
   761 
   759 static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
   762 static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
   761 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
   764 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
   762 		return CMD_ERROR;
   765 		return CMD_ERROR;
   763 
   766 
   764 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   767 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
   765 
   768 
   766 	if (flags & DC_EXEC) DeleteDepot(GetDepotByTile(tile));
   769 	if (flags & DC_EXEC) {
       
   770 		DoClearSquare(tile);
       
   771 		delete GetDepotByTile(tile);
       
   772 	}
   767 
   773 
   768 	return CommandCost(_price.remove_road_depot);
   774 	return CommandCost(_price.remove_road_depot);
   769 }
   775 }
   770 
   776 
   771 static CommandCost ClearTile_Road(TileIndex tile, byte flags)
   777 static CommandCost ClearTile_Road(TileIndex tile, byte flags)
   832 };
   838 };
   833 
   839 
   834 #include "table/road_land.h"
   840 #include "table/road_land.h"
   835 
   841 
   836 
   842 
   837 uint GetRoadFoundation(Slope tileh, RoadBits bits)
   843 Foundation GetRoadFoundation(Slope tileh, RoadBits bits)
   838 {
   844 {
   839 	uint i;
   845 	if (!IsSteepSlope(tileh)) {
   840 
   846 		if ((~_valid_tileh_slopes_road[0][tileh] & bits) == 0) {
   841 	/* normal level sloped building */
   847 			/* As one can remove a single road piece when in a corner on a foundation as
   842 	if (!IsSteepSlope(tileh) &&
   848 			 * it is on a sloped piece of landscape, one creates a state that cannot be
   843 			(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) {
   849 			 * created directly, but the state itself is still perfectly drawable.
   844 		return tileh;
   850 			 * However, as we do not want this to be build directly, we need to check
   845 	}
   851 			 * for that situation in here. */
   846 
   852 			return (tileh != 0 && HAS_SINGLE_BIT(bits)) ? FOUNDATION_LEVELED : FOUNDATION_NONE;
   847 	/* inclined sloped building */
   853 		}
   848 	switch (bits) {
   854 		if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return FOUNDATION_LEVELED;
   849 		case ROAD_X: i = 0; break;
   855 	}
   850 		case ROAD_Y: i = 1; break;
   856 
   851 		default:     return 0;
   857 	return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y);
   852 	}
       
   853 	switch (tileh) {
       
   854 		case SLOPE_W:
       
   855 		case SLOPE_STEEP_W: i += 0; break;
       
   856 		case SLOPE_S:
       
   857 		case SLOPE_STEEP_S: i += 2; break;
       
   858 		case SLOPE_E:
       
   859 		case SLOPE_STEEP_E: i += 4; break;
       
   860 		case SLOPE_N:
       
   861 		case SLOPE_STEEP_N: i += 6; break;
       
   862 		default: return 0;
       
   863 	}
       
   864 	return i + 15;
       
   865 }
   858 }
   866 
   859 
   867 const byte _road_sloped_sprites[14] = {
   860 const byte _road_sloped_sprites[14] = {
   868 	0,  0,  2,  0,
   861 	0,  0,  2,  0,
   869 	0,  1,  0,  0,
   862 	0,  1,  0,  0,
   911 	} else {
   904 	} else {
   912 		back  = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
   905 		back  = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[tram];
   913 		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
   906 		front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[tram];
   914 	}
   907 	}
   915 
   908 
   916 	SpriteID pal = PAL_NONE;
   909 	AddSortableSpriteToDraw(back,  PAL_NONE, ti->x, ti->y, 16, 16, 0x1F, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
   917 	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   910 	AddSortableSpriteToDraw(front, PAL_NONE, ti->x, ti->y, 16, 16, 0x1F, ti->z, HASBIT(_transparent_opt, TO_BUILDINGS));
   918 		SETBIT(front, PALETTE_MODIFIER_TRANSPARENT);
       
   919 		SETBIT(back,  PALETTE_MODIFIER_TRANSPARENT);
       
   920 		pal = PALETTE_TO_TRANSPARENT;
       
   921 	}
       
   922 
       
   923 	AddSortableSpriteToDraw(back,  pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
       
   924 	AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, 0x1F, ti->z);
       
   925 }
   911 }
   926 
   912 
   927 /**
   913 /**
   928  * Draws details on/around the road
   914  * Draws details on/around the road
   929  * @param img the sprite to draw
   915  * @param img the sprite to draw
   954 	SpriteID image = 0;
   940 	SpriteID image = 0;
   955 	SpriteID pal = PAL_NONE;
   941 	SpriteID pal = PAL_NONE;
   956 	Roadside roadside;
   942 	Roadside roadside;
   957 
   943 
   958 	if (ti->tileh != SLOPE_FLAT) {
   944 	if (ti->tileh != SLOPE_FLAT) {
   959 		int foundation = GetRoadFoundation(ti->tileh, road | tram);
   945 		DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
   960 
       
   961 		if (foundation != 0) DrawFoundation(ti, foundation);
       
   962 
   946 
   963 		/* DrawFoundation() modifies ti.
   947 		/* DrawFoundation() modifies ti.
   964 		 * Default sloped sprites.. */
   948 		 * Default sloped sprites.. */
   965 		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
   949 		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
   966 	}
   950 	}
  1029 		case ROAD_TILE_CROSSING: {
  1013 		case ROAD_TILE_CROSSING: {
  1030 			SpriteID image;
  1014 			SpriteID image;
  1031 			SpriteID pal = PAL_NONE;
  1015 			SpriteID pal = PAL_NONE;
  1032 			Roadside roadside = GetRoadside(ti->tile);
  1016 			Roadside roadside = GetRoadside(ti->tile);
  1033 
  1017 
  1034 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
  1018 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
  1035 
  1019 
  1036 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
  1020 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
  1037 
  1021 
  1038 			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
  1022 			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
  1039 			if (IsCrossingBarred(ti->tile)) image += 2;
  1023 			if (IsCrossingBarred(ti->tile)) image += 2;
  1061 		case ROAD_TILE_DEPOT: {
  1045 		case ROAD_TILE_DEPOT: {
  1062 			const DrawTileSprites* dts;
  1046 			const DrawTileSprites* dts;
  1063 			const DrawTileSeqStruct* dtss;
  1047 			const DrawTileSeqStruct* dtss;
  1064 			SpriteID palette;
  1048 			SpriteID palette;
  1065 
  1049 
  1066 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
  1050 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
  1067 
  1051 
  1068 			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
  1052 			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
  1069 
  1053 
  1070 			if (HASBIT(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
  1054 			if (HASBIT(GetRoadTypes(ti->tile), ROADTYPE_TRAM)) {
  1071 				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
  1055 				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
  1077 
  1061 
  1078 			for (dtss = dts->seq; dtss->image != 0; dtss++) {
  1062 			for (dtss = dts->seq; dtss->image != 0; dtss++) {
  1079 				SpriteID image = dtss->image;
  1063 				SpriteID image = dtss->image;
  1080 				SpriteID pal;
  1064 				SpriteID pal;
  1081 
  1065 
  1082 				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
  1066 				if (!HASBIT(_transparent_opt, TO_BUILDINGS) && HASBIT(image, PALETTE_MODIFIER_COLOR)) {
  1083 					SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
       
  1084 					pal = PALETTE_TO_TRANSPARENT;
       
  1085 				} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
       
  1086 					pal = palette;
  1067 					pal = palette;
  1087 				} else {
  1068 				} else {
  1088 					pal = PAL_NONE;
  1069 					pal = PAL_NONE;
  1089 				}
  1070 				}
  1090 
  1071 
  1091 				AddSortableSpriteToDraw(
  1072 				AddSortableSpriteToDraw(
  1092 					image, pal,
  1073 					image, pal,
  1093 					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
  1074 					ti->x + dtss->delta_x, ti->y + dtss->delta_y,
  1094 					dtss->size_x, dtss->size_y,
  1075 					dtss->size_x, dtss->size_y,
  1095 					dtss->size_z, ti->z
  1076 					dtss->size_z, ti->z,
       
  1077 					HASBIT(_transparent_opt, TO_BUILDINGS)
  1096 				);
  1078 				);
  1097 			}
  1079 			}
  1098 			break;
  1080 			break;
  1099 		}
  1081 		}
  1100 	}
  1082 	}
  1125 	uint z;
  1107 	uint z;
  1126 	Slope tileh = GetTileSlope(tile, &z);
  1108 	Slope tileh = GetTileSlope(tile, &z);
  1127 
  1109 
  1128 	if (tileh == SLOPE_FLAT) return z;
  1110 	if (tileh == SLOPE_FLAT) return z;
  1129 	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
  1111 	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
  1130 		uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
  1112 		Foundation f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
  1131 
  1113 		z += ApplyFoundationToSlope(f, &tileh);
  1132 		if (f != 0) {
       
  1133 			if (IsSteepSlope(tileh)) {
       
  1134 				z += TILE_HEIGHT;
       
  1135 			} else if (f < 15) {
       
  1136 				return z + TILE_HEIGHT; // leveled foundation
       
  1137 			}
       
  1138 			tileh = _inclined_tileh[f - 15]; // inclined foundation
       
  1139 		}
       
  1140 		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
  1114 		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
  1141 	} else {
  1115 	} else {
  1142 		return z + TILE_HEIGHT;
  1116 		return z + TILE_HEIGHT;
  1143 	}
  1117 	}
  1144 }
  1118 }
  1145 
  1119 
  1146 static Slope GetSlopeTileh_Road(TileIndex tile, Slope tileh)
  1120 static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
  1147 {
  1121 {
  1148 	if (tileh == SLOPE_FLAT) return SLOPE_FLAT;
       
  1149 	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
  1122 	if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
  1150 		uint f = GetRoadFoundation(tileh, GetAllRoadBits(tile));
  1123 		return GetRoadFoundation(tileh, GetAllRoadBits(tile));
  1151 
       
  1152 		if (f == 0) return tileh;
       
  1153 		if (f < 15) return SLOPE_FLAT; // leveled foundation
       
  1154 		return _inclined_tileh[f - 15]; // inclined foundation
       
  1155 	} else {
  1124 	} else {
  1156 		return SLOPE_FLAT;
  1125 		return FlatteningFoundation(tileh);
  1157 	}
  1126 	}
  1158 }
  1127 }
  1159 
  1128 
  1160 static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
  1129 static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
  1161 {
  1130 {
  1409 	AnimateTile_Road,        /* animate_tile_proc */
  1378 	AnimateTile_Road,        /* animate_tile_proc */
  1410 	TileLoop_Road,           /* tile_loop_clear */
  1379 	TileLoop_Road,           /* tile_loop_clear */
  1411 	ChangeTileOwner_Road,    /* change_tile_owner_clear */
  1380 	ChangeTileOwner_Road,    /* change_tile_owner_clear */
  1412 	NULL,                    /* get_produced_cargo_proc */
  1381 	NULL,                    /* get_produced_cargo_proc */
  1413 	VehicleEnter_Road,       /* vehicle_enter_tile_proc */
  1382 	VehicleEnter_Road,       /* vehicle_enter_tile_proc */
  1414 	GetSlopeTileh_Road,      /* get_slope_tileh_proc */
  1383 	GetFoundation_Road,      /* get_foundation_proc */
  1415 };
  1384 };