From f4fd2a770b0ed0cc55d5180e6cb39993f120a29d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 May 2021 09:20:34 +0200 Subject: [PATCH] - dudeLeechOperate --- source/games/blood/src/aiunicult.cpp | 39 ++++++++++++++++++---------- source/games/blood/src/aiunicult.h | 2 +- source/games/blood/src/nnexts.cpp | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index 19cdd90c0..e3b7677e1 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -1830,38 +1830,49 @@ int getDodgeChance(DBloodActor* actor) int chance = ((baseChance / mass) << 7); return chance; - } -void dudeLeechOperate(spritetype* pSprite, XSPRITE* pXSprite, EVENT event) +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +void dudeLeechOperate(DBloodActor* actor, const EVENT& event) { - if (event.cmd == kCmdOff) { + auto const pSprite = &actor->s(); + auto const pXSprite = &actor->x(); + + if (event.cmd == kCmdOff) + { actPostSprite(pSprite->index, kStatFree); return; } - auto actor = &bloodActors[pSprite->index]; - int nTarget = pXSprite->target_i; - if (spriRangeIsFine(nTarget) && nTarget != pSprite->owner) { - spritetype* pTarget = &sprite[nTarget]; - if (pTarget->statnum == kStatDude && !(pTarget->flags & 32) && pTarget->extra > 0 && pTarget->extra < kMaxXSprites && !pXSprite->stateTimer) { - - if (IsPlayerSprite(pTarget)) { + auto actTarget = actor->GetTarget(); + if (actTarget != nullptr && actTarget != actor->GetOwner()) + { + spritetype* pTarget = &actTarget->s(); + if (pTarget->statnum == kStatDude && !(pTarget->flags & 32) && pTarget->extra > 0 && pTarget->extra < kMaxXSprites && !pXSprite->stateTimer) + { + if (IsPlayerSprite(pTarget)) + { PLAYER* pPlayer = &gPlayer[pTarget->type - kDudePlayer1]; if (powerupCheck(pPlayer, kPwUpShadowCloak) > 0) return; } int top, bottom; - GetSpriteExtents(pSprite, &top, &bottom); + GetActorExtents(actor, &top, &bottom); int nType = pTarget->type - kDudeBase; DUDEINFO* pDudeInfo = &dudeInfo[nType]; int z1 = (top - pSprite->z) - 256; int x = pTarget->x; int y = pTarget->y; int z = pTarget->z; int nDist = approxDist(x - pSprite->x, y - pSprite->y); - if (nDist != 0 && cansee(pSprite->x, pSprite->y, top, pSprite->sectnum, x, y, z, pTarget->sectnum)) { + if (nDist != 0 && cansee(pSprite->x, pSprite->y, top, pSprite->sectnum, x, y, z, pTarget->sectnum)) + { int t = DivScale(nDist, 0x1aaaaa, 12); - x += (xvel[nTarget] * t) >> 12; - y += (yvel[nTarget] * t) >> 12; + x += (actTarget->xvel() * t) >> 12; + y += (actTarget->yvel() * t) >> 12; int angBak = pSprite->ang; pSprite->ang = getangle(x - pSprite->x, y - pSprite->y); int dx = CosScale16(pSprite->ang); diff --git a/source/games/blood/src/aiunicult.h b/source/games/blood/src/aiunicult.h index 2997d74c5..4c23a7e1e 100644 --- a/source/games/blood/src/aiunicult.h +++ b/source/games/blood/src/aiunicult.h @@ -209,7 +209,7 @@ int checkAttackState(DBloodActor* actor); bool doExplosion(DBloodActor* pSprite, int nType); spritetype* genDudeSpawn(XSPRITE* pXSource, spritetype* pSprite, int nDist); void genDudeTransform(spritetype* pSprite); -void dudeLeechOperate(spritetype* pSprite, XSPRITE* pXSprite, EVENT a3); +void dudeLeechOperate(DBloodActor* actor, const EVENT& a3); int getDodgeChance(DBloodActor* pSprite); int getRecoilChance(DBloodActor* pSprite); bool dudeIsMelee(DBloodActor* pXSprite); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index b89ef13e5..025abea9c 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -5066,7 +5066,7 @@ bool modernTypeOperateSprite(int nSprite, spritetype* pSprite, XSPRITE* pXSprite } return true; case kModernThingEnemyLifeLeech: - dudeLeechOperate(pSprite, pXSprite, event); + dudeLeechOperate(actor, event); return true; case kModernPlayerControl: { // WIP PLAYER* pPlayer = NULL; int cmd = (event.cmd >= kCmdNumberic) ? event.cmd : pXSprite->command;