Skip to content

Commit

Permalink
Move unit view functions to the main files
Browse files Browse the repository at this point in the history
  • Loading branch information
jwrober authored and lmoureaux committed Feb 21, 2023
1 parent 50b4a76 commit 7b77d85
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 84 deletions.
72 changes: 0 additions & 72 deletions client/repodlgs_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
// common
#include "game.h"
#include "government.h"
#include "unitlist.h"

/* client/include */
#include "citydlg_common.h"

// client
#include "client_main.h"
#include "control.h"
#include "options.h"
#include "repodlgs_common.h"

/**
Expand Down Expand Up @@ -150,76 +148,6 @@ void get_economy_report_units_data(struct unit_entry *entries,
unit_type_iterate_end;
}

/**
* Returns an array of units data.
*/
std::vector<unit_view_entry>
get_units_view_data(struct unit_view_entry *entries, int *num_entries_used)
{
*num_entries_used = 0;

if (nullptr == client.conn.playing) {
return {};
}

unit_type_iterate(unittype)
{
int count = 0; // Count of active unit type
int in_progress = 0; // Count of being produced
int gold_cost = 0; // Gold upkeep
int food_cost = 0; // Food upkeep
int shield_cost = 0; // Shield upkeep
bool upgradable = false; // Unit type is upgradable

unit_list_iterate(client.conn.playing->units, punit)
{
if (unit_type_get(punit) == unittype) {
count++;
gold_cost += punit->upkeep[O_GOLD];
food_cost += punit->upkeep[O_FOOD];
shield_cost += punit->upkeep[O_SHIELD];
upgradable =
client_has_player()
&& nullptr != can_upgrade_unittype(client_player(), unittype);
}
}
unit_list_iterate_end;

city_list_iterate(client.conn.playing->cities, pcity)
{
if (pcity->production.value.utype == unittype
&& pcity->production.kind == VUT_UTYPE) {
in_progress++;
}
}
city_list_iterate_end;

// Skip unused unit types
if (count == 0 && in_progress == 0) {
continue;
}

entries[*num_entries_used].type = unittype;
entries[*num_entries_used].count = count;
entries[*num_entries_used].in_prod = in_progress;
entries[*num_entries_used].upg = upgradable;
entries[*num_entries_used].gold_cost = gold_cost;
entries[*num_entries_used].food_cost = food_cost;
entries[*num_entries_used].shield_cost = shield_cost;
(*num_entries_used)++;
}
unit_type_iterate_end;

std::sort(entries, entries + *num_entries_used,
[](const auto &lhs, const auto &rhs) {
return QString::localeAwareCompare(
utype_name_translation(lhs.type),
utype_name_translation(rhs.type))
< 0;
});

return {};
}

/**
Sell all improvements of the given type in all cities. If
Expand Down
12 changes: 0 additions & 12 deletions client/repodlgs_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ struct unit_entry {
int count, cost, total_cost;
};

/*
* Structure of data for the Units View. See get_units_view_data()
*/
struct unit_view_entry {
struct unit_type *type;
int count, in_prod, total_cost, food_cost, gold_cost, shield_cost;
bool upg;
};

void get_economy_report_data(struct improvement_entry *entries,
int *num_entries_used, int *total_cost,
int *total_income);
Expand All @@ -51,9 +42,6 @@ void get_economy_report_data(struct improvement_entry *entries,
void get_economy_report_units_data(struct unit_entry *entries,
int *num_entries_used, int *total_cost);

std::vector<unit_view_entry>
get_units_view_data(struct unit_view_entry *entries, int *num_entries_used);

void sell_all_improvements(const struct impr_type *pimprove,
bool redundant_only, char *message,
size_t message_sz);
Expand Down

0 comments on commit 7b77d85

Please sign in to comment.