diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index 305a05545..f67374d56 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -1669,7 +1669,7 @@ void aiProcessDudes(void) case kDudeModernCustom: case kDudeModernCustomBurning: { GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); - if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite); + if (pExtra->slaveCount > 0) updateTargetOfSlaves(actor); if (pExtra->pLifeLeech != nullptr) updateTargetOfLeech(actor); if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState && (pXSprite->aiState->stateTicks > 0 || seqGetStatus(3, pSprite->extra) < 0)) diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index b7db502b6..d5abd152d 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -277,7 +277,7 @@ void genDudeAttack1(int, DBloodActor* actor) } gKillMgr.AddNewKill(1); - pExtra->slave[pExtra->slaveCount++] = spawned->s().index; + pExtra->slave[pExtra->slaveCount++] = spawned; if (!playGenDudeSound(actor, kGenDudeSndAttackNormal)) sfxPlay3DSoundCP(actor, 379, 1, 0, 0x10000 - Random3(0x3000)); } @@ -2206,36 +2206,41 @@ void updateTargetOfLeech(DBloodActor* actor) // //--------------------------------------------------------------------------- -void updateTargetOfSlaves(spritetype* pSprite) { - if (!xspriRangeIsFine(pSprite->extra)) { - Printf(PRINT_HIGH, "!xspriRangeIsFine(pSprite->extra)"); - return; - } - - auto actor = &bloodActors[pSprite->index]; - XSPRITE* pXSprite = &xsprite[pSprite->extra]; +void updateTargetOfSlaves(DBloodActor* actor) +{ + if (!actor->hasX()) return; + + auto const pSprite = &actor->s(); + auto const pXSprite = &actor->x(); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); - short* slave = pExtra->slave; - spritetype* pTarget = (pXSprite->target_i >= 0 && IsDudeSprite(&sprite[pXSprite->target_i])) ? &sprite[pXSprite->target_i] : NULL; - XSPRITE* pXTarget = (pTarget != NULL && xspriRangeIsFine(pTarget->extra) && xsprite[pTarget->extra].health > 0) ? &xsprite[pTarget->extra] : NULL; + auto slave = pExtra->slave; + 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 (spriRangeIsFine(slave[i])) { - spritetype* pSlave = &sprite[slave[i]]; - if (!IsDudeSprite(pSlave) || !xspriRangeIsFine(pSlave->extra) || xsprite[pSlave->extra].health < 0) { - slave[i] = pSlave->owner = -1; newCnt--; + for (int i = 0; i <= gGameOptions.nDifficulty; i++) + { + if (slave[i] != nullptr) + { + if (!slave[i]->IsDudeActor() || !slave[i]->hasX() || slave[i]->x().health <= 0) + { + slave[i]->SetOwner(nullptr); + slave[i] = nullptr; + newCnt--; continue; } - XSPRITE* pXSlave = &xsprite[pSlave->index]; - if (pXTarget != NULL) { - if (pXSprite->target_i != pXSlave->target_i) aiSetTarget_(pXSlave, pXSprite->target_i); + if (actTarget != nullptr) + { + if (actTarget != slave[i]->GetTarget()) aiSetTarget(slave[i], actTarget); // check if slave have proper target - if (!spriRangeIsFine(pXSlave->target_i) || sprite[pXSlave->target_i].owner == pSprite->index) - aiSetTarget_(pXSlave, pSprite->x, pSprite->y, pSprite->z); - } else { - aiSetTarget_(pXSlave, pSprite->x, pSprite->y, pSprite->z); // try return to master + if (slave[i]->GetTarget() == nullptr || slave[i]->GetTarget()->GetOwner() == actor) + aiSetTarget(slave[i], pSprite->x, pSprite->y, pSprite->z); + } + 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; } - pExtra->slave[pExtra->slaveCount++] = nSprite; + pExtra->slave[pExtra->slaveCount++] = &bloodActors[nSprite]; if (pExtra->slaveCount > gGameOptions.nDifficulty) break; } diff --git a/source/games/blood/src/aiunicult.h b/source/games/blood/src/aiunicult.h index aeaa975b5..67c13e857 100644 --- a/source/games/blood/src/aiunicult.h +++ b/source/games/blood/src/aiunicult.h @@ -170,7 +170,7 @@ struct GENDUDEEXTRA unsigned short slaveCount; // how many dudes is summoned //unsigned short incarnationsCount; 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 bool updReq[kGenDudePropertyMax]; // update requests union @@ -213,7 +213,7 @@ void dudeLeechOperate(DBloodActor* actor, const EVENT& a3); int getDodgeChance(DBloodActor* pSprite); int getRecoilChance(DBloodActor* pSprite); bool dudeIsMelee(DBloodActor* pXSprite); -void updateTargetOfSlaves(spritetype* pSprite); +void updateTargetOfSlaves(DBloodActor* pSprite); void updateTargetOfLeech(DBloodActor* pSprite); bool canSwim(spritetype* pSprite); bool canDuck(spritetype* pSprite);