Mercurial > hg > openttd
changeset 2988:2682be96ae43 draft
(svn r3563) Simplify the code for calculating the highscore table in network games and saving of old ecenomy data
author | tron <tron@openttd.org> |
---|---|
date | Mon, 06 Feb 2006 08:43:05 +0000 |
parents | f1bbf7b7003b |
children | 00a81ec78145 |
files | players.c |
diffstat | 1 files changed, 15 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/players.c +++ b/players.c @@ -1017,40 +1017,34 @@ #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 @@ 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); } }