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) {