From bba217d87a7cc6988cb198dd5ae7ce239bf3ecab Mon Sep 17 00:00:00 2001 From: Alain BKR Date: Sun, 30 May 2021 22:18:56 +0200 Subject: [PATCH] Wonders report sorted by nations and alphabetically More precisely : First sorted by nations and by city Then destroyed ones Then currently being built Then all the existing wonders again, sorted alphabetically. (not including destroyed or being built) --- server/report.c | 90 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 26 deletions(-) diff --git a/server/report.c b/server/report.c index 7d9a4e0653..eb4a2ded68 100644 --- a/server/report.c +++ b/server/report.c @@ -402,38 +402,67 @@ void report_wonders_of_the_world(struct conn_list *dest) { char buffer[4096]; + char *separator="\n"; + struct strvec *wonderlist = strvec_new(); + buffer[0] = '\0'; - improvement_iterate(i) { - if (is_great_wonder(i)) { - struct city *pcity = city_from_great_wonder(i); - - if (pcity) { - if (player_count() > team_count()) { - /* There exists a team with more than one member. */ - char team_name[2 * MAX_LEN_NAME]; - - team_pretty_name(city_owner(pcity)->team, team_name, - sizeof(team_name)); - cat_snprintf(buffer, sizeof(buffer), - /* TRANS: "Colossus in Rhodes (Greek, team 2)". */ - _("%s in %s (%s, %s)\n"), - city_improvement_name_translation(pcity, i), - city_name_get(pcity), - nation_adjective_for_player(city_owner(pcity)), - team_name); - } else { - cat_snprintf(buffer, sizeof(buffer), _("%s in %s (%s)\n"), - city_improvement_name_translation(pcity, i), - city_name_get(pcity), - nation_adjective_for_player(city_owner(pcity))); - } - } else if (great_wonder_is_destroyed(i)) { + /* sort by players and cities */ + players_iterate(pplayer) { + int n=0; + city_list_iterate(pplayer->cities, pcity) { + int w=0; + city_built_iterate(pcity, i) { + if (is_great_wonder(i)) { + w++; + n++; + if (player_count() > team_count()) { + /* There exists a team with more than one member. */ + char team_name[2 * MAX_LEN_NAME]; + + team_pretty_name(city_owner(pcity)->team, team_name, + sizeof(team_name)); + cat_snprintf(buffer, sizeof(buffer), + /* TRANS: "Colossus in Rhodes (Greek, team 2)". */ + _("%s in %s (%s, %s)\n"), + city_improvement_name_translation(pcity, i), + city_name_get(pcity), + nation_adjective_for_player(city_owner(pcity)), + team_name); + } else { + cat_snprintf(buffer, sizeof(buffer), _("%s in %s (%s)\n"), + city_improvement_name_translation(pcity, i), + city_name_get(pcity), + nation_adjective_for_player(city_owner(pcity))); + } + } /* endif is_great_wonder */ + } city_built_iterate_end; + if (w!=0) { + cat_snprintf(buffer, sizeof(buffer), "\n"); + } + } city_list_iterate_end; + } players_iterate_end; + + cat_snprintf(buffer, sizeof(buffer), "----------------------------\n"); + + /* find destroyed wonders */ + improvement_iterate(imp) { + if (is_great_wonder(imp)) { + if (great_wonder_is_destroyed(imp)) { cat_snprintf(buffer, sizeof(buffer), _("%s has been DESTROYED\n"), - improvement_name_translation(i)); + improvement_name_translation(imp)); } } } improvement_iterate_end; + + /* blank line */ + cat_snprintf(buffer, sizeof(buffer), "----------------------------\n"); + + + /* copy buffer into list before "building %s in ...." + because all "building %s" would be sorted at the same letter b */ + + strvec_from_str(wonderlist, *separator, buffer); improvement_iterate(i) { if (is_great_wonder(i)) { @@ -464,6 +493,15 @@ void report_wonders_of_the_world(struct conn_list *dest) } } improvement_iterate_end; + /* show again all wonders, sorted alphabetically */ + /* the separator line will be the first one, no need to add another one */ + strvec_remove_duplicate(wonderlist, strcmp); + strvec_sort(wonderlist, compare_strings_strvec); + + strvec_iterate(wonderlist,wonder) { + cat_snprintf(buffer, sizeof(buffer), "%s\n", wonder); + } strvec_iterate_end; + page_conn(dest, _("Traveler's Report:"), _("Wonders of the World"), buffer); } -- 2.25.1