MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BuildCargoAcceptanceString

Function BuildCargoAcceptanceString

src/cargotype.cpp:267–293  ·  view source on GitHub ↗

* Build comma-separated cargo acceptance string. * @param acceptance CargoArray filled with accepted cargo. * @param label Label to prefix cargo acceptance list. * @return String of accepted cargo, or nullopt if no cargo is accepted. */

Source from the content-addressed store, hash-verified

265 * @return String of accepted cargo, or nullopt if no cargo is accepted.
266 */
267std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
268{
269 std::string_view list_separator = GetListSeparator();
270
271 std::stringstream line;
272
273 bool found = false;
274 for (const CargoSpec *cs : _sorted_cargo_specs) {
275 CargoType cargo_type = cs->Index();
276 if (acceptance[cargo_type] > 0) {
277 /* Add a comma between each item. */
278 if (found) line << list_separator;
279 found = true;
280
281 /* If the accepted value is less than 8, show it in 1/8:ths */
282 if (acceptance[cargo_type] < 8) {
283 line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, acceptance[cargo_type], cs->name);
284 } else {
285 line << GetString(cs->name);
286 }
287 }
288 }
289
290 if (found) return GetString(label, line.str());
291
292 return std::nullopt;
293}

Callers 2

GetHouseInformationMethod · 0.85
OnInitMethod · 0.85

Calls 4

GetListSeparatorFunction · 0.85
GetStringFunction · 0.70
IndexMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected