* 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. */
| 265 | * @return String of accepted cargo, or nullopt if no cargo is accepted. |
| 266 | */ |
| 267 | std::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 | } |
no test coverage detected