- the rest of object.cpp

This commit is contained in:
Christoph Oelckers 2021-10-21 17:24:52 +02:00
parent b59cb67f05
commit df9d1b1ceb
4 changed files with 92 additions and 123 deletions

View file

@ -334,7 +334,7 @@ short FindWallSprites(short nSector);
void AddMovingSector(int nSector, int edx, int ebx, int ecx); void AddMovingSector(int nSector, int edx, int ebx, int ecx);
void ProcessTrailSprite(int nSprite, int nLotag, int nHitag); void ProcessTrailSprite(int nSprite, int nLotag, int nHitag);
void AddSectorBob(int nSector, int nHitag, int bx); void AddSectorBob(int nSector, int nHitag, int bx);
int BuildObject(int const nSprite, int nOjectType, int nHitag); DExhumedActor* BuildObject(DExhumedActor* nSprite, int nOjectType, int nHitag);
int BuildArrow(DExhumedActor* nSprite, int nVal); int BuildArrow(DExhumedActor* nSprite, int nVal);
int BuildFireBall(DExhumedActor*, int a, int b); int BuildFireBall(DExhumedActor*, int a, int b);
void BuildDrip(int nSprite); void BuildDrip(int nSprite);

View file

@ -411,7 +411,7 @@ void AIAnubis::Damage(RunListEvent* ev)
pDrumSprite->yrepeat = 40; pDrumSprite->yrepeat = 40;
pDrumSprite->shade = -64; pDrumSprite->shade = -64;
BuildObject(pDrumActor->GetSpriteIndex(), 2, 0); BuildObject(pDrumActor, 2, 0);
} }
ap->pTarget = ev->pOtherActor; ap->pTarget = ev->pOtherActor;

View file

@ -692,7 +692,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag)
} }
case 90: case 90:
{ {
BuildObject(nSprite, 3, nHitag); BuildObject(pActor, 3, nHitag);
return; return;
} }
case 79: case 79:
@ -740,12 +740,12 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag)
} }
case 76: // Explosion Trigger (Exploding Fire Cauldron) case 76: // Explosion Trigger (Exploding Fire Cauldron)
{ {
BuildObject(nSprite, 0, nHitag); BuildObject(pActor, 0, nHitag);
return; return;
} }
case 75: // Explosion Target (Cauldrons, fireballs and grenades will destroy nearby 75 sprites) case 75: // Explosion Target (Cauldrons, fireballs and grenades will destroy nearby 75 sprites)
{ {
BuildObject(nSprite, 1, nHitag); BuildObject(pActor, 1, nHitag);
return; return;
} }
case 71: case 71:

View file

