From 89d98ddf340ecd5989791d27d56685bd0ce048e3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 15 Oct 2021 23:00:02 +0200 Subject: [PATCH] - fixed the rat. - converted FuncRat to a class. --- source/games/exhumed/src/aistuff.h | 9 + source/games/exhumed/src/rat.cpp | 335 +++++++++++++++-------------- 2 files changed, 178 insertions(+), 166 deletions(-) diff --git a/source/games/exhumed/src/aistuff.h b/source/games/exhumed/src/aistuff.h index dc4dfe3a941..bfa3fc91383 100644 --- a/source/games/exhumed/src/aistuff.h +++ b/source/games/exhumed/src/aistuff.h @@ -593,6 +593,15 @@ struct AIRa : public ExhumedAI void Draw(RunListEvent* ev) override; }; +struct AIRat : public ExhumedAI +{ + void Tick(RunListEvent* ev) override; + void Damage(RunListEvent* ev) override; + void Draw(RunListEvent* ev) override; + void RadialDamage(RunListEvent* ev) override; +}; + + void runlist_DispatchEvent(ExhumedAI* ai, int nObject, int nMessage, int nDamage, int nRun); typedef void(*AiFunc)(int, int, int, int nRun); diff --git a/source/games/exhumed/src/rat.cpp b/source/games/exhumed/src/rat.cpp index 2c1260df1bd..daec091f7b1 100644 --- a/source/games/exhumed/src/rat.cpp +++ b/source/games/exhumed/src/rat.cpp @@ -204,211 +204,214 @@ int FindFood(short nSprite) return -1; } -void FuncRat(int nObject, int nMessage, int nDamage, int nRun) +void AIRat::RadialDamage(RunListEvent* ev) +{ + short nRat = RunData[ev->nRun].nVal; + short nSprite = RatList[nRat].nSprite; + ev->nDamage = runlist_CheckRadialDamage(nSprite); + Damage(ev); +} + +void AIRat::Damage(RunListEvent* ev) +{ + short nRat = RunData[ev->nRun].nVal; + short nSprite = RatList[nRat].nSprite; + auto pSprite = &sprite[nSprite]; + + if (ev->nDamage) + { + pSprite->cstat = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + RatList[nRat].nAction = 3; + RatList[nRat].nFrame = 0; + } + return; +} + +void AIRat::Draw(RunListEvent* ev) { - short nRat = RunData[nRun].nVal; + short nRat = RunData[ev->nRun].nVal; + short nAction = RatList[nRat].nAction; + + seq_PlotSequence(ev->nIndex, SeqOffsets[kSeqRat] + RatSeq[nAction].a, RatList[nRat].nFrame, RatSeq[nAction].b); +} + + +void AIRat::Tick(RunListEvent* ev) +{ + short nRat = RunData[ev->nRun].nVal; short nSprite = RatList[nRat].nSprite; short nAction = RatList[nRat].nAction; - auto pSprite = &sprite[nSprite]; + auto pSprite = &sprite[nSprite]; bool bVal = false; - switch (nMessage) + int nSeq = SeqOffsets[kSeqRat] + RatSeq[nAction].a; + pSprite->picnum = seq_GetSeqPicnum2(nSeq, RatList[nRat].nFrame); + + seq_MoveSequence(nSprite, nSeq, RatList[nRat].nFrame); + + RatList[nRat].nFrame++; + if (RatList[nRat].nFrame >= SeqSize[nSeq]) { - default: - { - Printf("unknown msg %d for Rathead\n", nMessage); - return; - } + bVal = true; + RatList[nRat].nFrame = 0; + } - case 0xA0000: - { - nDamage = runlist_CheckRadialDamage(nSprite); - // fall through to 0x80000 - fallthrough__; - } - case 0x80000: - { - if (nDamage) - { - pSprite->cstat = 0; - pSprite->xvel = 0; - pSprite->yvel = 0; - RatList[nRat].nAction = 3; - RatList[nRat].nFrame = 0; - } + short nTarget = RatList[nRat].nTarget; + + Gravity(nSprite); + + switch (nAction) + { + default: + return; + + case 0: + { + RatList[nRat].nCount--; + if (RatList[nRat].nCount > 0) { return; } - case 0x90000: + int xVal = abs(pSprite->x - sprite[nTarget].x); + int yVal = abs(pSprite->y - sprite[nTarget].y); + + if (xVal > 50 || yVal > 50) { - seq_PlotSequence(nObject, SeqOffsets[kSeqRat] + RatSeq[nAction].a, RatList[nRat].nFrame, RatSeq[nAction].b); + RatList[nRat].nAction = 2; + RatList[nRat].nFrame = 0; + RatList[nRat].nTarget = -1; + + pSprite->xvel = 0; + pSprite->yvel = 0; return; } - case 0x20000: - { - int nSeq = SeqOffsets[kSeqRat] + RatSeq[nAction].a; - pSprite->picnum = seq_GetSeqPicnum2(nSeq, RatList[nRat].nFrame); + RatList[nRat].nFrame ^= 1; + RatList[nRat].nCount = RandomSize(5) + 4; + RatList[nRat].nIndex--; - seq_MoveSequence(nSprite, nSeq, RatList[nRat].nFrame); - - RatList[nRat].nFrame++; - if (RatList[nRat].nFrame >= SeqSize[nSeq]) - { - bVal = true; - RatList[nRat].nFrame = 0; + if (RatList[nRat].nIndex <= 0) + { + short nFoodSprite = FindFood(nSprite); + if (nFoodSprite == -1) { + return; } - short nTarget = RatList[nRat].nTarget; + RatList[nRat].nTarget = nFoodSprite; - Gravity(nSprite); + PlotCourseToSprite(nSprite, nFoodSprite); + SetRatVel(nSprite); - switch (nAction) - { - default: - return; + RatList[nRat].nAction = 1; + RatList[nRat].nIndex = 900; + RatList[nRat].nFrame = 0; + } - case 0: - { - RatList[nRat].nCount--; - if (RatList[nRat].nCount > 0) { - return; - } - - int xVal = abs(pSprite->x - sprite[nTarget].x); - int yVal = abs(pSprite->y - sprite[nTarget].y); - - if (xVal > 50 || yVal > 50) - { - RatList[nRat].nAction = 2; - RatList[nRat].nFrame = 0; - RatList[nRat].nTarget = -1; - - pSprite->xvel = 0; - pSprite->yvel = 0; - return; - } - - RatList[nRat].nFrame ^= 1; - RatList[nRat].nCount = RandomSize(5) + 4; - RatList[nRat].nIndex--; - - if (RatList[nRat].nIndex <= 0) - { - short nFoodSprite = FindFood(nSprite); - if (nFoodSprite == -1) { - return; - } - - RatList[nRat].nTarget = nFoodSprite; - - PlotCourseToSprite(nSprite, nFoodSprite); - SetRatVel(nSprite); - - RatList[nRat].nAction = 1; - RatList[nRat].nIndex = 900; - RatList[nRat].nFrame = 0; - } + return; + } + case 1: + { + RatList[nRat].nIndex--; - return; - } - case 1: - { - RatList[nRat].nIndex--; + if (RatList[nRat].nIndex <= 0) + { + RatList[nRat].nAction = 2; + RatList[nRat].nFrame = 0; + RatList[nRat].nTarget = -1; + + pSprite->xvel = 0; + pSprite->yvel = 0; + } - if (RatList[nRat].nIndex <= 0) - { - RatList[nRat].nAction = 2; - RatList[nRat].nFrame = 0; - RatList[nRat].nTarget = -1; + MoveCreature(nSprite); - pSprite->xvel = 0; - pSprite->yvel = 0; - } + int xVal = abs(pSprite->x - sprite[nTarget].x); + int yVal = abs(pSprite->y - sprite[nTarget].y); - MoveCreature(nSprite); + if (xVal >= 50 || yVal >= 50) + { + RatList[nRat].nCount--; + if (RatList[nRat].nCount < 0) + { + PlotCourseToSprite(nSprite, nTarget); + SetRatVel(nSprite); - int xVal = abs(pSprite->x - sprite[nTarget].x); - int yVal = abs(pSprite->y - sprite[nTarget].y); + RatList[nRat].nCount = 32; + } - if (xVal >= 50 || yVal >= 50) - { - RatList[nRat].nCount--; - if (RatList[nRat].nCount < 0) - { - PlotCourseToSprite(nSprite, nTarget); - SetRatVel(nSprite); + return; + } - RatList[nRat].nCount = 32; - } + RatList[nRat].nAction = 0; + RatList[nRat].nFrame = 0; + RatList[nRat].nIndex = RandomSize(3); - return; - } + pSprite->xvel = 0; + pSprite->yvel = 0; + return; + } + case 2: + { + if (pSprite->xvel || pSprite->yvel || pSprite->zvel) { + MoveCreature(nSprite); + } - RatList[nRat].nAction = 0; - RatList[nRat].nFrame = 0; - RatList[nRat].nIndex = RandomSize(3); + RatList[nRat].nCount--; + if (RatList[nRat].nCount <= 0) + { + RatList[nRat].nTarget = FindFood(nSprite); + if (RatList[nRat].nTarget <= -1) + { + RatList[nRat].nCount = RandomSize(6); + if (pSprite->xvel || pSprite->yvel) + { pSprite->xvel = 0; pSprite->yvel = 0; return; } - case 2: - { - if (pSprite->xvel || pSprite->yvel || pSprite->zvel) { - MoveCreature(nSprite); - } - - RatList[nRat].nCount--; - if (RatList[nRat].nCount <= 0) - { - RatList[nRat].nTarget = FindFood(nSprite); - - if (RatList[nRat].nTarget <= -1) - { - RatList[nRat].nCount = RandomSize(6); - if (pSprite->xvel || pSprite->yvel) - { - pSprite->xvel = 0; - pSprite->yvel = 0; - return; - } - - pSprite->ang = RandomSize(11); - SetRatVel(nSprite); - return; - } - else - { - PlotCourseToSprite(nSprite, RatList[nRat].nTarget); - SetRatVel(nSprite); - RatList[nRat].nAction = 1; - RatList[nRat].nIndex = 900; - RatList[nRat].nFrame = 0; - return; - } - } - return; - } - case 3: - { - if (bVal) - { - runlist_DoSubRunRec(pSprite->owner); - runlist_FreeRun(pSprite->lotag - 1); - runlist_SubRunRec(RatList[nRat].nRun); - - pSprite->cstat = 0x8000; - mydeletesprite(nSprite); - } - return; - } + pSprite->ang = RandomSize(11); + SetRatVel(nSprite); + return; } + else + { + PlotCourseToSprite(nSprite, RatList[nRat].nTarget); + SetRatVel(nSprite); + RatList[nRat].nAction = 1; + RatList[nRat].nIndex = 900; + RatList[nRat].nFrame = 0; + return; + } + } - break; + return; + } + case 3: + { + if (bVal) + { + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); + runlist_SubRunRec(RatList[nRat].nRun); + + pSprite->cstat = 0x8000; + mydeletesprite(nSprite); } + return; } + } +} + + +void FuncRat(int nObject, int nMessage, int nDamage, int nRun) +{ + AIRat ai; + runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun); } + END_PS_NS