Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roadtype catenary not shown over bridges #7958

Closed
danielplaumann opened this issue Jan 25, 2020 · 2 comments
Closed

Roadtype catenary not shown over bridges #7958

danielplaumann opened this issue Jan 25, 2020 · 2 comments
Labels
Milestone

Comments

@danielplaumann
Copy link

@danielplaumann danielplaumann commented Jan 25, 2020

Version of OpenTTD

20200124-master-gf88ac83408

Expected result

If a road type provides catenary graphics, they should be shown instead of default catenary.

Actual result

The new catenary graphics are shown on normal tiles but not on bridge tiles. Instead, the default catenary is shown on bridges.

Steps to reproduce

The attached grf defines catenary for ROAD (just a large red square) which shows the behaviour.
catenarytest.grf.zip

@nielsmh nielsmh added this to the 1.10.0 milestone Jan 25, 2020
@nielsmh nielsmh added bug NewGRF labels Feb 9, 2020
@nielsmh
Copy link
Contributor

@nielsmh nielsmh commented Feb 9, 2020

Screenshot using the attached test GRF:
image

The bridge does indeed not use the red square catenary graphics.

@nielsmh
Copy link
Contributor

@nielsmh nielsmh commented Feb 9, 2020

I looked at this, and it will require an annoyingly large refactor of DrawRoadTypeCatenary to make it usable for bridge surfaces too.

OpenTTD/src/road_cmd.cpp

Lines 1370 to 1427 in e340934

/**
* 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
*/
void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb)
{
/* Don't draw the catenary under a low bridge */
if (IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
if (height <= GetTileMaxZ(ti->tile) + 1) return;
}
if (CountBits(rb) > 2) {
/* On junctions we check whether neighbouring tiles also have catenary, and possibly
* do not draw catenary towards those neighbours, which do not have catenary. */
RoadBits rb_new = ROAD_NONE;
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
if (rb & DiagDirToRoadBits(dir)) {
TileIndex neighbour = TileAddByDiagDir(ti->tile, dir);
if (MayHaveRoad(neighbour)) {
RoadType rt_road = GetRoadTypeRoad(neighbour);
RoadType rt_tram = GetRoadTypeTram(neighbour);
if ((rt_road != INVALID_ROADTYPE && HasRoadCatenary(rt_road)) ||
(rt_tram != INVALID_ROADTYPE && HasRoadCatenary(rt_tram))) {
rb_new |= DiagDirToRoadBits(dir);
}
}
}
}
if (CountBits(rb_new) >= 2) rb = rb_new;
}
const RoadTypeInfo* rti = GetRoadTypeInfo(rt);
SpriteID front = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_FRONT);
SpriteID back = GetCustomRoadSprite(rti, ti->tile, ROTSG_CATENARY_BACK);
if (front != 0 || back != 0) {
if (front != 0) front += GetRoadSpriteOffset(ti->tileh, rb);
if (back != 0) back += GetRoadSpriteOffset(ti->tileh, rb);
} else if (ti->tileh != SLOPE_FLAT) {
back = SPR_TRAMWAY_BACK_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
front = SPR_TRAMWAY_FRONT_WIRES_SLOPED + _road_sloped_sprites[ti->tileh - 1];
} else {
back = SPR_TRAMWAY_BASE + _road_backpole_sprites_1[rb];
front = SPR_TRAMWAY_BASE + _road_frontwire_sprites_1[rb];
}
/* Catenary uses 1st company colour to help identify owner.
* For tiles with OWNER_TOWN or OWNER_NONE, recolour CC to grey as a neutral colour. */
Owner owner = GetRoadOwner(ti->tile, GetRoadTramType(rt));
PaletteID pal = (owner == OWNER_NONE || owner == OWNER_TOWN ? GENERAL_SPRITE_COLOUR(COLOUR_GREY) : COMPANY_SPRITE_COLOUR(owner));
if (back != 0) AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
if (front != 0) AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY));
}

The part in DrawBridgeRoadBit doesn't seem to have everything ready at least, and several of the parameters to DrawRoadTypeCatenary would have to be synthesized in some way.

/* Road catenary takes precedence over tram */
trans_back[3] = IsTransparencySet(TO_CATENARY);
trans_front[0] = IsTransparencySet(TO_CATENARY);
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
seq_back[3] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
seq_front[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
if (seq_back[3] == 0 || seq_front[0] == 0) {
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
} else {
seq_back[3] += 23 + offset;
seq_front[0] += 23 + offset;
}
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
seq_back[3] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
seq_front[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
if (seq_back[3] == 0 || seq_front[0] == 0) {
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
} else {
seq_back[3] += 23 + offset;
seq_front[0] += 23 + offset;
}
}

nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 9, 2020
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 9, 2020
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 9, 2020
nielsmh added a commit to nielsmh/OpenTTD that referenced this issue Feb 9, 2020
@nielsmh nielsmh closed this in 45838d0 Feb 9, 2020
LordAro added a commit to LordAro/OpenTTD that referenced this issue Feb 29, 2020
Berbe added a commit to Berbe/OpenTTD that referenced this issue Mar 6, 2020
Berbe added a commit to Berbe/OpenTTD that referenced this issue Mar 6, 2020
LordAro added a commit that referenced this issue Mar 31, 2020
douiwby added a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.