diff --git a/source/games/blood/src/bloodactor.h b/source/games/blood/src/bloodactor.h index 8e2f7562c..bdf568610 100644 --- a/source/games/blood/src/bloodactor.h +++ b/source/games/blood/src/bloodactor.h @@ -298,6 +298,11 @@ class BloodLinearSpriteIterator int index = 0; public: + void Reset() + { + index = 0; + } + DBloodActor* Next() { while (index < MAXSPRITES) diff --git a/source/games/blood/src/eventq.cpp b/source/games/blood/src/eventq.cpp index fa168c9e2..3ba97f1ee 100644 --- a/source/games/blood/src/eventq.cpp +++ b/source/games/blood/src/eventq.cpp @@ -424,7 +424,7 @@ void evSend(DBloodActor* actor, int nIndex, int nType, int rxId, COMMAND_ID comm { XSPRITE* pXSprite = &actor->x(); if (pXSprite->rxID == rxId) - trMessageSprite(actor->s().index, event); + trMessageSprite(actor, event); } } return; @@ -442,7 +442,7 @@ void evSend(DBloodActor* actor, int nIndex, int nType, int rxId, COMMAND_ID comm { XSPRITE* pXSprite = &actor->x(); if (pXSprite->rxID == rxId) - trMessageSprite(actor->s().index, event); + trMessageSprite(actor, event); } } return; @@ -459,14 +459,14 @@ void evSend(DBloodActor* actor, int nIndex, int nType, int rxId, COMMAND_ID comm if (playerRXRngIsFine(rxId)) { if ((pPlayer = getPlayerById((rxId - kChannelPlayer7) + kMaxPlayers)) != nullptr) - trMessageSprite(pPlayer->nSprite, event); + trMessageSprite(pPlayer->actor(), event); } else if (rxId == kChannelAllPlayers) { for (int i = 0; i < kMaxPlayers; i++) { if ((pPlayer = getPlayerById(i)) != nullptr) - trMessageSprite(pPlayer->nSprite, event); + trMessageSprite(pPlayer->actor(), event); } return; } @@ -493,7 +493,7 @@ void evSend(DBloodActor* actor, int nIndex, int nType, int rxId, COMMAND_ID comm { XSPRITE* pXSprite = &actor->x(); if (actor->x().rxID > 0) - trMessageSprite(actor->s().index, event); + trMessageSprite(actor, event); } break; } @@ -650,7 +650,7 @@ void evProcess(unsigned int time) trMessageWall(event.index_, event); break; case SS_SPRITE: - trMessageSprite(event.actor->s().index, event); + trMessageSprite(event.actor, event); break; } } diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index 9eddcc8a1..d7a918c50 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -273,7 +273,7 @@ void LifeLeechOperate(DBloodActor* actor, EVENT event) actPostSprite(actor, kStatFree); } -void ActivateGenerator(int); +void ActivateGenerator(DBloodActor*); void OperateSprite(DBloodActor* actor, EVENT event) { @@ -556,7 +556,7 @@ void OperateSprite(DBloodActor* actor, EVENT event) SetSpriteState(actor, 0); break; case kCmdRepeat: - if (pSprite->type != kGenTrigger) ActivateGenerator(pSprite->index); + if (pSprite->type != kGenTrigger) ActivateGenerator(actor); if (pXSprite->txID) evSendActor(actor, pXSprite->txID, (COMMAND_ID)pXSprite->command); if (pXSprite->busyTime > 0) { int nRand = Random2(pXSprite->data1); @@ -1823,8 +1823,8 @@ void trMessageWall(unsigned int nWall, EVENT event) { } } -void trMessageSprite(unsigned int nSprite, EVENT event) { - auto actor = &bloodActors[nSprite]; +void trMessageSprite(DBloodActor* actor, EVENT event) +{ auto pSprite = &actor->s(); auto pXSprite = &actor->x(); if (pSprite->statnum != kStatFree) { @@ -1993,7 +1993,7 @@ void trProcessBusy(void) AlignSlopes(); } -void InitGenerator(int); +void InitGenerator(DBloodActor*); void trInit(void) { @@ -2099,16 +2099,17 @@ void trInit(void) } } } - for (int i = 0; i < kMaxSprites; i++) + + it.Reset(); + while (auto actor = it.Next()) { - int nXSprite = sprite[i].extra; - if (sprite[i].statnum < kStatFree && nXSprite > 0) + auto pSprite = &actor->s(); + if (pSprite->statnum < kStatFree && actor->hasX()) { - assert(nXSprite < kMaxXSprites); - XSPRITE *pXSprite = &xsprite[nXSprite]; + auto pXSprite = &actor->x(); if (pXSprite->state) pXSprite->busy = 65536; - switch (sprite[i].type) { + switch (pSprite->type) { case kSwitchPadlock: pXSprite->triggerOnce = 1; break; @@ -2117,9 +2118,9 @@ void trInit(void) case kModernRandom2: if (!gModernMap || pXSprite->state == pXSprite->restState) break; - evPostActor(&bloodActors[i], (120 * pXSprite->busyTime) / 10, kCmdRepeat); + evPostActor(actor, (120 * pXSprite->busyTime) / 10, kCmdRepeat); if (pXSprite->waitTime > 0) - evPostActor(&bloodActors[i], (pXSprite->waitTime * 120) / 10, pXSprite->restState ? kCmdOn : kCmdOff); + evPostActor(actor, (pXSprite->waitTime * 120) / 10, pXSprite->restState ? kCmdOn : kCmdOff); break; case kModernSeqSpawner: case kModernObjDataAccumulator: @@ -2127,9 +2128,9 @@ void trInit(void) case kModernEffectSpawner: case kModernWindGenerator: if (pXSprite->state == pXSprite->restState) break; - evPostActor(&bloodActors[i], 0, kCmdRepeat); + evPostActor(actor, 0, kCmdRepeat); if (pXSprite->waitTime > 0) - evPostActor(&bloodActors[i], (pXSprite->waitTime * 120) / 10, pXSprite->restState ? kCmdOn : kCmdOff); + evPostActor(actor, (pXSprite->waitTime * 120) / 10, pXSprite->restState ? kCmdOn : kCmdOff); break; #endif case kGenTrigger: @@ -2141,18 +2142,18 @@ void trInit(void) case kGenBubbleMulti: case kGenMissileEctoSkull: case kGenSound: - InitGenerator(i); + InitGenerator(actor); break; case kThingArmedProxBomb: pXSprite->Proximity = 1; break; case kThingFallingRock: - if (pXSprite->state) sprite[i].flags |= 7; - else sprite[i].flags &= ~7; + if (pXSprite->state) pSprite->flags |= 7; + else pSprite->flags &= ~7; break; } - if (pXSprite->Vector) sprite[i].cstat |= CSTAT_SPRITE_BLOCK_HITSCAN; - if (pXSprite->Push) sprite[i].cstat |= 4096; + if (pXSprite->Vector) pSprite->cstat |= CSTAT_SPRITE_BLOCK_HITSCAN; + if (pXSprite->Push) pSprite->cstat |= 4096; } } @@ -2178,38 +2179,31 @@ void trTextOver(int nId) viewSetMessage(pzMessage, VanillaMode() ? 0 : 8, MESSAGE_PRIORITY_INI); // 8: gold } -void InitGenerator(int nSprite) +void InitGenerator(DBloodActor* actor) { - assert(nSprite < kMaxSprites); - spritetype *pSprite = &sprite[nSprite]; - assert(pSprite->statnum != kMaxStatus); - int nXSprite = pSprite->extra; - assert(nXSprite > 0); - XSPRITE *pXSprite = &xsprite[nXSprite]; - switch (sprite[nSprite].type) { + spritetype *pSprite = &actor->s(); + assert(actor->hasX()); + XSPRITE *pXSprite = &actor->x(); + switch (pSprite->type) { case kGenTrigger: pSprite->cstat &= ~CSTAT_SPRITE_BLOCK; pSprite->cstat |= CSTAT_SPRITE_INVISIBLE; break; } if (pXSprite->state != pXSprite->restState && pXSprite->busyTime > 0) - evPostActor(&bloodActors[nSprite], (120*(pXSprite->busyTime+Random2(pXSprite->data1)))/10, kCmdRepeat); + evPostActor(actor, (120*(pXSprite->busyTime+Random2(pXSprite->data1)))/10, kCmdRepeat); } -void ActivateGenerator(int nSprite) +void ActivateGenerator(DBloodActor* actor) { - assert(nSprite < kMaxSprites); - auto actor = &bloodActors[nSprite]; - spritetype *pSprite = &sprite[nSprite]; - assert(pSprite->statnum != kMaxStatus); - int nXSprite = pSprite->extra; - assert(nXSprite > 0); - XSPRITE *pXSprite = &xsprite[nXSprite]; + spritetype *pSprite = &actor->s(); + assert(actor->hasX()); + XSPRITE *pXSprite = &actor->x(); switch (pSprite->type) { case kGenDripWater: case kGenDripBlood: { int top, bottom; - GetSpriteExtents(pSprite, &top, &bottom); + GetActorExtents(actor, &top, &bottom); actSpawnThing(pSprite->sectnum, pSprite->x, pSprite->y, bottom, (pSprite->type == kGenDripWater) ? kThingDripWater : kThingDripBlood); break; } @@ -2219,7 +2213,7 @@ void ActivateGenerator(int nSprite) case kGenMissileFireball: switch (pXSprite->data2) { case 0: - FireballTrapSeqCallback(3, &bloodActors[nSprite]); + FireballTrapSeqCallback(3, actor); break; case 1: seqSpawn(35, actor, nFireballTrapClient); @@ -2234,7 +2228,7 @@ void ActivateGenerator(int nSprite) case kGenBubble: case kGenBubbleMulti: { int top, bottom; - GetSpriteExtents(pSprite, &top, &bottom); + GetActorExtents(actor, &top, &bottom); gFX.fxSpawnActor((pSprite->type == kGenBubble) ? FX_23 : FX_26, pSprite->sectnum, pSprite->x, pSprite->y, top, 0); break; } diff --git a/source/games/blood/src/triggers.h b/source/games/blood/src/triggers.h index d82efccc9..aec13b0af 100644 --- a/source/games/blood/src/triggers.h +++ b/source/games/blood/src/triggers.h @@ -58,7 +58,7 @@ void trMessageSector(unsigned int nSector, EVENT event); void trTriggerWall(unsigned int nWall, XWALL *pXWall, int command); void trMessageWall(unsigned int nWall, EVENT event); void trTriggerSprite(DBloodActor* actor, int command); -void trMessageSprite(unsigned int nSprite, EVENT event); +void trMessageSprite(DBloodActor* actor, EVENT event); void trProcessBusy(void); void trInit(void); void trTextOver(int nId);