From 89c975387ae0adee6201c3d542b9fc3cfb748211 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Mon, 16 Oct 2023 22:03:04 -0500 Subject: [PATCH 1/2] Count units inside transporters for mission end results --- src/droid.cpp | 33 +++++++++++++++++++++------------ src/scores.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/droid.cpp b/src/droid.cpp index 7a44a5f9f37..ebfd478e8d0 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -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; } diff --git a/src/scores.cpp b/src/scores.cpp index 288d810eac7..12235f8faac 100644 --- a/src/scores.cpp +++ b/src/scores.cpp @@ -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; From 3af1206ec3f482043979ae5e578fd935c7e23d38 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sat, 28 Oct 2023 11:16:38 -0500 Subject: [PATCH 2/2] Cleanup proj_radiusSweep() Doesn't need a droid object passed to it. --- src/projectile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/projectile.cpp b/src/projectile.cpp index 156e20cb90a..a34e1dffb75 100644 --- a/src/projectile.cpp +++ b/src/projectile.cpp @@ -963,7 +963,7 @@ static void proj_InFlightFunc(PROJECTILE *psProj) /***************************************************************************/ -static void proj_radiusSweep(PROJECTILE *psObj, WEAPON_STATS *psStats, DROID *destDroid, Vector3i &targetPos, bool empRadius) +static void proj_radiusSweep(PROJECTILE *psObj, WEAPON_STATS *psStats, Vector3i &targetPos, bool empRadius) { static GridList gridList; // static to avoid allocations. gridList = gridStartIterate(targetPos.x, targetPos.y, (empRadius) ? psStats->upgrade[psObj->player].empRadius : psStats->upgrade[psObj->player].radius); @@ -1277,11 +1277,11 @@ static void proj_ImpactFunc(PROJECTILE *psObj) if (hasEMPRadius && psStats->weaponSubClass == WSC_EMP) { - proj_radiusSweep(psObj, psStats, destDroid, targetPos, true); + proj_radiusSweep(psObj, psStats, targetPos, true); } if (hasRadius) { - proj_radiusSweep(psObj, psStats, destDroid, targetPos, false); + proj_radiusSweep(psObj, psStats, targetPos, false); } }