- converted switches to classes.

This commit is contained in:
Christoph Oelckers 2021-10-15 23:40:02 +02:00
parent 601d358b49
commit 9badd2e78b
2 changed files with 290 additions and 257 deletions

View file

@ -661,6 +661,43 @@ struct AIWasp : public ExhumedAI
void RadialDamage(RunListEvent* ev) override;
};
struct AISWReady : public ExhumedAI
{
void Process(RunListEvent* ev) override;
};
struct AISWPause : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Tick(RunListEvent* ev) override;
void Process(RunListEvent* ev) override;
};
struct AISWStepOn : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void TouchFloor(RunListEvent* ev) override;
};
struct AISWNotOnPause : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Tick(RunListEvent* ev) override;
void Process(RunListEvent* ev) override;
void TouchFloor(RunListEvent* ev) override;
};
struct AISWPressSector : public ExhumedAI
{
void ProcessChannel(RunListEvent* ev) override;
void Use(RunListEvent* ev) override;
};
struct AISWPressWall : public ExhumedAI
{
void Process(RunListEvent* ev) override;
void Use(RunListEvent* ev) override;
};
void runlist_DispatchEvent(ExhumedAI* ai, int nObject, int nMessage, int nDamage, int nRun);

View file

@ -135,33 +135,25 @@ std::pair<int, int> BuildSwReady(int nChannel, short nLink)
return { SwitchCount, 0x10000 };
}
void FuncSwReady(int nObject, int nMessage, int, int nRun)
void AISWReady::Process(RunListEvent* ev)
{
short nSwitch = RunData[nRun].nVal;
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
switch (nMessage)
{
case 0x10000:
return;
case 0x30000:
{
assert(sRunChannels[nChannel].c < 8);
int8_t nVal = LinkMap[nLink].v[sRunChannels[nChannel].c];
if (nVal >= 0) {
runlist_ChangeChannel(nChannel, nVal);
}
break;
}
default:
return;
}
void FuncSwReady(int nObject, int nMessage, int, int nRun)
{
AISWReady ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
std::pair<int, int> BuildSwPause(int nChannel, int nLink, int ebx)
@ -187,32 +179,22 @@ std::pair<int, int> BuildSwPause(int nChannel, int nLink, int ebx)
return { SwitchCount, 0x20000 };
}
void FuncSwPause(int nObject, int nMessage, int, int nRun)
{
short nSwitch = RunData[nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
switch (nMessage)
{
default:
return;
case 0x10000:
void AISWPause::ProcessChannel(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
if (SwitchData[nSwitch].nRunPtr >= 0)
{
runlist_SubRunRec(SwitchData[nSwitch].nRunPtr);
SwitchData[nSwitch].nRunPtr = -1;
}
return;
}
case 0x20000:
void AISWPause::Tick(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
SwitchData[nSwitch].nWaitTimer--;
if (SwitchData[nSwitch].nWaitTimer <= 0)
{
@ -224,12 +206,13 @@ void FuncSwPause(int nObject, int nMessage, int, int nRun)
runlist_ChangeChannel(nChannel, LinkMap[nLink].v[sRunChannels[nChannel].c]);
}
return;
}
case 0x30000:
void AISWPause::Process(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
assert(sRunChannels[nChannel].c < 8);
if (LinkMap[nLink].v[sRunChannels[nChannel].c] < 0) {
@ -240,7 +223,7 @@ void FuncSwPause(int nObject, int nMessage, int, int nRun)
return;
}
SwitchData[nSwitch].nRunPtr = runlist_AddRunRec(NewRun, RunData[nRun].nVal, RunData[nRun].nRef);
SwitchData[nSwitch].nRunPtr = runlist_AddRunRec(NewRun, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
int eax;
@ -254,9 +237,12 @@ void FuncSwPause(int nObject, int nMessage, int, int nRun)
}
SwitchData[nSwitch].nWaitTimer = eax;
return;
}
}
void FuncSwPause(int nObject, int nMessage, int, int nRun)
{
AISWPause ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
std::pair<int, int> BuildSwStepOn(int nChannel, int nLink, int nSector)
@ -274,9 +260,9 @@ std::pair<int, int> BuildSwStepOn(int nChannel, int nLink, int nSector)
return { nSwitch , 0x30000 };
}
void FuncSwStepOn(int nObject, int nMessage, int, int nRun)
void AISWStepOn::ProcessChannel(RunListEvent* ev)
{
short nSwitch = RunData[nRun].nVal;
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nLink = SwitchData[nSwitch].nLink;
@ -287,13 +273,6 @@ void FuncSwStepOn(int nObject, int nMessage, int, int nRun)
int8_t var_14 = LinkMap[nLink].v[sRunChannels[nChannel].c];
switch (nMessage)
{
default:
return;
case 0x10000:
{
if (SwitchData[nSwitch].nRun2 >= 0)
{
runlist_SubRunRec(SwitchData[nSwitch].nRun2);
@ -302,14 +281,23 @@ void FuncSwStepOn(int nObject, int nMessage, int, int nRun)
if (var_14 >= 0)
{
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[nRun].nVal, RunData[nRun].nRef);
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
}
}
return;
}
case 0x50000:
void AISWStepOn::TouchFloor(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nLink = SwitchData[nSwitch].nLink;
short nChannel = SwitchData[nSwitch].nChannel;
short nSector = SwitchData[nSwitch].nSector;
assert(sRunChannels[nChannel].c < 8);
int8_t var_14 = LinkMap[nLink].v[sRunChannels[nChannel].c];
if (var_14 != sRunChannels[nChannel].c)
{
short nWall = sector[nSector].wallptr;
@ -321,9 +309,10 @@ void FuncSwStepOn(int nObject, int nMessage, int, int nRun)
}
}
return;
}
void FuncSwStepOn(int nObject, int nMessage, int, int nRun)
{
AISWStepOn ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
std::pair<int, int> BuildSwNotOnPause(int nChannel, int nLink, int nSector, int ecx)
@ -343,21 +332,11 @@ std::pair<int, int> BuildSwNotOnPause(int nChannel, int nLink, int nSector, int
return { nSwitch, 0x40000 };
}
void FuncSwNotOnPause(int nObject, int nMessage, int, int nRun)
void AISWNotOnPause::ProcessChannel(RunListEvent* ev)
{
short nSwitch = RunData[nRun].nVal;
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
switch (nMessage)
{
default:
return;
case 0x10000:
{
if (SwitchData[nSwitch].nRun2 >= 0)
{
runlist_SubRunRec(SwitchData[nSwitch].nRun2);
@ -373,8 +352,14 @@ void FuncSwNotOnPause(int nObject, int nMessage, int, int nRun)
return;
}
case 0x20000:
void AISWNotOnPause::Tick(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
SwitchData[nSwitch].nWaitTimer -= 4;
if (SwitchData[nSwitch].nWaitTimer <= 0)
{
@ -382,36 +367,44 @@ void FuncSwNotOnPause(int nObject, int nMessage, int, int nRun)
runlist_ChangeChannel(nChannel, LinkMap[nLink].v[sRunChannels[nChannel].c]);
}
return;
}
case 0x30000:
void AISWNotOnPause::Process(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
assert(sRunChannels[nChannel].c < 8);
if (LinkMap[nLink].v[sRunChannels[nChannel].c] >= 0)
{
if (SwitchData[nSwitch].nRunPtr < 0)
{
SwitchData[nSwitch].nRunPtr = runlist_AddRunRec(NewRun, RunData[nRun].nVal, RunData[nRun].nRef);
SwitchData[nSwitch].nRunPtr = runlist_AddRunRec(NewRun, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
short nSector = SwitchData[nSwitch].nSector;
SwitchData[nSwitch].nWaitTimer = SwitchData[nSwitch].nWait;
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[nRun].nVal, RunData[nRun].nRef);
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
}
}
}
return;
}
case 0x50000:
void AISWNotOnPause::TouchFloor(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
SwitchData[nSwitch].nWaitTimer = SwitchData[nSwitch].nWait;
return;
}
}
void FuncSwNotOnPause(int nObject, int nMessage, int, int nRun)
{
AISWNotOnPause ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
std::pair<int, int> BuildSwPressSector(int nChannel, int nLink, int nSector, int keyMask)
@ -430,21 +423,14 @@ std::pair<int, int> BuildSwPressSector(int nChannel, int nLink, int nSector, int
return { nSwitch, 0x50000 };
}
void FuncSwPressSector(int nPlayer, int nMessage, int, int nRun)
void AISWPressSector::ProcessChannel(RunListEvent* ev)
{
short nSwitch = RunData[nRun].nVal;
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
switch (nMessage)
{
default:
return;
case 0x10000:
{
if (SwitchData[nSwitch].nRun2 >= 0)
{
runlist_SubRunRec(SwitchData[nSwitch].nRun2);
@ -459,12 +445,18 @@ void FuncSwPressSector(int nPlayer, int nMessage, int, int nRun)
short nSector = SwitchData[nSwitch].nSector;
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[nRun].nVal, RunData[nRun].nRef);
return;
SwitchData[nSwitch].nRun2 = runlist_AddRunRec(sector[nSector].lotag - 1, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
}
case 0x40000:
void AISWPressSector::Use(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
int nPlayer = ev->nIndex;
if ((PlayerList[nPlayer].keys & SwitchData[nSwitch].nKeyMask) == SwitchData[nSwitch].nKeyMask)
{
runlist_ChangeChannel(nChannel, LinkMap[nLink].v[sRunChannels[nChannel].c]);
@ -479,8 +471,13 @@ void FuncSwPressSector(int nPlayer, int nMessage, int, int nRun)
StatusMessage(300, "YOU NEED THE KEY FOR THIS DOOR");
}
}
}
}
void FuncSwPressSector(int nObject, int nMessage, int, int nRun)
{
AISWPressSector ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
std::pair<int, int> BuildSwPressWall(short nChannel, short nLink, short nWall)
@ -499,21 +496,14 @@ std::pair<int, int> BuildSwPressWall(short nChannel, short nLink, short nWall)
return { SwitchCount, 0x60000 };
}
void FuncSwPressWall(int, int nMessage, int, int nRun)
void AISWPressWall::Process(RunListEvent* ev)
{
short nSwitch = RunData[nRun].nVal;
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
switch (nMessage)
{
default:
return;
case 0x30000:
{
if (SwitchData[nSwitch].nRun3 >= 0)
{
runlist_SubRunRec(SwitchData[nSwitch].nRun3);
@ -523,14 +513,18 @@ void FuncSwPressWall(int, int nMessage, int, int nRun)
if (LinkMap[nLink].v[sRunChannels[nChannel].c] >= 0)
{
short nWall = SwitchData[nSwitch].nWall;
SwitchData[nSwitch].nRun3 = runlist_AddRunRec(wall[nWall].lotag - 1, RunData[nRun].nVal, RunData[nRun].nRef);
SwitchData[nSwitch].nRun3 = runlist_AddRunRec(wall[nWall].lotag - 1, RunData[ev->nRun].nVal, RunData[ev->nRun].nRef);
}
}
return;
}
case 0x40000:
void AISWPressWall::Use(RunListEvent* ev)
{
short nSwitch = RunData[ev->nRun].nVal;
assert(nSwitch >= 0 && nSwitch < kMaxSwitches);
short nChannel = SwitchData[nSwitch].nChannel;
short nLink = SwitchData[nSwitch].nLink;
int8_t cx = LinkMap[nLink].v[sRunChannels[nChannel].c];
runlist_ChangeChannel(nChannel, LinkMap[nLink].v[sRunChannels[nChannel].c]);
@ -545,9 +539,11 @@ void FuncSwPressWall(int, int nMessage, int, int nRun)
short nSector = SwitchData[nSwitch].nSector; // CHECKME - where is this set??
PlayFXAtXYZ(StaticSound[nSwitchSound], wall[nWall].x, wall[nWall].y, 0, nSector, CHANF_LISTENERZ);
}
return;
}
}
void FuncSwPressWall(int nObject, int nMessage, int, int nRun)
{
AISWPressWall ai;
runlist_DispatchEvent(&ai, nObject, nMessage, 0, nRun);
}
END_PS_NS