src/road_cmd.cpp
changeset 8821 1411d08e26b3
parent 8806 4fe163e0b52a
child 8859 b527de22bf3e
equal deleted inserted replaced
8820:93ad0db32ea0 8821:1411d08e26b3
   340  * @param pieces The RoadBits we want to add
   340  * @param pieces The RoadBits we want to add
   341  * @param existing The existent RoadBits of the current type
   341  * @param existing The existent RoadBits of the current type
   342  * @param other The other existent RoadBits
   342  * @param other The other existent RoadBits
   343  * @return The costs for these RoadBits on this slope
   343  * @return The costs for these RoadBits on this slope
   344  */
   344  */
   345 static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing, RoadBits other)
   345 static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
   346 {
   346 {
   347 	/* Remove already build pieces */
   347 	/* Remove already build pieces */
   348 	CLRBITS(*pieces, existing);
   348 	CLRBITS(*pieces, existing);
   349 
   349 
   350 	/* If we can't build anything stop here */
   350 	/* If we can't build anything stop here */
   416  * @param p2 the town that is building the road (0 if not applicable)
   416  * @param p2 the town that is building the road (0 if not applicable)
   417  */
   417  */
   418 CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   418 CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   419 {
   419 {
   420 	CommandCost cost(EXPENSES_CONSTRUCTION);
   420 	CommandCost cost(EXPENSES_CONSTRUCTION);
   421 	CommandCost ret;
   421 
   422 	RoadBits existing = ROAD_NONE;
   422 	RoadBits existing = ROAD_NONE;
   423 	RoadBits other_bits = ROAD_NONE;
   423 	RoadBits other_bits = ROAD_NONE;
   424 
   424 
   425 	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
   425 	/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
   426 	 * if a non-player is building the road */
   426 	 * if a non-player is building the road */
   482 					goto do_clear;
   482 					goto do_clear;
   483 			}
   483 			}
   484 			break;
   484 			break;
   485 
   485 
   486 		case MP_RAILWAY: {
   486 		case MP_RAILWAY: {
   487 			Axis roaddir;
       
   488 
       
   489 			if (IsSteepSlope(tileh)) {
   487 			if (IsSteepSlope(tileh)) {
   490 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   488 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   491 			}
   489 			}
   492 
   490 
   493 			/* Level crossings may only be built on these slopes */
   491 			/* Level crossings may only be built on these slopes */
   494 			if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
   492 			if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) {
   495 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   493 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   496 			}
   494 			}
   497 
   495 
   498 			if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
   496 			if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
       
   497 
       
   498 			Axis roaddir;
   499 			switch (GetTrackBits(tile)) {
   499 			switch (GetTrackBits(tile)) {
   500 				case TRACK_BIT_X:
   500 				case TRACK_BIT_X:
   501 					if (pieces & ROAD_X) goto do_clear;
   501 					if (pieces & ROAD_X) goto do_clear;
   502 					roaddir = AXIS_Y;
   502 					roaddir = AXIS_Y;
   503 					break;
   503 					break;
   532 			if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
   532 			if (HasTileRoadType(tile, rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
   533 			/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
   533 			/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
   534 			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
   534 			if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
   535 			break;
   535 			break;
   536 
   536 
   537 		default:
   537 		default: {
   538 do_clear:;
   538 do_clear:;
   539 			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   539 			CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   540 			if (CmdFailed(ret)) return ret;
   540 			if (CmdFailed(ret)) return ret;
   541 			cost.AddCost(ret);
   541 			cost.AddCost(ret);
       
   542 		} break;
   542 	}
   543 	}
   543 
   544 
   544 	if (other_bits != pieces) {
   545 	if (other_bits != pieces) {
   545 		/* Check the foundation/slopes when adding road/tram bits */
   546 		/* Check the foundation/slopes when adding road/tram bits */
   546 		ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
   547 		CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
   547 		/* Return an error if we need to build a foundation (ret != 0) but the
   548 		/* Return an error if we need to build a foundation (ret != 0) but the
   548 		 * current patch-setting is turned off (or stupid AI@work) */
   549 		 * current patch-setting is turned off (or stupid AI@work) */
   549 		if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) {
   550 		if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) {
   550 			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   551 			return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
   551 		}
   552 		}
   641  * - p2 = (bit 3 + 4) - road type
   642  * - p2 = (bit 3 + 4) - road type
   642  * - p2 = (bit 5) - set road direction
   643  * - p2 = (bit 5) - set road direction
   643  */
   644  */
   644 CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   645 CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   645 {
   646 {
   646 	TileIndex start_tile, tile;
   647 	CommandCost cost(EXPENSES_CONSTRUCTION);
   647 	CommandCost ret, cost(EXPENSES_CONSTRUCTION);
       
   648 	bool had_bridge = false;
   648 	bool had_bridge = false;
   649 	bool had_tunnel = false;
   649 	bool had_tunnel = false;
   650 	bool had_success = false;
   650 	bool had_success = false;
   651 	DisallowedRoadDirections drd = DRD_NORTHBOUND;
   651 	DisallowedRoadDirections drd = DRD_NORTHBOUND;
   652 
   652 
   653 	_error_message = INVALID_STRING_ID;
   653 	_error_message = INVALID_STRING_ID;
   654 
   654 
   655 	if (p1 >= MapSize()) return CMD_ERROR;
   655 	if (p1 >= MapSize()) return CMD_ERROR;
   656 
   656 
   657 	start_tile = p1;
   657 	TileIndex start_tile = p1;
   658 	RoadType rt = (RoadType)GB(p2, 3, 2);
   658 	RoadType rt = (RoadType)GB(p2, 3, 2);
   659 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   659 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   660 
   660 
   661 	/* Only drag in X or Y direction dictated by the direction variable */
   661 	/* Only drag in X or Y direction dictated by the direction variable */
   662 	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   662 	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   676 	 * when you just 'click' on one tile to build them. */
   676 	 * when you just 'click' on one tile to build them. */
   677 	if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
   677 	if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
   678 	/* No disallowed direction bits have to be toggled */
   678 	/* No disallowed direction bits have to be toggled */
   679 	if (!HasBit(p2, 5)) drd = DRD_NONE;
   679 	if (!HasBit(p2, 5)) drd = DRD_NONE;
   680 
   680 
   681 	tile = start_tile;
   681 	TileIndex tile = start_tile;
   682 	/* Start tile is the small number. */
   682 	/* Start tile is the small number. */
   683 	for (;;) {
   683 	for (;;) {
   684 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   684 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   685 
   685 
   686 		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
   686 		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
   687 		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
   687 		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
   688 
   688 
   689 		ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
   689 		CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
   690 		if (CmdFailed(ret)) {
   690 		if (CmdFailed(ret)) {
   691 			if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
   691 			if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
   692 		} else {
   692 		} else {
   693 			had_success = true;
   693 			had_success = true;
   694 			/* Only pay for the upgrade on one side of the bridges and tunnels */
   694 			/* Only pay for the upgrade on one side of the bridges and tunnels */
   727  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   727  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
   728  * - p2 = (bit 3 + 4) - road type
   728  * - p2 = (bit 3 + 4) - road type
   729  */
   729  */
   730 CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   730 CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
   731 {
   731 {
   732 	TileIndex start_tile, tile;
   732 	CommandCost cost(EXPENSES_CONSTRUCTION);
   733 	CommandCost ret, cost(EXPENSES_CONSTRUCTION);
       
   734 	Money money;
       
   735 
   733 
   736 	if (p1 >= MapSize()) return CMD_ERROR;
   734 	if (p1 >= MapSize()) return CMD_ERROR;
   737 
   735 
   738 	start_tile = p1;
   736 	TileIndex start_tile = p1;
   739 	RoadType rt = (RoadType)GB(p2, 3, 2);
   737 	RoadType rt = (RoadType)GB(p2, 3, 2);
   740 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   738 	if (!IsValidRoadType(rt)) return CMD_ERROR;
   741 
   739 
   742 	/* Only drag in X or Y direction dictated by the direction variable */
   740 	/* Only drag in X or Y direction dictated by the direction variable */
   743 	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   741 	if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
   749 		start_tile = end_tile;
   747 		start_tile = end_tile;
   750 		end_tile = t;
   748 		end_tile = t;
   751 		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
   749 		p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
   752 	}
   750 	}
   753 
   751 
   754 	money = GetAvailableMoneyForCommand();
   752 	Money money = GetAvailableMoneyForCommand();
   755 	tile = start_tile;
   753 	TileIndex tile = start_tile;
   756 	/* Start tile is the small number. */
   754 	/* Start tile is the small number. */
   757 	for (;;) {
   755 	for (;;) {
   758 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   756 		RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
   759 
   757 
   760 		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
   758 		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
   761 		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
   759 		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
   762 
   760 
   763 		/* try to remove the halves. */
   761 		/* try to remove the halves. */
   764 		if (bits != 0) {
   762 		if (bits != 0) {
   765 			ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
   763 			CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
   766 			if (CmdSucceeded(ret)) {
   764 			if (CmdSucceeded(ret)) {
   767 				if (flags & DC_EXEC) {
   765 				if (flags & DC_EXEC) {
   768 					money -= ret.GetCost();
   766 					money -= ret.GetCost();
   769 					if (money < 0) {
   767 					if (money < 0) {
   770 						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
   768 						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
   794  * @todo When checking for the tile slope,
   792  * @todo When checking for the tile slope,
   795  * distingush between "Flat land required" and "land sloped in wrong direction"
   793  * distingush between "Flat land required" and "land sloped in wrong direction"
   796  */
   794  */
   797 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   795 CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   798 {
   796 {
   799 	CommandCost cost;
       
   800 	Slope tileh;
       
   801 
       
   802 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   797 	DiagDirection dir = Extract<DiagDirection, 0>(p1);
   803 	RoadType rt = (RoadType)GB(p1, 2, 2);
   798 	RoadType rt = (RoadType)GB(p1, 2, 2);
   804 
   799 
   805 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   800 	if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
   806 
   801 
   807 	tileh = GetTileSlope(tile, NULL);
   802 	Slope tileh = GetTileSlope(tile, NULL);
   808 	if (tileh != SLOPE_FLAT && (
   803 	if (tileh != SLOPE_FLAT && (
   809 				!_patches.build_on_slopes ||
   804 				!_patches.build_on_slopes ||
   810 				IsSteepSlope(tileh) ||
   805 				IsSteepSlope(tileh) ||
   811 				!CanBuildDepotByTileh(dir, tileh)
   806 				!CanBuildDepotByTileh(dir, tileh)
   812 			)) {
   807 			)) {
   813 		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   808 		return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   814 	}
   809 	}
   815 
   810 
   816 	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   811 	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   817 	if (CmdFailed(cost)) return CMD_ERROR;
   812 	if (CmdFailed(cost)) return CMD_ERROR;
   818 
   813 
   819 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   814 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
   820 
   815 
   821 	Depot *dep = new Depot(tile);
   816 	Depot *dep = new Depot(tile);
   832 	return cost.AddCost(_price.build_road_depot);
   827 	return cost.AddCost(_price.build_road_depot);
   833 }
   828 }
   834 
   829 
   835 static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
   830 static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
   836 {
   831 {
   837 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
   832 	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
   838 		return CMD_ERROR;
       
   839 
   833 
   840 	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
   834 	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
   841 
   835 
   842 	if (flags & DC_EXEC) {
   836 	if (flags & DC_EXEC) {
   843 		DoClearSquare(tile);
   837 		DoClearSquare(tile);
   966 /**
   960 /**
   967  * Draws the catenary for the given tile
   961  * Draws the catenary for the given tile
   968  * @param ti   information about the tile (slopes, height etc)
   962  * @param ti   information about the tile (slopes, height etc)
   969  * @param tram the roadbits for the tram
   963  * @param tram the roadbits for the tram
   970  */
   964  */
   971 void DrawTramCatenary(TileInfo *ti, RoadBits tram)
   965 void DrawTramCatenary(const TileInfo *ti, RoadBits tram)
   972 {
   966 {
   973 	/* Do not draw catenary if it is invisible */
   967 	/* Do not draw catenary if it is invisible */
   974 	if (IsInvisibilitySet(TO_CATENARY)) return;
   968 	if (IsInvisibilitySet(TO_CATENARY)) return;
   975 
   969 
   976 	/* Don't draw the catenary under a low bridge */
   970 	/* Don't draw the catenary under a low bridge */
  1001  * @param ti  the tile to draw on
   995  * @param ti  the tile to draw on
  1002  * @param dx  the offset from the top of the BB of the tile
   996  * @param dx  the offset from the top of the BB of the tile
  1003  * @param dy  the offset from the top of the BB of the tile
   997  * @param dy  the offset from the top of the BB of the tile
  1004  * @param h   the height of the sprite to draw
   998  * @param h   the height of the sprite to draw
  1005  */
   999  */
  1006 static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h)
  1000 static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h)
  1007 {
  1001 {
  1008 	int x = ti->x | dx;
  1002 	int x = ti->x | dx;
  1009 	int y = ti->y | dy;
  1003 	int y = ti->y | dy;
  1010 	byte z = ti->z;
  1004 	byte z = ti->z;
  1011 	if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
  1005 	if (ti->tileh != SLOPE_FLAT) z = GetSlopeZ(x, y);
  1014 
  1008 
  1015 /**
  1009 /**
  1016  * Draw ground sprite and road pieces
  1010  * Draw ground sprite and road pieces
  1017  * @param ti TileInfo
  1011  * @param ti TileInfo
  1018  */
  1012  */
  1019 static void DrawRoadBits(TileInfo* ti)
  1013 static void DrawRoadBits(TileInfo *ti)
  1020 {
  1014 {
  1021 	RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
  1015 	RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
  1022 	RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
  1016 	RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
  1023 
  1017 
  1024 	const DrawRoadTileStruct *drts;
       
  1025 	SpriteID image = 0;
  1018 	SpriteID image = 0;
  1026 	SpriteID pal = PAL_NONE;
  1019 	SpriteID pal = PAL_NONE;
  1027 	Roadside roadside;
       
  1028 
  1020 
  1029 	if (ti->tileh != SLOPE_FLAT) {
  1021 	if (ti->tileh != SLOPE_FLAT) {
  1030 		DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
  1022 		DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
  1031 
  1023 
  1032 		/* DrawFoundation() modifies ti.
  1024 		/* DrawFoundation() modifies ti.
  1034 		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
  1026 		if (ti->tileh != SLOPE_FLAT) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
  1035 	}
  1027 	}
  1036 
  1028 
  1037 	if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
  1029 	if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
  1038 
  1030 
  1039 	roadside = GetRoadside(ti->tile);
  1031 	Roadside roadside = GetRoadside(ti->tile);
  1040 
  1032 
  1041 	if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
  1033 	if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
  1042 		image += 19;
  1034 		image += 19;
  1043 	} else {
  1035 	} else {
  1044 		switch (roadside) {
  1036 		switch (roadside) {
  1094 
  1086 
  1095 	/* If there are no road bits, return, as there is nothing left to do */
  1087 	/* If there are no road bits, return, as there is nothing left to do */
  1096 	if (CountBits(road) < 2) return;
  1088 	if (CountBits(road) < 2) return;
  1097 
  1089 
  1098 	/* Draw extra details. */
  1090 	/* Draw extra details. */
  1099 	for (drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
  1091 	for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
  1100 		DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
  1092 		DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
  1101 	}
  1093 	}
  1102 }
  1094 }
  1103 
  1095 
  1104 static void DrawTile_Road(TileInfo *ti)
  1096 static void DrawTile_Road(TileInfo *ti)
  1107 		case ROAD_TILE_NORMAL:
  1099 		case ROAD_TILE_NORMAL:
  1108 			DrawRoadBits(ti);
  1100 			DrawRoadBits(ti);
  1109 			break;
  1101 			break;
  1110 
  1102 
  1111 		case ROAD_TILE_CROSSING: {
  1103 		case ROAD_TILE_CROSSING: {
  1112 			SpriteID image;
  1104 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
       
  1105 
       
  1106 			SpriteID image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
  1113 			SpriteID pal = PAL_NONE;
  1107 			SpriteID pal = PAL_NONE;
  1114 			Roadside roadside = GetRoadside(ti->tile);
       
  1115 
       
  1116 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
       
  1117 
       
  1118 			image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
       
  1119 
  1108 
  1120 			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
  1109 			if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
  1121 			if (IsCrossingBarred(ti->tile)) image += 2;
  1110 			if (IsCrossingBarred(ti->tile)) image += 2;
       
  1111 
       
  1112 			Roadside roadside = GetRoadside(ti->tile);
  1122 
  1113 
  1123 			if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
  1114 			if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
  1124 				image += 8;
  1115 				image += 8;
  1125 			} else {
  1116 			} else {
  1126 				switch (roadside) {
  1117 				switch (roadside) {
  1139 			break;
  1130 			break;
  1140 		}
  1131 		}
  1141 
  1132 
  1142 		default:
  1133 		default:
  1143 		case ROAD_TILE_DEPOT: {
  1134 		case ROAD_TILE_DEPOT: {
  1144 			const DrawTileSprites* dts;
       
  1145 			const DrawTileSeqStruct* dtss;
       
  1146 			SpriteID palette;
       
  1147 
       
  1148 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
  1135 			if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
  1149 
  1136 
  1150 			palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
  1137 			SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
  1151 
  1138 
       
  1139 			const DrawTileSprites *dts;
  1152 			if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
  1140 			if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
  1153 				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
  1141 				dts =  &_tram_depot[GetRoadDepotDirection(ti->tile)];
  1154 			} else {
  1142 			} else {
  1155 				dts =  &_road_depot[GetRoadDepotDirection(ti->tile)];
  1143 				dts =  &_road_depot[GetRoadDepotDirection(ti->tile)];
  1156 			}
  1144 			}
  1158 			DrawGroundSprite(dts->ground.sprite, PAL_NONE);
  1146 			DrawGroundSprite(dts->ground.sprite, PAL_NONE);
  1159 
  1147 
  1160 			/* End now if buildings are invisible */
  1148 			/* End now if buildings are invisible */
  1161 			if (IsInvisibilitySet(TO_BUILDINGS)) break;
  1149 			if (IsInvisibilitySet(TO_BUILDINGS)) break;
  1162 
  1150 
  1163 			for (dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
  1151 			for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
  1164 				SpriteID image = dtss->image.sprite;
  1152 				SpriteID image = dtss->image.sprite;
  1165 				SpriteID pal;
  1153 				SpriteID pal;
  1166 
  1154 
  1167 				if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
  1155 				if (!IsTransparencySet(TO_BUILDINGS) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
  1168 					pal = palette;
  1156 					pal = palette;
  1185 }
  1173 }
  1186 
  1174 
  1187 void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
  1175 void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
  1188 {
  1176 {
  1189 	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
  1177 	SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
  1190 	const DrawTileSprites* dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
  1178 	const DrawTileSprites *dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
  1191 	const DrawTileSeqStruct* dtss;
       
  1192 
  1179 
  1193 	x += 33;
  1180 	x += 33;
  1194 	y += 17;
  1181 	y += 17;
  1195 
  1182 
  1196 	DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
  1183 	DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
  1197 
  1184 
  1198 	for (dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
  1185 	for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
  1199 		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
  1186 		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
  1200 		SpriteID image = dtss->image.sprite;
  1187 		SpriteID image = dtss->image.sprite;
  1201 
  1188 
  1202 		DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
  1189 		DrawSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE, x + pt.x, y + pt.y);
  1203 	}
  1190 	}
  1273 			break;
  1260 			break;
  1274 	}
  1261 	}
  1275 
  1262 
  1276 	if (IsRoadDepot(tile)) return;
  1263 	if (IsRoadDepot(tile)) return;
  1277 
  1264 
  1278 	const Town* t = ClosestTownFromTile(tile, (uint)-1);
  1265 	const Town *t = ClosestTownFromTile(tile, (uint)-1);
  1279 	if (!HasRoadWorks(tile)) {
  1266 	if (!HasRoadWorks(tile)) {
  1280 		HouseZonesBits grp = HZB_TOWN_EDGE;
  1267 		HouseZonesBits grp = HZB_TOWN_EDGE;
  1281 
  1268 
  1282 		if (t != NULL) {
  1269 		if (t != NULL) {
  1283 			grp = GetTownRadiusGroup(t, tile);
  1270 			grp = GetTownRadiusGroup(t, tile);