* Get a parsed string with most special stringcodes replaced by the string parameters. * @param builder The builder of the string. * @param string The ID of the string to parse. * @param args Arguments for the string. * @param case_index The "case index". This will only be set when FormatString wants to print the string in a different case. * @param game_script The string is
| 334 | * @param game_script The string is coming directly from a game script. |
| 335 | */ |
| 336 | void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script) |
| 337 | { |
| 338 | if (string == 0) { |
| 339 | GetStringWithArgs(builder, STR_UNDEFINED, args); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | StringIndexInTab index = GetStringIndex(string); |
| 344 | StringTab tab = GetStringTab(string); |
| 345 | |
| 346 | switch (tab) { |
| 347 | case TEXT_TAB_TOWN: |
| 348 | if (IsInsideMM(string, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_END) && !game_script) { |
| 349 | try { |
| 350 | GenerateTownNameString(builder, string - SPECSTR_TOWNNAME_START, args.GetNextParameter<uint32_t>()); |
| 351 | } catch (const std::runtime_error &e) { |
| 352 | Debug(misc, 0, "GetStringWithArgs: {}", e.what()); |
| 353 | builder += "(invalid string parameter)"; |
| 354 | } |
| 355 | return; |
| 356 | } |
| 357 | break; |
| 358 | |
| 359 | case TEXT_TAB_SPECIAL: |
| 360 | if (!game_script) { |
| 361 | try { |
| 362 | if (GetSpecialNameString(builder, string, args)) return; |
| 363 | } catch (const std::runtime_error &e) { |
| 364 | Debug(misc, 0, "GetStringWithArgs: {}", e.what()); |
| 365 | builder += "(invalid string parameter)"; |
| 366 | return; |
| 367 | } |
| 368 | } |
| 369 | break; |
| 370 | |
| 371 | case TEXT_TAB_OLD_CUSTOM: |
| 372 | /* Old table for custom names. This is no longer used */ |
| 373 | if (!game_script) { |
| 374 | FatalError("Incorrect conversion of custom name string."); |
| 375 | } |
| 376 | break; |
| 377 | |
| 378 | case TEXT_TAB_GAMESCRIPT_START: { |
| 379 | FormatString(builder, GetGameStringPtr(index), args, case_index, true); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | case TEXT_TAB_OLD_NEWGRF: |
| 384 | NOT_REACHED(); |
| 385 | |
| 386 | case TEXT_TAB_NEWGRF_START: { |
| 387 | FormatString(builder, GetGRFStringPtr(index), args, case_index); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | default: |
| 392 | break; |
| 393 | } |
no test coverage detected