diff options
author | tron <tron@openttd.org> | 2006-02-06 08:43:05 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-02-06 08:43:05 +0000 |
commit | 75a70e1def8c677d2340a49e9f12e4c2a5d65aee (patch) | |
tree | db814ae025cb69524c8983b4d9b946bfbeee38d3 | |
parent | 286876b9d7b56669a693a2d1046f5e3570c177b2 (diff) | |
download | openttd-75a70e1def8c677d2340a49e9f12e4c2a5d65aee.tar.xz |
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
-rw-r--r-- | players.c | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -1017,40 +1017,34 @@ static int CDECL HighScoreSorter(const void *a, const void *b) #define LAST_HS_ITEM lengthof(_highscore_table) - 1 int8 SaveHighScoreValueNetwork(void) { - Player *p, *player_sort[MAX_PLAYERS]; + const Player* p; + const Player* pl[MAX_PLAYERS]; size_t count = 0; int8 player = -1; /* Sort all active players with the highest score first */ - FOR_ALL_PLAYERS(p) { - if (p->is_active) - player_sort[count++] = p; - } - qsort(player_sort, count, sizeof(player_sort[0]), HighScoreSorter); + FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p; + qsort(pl, count, sizeof(pl[0]), HighScoreSorter); { - HighScore *hs; - Player* const *p_cur = &player_sort[0]; - uint8 i; + uint i; memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); /* Copy over Top5 companies */ for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) { - hs = &_highscore_table[LAST_HS_ITEM][i]; - SetDParam(0, (*p_cur)->president_name_1); - SetDParam(1, (*p_cur)->president_name_2); - SetDParam(2, (*p_cur)->name_1); - SetDParam(3, (*p_cur)->name_2); + HighScore* hs = &_highscore_table[LAST_HS_ITEM][i]; + + SetDParam(0, pl[i]->president_name_1); + SetDParam(1, pl[i]->president_name_2); + SetDParam(2, pl[i]->name_1); + SetDParam(3, pl[i]->name_2); GetString(hs->company, STR_HIGHSCORE_NAME); // get manager/company name string - hs->score = (*p_cur)->old_economy[0].performance_history; + hs->score = pl[i]->old_economy[0].performance_history; hs->title = EndGameGetPerformanceTitleFromValue(hs->score); // get the ranking of the local player - if ((*p_cur)->index == _local_player) - player = i; - - p_cur++; + if (pl[i]->index == _local_player) player = i; } } @@ -1262,10 +1256,8 @@ static void SaveLoad_PLYR(Player* p) SlObject(&p->cur_economy, _player_economy_desc); // Write old economy entries. - { - PlayerEconomyEntry *pe; - for (i = p->num_valid_stat_ent, pe = p->old_economy; i != 0; i--, pe++) - SlObject(pe, _player_economy_desc); + for (i = 0; i < p->num_valid_stat_ent; i++) { + SlObject(&p->old_economy[i], _player_economy_desc); } } |