diff options
Diffstat (limited to 'src/bridge_gui.cpp')
-rw-r--r-- | src/bridge_gui.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 38ff698eb..77261932b 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -60,16 +60,14 @@ void CcBuildBridge(Commands cmd, const CommandCost &result, TileIndex end_tile, if (result.Failed()) return; if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile); - auto [tile, p1, p2, text] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_BRIDGE>::Args>(data); - - TransportType transport_type = Extract<TransportType, 15, 2>(p2); + auto [tile, tile_start, transport_type, bridge_type, road_rail_type] = EndianBufferReader::ToValue<CommandTraits<CMD_BUILD_BRIDGE>::Args>(data); if (transport_type == TRANSPORT_ROAD) { DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile)); ConnectRoadToStructure(end_tile, end_direction); - DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(p1)); - ConnectRoadToStructure(p1, start_direction); + DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(tile_start)); + ConnectRoadToStructure(tile_start, start_direction); } } @@ -86,7 +84,8 @@ private: /* Internal variables */ TileIndex start_tile; TileIndex end_tile; - uint32 type; + TransportType transport_type; + byte road_rail_type; GUIBridgeList *bridges; int bridgetext_offset; ///< Horizontal offset of the text describing the bridge properties in #WID_BBS_BRIDGE_LIST relative to the left edge. Scrollbar *vscroll; @@ -111,13 +110,13 @@ private: void BuildBridge(uint8 i) { - switch ((TransportType)(this->type >> 15)) { + switch (this->transport_type) { case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->at(i).index; break; case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->at(i).index; break; default: break; } Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, - this->end_tile, this->start_tile, this->type | this->bridges->at(i).index, {}); + this->end_tile, this->start_tile, this->transport_type, this->bridges->at(i).index, this->road_rail_type); } /** Sort the builable bridges */ @@ -134,19 +133,20 @@ private: } public: - BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc), + BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList *bl) : Window(desc), start_tile(start), end_tile(end), - type(br_type), + transport_type(transport_type), + road_rail_type(road_rail_type), bridges(bl) { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR); /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */ - this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION; - this->FinishInitNested(GB(br_type, 15, 2)); // Initializes 'this->bridgetext_offset'. + this->GetWidget<NWidgetCore>(WID_BBS_CAPTION)->widget_data = (transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION; + this->FinishInitNested(transport_type); // Initializes 'this->bridgetext_offset'. - this->parent = FindWindowById(WC_BUILD_TOOLBAR, GB(this->type, 15, 2)); + this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type); this->bridges->SetListing(this->last_sorting); this->bridges->SetSortFuncs(this->sorter_funcs); this->bridges->NeedResort(); @@ -361,12 +361,6 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo { CloseWindowByClass(WC_BUILD_BRIDGE); - /* Data type for the bridge. - * Bit 16,15 = transport type, - * 14..8 = road/rail types, - * 7..0 = type of bridge */ - uint32 type = (transport_type << 15) | (road_rail_type << 8); - /* The bridge length without ramps. */ const uint bridge_len = GetTunnelBridgeLength(start, end); @@ -382,14 +376,14 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo default: break; // water ways and air routes don't have bridge types } if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) { - Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, type | last_bridge_type, {}); + Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, road_rail_type); return; } /* only query bridge building possibility once, result is the same for all bridges! * returns CMD_ERROR on failure, and price on success */ StringID errmsg = INVALID_STRING_ID; - CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DC_QUERY_COST, end, start, type, {}); + CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DC_QUERY_COST, end, start, transport_type, 0, road_rail_type); GUIBridgeList *bl = nullptr; if (ret.Failed()) { @@ -449,7 +443,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo } if (bl != nullptr && bl->size() != 0) { - new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl); + new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, bl); } else { delete bl; ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE); |