@ -102,16 +102,6 @@ struct MoveSect
}; };
struct Object
{
short nFrame;
short nHealth;
short nRun;
short nSprite;
short nIndex;
short nTarget;
};
struct wallFace struct wallFace
{ {
short nChannel; short nChannel;
@ -180,7 +170,7 @@ TArray<Bob> sBob;
TArray<Trail> sTrail; TArray<Trail> sTrail;
TArray<TrailPoint> sTrailPoint; TArray<TrailPoint> sTrailPoint;
TArray<Elev> Elevator; TArray<Elev> Elevator;
TArray<Object> ObjectList; TArray<DExhumedActor*> ObjectList;
TArray<MoveSect> sMoveSect; TArray<MoveSect> sMoveSect;
TArray<slideData> SlideData; TArray<slideData> SlideData;
TArray<wallFace> WallFace; TArray<wallFace> WallFace;
@ -277,21 +267,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, MoveSect& w, MoveS
} }
return arc; return arc;
} }
FSerializer& Serialize(FSerializer& arc, const char* keyname, Object& w, Object* def)
{
if (arc.BeginObject(keyname))
{
arc("at0", w.nFrame)
("health", w.nHealth)
("at4", w.nRun)
("at8", w.nIndex)
("sprite", w.nSprite)
("at8", w.nIndex)
("at10", w.nTarget)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, wallFace& w, wallFace* def) FSerializer& Serialize(FSerializer& arc, const char* keyname, wallFace& w, wallFace* def)
{ {
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))
@ -1948,13 +1924,10 @@ void FuncEnergyBlock(int nObject, int nMessage, int nDamage, int nRun)
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun); runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
} }
int BuildObject(DExhumedActor* pActor, int nOjectType, int nHitag) DExhumedActor* BuildObject(DExhumedActor* pActor, int nOjectType, int nHitag)
{ {
auto spr = &pActor->s(); auto spr = &pActor->s();
auto nObject = ObjectList.Reserve(1);
ObjectList[nObject] = {};
ChangeActorStat(pActor, ObjectStatnum[nOjectType]); ChangeActorStat(pActor, ObjectStatnum[nOjectType]);
// 0x7FFD to ensure set as blocking ('B' and 'H') sprite and also disable translucency and set not invisible // 0x7FFD to ensure set as blocking ('B' and 'H') sprite and also disable translucency and set not invisible
@ -1965,34 +1938,34 @@ int BuildObject(DExhumedActor* pActor, int nOjectType, int nHitag)
spr->extra = -1; spr->extra = -1;
spr->lotag = runlist_HeadRun() + 1; spr->lotag = runlist_HeadRun() + 1;
spr->hitag = 0; spr->hitag = 0;
spr->owner = runlist_AddRunRec(spr->lotag - 1, nObject, 0x170000); spr->owner = runlist_AddRunRec(spr->lotag - 1, pActor, 0x170000);
// GrabTimeSlot(3); // GrabTimeSlot(3);
auto pObject = &ObjectList[nObject]; pActor->nPhase = ObjectList.Push(pActor);
if (spr->statnum == kStatDestructibleSprite) { if (spr->statnum == kStatDestructibleSprite) {
pObject->nHealth = 4; pActor->nHealth = 4;
} }
else { else {
pObject->nHealth = 120; pActor->nHealth = 120;
} }
pObject->nSprite = pActor->GetSpriteIndex(); pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x170000);
pObject->nRun = runlist_AddRunRec(NewRun, nObject, 0x170000);
short nSeq = ObjectSeq[nOjectType]; short nSeq = ObjectSeq[nOjectType];
if (nSeq > -1) if (nSeq > -1)
{ {
pObject->nIndex = SeqOffsets[nSeq]; pActor->nIndex = SeqOffsets[nSeq];
if (!nOjectType) // if not Explosion Trigger (e.g. Exploding Fire Cauldron) if (!nOjectType) // if not Explosion Trigger (e.g. Exploding Fire Cauldron)
{ {
pObject->nFrame = RandomSize(4) % (SeqSize[pObject->nIndex] - 1); pActor->nFrame = RandomSize(4) % (SeqSize[pActor->nIndex] - 1);
} }
int nSprite2 = insertsprite(spr->sectnum, 0); auto pActor2 = insertActor(spr->sectnum, 0);
auto pSprite2 = &sprite[nSprite2]; auto pSprite2 = &pActor2->s();
pObject->nTarget = nSprite2; pActor->pTarget = pActor2;
pActor->nIndex2 = -1;
pSprite2->cstat = 0x8000; pSprite2->cstat = 0x8000;
pSprite2->x = spr->x; pSprite2->x = spr->x;
@ -2001,45 +1974,42 @@ int BuildObject(DExhumedActor* pActor, int nOjectType, int nHitag)
} }
else else
{ {
pObject->nFrame = 0; pActor->nFrame = 0;
pObject->nIndex = -1; pActor->nIndex = -1;
if (spr->statnum == kStatDestructibleSprite) { if (spr->statnum == kStatDestructibleSprite) {
pObject->nTarget = -1; pActor->nIndex2 = -1;
} }
else { else {
pObject->nTarget = -nHitag; pActor->nIndex2 = -nHitag;
} }
} }
spr->backuppos(); spr->backuppos();
return nObject | 0x170000; return pActor;
} }
// in-game destructable wall mounted screen // in-game destructable wall mounted screen
void ExplodeScreen(short nSprite) void ExplodeScreen(DExhumedActor* pActor)
{ {
auto pSprite = &sprite[nSprite]; auto pSprite = &pActor->s();
pSprite->z -= GetSpriteHeight(nSprite) / 2; pSprite->z -= GetActorHeight(pActor) / 2;
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
BuildSpark(&exhumedActors[nSprite], 0); // shoot out blue orbs BuildSpark(pActor, 0); // shoot out blue orbs
} }
pSprite->cstat = 0x8000; pSprite->cstat = 0x8000;
PlayFX2(StaticSound[kSound78], nSprite); PlayFX2(StaticSound[kSound78], pActor);
} }
void AIObject::Tick(RunListEvent* ev) void AIObject::Tick(RunListEvent* ev)
{ {
short nObject = RunData[ev->nRun].nObjIndex; auto pActor = ev->pObjActor;
auto pObject = &ObjectList[nObject]; if (!pActor) return;
auto pSprite = &pActor->s();
auto pActor = &exhumedActors[pObject->nSprite];// ev->pObjActor;
short nSprite = pObject->nSprite;
auto pSprite = &sprite[nSprite];
short nStat = pSprite->statnum; short nStat = pSprite->statnum;
short bx = pObject->nIndex; short bx = pActor->nIndex;
if (nStat == 97 || (!(pSprite->cstat & 0x101))) { if (nStat == 97 || (!(pSprite->cstat & 0x101))) {
return; return;
@ -2052,38 +2022,38 @@ void AIObject::Tick(RunListEvent* ev)
// do animation // do animation
if (bx != -1) if (bx != -1)
{ {
pObject->nFrame++; pActor->nFrame++;
if (pObject->nFrame >= SeqSize[bx]) { if (pActor->nFrame >= SeqSize[bx]) {
pObject->nFrame = 0; pActor->nFrame = 0;
} }
pSprite->picnum = seq_GetSeqPicnum2(bx, pObject->nFrame); pSprite->picnum = seq_GetSeqPicnum2(bx, pActor->nFrame);
} }
if (pObject->nHealth >= 0) { if (pActor->nHealth >= 0) {
goto FUNCOBJECT_GOTO; goto FUNCOBJECT_GOTO;
} }
pObject->nHealth++; pActor->nHealth++;
if (pObject->nHealth) if (pActor->nHealth)
{ {
FUNCOBJECT_GOTO: FUNCOBJECT_GOTO:
if (nStat != kStatExplodeTarget) if (nStat != kStatExplodeTarget)
{ {
int nMov = movesprite(nSprite, pSprite->xvel << 6, pSprite->yvel << 6, pSprite->zvel, 0, 0, CLIPMASK0); auto nMov = movesprite(pActor, pSprite->xvel << 6, pSprite->yvel << 6, pSprite->zvel, 0, 0, CLIPMASK0);
if (pSprite->statnum == kStatExplodeTrigger) { if (pSprite->statnum == kStatExplodeTrigger) {
pSprite->pal = 1; pSprite->pal = 1;
} }
if (nMov & 0x20000) if (nMov.exbits & kHitAux2)
{ {
pSprite->xvel -= pSprite->xvel >> 3; pSprite->xvel -= pSprite->xvel >> 3;
pSprite->yvel -= pSprite->yvel >> 3; pSprite->yvel -= pSprite->yvel >> 3;
} }
if (((nMov & 0xC000) > 0x8000) && ((nMov & 0xC000) == 0xC000)) if (nMov.type == kHitSprite)
{ {
pSprite->yvel = 0; pSprite->yvel = 0;
pSprite->xvel = 0; pSprite->xvel = 0;
@ -2114,36 +2084,37 @@ void AIObject::Tick(RunListEvent* ev)
if (nStat == kStatExplodeTrigger) if (nStat == kStatExplodeTrigger)
{ {
for (int i = 4; i < 8; i++) { for (int i = 4; i < 8; i++) {
BuildCreatureChunk(nSprite | 0x4000, seq_GetSeqPicnum(kSeqFirePot, (i >> 2) + 1, 0)); BuildCreatureChunk(pActor, seq_GetSeqPicnum(kSeqFirePot, (i >> 2) + 1, 0), true);
} }
runlist_RadialDamageEnemy(nSprite, 200, 20); runlist_RadialDamageEnemy(pActor, 200, 20);
} }
else if (nStat == kStatExplodeTarget) else if (nStat == kStatExplodeTarget)
{ {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
BuildCreatureChunk(nSprite | 0x4000, seq_GetSeqPicnum(kSeqFirePot, (i >> 1) + 3, 0)); BuildCreatureChunk(pActor, seq_GetSeqPicnum(kSeqFirePot, (i >> 1) + 3, 0), true);
} }
} }
if (!(currentLevel->gameflags & LEVEL_EX_MULTI) || nStat != kStatExplodeTrigger) if (!(currentLevel->gameflags & LEVEL_EX_MULTI) || nStat != kStatExplodeTrigger)
{ {
runlist_SubRunRec(pSprite->owner); runlist_SubRunRec(pSprite->owner);
runlist_SubRunRec(pObject->nRun); runlist_SubRunRec(pActor->nRun);
mydeletesprite(nSprite); DeleteActor(pActor);
return; return;
} }
else else
{ {
StartRegenerate(pActor); StartRegenerate(pActor);
pObject->nHealth = 120; pActor->nHealth = 120;
pSprite->x = sprite[pObject->nTarget].x; auto pTargSpr = &pActor->pTarget->s();
pSprite->y = sprite[pObject->nTarget].y; pSprite->x = pTargSpr->x;
pSprite->z = sprite[pObject->nTarget].z; pSprite->y = pTargSpr->y;
pSprite->z = pTargSpr->z;
mychangespritesect(nSprite, sprite[pObject->nTarget].sectnum); ChangeActorSect(pActor, pTargSpr->sectnum);
return; return;
} }
} }
@ -2151,74 +2122,71 @@ void AIObject::Tick(RunListEvent* ev)
void AIObject::Damage(RunListEvent* ev) void AIObject::Damage(RunListEvent* ev)
{ {
short nObject = RunData[ev->nRun].nObjIndex; auto pActor = ev->pObjActor;
auto pObject = &ObjectList[nObject]; if (!pActor) return;
auto pSprite = &pActor->s();
short nSprite = pObject->nSprite;
auto pSprite = &sprite[nSprite];
short nStat = pSprite->statnum; short nStat = pSprite->statnum;
short bx = pObject->nIndex; short bx = pActor->nIndex;
if (nStat >= 150 || pObject->nHealth <= 0) { if (nStat >= 150 || pActor->nHealth <= 0) {
return; return;
} }
if (nStat == 98) if (nStat == 98)
{ {
D3PlayFX((StaticSound[kSound47] | 0x2000) | (RandomSize(2) << 9), nSprite); D3PlayFX((StaticSound[kSound47] | 0x2000) | (RandomSize(2) << 9), pActor);
return; return;
} }
pObject->nHealth -= (short)ev->nDamage; pActor->nHealth -= (short)ev->nDamage;
if (pObject->nHealth > 0) { if (pActor->nHealth > 0) {
return; return;
} }
if (nStat == kStatDestructibleSprite) if (nStat == kStatDestructibleSprite)
{ {
ExplodeScreen(nSprite); ExplodeScreen(pActor);
} }
else else
{ {
pObject->nHealth = -(RandomSize(3) + 1); pActor->nHealth = -(RandomSize(3) + 1);
} }
} }
void AIObject::Draw(RunListEvent* ev) void AIObject::Draw(RunListEvent* ev)
{ {
short nObject = RunData[ev->nRun].nObjIndex; auto pActor = ev->pObjActor;
auto pObject = &ObjectList[nObject]; if (!pActor) return;
short bx = pObject->nIndex; short bx = pActor->nIndex;
if (bx > -1) if (bx > -1)
{ {
seq_PlotSequence(ev->nParam, bx, pObject->nFrame, 1); seq_PlotSequence(ev->nParam, bx, pActor->nFrame, 1);
} }
return; return;
} }
void AIObject::RadialDamage(RunListEvent* ev) void AIObject::RadialDamage(RunListEvent* ev)
{ {
short nObject = RunData[ev->nRun].nObjIndex; auto pActor = ev->pObjActor;
auto pObject = &ObjectList[nObject]; if (!pActor) return;
short nSprite = pObject->nSprite; auto pSprite = &pActor->s();
auto pSprite = &sprite[nSprite];
short nStat = pSprite->statnum; short nStat = pSprite->statnum;
if (pObject->nHealth > 0 && pSprite->cstat & 0x101 if (pActor->nHealth > 0 && pSprite->cstat & 0x101
&& (nStat != kStatExplodeTarget && (nStat != kStatExplodeTarget
|| sprite[nRadialSpr].statnum == 201 || sprite[nRadialSpr].statnum == 201
|| (nRadialBullet != 3 && nRadialBullet > -1) || (nRadialBullet != 3 && nRadialBullet > -1)
|| sprite[nRadialSpr].statnum == kStatExplodeTrigger)) || sprite[nRadialSpr].statnum == kStatExplodeTrigger))
{ {
int nDamage = runlist_CheckRadialDamage(nSprite); int nDamage = runlist_CheckRadialDamage(pActor);
if (nDamage <= 0) { if (nDamage <= 0) {
return; return;
} }
if (pSprite->statnum != kStatAnubisDrum) { if (pSprite->statnum != kStatAnubisDrum) {
pObject->nHealth -= nDamage; pActor->nHealth -= nDamage;
} }
if (pSprite->statnum == kStatExplodeTarget) if (pSprite->statnum == kStatExplodeTarget)
@ -2234,30 +2202,30 @@ void AIObject::RadialDamage(RunListEvent* ev)
pSprite->zvel >>= 1; pSprite->zvel >>= 1;
} }
if (pObject->nHealth > 0) { if (pActor->nHealth > 0) {
return; return;
} }
if (pSprite->statnum == kStatExplodeTarget) if (pSprite->statnum == kStatExplodeTarget)
{ {
pObject->nHealth = -1; pActor->nHealth = -1;
short ax = pObject->nTarget; short ax = pActor->nIndex2;
if (ax < 0 || ObjectList[ax].nHealth <= 0) { if (ax < 0 || ObjectList[ax]->nHealth <= 0) {
return; return;
} }
ObjectList[ax].nHealth = -1; ObjectList[ax]->nHealth = -1;
} }
else if (pSprite->statnum == kStatDestructibleSprite) else if (pSprite->statnum == kStatDestructibleSprite)
{ {
pObject->nHealth = 0; pActor->nHealth = 0;
ExplodeScreen(nSprite); ExplodeScreen(pActor);
} }
else else
{ {
pObject->nHealth = -(RandomSize(4) + 1); pActor->nHealth = -(RandomSize(4) + 1);
} }
} }
} }
@ -2765,24 +2733,25 @@ void PostProcess()
for (unsigned i = 0; i < ObjectList.Size(); i++) for (unsigned i = 0; i < ObjectList.Size(); i++)
{ {
int nObjectSprite = ObjectList[i].nSprite; auto pObjectActor = ObjectList[i];
if (sprite[nObjectSprite].statnum == kStatExplodeTarget) if (pObjectActor->s().statnum == kStatExplodeTarget)
{ {
if (!ObjectList[i].nTarget) { if (!pObjectActor->nIndex2) {
ObjectList[i].nTarget = -1; pObjectActor->nIndex2 = -1;
} }
else else
{ {
int edi = ObjectList[i].nTarget; int edi = pObjectActor->nIndex2;
ObjectList[i].nTarget = -1; pObjectActor->nIndex2 = -1;
for (unsigned j = 0; j < ObjectList.Size(); j++) for (unsigned j = 0; j < ObjectList.Size(); j++)
{ {
if (i != j && sprite[ObjectList[j].nSprite].statnum == kStatExplodeTarget && edi == ObjectList[j].nTarget)
if (i != j && ObjectList[j]->s().statnum == kStatExplodeTarget && edi == ObjectList[j]->nIndex2)
{ {
ObjectList[i].nTarget = j; pObjectActor->nIndex2 = j;
ObjectList[j].nTarget = i; ObjectList[j]->nIndex2 = i;
} }
} }
} }