Skip to content

Commit

Permalink
Groups UI: Include commander-assigned droids in the commander's group
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Aug 29, 2023
1 parent 48c112a commit 601c1d8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/hci/groups.cpp
Expand Up @@ -20,6 +20,7 @@
#include "../hci.h"
#include "groups.h"
#include "objects_stats.h"
#include "../group.h"

static bool groupButtonEnabled = true;

Expand All @@ -39,6 +40,7 @@ class GroupsUIController: public std::enable_shared_from_this<GroupsUIController
struct GroupDisplayInfo
{
size_t numberInGroup = 0;
size_t numberCommandedByGroup = 0; // the number of droids commanded by commanders in this group
uint64_t totalGroupMaxHealth = 0;
DROID_TEMPLATE displayDroidTemplate;

Expand Down Expand Up @@ -239,6 +241,7 @@ void GroupsUIController::updateData()
struct AccumulatedGroupInfo
{
size_t numberInGroup = 0;
size_t numberCommandedByGroup = 0; // the number of droids commanded by commanders in this group
uint64_t totalGroupMaxHealth = 0;
DROID *displayDroid = nullptr;
std::map<std::vector<uint32_t>, size_t> unitcounter;
Expand All @@ -248,12 +251,21 @@ void GroupsUIController::updateData()
std::array<AccumulatedGroupInfo, 10> calculatedGroupInfo;
for (DROID *psDroid = apsDroidLists[selectedPlayer]; psDroid != nullptr; psDroid = psDroid->psNext)
{
auto groupIdx = psDroid->group;
if (psDroid->group >= calculatedGroupInfo.size())
{
continue;
if ((psDroid->psGroup) && (psDroid->psGroup->psCommander) && (psDroid->psGroup->psCommander->group < calculatedGroupInfo.size()))
{
groupIdx = psDroid->psGroup->psCommander->group; // accumulate in commander's group
++(calculatedGroupInfo[groupIdx].numberCommandedByGroup);
}
else
{
continue;
}
}

auto& currGroupInfo = calculatedGroupInfo[psDroid->group];
auto& currGroupInfo = calculatedGroupInfo[groupIdx];

// display whatever unit occurs the most in this group
// find the identifier for this droid
Expand All @@ -272,6 +284,7 @@ void GroupsUIController::updateData()
const auto& calculatedInfo = calculatedGroupInfo[idx];
auto& storedGroupInfo = groupInfo[idx];
storedGroupInfo.numberInGroup = calculatedInfo.numberInGroup;
storedGroupInfo.numberCommandedByGroup = calculatedInfo.numberCommandedByGroup;
storedGroupInfo.totalGroupMaxHealth = calculatedInfo.totalGroupMaxHealth;
if (calculatedInfo.numberInGroup > 0)
{
Expand Down

0 comments on commit 601c1d8

Please sign in to comment.