Skip to content

Commit

Permalink
Simplify get_economy_report_data
Browse files Browse the repository at this point in the history
Remove a variable by using the size of the list of redundant cities to
count them.
  • Loading branch information
lmoureaux authored and jwrober committed Jul 14, 2024
1 parent 31cfd4d commit 427df5a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions client/repodlgs_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ void get_economy_report_data(struct improvement_entry *entries,
*num_entries_used = 0;
*total_cost = 0;
*total_income = 0;
QStringList redundant_cities;
redundant_cities.clear();
QString str;

if (nullptr == client.conn.playing) {
Expand All @@ -48,14 +46,14 @@ void get_economy_report_data(struct improvement_entry *entries,
improvement_iterate(pimprove)
{
if (is_improvement(pimprove)) {
int count = 0, redundant = 0, cost = 0;
QStringList redundant_cities;
int count = 0, cost = 0;
city_list_iterate(client.conn.playing->cities, pcity)
{
if (city_has_building(pcity, pimprove)) {
count++;
cost += city_improvement_upkeep(pcity, pimprove);
if (is_improvement_redundant(pcity, pimprove)) {
redundant++;
redundant_cities.append(pcity->name);
}
}
Expand All @@ -66,7 +64,7 @@ void get_economy_report_data(struct improvement_entry *entries,
continue;
}

if (redundant == 0) {
if (redundant_cities.isEmpty()) {
str = (_("None"));
} else {
// Convert the string list we built to a standard string for display.
Expand All @@ -75,7 +73,7 @@ void get_economy_report_data(struct improvement_entry *entries,

entries[*num_entries_used].type = pimprove;
entries[*num_entries_used].count = count;
entries[*num_entries_used].redundant = redundant;
entries[*num_entries_used].redundant = redundant_cities.size();
entries[*num_entries_used].total_cost = cost;
entries[*num_entries_used].cost = cost / count;
entries[*num_entries_used].city_names = str;
Expand Down

0 comments on commit 427df5a

Please sign in to comment.