Skip to content

Commit

Permalink
Count units inside transporters for mission end results
Browse files Browse the repository at this point in the history
  • Loading branch information
KJeff01 committed Nov 1, 2023
1 parent 2ec127a commit f19cf46
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
33 changes: 21 additions & 12 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2286,29 +2286,38 @@ const char *getDroidLevelName(const DROID *psDroid)

UDWORD getNumDroidsForLevel(uint32_t player, UDWORD level)
{
DROID *psDroid;
UDWORD count = 0;
unsigned int idx = 0;
unsigned int count = 0;

if (player >= MAX_PLAYERS) { return 0; }

for (psDroid = apsDroidLists[player]; psDroid; psDroid = psDroid->psNext)
do
{
if (getDroidLevel(psDroid) == level)
DROID *psDroid = nullptr;
switch (idx)
{
count++;
case 0: psDroid = apsDroidLists[selectedPlayer]; break;
case 1: if (prevMissionType == LEVEL_TYPE::LDS_MKEEP_LIMBO) { psDroid = apsLimboDroids[selectedPlayer]; } break;
default: psDroid = nullptr;
}
}

if (prevMissionType == LEVEL_TYPE::LDS_MKEEP_LIMBO)
{
for (psDroid = apsLimboDroids[player]; psDroid; psDroid = psDroid->psNext)
for (; psDroid; psDroid = psDroid->psNext)
{
if (getDroidLevel(psDroid) == level)
{
count++;
++count;
}
if (isTransporter(psDroid))
{
for (DROID *psCurr = psDroid->psGroup->psList; psCurr != nullptr; psCurr = psCurr->psGrpNext)
{
if (psCurr != psDroid && getDroidLevel(psCurr) == level)
{
++count;
}
}
}
}
}
} while (++idx < 2);

return count;
}
Expand Down
28 changes: 25 additions & 3 deletions src/scores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,31 @@ END_GAME_STATS_DATA collectEndGameStatsData()
fullStats.numUnits = 0;
if (selectedPlayer < MAX_PLAYERS)
{
for (DROID *psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid = psDroid->psNext, fullStats.numUnits++) {}
for (DROID *psDroid = mission.apsDroidLists[selectedPlayer]; psDroid; psDroid = psDroid->psNext, fullStats.numUnits++) {}
if (prevMissionType == LEVEL_TYPE::LDS_MKEEP_LIMBO) { for (DROID *psDroid = apsLimboDroids[selectedPlayer]; psDroid; psDroid = psDroid->psNext, fullStats.numUnits++) {} }
unsigned int idx = 0;
do
{
DROID *psDroid = nullptr;
switch (idx)
{
case 0: psDroid = apsDroidLists[selectedPlayer]; break;
case 1: psDroid = mission.apsDroidLists[selectedPlayer]; break;
case 2: if (prevMissionType == LEVEL_TYPE::LDS_MKEEP_LIMBO) { psDroid = apsLimboDroids[selectedPlayer]; } break;
default: psDroid = nullptr;
}
for (; psDroid; psDroid = psDroid->psNext, ++fullStats.numUnits)
{
if (isTransporter(psDroid))
{
for (DROID *psCurr = psDroid->psGroup->psList; psCurr != nullptr; psCurr = psCurr->psGrpNext)
{
if (psCurr != psDroid)
{
++fullStats.numUnits;
}
}
}
}
} while (++idx < 3);
}

return fullStats;
Expand Down

0 comments on commit f19cf46

Please sign in to comment.