Changeset - r26780:68ae5eb97708
[Not reviewed]
master
0 4 0
Francis Herne - 23 months ago 2023-01-16 17:51:34
mail@flherne.uk
Fix #10362: NewGRF bridges without speed limits.

For bridges, a max speed of 0xFFFF (i.e. no effective limit)
is no longer displayed as a limit in the UI.

A max speed of 0 is also considered unlimited, for similarity to the
roadtype and railtype interface.
4 files changed with 33 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/bridge_gui.cpp
Show inline comments
 
@@ -130,6 +130,23 @@ private:
 
		this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
 
	}
 

	
 
	/**
 
	 * Get the StringID to draw in the selection list and set the appropriate DParams.
 
	 * @param bridge_data the bridge to get the StringID of.
 
	 * @return the StringID.
 
	 */
 
	StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
 
	{
 
		SetDParam(0, bridge_data.spec->material);
 
		SetDParam(1, bridge_data.spec->speed);
 
		SetDParam(2, bridge_data.cost);
 
		/* If the bridge has no meaningful speed limit, don't display it. */
 
		if (bridge_data.spec->speed == UINT16_MAX) {
 
			return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME : STR_SELECT_BRIDGE_INFO_NAME_COST;
 
		}
 
		return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
 
	}
 

	
 
public:
 
	BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList *bl) : Window(desc),
 
		start_tile(start),
 
@@ -183,14 +200,9 @@ public:
 
			case WID_BBS_BRIDGE_LIST: {
 
				Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
 
				Dimension text_dim   = {0, 0}; // Biggest text dimension
 
				for (int i = 0; i < (int)this->bridges->size(); i++) {
 
					const BridgeSpec *b = this->bridges->at(i).spec;
 
					sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));
 

	
 
					SetDParam(2, this->bridges->at(i).cost);
 
					SetDParam(1, b->speed);
 
					SetDParam(0, b->material);
 
					text_dim = maxdim(text_dim, GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
 
				for (const BuildBridgeData &bridge_data : *this->bridges) {
 
					sprite_dim = maxdim(sprite_dim, GetSpriteSize(bridge_data.spec->sprite));
 
					text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
 
				}
 
				sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
 
				text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
 
@@ -224,15 +236,10 @@ public:
 
			case WID_BBS_BRIDGE_LIST: {
 
				Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
 
				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
 
					const BridgeSpec *b = this->bridges->at(i).spec;
 

	
 
					SetDParam(2, this->bridges->at(i).cost);
 
					SetDParam(1, b->speed);
 
					SetDParam(0, b->material);
 

	
 
					const BuildBridgeData &bridge_data = this->bridges->at(i);
 
					const BridgeSpec *b = bridge_data.spec;
 
					DrawSprite(b->sprite, b->pal, tr.left, tr.bottom - GetSpriteSize(b->sprite).height);
 
					DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false),
 
							_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO);
 
					DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false), GetBridgeSelectString(bridge_data));
 
					tr = tr.Translate(0, this->resize.step_height);
 
				}
 
				break;
src/lang/english.txt
Show inline comments
 
@@ -2698,8 +2698,10 @@ STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_IN
 
STR_SELECT_RAIL_BRIDGE_CAPTION                                  :{WHITE}Select Rail Bridge
 
STR_SELECT_ROAD_BRIDGE_CAPTION                                  :{WHITE}Select Road Bridge
 
STR_SELECT_BRIDGE_SELECTION_TOOLTIP                             :{BLACK}Bridge selection - click on your preferred bridge to build it
 
STR_SELECT_BRIDGE_INFO                                          :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG}
 
STR_SELECT_BRIDGE_SCENEDIT_INFO                                 :{GOLD}{STRING},{} {VELOCITY}
 
STR_SELECT_BRIDGE_INFO_NAME                                     :{GOLD}{STRING}
 
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED                           :{GOLD}{STRING},{} {VELOCITY}
 
STR_SELECT_BRIDGE_INFO_NAME_COST                                :{GOLD}{0:STRING},{} {WHITE}{2:CURRENCY_LONG}
 
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST                      :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG}
 
STR_BRIDGE_NAME_SUSPENSION_STEEL                                :Suspension, Steel
 
STR_BRIDGE_NAME_GIRDER_STEEL                                    :Girder, Steel
 
STR_BRIDGE_NAME_CANTILEVER_STEEL                                :Cantilever, Steel
src/newgrf.cpp
Show inline comments
 
@@ -2190,7 +2190,7 @@ static ChangeInfoResult BridgeChangeInfo
 

	
 
			case 0x0A: // Maximum length
 
				bridge->max_length = buf->ReadByte();
 
				if (bridge->max_length > 16) bridge->max_length = 0xFFFF;
 
				if (bridge->max_length > 16) bridge->max_length = UINT16_MAX;
 
				break;
 

	
 
			case 0x0B: // Cost factor
 
@@ -2199,6 +2199,7 @@ static ChangeInfoResult BridgeChangeInfo
 

	
 
			case 0x0C: // Maximum speed
 
				bridge->speed = buf->ReadWord();
 
				if (bridge->speed == 0) bridge->speed = UINT16_MAX;
 
				break;
 

	
 
			case 0x0D: { // Bridge sprite tables
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1757,12 +1757,16 @@ static void GetTileDesc_TunnelBridge(Til
 

	
 
		if (!IsTunnel(tile)) {
 
			uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
 
			/* rail speed special-cases 0 as unlimited, hides display of limit etc. */
 
			if (spd == UINT16_MAX) spd = 0;
 
			if (td->rail_speed == 0 || spd < td->rail_speed) {
 
				td->rail_speed = spd;
 
			}
 
		}
 
	} else if (tt == TRANSPORT_ROAD && !IsTunnel(tile)) {
 
		uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
 
		/* road speed special-cases 0 as unlimited, hides display of limit etc. */
 
		if (spd == UINT16_MAX) spd = 0;
 
		if (road_rt != INVALID_ROADTYPE && (td->road_speed == 0 || spd < td->road_speed)) td->road_speed = spd;
 
		if (tram_rt != INVALID_ROADTYPE && (td->tram_speed == 0 || spd < td->tram_speed)) td->tram_speed = spd;
 
	}
0 comments (0 inline, 0 general)