* Draws the catenary for the RoadType of the given tile * @param ti information about the tile (slopes, height etc) * @param rt road type to draw catenary for * @param rb the roadbits for the tram */
| 1364 | * @param rb the roadbits for the tram |
| 1365 | */ |
| 1366 | void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb) |
| 1367 | { |
| 1368 | /* Don't draw the catenary under a low bridge */ |
| 1369 | if (IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) { |
| 1370 | int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile)); |
| 1371 | |
| 1372 | if (height <= GetTileMaxZ(ti->tile) + 1) return; |
| 1373 | } |
| 1374 | |
| 1375 | if (CountBits(rb) > 2) { |
| 1376 | /* On junctions we check whether neighbouring tiles also have catenary, and possibly |
| 1377 | * do not draw catenary towards those neighbours, which do not have catenary. */ |
| 1378 | RoadBits rb_new = ROAD_NONE; |
| 1379 | for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { |
| 1380 | if (rb & DiagDirToRoadBits(dir)) { |
| 1381 | TileIndex neighbour = TileAddByDiagDir(ti->tile, dir); |
| 1382 | if (MayHaveRoad(neighbour)) { |
| 1383 | RoadType rt_road = GetRoadTypeRoad(neighbour); |
| 1384 | RoadType rt_tram = GetRoadTypeTram(neighbour); |
| 1385 | |
| 1386 | if ((rt_road != INVALID_ROADTYPE && HasRoadCatenary(rt_road)) || |
| 1387 | (rt_tram != INVALID_ROADTYPE && HasRoadCatenary(rt_tram))) { |
| 1388 | rb_new |= DiagDirToRoadBits(dir); |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | if (CountBits(rb_new) >= 2) rb = rb_new; |
| 1394 | } |
| 1395 | |
| 1396 | const RoadTypeInfo *rti = GetRoadTypeInfo(rt); |
| 1397 | SpriteID front = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_FRONT); |
| 1398 | SpriteID back = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_BACK); |
| 1399 | |
| 1400 | if (front != 0 || back != 0) { |
| 1401 | if (front != 0) front += GetRoadSpriteOffset(ti->tileh, rb); |
| 1402 | if (back != 0) back += GetRoadSpriteOffset(ti->tileh, rb); |
| 1403 | } else if (ti->tileh != SLOPE_FLAT) { |
| 1404 | back = SPR_TRAMWAY_BACK_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1]; |
| 1405 | front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1]; |
| 1406 | } else { |
| 1407 | back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[rb]; |
| 1408 | front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[rb]; |
| 1409 | } |
| 1410 | |
| 1411 | /* Catenary uses 1st company colour to help identify owner. |
| 1412 | * For tiles with OWNER_TOWN or OWNER_NONE, recolour CC to grey as a neutral colour. */ |
| 1413 | Owner owner = GetRoadOwner(ti->tile, GetRoadTramType(rt)); |
| 1414 | PaletteID pal = (owner == OWNER_NONE || owner == OWNER_TOWN ? GetColourPalette(COLOUR_GREY) : GetCompanyPalette(owner)); |
| 1415 | uint8_t z_wires = (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT) + BB_HEIGHT_UNDER_BRIDGE; |
| 1416 | if (back != 0) { |
| 1417 | /* The "back" sprite contains the west, north and east pillars. |
| 1418 | * We cut the sprite at 3/8 of the west/east edges to create 3 sprites. |
| 1419 | * 3/8 is chosen so that sprites can somewhat graphically extend into the tile. */ |
| 1420 | static const int INF = 1000; ///< big number compared to sprite size |
| 1421 | static const SubSprite west = { -INF, -INF, -12, INF }; |
| 1422 | static const SubSprite north = { -12, -INF, 12, INF }; |
| 1423 | static const SubSprite east = { 12, -INF, INF, INF }; |
no test coverage detected