Skip to content

Commit 742dd07

Browse files
authored
Allow Display Name to be used in Kills Stats by Ship Class (#6791)
* Allow Display Name to be used in Kills Stats by Ship Class Currently, the display that is shown for kills by ship type does not use display name of the ship class, which makes the ship classes look different than the other areas where they are displayed throughout the game. This PR fixes that by using display name when rendering the kill stats. Note, this PR does not edit the pilot file structure at all, it simply just tunes how the names are displayed/rendered. Importantly though, display names do not have to be unique, while the ship class names do. Thus, this PR also consolidates the number of kills of ship classes with the same display name (For example, FotG uses classes like `X-wing#Red` and `X-wing#Blue`, but both have the same display name of `X-wing`, so this consolidation means FSO will simple display `X-wing` with the sum. Overall, mods not using display name will be unaffected, while mods that do use display name will now have it properly work in the barracks and debrief rendering. Tested and works as expected. * remove flag for now * move assert * use handy get_display_name
1 parent f1a25ab commit 742dd07

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

code/menuui/barracks.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,25 +451,34 @@ void barracks_init_stats(scoring_struct *stats)
451451
// Goober5000 - make sure we have room for all ships
452452
Assert((Num_stat_lines + Ship_info.size()) < Max_stat_lines);
453453

454+
// wookieejedi - Show kills by ship type, but if using display name
455+
// then consolidate values for similarly named entries
456+
std::map<SCP_string, int, SCP_string_lcase_less_than> kill_map;
454457
i = 0;
455458
for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); i++, ++it) {
456459
if (stats->kills[i]) {
457-
Assert(Num_stat_lines < Max_stat_lines);
458-
459-
// Goober5000 - in case above Assert isn't triggered (such as in non-debug builds)
460-
if (Num_stat_lines < Max_stat_lines)
461-
{
462-
Assert(strlen(it->name) + 1 < STAT_COLUMN1_W);
463-
sprintf(Stat_labels[Num_stat_lines], NOX("%s:"), it->name);
464-
sprintf(Stats[Num_stat_lines], "%d", stats->kills[i]);
465-
Num_stat_lines++;
466-
}
467-
468-
// work out the total score from ship kills
460+
// wookieejedi - consolidate by display name or ship class name
461+
const char* name_key = it->get_display_name();
462+
Assert(strlen(name_key) + 1 < STAT_COLUMN1_W);
463+
kill_map[name_key] += stats->kills[i];
469464
score_from_kills += stats->kills[i] * it->score;
470465
}
471466
}
472467

468+
// wookieejedi - now display the kills per ship type
469+
for (const auto& [name, count] : kill_map) {
470+
Assert(Num_stat_lines < Max_stat_lines);
471+
// Goober5000 - in case above Assert isn't triggered (such as in non-debug builds)
472+
if (Num_stat_lines >= Max_stat_lines) {
473+
break;
474+
}
475+
476+
Assert(name.length() + 1 < STAT_COLUMN1_W);
477+
sprintf(Stat_labels[Num_stat_lines], NOX("%s:"), name.c_str());
478+
sprintf(Stats[Num_stat_lines], "%d", count);
479+
Num_stat_lines++;
480+
}
481+
473482
// add the score from kills
474483
Assert((Num_stat_lines + 1) < Max_stat_lines);
475484
STRCPY1(Stat_labels[Num_stat_lines], XSTR("Score from kills only:", 1636));

code/missionui/missiondebrief.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,9 @@ void debrief_setup_ship_kill_stats(int /*stage_num*/)
17211721

17221722
auto stats_type = ( Current_stage == DEBRIEF_MISSION_KILLS ) ? StatsType::MISSION_STATS : StatsType::ALL_TIME_EVER_STATS;
17231723

1724+
// wookieejedi - Show kills by ship type, but if using display name
1725+
// then consolidate values for similarly named entries
1726+
std::map<SCP_string, int, SCP_string_lcase_less_than> kill_map;
17241727
Num_text_lines = 0;
17251728
i = 0;
17261729
for ( auto it = Ship_info.begin(); it != Ship_info.end(); i++, ++it ) {
@@ -1732,12 +1735,16 @@ void debrief_setup_ship_kill_stats(int /*stage_num*/)
17321735
continue;
17331736
}
17341737

1738+
// wookieejedi - consolidate by display name or ship class name
1739+
const char* name_key = it->get_display_name();
1740+
kill_map[name_key] += num_kills;
1741+
}
17351742

1743+
// wookieejedi - now copy into Debrief_stats_kills[] for display
1744+
for (const auto& [name, count] : kill_map) {
17361745
kill_info = &Debrief_stats_kills[Num_text_lines++];
1737-
1738-
kill_info->num = num_kills;
1739-
1740-
strcpy_s(kill_info->text, it->name);
1746+
kill_info->num = count;
1747+
strcpy_s(kill_info->text, name.c_str());
17411748
strcat_s(kill_info->text, NOX(":"));
17421749
}
17431750

0 commit comments

Comments
 (0)