- ensure the 'slave' array in genDudeExtra is always free of gaps.

This will ensure that adding entries won't accidentally overwrite things.
This commit is contained in:
Christoph Oelckers 2021-09-01 00:00:53 +02:00
parent 6bee3b5ba0
commit acec23e034

View file

@ -2218,7 +2218,6 @@ void updateTargetOfSlaves(DBloodActor* actor)
auto actTarget = actor->GetTarget(); auto actTarget = actor->GetTarget();
if (!actTarget || !actTarget->IsDudeActor() || !actTarget->hasX() || actTarget->x().health <= 0) actTarget = nullptr; if (!actTarget || !actTarget->IsDudeActor() || !actTarget->hasX() || actTarget->x().health <= 0) actTarget = nullptr;
int newCnt = pExtra->slaveCount;
for (int i = 0; i <= gGameOptions.nDifficulty; i++) for (int i = 0; i <= gGameOptions.nDifficulty; i++)
{ {
if (slave[i] != nullptr) if (slave[i] != nullptr)
@ -2227,7 +2226,6 @@ void updateTargetOfSlaves(DBloodActor* actor)
{ {
slave[i]->SetOwner(nullptr); slave[i]->SetOwner(nullptr);
slave[i] = nullptr; slave[i] = nullptr;
newCnt--;
continue; continue;
} }
@ -2244,8 +2242,16 @@ void updateTargetOfSlaves(DBloodActor* actor)
} }
} }
} }
// compact the array after processing.
pExtra->slaveCount = newCnt; 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) { short inDodge(AISTATE* aiState) {