Skip to content

Commit

Permalink
Add redundant city names
Browse files Browse the repository at this point in the history
Part of #1238. List the names of cities where the redundant improvement resides. Does not offer a quick link at this time, but at least gives you the some more information. Units are never redundant, they are upgradeable, which is shown on the units view.
  • Loading branch information
jwrober authored and lmoureaux committed Jan 24, 2024
1 parent f38a9fd commit cfadfba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions client/repodlgs_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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) {
return;
Expand All @@ -53,6 +56,7 @@ void get_economy_report_data(struct improvement_entry *entries,
cost += city_improvement_upkeep(pcity, pimprove);
if (is_improvement_redundant(pcity, pimprove)) {
redundant++;
redundant_cities.append(pcity->name);
}
}
}
Expand All @@ -62,11 +66,19 @@ void get_economy_report_data(struct improvement_entry *entries,
continue;
}

if (redundant == 0) {
str = (_("None"));
} else {
// Convert the string list we built to a standard string for display.
str = redundant_cities.join(", ");
}

entries[*num_entries_used].type = pimprove;
entries[*num_entries_used].count = count;
entries[*num_entries_used].redundant = redundant;
entries[*num_entries_used].total_cost = cost;
entries[*num_entries_used].cost = cost / count;
entries[*num_entries_used].city_names = str;
(*num_entries_used)++;

/* Currently there is no building expense under anarchy. It's
Expand Down
3 changes: 3 additions & 0 deletions client/repodlgs_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

#pragma once

#include <QString>

/*
* Structure of data for the Economics View. See get_economy_report_data()
*/
struct improvement_entry {
struct impr_type *type;
int count, redundant, cost, total_cost;
QString city_names;
};

/*
Expand Down
13 changes: 10 additions & 3 deletions client/views/view_economics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ eco_report::eco_report() : QWidget()

QStringList slist;
slist << _("Type") << Q_("?Building or Unit type:Name") << _("Redundant")
<< _("Count") << _("Cost") << _("Total Upkeep");
<< _("Count") << _("Cost") << _("Total Upkeep")
<< _("Redundant Cities");

ui.eco_widget->setColumnCount(slist.count());
ui.eco_widget->setHorizontalHeaderLabels(slist);
Expand Down Expand Up @@ -92,7 +93,7 @@ void eco_report::update_report()
cid id = cid_encode_building(pimprove);

ui.eco_widget->insertRow(i);
for (j = 0; j < 6; j++) {
for (j = 0; j < 7; j++) {
item = new QTableWidgetItem;
switch (j) {
case 0: {
Expand Down Expand Up @@ -124,6 +125,9 @@ void eco_report::update_report()
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
item->setData(Qt::DisplayRole, pentry->total_cost);
break;
case 6:
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft);
item->setData(Qt::DisplayRole, pentry->city_names);
}
ui.eco_widget->setItem(i, j, item);
}
Expand All @@ -136,7 +140,7 @@ void eco_report::update_report()
cid id = cid_encode_unit(putype);

ui.eco_widget->insertRow(i + max_row);
for (j = 0; j < 6; j++) {
for (j = 0; j < 7; j++) {
item = new QTableWidgetItem;
switch (j) {
case 0: {
Expand Down Expand Up @@ -170,6 +174,9 @@ void eco_report::update_report()
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
item->setData(Qt::DisplayRole, pentry->total_cost);
break;
case 6:
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft);
item->setText(_("Not Applicable"));
}
ui.eco_widget->setItem(max_row + i, j, item);
}
Expand Down

0 comments on commit cfadfba

Please sign in to comment.