diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 797ead1..d02aeee 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -36,6 +36,8 @@ static BridgeType _last_railbridge_type = 0; /** The type of the last built road bridge */ static BridgeType _last_roadbridge_type = 0; +bool _bridge_catenary_flag = true; + /** * Carriage for the data we need if we want to build a bridge */ @@ -117,7 +119,7 @@ private: case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->Get(i)->index; break; default: break; } - DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index, + DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index | (_bridge_catenary_flag << 17), CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge); } @@ -358,10 +360,12 @@ static WindowDesc _build_bridge_desc( * @param transport_type The transport type * @param road_rail_type The road/rail type */ -void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type) +void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, bool catenary_flag) { DeleteWindowByClass(WC_BUILD_BRIDGE); + _bridge_catenary_flag = catenary_flag; + /* Data type for the bridge. * Bit 16,15 = transport type, * 14..8 = road/rail types, diff --git a/src/bridge_map.h b/src/bridge_map.h index 74c6974..426bafa 100644 --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -116,6 +116,19 @@ static inline void SetBridgeMiddle(TileIndex t, Axis a) SetBit(_m[t].type, 2 + a); } + +static inline void SetBridgeRoadTramCatenary(TileIndex t, bool b) +{ + assert(IsTileType(t, MP_TUNNELBRIDGE)); + SB(_m[t].m1, 7, 1, b ? 1 : 0); +} + +static inline bool HasBridgeRoadTramCatenary(TileIndex t) +{ + return GB(_m[t].m1, 7, 1); +} + + /** * Generic part to make a bridge ramp for both roads and rails. * @param t the tile to make a bridge ramp @@ -148,12 +161,13 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D * @param d the direction this ramp must be facing * @param r the road type of the bridge */ -static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r) +static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r, bool catenary_flag = false) { MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0); SetRoadOwner(t, ROADTYPE_ROAD, owner_road); if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram); SetRoadTypes(t, r); + SetBridgeRoadTramCatenary(t, catenary_flag); } /** diff --git a/src/gui.h b/src/gui.h index 39f1ea6..eb2961d 100644 --- a/src/gui.h +++ b/src/gui.h @@ -61,7 +61,7 @@ void ShowExtraViewPortWindow(TileIndex tile = INVALID_TILE); void ShowExtraViewPortWindowForTileUnderCursor(); /* bridge_gui.cpp */ -void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type); +void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type, bool catenary_flag = false); void ShowBuildIndustryWindow(); void ShowFoundTownWindow(); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 2010f9b..e5bf3ac 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -636,7 +636,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, owner = GetTileOwner(tile); Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR; DirtyCompanyInfrastructureWindows(owner); - MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM)); + MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypes(tile), GetTownIndex(tile), GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), HasCatenary(tile)); DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile); } break; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index aa445eb..1c84dbb 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -477,6 +477,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi * @param p1 bit 0..3 road pieces to build (RoadBits) * bit 4..5 road type * bit 6..7 disallowed directions to toggle + * bit 8 catenary * @param p2 the town that is building the road (0 if not applicable) * @param text unused * @return the cost of this operation or an error @@ -515,6 +516,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; DisallowedRoadDirections toggle_drd = Extract(p1); + bool _catenary_flag = HasBit(p1, 8); Slope tileh = GetTileSlope(tile); @@ -749,6 +751,7 @@ do_clear:; if (rt == ROADTYPE_ROAD) SetTownIndex(tile, p2); } if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt); + SetCatenary(tile, _catenary_flag); break; } @@ -777,7 +780,7 @@ do_clear:; break; default: - MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, company, company); + MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, company, company, _catenary_flag); break; } @@ -794,7 +797,6 @@ do_clear:; SetDisallowedRoadDirections(tile, IsStraightRoad(existing) ? GetDisallowedRoadDirections(tile) ^ toggle_drd : DRD_NONE); } - MarkTileDirtyByTile(tile); } return cost; @@ -827,6 +829,7 @@ static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir) * - p2 = (bit 6) - defines two different behaviors for this command: * - 0 = Build up to an obstacle. Do not build the first and last roadbits unless they can be connected to something, or if we are building a single tile * - 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts + * - p2 = (bit 7) - catenary * @param text unused * @return the cost of this operation or an error */ @@ -886,8 +889,8 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir)); if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir); } - - CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD); + bool _has_catenary = HasBit(p2, 7); + CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits | _has_catenary << 8 , 0, flags, CMD_BUILD_ROAD); if (ret.Failed()) { last_error = ret; if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) { @@ -1298,7 +1301,7 @@ static void DrawRoadBits(TileInfo *ti) return; } - if (tram != ROAD_NONE) DrawTramCatenary(ti, tram); + if (HasCatenary(ti->tile)) DrawTramCatenary(ti, tram); /* Return if full detail is disabled, or we are zoomed fully out. */ if (!HasBit(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return; @@ -1388,7 +1391,7 @@ static void DrawTile_Road(TileInfo *ti) if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) { DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal); - DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile)); + if (HasCatenary(ti->tile)) DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile)); } if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti); break; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 92c660e..7dc8dc8 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -60,6 +60,7 @@ DECLARE_ENUM_AS_BIT_SET(RoadFlags) static RoadFlags _place_road_flag; static RoadType _cur_roadtype; +bool _catenary_flag; static DiagDirection _road_depot_orientation; static DiagDirection _road_station_picker_orientation; @@ -231,6 +232,7 @@ static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, u ddir -= DIAGDIR_END; // Adjust picker result to actual direction. } p2 |= ddir << 6; // Set the DiagDirecion into p2 bits 6 and 7. + SB(p2, 9, 1, _catenary_flag); // set _catenary_flag into p2 bit 9. TileArea ta(start_tile, end_tile); CommandContainer cmdcont = { ta.tile, (uint32)(ta.w | ta.h << 8), p2, cmd, CcRoadStop, "" }; @@ -610,7 +612,7 @@ struct BuildRoadToolbarWindow : Window { default: NOT_REACHED(); case DDSP_BUILD_BRIDGE: if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace(); - ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype)); + ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype), _catenary_flag); break; case DDSP_DEMOLISH_AREA: @@ -626,7 +628,7 @@ struct BuildRoadToolbarWindow : Window { * not the 3rd bit set) */ _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3)); - DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), + DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5) | (_catenary_flag << 7), _remove_button_clicked ? CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) : CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D); @@ -802,10 +804,11 @@ static WindowDesc _build_tramway_desc( * * @return newly opened road toolbar, or NULL if the toolbar could not be opened. */ -Window *ShowBuildRoadToolbar(RoadType roadtype) +Window *ShowBuildRoadToolbar(RoadType roadtype, bool catenary_flag) { if (!Company::IsValidID(_local_company)) return NULL; _cur_roadtype = roadtype; + _catenary_flag = catenary_flag; DeleteWindowByClass(WC_BUILD_TOOLBAR); return AllocateWindowDescFront(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD); diff --git a/src/road_gui.h b/src/road_gui.h index c56443c..dd61ce9 100644 --- a/src/road_gui.h +++ b/src/road_gui.h @@ -16,7 +16,7 @@ #include "tile_type.h" #include "direction_type.h" -struct Window *ShowBuildRoadToolbar(RoadType roadtype); +struct Window *ShowBuildRoadToolbar(RoadType roadtype, bool catenary_flag = false); struct Window *ShowBuildRoadScenToolbar(); void ConnectRoadToStructure(TileIndex tile, DiagDirection direction); diff --git a/src/road_map.h b/src/road_map.h index 6937302..a847568 100644 --- a/src/road_map.h +++ b/src/road_map.h @@ -251,6 +251,11 @@ static inline bool HasTownOwnedRoad(TileIndex t) return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN); } +static inline bool HasCatenary(TileIndex t) +{ + return GB(_m[t].m1, 7, 1); +} + /** Which directions are disallowed ? */ enum DisallowedRoadDirections { DRD_NONE, ///< None of the directions are disallowed @@ -286,6 +291,12 @@ static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirect SB(_m[t].m5, 4, 2, drd); } +static inline void SetCatenary(TileIndex t, bool b) +{ + assert(IsNormalRoad(t)); + SB(_m[t].m1, 7, 1, b ? 1 : 0); +} + /** * Get the road axis of a level crossing. * @param t The tile to query. @@ -550,7 +561,7 @@ RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge * @param road New owner of road. * @param tram New owner of tram tracks. */ -static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram) +static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram, bool catenary_flag = false) { SetTileType(t, MP_ROAD); SetTileOwner(t, road); @@ -561,6 +572,7 @@ static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, Tow SB(_me[t].m6, 2, 4, 0); _me[t].m7 = rot << 6; SetRoadOwner(t, ROADTYPE_TRAM, tram); + SetCatenary(t, catenary_flag); } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index eb90c29..b5ca448 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1759,6 +1759,11 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin bool reuse = (station_to_join != NEW_STATION); if (!reuse) station_to_join = INVALID_STATION; bool distant_join = (station_to_join != INVALID_STATION); + bool catenary_flag = HasBit(p2, 9); // the setting from the selected roadtype + bool cur_tile_catenary_flag = catenary_flag; // used to set catenary flag on any given tile + printf("CmdBuildRoadStop called %d ", tile); + printf("catenary_flag %d ", catenary_flag); + printf("\n"); uint8 width = (uint8)GB(p1, 0, 8); uint8 lenght = (uint8)GB(p1, 8, 8); @@ -1815,6 +1820,12 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin /* Check every tile in the area. */ TILE_AREA_LOOP(cur_tile, roadstop_area) { RoadTypes cur_rts = GetRoadTypes(cur_tile); + // don't remove existing catenary if present + if (HasCatenary(cur_tile)) { + cur_tile_catenary_flag = true; + } else { + cur_tile_catenary_flag = catenary_flag; + } Owner road_owner = HasBit(cur_rts, ROADTYPE_ROAD) ? GetRoadOwner(cur_tile, ROADTYPE_ROAD) : _current_company; Owner tram_owner = HasBit(cur_rts, ROADTYPE_TRAM) ? GetRoadOwner(cur_tile, ROADTYPE_TRAM) : _current_company; @@ -1851,7 +1862,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin } } - MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts | cur_rts, axis); + MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts | cur_rts, axis, cur_tile_catenary_flag); road_stop->MakeDriveThrough(); } else { /* Non-drive-through stop never overbuild and always count as two road bits. */ @@ -2013,6 +2024,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui uint8 width = (uint8)GB(p1, 0, 8); uint8 height = (uint8)GB(p1, 8, 8); bool keep_drive_through_roads = !HasBit(p2, 1); + bool keep_catenary = false; /* Check for incorrect width / height. */ if (width == 0 || height == 0) return CMD_ERROR; @@ -2030,6 +2042,11 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui TILE_AREA_LOOP(cur_tile, roadstop_area) { /* Make sure the specified tile is a road stop of the correct type */ if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue; + if (HasCatenary(cur_tile)) { + keep_catenary = true; + } else { + keep_catenary = false; + } /* Save information on to-be-restored roads before the stop is removed. */ RoadTypes rts = ROADTYPES_NONE; @@ -2057,7 +2074,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui /* Restore roads. */ if ((flags & DC_EXEC) && rts != ROADTYPES_NONE) { MakeRoadNormal(cur_tile, road_bits, rts, ClosestTownFromTile(cur_tile, UINT_MAX)->index, - road_owner[ROADTYPE_ROAD], road_owner[ROADTYPE_TRAM]); + road_owner[ROADTYPE_ROAD], road_owner[ROADTYPE_TRAM], keep_catenary); /* Update company infrastructure counts. */ RoadType rt; @@ -2902,7 +2919,7 @@ draw_default_foundation: if (HasBit(roadtypes, ROADTYPE_TRAM)) { Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y; DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE); - DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y); + if (HasRoadTramCatenary(ti->tile)) DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y); } if (IsRailWaypoint(ti->tile)) { diff --git a/src/station_map.h b/src/station_map.h index 7ca9bd7..8a101ad 100644 --- a/src/station_map.h +++ b/src/station_map.h @@ -521,6 +521,17 @@ static inline byte GetStationTileRandomBits(TileIndex t) return GB(_m[t].m3, 4, 4); } +static inline void SetRoadTramCatenary(TileIndex t, bool b) +{ + assert(IsTileType(t, MP_STATION)); + SB(_m[t].m1, 7, 1, b ? 1 : 0); +} + +static inline bool HasRoadTramCatenary(TileIndex t) +{ + return GB(_m[t].m1, 7, 1); +} + /** * Make the given tile a station tile. * @param t the tile to make a station tile @@ -604,12 +615,13 @@ static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopTyp * @param rt the roadtypes on this tile * @param a the direction of the roadstop */ -static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a) +static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a, bool catenary_flag) { MakeStation(t, station, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a); SetRoadTypes(t, rt); SetRoadOwner(t, ROADTYPE_ROAD, road); SetRoadOwner(t, ROADTYPE_TRAM, tram); + SetRoadTramCatenary(t, catenary_flag); } /** diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 45d751d..0f28fbd 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -891,7 +891,8 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w) DropDownList *list = new DropDownList(); /* Road is always visible and available. */ - *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, 0, false); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, 1, false); /* Tram is only visible when there will be a tram, and available when that has been introduced. */ Engine *e; @@ -899,7 +900,8 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w) if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue; - *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, 2, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)); + *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, 3, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)); break; } ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true); @@ -915,8 +917,19 @@ static CallBackFunction ToolbarBuildRoadClick(Window *w) */ static CallBackFunction MenuClickBuildRoad(int index) { - _last_built_roadtype = (RoadType)index; - ShowBuildRoadToolbar(_last_built_roadtype); + bool _catenary_flag = false; + if (index == 0) { + _last_built_roadtype = (RoadType)ROADTYPE_ROAD; + } else if (index == 1) { + _last_built_roadtype = (RoadType)ROADTYPE_ROAD; + _catenary_flag = true; + } else if (index == 2) { + _last_built_roadtype = (RoadType)ROADTYPE_TRAM; + } else if (index == 3) { + _last_built_roadtype = (RoadType)ROADTYPE_TRAM; + _catenary_flag = true; + } + ShowBuildRoadToolbar(_last_built_roadtype, _catenary_flag); return CBF_NONE; } diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 5f2534b..a93fa1a 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -515,8 +515,9 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u } Owner owner_road = HasBit(prev_roadtypes, ROADTYPE_ROAD) ? GetRoadOwner(tile_start, ROADTYPE_ROAD) : company; Owner owner_tram = HasBit(prev_roadtypes, ROADTYPE_TRAM) ? GetRoadOwner(tile_start, ROADTYPE_TRAM) : company; - MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes); - MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes); + bool catenary_flag = HasBit(p2, 17); // the setting from the selected roadtype + MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes, catenary_flag); + MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes, catenary_flag); break; } @@ -1087,7 +1088,7 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis * @param overlay do we want to still see the road? * @param head are we drawing bridge head? */ -static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bool head) +static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bool head, bool has_catenary) { static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } }; static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 }; @@ -1107,7 +1108,7 @@ static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bo } /* Do not draw catenary if it is set invisible */ - if (!IsInvisibilitySet(TO_CATENARY)) { + if (has_catenary && !IsInvisibilitySet(TO_CATENARY)) { AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE, x, y, size_x[offset], size_y[offset], 0x28, z, IsTransparencySet(TO_CATENARY)); @@ -1118,7 +1119,7 @@ static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bo StartSpriteCombine(); /* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */ - if (!IsInvisibilitySet(TO_CATENARY)) { + if (has_catenary && !IsInvisibilitySet(TO_CATENARY)) { AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE, x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z, IsTransparencySet(TO_CATENARY), front_bb_offset_x[offset], front_bb_offset_y[offset]); @@ -1193,7 +1194,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti) DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE); /* Do not draw wires if they are invisible */ - if (!IsInvisibilitySet(TO_CATENARY)) { + if (HasTunnelBridgeRoadTramCatenary(ti->tile) && !IsInvisibilitySet(TO_CATENARY)) { catenary = true; StartSpriteCombine(); AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR); @@ -1303,7 +1304,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti) offset += 2; } /* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */ - DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true); + DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true, HasBridgeRoadTramCatenary(ti->tile)); } EndSpriteCombine(); } else if (transport_type == TRANSPORT_RAIL) { @@ -1466,7 +1467,7 @@ void DrawBridgeMiddle(const TileInfo *ti) if (HasBit(rts, ROADTYPE_TRAM)) { /* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */ - DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false); + DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false, HasBridgeRoadTramCatenary(ti->tile)); } else { EndSpriteCombine(); StartSpriteCombine(); diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h index 0f7f17b..199033e 100644 --- a/src/tunnelbridge_map.h +++ b/src/tunnelbridge_map.h @@ -121,4 +121,16 @@ static inline TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t) return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE; } + +static inline void SetTunnelBridgeRoadTramCatenary(TileIndex t, bool b) +{ + assert(IsTileType(t, MP_TUNNELBRIDGE)); + SB(_m[t].m1, 7, 1, b ? 1 : 0); +} + +static inline bool HasTunnelBridgeRoadTramCatenary(TileIndex t) +{ + return GB(_m[t].m1, 7, 1); +} + #endif /* TUNNELBRIDGE_MAP_H */