mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-26 05:34:12 +01:00
Codechange: HighScore sorting to use std::vector (#14779)
Replaces the fixed-size array for company sorting with a std::vector and updates sorting to use std::ranges::sort. This removes the need for manual count management.
This commit is contained in:
@@ -87,20 +87,19 @@ static bool HighScoreSorter(const Company * const &a, const Company * const &b)
|
||||
*/
|
||||
int8_t SaveHighScoreValueNetwork()
|
||||
{
|
||||
const Company *cl[MAX_COMPANIES];
|
||||
size_t count = 0;
|
||||
std::vector<const Company *> cl;
|
||||
int8_t local_company_place = -1;
|
||||
|
||||
/* Sort all active companies with the highest score first */
|
||||
for (const Company *c : Company::Iterate()) cl[count++] = c;
|
||||
for (const Company *c : Company::Iterate()) cl.push_back(c);
|
||||
|
||||
std::sort(std::begin(cl), std::begin(cl) + count, HighScoreSorter);
|
||||
std::ranges::sort(cl, HighScoreSorter);
|
||||
|
||||
/* Clear the high scores from the previous network game. */
|
||||
auto &highscores = _highscore_table[SP_MULTIPLAYER];
|
||||
std::fill(highscores.begin(), highscores.end(), HighScore{});
|
||||
|
||||
for (size_t i = 0; i < count && i < highscores.size(); i++) {
|
||||
for (size_t i = 0; i < cl.size() && i < highscores.size(); i++) {
|
||||
const Company *c = cl[i];
|
||||
auto &highscore = highscores[i];
|
||||
highscore.name = GetString(STR_HIGHSCORE_NAME, c->index, c->index); // get manager/company name string
|
||||
|
||||
Reference in New Issue
Block a user