From fb5916a3dde086adfdcff19c7502b8d479ae5534 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 6 May 2021 10:24:29 +0200 Subject: [PATCH] - canSwim et.al. --- source/games/blood/src/actor.cpp | 2 +- source/games/blood/src/ai.cpp | 12 ++++---- source/games/blood/src/aiunicult.cpp | 46 ++++++++++++++++++++-------- source/games/blood/src/aiunicult.h | 6 ++-- source/games/blood/src/nnexts.cpp | 2 +- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index a9c5052a8..a5621dca0 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5184,7 +5184,7 @@ void MoveDude(DBloodActor* actor) if (pSprite->type == kDudeModernCustom) { evPost(actor, 0, kCallbackEnemeyBubble); - if (!canSwim(pSprite)) actKillDude(actor, actor, kDamageFall, 1000 << 4); + if (!canSwim(actor)) actKillDude(actor, actor, kDamageFall, 1000 << 4); break; } diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index f67374d56..2cff6cf54 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -227,7 +227,7 @@ bool CanMove(DBloodActor* actor, DBloodActor* target, int nAngle, int nRange) #ifdef NOONE_EXTENSIONS case kDudeModernCustom: case kDudeModernCustomBurning: - if ((Crusher && !nnExtIsImmune(pSprite, pXSector->damageType)) || ((Water || Underwater) && !canSwim(pSprite))) return false; + if ((Crusher && !nnExtIsImmune(pSprite, pXSector->damageType)) || ((Water || Underwater) && !canSwim(actor))) return false; return true; [[fallthrough]]; #endif @@ -1092,8 +1092,8 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType { actKillDude(actor, actor, kDamageFall, 65535); } - } - else if (canWalk(pSprite) && !inDodge(pXSprite->aiState) && !inRecoil(pXSprite->aiState)) + } + else if (canWalk(actor) && !inDodge(pXSprite->aiState) && !inRecoil(pXSprite->aiState)) { if (!dudeIsMelee(actor)) { @@ -1101,7 +1101,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType { if (!spriteIsUnderwater(actor)) { - if (!canDuck(pSprite) || !dudeIsPlayingSeq(actor, 14)) aiGenDudeNewState(actor, &genDudeDodgeShortL); + if (!canDuck(actor) || !dudeIsPlayingSeq(actor, 14)) aiGenDudeNewState(actor, &genDudeDodgeShortL); else aiGenDudeNewState(actor, &genDudeDodgeShortD); if (Chance(0x0200)) @@ -1279,7 +1279,7 @@ void RecoilDude(DBloodActor* actor) { if (Chance(rChance << 3) || (dudeIsMelee(actor) && Chance(rChance << 4))) aiGenDudeNewState(actor, &genDudeRecoilTesla); else if (pExtra->canRecoil && Chance(rChance)) aiGenDudeNewState(actor, &genDudeRecoilL); - else if (canWalk(pSprite)) + else if (canWalk(actor)) { if (Chance(rChance >> 2)) aiGenDudeNewState(actor, &genDudeDodgeL); @@ -1298,7 +1298,7 @@ void RecoilDude(DBloodActor* actor) short rState = inRecoil(pXSprite->aiState); if (rState > 0) { - if (!canWalk(pSprite)) + if (!canWalk(actor)) { if (rState == 1) pXSprite->aiState->nextState = &genDudeChaseNoWalkL; else if (rState == 2) pXSprite->aiState->nextState = &genDudeChaseNoWalkD; diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index d7fa49d9f..16c762ed9 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -627,7 +627,7 @@ static void unicultThinkChase(DBloodActor* actor) genDudeThrow2.nextState = &genDudeChaseL; if (dist > 5072 && Chance(0x5000)) { - if (!canDuck(pSprite) || Chance(0x4000)) aiGenDudeNewState(actor, &genDudeDodgeShortL); + if (!canDuck(actor) || Chance(0x4000)) aiGenDudeNewState(actor, &genDudeDodgeShortL); else aiGenDudeNewState(actor, &genDudeDodgeShortD); } else @@ -1202,7 +1202,7 @@ void aiGenDudeMoveForward(DBloodActor* actor) int sin = Sin(pSprite->ang); int cos = Cos(pSprite->ang); - int frontSpeed = gGenDudeExtra[pSprite->index].moveSpeed; + int frontSpeed = actor->genDudeExtra().moveSpeed; actor->xvel() += MulScale(cos, frontSpeed, 30); actor->yvel() += MulScale(sin, frontSpeed, 30); } @@ -1304,7 +1304,7 @@ void aiGenDudeNewState(DBloodActor* actor, AISTATE* pAIState) } - if (!gGenDudeExtra[pSprite->index].canRecoil) + if (!actor->genDudeExtra().canRecoil) { if (pAIState == &genDudeRecoilL || pAIState == &genDudeRecoilD) pAIState = &genDudeIdleL; else if (pAIState == &genDudeRecoilW) pAIState = &genDudeIdleW; @@ -1474,8 +1474,8 @@ void removeLeech(DBloodActor* actLeech, bool delSprite) sfxPlay3DSoundCP(pLeech, 490, -1, 0,60000); - if (pLeech->owner >= 0 && pLeech->owner < kMaxSprites) - gGenDudeExtra[sprite[pLeech->owner].index].pLifeLeech = nullptr; + if (actLeech->GetOwner()) + actLeech->GetOwner()->genDudeExtra().pLifeLeech = nullptr; if (delSprite) { @@ -2254,7 +2254,14 @@ void updateTargetOfSlaves(DBloodActor* actor) pExtra->slaveCount = writeindex; } -short inDodge(AISTATE* aiState) { +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +short inDodge(AISTATE* aiState) +{ if (aiState == &genDudeDodgeL) return 1; else if (aiState == &genDudeDodgeD) return 2; else if (aiState == &genDudeDodgeW) return 3; @@ -2309,18 +2316,33 @@ short inDuck(AISTATE* aiState) { } -bool canSwim(spritetype* pSprite) { - return gGenDudeExtra[pSprite->index].canSwim; +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +bool canSwim(DBloodActor* actor) +{ + return actor->genDudeExtra().canSwim; } -bool canDuck(spritetype* pSprite) { - return gGenDudeExtra[pSprite->index].canDuck; +bool canDuck(DBloodActor* actor) +{ + return actor->genDudeExtra().canDuck; } -bool canWalk(spritetype* pSprite) { - return gGenDudeExtra[pSprite->index].canWalk; +bool canWalk(DBloodActor* actor) +{ + return actor->genDudeExtra().canWalk; } +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + int genDudeSeqStartId(XSPRITE* pXSprite) { if (genDudePrepare(&sprite[pXSprite->reference], kGenDudePropertyStates)) return pXSprite->data2; else return kGenDudeDefaultSeq; diff --git a/source/games/blood/src/aiunicult.h b/source/games/blood/src/aiunicult.h index 67c13e857..98c6d78c1 100644 --- a/source/games/blood/src/aiunicult.h +++ b/source/games/blood/src/aiunicult.h @@ -215,9 +215,9 @@ int getRecoilChance(DBloodActor* pSprite); bool dudeIsMelee(DBloodActor* pXSprite); void updateTargetOfSlaves(DBloodActor* pSprite); void updateTargetOfLeech(DBloodActor* pSprite); -bool canSwim(spritetype* pSprite); -bool canDuck(spritetype* pSprite); -bool canWalk(spritetype* pSprite); +bool canSwim(DBloodActor* actor); +bool canDuck(DBloodActor* actor); +bool canWalk(DBloodActor* actor); short inDodge(AISTATE* aiState); bool inIdle(AISTATE* aiState); bool inAttack(AISTATE* aiState); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index bb5a6f96b..845548bd4 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -7485,7 +7485,7 @@ void aiPatrolThink(DBloodActor* actor) { bool crouch = (pXSprite->unused1 & kDudeFlagCrouch), uwater = spriteIsUnderwater(actor); - if (!spriRangeIsFine(nMarker) || (pSprite->type == kDudeModernCustom && ((uwater && !canSwim(pSprite)) || !canWalk(pSprite)))) { + if (!spriRangeIsFine(nMarker) || (pSprite->type == kDudeModernCustom && ((uwater && !canSwim(actor)) || !canWalk(actor)))) { aiPatrolStop(pSprite, -1); return; }