Changeset - r27436:b0ef5dbb29c2
[Not reviewed]
master
0 1 0
Rubidium - 17 months ago 2023-05-24 20:58:21
rubidium@openttd.org
Codechange: use std::string over strecat to create the RV capacity string
1 file changed with 4 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/roadveh_gui.cpp
Show inline comments
 
@@ -38,41 +38,36 @@ void DrawRoadVehDetails(const Vehicle *v
 
	DrawString(r.left, r.right, y, STR_VEHICLE_INFO_BUILT_VALUE);
 
	y += FONT_HEIGHT_NORMAL;
 

	
 
	if (v->HasArticulatedPart()) {
 
		CargoArray max_cargo{};
 
		StringID subtype_text[NUM_CARGO];
 
		char capacity[512];
 

	
 
		memset(subtype_text, 0, sizeof(subtype_text));
 

	
 
		for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
 
			max_cargo[u->cargo_type] += u->cargo_cap;
 
			if (u->cargo_cap > 0) {
 
				StringID text = GetCargoSubtypeText(u);
 
				if (text != STR_EMPTY) subtype_text[u->cargo_type] = text;
 
			}
 
		}
 

	
 
		GetString(capacity, STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY, lastof(capacity));
 
		std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY);
 

	
 
		bool first = true;
 
		for (CargoID i = 0; i < NUM_CARGO; i++) {
 
			if (max_cargo[i] > 0) {
 
				char buffer[128];
 
				if (!first) capacity += ", ";
 

	
 
				SetDParam(0, i);
 
				SetDParam(1, max_cargo[i]);
 
				GetString(buffer, STR_JUST_CARGO, lastof(buffer));
 

	
 
				if (!first) strecat(capacity, ", ", lastof(capacity));
 
				strecat(capacity, buffer, lastof(capacity));
 
				capacity += GetString(STR_JUST_CARGO);
 

	
 
				if (subtype_text[i] != 0) {
 
					GetString(buffer, subtype_text[i], lastof(buffer));
 
					strecat(capacity, buffer, lastof(capacity));
 
					capacity += GetString(subtype_text[i]);
 
				}
 

	
 
				first = false;
 
			}
 
		}
 

	
0 comments (0 inline, 0 general)