- updateTargetOfSlaves, also storing the slave data as pointers and major cleanup of this function.

This commit is contained in:
Christoph Oelckers 2021-09-01 12:04:27 +02:00
parent c42e26351e
commit 6bee3b5ba0
3 changed files with 33 additions and 28 deletions

View file

@ -1669,7 +1669,7 @@ void aiProcessDudes(void)
case kDudeModernCustom: case kDudeModernCustom:
case kDudeModernCustomBurning: { case kDudeModernCustomBurning: {
GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite); if (pExtra->slaveCount > 0) updateTargetOfSlaves(actor);
if (pExtra->pLifeLeech != nullptr) updateTargetOfLeech(actor); if (pExtra->pLifeLeech != nullptr) updateTargetOfLeech(actor);
if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState
&& (pXSprite->aiState->stateTicks > 0 || seqGetStatus(3, pSprite->extra) < 0)) && (pXSprite->aiState->stateTicks > 0 || seqGetStatus(3, pSprite->extra) < 0))

View file

@ -277,7 +277,7 @@ void genDudeAttack1(int, DBloodActor* actor)
} }
gKillMgr.AddNewKill(1); gKillMgr.AddNewKill(1);
pExtra->slave[pExtra->slaveCount++] = spawned->s().index; pExtra->slave[pExtra->slaveCount++] = spawned;
if (!playGenDudeSound(actor, kGenDudeSndAttackNormal)) if (!playGenDudeSound(actor, kGenDudeSndAttackNormal))
sfxPlay3DSoundCP(actor, 379, 1, 0, 0x10000 - Random3(0x3000)); sfxPlay3DSoundCP(actor, 379, 1, 0, 0x10000 - Random3(0x3000));
} }
@ -2206,36 +2206,41 @@ void updateTargetOfLeech(DBloodActor* actor)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void updateTargetOfSlaves(spritetype* pSprite) { void updateTargetOfSlaves(DBloodActor* actor)
if (!xspriRangeIsFine(pSprite->extra)) { {
Printf(PRINT_HIGH, "!xspriRangeIsFine(pSprite->extra)"); if (!actor->hasX()) return;
return;
} auto const pSprite = &actor->s();
auto const pXSprite = &actor->x();
auto actor = &bloodActors[pSprite->index];
XSPRITE* pXSprite = &xsprite[pSprite->extra];
GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
short* slave = pExtra->slave; auto slave = pExtra->slave;
spritetype* pTarget = (pXSprite->target_i >= 0 && IsDudeSprite(&sprite[pXSprite->target_i])) ? &sprite[pXSprite->target_i] : NULL; auto actTarget = actor->GetTarget();
XSPRITE* pXTarget = (pTarget != NULL && xspriRangeIsFine(pTarget->extra) && xsprite[pTarget->extra].health > 0) ? &xsprite[pTarget->extra] : NULL; if (!actTarget || !actTarget->IsDudeActor() || !actTarget->hasX() || actTarget->x().health <= 0) actTarget = nullptr;
int newCnt = pExtra->slaveCount; int newCnt = pExtra->slaveCount;
for (int i = 0; i <= gGameOptions.nDifficulty; i++) { for (int i = 0; i <= gGameOptions.nDifficulty; i++)
if (spriRangeIsFine(slave[i])) { {
spritetype* pSlave = &sprite[slave[i]]; if (slave[i] != nullptr)
if (!IsDudeSprite(pSlave) || !xspriRangeIsFine(pSlave->extra) || xsprite[pSlave->extra].health < 0) { {
slave[i] = pSlave->owner = -1; newCnt--; if (!slave[i]->IsDudeActor() || !slave[i]->hasX() || slave[i]->x().health <= 0)
{
slave[i]->SetOwner(nullptr);
slave[i] = nullptr;
newCnt--;
continue; continue;
} }
XSPRITE* pXSlave = &xsprite[pSlave->index]; if (actTarget != nullptr)
if (pXTarget != NULL) { {
if (pXSprite->target_i != pXSlave->target_i) aiSetTarget_(pXSlave, pXSprite->target_i); if (actTarget != slave[i]->GetTarget()) aiSetTarget(slave[i], actTarget);
// check if slave have proper target // check if slave have proper target
if (!spriRangeIsFine(pXSlave->target_i) || sprite[pXSlave->target_i].owner == pSprite->index) if (slave[i]->GetTarget() == nullptr || slave[i]->GetTarget()->GetOwner() == actor)
aiSetTarget_(pXSlave, pSprite->x, pSprite->y, pSprite->z); aiSetTarget(slave[i], pSprite->x, pSprite->y, pSprite->z);
} else { }
aiSetTarget_(pXSlave, pSprite->x, pSprite->y, pSprite->z); // try return to master else
{
aiSetTarget(slave[i], pSprite->x, pSprite->y, pSprite->z); // try return to master
} }
} }
} }
@ -2532,7 +2537,7 @@ bool genDudePrepare(spritetype* pSprite, int propId) {
continue; continue;
} }
pExtra->slave[pExtra->slaveCount++] = nSprite; pExtra->slave[pExtra->slaveCount++] = &bloodActors[nSprite];
if (pExtra->slaveCount > gGameOptions.nDifficulty) if (pExtra->slaveCount > gGameOptions.nDifficulty)
break; break;
} }

View file

@ -170,7 +170,7 @@ struct GENDUDEEXTRA
unsigned short slaveCount; // how many dudes is summoned unsigned short slaveCount; // how many dudes is summoned
//unsigned short incarnationsCount; //unsigned short incarnationsCount;
DBloodActor* pLifeLeech; // spritenum of dropped dude's leech DBloodActor* pLifeLeech; // spritenum of dropped dude's leech
signed short slave[kGenDudeMaxSlaves]; // index of the ones dude is summon DBloodActor* slave[kGenDudeMaxSlaves]; // index of the ones dude is summon
signed short dmgControl[kDamageMax]; // depends of current weapon, drop armor item, sprite yrepeat and surface type signed short dmgControl[kDamageMax]; // depends of current weapon, drop armor item, sprite yrepeat and surface type
bool updReq[kGenDudePropertyMax]; // update requests bool updReq[kGenDudePropertyMax]; // update requests
union union
@ -213,7 +213,7 @@ void dudeLeechOperate(DBloodActor* actor, const EVENT& a3);
int getDodgeChance(DBloodActor* pSprite); int getDodgeChance(DBloodActor* pSprite);
int getRecoilChance(DBloodActor* pSprite); int getRecoilChance(DBloodActor* pSprite);
bool dudeIsMelee(DBloodActor* pXSprite); bool dudeIsMelee(DBloodActor* pXSprite);
void updateTargetOfSlaves(spritetype* pSprite); void updateTargetOfSlaves(DBloodActor* pSprite);
void updateTargetOfLeech(DBloodActor* pSprite); void updateTargetOfLeech(DBloodActor* pSprite);
bool canSwim(spritetype* pSprite); bool canSwim(spritetype* pSprite);
bool canDuck(spritetype* pSprite); bool canDuck(spritetype* pSprite);