From e5047816c214c8e3f54ce1ac7be408b6f241ddba Mon Sep 17 00:00:00 2001 From: Dino Date: Sun, 31 Aug 2025 20:18:35 -0400 Subject: [PATCH] #1669 - improve report_wonders_of_the_world_long() --- server/report.c | 112 ++++++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/server/report.c b/server/report.c index 828bc14675..5210feb82a 100644 --- a/server/report.c +++ b/server/report.c @@ -416,18 +416,15 @@ void report_wonders_of_the_world_long(struct conn_list *dest) char buffer[4096]; const char *separator = "\n"; struct strvec *wonderlist = strvec_new(); + int count; buffer[0] = '\0'; - /* Sort by players and cities */ + /* get built wonders by players and cities */ players_iterate(pplayer) { city_list_iterate(pplayer->cities, pcity) { - int w = 0; - city_built_iterate(pcity, i) { if (is_great_wonder(i)) { - w++; - if (player_count() > team_count()) { /* There exists a team with more than one member. */ char team_name[2 * MAX_LEN_NAME]; @@ -449,70 +446,93 @@ void report_wonders_of_the_world_long(struct conn_list *dest) } } /* 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"); + /* make strvec and sort it */ + strvec_from_str(wonderlist, *separator, buffer); + strvec_sort(wonderlist, compare_strings_strvec); + + /* restart buffer */ + buffer[0] = '\0'; + + /* read out sorted strvec into buffer */ + strvec_iterate(wonderlist,wonder) { + cat_snprintf(buffer, sizeof(buffer), "%s\n", wonder); + } strvec_iterate_end; - /* Find destroyed wonders */ + /* count destroyed wonders */ + count = 0; 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(imp)); + count++; } } } 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); + /* any destroyed wonders? */ + if (count > 0) { + 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(imp)); + } + } + } improvement_iterate_end; + } + /* count building wonders */ + count = 0; improvement_iterate(i) { if (is_great_wonder(i)) { players_iterate(pplayer) { city_list_iterate(pplayer->cities, pcity) { if (VUT_IMPROVEMENT == pcity->production.kind - && pcity->production.value.building == i) { - 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: "([...] (Roman, team 4))". */ - _("(building %s in %s (%s, %s))\n"), - improvement_name_translation(i), city_name_get(pcity), - _(nation_adjective_for_player(pplayer)), team_name); - } else { - cat_snprintf(buffer, sizeof(buffer), - _("(building %s in %s (%s))\n"), - improvement_name_translation(i), city_name_get(pcity), - _(nation_adjective_for_player(pplayer))); - } + && pcity->production.value.building == i) { + count++; } } city_list_iterate_end; } players_iterate_end; } } 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; + /* any building wonders? */ + if (count > 0) { + cat_snprintf(buffer, sizeof(buffer), "----------------------------\n"); + /* Find building wonders */ + improvement_iterate(i) { + if (is_great_wonder(i)) { + players_iterate(pplayer) { + city_list_iterate(pplayer->cities, pcity) { + if (VUT_IMPROVEMENT == pcity->production.kind + && pcity->production.value.building == i) { + 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: "([...] (Roman, team 4))". */ + _("(building %s in %s (%s, %s))\n"), + improvement_name_translation(i), city_name_get(pcity), + _(nation_adjective_for_player(pplayer)), team_name); + } else { + cat_snprintf(buffer, sizeof(buffer), + _("(building %s in %s (%s))\n"), + improvement_name_translation(i), city_name_get(pcity), + _(nation_adjective_for_player(pplayer))); + } + } + } city_list_iterate_end; + } players_iterate_end; + } + } improvement_iterate_end; + } page_conn(dest, _("Traveler's Report:"), _("Wonders of the World"), buffer); -- 2.31.0