From ce78b23fb6eddf10a324d3479710ded86a00895f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 15 Oct 2021 21:06:53 +0200 Subject: [PATCH] - converted FuncAnim into a class --- source/games/exhumed/src/aistuff.h | 18 ++- source/games/exhumed/src/anims.cpp | 197 +++++++++++++-------------- source/games/exhumed/src/runlist.cpp | 4 +- 3 files changed, 113 insertions(+), 106 deletions(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index b9ff35b1e..2d0b0f7b2 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -413,11 +413,13 @@ struct RunListEvent int nRadialDamage; // Radial damage needs a bit more info. int nDamageRadius; + + int RunValue() const; }; struct ExhumedAI { - virtual ~ExhumedAI() = default; + //virtual ~ExhumedAI() = default; virtual void ProcessChannel(RunListEvent* ev) {} virtual void Tick(RunListEvent* ev) {} virtual void Process(RunListEvent* ev) {} @@ -430,11 +432,25 @@ struct ExhumedAI virtual void RadialDamage(RunListEvent* ev) {} }; +struct AIAnim : public ExhumedAI +{ + void Tick(RunListEvent* ev) override; + void Draw(RunListEvent* ev) override; +}; + + + void runlist_DispatchEvent(ExhumedAI* ai, int nObject, int nMessage, int nDamage, int nRun); typedef void(*AiFunc)(int, int, int, int nRun); extern FreeListArray RunData; + +inline int RunListEvent::RunValue() const +{ + return RunData[nRun].nVal; +} + extern RunChannel sRunChannels[kMaxChannels]; extern short NewRun; extern int nRadialOwner; diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index 06f885d4d..2199c6b86 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -150,143 +150,132 @@ short GetAnimSprite(short nAnim) return AnimList[nAnim].nSprite; } -void FuncAnim(int nObject, int nMessage, int, int nRun) +void AIAnim::Tick(RunListEvent* ev) { - short nAnim = RunData[nRun].nVal; + short nAnim = RunData[ev->nRun].nVal; assert(nAnim >= 0 && nAnim < kMaxAnims); short nSprite = AnimList[nAnim].nSprite; short nSeq = AnimList[nAnim].nSeq; - auto pSprite = &sprite[nSprite]; + auto pSprite = &sprite[nSprite]; assert(nSprite != -1); - switch (nMessage) - { - case 0x20000: - { - short var_1C = AnimList[nAnim].field_2; + short var_1C = AnimList[nAnim].field_2; - if (!(pSprite->cstat & 0x8000)) + if (!(pSprite->cstat & 0x8000)) + { + seq_MoveSequence(nSprite, nSeq, var_1C); + } + + if (pSprite->statnum == kStatIgnited) + { + short nSpriteB = pSprite->hitag; + if (nSpriteB > -1) + { + auto pSpriteB = &sprite[nSpriteB]; + pSprite->x = pSpriteB->x; + pSprite->y = pSpriteB->y; + pSprite->z = pSpriteB->z; + + if (pSpriteB->sectnum != pSprite->sectnum) { - seq_MoveSequence(nSprite, nSeq, var_1C); + if (pSpriteB->sectnum < 0 || pSpriteB->sectnum >= kMaxSectors) + { + DestroyAnim(nAnim); + mydeletesprite(nSprite); + return; + } + else + { + mychangespritesect(nSprite, pSpriteB->sectnum); + } } - if (pSprite->statnum == kStatIgnited) + if (!var_1C) { - short nSpriteB = pSprite->hitag; - if (nSpriteB > -1) + if (pSpriteB->cstat != 0x8000) { - auto pSpriteB = &sprite[nSpriteB]; - pSprite->x = pSpriteB->x; - pSprite->y = pSpriteB->y; - pSprite->z = pSpriteB->z; + short hitag2 = pSpriteB->hitag; + pSpriteB->hitag--; - if (pSpriteB->sectnum != pSprite->sectnum) + if (hitag2 >= 15) { - if (pSpriteB->sectnum < 0 || pSpriteB->sectnum >= kMaxSectors) + runlist_DamageEnemy(nSpriteB, -1, (pSpriteB->hitag - 14) * 2); + + if (pSpriteB->shade < 100) + { + pSpriteB->pal = 0; + pSpriteB->shade++; + } + + if (!(pSpriteB->cstat & 101)) { DestroyAnim(nAnim); mydeletesprite(nSprite); return; } - else - { - mychangespritesect(nSprite, pSpriteB->sectnum); - } } - - if (!var_1C) + else { - if (pSpriteB->cstat != 0x8000) - { - short hitag2 = pSpriteB->hitag; - pSpriteB->hitag--; - - if (hitag2 >= 15) - { - runlist_DamageEnemy(nSpriteB, -1, (pSpriteB->hitag - 14) * 2); - - if (pSpriteB->shade < 100) - { - pSpriteB->pal = 0; - pSpriteB->shade++; - } - - if (!(pSpriteB->cstat & 101)) - { - DestroyAnim(nAnim); - mydeletesprite(nSprite); - return; - } - } - else - { - pSpriteB->hitag = 1; - DestroyAnim(nAnim); - mydeletesprite(nSprite); - } - } - else - { - pSpriteB->hitag = 1; - DestroyAnim(nAnim); - mydeletesprite(nSprite); - } + pSpriteB->hitag = 1; + DestroyAnim(nAnim); + mydeletesprite(nSprite); } } - } - - AnimList[nAnim].field_2++; - if (AnimList[nAnim].field_2 >= SeqSize[nSeq]) - { - if (AnimList[nAnim].AnimFlags & 0x10) - { - AnimList[nAnim].field_2 = 0; - } - else if (nSeq == nPreMagicSeq) - { - AnimList[nAnim].field_2 = 0; - AnimList[nAnim].nSeq = nMagicSeq; - short nAnimSprite = AnimList[nAnim].nSprite; - AnimList[nAnim].AnimFlags |= 0x10; - sprite[nAnimSprite].cstat |= 2; - } - else if (nSeq == nSavePointSeq) - { - AnimList[nAnim].field_2 = 0; - AnimList[nAnim].nSeq++; - AnimList[nAnim].AnimFlags |= 0x10; - } else { + pSpriteB->hitag = 1; DestroyAnim(nAnim); mydeletesprite(nSprite); } - return; } - - return; - } - - case 0x90000: - { - seq_PlotSequence(nObject, nSeq, AnimList[nAnim].field_2, 0x101); - mytsprite[nObject].owner = -1; - return; - } - - case 0xA0000: - { - return; - } - - default: - { - Printf("unknown msg %x for anim\n", nMessage); - return; } } + + AnimList[nAnim].field_2++; + if (AnimList[nAnim].field_2 >= SeqSize[nSeq]) + { + if (AnimList[nAnim].AnimFlags & 0x10) + { + AnimList[nAnim].field_2 = 0; + } + else if (nSeq == nPreMagicSeq) + { + AnimList[nAnim].field_2 = 0; + AnimList[nAnim].nSeq = nMagicSeq; + short nAnimSprite = AnimList[nAnim].nSprite; + AnimList[nAnim].AnimFlags |= 0x10; + sprite[nAnimSprite].cstat |= 2; + } + else if (nSeq == nSavePointSeq) + { + AnimList[nAnim].field_2 = 0; + AnimList[nAnim].nSeq++; + AnimList[nAnim].AnimFlags |= 0x10; + } + else + { + DestroyAnim(nAnim); + mydeletesprite(nSprite); + } + } +} + +void AIAnim::Draw(RunListEvent* ev) +{ + short nAnim = RunData[ev->nRun].nVal; + assert(nAnim >= 0 && nAnim < kMaxAnims); + short nSeq = AnimList[nAnim].nSeq; + + seq_PlotSequence(ev->nIndex, nSeq, AnimList[nAnim].field_2, 0x101); + ev->pTSprite->owner = -1; +} + +void FuncAnim(int nObject, int nMessage, int nDamage, int nRun) +{ + AIAnim ai; + runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun); } void BuildExplosion(short nSprite) diff --git a/source/games/exhumed/src/runlist.cpp b/source/games/exhumed/src/runlist.cpp index 12b69e725..6d856f1cc 100644 --- a/source/games/exhumed/src/runlist.cpp +++ b/source/games/exhumed/src/runlist.cpp @@ -1702,9 +1702,11 @@ void runlist_DamageEnemy(int nSprite, int nSprite2, short nDamage) // This is only temporary so that the event system can be refactored in smaller steps. void runlist_DispatchEvent(ExhumedAI* ai, int nObject, int nMessage, int nDamage, int nRun) { - RunListEvent ev; + RunListEvent ev{}; ev.nMessage = (EMessageType)(nMessage >> 16); ev.nIndex = nObject; + ev.nDamage = nDamage; + ev.nRun = nRun; switch (ev.nMessage) { case EMessageType::ProcessChannel: