diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 192406c05..1033d3fa6 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -174,7 +174,7 @@ void DoClockBeep() ExhumedStatIterator it(407); while (auto i = it.Next()) { - PlayFX2(StaticSound[kSound74], i->GetSpriteIndex()); + PlayFX2(StaticSound[kSound74], i); } } @@ -641,7 +641,7 @@ void SerializeState(FSerializer& arc) ("bsnakecam", bSnakeCam) ("slipmode", bSlipMode) ("PlayClock", PlayClock) - ("spiritsprite", nSpiritSprite) + ("spiritsprite", pSpiritSprite) .EndObject(); } } diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 054e3d779..63d4b60ac 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -114,7 +114,7 @@ extern short nEnergyTowers; extern short nEnergyChan; -extern short nSpiritSprite; +extern DExhumedActor* pSpiritSprite; extern short bInDemo; diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 67402e6af..bd7420cdb 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -252,7 +252,7 @@ void ResetSwordSeqs() WeaponInfo[kWeaponSword].b[3] = 7; } -int CheckCloseRange(short nPlayer, int *x, int *y, int *z, short *nSector) +Collision CheckCloseRange(short nPlayer, int *x, int *y, int *z, short *nSector) { short hitSect, hitWall, hitSprite; int hitX, hitY, hitZ; @@ -285,9 +285,10 @@ int CheckCloseRange(short nPlayer, int *x, int *y, int *z, short *nSector) DPrintf(DMSG_WARNING, "%s %d: overflow\n", __func__, __LINE__); sqrtNum = INT_MAX; } + Collision c(0); if (ksqrt(sqrtNum) >= ecx) - return 0; + return c; *x = hitX; *y = hitY; @@ -295,13 +296,13 @@ int CheckCloseRange(short nPlayer, int *x, int *y, int *z, short *nSector) *nSector = hitSect; if (hitSprite > -1) { - return hitSprite | 0xC000; + c.setSprite(&exhumedActors[hitSprite]); } if (hitWall > -1) { - return hitWall | 0x8000; + c.setWall(hitWall); } - return 0; + return c; } void CheckClip(short nPlayer) @@ -727,9 +728,9 @@ loc_flag: var_28 = 9; } - int cRange = CheckCloseRange(nPlayer, &theX, &theY, &theZ, &nSectorB); + auto cRange = CheckCloseRange(nPlayer, &theX, &theY, &theZ, &nSectorB); - if (cRange) + if (cRange.type != kHitNone) { short nDamage = BulletInfo[kWeaponSword].nDamage; @@ -737,17 +738,16 @@ loc_flag: nDamage *= 2; } - if ((cRange & 0xC000) >= 0x8000) + //if (cRange.type != kHitNone) { - if ((cRange & 0xC000) == 0x8000) // hit wall + if (cRange.type == kHitWall) { // loc_2730E: var_28 += 2; } - else if ((cRange & 0xC000) == 0xC000) // hit sprite + else if (cRange.type == kHitSprite) { - //short nSprite2 = cRange & 0x3FFF; - auto pActor2 = &exhumedActors[cRange & 0x3FFF]; + auto pActor2 = cRange.actor; auto pSprite2 = &pActor2->s(); if (pSprite2->cstat & 0x50) diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 1f909d3fe..478dd1498 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -88,7 +88,7 @@ uint8_t LoadLevel(MapRecord* map) nCreaturesKilled = 0; nCreaturesTotal = 0; nFreeze = 0; - nSpiritSprite = -1; + pSpiritSprite = nullptr; PlayClock = 0; memset(Counters, 0, sizeof(Counters)); @@ -319,9 +319,8 @@ void InitSectFlag() } } -void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) +void ProcessSpriteTag(DExhumedActor* pActor, short nLotag, short nHitag) { - auto pActor = &exhumedActors[nSprite]; auto pSprite = &pActor->s(); int nChannel = runlist_AllocChannel(nHitag % 1000); @@ -776,7 +775,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case kTagRamses: // Ramses head { - nSpiritSprite = nSprite; + pSpiritSprite = pActor; pSprite->cstat |= 0x8000; return; } @@ -812,7 +811,7 @@ void ExamineSprites() pSprite->lotag = 0; pSprite->hitag = 0; - ProcessSpriteTag(ac->GetSpriteIndex(), lotag, hitag); + ProcessSpriteTag(ac, lotag, hitag); } else { diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index f56e53154..adce741f6 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -630,7 +630,7 @@ int CheckSectorSprites(short nSector, int nVal) b = 1; - runlist_DamageEnemy(pActor->GetSpriteIndex(), -1, 5); + runlist_DamageEnemy(pActor, nullptr, 5); if (pSprite->statnum == 100 && PlayerList[GetPlayerFromActor(pActor)].nHealth <= 0) { diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index fc99d8ee4..fa02d4c10 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -943,7 +943,7 @@ void AIPlayer::Tick(RunListEvent* ev) { if (nTotalPlayers <= 1) { - auto ang = GetAngleToSprite(pPlayerActor, &exhumedActors[nSpiritSprite]) & kAngleMask; + auto ang = GetAngleToSprite(pPlayerActor, pSpiritSprite) & kAngleMask; PlayerList[nPlayer].angle.settarget(ang, true); pPlayerSprite->ang = ang; @@ -1085,7 +1085,7 @@ void AIPlayer::Tick(RunListEvent* ev) { if (PlayerList[nPlayer].nPlayerPushSect > -1) { - StopSpriteSound(sBlockInfo[sector[PlayerList[nPlayer].nPlayerPushSect].extra].nSprite); + StopActorSound(&exhumedActors[sBlockInfo[sector[PlayerList[nPlayer].nPlayerPushSect].extra].nSprite]); } PlayerList[nPlayer].nPlayerPushSound = -1; diff --git a/source/games/exhumed/src/ramses.cpp b/source/games/exhumed/src/ramses.cpp index 45b30000f..95d9dc79e 100644 --- a/source/games/exhumed/src/ramses.cpp +++ b/source/games/exhumed/src/ramses.cpp @@ -57,7 +57,7 @@ short word_964EC = 10; short nSpiritRepeatX; short nSpiritRepeatY; -short nSpiritSprite; +DExhumedActor* pSpiritSprite; short nPixelsToShow; short nTalkTime = 0; @@ -65,18 +65,19 @@ short nTalkTime = 0; void InitSpiritHead() { nPixels = 0; - auto pSpiritSprite = &sprite[nSpiritSprite]; + auto pSpiritSpr = &pSpiritSprite->s(); - nSpiritRepeatX = pSpiritSprite->xrepeat; - nSpiritRepeatY = pSpiritSprite->yrepeat; + nSpiritRepeatX = pSpiritSpr->xrepeat; + nSpiritRepeatY = pSpiritSpr->yrepeat; tileLoad(kTileRamsesNormal); // Ramses Normal Head - for (int i = 0; i < kMaxSprites; i++) + ExhumedSpriteIterator it; + while (auto act = it.Next()) { - if (sprite[i].statnum) + if (act->s().statnum) { - sprite[i].cstat |= 0x8000; + act->s().cstat |= 0x8000; } } @@ -116,16 +117,16 @@ void InitSpiritHead() } - pSpiritSprite->yrepeat = 140; - pSpiritSprite->xrepeat = 140; - pSpiritSprite->picnum = kTileRamsesWorkTile; + pSpiritSpr->yrepeat = 140; + pSpiritSpr->xrepeat = 140; + pSpiritSpr->picnum = kTileRamsesWorkTile; nHeadStage = 0; // work tile is twice as big as the normal head size Worktile = TileFiles.tileCreate(kTileRamsesWorkTile, kSpiritY * 2, kSpiritX * 2); - pSpiritSprite->cstat &= 0x7FFF; + pSpiritSpr->cstat &= 0x7FFF; nHeadTimeStart = PlayClock; @@ -197,7 +198,7 @@ void CopyHeadToWorkTile(short nTile) void DoSpiritHead() { static short dimSectCount = 0; - auto pSpiritSprite = &sprite[nSpiritSprite]; + auto pSpiritSpr = &pSpiritSprite->s(); sPlayerInput[0].actions |= SB_CENTERVIEW; TileFiles.InvalidateTile(kTileRamsesWorkTile); @@ -297,11 +298,11 @@ void DoSpiritHead() case 1: case 2: UpdateSwirlies(); - if (pSpiritSprite->shade > -127) - pSpiritSprite->shade--; + if (pSpiritSpr->shade > -127) + pSpiritSpr->shade--; if (--dimSectCount < 0) { - DimSector(pSpiritSprite->sectnum); + DimSector(pSpiritSpr->sectnum); dimSectCount = 5; } @@ -381,17 +382,17 @@ void DoSpiritHead() if (nHeadStage == 1) { - if (pSpiritSprite->xrepeat > nSpiritRepeatX) + if (pSpiritSpr->xrepeat > nSpiritRepeatX) { - pSpiritSprite->xrepeat -= 2; - if (pSpiritSprite->xrepeat < nSpiritRepeatX) - pSpiritSprite->xrepeat = (uint8_t)nSpiritRepeatX; + pSpiritSpr->xrepeat -= 2; + if (pSpiritSpr->xrepeat < nSpiritRepeatX) + pSpiritSpr->xrepeat = (uint8_t)nSpiritRepeatX; } - if (pSpiritSprite->yrepeat > nSpiritRepeatY) + if (pSpiritSpr->yrepeat > nSpiritRepeatY) { - pSpiritSprite->yrepeat -= 2; - if (pSpiritSprite->yrepeat < nSpiritRepeatY) - pSpiritSprite->yrepeat = (uint8_t)nSpiritRepeatY; + pSpiritSpr->yrepeat -= 2; + if (pSpiritSpr->yrepeat < nSpiritRepeatY) + pSpiritSpr->yrepeat = (uint8_t)nSpiritRepeatY; } int nCount = 0; @@ -427,9 +428,9 @@ void DoSpiritHead() if (nCount < (15 * nPixels) / 16) { SoundBigEntrance(); - AddGlow(pSpiritSprite->sectnum, 20); - AddFlash(pSpiritSprite->sectnum, pSpiritSprite->x, pSpiritSprite->y, - pSpiritSprite->z, 128); + AddGlow(pSpiritSpr->sectnum, 20); + AddFlash(pSpiritSpr->sectnum, pSpiritSpr->x, pSpiritSpr->y, + pSpiritSpr->z, 128); nHeadStage = 3; TintPalette(255, 255, 255); CopyHeadToWorkTile(kTileRamsesNormal); diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index 60482f8f2..613705c01 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -771,10 +771,10 @@ void UpdateCreepySounds() // //========================================================================== -void StopSpriteSound(short nSprite) +void StopActorSound(DExhumedActor *pActor) { - if (nSprite >= 0 && nSprite < MAXSPRITES) - soundEngine->StopSound(SOURCE_Actor, &sprite[nSprite], -1); + if (pActor) + soundEngine->StopSound(SOURCE_Actor, &pActor->s(), -1); } void StopAllSounds(void) diff --git a/source/games/exhumed/src/sound.h b/source/games/exhumed/src/sound.h index e1121019d..2ebc02302 100644 --- a/source/games/exhumed/src/sound.h +++ b/source/games/exhumed/src/sound.h @@ -147,11 +147,7 @@ inline void D3PlayFX(unsigned short nSound, DExhumedActor* actor, short flags = PlayFX2(nSound, actor->GetSpriteIndex(), 0, CHANF_NONE, flags); } -void StopSpriteSound(short nSprite); -inline void StopActorSound(DExhumedActor* actor) -{ - if (actor) StopSpriteSound(actor->GetSpriteIndex()); -} +void StopActorSound(DExhumedActor* actor); void StartSwirlies(); void UpdateSwirlies();