From acec23e034d18e6bfa2d69a399f21ed3886bdfb8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 1 Sep 2021 00:00:53 +0200 Subject: [PATCH] - ensure the 'slave' array in genDudeExtra is always free of gaps. This will ensure that adding entries won't accidentally overwrite things. --- source/games/blood/src/aiunicult.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index d5abd152d..d7fa49d9f 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -2218,7 +2218,6 @@ void updateTargetOfSlaves(DBloodActor* actor) auto actTarget = actor->GetTarget(); if (!actTarget || !actTarget->IsDudeActor() || !actTarget->hasX() || actTarget->x().health <= 0) actTarget = nullptr; - int newCnt = pExtra->slaveCount; for (int i = 0; i <= gGameOptions.nDifficulty; i++) { if (slave[i] != nullptr) @@ -2227,7 +2226,6 @@ void updateTargetOfSlaves(DBloodActor* actor) { slave[i]->SetOwner(nullptr); slave[i] = nullptr; - newCnt--; continue; } @@ -2244,8 +2242,16 @@ void updateTargetOfSlaves(DBloodActor* actor) } } } - - pExtra->slaveCount = newCnt; + // compact the array after processing. + int writeindex = 0; + for (int i = 0; i <= gGameOptions.nDifficulty; i++) + { + if (slave[i] != nullptr) + { + slave[writeindex++] = slave[i]; + } + } + pExtra->slaveCount = writeindex; } short inDodge(AISTATE* aiState) {