- converted all FuncObjects to classes.

This commit is contained in:
Christoph Oelckers 2021-10-15 22:13:05 +02:00
parent 3bda4d5b07
commit f13e1f2127
2 changed files with 913 additions and 878 deletions

View file

@ -513,6 +513,47 @@ struct AIMummy : public ExhumedAI
void RadialDamage(RunListEvent* ev) override;
};
struct AIElev : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Tick(RunListEvent* ev) override;
};
struct AIWallFace : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
};
struct AISlide : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Tick(RunListEvent* ev) override;
};
struct AITrap : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Tick(RunListEvent* ev) override;
};
struct AISpark : public ExhumedAI
{
void Tick(RunListEvent* ev) override;
};
struct AIEnergyBlock : public ExhumedAI
{
virtual void Damage(RunListEvent* ev) override;
virtual void RadialDamage(RunListEvent* ev) override;
};
struct AIObject : 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);

View file

@ -717,8 +717,9 @@ void StartElevSound(short nSprite, int nVal)
D3PlayFX(StaticSound[nSound], nSprite);
}
void FuncElev(int nObject, int nMessage, int, int nRun)
void AIElev::ProcessChannel(RunListEvent* ev)
{
int nRun = ev->nRun;
short nElev = RunData[nRun].nVal;
assert(nElev >= 0 && nElev < (int)Elevator.Size());
@ -727,21 +728,6 @@ void FuncElev(int nObject, int nMessage, int, int nRun)
assert(nChannel >= 0 && nChannel < kMaxChannels);
if (nMessage < 0x10000) {
return;
}
// int var_24 = var_18 & 0x10; // floor based?
switch (nMessage)
{
default:
{
return;
}
case 0x10000:
{
// short ax = var_18 & 8;
short dx = sRunChannels[nChannel].c;
@ -811,12 +797,19 @@ void FuncElev(int nObject, int nMessage, int, int nRun)
Elevator[nElev].field_32 = -1;
}
}
return;
}
case 0x20000:
void AIElev::Tick(RunListEvent* ev)
{
int nRun = ev->nRun;
short nElev = RunData[nRun].nVal;
assert(nElev >= 0 && nElev < (int)Elevator.Size());
short nChannel = Elevator[nElev].nChannel;
short var_18 = Elevator[nElev].field_0;
assert(nChannel >= 0 && nChannel < kMaxChannels);
short nSector = Elevator[nElev].nSector;
short di = Elevator[nElev].nSprite;
@ -931,10 +924,13 @@ void FuncElev(int nObject, int nMessage, int, int nRun)
sprite[di].z += ebp;
di = sprite[di].owner;
}
}
return;
}
}
void FuncElev(int nObject, int nMessage, int nDamage, int nRun)
{
AIElev ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
// done
@ -970,16 +966,13 @@ int BuildWallFace(short nChannel, short nWall, int nCount, ...)
return WallFaceCount;
}
void FuncWallFace(int, int nMessage, int, int nRun)
void AIWallFace::ProcessChannel(RunListEvent* ev)
{
int nWallFace = RunData[nRun].nVal;
int nWallFace = RunData[ev->nRun].nVal;
assert(nWallFace >= 0 && nWallFace < (int)WallFace.Size());
short nChannel = WallFace[nWallFace].nChannel;
if (nMessage != 0x10000)
return;
short si = sRunChannels[nChannel].c;
if ((si <= WallFace[nWallFace].field_4) && (si >= 0))
@ -988,6 +981,12 @@ void FuncWallFace(int, int nMessage, int, int nRun)
}
}
void FuncWallFace(int nObject, int nMessage, int nDamage, int nRun)
{
AIWallFace ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
// done
void InitPoint()
{
@ -1127,21 +1126,14 @@ int BuildSlide(int nChannel, int nStartWall, int nWall1, int ecx, int nWall2, in
return nSlide;
}
void FuncSlide(int, int nMessage , int, int nRun)
void AISlide::ProcessChannel(RunListEvent* ev)
{
int nRun = ev->nRun;
int nSlide = RunData[nRun].nVal;
assert(nSlide >= 0 && nSlide < (int)SlideData.Size());
short nChannel = SlideData[nSlide].nChannel;
int ebp = 0;
short cx = sRunChannels[nChannel].c;
switch (nMessage)
{
case 0x10000:
{
if (SlideData[nSlide].field_4a >= 0)
{
runlist_SubRunRec(SlideData[nSlide].field_4a);
@ -1159,12 +1151,19 @@ void FuncSlide(int, int nMessage , int, int nRun)
D3PlayFX(StaticSound[kSound23], SlideData[nSlide].nSprite);
SlideData[nSlide].field_8a = sRunChannels[nChannel].c;
}
return;
}
case 0x20000:
void AISlide::Tick(RunListEvent* ev)
{
int nRun = ev->nRun;
int nSlide = RunData[nRun].nVal;
assert(nSlide >= 0 && nSlide < (int)SlideData.Size());
short nChannel = SlideData[nSlide].nChannel;
int ebp = 0;
short cx = sRunChannels[nChannel].c;
int clipmask = ebp + 1; // RENAME
if (cx == 1)
@ -1289,10 +1288,12 @@ void FuncSlide(int, int nMessage , int, int nRun)
runlist_ReadyChannel(nChannel);
}
}
return;
}
}
void FuncSlide(int nObject, int nMessage, int nDamage, int nRun)
{
AISlide ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
int BuildTrap(int nSprite, int edx, int ebx, int ecx)
@ -1370,17 +1371,10 @@ int BuildTrap(int nSprite, int edx, int ebx, int ecx)
}
void FuncTrap(int nObject, int nMessage, int, int nRun)
void AITrap::ProcessChannel(RunListEvent* ev)
{
short nTrap = RunData[nRun].nVal;
short nSprite = sTrap[nTrap].nSprite;
auto pSprite = &sprite[nSprite];
switch (nMessage)
{
case 0x10000:
{
short nChannel = nObject & 0x3FFF;
short nChannel = ev->nIndex & 0x3FFF;
short nTrap = RunData[ev->nRun].nVal;
if (sRunChannels[nChannel].c > 0)
{
@ -1390,12 +1384,14 @@ void FuncTrap(int nObject, int nMessage, int, int nRun)
{
sTrap[nTrap].field_0 = -1;
}
return;
}
case 0x20000:
void AITrap::Tick(RunListEvent* ev)
{
short nTrap = RunData[ev->nRun].nVal;
short nSprite = sTrap[nTrap].nSprite;
auto pSprite = &sprite[nSprite];
if (sTrap[nTrap].field_0 >= 0)
{
sTrap[nTrap].field_0--;
@ -1463,20 +1459,12 @@ void FuncTrap(int nObject, int nMessage, int, int nRun)
}
}
}
return;
}
case 0x30000:
case 0x90000:
case 0x80000:
case 0xA0000:
return;
default:
DebugOut("unknown msg %d for trap\n", nMessage);
return;
}
void FuncTrap(int nObject, int nMessage, int nDamage, int nRun)
{
AITrap ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
int BuildArrow(int nSprite, int nVal)
@ -1561,17 +1549,13 @@ int BuildSpark(int nSprite, int nVal)
return var_14;
}
void FuncSpark(int, int nMessage, int, int nRun)
void AISpark::Tick(RunListEvent* ev)
{
int nSprite = RunData[nRun].nVal;
int nSprite = RunData[ev->nRun].nVal;
auto pSprite = &sprite[nSprite];
assert(nSprite >= 0 && nSprite < kMaxSprites);
if (nMessage != 0x20000) {
return;
}
pSprite->shade += 3;
pSprite->xrepeat -= 2;
@ -1615,6 +1599,13 @@ void FuncSpark(int, int nMessage, int, int nRun)
mydeletesprite(nSprite);
}
void FuncSpark(int nObject, int nMessage, int nDamage, int nRun)
{
AISpark ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
void DimLights()
{
static short word_96786 = 0;
@ -1898,62 +1889,24 @@ void ExplodeEnergyBlock(int nSprite)
changespritestat(nSprite, 0);
}
void FuncEnergyBlock(int nObject, int nMessage, int nDamage, int nRun)
void AIEnergyBlock::Damage(RunListEvent* ev)
{
int const nSprite = RunData[nRun].nVal;
int const nSprite = RunData[ev->nRun].nVal;
auto spr = &sprite[nSprite];
switch (nMessage)
{
case 0x20000:
case 0x30000:
case 0x90000:
{
ev->nDamage >>= 2;
if (ev->nDamage <= 0) {
return;
}
case 0xA0000:
if (ev->nDamage < spr->xrepeat)
{
short nSector = spr->sectnum;
if (sector[nSector].extra == -1) {
return;
}
int nFloorZ = sector[nSector].floorz;
sector[nSector].floorz = spr->z;
spr->z -= 256;
nDamage = runlist_CheckRadialDamage(nSprite);
// restore previous values
sector[nSector].floorz = nFloorZ;
spr->z += 256;
if (nDamage <= 0) {
return;
}
// fall through to case 0x80000
fallthrough__;
}
case 0x80000:
{
nDamage >>= 2;
if (nDamage <= 0) {
return;
}
if (nDamage < spr->xrepeat)
{
spr->xrepeat -= nDamage;
spr->xrepeat -= ev->nDamage;
int nSprite2 = insertsprite(lasthitsect, 0);
auto pSprite2 = &sprite[nSprite2];
pSprite2->ang = nObject;
pSprite2->ang = ev->nIndex;
pSprite2->x = lasthitx;
pSprite2->y = lasthity;
pSprite2->z = lasthitz;
@ -1966,10 +1919,44 @@ void FuncEnergyBlock(int nObject, int nMessage, int nDamage, int nRun)
spr->xrepeat = 0; // using xrepeat to store health
ExplodeEnergyBlock(nSprite);
}
}
void AIEnergyBlock::RadialDamage(RunListEvent* ev)
{
int const nSprite = RunData[ev->nRun].nVal;
auto spr = &sprite[nSprite];
short nSector = spr->sectnum;
if (sector[nSector].extra == -1) {
return;
}
int nFloorZ = sector[nSector].floorz;
sector[nSector].floorz = spr->z;
spr->z -= 256;
ev->nDamage = runlist_CheckRadialDamage(nSprite);
// restore previous values
sector[nSector].floorz = nFloorZ;
spr->z += 256;
if (ev->nDamage <= 0) {
return;
}
// fall through to case 0x80000
Damage(ev);
}
void FuncEnergyBlock(int nObject, int nMessage, int nDamage, int nRun)
{
AIEnergyBlock ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
int BuildObject(int const nSprite, int nOjectType, int nHitag)
@ -2053,9 +2040,9 @@ void ExplodeScreen(short nSprite)
PlayFX2(StaticSound[kSound78], nSprite);
}
void FuncObject(int nMessageParm, int nMessage, int b, int nRun)
void AIObject::Tick(RunListEvent* ev)
{
short nObject = RunData[nRun].nVal;
short nObject = RunData[ev->nRun].nVal;
auto pObject = &ObjectList[nObject];
short nSprite = pObject->nSprite;
@ -2063,117 +2050,6 @@ void FuncObject(int nMessageParm, int nMessage, int b, int nRun)
short nStat = pSprite->statnum;
short bx = pObject->field_8;
switch (nMessage)
{
default:
{
DebugOut("unknown msg %d for Object\n", nMessage);
return;
}
case 0x30000:
return;
case 0x80000:
{
if (nStat >= 150 || pObject->nHealth <= 0) {
return;
}
if (nStat == 98)
{
D3PlayFX((StaticSound[kSound47] | 0x2000) | (RandomSize(2) << 9), nSprite);
return;
}
pObject->nHealth -= (short)b;
if (pObject->nHealth > 0) {
return;
}
if (nStat == kStatDestructibleSprite)
{
ExplodeScreen(nSprite);
}
else
{
pObject->nHealth = -(RandomSize(3) + 1);
}
return;
}
case 0x90000:
{
if (bx > -1)
{
seq_PlotSequence(nMessageParm, bx, pObject->field_0, 1);
}
return;
}
case 0xA0000:
{
if (pObject->nHealth > 0 && pSprite->cstat & 0x101
&& (nStat != kStatExplodeTarget
|| sprite[nRadialSpr].statnum == 201
|| (nRadialBullet != 3 && nRadialBullet > -1)
|| sprite[nRadialSpr].statnum == kStatExplodeTrigger))
{
int nDamage = runlist_CheckRadialDamage(nSprite);
if (nDamage <= 0) {
return;
}
if (pSprite->statnum != kStatAnubisDrum) {
pObject->nHealth -= nDamage;
}
if (pSprite->statnum == kStatExplodeTarget)
{
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
}
else if (pSprite->statnum != kStatAnubisDrum)
{
pSprite->xvel >>= 1;
pSprite->yvel >>= 1;
pSprite->zvel >>= 1;
}
if (pObject->nHealth > 0) {
return;
}
if (pSprite->statnum == kStatExplodeTarget)
{
pObject->nHealth = -1;
short ax = pObject->field_10;
if (ax < 0 || ObjectList[ax].nHealth <= 0) {
return;
}
ObjectList[ax].nHealth = -1;
}
else if (pSprite->statnum == kStatDestructibleSprite)
{
pObject->nHealth = 0;
ExplodeScreen(nSprite);
}
else
{
pObject->nHealth = -(RandomSize(4) + 1);
}
}
return;
}
case 0x20000:
{
if (nStat == 97 || (!(pSprite->cstat & 0x101))) {
return;
}
@ -2281,7 +2157,125 @@ FUNCOBJECT_GOTO:
}
}
}
void AIObject::Damage(RunListEvent* ev)
{
short nObject = RunData[ev->nRun].nVal;
auto pObject = &ObjectList[nObject];
short nSprite = pObject->nSprite;
auto pSprite = &sprite[nSprite];
short nStat = pSprite->statnum;
short bx = pObject->field_8;
if (nStat >= 150 || pObject->nHealth <= 0) {
return;
}
if (nStat == 98)
{
D3PlayFX((StaticSound[kSound47] | 0x2000) | (RandomSize(2) << 9), nSprite);
return;
}
pObject->nHealth -= (short)ev->nDamage;
if (pObject->nHealth > 0) {
return;
}
if (nStat == kStatDestructibleSprite)
{
ExplodeScreen(nSprite);
}
else
{
pObject->nHealth = -(RandomSize(3) + 1);
}
}
void AIObject::Draw(RunListEvent* ev)
{
short nObject = RunData[ev->nRun].nVal;
auto pObject = &ObjectList[nObject];
short bx = pObject->field_8;
if (bx > -1)
{
seq_PlotSequence(ev->nIndex, bx, pObject->field_0, 1);
}
return;
}
void AIObject::RadialDamage(RunListEvent* ev)
{
short nObject = RunData[ev->nRun].nVal;
auto pObject = &ObjectList[nObject];
short nSprite = pObject->nSprite;
auto pSprite = &sprite[nSprite];
short nStat = pSprite->statnum;
if (pObject->nHealth > 0 && pSprite->cstat & 0x101
&& (nStat != kStatExplodeTarget
|| sprite[nRadialSpr].statnum == 201
|| (nRadialBullet != 3 && nRadialBullet > -1)
|| sprite[nRadialSpr].statnum == kStatExplodeTrigger))
{
int nDamage = runlist_CheckRadialDamage(nSprite);
if (nDamage <= 0) {
return;
}
if (pSprite->statnum != kStatAnubisDrum) {
pObject->nHealth -= nDamage;
}
if (pSprite->statnum == kStatExplodeTarget)
{
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
}
else if (pSprite->statnum != kStatAnubisDrum)
{
pSprite->xvel >>= 1;
pSprite->yvel >>= 1;
pSprite->zvel >>= 1;
}
if (pObject->nHealth > 0) {
return;
}
if (pSprite->statnum == kStatExplodeTarget)
{
pObject->nHealth = -1;
short ax = pObject->field_10;
if (ax < 0 || ObjectList[ax].nHealth <= 0) {
return;
}
ObjectList[ax].nHealth = -1;
}
else if (pSprite->statnum == kStatDestructibleSprite)
{
pObject->nHealth = 0;
ExplodeScreen(nSprite);
}
else
{
pObject->nHealth = -(RandomSize(4) + 1);
}
}
}
void FuncObject(int nObject, int nMessage, int nDamage, int nRun)
{
AIObject ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
void BuildDrip(int nSprite)