diff --git a/source/games/exhumed/src/anims.cpp b/source/games/exhumed/src/anims.cpp index 83542258f..887052aa3 100644 --- a/source/games/exhumed/src/anims.cpp +++ b/source/games/exhumed/src/anims.cpp @@ -72,10 +72,11 @@ void DestroyAnim(int nAnim) if (nSprite >= 0) { + auto pSprite = &sprite[nSprite]; StopSpriteSound(nSprite); runlist_SubRunRec(AnimList[nAnim].AnimRunRec); - runlist_DoSubRunRec(sprite[nSprite].extra); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->extra); + runlist_FreeRun(pSprite->lotag - 1); } AnimList.Release(nAnim); @@ -91,43 +92,44 @@ int BuildAnim(int nSprite, int val, int val2, int x, int y, int z, int nSector, if (nSprite == -1) { nSprite = insertsprite(nSector, 500); } + auto pSprite = &sprite[nSprite]; - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0; if (nFlag & 4) { - sprite[nSprite].pal = 4; - sprite[nSprite].shade = -64; + pSprite->pal = 4; + pSprite->shade = -64; } else { - sprite[nSprite].pal = 0; - sprite[nSprite].shade = -12; + pSprite->pal = 0; + pSprite->shade = -12; } - sprite[nSprite].clipdist = 10; - sprite[nSprite].xrepeat = nRepeat; - sprite[nSprite].yrepeat = nRepeat; - sprite[nSprite].picnum = 1; - sprite[nSprite].ang = 0; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].backuppos(); + pSprite->clipdist = 10; + pSprite->xrepeat = nRepeat; + pSprite->yrepeat = nRepeat; + pSprite->picnum = 1; + pSprite->ang = 0; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->backuppos(); // CHECKME - where is hitag set otherwise? - if (sprite[nSprite].statnum < 900) { - sprite[nSprite].hitag = -1; + if (pSprite->statnum < 900) { + pSprite->hitag = -1; } - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].owner = -1; - sprite[nSprite].extra = runlist_AddRunRec(sprite[nSprite].lotag - 1, nAnim | 0x100000); + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->owner = -1; + pSprite->extra = runlist_AddRunRec(pSprite->lotag - 1, nAnim | 0x100000); AnimList[nAnim].AnimRunRec = runlist_AddRunRec(NewRun, nAnim | 0x100000); AnimList[nAnim].nSprite = nSprite; @@ -137,7 +139,7 @@ int BuildAnim(int nSprite, int val, int val2, int x, int y, int z, int nSector, AnimList[nAnim].field_4 = 256; if (nFlag & 0x80) { - sprite[nSprite].cstat |= 0x2; // set transluscence + pSprite->cstat |= 0x2; // set transluscence } return nAnim; @@ -155,6 +157,7 @@ void FuncAnim(int a, int, int nRun) short nSprite = AnimList[nAnim].nSprite; short nSeq = AnimList[nAnim].nSeq; + auto pSprite = &sprite[nSprite]; assert(nSprite != -1); @@ -166,23 +169,24 @@ void FuncAnim(int a, int, int nRun) { short var_1C = AnimList[nAnim].field_2; - if (!(sprite[nSprite].cstat & 0x8000)) + if (!(pSprite->cstat & 0x8000)) { seq_MoveSequence(nSprite, nSeq, var_1C); } - if (sprite[nSprite].statnum == kStatIgnited) + if (pSprite->statnum == kStatIgnited) { - short nSpriteB = sprite[nSprite].hitag; + short nSpriteB = pSprite->hitag; if (nSpriteB > -1) { - sprite[nSprite].x = sprite[nSpriteB].x; - sprite[nSprite].y = sprite[nSpriteB].y; - sprite[nSprite].z = sprite[nSpriteB].z; + auto pSpriteB = &sprite[nSpriteB]; + pSprite->x = pSpriteB->x; + pSprite->y = pSpriteB->y; + pSprite->z = pSpriteB->z; - if (sprite[nSpriteB].sectnum != sprite[nSprite].sectnum) + if (pSpriteB->sectnum != pSprite->sectnum) { - if (sprite[nSpriteB].sectnum < 0 || sprite[nSpriteB].sectnum >= kMaxSectors) + if (pSpriteB->sectnum < 0 || pSpriteB->sectnum >= kMaxSectors) { DestroyAnim(nAnim); mydeletesprite(nSprite); @@ -190,28 +194,28 @@ void FuncAnim(int a, int, int nRun) } else { - mychangespritesect(nSprite, sprite[nSpriteB].sectnum); + mychangespritesect(nSprite, pSpriteB->sectnum); } } if (!var_1C) { - if (sprite[nSpriteB].cstat != 0x8000) + if (pSpriteB->cstat != 0x8000) { - short hitag2 = sprite[nSpriteB].hitag; - sprite[nSpriteB].hitag--; + short hitag2 = pSpriteB->hitag; + pSpriteB->hitag--; if (hitag2 >= 15) { - runlist_DamageEnemy(nSpriteB, -1, (sprite[nSpriteB].hitag - 14) * 2); + runlist_DamageEnemy(nSpriteB, -1, (pSpriteB->hitag - 14) * 2); - if (sprite[nSpriteB].shade < 100) + if (pSpriteB->shade < 100) { - sprite[nSpriteB].pal = 0; - sprite[nSpriteB].shade++; + pSpriteB->pal = 0; + pSpriteB->shade++; } - if (!(sprite[nSpriteB].cstat & 101)) + if (!(pSpriteB->cstat & 101)) { DestroyAnim(nAnim); mydeletesprite(nSprite); @@ -220,14 +224,14 @@ void FuncAnim(int a, int, int nRun) } else { - sprite[nSpriteB].hitag = 1; + pSpriteB->hitag = 1; DestroyAnim(nAnim); mydeletesprite(nSprite); } } else { - sprite[nSpriteB].hitag = 1; + pSpriteB->hitag = 1; DestroyAnim(nAnim); mydeletesprite(nSprite); } @@ -289,7 +293,9 @@ void FuncAnim(int a, int, int nRun) void BuildExplosion(short nSprite) { - short nSector = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + + short nSector = pSprite->sectnum; int edx = 36; @@ -297,21 +303,22 @@ void BuildExplosion(short nSprite) { edx = 75; } - else if (sprite[nSprite].z == sector[nSector].floorz) + else if (pSprite->z == sector[nSector].floorz) { edx = 34; } - BuildAnim(-1, edx, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].xrepeat, 4); + BuildAnim(-1, edx, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->xrepeat, 4); } int BuildSplash(int nSprite, int nSector) { + auto pSprite = &sprite[nSprite]; int nRepeat, nSound; - if (sprite[nSprite].statnum != 200) + if (pSprite->statnum != 200) { - nRepeat = sprite[nSprite].xrepeat + (RandomWord() % sprite[nSprite].xrepeat); + nRepeat = pSprite->xrepeat + (RandomWord() % pSprite->xrepeat); nSound = kSound0; } else @@ -335,7 +342,7 @@ int BuildSplash(int nSprite, int nSector) nFlag = 0; } - int nAnim = BuildAnim(-1, edx, 0, sprite[nSprite].x, sprite[nSprite].y, sector[nSector].floorz, nSector, nRepeat, nFlag); + int nAnim = BuildAnim(-1, edx, 0, pSprite->x, pSprite->y, sector[nSector].floorz, nSector, nRepeat, nFlag); if (!bIsLava) { diff --git a/source/games/exhumed/src/anubis.cpp b/source/games/exhumed/src/anubis.cpp index 0949dbb8e..e8e287b85 100644 --- a/source/games/exhumed/src/anubis.cpp +++ b/source/games/exhumed/src/anubis.cpp @@ -199,6 +199,7 @@ void FuncAnubis(int a, int nDamage, int nRun) } short nTarget = ap->nTarget; + auto pTarget = nTarget < 0? nullptr : &sprite[nTarget]; short nFrame = SeqBase[nSeq] + ap->nFrame; short nFlag = FrameFlag[nFrame]; @@ -249,7 +250,7 @@ void FuncAnubis(int a, int nDamage, int nRun) { if ((nMov & 0x3FFF) == nTarget) { - int nAng = getangle(sprite[nTarget].x - sp->x, sprite[nTarget].y - sp->y); + int nAng = getangle(pTarget->x - sp->x, pTarget->y - sp->y); int nAngDiff = AngleDiff(sp->ang, nAng); if (nAngDiff < 64) @@ -283,11 +284,11 @@ void FuncAnubis(int a, int nDamage, int nRun) if (nTarget > -1) // NOTE: nTarget can be -1. this check wasn't in original code. TODO: demo compatiblity? { if (cansee(sp->x, sp->y, sp->z - GetSpriteHeight(nSprite), sp->sectnum, - sprite[nTarget].x, sprite[nTarget].y, sprite[nTarget].z - GetSpriteHeight(nTarget), sprite[nTarget].sectnum)) + pTarget->x, pTarget->y, pTarget->z - GetSpriteHeight(nTarget), pTarget->sectnum)) { sp->xvel = 0; sp->yvel = 0; - sp->ang = GetMyAngle(sprite[nTarget].x - sp->x, sprite[nTarget].y - sp->y); + sp->ang = GetMyAngle(pTarget->x - sp->x, pTarget->y - sp->y); ap->nAction = 3; ap->nFrame = 0; @@ -397,7 +398,7 @@ void FuncAnubis(int a, int nDamage, int nRun) // loc_2564C: if (nAction && nTarget != -1) { - if (!(sprite[nTarget].cstat & 0x101)) + if (!(pTarget->cstat & 0x101)) { ap->nAction = 0; ap->nFrame = 0; @@ -444,8 +445,9 @@ void FuncAnubis(int a, int nDamage, int nRun) if (nTarget < 0) { return; } + auto pTarget = &sprite[nTarget]; - if (sprite[nTarget].statnum == 100 || sprite[nTarget].statnum < 199) + if (pTarget->statnum == 100 || pTarget->statnum < 199) { if (!RandomSize(5)) { ap->nTarget = nTarget; @@ -457,13 +459,14 @@ void FuncAnubis(int a, int nDamage, int nRun) if (nAction >= 6 && nAction <= 10) { int nDrumSprite = insertsprite(sp->sectnum, kStatAnubisDrum); + auto pDrumSprite = &sprite[nDrumSprite]; - sprite[nDrumSprite].x = sp->x; - sprite[nDrumSprite].y = sp->y; - sprite[nDrumSprite].z = sector[sprite[nDrumSprite].sectnum].floorz; - sprite[nDrumSprite].xrepeat = 40; - sprite[nDrumSprite].yrepeat = 40; - sprite[nDrumSprite].shade = -64; + pDrumSprite->x = sp->x; + pDrumSprite->y = sp->y; + pDrumSprite->z = sector[pDrumSprite->sectnum].floorz; + pDrumSprite->xrepeat = 40; + pDrumSprite->yrepeat = 40; + pDrumSprite->shade = -64; BuildObject(nDrumSprite, 2, 0); } diff --git a/source/games/exhumed/src/bubbles.cpp b/source/games/exhumed/src/bubbles.cpp index 64b6a9046..c2231ad46 100644 --- a/source/games/exhumed/src/bubbles.cpp +++ b/source/games/exhumed/src/bubbles.cpp @@ -97,9 +97,10 @@ void InitBubbles() void DestroyBubble(short nBubble) { short nSprite = BubbleList[nBubble].nSprite; + auto pSprite = &sprite[nSprite]; - runlist_DoSubRunRec(sprite[nSprite].lotag - 1); - runlist_DoSubRunRec(sprite[nSprite].owner); + runlist_DoSubRunRec(pSprite->lotag - 1); + runlist_DoSubRunRec(pSprite->owner); runlist_SubRunRec(BubbleList[nBubble].nRun); mydeletesprite(nSprite); @@ -126,27 +127,28 @@ int BuildBubble(int x, int y, int z, short nSector) int nSprite = insertsprite(nSector, 402); assert(nSprite >= 0 && nSprite < kMaxSprites); + auto pSprite = &sprite[nSprite]; - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0; - sprite[nSprite].shade = -32; - sprite[nSprite].pal = 0; - sprite[nSprite].clipdist = 5; - sprite[nSprite].xrepeat = 40; - sprite[nSprite].yrepeat = 40; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = 1; - sprite[nSprite].ang = inita; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = -1200; - sprite[nSprite].hitag = -1; - sprite[nSprite].extra = -1; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].backuppos(); + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0; + pSprite->shade = -32; + pSprite->pal = 0; + pSprite->clipdist = 5; + pSprite->xrepeat = 40; + pSprite->yrepeat = 40; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = 1; + pSprite->ang = inita; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = -1200; + pSprite->hitag = -1; + pSprite->extra = -1; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->backuppos(); // GrabTimeSlot(3); @@ -154,7 +156,7 @@ int BuildBubble(int x, int y, int z, short nSector) BubbleList[nBubble].nFrame = 0; BubbleList[nBubble].nSeq = SeqOffsets[kSeqBubble] + nSize; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nBubble | 0x140000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nBubble | 0x140000); BubbleList[nBubble].nRun = runlist_AddRunRec(NewRun, nBubble | 0x140000); return nBubble | 0x140000; @@ -167,6 +169,7 @@ void FuncBubble(int a, int, int nRun) short nSprite = BubbleList[nBubble].nSprite; short nSeq = BubbleList[nBubble].nSeq; + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -182,16 +185,16 @@ void FuncBubble(int a, int, int nRun) BubbleList[nBubble].nFrame = 0; } - sprite[nSprite].z += sprite[nSprite].zvel; + pSprite->z += pSprite->zvel; - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; - if (sprite[nSprite].z <= sector[nSector].ceilingz) + if (pSprite->z <= sector[nSector].ceilingz) { short nSectAbove = SectAbove[nSector]; - if (sprite[nSprite].hitag > -1 && nSectAbove != -1) { - BuildAnim(-1, 70, 0, sprite[nSprite].x, sprite[nSprite].y, sector[nSectAbove].floorz, nSectAbove, 64, 0); + if (pSprite->hitag > -1 && nSectAbove != -1) { + BuildAnim(-1, 70, 0, pSprite->x, pSprite->y, sector[nSectAbove].floorz, nSectAbove, 64, 0); } DestroyBubble(nBubble); @@ -228,7 +231,8 @@ void DoBubbleMachines() Machine[i]._0 = (RandomWord() % Machine[i]._4) + 30; int nSprite = Machine[i].nSprite; - BuildBubble(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum); + auto pSprite = &sprite[nSprite]; + BuildBubble(pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum); } } } @@ -245,7 +249,8 @@ void BuildBubbleMachine(int nSprite) Machine[nMachineCount]._0 = Machine[nMachineCount]._4; nMachineCount++; - sprite[nSprite].cstat = 0x8000; + auto pSprite = &sprite[nSprite]; + pSprite->cstat = 0x8000; } void DoBubbles(int nPlayer) @@ -257,7 +262,8 @@ void DoBubbles(int nPlayer) int nBubble = BuildBubble(x, y, z, nSector); int nSprite = GetBubbleSprite(nBubble); + auto pSprite = &sprite[nSprite]; - sprite[nSprite].hitag = nPlayer; + pSprite->hitag = nPlayer; } END_PS_NS diff --git a/source/games/exhumed/src/bullet.cpp b/source/games/exhumed/src/bullet.cpp index a54d37fb1..8b273ec43 100644 --- a/source/games/exhumed/src/bullet.cpp +++ b/source/games/exhumed/src/bullet.cpp @@ -146,9 +146,10 @@ int GrabBullet() void DestroyBullet(short nBullet) { short nSprite = BulletList[nBullet].nSprite; + auto pSprite = &sprite[nSprite]; runlist_DoSubRunRec(BulletList[nBullet].field_6); - runlist_DoSubRunRec(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->lotag - 1); runlist_SubRunRec(BulletList[nBullet].field_8); StopSpriteSound(nSprite); @@ -159,9 +160,11 @@ void DestroyBullet(short nBullet) void IgniteSprite(int nSprite) { - sprite[nSprite].hitag += 2; + auto pSprite = &sprite[nSprite]; - int nAnim = BuildAnim(-1, 38, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, 40, 20); + pSprite->hitag += 2; + + int nAnim = BuildAnim(-1, 38, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, 40, 20); short nAnimSprite = GetAnimSprite(nAnim); sprite[nAnimSprite].hitag = nSprite; @@ -393,7 +396,7 @@ MOVEEND: } } - // sprite[nSprite].sectnum may have changed since we set nSectFlag ? + // pSprite->sectnum may have changed since we set nSectFlag ? short nFlagVal = nSectFlag ^ SectFlag[pSprite->sectnum]; if (nFlagVal & kSectUnderwater) { @@ -403,10 +406,10 @@ MOVEEND: if (nVal == 0 && nType != 15 && nType != 3) { - AddFlash(sprite[nSprite].sectnum, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, 0); + AddFlash(pSprite->sectnum, pSprite->x, pSprite->y, pSprite->z, 0); - if (sprite[nSprite].pal != 5) { - sprite[nSprite].pal = 1; + if (pSprite->pal != 5) { + pSprite->pal = 1; } } } @@ -555,6 +558,7 @@ void SetBulletEnemy(short nBullet, short nEnemy) int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int val2, int val3) { + auto pSprite = &sprite[nSprite]; Bullet sBullet; bulletInfo *pBulletInfo = &BulletInfo[nType]; @@ -567,19 +571,19 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va short nTargetSprite = val2; spritetype *pTargetSprite = &sprite[nTargetSprite]; -// assert(sprite[nTargetSprite].sectnum <= kMaxSectors); +// assert(pTargetSprite->sectnum <= kMaxSectors); if (pTargetSprite->cstat & 0x101) { sBullet.nType = nType; sBullet.field_13 = val3; - sBullet.nSprite = insertsprite(sprite[nSprite].sectnum, 200); + sBullet.nSprite = insertsprite(pSprite->sectnum, 200); sprite[sBullet.nSprite].ang = nAngle; int nHeight = GetSpriteHeight(nTargetSprite); - assert(sprite[nTargetSprite].sectnum >= 0 && sprite[nTargetSprite].sectnum < kMaxSectors); + assert(pTargetSprite->sectnum >= 0 && pTargetSprite->sectnum < kMaxSectors); BulletHitsSprite(&sBullet, nSprite, nTargetSprite, pTargetSprite->x, pTargetSprite->y, pTargetSprite->z - (nHeight >> 1), pTargetSprite->sectnum); mydeletesprite(sBullet.nSprite); @@ -599,16 +603,17 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va short nSector; - if (sprite[nSprite].statnum == 100) + if (pSprite->statnum == 100) { nSector = nPlayerViewSect[GetPlayerFromSprite(nSprite)]; } else { - nSector = sprite[nSprite].sectnum; + nSector = pSprite->sectnum; } short nBulletSprite = insertsprite(nSector, 200); + auto pBulletSprite = &sprite[nBulletSprite]; int nHeight = GetSpriteHeight(nSprite); nHeight = nHeight - (nHeight >> 2); @@ -616,9 +621,9 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va val1 = -nHeight; } - sprite[nBulletSprite].x = sprite[nSprite].x; - sprite[nBulletSprite].y = sprite[nSprite].y; - sprite[nBulletSprite].z = sprite[nSprite].z; + pBulletSprite->x = pSprite->x; + pBulletSprite->y = pSprite->y; + pBulletSprite->z = pSprite->z; // why is this done here??? assert(nBulletSprite >= 0 && nBulletSprite < kMaxSprites); @@ -627,35 +632,35 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va pBullet->enemy = -1; - sprite[nBulletSprite].cstat = 0; - sprite[nBulletSprite].shade = -64; + pBulletSprite->cstat = 0; + pBulletSprite->shade = -64; if (pBulletInfo->nFlags & 4) { - sprite[nBulletSprite].pal = 4; + pBulletSprite->pal = 4; } else { - sprite[nBulletSprite].pal = 0; + pBulletSprite->pal = 0; } - sprite[nBulletSprite].clipdist = 25; + pBulletSprite->clipdist = 25; short nRepeat = pBulletInfo->xyRepeat; if (nRepeat < 0) { nRepeat = 30; } - sprite[nBulletSprite].xrepeat = (uint8_t)nRepeat; - sprite[nBulletSprite].yrepeat = (uint8_t)nRepeat; - sprite[nBulletSprite].xoffset = 0; - sprite[nBulletSprite].yoffset = 0; - sprite[nBulletSprite].ang = nAngle; - sprite[nBulletSprite].xvel = 0; - sprite[nBulletSprite].yvel = 0; - sprite[nBulletSprite].zvel = 0; - sprite[nBulletSprite].owner = nSprite; - sprite[nBulletSprite].lotag = runlist_HeadRun() + 1; - sprite[nBulletSprite].extra = -1; - sprite[nBulletSprite].hitag = 0; + pBulletSprite->xrepeat = (uint8_t)nRepeat; + pBulletSprite->yrepeat = (uint8_t)nRepeat; + pBulletSprite->xoffset = 0; + pBulletSprite->yoffset = 0; + pBulletSprite->ang = nAngle; + pBulletSprite->xvel = 0; + pBulletSprite->yvel = 0; + pBulletSprite->zvel = 0; + pBulletSprite->owner = nSprite; + pBulletSprite->lotag = runlist_HeadRun() + 1; + pBulletSprite->extra = -1; + pBulletSprite->hitag = 0; // GrabTimeSlot(3); @@ -678,30 +683,30 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va pBullet->nSeq = nSeq; - sprite[nBulletSprite].picnum = seq_GetSeqPicnum(nSeq, 0, 0); + pBulletSprite->picnum = seq_GetSeqPicnum(nSeq, 0, 0); if (nSeq == kSeqBullet) { - sprite[nBulletSprite].cstat |= 0x8000; + pBulletSprite->cstat |= 0x8000; } pBullet->field_C = val2; pBullet->nType = nType; pBullet->nSprite = nBulletSprite; - pBullet->field_6 = runlist_AddRunRec(sprite[nBulletSprite].lotag - 1, nBullet | 0xB0000); + pBullet->field_6 = runlist_AddRunRec(pBulletSprite->lotag - 1, nBullet | 0xB0000); pBullet->field_8 = runlist_AddRunRec(NewRun, nBullet | 0xB0000); pBullet->field_13 = val3; - sprite[nBulletSprite].z += val1; - sprite[nBulletSprite].backuppos(); + pBulletSprite->z += val1; + pBulletSprite->backuppos(); int var_18; - nSector = sprite[nBulletSprite].sectnum; + nSector = pBulletSprite->sectnum; - while (sprite[nBulletSprite].z < sector[nSector].ceilingz) + while (pBulletSprite->z < sector[nSector].ceilingz) { if (SectAbove[nSector] == -1) { - sprite[nBulletSprite].z = sector[nSector].ceilingz; + pBulletSprite->z = sector[nSector].ceilingz; break; } @@ -718,6 +723,7 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va val2 -= 10000; short nTargetSprite = val2; + auto pTargetSprite = &sprite[nTargetSprite]; if ((unsigned int)pBulletInfo->field_4 > 30000) { @@ -727,7 +733,7 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va { nHeight = GetSpriteHeight(nTargetSprite); - if (sprite[nTargetSprite].statnum == 100) + if (pTargetSprite->statnum == 100) { nHeight -= nHeight >> 2; } @@ -736,19 +742,19 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va nHeight -= nHeight >> 1; } - int var_20 = sprite[nTargetSprite].z - nHeight; + int var_20 = pTargetSprite->z - nHeight; int x, y; - if (nSprite != -1 && sprite[nSprite].statnum != 100) + if (nSprite != -1 && pSprite->statnum != 100) { - x = sprite[nTargetSprite].x; - y = sprite[nTargetSprite].y; + x = pTargetSprite->x; + y = pTargetSprite->y; - if (sprite[nTargetSprite].statnum != 100) + if (pTargetSprite->statnum != 100) { - x += (sprite[nTargetSprite].xvel * 20) >> 6; - y += (sprite[nTargetSprite].yvel * 20) >> 6; + x += (pTargetSprite->xvel * 20) >> 6; + y += (pTargetSprite->yvel * 20) >> 6; } else { @@ -760,23 +766,23 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va } } - x -= sprite[nBulletSprite].x; - y -= sprite[nBulletSprite].y; + x -= pBulletSprite->x; + y -= pBulletSprite->y; nAngle = GetMyAngle(x, y); - sprite[nSprite].ang = nAngle; + pSprite->ang = nAngle; } else { // loc_2ABA3: - x = sprite[nTargetSprite].x - sprite[nBulletSprite].x; - y = sprite[nTargetSprite].y - sprite[nBulletSprite].y; + x = pTargetSprite->x - pBulletSprite->x; + y = pTargetSprite->y - pBulletSprite->y; } int nSqrt = lsqrt(y*y + x*x); if ((unsigned int)nSqrt > 0) { - var_18 = ((var_20 - sprite[nBulletSprite].z) * pBulletInfo->field_4) / nSqrt; + var_18 = ((var_20 - pBulletSprite->z) * pBulletInfo->field_4) / nSqrt; } else { @@ -786,8 +792,8 @@ int BuildBullet(short nSprite, int nType, int, int, int val1, int nAngle, int va } pBullet->z = 0; - pBullet->x = (sprite[nSprite].clipdist << 2) * bcos(nAngle); - pBullet->y = (sprite[nSprite].clipdist << 2) * bsin(nAngle); + pBullet->x = (pSprite->clipdist << 2) * bcos(nAngle); + pBullet->y = (pSprite->clipdist << 2) * bsin(nAngle); BulletList[nBullet].enemy = -1; if (MoveBullet(nBullet)) @@ -812,6 +818,7 @@ void FuncBullet(int a, int, int nRun) short nSeq = SeqOffsets[BulletList[nBullet].nSeq]; short nSprite = BulletList[nBullet].nSprite; + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -825,7 +832,7 @@ void FuncBullet(int a, int, int nRun) if (nFlag & 0x80) { - BuildAnim(-1, 45, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].xrepeat, 0); + BuildAnim(-1, 45, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->xrepeat, 0); } BulletList[nBullet].nFrame++; diff --git a/source/games/exhumed/src/exhumed.cpp b/source/games/exhumed/src/exhumed.cpp index 47a43aead..de404f3dd 100644 --- a/source/games/exhumed/src/exhumed.cpp +++ b/source/games/exhumed/src/exhumed.cpp @@ -193,8 +193,9 @@ void DoRedAlert(int nVal) { if (nVal) { - PlayFXAtXYZ(StaticSound[kSoundAlarm], sprite[i].x, sprite[i].y, sprite[i].z, sprite[i].sectnum); - AddFlash(sprite[i].sectnum, sprite[i].x, sprite[i].y, sprite[i].z, 192); + auto spri = &sprite[i]; + PlayFXAtXYZ(StaticSound[kSoundAlarm], spri->x, spri->y, spri->z, spri->sectnum); + AddFlash(spri->sectnum, spri->x, spri->y, spri->z, 192); } } } @@ -253,7 +254,7 @@ void GameMove(void) for (int i = 0; i < MAXSPRITES; i++) { - sprite[i].backuploc(); + sprite[i].backuploc(); } if (currentLevel->gameflags & LEVEL_EX_COUNTDOWN) diff --git a/source/games/exhumed/src/fish.cpp b/source/games/exhumed/src/fish.cpp index 0948c8615..71ac7a72a 100644 --- a/source/games/exhumed/src/fish.cpp +++ b/source/games/exhumed/src/fish.cpp @@ -103,41 +103,43 @@ void InitFishes() int BuildFishLimb(short nFish, short edx) { short nSprite = FishList[nFish].nSprite; + auto pSprite = &sprite[nSprite]; int nFree = FishChunk.Reserve(1); - int nSprite2 = insertsprite(sprite[nSprite].sectnum, 99); + int nSprite2 = insertsprite(pSprite->sectnum, 99); assert(nSprite2 >= 0 && nSprite2 < kMaxSprites); + auto pSprite2 = &sprite[nSprite2]; FishChunk[nFree].nSprite = nSprite2; FishChunk[nFree].nSeqIndex = edx + 40; FishChunk[nFree].nIndex = RandomSize(3) % SeqSize[SeqOffsets[kSeqFish] + edx + 40]; - sprite[nSprite2].x = sprite[nSprite].x; - sprite[nSprite2].y = sprite[nSprite].y; - sprite[nSprite2].z = sprite[nSprite].z; - sprite[nSprite2].cstat = 0; - sprite[nSprite2].shade = -12; - sprite[nSprite2].pal = 0; - sprite[nSprite2].xvel = (RandomSize(5) - 16) << 8; - sprite[nSprite2].yvel = (RandomSize(5) - 16) << 8; - sprite[nSprite2].xrepeat = 64; - sprite[nSprite2].yrepeat = 64; - sprite[nSprite2].xoffset = 0; - sprite[nSprite2].yoffset = 0; - sprite[nSprite2].zvel = (-(RandomByte() + 512)) * 2; + pSprite2->x = pSprite->x; + pSprite2->y = pSprite->y; + pSprite2->z = pSprite->z; + pSprite2->cstat = 0; + pSprite2->shade = -12; + pSprite2->pal = 0; + pSprite2->xvel = (RandomSize(5) - 16) << 8; + pSprite2->yvel = (RandomSize(5) - 16) << 8; + pSprite2->xrepeat = 64; + pSprite2->yrepeat = 64; + pSprite2->xoffset = 0; + pSprite2->yoffset = 0; + pSprite2->zvel = (-(RandomByte() + 512)) * 2; seq_GetSeqPicnum(kSeqFish, FishChunk[nFree].nSeqIndex, 0); - sprite[nSprite2].picnum = edx; - sprite[nSprite2].lotag = runlist_HeadRun() + 1; - sprite[nSprite2].clipdist = 0; + pSprite2->picnum = edx; + pSprite2->lotag = runlist_HeadRun() + 1; + pSprite2->clipdist = 0; // GrabTimeSlot(3); - sprite[nSprite2].extra = -1; - sprite[nSprite2].owner = runlist_AddRunRec(sprite[nSprite2].lotag - 1, nFree | 0x200000); - sprite[nSprite2].hitag = runlist_AddRunRec(NewRun, nFree | 0x200000); + pSprite2->extra = -1; + pSprite2->owner = runlist_AddRunRec(pSprite2->lotag - 1, nFree | 0x200000); + pSprite2->hitag = runlist_AddRunRec(NewRun, nFree | 0x200000); return nFree | 0x200000; } @@ -152,6 +154,7 @@ void FuncFishLimb(int a, int, int nRun) short nFish = RunData[nRun].nVal; short nSprite = FishChunk[nFish].nSprite; assert(nSprite >= 0 && nSprite < kMaxSprites); + auto pSprite = &sprite[nSprite]; int nSeq = SeqOffsets[kSeqFish] + FishChunk[nFish].nSeqIndex; @@ -161,7 +164,7 @@ void FuncFishLimb(int a, int, int nRun) { case 0x20000: { - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, FishChunk[nFish].nIndex); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, FishChunk[nFish].nIndex); Gravity(nSprite); @@ -171,37 +174,37 @@ void FuncFishLimb(int a, int, int nRun) { FishChunk[nFish].nIndex = 0; if (RandomBit()) { - BuildBlood(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum); + BuildBlood(pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum); } } - int FloorZ = sector[sprite[nSprite].sectnum].floorz; + int FloorZ = sector[pSprite->sectnum].floorz; - if (FloorZ <= sprite[nSprite].z) + if (FloorZ <= pSprite->z) { - sprite[nSprite].z += 256; + pSprite->z += 256; - if ((sprite[nSprite].z - FloorZ) > 25600) + if ((pSprite->z - FloorZ) > 25600) { - sprite[nSprite].zvel = 0; - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); - runlist_SubRunRec(sprite[nSprite].hitag); + pSprite->zvel = 0; + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); + runlist_SubRunRec(pSprite->hitag); mydeletesprite(nSprite); } - else if ((sprite[nSprite].z - FloorZ) > 0) + else if ((pSprite->z - FloorZ) > 0) { - sprite[nSprite].zvel = 1024; + pSprite->zvel = 1024; } return; } else { - if (movesprite(nSprite, sprite[nSprite].xvel << 8, sprite[nSprite].yvel << 8, sprite[nSprite].zvel, 2560, -2560, CLIPMASK1)) + if (movesprite(nSprite, pSprite->xvel << 8, pSprite->yvel << 8, pSprite->zvel, 2560, -2560, CLIPMASK1)) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } @@ -219,41 +222,43 @@ void FuncFishLimb(int a, int, int nRun) int BuildFish(int nSprite, int x, int y, int z, int nSector, int nAngle) { int nFish = FishList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 103); + pSprite = &sprite[nSprite]; } else { - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sprite[nSprite].z; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = pSprite->z; + nAngle = pSprite->ang; changespritestat(nSprite, 103); } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].shade = -12; - sprite[nSprite].clipdist = 80; - sprite[nSprite].xrepeat = 40; - sprite[nSprite].yrepeat = 40; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = seq_GetSeqPicnum(kSeqFish, FishSeq[0].a, 0); - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].extra = -1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->shade = -12; + pSprite->clipdist = 80; + pSprite->xrepeat = 40; + pSprite->yrepeat = 40; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = seq_GetSeqPicnum(kSeqFish, FishSeq[0].a, 0); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->ang = nAngle; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->hitag = 0; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -264,7 +269,7 @@ int BuildFish(int nSprite, int x, int y, int z, int nSector, int nAngle) FishList[nFish].nCount = 60; FishList[nFish].nFrame = 0; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nFish | 0x120000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nFish | 0x120000); FishList[nFish].nRun = runlist_AddRunRec(NewRun, nFish | 0x120000); nCreaturesTotal++; @@ -275,36 +280,38 @@ int BuildFish(int nSprite, int x, int y, int z, int nSector, int nAngle) void IdleFish(short nFish, short edx) { short nSprite = FishList[nFish].nSprite; + auto pSprite = &sprite[nSprite]; - sprite[nSprite].ang += (256 - RandomSize(9)) + 1024; - sprite[nSprite].ang &= kAngleMask; + pSprite->ang += (256 - RandomSize(9)) + 1024; + pSprite->ang &= kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -8); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -8); + pSprite->xvel = bcos(pSprite->ang, -8); + pSprite->yvel = bsin(pSprite->ang, -8); FishList[nFish].nAction = 0; FishList[nFish].nFrame = 0; - sprite[nSprite].zvel = RandomSize(9); + pSprite->zvel = RandomSize(9); if (!edx) { if (RandomBit()) { - sprite[nSprite].zvel = -sprite[nSprite].zvel; + pSprite->zvel = -pSprite->zvel; } } else if (edx < 0) { - sprite[nSprite].zvel = -sprite[nSprite].zvel; + pSprite->zvel = -pSprite->zvel; } } void DestroyFish(short nFish) { short nSprite = FishList[nFish].nSprite; + auto pSprite = &sprite[nSprite]; - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); runlist_SubRunRec(FishList[nFish].nRun); mydeletesprite(nSprite); } @@ -316,6 +323,7 @@ void FuncFish(int a, int nDamage, int nRun) short nSprite = FishList[nFish].nSprite; short nAction = FishList[nFish].nAction; + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -363,7 +371,7 @@ void FuncFish(int a, int nDamage, int nRun) FishList[nFish].nHealth = 0; nCreaturesKilled++; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; if (nMessage == 0x80000) { @@ -372,7 +380,7 @@ void FuncFish(int a, int nDamage, int nRun) BuildFishLimb(nFish, i); } - PlayFXAtXYZ(StaticSound[kSound40], sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum); + PlayFXAtXYZ(StaticSound[kSound40], pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum); DestroyFish(nFish); } else @@ -401,14 +409,14 @@ void FuncFish(int a, int nDamage, int nRun) case 0x20000: { - if (!(SectFlag[sprite[nSprite].sectnum] & kSectUnderwater)) + if (!(SectFlag[pSprite->sectnum] & kSectUnderwater)) { Gravity(nSprite); } short nSeq = SeqOffsets[kSeqFish] + FishSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, FishList[nFish].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, FishList[nFish].nFrame); seq_MoveSequence(nSprite, nSeq, FishList[nFish].nFrame); @@ -436,8 +444,8 @@ void FuncFish(int a, int nDamage, int nRun) FishList[nFish].nAction = 2; FishList[nFish].nFrame = 0; - int nAngle = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].z - sprite[nSprite].z); - sprite[nSprite].zvel = bsin(nAngle, -5); + int nAngle = GetMyAngle(sprite[nTarget].x - pSprite->x, sprite[nTarget].z - pSprite->z); + pSprite->zvel = bsin(nAngle, -5); FishList[nFish].nCount = RandomSize(6) + 90; } @@ -467,20 +475,20 @@ void FuncFish(int a, int nDamage, int nRun) PlotCourseToSprite(nSprite, nTarget); int nHeight = GetSpriteHeight(nSprite) >> 1; - int z = abs(sprite[nTarget].z - sprite[nSprite].z); + int z = abs(sprite[nTarget].z - pSprite->z); if (z <= nHeight) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -5) - bcos(sprite[nSprite].ang, -7); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -5) - bsin(sprite[nSprite].ang, -7); + pSprite->xvel = bcos(pSprite->ang, -5) - bcos(pSprite->ang, -7); + pSprite->yvel = bsin(pSprite->ang, -5) - bsin(pSprite->ang, -7); } else { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } - sprite[nSprite].zvel = (sprite[nTarget].z - sprite[nSprite].z) >> 3; + pSprite->zvel = (sprite[nTarget].z - pSprite->z) >> 3; } break; } @@ -509,20 +517,20 @@ void FuncFish(int a, int nDamage, int nRun) } } - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; + short nSector = pSprite->sectnum; // loc_2EF54 - int nMov = movesprite(nSprite, sprite[nSprite].xvel << 13, sprite[nSprite].yvel << 13, sprite[nSprite].zvel << 2, 0, 0, CLIPMASK0); + int nMov = movesprite(nSprite, pSprite->xvel << 13, pSprite->yvel << 13, pSprite->zvel << 2, 0, 0, CLIPMASK0); - if (!(SectFlag[sprite[nSprite].sectnum] & kSectUnderwater)) + if (!(SectFlag[pSprite->sectnum] & kSectUnderwater)) { mychangespritesect(nSprite, nSector); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; IdleFish(nFish, 0); return; @@ -554,7 +562,7 @@ void FuncFish(int a, int nDamage, int nRun) if (sprite[nMov & 0x3FFF].statnum == 100) { FishList[nFish].nTarget = nMov & 0x3FFF; - sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); + pSprite->ang = GetMyAngle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); if (nAction != 3) { diff --git a/source/games/exhumed/src/grenade.cpp b/source/games/exhumed/src/grenade.cpp index c8aaf60d7..d05ef11bb 100644 --- a/source/games/exhumed/src/grenade.cpp +++ b/source/games/exhumed/src/grenade.cpp @@ -114,30 +114,32 @@ int ThrowGrenade(short nPlayer, int, int, int ecx, int push1) short nGrenadeSprite = GrenadeList[nGrenade].nSprite; short nPlayerSprite = PlayerList[nPlayer].nSprite; + auto pGrenadeSprite = &sprite[nGrenadeSprite]; + auto pPlayerSprite = &sprite[nPlayerSprite]; - short nAngle = sprite[nPlayerSprite].ang; + short nAngle = pPlayerSprite->ang; mychangespritesect(nGrenadeSprite, nPlayerViewSect[nPlayer]); - sprite[nGrenadeSprite].x = sprite[nPlayerSprite].x; - sprite[nGrenadeSprite].y = sprite[nPlayerSprite].y; - sprite[nGrenadeSprite].z = sprite[nPlayerSprite].z; + pGrenadeSprite->x = pPlayerSprite->x; + pGrenadeSprite->y = pPlayerSprite->y; + pGrenadeSprite->z = pPlayerSprite->z; if (nAngle < 0) { - nAngle = sprite[nPlayerSprite].ang; + nAngle = pPlayerSprite->ang; } - sprite[nGrenadeSprite].cstat &= 0x7FFF; - sprite[nGrenadeSprite].ang = nAngle; + pGrenadeSprite->cstat &= 0x7FFF; + pGrenadeSprite->ang = nAngle; if (push1 >= -3000) { int nVel = totalvel[nPlayer] << 5; GrenadeList[nGrenade].field_10 = ((90 - GrenadeList[nGrenade].field_E) * (90 - GrenadeList[nGrenade].field_E)) + nVel; - sprite[nGrenadeSprite].zvel = (-64 * push1) - 4352; + pGrenadeSprite->zvel = (-64 * push1) - 4352; - int nMov = movesprite(nGrenadeSprite, bcos(nAngle) * (sprite[nPlayerSprite].clipdist << 3), bsin(nAngle) * (sprite[nPlayerSprite].clipdist << 3), ecx, 0, 0, CLIPMASK1); + int nMov = movesprite(nGrenadeSprite, bcos(nAngle) * (pPlayerSprite->clipdist << 3), bsin(nAngle) * (pPlayerSprite->clipdist << 3), ecx, 0, 0, CLIPMASK1); if (nMov & 0x8000) { nAngle = GetWallNormal(nMov & 0x3FFF); @@ -147,7 +149,7 @@ int ThrowGrenade(short nPlayer, int, int, int ecx, int push1) else { GrenadeList[nGrenade].field_10 = 0; - sprite[nGrenadeSprite].zvel = sprite[nPlayerSprite].zvel; + pGrenadeSprite->zvel = pPlayerSprite->zvel; } GrenadeList[nGrenade].x = bcos(nAngle, -4) * GrenadeList[nGrenade].field_10; @@ -165,30 +167,32 @@ int BuildGrenade(int nPlayer) int nSprite = insertsprite(nPlayerViewSect[nPlayer], 201); assert(nSprite >= 0 && nSprite < kMaxSprites); + auto pSprite = &sprite[nSprite]; int nPlayerSprite = PlayerList[nPlayer].nSprite; + auto pPlayerSprite = &sprite[nPlayerSprite]; - sprite[nSprite].x = sprite[nPlayerSprite].x; - sprite[nSprite].y = sprite[nPlayerSprite].y; - sprite[nSprite].z = sprite[nPlayerSprite].z - 3840; - sprite[nSprite].shade = -64; - sprite[nSprite].xrepeat = 20; - sprite[nSprite].yrepeat = 20; - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = 0; - sprite[nSprite].clipdist = 30; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = sprite[nPlayerSprite].ang; - sprite[nSprite].owner = nPlayerSprite; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; - sprite[nSprite].backuppos(); + pSprite->x = pPlayerSprite->x; + pSprite->y = pPlayerSprite->y; + pSprite->z = pPlayerSprite->z - 3840; + pSprite->shade = -64; + pSprite->xrepeat = 20; + pSprite->yrepeat = 20; + pSprite->cstat = 0x8000; + pSprite->picnum = 1; + pSprite->pal = 0; + pSprite->clipdist = 30; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = pPlayerSprite->ang; + pSprite->owner = nPlayerSprite; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; + pSprite->backuppos(); // GrabTimeSlot(3); @@ -199,7 +203,7 @@ int BuildGrenade(int nPlayer) GrenadeList[nGrenade].nSprite = nSprite; GrenadeList[nGrenade].field_A = 0; GrenadeList[nGrenade].field_C = 0; - GrenadeList[nGrenade].field_6 = runlist_AddRunRec(sprite[nSprite].lotag - 1, nGrenade | 0x0F0000); + GrenadeList[nGrenade].field_6 = runlist_AddRunRec(pSprite->lotag - 1, nGrenade | 0x0F0000); GrenadeList[nGrenade].field_8 = runlist_AddRunRec(NewRun, nGrenade | 0x0F0000); nGrenadePlayer[nGrenade] = nPlayer; @@ -214,7 +218,8 @@ void ExplodeGrenade(short nGrenade) short nPlayer = nGrenadePlayer[nGrenade]; int nGrenadeSprite = GrenadeList[nGrenade].nSprite; - short nGrenadeSect = sprite[nGrenadeSprite].sectnum; + auto pGrenadeSprite = &sprite[nGrenadeSprite]; + short nGrenadeSect = pGrenadeSprite->sectnum; GrenadeList[nGrenade].field_C = 1; @@ -225,7 +230,7 @@ void ExplodeGrenade(short nGrenade) } else { - if (sprite[nGrenadeSprite].z < sector[nGrenadeSect].floorz) + if (pGrenadeSprite->z < sector[nGrenadeSect].floorz) { var_20 = 200; var_28 = 36; @@ -244,13 +249,14 @@ void ExplodeGrenade(short nGrenade) if (GrenadeList[nGrenade].field_10 < 0) { short nPlayerSprite = PlayerList[nPlayer].nSprite; - short nAngle = sprite[nPlayerSprite].ang; + auto pPlayerSprite = &sprite[nPlayerSprite]; + short nAngle = pPlayerSprite->ang; - sprite[nGrenadeSprite].z = sprite[nPlayerSprite].z; - sprite[nGrenadeSprite].x = bcos(nAngle, -5) + sprite[nPlayerSprite].x; - sprite[nGrenadeSprite].y = bsin(nAngle, -5) + sprite[nPlayerSprite].y; + pGrenadeSprite->z = pPlayerSprite->z; + pGrenadeSprite->x = bcos(nAngle, -5) + pPlayerSprite->x; + pGrenadeSprite->y = bsin(nAngle, -5) + pPlayerSprite->y; - changespritesect(nGrenadeSprite, sprite[nPlayerSprite].sectnum); + changespritesect(nGrenadeSprite, pPlayerSprite->sectnum); if (!PlayerList[nPlayer].invincibility) { PlayerList[nPlayer].nHealth = 1; @@ -265,8 +271,8 @@ void ExplodeGrenade(short nGrenade) runlist_RadialDamageEnemy(nGrenadeSprite, nDamage, BulletInfo[kWeaponGrenade].nRadius); - BuildAnim(-1, var_28, 0, sprite[nGrenadeSprite].x, sprite[nGrenadeSprite].y, sprite[nGrenadeSprite].z, sprite[nGrenadeSprite].sectnum, var_20, 4); - AddFlash(sprite[nGrenadeSprite].sectnum, sprite[nGrenadeSprite].x, sprite[nGrenadeSprite].y, sprite[nGrenadeSprite].z, 128); + BuildAnim(-1, var_28, 0, pGrenadeSprite->x, pGrenadeSprite->y, pGrenadeSprite->z, pGrenadeSprite->sectnum, var_20, 4); + AddFlash(pGrenadeSprite->sectnum, pGrenadeSprite->x, pGrenadeSprite->y, pGrenadeSprite->z, 128); nGrenadePlayer[nGrenade] = -1; DestroyGrenade(nGrenade); @@ -278,6 +284,7 @@ void FuncGrenade(int a, int, int nRun) assert(nGrenade >= 0 && nGrenade < kMaxGrenades); short nGrenadeSprite = GrenadeList[nGrenade].nSprite; + auto pGrenadeSprite = &sprite[nGrenadeSprite]; short nSeq; if (GrenadeList[nGrenade].field_C) @@ -308,7 +315,7 @@ void FuncGrenade(int a, int, int nRun) case 0x20000: { seq_MoveSequence(nGrenadeSprite, nSeq, GrenadeList[nGrenade].field_2 >> 8); - sprite[nGrenadeSprite].picnum = seq_GetSeqPicnum2(nSeq, GrenadeList[nGrenade].field_2 >> 8); + pGrenadeSprite->picnum = seq_GetSeqPicnum2(nSeq, GrenadeList[nGrenade].field_2 >> 8); GrenadeList[nGrenade].field_E--; if (!GrenadeList[nGrenade].field_E) @@ -370,10 +377,10 @@ void FuncGrenade(int a, int, int nRun) return; } - int zVel = sprite[nGrenadeSprite].zvel; + int zVel = pGrenadeSprite->zvel; Gravity(nGrenadeSprite); - int nMov = movesprite(nGrenadeSprite, GrenadeList[nGrenade].x, GrenadeList[nGrenade].y, sprite[nGrenadeSprite].zvel, sprite[nGrenadeSprite].clipdist >> 1, sprite[nGrenadeSprite].clipdist >> 1, CLIPMASK1); + int nMov = movesprite(nGrenadeSprite, GrenadeList[nGrenade].x, GrenadeList[nGrenade].y, pGrenadeSprite->zvel, pGrenadeSprite->clipdist >> 1, pGrenadeSprite->clipdist >> 1, CLIPMASK1); if (!nMov) return; @@ -382,7 +389,7 @@ void FuncGrenade(int a, int, int nRun) { if (zVel) { - if (SectDamage[sprite[nGrenadeSprite].sectnum] > 0) + if (SectDamage[pGrenadeSprite->sectnum] > 0) { ExplodeGrenade(nGrenade); return; @@ -392,14 +399,14 @@ void FuncGrenade(int a, int, int nRun) D3PlayFX(StaticSound[kSound3], nGrenadeSprite); - sprite[nGrenadeSprite].zvel = -(zVel >> 1); + pGrenadeSprite->zvel = -(zVel >> 1); - if (sprite[nGrenadeSprite].zvel > -1280) + if (pGrenadeSprite->zvel > -1280) { D3PlayFX(StaticSound[kSound5], nGrenadeSprite); GrenadeList[nGrenade].field_0 = 0; GrenadeList[nGrenade].field_2 = 0; - sprite[nGrenadeSprite].zvel = 0; + pGrenadeSprite->zvel = 0; GrenadeList[nGrenade].field_A = 1; } } diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index f84a3a65a..4a0bf53db 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -338,6 +338,7 @@ void MoveWeapons(short nPlayer) nTemperature[nPlayer] = 0; short nPlayerSprite = PlayerList[nPlayer].nSprite; + auto pPlayerSprite = &sprite[nPlayerSprite]; short nWeapon = PlayerList[nPlayer].nCurrentWeapon; if (nWeapon < -1) @@ -630,12 +631,12 @@ loc_flag: if (((!(nSectFlag & kSectUnderwater)) || nWeapon == kWeaponRing) && (nFrameFlag & 4)) { - BuildFlash(nPlayer, sprite[nPlayerSprite].sectnum, 512); + BuildFlash(nPlayer, pPlayerSprite->sectnum, 512); AddFlash( - sprite[nPlayerSprite].sectnum, - sprite[nPlayerSprite].x, - sprite[nPlayerSprite].y, - sprite[nPlayerSprite].z, + pPlayerSprite->sectnum, + pPlayerSprite->x, + pPlayerSprite->y, + pPlayerSprite->z, 0); } @@ -666,13 +667,13 @@ loc_flag: } short nAmmoType = WeaponInfo[nWeapon].nAmmoType; - short nAngle = sprite[nPlayerSprite].ang; - int theX = sprite[nPlayerSprite].x; - int theY = sprite[nPlayerSprite].y; - int theZ = sprite[nPlayerSprite].z; + short nAngle = pPlayerSprite->ang; + int theX = pPlayerSprite->x; + int theY = pPlayerSprite->y; + int theZ = pPlayerSprite->z; - int ebp = bcos(nAngle) * (sprite[nPlayerSprite].clipdist << 3); - int ebx = bsin(nAngle) * (sprite[nPlayerSprite].clipdist << 3); + int ebp = bcos(nAngle) * (pPlayerSprite->clipdist << 3); + int ebx = bsin(nAngle) * (pPlayerSprite->clipdist << 3); if (WeaponInfo[nWeapon].c) { @@ -706,7 +707,7 @@ loc_flag: } } - short nSectorB = sprite[nPlayerSprite].sectnum; + short nSectorB = pPlayerSprite->sectnum; switch (nWeapon) { @@ -830,8 +831,8 @@ loc_flag: { // only autoaim if target is in front of the player. auto pTargetSprite = &sprite[t]; - int angletotarget = bvectangbam(pTargetSprite->x - sprite[nPlayerSprite].x, pTargetSprite->y - sprite[nPlayerSprite].y).asbuild(); - int anglediff = (sprite[nPlayerSprite].ang - angletotarget) & 2047; + int angletotarget = bvectangbam(pTargetSprite->x - pPlayerSprite->x, pTargetSprite->y - pPlayerSprite->y).asbuild(); + int anglediff = (pPlayerSprite->ang - angletotarget) & 2047; if (anglediff < 512 || anglediff > 1536) target = t + 10000; } } @@ -850,8 +851,8 @@ loc_flag: BuildSnake(nPlayer, nHeight); nQuake[nPlayer] = 512; - nXDamage[nPlayer] -= bcos(sprite[nPlayerSprite].ang, 9); - nYDamage[nPlayer] -= bsin(sprite[nPlayerSprite].ang, 9); + nXDamage[nPlayer] -= bcos(pPlayerSprite->ang, 9); + nYDamage[nPlayer] -= bsin(pPlayerSprite->ang, 9); break; } case kWeaponRing: diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 1bd543b8f..f780c6b2b 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -331,6 +331,7 @@ void InitSectFlag() void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) { + auto pSprite = &sprite[nSprite]; int nChannel = runlist_AllocChannel(nHitag % 1000); int nSpeed = nLotag / 1000; @@ -402,33 +403,33 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) case 58: case 60: { - sprite[nSprite].hitag = nVal; + pSprite->hitag = nVal; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } case 12: // berry twig { - sprite[nSprite].hitag = 40; + pSprite->hitag = 40; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } case 13: // blood bowl { - sprite[nSprite].hitag = 160; + pSprite->hitag = 160; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } case 14: // venom bowl { - sprite[nSprite].hitag = -200; + pSprite->hitag = -200; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } @@ -449,18 +450,18 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } else { - sprite[nSprite].hitag = nVal; + pSprite->hitag = nVal; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } } case 27: { - sprite[nSprite].hitag = 1; + pSprite->hitag = 1; changespritestat(nSprite, 9 + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } @@ -469,9 +470,9 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) { nVal++; nVal--; // CHECKME ?? - sprite[nSprite].hitag = nVal; + pSprite->hitag = nVal; changespritestat(nSprite, nLotag + 900); - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; BuildItemAnim(nSprite); return; } @@ -490,12 +491,12 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) { case 999: { - AddFlicker(sprite[nSprite].sectnum, nSpeed); + AddFlicker(pSprite->sectnum, nSpeed); break; } case 998: { - AddGlow(sprite[nSprite].sectnum, nSpeed); + AddGlow(pSprite->sectnum, nSpeed); break; } case 118: // Anubis with drum @@ -640,7 +641,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case 99: // underwater type 2 { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SetAbove(nSector, nHitag); SectFlag[nSector] |= kSectUnderwater; @@ -649,7 +650,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case 98: { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SetBelow(nSector, nHitag); SnapSectors(nSector, nHitag, 1); @@ -658,7 +659,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case 97: { - AddSectorBob(sprite[nSprite].sectnum, nHitag, 1); + AddSectorBob(pSprite->sectnum, nHitag, 1); mydeletesprite(nSprite); return; @@ -670,7 +671,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) nDamage = 1; } - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SectDamage[nSector] = nDamage; SectFlag[nSector] |= kSectLava; @@ -680,14 +681,14 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case 95: { - AddSectorBob(sprite[nSprite].sectnum, nHitag, 0); + AddSectorBob(pSprite->sectnum, nHitag, 0); mydeletesprite(nSprite); return; } case 94: // water { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SectDepth[nSector] = nHitag << 8; mydeletesprite(nSprite); @@ -706,10 +707,10 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) case 79: case 89: { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SectSpeed[nSector] = nSpeed; - SectFlag[nSector] |= sprite[nSprite].ang; + SectFlag[nSector] |= pSprite->ang; mydeletesprite(nSprite); return; @@ -723,7 +724,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) } case 80: // underwater { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SectFlag[nSector] |= kSectUnderwater; mydeletesprite(nSprite); @@ -733,7 +734,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) { AddFlow(nSprite, nSpeed, 1); - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; SectFlag[nSector] |= 0x8000; mydeletesprite(nSprite); @@ -771,13 +772,13 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) case 63: { changespritestat(nSprite, 405); - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; return; } case 62: { nNetStartSprite[nNetStartSprites] = nSprite; - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; nNetStartSprites++; return; @@ -785,7 +786,7 @@ void ProcessSpriteTag(short nSprite, short nLotag, short nHitag) case kTagRamses: // Ramses head { nSpiritSprite = nSprite; - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; return; } default: // TODO - checkme! @@ -806,16 +807,18 @@ void ExamineSprites() for (int nSprite = 0; nSprite < kMaxSprites; nSprite++) { - int nStatus = sprite[nSprite].statnum; + auto pSprite = &sprite[nSprite]; + + int nStatus = pSprite->statnum; if (!nStatus) { - short lotag = sprite[nSprite].lotag; - short hitag = sprite[nSprite].hitag; + short lotag = pSprite->lotag; + short hitag = pSprite->hitag; if ((nStatus < kMaxStatus) && lotag) { - sprite[nSprite].lotag = 0; - sprite[nSprite].hitag = 0; + pSprite->lotag = 0; + pSprite->hitag = 0; ProcessSpriteTag(nSprite, lotag, hitag); } @@ -829,10 +832,12 @@ void ExamineSprites() if (nNetPlayerCount) { int nSprite = insertsprite(initsect, 0); - sprite[nSprite].x = initx; - sprite[nSprite].y = inity; - sprite[nSprite].z = initz; - sprite[nSprite].cstat = 0x8000; + auto pSprite = &sprite[nSprite]; + + pSprite->x = initx; + pSprite->y = inity; + pSprite->z = initz; + pSprite->cstat = 0x8000; nNetStartSprite[nNetStartSprites] = nSprite; nNetStartSprites++; } diff --git a/source/games/exhumed/src/items.cpp b/source/games/exhumed/src/items.cpp index b6204c7ed..6e8d379be 100644 --- a/source/games/exhumed/src/items.cpp +++ b/source/games/exhumed/src/items.cpp @@ -122,33 +122,37 @@ void SerializeItems(FSerializer& arc) void BuildItemAnim(short nSprite) { - int nItem = sprite[nSprite].statnum - 906; + auto pSprite = &sprite[nSprite]; + + int nItem = pSprite->statnum - 906; if (nItemAnimInfo[nItem].a >= 0) { - int nAnim = BuildAnim(nSprite, 41, nItemAnimInfo[nItem].a, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, nItemAnimInfo[nItem].repeat, 20); + int nAnim = BuildAnim(nSprite, 41, nItemAnimInfo[nItem].a, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, nItemAnimInfo[nItem].repeat, 20); int nAnimSprite = GetAnimSprite(nAnim); if (nItem == 44) { sprite[nAnimSprite].cstat |= 2; } - changespritestat(nAnimSprite, sprite[nSprite].statnum); + changespritestat(nAnimSprite, pSprite->statnum); sprite[nAnimSprite].owner = nAnim; - sprite[nAnimSprite].hitag = sprite[nSprite].hitag; + sprite[nAnimSprite].hitag = pSprite->hitag; } else { - sprite[nSprite].owner = -1; - sprite[nSprite].yrepeat = (uint8_t)nItemAnimInfo[nItem].repeat; - sprite[nSprite].xrepeat = (uint8_t)nItemAnimInfo[nItem].repeat; + pSprite->owner = -1; + pSprite->yrepeat = (uint8_t)nItemAnimInfo[nItem].repeat; + pSprite->xrepeat = (uint8_t)nItemAnimInfo[nItem].repeat; } } void DestroyItemAnim(short nSprite) { - short nAnim = sprite[nSprite].owner; + auto pSprite = &sprite[nSprite]; + + short nAnim = pSprite->owner; if (nAnim >= 0) { DestroyAnim(nAnim); @@ -185,11 +189,12 @@ static bool UseEye(short nPlayer) PlayerList[nPlayer].nInvisible = 900; int nSprite = PlayerList[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; if (nPlayerFloorSprite[nPlayer] >= 0) { - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; } if (nPlayer == nLocalPlayer) @@ -334,6 +339,8 @@ int GrabItem(short nPlayer, short nItem) void DropMagic(short nSprite) { + auto pSprite = &sprite[nSprite]; + if (lFinaleStart) { return; } @@ -346,10 +353,10 @@ void DropMagic(short nSprite) -1, 64, 0, - sprite[nSprite].x, - sprite[nSprite].y, - sprite[nSprite].z, - sprite[nSprite].sectnum, + pSprite->x, + pSprite->y, + pSprite->z, + pSprite->sectnum, 48, 4); @@ -409,7 +416,7 @@ void StartRegenerate(short nSprite) } else { - sprite[edi].ang = sprite[nSprite].ang; + sprite[edi].ang = pSprite->ang; } nRegenerates--; @@ -437,16 +444,17 @@ void StartRegenerate(short nSprite) void DoRegenerates() { int nSprite = nFirstRegenerate; + auto pSprite = &sprite[nSprite]; - for (int i = nRegenerates; i > 0; i--, nSprite = sprite[nSprite].ang) + for (int i = nRegenerates; i > 0; i--, nSprite = pSprite->ang) { - if (sprite[nSprite].extra > 0) + if (pSprite->extra > 0) { - sprite[nSprite].extra--; + pSprite->extra--; - if (sprite[nSprite].extra <= 0) + if (pSprite->extra <= 0) { - BuildAnim(-1, 38, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, 64, 4); + BuildAnim(-1, 38, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, 64, 4); D3PlayFX(StaticSound[kSoundTorchOn], nSprite); } else { @@ -455,27 +463,27 @@ void DoRegenerates() } else { - if (sprite[nSprite].xrepeat < sprite[nSprite].xvel) + if (pSprite->xrepeat < pSprite->xvel) { - sprite[nSprite].xrepeat += 2; - sprite[nSprite].yrepeat += 2; + pSprite->xrepeat += 2; + pSprite->yrepeat += 2; continue; } } - sprite[nSprite].zvel = 0; - sprite[nSprite].yrepeat = (uint8_t)sprite[nSprite].xvel; - sprite[nSprite].xrepeat = (uint8_t)sprite[nSprite].xvel; - sprite[nSprite].pal = (uint8_t)sprite[nSprite].yvel; - sprite[nSprite].yvel = sprite[nSprite].zvel; // setting to 0 - sprite[nSprite].xvel = sprite[nSprite].zvel; // setting to 0 + pSprite->zvel = 0; + pSprite->yrepeat = (uint8_t)pSprite->xvel; + pSprite->xrepeat = (uint8_t)pSprite->xvel; + pSprite->pal = (uint8_t)pSprite->yvel; + pSprite->yvel = pSprite->zvel; // setting to 0 + pSprite->xvel = pSprite->zvel; // setting to 0 nRegenerates--; - if (sprite[nSprite].statnum == kStatExplodeTrigger) { - sprite[nSprite].cstat = 0x101; + if (pSprite->statnum == kStatExplodeTrigger) { + pSprite->cstat = 0x101; } else { - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; } if (nRegenerates == 0) { diff --git a/source/games/exhumed/src/lavadude.cpp b/source/games/exhumed/src/lavadude.cpp index e36fa7600..14ddfe3aa 100644 --- a/source/games/exhumed/src/lavadude.cpp +++ b/source/games/exhumed/src/lavadude.cpp @@ -79,34 +79,36 @@ void InitLava() int BuildLavaLimb(int nSprite, int edx, int ebx) { - short nSector = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + short nSector = pSprite->sectnum; int nLimbSprite = insertsprite(nSector, 118); assert(nLimbSprite >= 0 && nLimbSprite < kMaxSprites); + auto pLimbSprite = &sprite[nLimbSprite]; - sprite[nLimbSprite].x = sprite[nSprite].x; - sprite[nLimbSprite].y = sprite[nSprite].y; - sprite[nLimbSprite].z = sprite[nSprite].z - RandomLong() % ebx; - sprite[nLimbSprite].cstat = 0; - sprite[nLimbSprite].shade = -127; - sprite[nLimbSprite].pal = 1; - sprite[nLimbSprite].xvel = (RandomSize(5) - 16) << 8; - sprite[nLimbSprite].yvel = (RandomSize(5) - 16) << 8; - sprite[nLimbSprite].zvel = 2560 - (RandomSize(5) << 8); - sprite[nLimbSprite].xoffset = 0; - sprite[nLimbSprite].yoffset = 0; - sprite[nLimbSprite].xrepeat = 90; - sprite[nLimbSprite].yrepeat = 90; - sprite[nLimbSprite].picnum = (edx & 3) % 3; - sprite[nLimbSprite].hitag = 0; - sprite[nLimbSprite].lotag = runlist_HeadRun() + 1; - sprite[nLimbSprite].clipdist = 0; + pLimbSprite->x = pSprite->x; + pLimbSprite->y = pSprite->y; + pLimbSprite->z = pSprite->z - RandomLong() % ebx; + pLimbSprite->cstat = 0; + pLimbSprite->shade = -127; + pLimbSprite->pal = 1; + pLimbSprite->xvel = (RandomSize(5) - 16) << 8; + pLimbSprite->yvel = (RandomSize(5) - 16) << 8; + pLimbSprite->zvel = 2560 - (RandomSize(5) << 8); + pLimbSprite->xoffset = 0; + pLimbSprite->yoffset = 0; + pLimbSprite->xrepeat = 90; + pLimbSprite->yrepeat = 90; + pLimbSprite->picnum = (edx & 3) % 3; + pLimbSprite->hitag = 0; + pLimbSprite->lotag = runlist_HeadRun() + 1; + pLimbSprite->clipdist = 0; // GrabTimeSlot(3); - sprite[nLimbSprite].extra = -1; - sprite[nLimbSprite].owner = runlist_AddRunRec(sprite[nLimbSprite].lotag - 1, nLimbSprite | 0x160000); - sprite[nLimbSprite].hitag = runlist_AddRunRec(NewRun, nLimbSprite | 0x160000); + pLimbSprite->extra = -1; + pLimbSprite->owner = runlist_AddRunRec(pLimbSprite->lotag - 1, nLimbSprite | 0x160000); + pLimbSprite->hitag = runlist_AddRunRec(NewRun, nLimbSprite | 0x160000); return nLimbSprite; } @@ -115,6 +117,7 @@ void FuncLavaLimb(int a, int, int nRun) { short nSprite = RunData[nRun].nVal; assert(nSprite >= 0 && nSprite < kMaxSprites); + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -122,19 +125,19 @@ void FuncLavaLimb(int a, int, int nRun) { case 0x20000: { - sprite[nSprite].shade += 3; + pSprite->shade += 3; - int nRet = movesprite(nSprite, sprite[nSprite].xvel << 12, sprite[nSprite].yvel << 12, sprite[nSprite].zvel, 2560, -2560, CLIPMASK1); + int nRet = movesprite(nSprite, pSprite->xvel << 12, pSprite->yvel << 12, pSprite->zvel, 2560, -2560, CLIPMASK1); - if (nRet || sprite[nSprite].shade > 100) + if (nRet || pSprite->shade > 100) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); - runlist_SubRunRec(sprite[nSprite].hitag); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); + runlist_SubRunRec(pSprite->hitag); mydeletesprite(nSprite); } @@ -143,7 +146,7 @@ void FuncLavaLimb(int a, int, int nRun) case 0x90000: { - seq_PlotSequence(a & 0xFFFF, (SeqOffsets[kSeqLavag] + 30) + sprite[nSprite].picnum, 0, 1); + seq_PlotSequence(a & 0xFFFF, (SeqOffsets[kSeqLavag] + 30) + pSprite->picnum, 0, 1); break; } @@ -156,44 +159,46 @@ int BuildLava(short nSprite, int x, int y, int, short nSector, short nAngle, int { auto nLava = LavaList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 118); + pSprite = &sprite[nSprite]; } else { - nSector = sprite[nSprite].sectnum; - nAngle = sprite[nSprite].ang; - x = sprite[nSprite].x; - y = sprite[nSprite].y; + nSector = pSprite->sectnum; + nAngle = pSprite->ang; + x = pSprite->x; + y = pSprite->y; changespritestat(nSprite, 118); } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = sector[nSector].floorz; - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].xrepeat = 200; - sprite[nSprite].yrepeat = 200; - sprite[nSprite].shade = -12; - sprite[nSprite].pal = 0; - sprite[nSprite].clipdist = 127; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = seq_GetSeqPicnum(kSeqLavag, LavadudeSeq[3].a, 0); - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = sector[nSector].floorz; + pSprite->cstat = 0x8000; + pSprite->xrepeat = 200; + pSprite->yrepeat = 200; + pSprite->shade = -12; + pSprite->pal = 0; + pSprite->clipdist = 127; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = seq_GetSeqPicnum(kSeqLavag, LavadudeSeq[3].a, 0); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->ang = nAngle; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; // GrabTimeSlot(3); - sprite[nSprite].extra = -1; + pSprite->extra = -1; LavaList[nLava].nAction = 0; LavaList[nLava].nHealth = 4000; @@ -202,7 +207,7 @@ int BuildLava(short nSprite, int x, int y, int, short nSector, short nAngle, int LavaList[nLava].nIndex = nChannel; LavaList[nLava].nFrame = 0; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nLava | 0x150000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nLava | 0x150000); LavaList[nLava].nRun = runlist_AddRunRec(NewRun, nLava | 0x150000); nCreaturesTotal++; @@ -218,6 +223,7 @@ void FuncLava(int a, int nDamage, int nRun) short nAction = LavaList[nLava].nAction; short nSeq = LavadudeSeq[nAction].a + SeqOffsets[kSeqLavag]; short nSprite = LavaList[nLava].nSprite; + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -257,7 +263,7 @@ void FuncLava(int a, int nDamage, int nRun) nCreaturesKilled++; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; } else { @@ -277,7 +283,7 @@ void FuncLava(int a, int nDamage, int nRun) { LavaList[nLava].nAction = 4; LavaList[nLava].nFrame = 0; - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; } } @@ -289,7 +295,7 @@ void FuncLava(int a, int nDamage, int nRun) case 0x20000: { - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, LavaList[nLava].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, LavaList[nLava].nFrame); int var_38 = LavaList[nLava].nFrame; short nFlag = FrameFlag[SeqBase[nSeq] + var_38]; @@ -336,36 +342,36 @@ void FuncLava(int a, int nDamage, int nRun) PlotCourseToSprite(nSprite, nTarget); - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); if (nTarget >= 0 && !RandomSize(1)) { LavaList[nLava].nTarget = nTarget; LavaList[nLava].nAction = 2; - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; LavaList[nLava].nFrame = 0; break; } } - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; + short nSector = pSprite->sectnum; - int nVal = movesprite(nSprite, sprite[nSprite].xvel << 8, sprite[nSprite].yvel << 8, 0, 0, 0, CLIPMASK0); + int nVal = movesprite(nSprite, pSprite->xvel << 8, pSprite->yvel << 8, 0, 0, 0, CLIPMASK0); - if (nSector != sprite[nSprite].sectnum) + if (nSector != pSprite->sectnum) { changespritesect(nSprite, nSector); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; - sprite[nSprite].ang = (sprite[nSprite].ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->ang = (pSprite->ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); break; } @@ -375,21 +381,21 @@ void FuncLava(int a, int nDamage, int nRun) if ((nVal & 0xC000) == 0x8000) { - sprite[nSprite].ang = (sprite[nSprite].ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->ang = (pSprite->ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); break; } else if ((nVal & 0xC000) == 0xC000) { if ((nVal & 0x3FFF) == nTarget) { - int nAng = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); - if (AngleDiff(sprite[nSprite].ang, nAng) < 64) + int nAng = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); + if (AngleDiff(pSprite->ang, nAng) < 64) { LavaList[nLava].nAction = 2; LavaList[nLava].nFrame = 0; - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; break; } } @@ -413,7 +419,7 @@ void FuncLava(int a, int nDamage, int nRun) PlotCourseToSprite(nSprite, nTarget); - sprite[nSprite].cstat |= 0x101; + pSprite->cstat |= 0x101; } break; @@ -426,7 +432,7 @@ void FuncLava(int a, int nDamage, int nRun) int nHeight = GetSpriteHeight(nSprite); GetUpAngle(nSprite, -64000, nTarget, (-(nHeight >> 1))); - BuildBullet(nSprite, 10, bcos(sprite[nSprite].ang, 8), bsin(sprite[nSprite].ang, 8), -1, sprite[nSprite].ang, nTarget + 10000, 1); + BuildBullet(nSprite, 10, bcos(pSprite->ang, 8), bsin(pSprite->ang, 8), -1, pSprite->ang, nTarget + 10000, 1); } else if (var_1C) { @@ -443,7 +449,7 @@ void FuncLava(int a, int nDamage, int nRun) if (var_1C) { LavaList[nLava].nAction = 7; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; } break; @@ -482,8 +488,8 @@ void FuncLava(int a, int nDamage, int nRun) } while (ecx < 30); - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); runlist_SubRunRec(LavaList[nLava].nRun); mydeletesprite(nSprite); } @@ -507,14 +513,14 @@ void FuncLava(int a, int nDamage, int nRun) { LavaList[nLava].nAction = 0; LavaList[nLava].nFrame = 0; - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; } break; } } // loc_31521: - sprite[nSprite].pal = 1; + pSprite->pal = 1; } } } diff --git a/source/games/exhumed/src/lighting.cpp b/source/games/exhumed/src/lighting.cpp index 5429739aa..ae1dfa7f6 100644 --- a/source/games/exhumed/src/lighting.cpp +++ b/source/games/exhumed/src/lighting.cpp @@ -352,27 +352,28 @@ void AddFlash(short nSector, int x, int y, int z, int val) SectIterator it(nSector); while ((nSprite = it.NextIndex()) >= 0) { - if (sprite[nSprite].pal < 4) + auto pSprite = &sprite[nSprite]; + if (pSprite->pal < 4) { short nFlash3 = GrabFlash(); if (nFlash3 >= 0) { sFlash[nFlash3].field_0 = var_20 | 4; - sFlash[nFlash3].shade = sprite[nSprite].shade; + sFlash[nFlash3].shade = pSprite->shade; sFlash[nFlash3].field_1 = nSprite; - sprite[nSprite].pal += 7; + pSprite->pal += 7; int eax = -255; if (!var_18) { - int xDiff = x - sprite[nSprite].x; + int xDiff = x - pSprite->x; if (xDiff < 0) { xDiff = -xDiff; } - int yDiff = y - sprite[nSprite].y; + int yDiff = y - pSprite->y; if (yDiff < 0) { yDiff = -yDiff; } @@ -382,12 +383,12 @@ void AddFlash(short nSector, int x, int y, int z, int val) if (eax < 0) { - short shade = sprite[nSprite].shade + eax; + short shade = pSprite->shade + eax; if (shade < -127) { shade = -127; } - sprite[nSprite].shade = (int8_t)shade; + pSprite->shade = (int8_t)shade; } } } diff --git a/source/games/exhumed/src/lion.cpp b/source/games/exhumed/src/lion.cpp index 57a376888..0867b4cef 100644 --- a/source/games/exhumed/src/lion.cpp +++ b/source/games/exhumed/src/lion.cpp @@ -85,40 +85,42 @@ int BuildLion(short nSprite, int x, int y, int z, short nSector, short nAngle) { auto nLion = LionList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 104); + pSprite = &sprite[nSprite]; } else { changespritestat(nSprite, 104); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + nAngle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].clipdist = 60; - sprite[nSprite].shade = -12; - sprite[nSprite].xrepeat = 40; - sprite[nSprite].yrepeat = 40; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].extra = -1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->clipdist = 60; + pSprite->shade = -12; + pSprite->xrepeat = 40; + pSprite->yrepeat = 40; + pSprite->picnum = 1; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = nAngle; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->hitag = 0; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -130,7 +132,7 @@ int BuildLion(short nSprite, int x, int y, int z, short nSector, short nAngle) LionList[nLion].nCount = 0; LionList[nLion].nIndex = nLion; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nLion | 0x130000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nLion | 0x130000); LionList[nLion].nRun = runlist_AddRunRec(NewRun, nLion | 0x130000); @@ -145,6 +147,7 @@ void FuncLion(int a, int nDamage, int nRun) assert(nLion >= 0 && nLion < (int)LionList.Size()); short nSprite = LionList[nLion].nSprite; + auto pSprite = &sprite[nSprite]; short nAction = LionList[nLion].nAction; bool bVal = false; @@ -179,10 +182,10 @@ void FuncLion(int a, int nDamage, int nRun) if (LionList[nLion].nHealth <= 0) { // R.I.P. - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->cstat &= 0xFEFE; LionList[nLion].nHealth = 0; @@ -219,22 +222,22 @@ void FuncLion(int a, int nDamage, int nRun) if (RandomSize(8) <= (LionList[nLion].nHealth >> 2)) { LionList[nLion].nAction = 4; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } else if (RandomSize(1)) { PlotCourseToSprite(nSprite, nTarget); LionList[nLion].nAction = 5; LionList[nLion].nCount = RandomSize(3); - sprite[nSprite].ang = (sprite[nSprite].ang - (RandomSize(1) << 8)) + (RandomSize(1) << 8); // NOTE: no angle mask in original code + pSprite->ang = (pSprite->ang - (RandomSize(1) << 8)) + (RandomSize(1) << 8); // NOTE: no angle mask in original code } else { LionList[nLion].nAction = 8; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->cstat &= 0xFEFE; } LionList[nLion].nFrame = 0; @@ -253,7 +256,7 @@ void FuncLion(int a, int nDamage, int nRun) short nSeq = SeqOffsets[kSeqLion] + LionSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, LionList[nLion].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, LionList[nLion].nFrame); seq_MoveSequence(nSprite, nSeq, LionList[nLion].nFrame); @@ -288,8 +291,8 @@ void FuncLion(int a, int nDamage, int nRun) LionList[nLion].nAction = 2; LionList[nLion].nFrame = 0; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); LionList[nLion].nTarget = nTarget; return; } @@ -303,14 +306,14 @@ void FuncLion(int a, int nDamage, int nRun) { if (RandomBit()) { - sprite[nSprite].ang = RandomWord() & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->ang = RandomWord() & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); } else { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } LionList[nLion].nCount = 100; @@ -326,17 +329,17 @@ void FuncLion(int a, int nDamage, int nRun) { PlotCourseToSprite(nSprite, nTarget); - int nAng = sprite[nSprite].ang & 0xFFF8; + int nAng = pSprite->ang & 0xFFF8; - if (sprite[nSprite].cstat & 0x8000) + if (pSprite->cstat & 0x8000) { - sprite[nSprite].xvel = bcos(nAng, 1); - sprite[nSprite].yvel = bsin(nAng, 1); + pSprite->xvel = bcos(nAng, 1); + pSprite->yvel = bsin(nAng, 1); } else { - sprite[nSprite].xvel = bcos(nAng, -1); - sprite[nSprite].yvel = bsin(nAng, -1); + pSprite->xvel = bcos(nAng, -1); + pSprite->yvel = bsin(nAng, -1); } } @@ -347,27 +350,27 @@ void FuncLion(int a, int nDamage, int nRun) else if ((nMov & 0xC000) == 0x8000) { // loc_378FA: - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); break; } else if ((nMov & 0xC000) == 0xC000) { if ((nMov & 0x3FFF) == nTarget) { - if (sprite[nSprite].cstat & 0x8000) + if (pSprite->cstat & 0x8000) { LionList[nLion].nAction = 9; - sprite[nSprite].cstat &= 0x7FFF; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->cstat &= 0x7FFF; + pSprite->xvel = 0; + pSprite->yvel = 0; } else { - int nAng = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); + int nAng = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); - if (AngleDiff(sprite[nSprite].ang, nAng) < 64) + if (AngleDiff(pSprite->ang, nAng) < 64) { LionList[nLion].nAction = 3; } @@ -379,9 +382,9 @@ void FuncLion(int a, int nDamage, int nRun) else { // loc_378FA: - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); break; } } @@ -421,8 +424,8 @@ void FuncLion(int a, int nDamage, int nRun) if (nMov & 0x20000) { - sprite[nSprite].xvel >>= 1; - sprite[nSprite].yvel >>= 1; + pSprite->xvel >>= 1; + pSprite->yvel >>= 1; } return; @@ -433,17 +436,17 @@ void FuncLion(int a, int nDamage, int nRun) LionList[nLion].nCount--; if (LionList[nLion].nCount <= 0) { - sprite[nSprite].zvel = -4000; + pSprite->zvel = -4000; LionList[nLion].nCount = 0; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z - (GetSpriteHeight(nSprite) >> 1); + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z - (GetSpriteHeight(nSprite) >> 1); int nCheckDist = 0x7FFFFFFF; - short nAngle = sprite[nSprite].ang; - short nScanAngle = (sprite[nSprite].ang - 512) & kAngleMask; + short nAngle = pSprite->ang; + short nScanAngle = (pSprite->ang - 512) & kAngleMask; for (int i = 0; i < 5; i++) { @@ -452,7 +455,7 @@ void FuncLion(int a, int nDamage, int nRun) vec3_t startPos = { x, y, z }; hitdata_t hitData; - hitscan(&startPos, sprite[nSprite].sectnum, bcos(nScanAngle), bsin(nScanAngle), 0, &hitData, CLIPMASK1); + hitscan(&startPos, pSprite->sectnum, bcos(nScanAngle), bsin(nScanAngle), 0, &hitData, CLIPMASK1); hitx = hitData.pos.x; hity = hitData.pos.y; @@ -474,11 +477,11 @@ void FuncLion(int a, int nDamage, int nRun) nScanAngle &= kAngleMask; } - sprite[nSprite].ang = nAngle; + pSprite->ang = nAngle; LionList[nLion].nAction = 6; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang) - bcos(sprite[nSprite].ang, -3); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang) - bsin(sprite[nSprite].ang, -3); + pSprite->xvel = bcos(pSprite->ang) - bcos(pSprite->ang, -3); + pSprite->yvel = bsin(pSprite->ang) - bsin(pSprite->ang, -3); D3PlayFX(StaticSound[kSound24], nSprite); } @@ -497,7 +500,7 @@ void FuncLion(int a, int nDamage, int nRun) if ((nMov & 0xC000) == 0x8000) { LionList[nLion].nAction = 7; - sprite[nSprite].ang = (GetWallNormal(nMov & 0x3FFF) + 1024) & kAngleMask; + pSprite->ang = (GetWallNormal(nMov & 0x3FFF) + 1024) & kAngleMask; LionList[nLion].nCount = RandomSize(4); return; } @@ -505,8 +508,8 @@ void FuncLion(int a, int nDamage, int nRun) { if ((nMov & 0x3FFF) == nTarget) { - int nAng = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); - if (AngleDiff(sprite[nSprite].ang, nAng) < 64) + int nAng = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); + if (AngleDiff(pSprite->ang, nAng) < 64) { LionList[nLion].nAction = 3; LionList[nLion].nFrame = 0; @@ -515,9 +518,9 @@ void FuncLion(int a, int nDamage, int nRun) else { // loc_378FA: - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); break; } } @@ -538,14 +541,14 @@ void FuncLion(int a, int nDamage, int nRun) } else { - sprite[nSprite].ang = (RandomSize(9) + (sprite[nSprite].ang + 768)) & kAngleMask; + pSprite->ang = (RandomSize(9) + (pSprite->ang + 768)) & kAngleMask; } - sprite[nSprite].zvel = -1000; + pSprite->zvel = -1000; LionList[nLion].nAction = 6; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang) - bcos(sprite[nSprite].ang, -3); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang) - bsin(sprite[nSprite].ang, -3); + pSprite->xvel = bcos(pSprite->ang) - bcos(pSprite->ang, -3); + pSprite->yvel = bsin(pSprite->ang) - bsin(pSprite->ang, -3); D3PlayFX(StaticSound[kSound24], nSprite); } @@ -558,7 +561,7 @@ void FuncLion(int a, int nDamage, int nRun) { LionList[nLion].nAction = 2; LionList[nLion].nFrame = 0; - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; } return; } @@ -569,7 +572,7 @@ void FuncLion(int a, int nDamage, int nRun) { LionList[nLion].nFrame = 0; LionList[nLion].nAction = 2; - sprite[nSprite].cstat |= 0x101; + pSprite->cstat |= 0x101; } return; } @@ -579,9 +582,9 @@ void FuncLion(int a, int nDamage, int nRun) { if (bVal) { - runlist_SubRunRec(sprite[nSprite].owner); + runlist_SubRunRec(pSprite->owner); runlist_SubRunRec(LionList[nLion].nRun); - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; } return; } @@ -596,8 +599,8 @@ void FuncLion(int a, int nDamage, int nRun) LionList[nLion].nFrame = 0; LionList[nLion].nCount = 100; LionList[nLion].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } diff --git a/source/games/exhumed/src/move.cpp b/source/games/exhumed/src/move.cpp index d9b6a4bb4..b4b8e4731 100644 --- a/source/games/exhumed/src/move.cpp +++ b/source/games/exhumed/src/move.cpp @@ -284,8 +284,9 @@ void BuildNear(int x, int y, int walldist, int nSector) int BelowNear(short nSprite) { - short nSector = sprite[nSprite].sectnum; - int z = sprite[nSprite].z; + auto pSprite = &sprite[nSprite]; + short nSector = pSprite->sectnum; + int z = pSprite->z; int var_24, z2; @@ -325,11 +326,11 @@ int BelowNear(short nSprite) } } - if (z2 < sprite[nSprite].z) + if (z2 < pSprite->z) { - sprite[nSprite].z = z2; + pSprite->z = z2; overridesect = nSector; - sprite[nSprite].zvel = 0; + pSprite->zvel = 0; bTouchFloor = true; @@ -516,7 +517,8 @@ int movespritez(short nSprite, int z, int height, int, int clipdist) int GetSpriteHeight(int nSprite) { - return tileHeight(sprite[nSprite].picnum) * sprite[nSprite].yrepeat * 4; + auto pSprite = &sprite[nSprite]; + return tileHeight(pSprite->picnum) * pSprite->yrepeat * 4; } int movesprite(short nSprite, int dx, int dy, int dz, int, int flordist, unsigned int clipmask) @@ -601,65 +603,68 @@ int movesprite(short nSprite, int dx, int dy, int dz, int, int flordist, unsigne void Gravity(short nSprite) { - short nSector = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + short nSector = pSprite->sectnum; if (SectFlag[nSector] & kSectUnderwater) { - if (sprite[nSprite].statnum != 100) + if (pSprite->statnum != 100) { - if (sprite[nSprite].zvel <= 1024) + if (pSprite->zvel <= 1024) { - if (sprite[nSprite].zvel < 2048) { - sprite[nSprite].zvel += 512; + if (pSprite->zvel < 2048) { + pSprite->zvel += 512; } } else { - sprite[nSprite].zvel -= 64; + pSprite->zvel -= 64; } } else { - if (sprite[nSprite].zvel > 0) + if (pSprite->zvel > 0) { - sprite[nSprite].zvel -= 64; - if (sprite[nSprite].zvel < 0) { - sprite[nSprite].zvel = 0; + pSprite->zvel -= 64; + if (pSprite->zvel < 0) { + pSprite->zvel = 0; } } - else if (sprite[nSprite].zvel < 0) + else if (pSprite->zvel < 0) { - sprite[nSprite].zvel += 64; - if (sprite[nSprite].zvel > 0) { - sprite[nSprite].zvel = 0; + pSprite->zvel += 64; + if (pSprite->zvel > 0) { + pSprite->zvel = 0; } } } } else { - sprite[nSprite].zvel += 512; - if (sprite[nSprite].zvel > 16384) { - sprite[nSprite].zvel = 16384; + pSprite->zvel += 512; + if (pSprite->zvel > 16384) { + pSprite->zvel = 16384; } } } int MoveCreature(short nSprite) { - return movesprite(nSprite, sprite[nSprite].xvel << 8, sprite[nSprite].yvel << 8, sprite[nSprite].zvel, 15360, -5120, CLIPMASK0); + auto pSprite = &sprite[nSprite]; + return movesprite(nSprite, pSprite->xvel << 8, pSprite->yvel << 8, pSprite->zvel, 15360, -5120, CLIPMASK0); } int MoveCreatureWithCaution(int nSprite) { - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; - short nSectorPre = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; + short nSectorPre = pSprite->sectnum; int ecx = MoveCreature(nSprite); - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; if (nSector != nSectorPre) { @@ -670,15 +675,15 @@ int MoveCreatureWithCaution(int nSprite) if (zDiff > 15360 || (SectFlag[nSector] & kSectUnderwater) || (SectBelow[nSector] > -1 && SectFlag[SectBelow[nSector]]) || SectDamage[nSector]) { - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; mychangespritesect(nSprite, nSectorPre); - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); return 0; } } @@ -691,7 +696,10 @@ int GetAngleToSprite(int nSprite1, int nSprite2) if (nSprite1 < 0 || nSprite2 < 0) return -1; - return GetMyAngle(sprite[nSprite2].x - sprite[nSprite1].x, sprite[nSprite2].y - sprite[nSprite1].y); + auto pSprite1 = &sprite[nSprite1]; + auto pSprite2 = &sprite[nSprite2]; + + return GetMyAngle(pSprite2->x - pSprite1->x, pSprite2->y - pSprite1->y); } int PlotCourseToSprite(int nSprite1, int nSprite2) @@ -699,10 +707,12 @@ int PlotCourseToSprite(int nSprite1, int nSprite2) if (nSprite1 < 0 || nSprite2 < 0) return -1; - int x = sprite[nSprite2].x - sprite[nSprite1].x; - int y = sprite[nSprite2].y - sprite[nSprite1].y; + auto pSprite1 = &sprite[nSprite1]; + auto pSprite2 = &sprite[nSprite2]; + int x = pSprite2->x - pSprite1->x; + int y = pSprite2->y - pSprite1->y; - sprite[nSprite1].ang = GetMyAngle(x, y); + pSprite1->ang = GetMyAngle(x, y); uint32_t x2 = abs(x); uint32_t y2 = abs(y); @@ -720,6 +730,7 @@ int PlotCourseToSprite(int nSprite1, int nSprite2) int FindPlayer(int nSprite, int nDistance) { + auto pSprite = &sprite[nSprite]; int var_18 = 0; if (nSprite >= 0) var_18 = 1; @@ -730,11 +741,11 @@ int FindPlayer(int nSprite, int nDistance) if (nDistance < 0) nDistance = 100; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + short nSector = pSprite->sectnum; - int z = sprite[nSprite].z - GetSpriteHeight(nSprite); + int z = pSprite->z - GetSpriteHeight(nSprite); nDistance <<= 8; @@ -798,11 +809,13 @@ void CheckSectorFloor(short nSector, int z, int *x, int *y) int GetUpAngle(short nSprite1, int nVal, short nSprite2, int ecx) { - int x = sprite[nSprite2].x - sprite[nSprite1].x; - int y = sprite[nSprite2].y - sprite[nSprite1].y; + auto pSprite1 = &sprite[nSprite1]; + auto pSprite2 = &sprite[nSprite2]; + int x = pSprite2->x - pSprite1->x; + int y = pSprite2->y - pSprite1->y; - int ebx = (sprite[nSprite2].z + ecx) - (sprite[nSprite1].z + nVal); - int edx = (sprite[nSprite2].z + ecx) - (sprite[nSprite1].z + nVal); + int ebx = (pSprite2->z + ecx) - (pSprite1->z + nVal); + int edx = (pSprite2->z + ecx) - (pSprite1->z + nVal); ebx >>= 4; edx >>= 8; @@ -854,13 +867,14 @@ void CreatePushBlock(int nSector) sBlockInfo[nBlock].y = yAvg; int nSprite = insertsprite(nSector, 0); + auto pSprite = &sprite[nSprite]; sBlockInfo[nBlock].nSprite = nSprite; - sprite[nSprite].x = xAvg; - sprite[nSprite].y = yAvg; - sprite[nSprite].z = sector[nSector].floorz - 256; - sprite[nSprite].cstat = 0x8000; + pSprite->x = xAvg; + pSprite->y = yAvg; + pSprite->z = sector[nSector].floorz - 256; + pSprite->cstat = 0x8000; int var_28 = 0; @@ -885,7 +899,7 @@ void CreatePushBlock(int nSector) sBlockInfo[nBlock].field_8 = var_28; - sprite[nSprite].clipdist = (var_28 & 0xFF) << 2; + pSprite->clipdist = (var_28 & 0xFF) << 2; sector[nSector].extra = nBlock; } @@ -1133,8 +1147,9 @@ void MoveSector(short nSector, int nAngle, int *nXVel, int *nYVel) void SetQuake(short nSprite, int nVal) { - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; + auto pSprite = &sprite[nSprite]; + int x = pSprite->x; + int y = pSprite->y; nVal *= 256; @@ -1181,7 +1196,8 @@ void SetQuake(short nSprite, int nVal) int AngleChase(int nSprite, int nSprite2, int ebx, int ecx, int push1) { - int nClipType = sprite[nSprite].statnum != 107; + auto pSprite = &sprite[nSprite]; + int nClipType = pSprite->statnum != 107; /* bjd - need to handle cliptype to clipmask change that occured in later build engine version */ if (nClipType == 1) { @@ -1195,17 +1211,19 @@ int AngleChase(int nSprite, int nSprite2, int ebx, int ecx, int push1) if (nSprite2 < 0) { - sprite[nSprite].zvel = 0; - nAngle = sprite[nSprite].ang; + pSprite->zvel = 0; + nAngle = pSprite->ang; } else { - int nHeight = tileHeight(sprite[nSprite2].picnum) * sprite[nSprite2].yrepeat * 2; + auto pSprite2 = &sprite[nSprite2]; - int nMyAngle = GetMyAngle(sprite[nSprite2].x - sprite[nSprite].x, sprite[nSprite2].y - sprite[nSprite].y); + int nHeight = tileHeight(pSprite2->picnum) * pSprite2->yrepeat * 2; - uint32_t xDiff = abs(sprite[nSprite2].x - sprite[nSprite].x); - uint32_t yDiff = abs(sprite[nSprite2].y - sprite[nSprite].y); + int nMyAngle = GetMyAngle(pSprite2->x - pSprite->x, pSprite2->y - pSprite->y); + + uint32_t xDiff = abs(pSprite2->x - pSprite->x); + uint32_t yDiff = abs(pSprite2->y - pSprite->y); uint32_t sqrtNum = xDiff * xDiff + yDiff * yDiff; @@ -1217,9 +1235,9 @@ int AngleChase(int nSprite, int nSprite2, int ebx, int ecx, int push1) int nSqrt = ksqrt(sqrtNum); - int var_18 = GetMyAngle(nSqrt, ((sprite[nSprite2].z - nHeight) - sprite[nSprite].z) >> 8); + int var_18 = GetMyAngle(nSqrt, ((pSprite2->z - nHeight) - pSprite->z) >> 8); - int nAngDelta = AngleDelta(sprite[nSprite].ang, nMyAngle, 1024); + int nAngDelta = AngleDelta(pSprite->ang, nMyAngle, 1024); int nAngDelta2 = abs(nAngDelta); if (nAngDelta2 > 63) @@ -1243,15 +1261,15 @@ int AngleChase(int nSprite, int nSprite2, int ebx, int ecx, int push1) nAngDelta = -push1; } - nAngle = (nAngDelta + sprite[nSprite].ang) & kAngleMask; - int nAngDeltaD = AngleDelta(sprite[nSprite].zvel, var_18, 24); + nAngle = (nAngDelta + pSprite->ang) & kAngleMask; + int nAngDeltaD = AngleDelta(pSprite->zvel, var_18, 24); - sprite[nSprite].zvel = (sprite[nSprite].zvel + nAngDeltaD) & kAngleMask; + pSprite->zvel = (pSprite->zvel + nAngDeltaD) & kAngleMask; } - sprite[nSprite].ang = nAngle; + pSprite->ang = nAngle; - int eax = abs(bcos(sprite[nSprite].zvel)); + int eax = abs(bcos(pSprite->zvel)); int x = ((bcos(nAngle) * ebx) >> 14) * eax; int y = ((bsin(nAngle) * ebx) >> 14) * eax; @@ -1267,7 +1285,7 @@ int AngleChase(int nSprite, int nSprite2, int ebx, int ecx, int push1) sqrtNum = INT_MAX; } - int z = bsin(sprite[nSprite].zvel) * ksqrt(sqrtNum); + int z = bsin(pSprite->zvel) * ksqrt(sqrtNum); return movesprite(nSprite, x >> 2, y >> 2, (z >> 13) + bsin(ecx, -5), 0, 0, nClipType); } @@ -1285,18 +1303,19 @@ int GetWallNormal(short nWall) void WheresMyMouth(int nPlayer, int *x, int *y, int *z, short *sectnum) { int nSprite = PlayerList[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; - *x = sprite[nSprite].x; - *y = sprite[nSprite].y; + *x = pSprite->x; + *y = pSprite->y; int height = GetSpriteHeight(nSprite) / 2; - *z = sprite[nSprite].z - height; - *sectnum = sprite[nSprite].sectnum; + *z = pSprite->z - height; + *sectnum = pSprite->sectnum; clipmove_old((int32_t*)x, (int32_t*)y, (int32_t*)z, sectnum, - bcos(sprite[nSprite].ang, 7), - bsin(sprite[nSprite].ang, 7), + bcos(pSprite->ang, 7), + bsin(pSprite->ang, 7), 5120, 1280, 1280, CLIPMASK1); } @@ -1315,25 +1334,27 @@ void InitChunks() int GrabBodyGunSprite() { int nSprite = nBodyGunSprite[nCurBodyGunNum]; + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(0, 899); + pSprite = &sprite[nSprite]; nBodyGunSprite[nCurBodyGunNum] = nSprite; - sprite[nSprite].lotag = -1; - sprite[nSprite].owner = -1; + pSprite->lotag = -1; + pSprite->owner = -1; } else { - int nAnim = sprite[nSprite].owner; + int nAnim = pSprite->owner; if (nAnim != -1) { DestroyAnim(nAnim); } - sprite[nSprite].lotag = -1; - sprite[nSprite].owner = -1; + pSprite->lotag = -1; + pSprite->owner = -1; } nCurBodyGunNum++; @@ -1341,7 +1362,7 @@ int GrabBodyGunSprite() nCurBodyGunNum = 0; } - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; return nSprite; } @@ -1350,41 +1371,46 @@ int GrabBody() { int nSprite; + spritetype* pSprite = nullptr; do { nSprite = nBodySprite[nCurBodyNum]; + pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(0, 899); + pSprite = &sprite[nSprite]; nBodySprite[nCurBodyNum] = nSprite; - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; } nCurBodyNum++; if (nCurBodyNum >= 50) { nCurBodyNum = 0; } - } while (sprite[nSprite].cstat & 0x101); + } while (pSprite->cstat & 0x101); if (nBodyTotal < 50) { nBodyTotal++; } - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; return nSprite; } int GrabChunkSprite() { int nSprite = nChunkSprite[nCurChunkNum]; + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(0, 899); + pSprite = &sprite[nSprite]; nChunkSprite[nCurChunkNum] = nSprite; } - else if (sprite[nSprite].statnum) + else if (pSprite->statnum) { // TODO MonoOut("too many chunks being used at once!\n"); return -1; @@ -1399,7 +1425,7 @@ int GrabChunkSprite() if (nChunkTotal < kMaxMoveChunks) nChunkTotal++; - sprite[nSprite].cstat = 0x80; + pSprite->cstat = 0x80; return nSprite; } @@ -1413,6 +1439,7 @@ int BuildCreatureChunk(int nVal, int nPic) if (nSprite == -1) { return -1; } + auto pSprite = &sprite[nSprite]; if (nVal & 0x4000) { @@ -1426,40 +1453,40 @@ int BuildCreatureChunk(int nVal, int nPic) nVal &= 0xFFFF; - sprite[nSprite].x = sprite[nVal].x; - sprite[nSprite].y = sprite[nVal].y; - sprite[nSprite].z = sprite[nVal].z; + pSprite->x = sprite[nVal].x; + pSprite->y = sprite[nVal].y; + pSprite->z = sprite[nVal].z; mychangespritesect(nSprite, sprite[nVal].sectnum); - sprite[nSprite].cstat = 0x80; - sprite[nSprite].shade = -12; - sprite[nSprite].pal = 0; + pSprite->cstat = 0x80; + pSprite->shade = -12; + pSprite->pal = 0; - sprite[nSprite].xvel = (RandomSize(5) - 16) << 7; - sprite[nSprite].yvel = (RandomSize(5) - 16) << 7; - sprite[nSprite].zvel = (-(RandomSize(8) + 512)) << 3; + pSprite->xvel = (RandomSize(5) - 16) << 7; + pSprite->yvel = (RandomSize(5) - 16) << 7; + pSprite->zvel = (-(RandomSize(8) + 512)) << 3; if (var_14) { - sprite[nSprite].xvel *= 4; - sprite[nSprite].yvel *= 4; - sprite[nSprite].zvel *= 2; + pSprite->xvel *= 4; + pSprite->yvel *= 4; + pSprite->zvel *= 2; } - sprite[nSprite].xrepeat = 64; - sprite[nSprite].yrepeat = 64; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = nPic; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].clipdist = 40; + pSprite->xrepeat = 64; + pSprite->yrepeat = 64; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = nPic; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->clipdist = 40; // GrabTimeSlot(3); - sprite[nSprite].extra = -1; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nSprite | 0xD0000); - sprite[nSprite].hitag = runlist_AddRunRec(NewRun, nSprite | 0xD0000); + pSprite->extra = -1; + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nSprite | 0xD0000); + pSprite->hitag = runlist_AddRunRec(NewRun, nSprite | 0xD0000); return nSprite | 0xD0000; } @@ -1468,6 +1495,7 @@ void FuncCreatureChunk(int a, int, int nRun) { int nSprite = RunData[nRun].nVal; assert(nSprite >= 0 && nSprite < kMaxSprites); + auto pSprite = &sprite[nSprite]; int nMessage = a & 0x7F0000; @@ -1476,20 +1504,20 @@ void FuncCreatureChunk(int a, int, int nRun) Gravity(nSprite); - int nSector = sprite[nSprite].sectnum; - sprite[nSprite].pal = sector[nSector].ceilingpal; + int nSector = pSprite->sectnum; + pSprite->pal = sector[nSector].ceilingpal; - int nVal = movesprite(nSprite, sprite[nSprite].xvel << 10, sprite[nSprite].yvel << 10, sprite[nSprite].zvel, 2560, -2560, CLIPMASK1); + int nVal = movesprite(nSprite, pSprite->xvel << 10, pSprite->yvel << 10, pSprite->zvel, 2560, -2560, CLIPMASK1); - if (sprite[nSprite].z >= sector[nSector].floorz) + if (pSprite->z >= sector[nSector].floorz) { // re-grab this variable as it may have changed in movesprite(). Note the check above is against the value *before* movesprite so don't change it. - nSector = sprite[nSprite].sectnum; + nSector = pSprite->sectnum; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].z = sector[nSector].floorz; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->z = sector[nSector].floorz; } else { @@ -1500,15 +1528,15 @@ void FuncCreatureChunk(int a, int, int nRun) if (nVal & 0x20000) { - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; } else { if ((nVal & 0x3C000) == 0x10000) { - sprite[nSprite].xvel >>= 1; - sprite[nSprite].yvel >>= 1; - sprite[nSprite].zvel = -sprite[nSprite].zvel; + pSprite->xvel >>= 1; + pSprite->yvel >>= 1; + pSprite->zvel = -pSprite->zvel; return; } else if ((nVal & 0x3C000) == 0xC000) @@ -1525,22 +1553,22 @@ void FuncCreatureChunk(int a, int, int nRun) } // loc_16E0C - int nSqrt = lsqrt(((sprite[nSprite].yvel >> 10) * (sprite[nSprite].yvel >> 10) - + (sprite[nSprite].xvel >> 10) * (sprite[nSprite].xvel >> 10)) >> 8); + int nSqrt = lsqrt(((pSprite->yvel >> 10) * (pSprite->yvel >> 10) + + (pSprite->xvel >> 10) * (pSprite->xvel >> 10)) >> 8); - sprite[nSprite].xvel = bcos(nAngle) * (nSqrt >> 1); - sprite[nSprite].yvel = bsin(nAngle) * (nSqrt >> 1); + pSprite->xvel = bcos(nAngle) * (nSqrt >> 1); + pSprite->yvel = bsin(nAngle) * (nSqrt >> 1); return; } } - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); - runlist_SubRunRec(sprite[nSprite].hitag); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); + runlist_SubRunRec(pSprite->hitag); changespritestat(nSprite, 0); - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = 0; + pSprite->hitag = 0; + pSprite->lotag = 0; } short UpdateEnemy(short *nEnemy) diff --git a/source/games/exhumed/src/mummy.cpp b/source/games/exhumed/src/mummy.cpp index df919f13f..f570ed649 100644 --- a/source/games/exhumed/src/mummy.cpp +++ b/source/games/exhumed/src/mummy.cpp @@ -82,42 +82,44 @@ void InitMummy() int BuildMummy(int nSprite, int x, int y, int z, int nSector, int nAngle) { auto nMummy = MummyList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 102); + pSprite = &sprite[nSprite]; } else { - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sprite[nSprite].z; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = pSprite->z; + nAngle = pSprite->ang; changespritestat(nSprite, 102); } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].shade = -12; - sprite[nSprite].clipdist = 32; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].xrepeat = 42; - sprite[nSprite].yrepeat = 42; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].picnum = 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->shade = -12; + pSprite->clipdist = 32; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->xrepeat = 42; + pSprite->yrepeat = 42; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = nAngle; + pSprite->picnum = 1; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -129,7 +131,7 @@ int BuildMummy(int nSprite, int x, int y, int z, int nSector, int nAngle) MummyList[nMummy].nIndex = nMummy; MummyList[nMummy].nCount = 0; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nMummy | 0xE0000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nMummy | 0xE0000); MummyList[nMummy].nRun = runlist_AddRunRec(NewRun, nMummy | 0xE0000); @@ -141,6 +143,7 @@ int BuildMummy(int nSprite, int x, int y, int z, int nSector, int nAngle) void CheckMummyRevive(short nMummy) { short nSprite = MummyList[nMummy].nSprite; + auto pSprite = &sprite[nSprite]; for (unsigned i = 0; i < MummyList.Size(); i++) { @@ -155,12 +158,12 @@ void CheckMummyRevive(short nMummy) continue; } - int x = abs(sprite[nSprite2].x - sprite[nSprite].x) >> 8; - int y = abs(sprite[nSprite2].y - sprite[nSprite].y) >> 8; + int x = abs(sprite[nSprite2].x - pSprite->x) >> 8; + int y = abs(sprite[nSprite2].y - pSprite->y) >> 8; if (x <= 20 && y <= 20) { - if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - 8192, sprite[nSprite].sectnum, + if (cansee(pSprite->x, pSprite->y, pSprite->z - 8192, pSprite->sectnum, sprite[nSprite2].x, sprite[nSprite2].y, sprite[nSprite2].z - 8192, sprite[nSprite2].sectnum)) { sprite[nSprite2].cstat = 0; @@ -180,6 +183,7 @@ void FuncMummy(int a, int nDamage, int nRun) short nTarget = UpdateEnemy(&MummyList[nMummy].nTarget); short nSprite = MummyList[nMummy].nSprite; + auto pSprite = &sprite[nSprite]; short nAction = MummyList[nMummy].nAction; int nMessage = a & kMessageMask; @@ -198,7 +202,7 @@ void FuncMummy(int a, int nDamage, int nRun) int nSeq = SeqOffsets[kSeqMummy] + MummySeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, MummyList[nMummy].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, MummyList[nMummy].nFrame); short nFrame = SeqBase[nSeq] + MummyList[nMummy].nFrame; short nFrameFlag = FrameFlag[nFrame]; @@ -221,8 +225,8 @@ void FuncMummy(int a, int nDamage, int nRun) { MummyList[nMummy].nAction = 0; MummyList[nMummy].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } @@ -237,7 +241,7 @@ void FuncMummy(int a, int nDamage, int nRun) { if ((MummyList[nMummy].nIndex & 0x1F) == (totalmoves & 0x1F)) { - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; if (nTarget < 0) { @@ -250,8 +254,8 @@ void FuncMummy(int a, int nDamage, int nRun) MummyList[nMummy].nAction = 1; MummyList[nMummy].nCount = 90; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); } } } @@ -267,7 +271,7 @@ void FuncMummy(int a, int nDamage, int nRun) if ((MummyList[nMummy].nIndex & 0x1F) == (totalmoves & 0x1F)) { - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; PlotCourseToSprite(nSprite, nTarget); @@ -275,14 +279,14 @@ void FuncMummy(int a, int nDamage, int nRun) { if (RandomBit()) { - if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - GetSpriteHeight(nSprite), sprite[nSprite].sectnum, + if (cansee(pSprite->x, pSprite->y, pSprite->z - GetSpriteHeight(nSprite), pSprite->sectnum, sprite[nTarget].x, sprite[nTarget].y, sprite[nTarget].z - GetSpriteHeight(nTarget), sprite[nTarget].sectnum)) { MummyList[nMummy].nAction = 3; MummyList[nMummy].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } } @@ -292,39 +296,39 @@ void FuncMummy(int a, int nDamage, int nRun) // loc_2B5A8 if (!MummyList[nMummy].nFrame) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); } - if (sprite[nSprite].xvel || sprite[nSprite].yvel) + if (pSprite->xvel || pSprite->yvel) { - if (sprite[nSprite].xvel > 0) + if (pSprite->xvel > 0) { - sprite[nSprite].xvel -= 1024; - if (sprite[nSprite].xvel < 0) { - sprite[nSprite].xvel = 0; + pSprite->xvel -= 1024; + if (pSprite->xvel < 0) { + pSprite->xvel = 0; } } - else if (sprite[nSprite].xvel < 0) + else if (pSprite->xvel < 0) { - sprite[nSprite].xvel += 1024; - if (sprite[nSprite].xvel > 0) { - sprite[nSprite].xvel = 0; + pSprite->xvel += 1024; + if (pSprite->xvel > 0) { + pSprite->xvel = 0; } } - if (sprite[nSprite].yvel > 0) + if (pSprite->yvel > 0) { - sprite[nSprite].yvel -= 1024; - if (sprite[nSprite].yvel < 0) { - sprite[nSprite].yvel = 0; + pSprite->yvel -= 1024; + if (pSprite->yvel < 0) { + pSprite->yvel = 0; } } - else if (sprite[nSprite].yvel < 0) + else if (pSprite->yvel < 0) { - sprite[nSprite].yvel += 1024; - if (sprite[nSprite].yvel > 0) { - sprite[nSprite].yvel = 0; + pSprite->yvel += 1024; + if (pSprite->yvel > 0) { + pSprite->yvel = 0; } } } @@ -335,9 +339,9 @@ void FuncMummy(int a, int nDamage, int nRun) { case 0x8000: { - sprite[nSprite].ang = (sprite[nSprite].ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->ang = (pSprite->ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); return; } @@ -345,14 +349,14 @@ void FuncMummy(int a, int nDamage, int nRun) { if ((nMov & 0x3FFF) == nTarget) { - int nAngle = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); - if (AngleDiff(sprite[nSprite].ang, nAngle) < 64) + int nAngle = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); + if (AngleDiff(pSprite->ang, nAngle) < 64) { MummyList[nMummy].nAction = 2; MummyList[nMummy].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } return; @@ -400,7 +404,7 @@ void FuncMummy(int a, int nDamage, int nRun) SetQuake(nSprite, 100); // low 16 bits of returned var contains the sprite index, the high 16 the bullet number - int nBullet = BuildBullet(nSprite, 9, 0, 0, -15360, sprite[nSprite].ang, nTarget + 10000, 1); + int nBullet = BuildBullet(nSprite, 9, 0, 0, -15360, pSprite->ang, nTarget + 10000, 1); CheckMummyRevive(nMummy); if (nBullet > -1) @@ -437,7 +441,7 @@ void FuncMummy(int a, int nDamage, int nRun) { if (bVal) { - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; MummyList[nMummy].nAction = 0; MummyList[nMummy].nHealth = 300; @@ -452,15 +456,15 @@ void FuncMummy(int a, int nDamage, int nRun) { if (nMov & 0x20000) { - sprite[nSprite].xvel >>= 1; - sprite[nSprite].yvel >>= 1; + pSprite->xvel >>= 1; + pSprite->yvel >>= 1; } if (bVal) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].cstat = 0x101; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->cstat = 0x101; MummyList[nMummy].nAction = 0; MummyList[nMummy].nFrame = 0; @@ -503,7 +507,7 @@ void FuncMummy(int a, int nDamage, int nRun) if (MummyList[nMummy].nHealth <= 0) { MummyList[nMummy].nHealth = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; nCreaturesKilled++; DropMagic(nSprite); @@ -511,10 +515,10 @@ void FuncMummy(int a, int nDamage, int nRun) MummyList[nMummy].nFrame = 0; MummyList[nMummy].nAction = 4; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].z = sector[sprite[nSprite].sectnum].floorz; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->z = sector[pSprite->sectnum].floorz; } else { @@ -523,8 +527,8 @@ void FuncMummy(int a, int nDamage, int nRun) MummyList[nMummy].nAction = 7; MummyList[nMummy].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index 86c8840fe..ba51ab5b2 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -429,11 +429,12 @@ int BuildWallSprite(int nSector) int y2 = wall[nWall + 1].y; int nSprite = insertsprite(nSector, 401); + auto pSprite = &sprite[nSprite]; - sprite[nSprite].x = (x + x2) / 2; - sprite[nSprite].y = (y + y2) / 2; - sprite[nSprite].z = (sector[nSector].floorz + sector[nSector].ceilingz) / 2; - sprite[nSprite].cstat = 0x8000; + pSprite->x = (x + x2) / 2; + pSprite->y = (y + y2) / 2; + pSprite->z = (sector[nSector].floorz + sector[nSector].ceilingz) / 2; + pSprite->cstat = 0x8000; return nSprite; } @@ -501,14 +502,15 @@ short FindWallSprites(short nSector) if (nSprite < 0) { nSprite = insertsprite(nSector, 401); + auto pSprite = &sprite[nSprite]; - sprite[nSprite].x = (var_24 + esi) / 2; - sprite[nSprite].y = (ecx + edi) / 2; - sprite[nSprite].z = sector[nSector].floorz; - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].owner = -1; - sprite[nSprite].lotag = 0; - sprite[nSprite].hitag = 0; + pSprite->x = (var_24 + esi) / 2; + pSprite->y = (ecx + edi) / 2; + pSprite->z = sector[nSector].floorz; + pSprite->cstat = 0x8000; + pSprite->owner = -1; + pSprite->lotag = 0; + pSprite->hitag = 0; } return nSprite; @@ -643,7 +645,8 @@ int CheckSectorSprites(short nSector, int nVal) SectIterator it(nSector); while ((nSprite = it.NextIndex()) >= 0) { - if ((sprite[nSprite].cstat & 0x101) && (nZDiff < GetSpriteHeight(nSprite))) + auto pSprite = &sprite[nSprite]; + if ((pSprite->cstat & 0x101) && (nZDiff < GetSpriteHeight(nSprite))) { if (nVal != 1) { return 1; @@ -653,13 +656,13 @@ int CheckSectorSprites(short nSector, int nVal) runlist_DamageEnemy(nSprite, -1, 5); - if (sprite[nSprite].statnum == 100 && PlayerList[GetPlayerFromSprite(nSprite)].nHealth <= 0) + if (pSprite->statnum == 100 && PlayerList[GetPlayerFromSprite(nSprite)].nHealth <= 0) { PlayFXAtXYZ(StaticSound[kSoundJonFDie], - sprite[nSprite].x, - sprite[nSprite].y, - sprite[nSprite].z, - sprite[nSprite].sectnum | 0x4000); + pSprite->x, + pSprite->y, + pSprite->z, + pSprite->sectnum | 0x4000); } } } @@ -691,10 +694,11 @@ void MoveSectorSprites(int nSector, int z) SectIterator it(nSector); while ((nSprite = it.NextIndex()) >= 0) { - int z = sprite[nSprite].z; - if ((sprite[nSprite].statnum != 200 && z >= minz && z <= maxz) || sprite[nSprite].statnum >= 900) + auto pSprite = &sprite[nSprite]; + int z = pSprite->z; + if ((pSprite->statnum != 200 && z >= minz && z <= maxz) || pSprite->statnum >= 900) { - sprite[nSprite].z = newz; + pSprite->z = newz; } } } @@ -1111,13 +1115,14 @@ int BuildSlide(int nChannel, int nStartWall, int nWall1, int ecx, int nWall2, in int nSprite = insertsprite(nSector, 899); + auto pSprite = &sprite[nSprite]; SlideData[nSlide].nSprite = nSprite; - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].x = wall[nStartWall].x; - sprite[nSprite].y = wall[nStartWall].y; - sprite[nSprite].z = sector[nSector].floorz; - sprite[nSprite].backuppos(); + pSprite->cstat = 0x8000; + pSprite->x = wall[nStartWall].x; + pSprite->y = wall[nStartWall].y; + pSprite->z = sector[nSector].floorz; + pSprite->backuppos(); SlideData[nSlide].field_8a = 0; @@ -1296,6 +1301,7 @@ void FuncSlide(int a, int, int nRun) int BuildTrap(int nSprite, int edx, int ebx, int ecx) { + auto pSprite = &sprite[nSprite]; int var_14 = edx; int var_18 = ebx; int var_10 = ecx; @@ -1304,15 +1310,15 @@ int BuildTrap(int nSprite, int edx, int ebx, int ecx) changespritestat(nSprite, 0); - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].extra = -1; + pSprite->cstat = 0x8000; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->extra = -1; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].hitag = runlist_AddRunRec(NewRun, nTrap | 0x1F0000); - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nTrap | 0x1F0000); + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->hitag = runlist_AddRunRec(NewRun, nTrap | 0x1F0000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nTrap | 0x1F0000); // GrabTimeSlot(3); @@ -1335,7 +1341,7 @@ int BuildTrap(int nSprite, int edx, int ebx, int ecx) sTrap[nTrap].field_6 = -1; sTrap[nTrap].field_8 = -1; - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; short nWall = sector[nSector].wallptr; int i = 0; @@ -1364,7 +1370,7 @@ int BuildTrap(int nSprite, int edx, int ebx, int ecx) ecx++; nWall++; } - sprite[nSprite].backuppos(); + pSprite->backuppos(); } @@ -1372,6 +1378,7 @@ void FuncTrap(int a, int, int nRun) { short nTrap = RunData[nRun].nVal; short nSprite = sTrap[nTrap].nSprite; + auto pSprite = &sprite[nSprite]; int nMessage = a & 0x7F0000; @@ -1430,7 +1437,7 @@ void FuncTrap(int a, int, int nRun) return; } - int nBullet = BuildBullet(nSprite, nType, 0, 0, 0, sprite[nSprite].ang, 0, 1); + int nBullet = BuildBullet(nSprite, nType, 0, 0, 0, pSprite->ang, 0, 1); if (nBullet > -1) { short nBulletSprite = nBullet & 0xFFFF; // isolate the sprite index (disregard top 16 bits) @@ -1490,7 +1497,8 @@ int BuildFireBall(int nSprite, int a, int b) int BuildSpark(int nSprite, int nVal) { - int var_14 = insertsprite(sprite[nSprite].sectnum, 0); + auto pSprite = &sprite[nSprite]; + int var_14 = insertsprite(pSprite->sectnum, 0); if (var_14 < 0) { return -1; @@ -1499,8 +1507,8 @@ int BuildSpark(int nSprite, int nVal) assert(var_14 < kMaxSprites); - spr->x = sprite[nSprite].x; - spr->y = sprite[nSprite].y; + spr->x = pSprite->x; + spr->y = pSprite->y; spr->cstat = 0; spr->shade = -127; spr->pal = 1; @@ -1521,13 +1529,13 @@ int BuildSpark(int nSprite, int nVal) } else { - spr->xrepeat = sprite[nSprite].xrepeat + 15; - spr->yrepeat = sprite[nSprite].xrepeat + 15; + spr->xrepeat = pSprite->xrepeat + 15; + spr->yrepeat = pSprite->xrepeat + 15; } } else { - int nAngle = (sprite[nSprite].ang + 256) - RandomSize(9); + int nAngle = (pSprite->ang + 256) - RandomSize(9); if (nVal) { @@ -1544,7 +1552,7 @@ int BuildSpark(int nSprite, int nVal) spr->picnum = kTile985 + nVal; } - spr->z = sprite[nSprite].z; + spr->z = pSprite->z; spr->lotag = runlist_HeadRun() + 1; spr->clipdist = 1; spr->hitag = 0; @@ -1562,6 +1570,8 @@ int BuildSpark(int nSprite, int nVal) void FuncSpark(int a, int, int nRun) { int nSprite = RunData[nRun].nVal; + auto pSprite = &sprite[nSprite]; + assert(nSprite >= 0 && nSprite < kMaxSprites); int nMessage = a & 0x7F0000; @@ -1570,46 +1580,46 @@ void FuncSpark(int a, int, int nRun) return; } - sprite[nSprite].shade += 3; - sprite[nSprite].xrepeat -= 2; + pSprite->shade += 3; + pSprite->xrepeat -= 2; - if (sprite[nSprite].xrepeat >= 4 && sprite[nSprite].shade <= 100) + if (pSprite->xrepeat >= 4 && pSprite->shade <= 100) { - sprite[nSprite].yrepeat -= 2; + pSprite->yrepeat -= 2; // calling BuildSpark() with 2nd parameter as '1' will set kTile986 - if (sprite[nSprite].picnum == kTile986 && (sprite[nSprite].xrepeat & 2)) + if (pSprite->picnum == kTile986 && (pSprite->xrepeat & 2)) { BuildSpark(nSprite, 2); } - if (sprite[nSprite].picnum >= kTile3000) { + if (pSprite->picnum >= kTile3000) { return; } - sprite[nSprite].zvel += 128; + pSprite->zvel += 128; - int nMov = movesprite(nSprite, sprite[nSprite].xvel << 12, sprite[nSprite].yvel << 12, sprite[nSprite].zvel, 2560, -2560, CLIPMASK1); + int nMov = movesprite(nSprite, pSprite->xvel << 12, pSprite->yvel << 12, pSprite->zvel, 2560, -2560, CLIPMASK1); if (!nMov) { return; } - if (sprite[nSprite].zvel <= 0) { + if (pSprite->zvel <= 0) { return; } } - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; - if (sprite[nSprite].picnum > kTile3000) { + if (pSprite->picnum > kTile3000) { nSmokeSparks--; } - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); - runlist_SubRunRec(sprite[nSprite].hitag); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); + runlist_SubRunRec(pSprite->hitag); mydeletesprite(nSprite); } @@ -1796,7 +1806,9 @@ void KillCreatures() void ExplodeEnergyBlock(int nSprite) { - short nSector = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + + short nSector = pSprite->sectnum; short startwall = sector[nSector].wallptr; short nWalls = sector[nSector].wallnum; @@ -1826,24 +1838,24 @@ void ExplodeEnergyBlock(int nSprite) sector[nSector].floorshade = 50; sector[nSector].extra = -1; - sector[nSector].floorz = sprite[nSprite].z; + sector[nSector].floorz = pSprite->z; - sprite[nSprite].z = (sprite[nSprite].z + sector[nSector].floorz) / 2; + pSprite->z = (pSprite->z + sector[nSector].floorz) / 2; BuildSpark(nSprite, 3); - sprite[nSprite].cstat = 0; - sprite[nSprite].xrepeat = 100; + pSprite->cstat = 0; + pSprite->xrepeat = 100; PlayFX2(StaticSound[kSound78], nSprite); - sprite[nSprite].xrepeat = 0; + pSprite->xrepeat = 0; nEnergyTowers--; for (i = 0; i < 20; i++) { - sprite[nSprite].ang = RandomSize(11); + pSprite->ang = RandomSize(11); BuildSpark(nSprite, 1); // shoot out blue orbs } @@ -1949,11 +1961,12 @@ void FuncEnergyBlock(int a, int nDamage, int nRun) spr->xrepeat -= nDamage; int nSprite2 = insertsprite(lasthitsect, 0); + auto pSprite2 = &sprite[nSprite2]; - sprite[nSprite2].ang = a & 0xFFFF; - sprite[nSprite2].x = lasthitx; - sprite[nSprite2].y = lasthity; - sprite[nSprite2].z = lasthitz; + pSprite2->ang = a & 0xFFFF; + pSprite2->x = lasthitx; + pSprite2->y = lasthity; + pSprite2->z = lasthitz; BuildSpark(nSprite2, 0); // shoot out blue orb when damaged mydeletesprite(nSprite2); @@ -2011,12 +2024,13 @@ int BuildObject(int const nSprite, int nOjectType, int nHitag) } int nSprite2 = insertsprite(spr->sectnum, 0); + auto pSprite2 = &sprite[nSprite2]; ObjectList[nObject].field_10 = nSprite2; - sprite[nSprite2].cstat = 0x8000; - sprite[nSprite2].x = spr->x; - sprite[nSprite2].y = spr->y; - sprite[nSprite2].z = spr->z; + pSprite2->cstat = 0x8000; + pSprite2->x = spr->x; + pSprite2->y = spr->y; + pSprite2->z = spr->z; } else { @@ -2038,13 +2052,14 @@ int BuildObject(int const nSprite, int nOjectType, int nHitag) // in-game destructable wall mounted screen void ExplodeScreen(short nSprite) { - sprite[nSprite].z -= GetSpriteHeight(nSprite) / 2; + auto pSprite = &sprite[nSprite]; + pSprite->z -= GetSpriteHeight(nSprite) / 2; for (int i = 0; i < 30; i++) { BuildSpark(nSprite, 0); // shoot out blue orbs } - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; PlayFX2(StaticSound[kSound78], nSprite); } @@ -2053,7 +2068,8 @@ void FuncObject(int a, int b, int nRun) short nObject = RunData[nRun].nVal; short nSprite = ObjectList[nObject].nSprite; - short nStat = sprite[nSprite].statnum; + auto pSprite = &sprite[nSprite]; + short nStat = pSprite->statnum; short bx = ObjectList[nObject].field_8; int nMessage = a & 0x7F0000; @@ -2109,7 +2125,7 @@ void FuncObject(int a, int b, int nRun) case 0xA0000: { - if (ObjectList[nObject].nHealth > 0 && sprite[nSprite].cstat & 0x101 + if (ObjectList[nObject].nHealth > 0 && pSprite->cstat & 0x101 && (nStat != kStatExplodeTarget || sprite[nRadialSpr].statnum == 201 || (nRadialBullet != 3 && nRadialBullet > -1) @@ -2120,28 +2136,28 @@ void FuncObject(int a, int b, int nRun) return; } - if (sprite[nSprite].statnum != kStatAnubisDrum) { + if (pSprite->statnum != kStatAnubisDrum) { ObjectList[nObject].nHealth -= nDamage; } - if (sprite[nSprite].statnum == kStatExplodeTarget) + if (pSprite->statnum == kStatExplodeTarget) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; } - else if (sprite[nSprite].statnum != kStatAnubisDrum) + else if (pSprite->statnum != kStatAnubisDrum) { - sprite[nSprite].xvel >>= 1; - sprite[nSprite].yvel >>= 1; - sprite[nSprite].zvel >>= 1; + pSprite->xvel >>= 1; + pSprite->yvel >>= 1; + pSprite->zvel >>= 1; } if (ObjectList[nObject].nHealth > 0) { return; } - if (sprite[nSprite].statnum == kStatExplodeTarget) + if (pSprite->statnum == kStatExplodeTarget) { ObjectList[nObject].nHealth = -1; short ax = ObjectList[nObject].field_10; @@ -2152,7 +2168,7 @@ void FuncObject(int a, int b, int nRun) ObjectList[ax].nHealth = -1; } - else if (sprite[nSprite].statnum == kStatDestructibleSprite) + else if (pSprite->statnum == kStatDestructibleSprite) { ObjectList[nObject].nHealth = 0; @@ -2169,7 +2185,7 @@ void FuncObject(int a, int b, int nRun) case 0x20000: { - if (nStat == 97 || (!(sprite[nSprite].cstat & 0x101))) { + if (nStat == 97 || (!(pSprite->cstat & 0x101))) { return; } @@ -2185,7 +2201,7 @@ void FuncObject(int a, int b, int nRun) ObjectList[nObject].field_0 = 0; } - sprite[nSprite].picnum = seq_GetSeqPicnum2(bx, ObjectList[nObject].field_0); + pSprite->picnum = seq_GetSeqPicnum2(bx, ObjectList[nObject].field_0); } if (ObjectList[nObject].nHealth >= 0) { @@ -2199,22 +2215,22 @@ void FuncObject(int a, int b, int nRun) FUNCOBJECT_GOTO: if (nStat != kStatExplodeTarget) { - int nMov = movesprite(nSprite, sprite[nSprite].xvel << 6, sprite[nSprite].yvel << 6, sprite[nSprite].zvel, 0, 0, CLIPMASK0); + int nMov = movesprite(nSprite, pSprite->xvel << 6, pSprite->yvel << 6, pSprite->zvel, 0, 0, CLIPMASK0); - if (sprite[nSprite].statnum == kStatExplodeTrigger) { - sprite[nSprite].pal = 1; + if (pSprite->statnum == kStatExplodeTrigger) { + pSprite->pal = 1; } if (nMov & 0x20000) { - sprite[nSprite].xvel -= sprite[nSprite].xvel >> 3; - sprite[nSprite].yvel -= sprite[nSprite].yvel >> 3; + pSprite->xvel -= pSprite->xvel >> 3; + pSprite->yvel -= pSprite->yvel >> 3; } if (((nMov & 0xC000) > 0x8000) && ((nMov & 0xC000) == 0xC000)) { - sprite[nSprite].yvel = 0; - sprite[nSprite].xvel = 0; + pSprite->yvel = 0; + pSprite->xvel = 0; } } @@ -2225,7 +2241,7 @@ FUNCOBJECT_GOTO: int var_18; // red branch - if ((nStat == kStatExplodeTarget) || (sprite[nSprite].z < sector[sprite[nSprite].sectnum].floorz)) + if ((nStat == kStatExplodeTarget) || (pSprite->z < sector[pSprite->sectnum].floorz)) { var_18 = 36; } @@ -2234,8 +2250,8 @@ FUNCOBJECT_GOTO: var_18 = 34; } - AddFlash(sprite[nSprite].sectnum, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, 128); - BuildAnim(-1, var_18, 0, sprite[nSprite].x, sprite[nSprite].y, sector[sprite[nSprite].sectnum].floorz, sprite[nSprite].sectnum, 240, 4); + AddFlash(pSprite->sectnum, pSprite->x, pSprite->y, pSprite->z, 128); + BuildAnim(-1, var_18, 0, pSprite->x, pSprite->y, sector[pSprite->sectnum].floorz, pSprite->sectnum, 240, 4); // int edi = nSprite | 0x4000; @@ -2256,7 +2272,7 @@ FUNCOBJECT_GOTO: if (!(currentLevel->gameflags & LEVEL_EX_MULTI) || nStat != kStatExplodeTrigger) { - runlist_SubRunRec(sprite[nSprite].owner); + runlist_SubRunRec(pSprite->owner); runlist_SubRunRec(ObjectList[nObject].field_4); mydeletesprite(nSprite); @@ -2267,9 +2283,9 @@ FUNCOBJECT_GOTO: StartRegenerate(nSprite); ObjectList[nObject].nHealth = 120; - sprite[nSprite].x = sprite[ObjectList[nObject].field_10].x; - sprite[nSprite].y = sprite[ObjectList[nObject].field_10].y; - sprite[nSprite].z = sprite[ObjectList[nObject].field_10].z; + pSprite->x = sprite[ObjectList[nObject].field_10].x; + pSprite->y = sprite[ObjectList[nObject].field_10].y; + pSprite->z = sprite[ObjectList[nObject].field_10].z; mychangespritesect(nSprite, sprite[ObjectList[nObject].field_10].sectnum); return; @@ -2281,10 +2297,11 @@ FUNCOBJECT_GOTO: void BuildDrip(int nSprite) { + auto pSprite = &sprite[nSprite]; auto nDrips = sDrip.Reserve(1); sDrip[nDrips].nSprite = nSprite; sDrip[nDrips].field_2 = RandomSize(8) + 90; - sprite[nSprite].cstat = 0x8000u; + pSprite->cstat = 0x8000u; } void DoDrips() @@ -2295,10 +2312,11 @@ void DoDrips() if (sDrip[i].field_2 <= 0) { short nSprite = sDrip[i].nSprite; + auto pSprite = &sprite[nSprite]; short nSeqOffset = SeqOffsets[kSeqDrips]; - if (!(SectFlag[sprite[nSprite].sectnum] & kSectLava)) { + if (!(SectFlag[pSprite->sectnum] & kSectLava)) { nSeqOffset++; } @@ -2413,10 +2431,11 @@ int FindTrail(int nVal) // ok ? void ProcessTrailSprite(int nSprite, int nLotag, int nHitag) { + auto pSprite = &sprite[nSprite]; auto nPoint = sTrailPoint.Reserve(1); - sTrailPoint[nPoint].x = sprite[nSprite].x; - sTrailPoint[nPoint].y = sprite[nSprite].y; + sTrailPoint[nPoint].x = pSprite->x; + sTrailPoint[nPoint].y = pSprite->y; int nTrail = FindTrail(nHitag); @@ -2752,7 +2771,8 @@ void PostProcess() { wall[nWall].pal = 1; int nSprite = insertsprite(i, 407); - sprite[nSprite].cstat = 0x8000; + auto pSprite = &sprite[nSprite]; + pSprite->cstat = 0x8000; } nWall++; diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index b35b7fe7e..db50ba60c 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -244,7 +244,8 @@ void InitPlayerInventory(short nPlayer) short GetPlayerFromSprite(short nSprite) { - return RunData[sprite[nSprite].owner].nVal; + auto pSprite = &sprite[nSprite]; + return RunData[pSprite->owner].nVal; } void RestartPlayer(short nPlayer) @@ -478,9 +479,10 @@ void StartDeathSeq(int nPlayer, int nVal) FreeRa(nPlayer); short nSprite = PlayerList[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; PlayerList[nPlayer].nHealth = 0; - short nLotag = sector[sprite[nSprite].sectnum].lotag; + short nLotag = sector[pSprite->sectnum].lotag; if (nLotag > 0) { runlist_SignalRun(nLotag - 1, nPlayer | 0x70000); @@ -498,7 +500,7 @@ void StartDeathSeq(int nPlayer, int nVal) if (nWeapon > kWeaponSword && nWeapon <= kWeaponRing) { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; if (SectBelow[nSector] > -1) { nSector = SectBelow[nSector]; } @@ -506,8 +508,8 @@ void StartDeathSeq(int nPlayer, int nVal) int nGunSprite = GrabBodyGunSprite(); changespritesect(nGunSprite, nSector); - sprite[nGunSprite].x = sprite[nSprite].x; - sprite[nGunSprite].y = sprite[nSprite].y; + sprite[nGunSprite].x = pSprite->x; + sprite[nGunSprite].y = pSprite->y; sprite[nGunSprite].z = sector[nSector].floorz - 512; changespritestat(nGunSprite, nGunLotag[nWeapon] + 900); @@ -526,11 +528,11 @@ void StartDeathSeq(int nPlayer, int nVal) PlayerList[nPlayer].nInvisible = 0; dVertPan[nPlayer] = 15; - sprite[nSprite].cstat &= 0x7FFF; + pSprite->cstat &= 0x7FFF; SetNewWeaponImmediate(nPlayer, -2); - if (SectDamage[sprite[nSprite].sectnum] <= 0) + if (SectDamage[pSprite->sectnum] <= 0) { nDeathType[nPlayer] = nVal; } @@ -541,7 +543,7 @@ void StartDeathSeq(int nPlayer, int nVal) nVal *= 2; - if (nVal || !(SectFlag[sprite[nSprite].sectnum] & kSectUnderwater)) + if (nVal || !(SectFlag[pSprite->sectnum] & kSectUnderwater)) { PlayerList[nPlayer].nAction = nVal + 17; } @@ -551,7 +553,7 @@ void StartDeathSeq(int nPlayer, int nVal) PlayerList[nPlayer].field_2 = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; if (nTotalPlayers == 1) { @@ -599,9 +601,10 @@ int AddAmmo(int nPlayer, int nWeapon, int nAmmoAmount) void SetPlayerMummified(int nPlayer, int bIsMummified) { int nSprite = PlayerList[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; - sprite[nSprite].yvel = 0; - sprite[nSprite].xvel = 0; + pSprite->yvel = 0; + pSprite->xvel = 0; PlayerList[nPlayer].bIsMummified = bIsMummified; @@ -659,6 +662,7 @@ void FuncPlayer(int a, int nDamage, int nRun) assert(nPlayer >= 0 && nPlayer < kMaxPlayers); short nPlayerSprite = PlayerList[nPlayer].nSprite; + auto pPlayerSprite = &sprite[nPlayerSprite]; short nDopple = nDoppleSprite[nPlayer]; @@ -733,7 +737,7 @@ void FuncPlayer(int a, int nDamage, int nRun) return; } - if (SectFlag[sprite[nPlayerSprite].sectnum] & kSectUnderwater) + if (SectFlag[pPlayerSprite->sectnum] & kSectUnderwater) { if (nAction != 12) { @@ -805,8 +809,8 @@ void FuncPlayer(int a, int nDamage, int nRun) case 0x20000: { - sprite[nPlayerSprite].xvel = sPlayerInput[nPlayer].xVel >> 14; - sprite[nPlayerSprite].yvel = sPlayerInput[nPlayer].yVel >> 14; + pPlayerSprite->xvel = sPlayerInput[nPlayer].xVel >> 14; + pPlayerSprite->yvel = sPlayerInput[nPlayer].yVel >> 14; if (sPlayerInput[nPlayer].nItem > -1) { @@ -816,8 +820,8 @@ void FuncPlayer(int a, int nDamage, int nRun) int var_EC = PlayerList[nPlayer].field_2; - sprite[nPlayerSprite].picnum = seq_GetSeqPicnum(PlayerList[nPlayer].nSeq, PlayerSeq[nHeightTemplate[nAction]].a, var_EC); - sprite[nDopple].picnum = sprite[nPlayerSprite].picnum; + pPlayerSprite->picnum = seq_GetSeqPicnum(PlayerList[nPlayer].nSeq, PlayerSeq[nHeightTemplate[nAction]].a, var_EC); + sprite[nDopple].picnum = pPlayerSprite->picnum; if (PlayerList[nPlayer].nTorch > 0) { @@ -831,10 +835,10 @@ void FuncPlayer(int a, int nDamage, int nRun) if (nPlayer != nLocalPlayer) { nFlashDepth = 5; - AddFlash(sprite[nPlayerSprite].sectnum, - sprite[nPlayerSprite].x, - sprite[nPlayerSprite].y, - sprite[nPlayerSprite].z, 0); + AddFlash(pPlayerSprite->sectnum, + pPlayerSprite->x, + pPlayerSprite->y, + pPlayerSprite->z, 0); } } } @@ -852,7 +856,7 @@ void FuncPlayer(int a, int nDamage, int nRun) PlayerList[nPlayer].nInvisible--; if (PlayerList[nPlayer].nInvisible == 0) { - sprite[nPlayerSprite].cstat &= 0x7FFF; // set visible + pPlayerSprite->cstat &= 0x7FFF; // set visible short nFloorSprite = nPlayerFloorSprite[nPlayerSprite]; if (nFloorSprite > -1) { @@ -892,29 +896,29 @@ void FuncPlayer(int a, int nDamage, int nRun) UpdatePlayerSpriteAngle(pPlayer); } - // sprite[nPlayerSprite].zvel is modified within Gravity() - short zVel = sprite[nPlayerSprite].zvel; + // pPlayerSprite->zvel is modified within Gravity() + short zVel = pPlayerSprite->zvel; Gravity(nPlayerSprite); - if (sprite[nPlayerSprite].zvel >= 6500 && zVel < 6500) + if (pPlayerSprite->zvel >= 6500 && zVel < 6500) { D3PlayFX(StaticSound[kSound17], nPlayerSprite); } // loc_1A4E6 - short nSector = sprite[nPlayerSprite].sectnum; + short nSector = pPlayerSprite->sectnum; short nSectFlag = SectFlag[nPlayerViewSect[nPlayer]]; - int playerX = sprite[nPlayerSprite].x; - int playerY = sprite[nPlayerSprite].y; + int playerX = pPlayerSprite->x; + int playerY = pPlayerSprite->y; int x = (sPlayerInput[nPlayer].xVel * 4) >> 2; int y = (sPlayerInput[nPlayer].yVel * 4) >> 2; - int z = (sprite[nPlayerSprite].zvel * 4) >> 2; + int z = (pPlayerSprite->zvel * 4) >> 2; - if (sprite[nPlayerSprite].zvel > 8192) - sprite[nPlayerSprite].zvel = 8192; + if (pPlayerSprite->zvel > 8192) + pPlayerSprite->zvel = 8192; if (PlayerList[nPlayer].bIsMummified) { @@ -922,15 +926,15 @@ void FuncPlayer(int a, int nDamage, int nRun) y /= 2; } - int spr_x = sprite[nPlayerSprite].x; - int spr_y = sprite[nPlayerSprite].y; - int spr_z = sprite[nPlayerSprite].z; - int spr_sectnum = sprite[nPlayerSprite].sectnum; + int spr_x = pPlayerSprite->x; + int spr_y = pPlayerSprite->y; + int spr_z = pPlayerSprite->z; + int spr_sectnum = pPlayerSprite->sectnum; // TODO // nSectFlag & kSectUnderwater; - zVel = sprite[nPlayerSprite].zvel; + zVel = pPlayerSprite->zvel; int nMove = 0; // TEMP @@ -938,41 +942,41 @@ void FuncPlayer(int a, int nDamage, int nRun) { nMove = 0; - sprite[nPlayerSprite].x += (x >> 14); - sprite[nPlayerSprite].y += (y >> 14); + pPlayerSprite->x += (x >> 14); + pPlayerSprite->y += (y >> 14); - vec3_t pos = { sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].z }; + vec3_t pos = { pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->z }; setsprite(nPlayerSprite, &pos); - sprite[nPlayerSprite].z = sector[sprite[nPlayerSprite].sectnum].floorz; + pPlayerSprite->z = sector[pPlayerSprite->sectnum].floorz; } else { nMove = movesprite(nPlayerSprite, x, y, z, 5120, -5120, CLIPMASK0); - short var_54 = sprite[nPlayerSprite].sectnum; + short var_54 = pPlayerSprite->sectnum; - pushmove_old(&sprite[nPlayerSprite].x, &sprite[nPlayerSprite].y, &sprite[nPlayerSprite].z, &var_54, sprite[nPlayerSprite].clipdist << 2, 5120, -5120, CLIPMASK0); - if (var_54 != sprite[nPlayerSprite].sectnum) { + pushmove_old(&pPlayerSprite->x, &pPlayerSprite->y, &pPlayerSprite->z, &var_54, pPlayerSprite->clipdist << 2, 5120, -5120, CLIPMASK0); + if (var_54 != pPlayerSprite->sectnum) { mychangespritesect(nPlayerSprite, var_54); } } // loc_1A6E4 - if (inside(sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].sectnum) != 1) + if (inside(pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->sectnum) != 1) { mychangespritesect(nPlayerSprite, spr_sectnum); - sprite[nPlayerSprite].x = spr_x; - sprite[nPlayerSprite].y = spr_y; + pPlayerSprite->x = spr_x; + pPlayerSprite->y = spr_y; - if (zVel < sprite[nPlayerSprite].zvel) { - sprite[nPlayerSprite].zvel = zVel; + if (zVel < pPlayerSprite->zvel) { + pPlayerSprite->zvel = zVel; } } // int _bTouchFloor = bTouchFloor; - short bUnderwater = SectFlag[sprite[nPlayerSprite].sectnum] & kSectUnderwater; + short bUnderwater = SectFlag[pPlayerSprite->sectnum] & kSectUnderwater; if (bUnderwater) { @@ -981,22 +985,22 @@ void FuncPlayer(int a, int nDamage, int nRun) } // Trigger Ramses? - if ((SectFlag[sprite[nPlayerSprite].sectnum] & 0x8000) && bTouchFloor) + if ((SectFlag[pPlayerSprite->sectnum] & 0x8000) && bTouchFloor) { if (nTotalPlayers <= 1) { auto ang = GetAngleToSprite(nPlayerSprite, nSpiritSprite) & kAngleMask; PlayerList[nPlayer].angle.settarget(ang, true); - sprite[nPlayerSprite].ang = ang; + pPlayerSprite->ang = ang; PlayerList[nPlayer].horizon.settarget(0, true); lPlayerXVel = 0; lPlayerYVel = 0; - sprite[nPlayerSprite].xvel = 0; - sprite[nPlayerSprite].yvel = 0; - sprite[nPlayerSprite].zvel = 0; + pPlayerSprite->xvel = 0; + pPlayerSprite->yvel = 0; + pPlayerSprite->zvel = 0; if (nFreeze < 1) { @@ -1040,18 +1044,18 @@ void FuncPlayer(int a, int nDamage, int nRun) if (zVel >= 6500) { - sprite[nPlayerSprite].xvel >>= 2; - sprite[nPlayerSprite].yvel >>= 2; + pPlayerSprite->xvel >>= 2; + pPlayerSprite->yvel >>= 2; runlist_DamageEnemy(nPlayerSprite, -1, ((zVel - 6500) >> 7) + 10); if (PlayerList[nPlayer].nHealth <= 0) { - sprite[nPlayerSprite].xvel = 0; - sprite[nPlayerSprite].yvel = 0; + pPlayerSprite->xvel = 0; + pPlayerSprite->yvel = 0; StopSpriteSound(nPlayerSprite); - PlayFXAtXYZ(StaticSound[kSoundJonFDie], sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].z, sprite[nPlayerSprite].sectnum, CHANF_NONE, 1); // CHECKME + PlayFXAtXYZ(StaticSound[kSoundJonFDie], pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->z, pPlayerSprite->sectnum, CHANF_NONE, 1); // CHECKME } else { @@ -1078,7 +1082,7 @@ void FuncPlayer(int a, int nDamage, int nRun) if ((sector[sectnum].hitag == 45) && bTouchFloor) { int nNormal = GetWallNormal(nMove & 0x3FFF); - int nDiff = AngleDiff(nNormal, (sprite[nPlayerSprite].ang + 1024) & kAngleMask); + int nDiff = AngleDiff(nNormal, (pPlayerSprite->ang + 1024) & kAngleMask); if (nDiff < 0) { nDiff = -nDiff; @@ -1105,9 +1109,9 @@ void FuncPlayer(int a, int nDamage, int nRun) } else { - sprite[nPlayerSprite].x = spr_x; - sprite[nPlayerSprite].y = spr_y; - sprite[nPlayerSprite].z = spr_z; + pPlayerSprite->x = spr_x; + pPlayerSprite->y = spr_y; + pPlayerSprite->z = spr_z; mychangespritesect(nPlayerSprite, spr_sectnum); } @@ -1134,11 +1138,11 @@ void FuncPlayer(int a, int nDamage, int nRun) sectdone: if (!PlayerList[nPlayer].bPlayerPan && !PlayerList[nPlayer].bLockPan) { - PlayerList[nPlayer].nDestVertPan = q16horiz(clamp((spr_z - sprite[nPlayerSprite].z) << 9, gi->playerHorizMin(), gi->playerHorizMax())); + PlayerList[nPlayer].nDestVertPan = q16horiz(clamp((spr_z - pPlayerSprite->z) << 9, gi->playerHorizMin(), gi->playerHorizMax())); } - playerX -= sprite[nPlayerSprite].x; - playerY -= sprite[nPlayerSprite].y; + playerX -= pPlayerSprite->x; + playerY -= pPlayerSprite->y; uint32_t sqrtNum = playerX * playerX + playerY * playerY; @@ -1151,9 +1155,9 @@ sectdone: ototalvel[nPlayer] = totalvel[nPlayer]; totalvel[nPlayer] = ksqrt(sqrtNum); - int nViewSect = sprite[nPlayerSprite].sectnum; + int nViewSect = pPlayerSprite->sectnum; - int EyeZ = eyelevel[nPlayer] + sprite[nPlayerSprite].z + nQuake[nPlayer]; + int EyeZ = eyelevel[nPlayer] + pPlayerSprite->z + nQuake[nPlayer]; while (1) { @@ -1171,34 +1175,34 @@ sectdone: // Do underwater sector check if (bUnderwater) { - if (nViewSect != sprite[nPlayerSprite].sectnum) + if (nViewSect != pPlayerSprite->sectnum) { if ((nMove & 0xC000) == 0x8000) { - int var_C4 = sprite[nPlayerSprite].x; - int var_D4 = sprite[nPlayerSprite].y; - int var_C8 = sprite[nPlayerSprite].z; + int var_C4 = pPlayerSprite->x; + int var_D4 = pPlayerSprite->y; + int var_C8 = pPlayerSprite->z; mychangespritesect(nPlayerSprite, nViewSect); - sprite[nPlayerSprite].x = spr_x; - sprite[nPlayerSprite].y = spr_y; + pPlayerSprite->x = spr_x; + pPlayerSprite->y = spr_y; int var_FC = sector[nViewSect].floorz + (-5120); - sprite[nPlayerSprite].z = var_FC; + pPlayerSprite->z = var_FC; if ((movesprite(nPlayerSprite, x, y, 0, 5120, 0, CLIPMASK0) & 0xC000) == 0x8000) { - mychangespritesect(nPlayerSprite, sprite[nPlayerSprite].sectnum); + mychangespritesect(nPlayerSprite, pPlayerSprite->sectnum); - sprite[nPlayerSprite].x = var_C4; - sprite[nPlayerSprite].y = var_D4; - sprite[nPlayerSprite].z = var_C8; + pPlayerSprite->x = var_C4; + pPlayerSprite->y = var_D4; + pPlayerSprite->z = var_C8; } else { - sprite[nPlayerSprite].z = var_FC - 256; + pPlayerSprite->z = var_FC - 256; D3PlayFX(StaticSound[kSound42], nPlayerSprite); } } @@ -1208,8 +1212,8 @@ sectdone: // loc_1ADAF nPlayerViewSect[nPlayer] = nViewSect; - nPlayerDX[nPlayer] = sprite[nPlayerSprite].x - spr_x; - nPlayerDY[nPlayer] = sprite[nPlayerSprite].y - spr_y; + nPlayerDX[nPlayer] = pPlayerSprite->x - spr_x; + nPlayerDY[nPlayer] = pPlayerSprite->y - spr_y; int var_5C = SectFlag[nViewSect] & kSectUnderwater; @@ -1290,9 +1294,9 @@ sectdone: } else { - int nTmpSectNum = sprite[nPlayerSprite].sectnum; + int nTmpSectNum = pPlayerSprite->sectnum; - if (totalvel[nPlayer] > 25 && sprite[nPlayerSprite].z > sector[nTmpSectNum].floorz) + if (totalvel[nPlayer] > 25 && pPlayerSprite->z > sector[nTmpSectNum].floorz) { if (SectDepth[nTmpSectNum] && !SectSpeed[nTmpSectNum] && !SectDamage[nTmpSectNum]) { @@ -1328,15 +1332,15 @@ sectdone: { int nFloorSprite = nPlayerFloorSprite[nPlayer]; - sprite[nFloorSprite].x = sprite[nPlayerSprite].x; - sprite[nFloorSprite].y = sprite[nPlayerSprite].y; + sprite[nFloorSprite].x = pPlayerSprite->x; + sprite[nFloorSprite].y = pPlayerSprite->y; - if (sprite[nFloorSprite].sectnum != sprite[nPlayerSprite].sectnum) + if (sprite[nFloorSprite].sectnum != pPlayerSprite->sectnum) { - mychangespritesect(nFloorSprite, sprite[nPlayerSprite].sectnum); + mychangespritesect(nFloorSprite, pPlayerSprite->sectnum); } - sprite[nFloorSprite].z = sector[sprite[nPlayerSprite].sectnum].floorz; + sprite[nFloorSprite].z = sector[pPlayerSprite->sectnum].floorz; } int var_30 = 0; @@ -1358,19 +1362,20 @@ sectdone: short nValB; // neartag finds the nearest sector, wall, and sprite which has its hitag and/or lotag set to a value. - neartag(sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].z, sprite[nPlayerSprite].sectnum, sprite[nPlayerSprite].ang, + neartag(pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->z, pPlayerSprite->sectnum, pPlayerSprite->ang, &nearTagSector, &nearTagWall, &nearTagSprite, (int32_t*)&nearHitDist, 1024, 2, NULL); - feebtag(sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].z, sprite[nPlayerSprite].sectnum, + feebtag(pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->z, pPlayerSprite->sectnum, &nValB, var_30, 768); + auto pSprite = &sprite[nValB]; // Item pickup code - if (nValB >= 0 && sprite[nValB].statnum >= 900) + if (nValB >= 0 && pSprite->statnum >= 900) { int var_8C = 16; int var_88 = 9; - int var_70 = sprite[nValB].statnum - 900; + int var_70 = pSprite->statnum - 900; int var_44 = 0; // item lotags start at 6 (1-5 reserved?) so 0-offset them @@ -1416,7 +1421,7 @@ do_default_b: } case 0: // Speed Loader { - if (AddAmmo(nPlayer, 1, sprite[nValB].hitag)) + if (AddAmmo(nPlayer, 1, pSprite->hitag)) { var_88 = StaticSound[kSoundAmmoPickup]; goto do_default; @@ -1426,7 +1431,7 @@ do_default_b: } case 1: // Fuel Canister { - if (AddAmmo(nPlayer, 3, sprite[nValB].hitag)) + if (AddAmmo(nPlayer, 3, pSprite->hitag)) { var_88 = StaticSound[kSoundAmmoPickup]; goto do_default; @@ -1435,7 +1440,7 @@ do_default_b: } case 2: // M - 60 Ammo Belt { - if (AddAmmo(nPlayer, 2, sprite[nValB].hitag)) + if (AddAmmo(nPlayer, 2, pSprite->hitag)) { var_88 = StaticSound[kSoundAmmoPickup]; CheckClip(nPlayer); @@ -1458,7 +1463,7 @@ do_default_b: if (var_70 == 55) { - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); // loc_1BA74: - repeated block, see in default case @@ -1514,7 +1519,7 @@ do_default_b: case 6: // Berry Twig { - if (sprite[nValB].hitag == 0) { + if (pSprite->hitag == 0) { break; } @@ -1542,8 +1547,8 @@ do_default_b: if (var_70 == 12) { - sprite[nValB].hitag = 0; - sprite[nValB].picnum++; + pSprite->hitag = 0; + pSprite->picnum++; changespritestat(nValB, 0); @@ -1611,8 +1616,8 @@ do_default_b: if (var_70 == 12) { - sprite[nValB].hitag = 0; - sprite[nValB].picnum++; + pSprite->hitag = 0; + pSprite->picnum++; changespritestat(nValB, 0); @@ -1680,8 +1685,8 @@ do_default_b: if (var_70 == 12) { - sprite[nValB].hitag = 0; - sprite[nValB].picnum++; + pSprite->hitag = 0; + pSprite->picnum++; changespritestat(nValB, 0); @@ -1847,7 +1852,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -1909,7 +1914,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -1971,7 +1976,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -2033,7 +2038,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -2095,7 +2100,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -2157,7 +2162,7 @@ do_default_b: goto do_default; } - sprite[nValB].cstat = 0x8000; + pSprite->cstat = 0x8000; DestroyItemAnim(nValB); //// // loc_1BA74: - repeated block, see in default case @@ -2192,7 +2197,7 @@ do_default_b: case 32: // Raw Energy { - if (AddAmmo(nPlayer, 6, sprite[nValB].hitag)) { + if (AddAmmo(nPlayer, 6, pSprite->hitag)) { var_88 = StaticSound[kSoundAmmoPickup]; goto do_default; } @@ -2247,7 +2252,7 @@ do_default_b: { if (nLocalPlayer == nPlayer) { - short nAnim = sprite[nValB].owner; + short nAnim = pSprite->owner; AnimList[nAnim].nSeq++; AnimList[nAnim].AnimFlags &= 0xEF; AnimList[nAnim].field_2 = 0; @@ -2255,7 +2260,7 @@ do_default_b: changespritestat(nValB, 899); } - SetSavePoint(nPlayer, sprite[nPlayerSprite].x, sprite[nPlayerSprite].y, sprite[nPlayerSprite].z, sprite[nPlayerSprite].sectnum, sprite[nPlayerSprite].ang); + SetSavePoint(nPlayer, pPlayerSprite->x, pPlayerSprite->y, pPlayerSprite->z, pPlayerSprite->sectnum, pPlayerSprite->ang); break; } @@ -2277,22 +2282,22 @@ do_default_b: // CORRECT ? // loc_1BAF9: if (bTouchFloor) { - if (sector[sprite[nPlayerSprite].sectnum].lotag > 0) + if (sector[pPlayerSprite->sectnum].lotag > 0) { - runlist_SignalRun(sector[sprite[nPlayerSprite].sectnum].lotag - 1, nPlayer | 0x50000); + runlist_SignalRun(sector[pPlayerSprite->sectnum].lotag - 1, nPlayer | 0x50000); } } - if (nSector != sprite[nPlayerSprite].sectnum) + if (nSector != pPlayerSprite->sectnum) { if (sector[nSector].lotag > 0) { runlist_SignalRun(sector[nSector].lotag - 1, nPlayer | 0x70000); } - if (sector[sprite[nPlayerSprite].sectnum].lotag > 0) + if (sector[pPlayerSprite->sectnum].lotag > 0) { - runlist_SignalRun(sector[sprite[nPlayerSprite].sectnum].lotag - 1, nPlayer | 0x60000); + runlist_SignalRun(sector[pPlayerSprite->sectnum].lotag - 1, nPlayer | 0x60000); } } @@ -2325,8 +2330,8 @@ do_default_b: // loc_1BC57: - // CHECKME - are we finished with 'nSector' variable at this point? if so, maybe set it to sprite[nPlayerSprite].sectnum so we can make this code a bit neater. Don't assume sprite[nPlayerSprite].sectnum == nSector here!! - if (nStandHeight > (sector[sprite[nPlayerSprite].sectnum].floorz - sector[sprite[nPlayerSprite].sectnum].ceilingz)) { + // CHECKME - are we finished with 'nSector' variable at this point? if so, maybe set it to pPlayerSprite->sectnum so we can make this code a bit neater. Don't assume pPlayerSprite->sectnum == nSector here!! + if (nStandHeight > (sector[pPlayerSprite->sectnum].floorz - sector[pPlayerSprite->sectnum].ceilingz)) { var_48 = 1; } @@ -2335,14 +2340,14 @@ do_default_b: { if (bUnderwater) { - sprite[nPlayerSprite].zvel = -2048; + pPlayerSprite->zvel = -2048; nActionB = 10; } else if (bTouchFloor) { if (nAction < 6 || nAction > 8) { - sprite[nPlayerSprite].zvel = -3584; + pPlayerSprite->zvel = -3584; nActionB = 3; } } @@ -2353,7 +2358,7 @@ do_default_b: { if (bUnderwater) { - sprite[nPlayerSprite].zvel = 2048; + pPlayerSprite->zvel = 2048; nActionB = 10; } else @@ -2522,9 +2527,9 @@ loc_1BD2E: { if (nAction != 20) { - sprite[nPlayerSprite].picnum = seq_GetSeqPicnum(kSeqJoe, 120, 0); - sprite[nPlayerSprite].cstat = 0; - sprite[nPlayerSprite].z = sector[sprite[nPlayerSprite].sectnum].floorz; + pPlayerSprite->picnum = seq_GetSeqPicnum(kSeqJoe, 120, 0); + pPlayerSprite->cstat = 0; + pPlayerSprite->z = sector[pPlayerSprite->sectnum].floorz; } // will invalidate nPlayerSprite @@ -2572,8 +2577,8 @@ loc_1BD2E: case 16: PlayerList[nPlayer].field_2 = SeqSize[var_AC] - 1; - if (sprite[nPlayerSprite].z < sector[sprite[nPlayerSprite].sectnum].floorz) { - sprite[nPlayerSprite].z += 256; + if (pPlayerSprite->z < sector[pPlayerSprite->sectnum].floorz) { + pPlayerSprite->z += 256; } if (!RandomSize(5)) @@ -2582,14 +2587,14 @@ loc_1BD2E: short mouthSect; WheresMyMouth(nPlayer, &mouthX, &mouthY, &mouthZ, &mouthSect); - BuildAnim(-1, 71, 0, mouthX, mouthY, sprite[nPlayerSprite].z + 3840, mouthSect, 75, 128); + BuildAnim(-1, 71, 0, mouthX, mouthY, pPlayerSprite->z + 3840, mouthSect, 75, 128); } break; case 17: PlayerList[nPlayer].nAction = 18; break; case 19: - sprite[nPlayerSprite].cstat |= 0x8000; + pPlayerSprite->cstat |= 0x8000; PlayerList[nPlayer].nAction = 20; break; } @@ -2598,11 +2603,11 @@ loc_1BD2E: // loc_1C3B4: if (nPlayer == nLocalPlayer) { - initx = sprite[nPlayerSprite].x; - inity = sprite[nPlayerSprite].y; - initz = sprite[nPlayerSprite].z; - initsect = sprite[nPlayerSprite].sectnum; - inita = sprite[nPlayerSprite].ang; + initx = pPlayerSprite->x; + inity = pPlayerSprite->y; + initz = pPlayerSprite->z; + initsect = pPlayerSprite->sectnum; + inita = pPlayerSprite->ang; } if (!PlayerList[nPlayer].nHealth) @@ -2632,7 +2637,7 @@ loc_1BD2E: } else if (PlayerList[nPlayer].horizon.horiz.asq16() <= 0) { - if (!(SectFlag[sprite[nPlayerSprite].sectnum] & kSectUnderwater)) + if (!(SectFlag[pPlayerSprite->sectnum] & kSectUnderwater)) { SetNewWeapon(nPlayer, nDeathType[nPlayer] + 8); } @@ -2644,14 +2649,14 @@ loc_1BD2E: } // loc_1C4E1 - sprite[nDopple].x = sprite[nPlayerSprite].x; - sprite[nDopple].y = sprite[nPlayerSprite].y; - sprite[nDopple].z = sprite[nPlayerSprite].z; + sprite[nDopple].x = pPlayerSprite->x; + sprite[nDopple].y = pPlayerSprite->y; + sprite[nDopple].z = pPlayerSprite->z; - if (SectAbove[sprite[nPlayerSprite].sectnum] > -1) + if (SectAbove[pPlayerSprite->sectnum] > -1) { - sprite[nDopple].ang = sprite[nPlayerSprite].ang; - mychangespritesect(nDopple, SectAbove[sprite[nPlayerSprite].sectnum]); + sprite[nDopple].ang = pPlayerSprite->ang; + mychangespritesect(nDopple, SectAbove[pPlayerSprite->sectnum]); sprite[nDopple].cstat = 0x101; } else diff --git a/source/games/exhumed/src/queen.cpp b/source/games/exhumed/src/queen.cpp index 0e4b73bda..eb07c8919 100644 --- a/source/games/exhumed/src/queen.cpp +++ b/source/games/exhumed/src/queen.cpp @@ -236,10 +236,11 @@ void BlowChunks(int nSprite) void DestroyEgg(short nEgg) { short nSprite = QueenEgg[nEgg].nSprite; + auto pSprite = &sprite[nSprite]; if (QueenEgg[nEgg].nAction != 4) { - BuildAnim(-1, 34, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].xrepeat, 4); + BuildAnim(-1, 34, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->xrepeat, 4); } else { @@ -249,8 +250,8 @@ void DestroyEgg(short nEgg) } } - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_DoSubRunRec(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_DoSubRunRec(pSprite->lotag - 1); runlist_SubRunRec(QueenEgg[nEgg].nRunPtr); QueenEgg[nEgg].nRunPtr = -1; @@ -272,10 +273,11 @@ void DestroyAllEggs() void SetHeadVel(short nSprite) { - short nAngle = sprite[nSprite].ang; + auto pSprite = &sprite[nSprite]; + short nAngle = pSprite->ang; - sprite[nSprite].xvel = bcos(nAngle, nVelShift); - sprite[nSprite].yvel = bsin(nAngle, nVelShift); + pSprite->xvel = bcos(nAngle, nVelShift); + pSprite->yvel = bsin(nAngle, nVelShift); } int QueenAngleChase(short nSprite, short nSprite2, int val1, int val2) @@ -329,7 +331,7 @@ int QueenAngleChase(short nSprite, short nSprite2, int val1, int val2) nAngDelta = val2; } - nAngle = (nAngDelta + sprite[nSprite].ang) & kAngleMask; + nAngle = (nAngDelta + pSprite->ang) & kAngleMask; pSprite->zvel = (AngleDelta(pSprite->zvel, var_14, 24) + pSprite->zvel) & kAngleMask; } @@ -382,39 +384,41 @@ int DestroyTailPart() void BuildTail() { short nSprite = QueenHead.nSprite; + auto pSprite = &sprite[nSprite]; - int x = sprite[nSprite].x; - int y = sprite[nSprite].x; - int z = sprite[nSprite].x; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->x; + int z = pSprite->x; + short nSector = pSprite->sectnum; int i; for (i = 0; i < kMaxTails; i++) { short nTailSprite = insertsprite(nSector, 121); + auto pTailSprite = &sprite[nTailSprite]; tailspr[i] = nTailSprite; if (nTailSprite < 0) { I_Error("Can't create queen's tail!\n"); } - sprite[nTailSprite].lotag = runlist_HeadRun() + 1; - sprite[nTailSprite].owner = runlist_AddRunRec(sprite[nTailSprite].lotag - 1, (i + 1) | 0x1B0000); - sprite[nTailSprite].shade = -12; - sprite[nTailSprite].x = x; - sprite[nTailSprite].y = y; - sprite[nTailSprite].hitag = 0; - sprite[nTailSprite].cstat = 0; - sprite[nTailSprite].clipdist = 100; - sprite[nTailSprite].xrepeat = 80; - sprite[nTailSprite].yrepeat = 80; - sprite[nTailSprite].picnum = 1; - sprite[nTailSprite].pal = sector[sprite[nTailSprite].sectnum].ceilingpal; - sprite[nTailSprite].xoffset = 0; - sprite[nTailSprite].yoffset = 0; - sprite[nTailSprite].z = z; - sprite[nTailSprite].extra = -1; + pTailSprite->lotag = runlist_HeadRun() + 1; + pTailSprite->owner = runlist_AddRunRec(sprite[nTailSprite].lotag - 1, (i + 1) | 0x1B0000); + pTailSprite->shade = -12; + pTailSprite->x = x; + pTailSprite->y = y; + pTailSprite->hitag = 0; + pTailSprite->cstat = 0; + pTailSprite->clipdist = 100; + pTailSprite->xrepeat = 80; + pTailSprite->yrepeat = 80; + pTailSprite->picnum = 1; + pTailSprite->pal = sector[sprite[nTailSprite].sectnum].ceilingpal; + pTailSprite->xoffset = 0; + pTailSprite->yoffset = 0; + pTailSprite->z = z; + pTailSprite->extra = -1; } for (i = 0; i < 24 + 1; i++) @@ -438,50 +442,52 @@ int BuildQueenEgg(short nQueen, int nVal) } short nSprite = QueenList[nQueen].nSprite; + auto pSprite = &sprite[nSprite]; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + short nSector = pSprite->sectnum; int nFloorZ = sector[nSector].floorz; - short nAngle = sprite[nSprite].ang; + short nAngle = pSprite->ang; int nSprite2 = insertsprite(nSector, 121); assert(nSprite2 >= 0 && nSprite2 < kMaxSprites); + auto pSprite2 = &sprite[nSprite2]; - sprite[nSprite2].x = x; - sprite[nSprite2].y = y; - sprite[nSprite2].z = nFloorZ; - sprite[nSprite2].pal = 0; - sprite[nSprite2].clipdist = 50; - sprite[nSprite2].xoffset = 0; - sprite[nSprite2].yoffset = 0; - sprite[nSprite2].shade = -12; - sprite[nSprite2].picnum = 1; - sprite[nSprite2].ang = (RandomSize(9) + (nAngle - 256)) & kAngleMask; - sprite[nSprite2].backuppos(); + pSprite2->x = x; + pSprite2->y = y; + pSprite2->z = nFloorZ; + pSprite2->pal = 0; + pSprite2->clipdist = 50; + pSprite2->xoffset = 0; + pSprite2->yoffset = 0; + pSprite2->shade = -12; + pSprite2->picnum = 1; + pSprite2->ang = (RandomSize(9) + (nAngle - 256)) & kAngleMask; + pSprite2->backuppos(); if (!nVal) { - sprite[nSprite2].xrepeat = 30; - sprite[nSprite2].yrepeat = 30; - sprite[nSprite2].xvel = bcos(sprite[nSprite2].ang); - sprite[nSprite2].yvel = bsin(sprite[nSprite2].ang); - sprite[nSprite2].zvel = -6000; - sprite[nSprite2].cstat = 0; + pSprite2->xrepeat = 30; + pSprite2->yrepeat = 30; + pSprite2->xvel = bcos(pSprite2->ang); + pSprite2->yvel = bsin(pSprite2->ang); + pSprite2->zvel = -6000; + pSprite2->cstat = 0; } else { - sprite[nSprite2].xrepeat = 60; - sprite[nSprite2].yrepeat = 60; - sprite[nSprite2].xvel = 0; - sprite[nSprite2].yvel = 0; - sprite[nSprite2].zvel = -2000; - sprite[nSprite2].cstat = 0x101; + pSprite2->xrepeat = 60; + pSprite2->yrepeat = 60; + pSprite2->xvel = 0; + pSprite2->yvel = 0; + pSprite2->zvel = -2000; + pSprite2->cstat = 0x101; } - sprite[nSprite2].lotag = runlist_HeadRun() + 1; - sprite[nSprite2].extra = -1; - sprite[nSprite2].hitag = 0; + pSprite2->lotag = runlist_HeadRun() + 1; + pSprite2->extra = -1; + pSprite2->hitag = 0; GrabTimeSlot(3); @@ -499,7 +505,7 @@ int BuildQueenEgg(short nQueen, int nVal) QueenEgg[nEgg].nAction = nVal; - sprite[nSprite2].owner = runlist_AddRunRec(sprite[nSprite2].lotag - 1, nEgg | 0x1D0000); + pSprite2->owner = runlist_AddRunRec(pSprite2->lotag - 1, nEgg | 0x1D0000); QueenEgg[nEgg].nRunPtr = runlist_AddRunRec(NewRun, nEgg | 0x1D0000); return 0; @@ -511,6 +517,7 @@ void FuncQueenEgg(int a, int nDamage, int nRun) Egg *pEgg = &QueenEgg[nEgg]; short nSprite = pEgg->nSprite; + auto pSprite = &sprite[nSprite]; short nAction = pEgg->nAction; short nTarget; @@ -541,7 +548,7 @@ void FuncQueenEgg(int a, int nDamage, int nRun) short nSeq = SeqOffsets[kSeqQueenEgg] + EggSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, pEgg->nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, pEgg->nFrame); if (nAction != 4) { @@ -606,9 +613,9 @@ void FuncQueenEgg(int a, int nDamage, int nRun) break; } - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = bcos(nAngle, -1); - sprite[nSprite].yvel = bsin(nAngle, -1); + pSprite->ang = nAngle; + pSprite->xvel = bcos(nAngle, -1); + pSprite->yvel = bsin(nAngle, -1); } break; @@ -619,7 +626,7 @@ void FuncQueenEgg(int a, int nDamage, int nRun) if (bVal) { pEgg->nAction = 3; - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; } break; } @@ -638,11 +645,11 @@ void FuncQueenEgg(int a, int nDamage, int nRun) } fallthrough__; case 0x8000: - sprite[nSprite].ang += (RandomSize(9) + 768); - sprite[nSprite].ang &= kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -3); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -3); - sprite[nSprite].zvel = -RandomSize(5); + pSprite->ang += (RandomSize(9) + 768); + pSprite->ang &= kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -3); + pSprite->yvel = bsin(pSprite->ang, -3); + pSprite->zvel = -RandomSize(5); break; } @@ -655,18 +662,18 @@ void FuncQueenEgg(int a, int nDamage, int nRun) if (nMov & 0x20000) { - sprite[nSprite].zvel = -(sprite[nSprite].zvel - 256); - if (sprite[nSprite].zvel < -512) + pSprite->zvel = -(pSprite->zvel - 256); + if (pSprite->zvel < -512) { - sprite[nSprite].zvel = 0; + pSprite->zvel = 0; } } pEgg->field_C--; if (pEgg->field_C <= 0) { - short nWaspSprite = BuildWasp(-2, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].ang); - sprite[nSprite].z = sprite[nWaspSprite].z; + short nWaspSprite = BuildWasp(-2, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->ang); + pSprite->z = sprite[nWaspSprite].z; DestroyEgg(nEgg); } @@ -678,7 +685,7 @@ void FuncQueenEgg(int a, int nDamage, int nRun) case 0xA0000: { - if (sprite[nRadialSpr].statnum != 121 && (sprite[nSprite].cstat & 0x101) != 0) + if (sprite[nRadialSpr].statnum != 121 && (pSprite->cstat & 0x101) != 0) { nDamage = runlist_CheckRadialDamage(nSprite); @@ -710,37 +717,39 @@ void FuncQueenEgg(int a, int nDamage, int nRun) int BuildQueenHead(short nQueen) { short nSprite = QueenList[nQueen].nSprite; + auto pSprite = &sprite[nSprite]; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - short nAngle = sprite[nSprite].ang; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + short nAngle = pSprite->ang; + short nSector = pSprite->sectnum; int z = sector[nSector].floorz; int nSprite2 = insertsprite(nSector, 121); assert(nSprite2 >= 0 && nSprite2 < kMaxSprites); + auto pSprite2 = &sprite[nSprite2]; - sprite[nSprite2].x = x; - sprite[nSprite2].y = y; - sprite[nSprite2].z = z; - sprite[nSprite2].clipdist = 70; - sprite[nSprite2].xrepeat = 80; - sprite[nSprite2].yrepeat = 80; - sprite[nSprite2].cstat = 0; - sprite[nSprite2].picnum = 1; - sprite[nSprite2].shade = -12; - sprite[nSprite2].pal = 0; - sprite[nSprite2].xoffset = 0; - sprite[nSprite2].yoffset = 0; - sprite[nSprite2].ang = nAngle; + pSprite2->x = x; + pSprite2->y = y; + pSprite2->z = z; + pSprite2->clipdist = 70; + pSprite2->xrepeat = 80; + pSprite2->yrepeat = 80; + pSprite2->cstat = 0; + pSprite2->picnum = 1; + pSprite2->shade = -12; + pSprite2->pal = 0; + pSprite2->xoffset = 0; + pSprite2->yoffset = 0; + pSprite2->ang = nAngle; nVelShift = 2; SetHeadVel(nSprite2); - sprite[nSprite2].zvel = -8192; - sprite[nSprite2].lotag = runlist_HeadRun() + 1; - sprite[nSprite2].hitag = 0; - sprite[nSprite2].extra = -1; + pSprite2->zvel = -8192; + pSprite2->lotag = runlist_HeadRun() + 1; + pSprite2->hitag = 0; + pSprite2->extra = -1; GrabTimeSlot(3); @@ -751,7 +760,7 @@ int BuildQueenHead(short nQueen) QueenHead.nSprite = nSprite2; QueenHead.field_C = 0; - sprite[nSprite2].owner = runlist_AddRunRec(sprite[nSprite2].lotag - 1, 0x1B0000); + pSprite2->owner = runlist_AddRunRec(pSprite2->lotag - 1, 0x1B0000); QueenHead.field_8 = runlist_AddRunRec(NewRun, 0x1B0000); QueenHead.tails = 0; @@ -764,7 +773,9 @@ void FuncQueenHead(int a, int nDamage, int nRun) short nHead = RunData[nRun].nVal; short nSprite = QueenHead.nSprite; - int nSector = sprite[nSprite].sectnum; + auto pSprite = &sprite[nSprite]; + + int nSector = pSprite->sectnum; assert(nSector >= 0 && nSector < kMaxSectors); short nAction = QueenHead.nAction; @@ -787,7 +798,7 @@ void FuncQueenHead(int a, int nDamage, int nRun) seq_MoveSequence(nSprite, nSeq, QueenHead.nFrame); - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, QueenHead.nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, QueenHead.nFrame); QueenHead.nFrame++; if (QueenHead.nFrame >= SeqSize[nSeq]) @@ -824,11 +835,11 @@ void FuncQueenHead(int a, int nDamage, int nRun) QueenHead.nAction = 6; nHeadVel = 800; - sprite[nSprite].cstat = 0x101; + pSprite->cstat = 0x101; } else if (QueenHead.field_C < 60) { - sprite[nSprite].shade--; + pSprite->shade--; } } else @@ -836,7 +847,7 @@ void FuncQueenHead(int a, int nDamage, int nRun) int nMov = MoveCreature(nSprite); // original BUG - this line doesn't exist in original code? - short nNewAng = sprite[nSprite].ang; + short nNewAng = pSprite->ang; switch (nMov & 0xFC000) { @@ -849,18 +860,18 @@ void FuncQueenHead(int a, int nDamage, int nRun) nNewAng = GetWallNormal(nMov & 0x3FFF); break; case 0x20000: - sprite[nSprite].zvel = -(sprite[nSprite].zvel >> 1); + pSprite->zvel = -(pSprite->zvel >> 1); - if (sprite[nSprite].zvel > -256) + if (pSprite->zvel > -256) { nVelShift = 100; - sprite[nSprite].zvel = 0; + pSprite->zvel = 0; } break; } // original BUG - var_18 isn't being set if the check above == 0x20000 ? - sprite[nSprite].ang = nNewAng; + pSprite->ang = nNewAng; nVelShift++; if (nVelShift < 5) @@ -869,10 +880,10 @@ void FuncQueenHead(int a, int nDamage, int nRun) } else { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; - if (sprite[nSprite].zvel == 0) + if (pSprite->zvel == 0) { QueenHead.field_C = 120; } @@ -891,14 +902,14 @@ void FuncQueenHead(int a, int nDamage, int nRun) fallthrough__; case 1: - if ((sprite[nTarget].z - 51200) > sprite[nSprite].z) + if ((sprite[nTarget].z - 51200) > pSprite->z) { QueenHead.nAction = 4; QueenHead.nFrame = 0; } else { - sprite[nSprite].z -= 2048; + pSprite->z -= 2048; goto __MOVEQS; } break; @@ -938,10 +949,10 @@ void FuncQueenHead(int a, int nDamage, int nRun) runlist_DamageEnemy(nTarget, nSprite, 10); D3PlayFX(StaticSound[kSoundQTail] | 0x2000, nSprite); - sprite[nSprite].ang += RandomSize(9) + 768; - sprite[nSprite].ang &= kAngleMask; + pSprite->ang += RandomSize(9) + 768; + pSprite->ang &= kAngleMask; - sprite[nSprite].zvel = (-20) - RandomSize(6); + pSprite->zvel = (-20) - RandomSize(6); SetHeadVel(nSprite); } @@ -951,12 +962,12 @@ void FuncQueenHead(int a, int nDamage, int nRun) // switch break. MoveQS stuff? __MOVEQS: - MoveQX[nQHead] = sprite[nSprite].x; - MoveQY[nQHead] = sprite[nSprite].y; - MoveQZ[nQHead] = sprite[nSprite].z; - assert(sprite[nSprite].sectnum >= 0 && sprite[nSprite].sectnum < kMaxSectors); - MoveQS[nQHead] = sprite[nSprite].sectnum; - MoveQA[nQHead] = sprite[nSprite].ang; + MoveQX[nQHead] = pSprite->x; + MoveQY[nQHead] = pSprite->y; + MoveQZ[nQHead] = pSprite->z; + assert(pSprite->sectnum >= 0 && pSprite->sectnum < kMaxSectors); + MoveQS[nQHead] = pSprite->sectnum; + MoveQA[nQHead] = pSprite->ang; nHd = nQHead; @@ -1001,16 +1012,16 @@ __MOVEQS: { if (QueenHead.tails >= 15 || QueenHead.tails < 10) { - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; - short nSector = sprite[nSprite].sectnum; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; + short nSector = pSprite->sectnum; int nAngle = RandomSize(11) & kAngleMask; - sprite[nSprite].xrepeat = 127 - QueenHead.tails; - sprite[nSprite].yrepeat = 127 - QueenHead.tails; + pSprite->xrepeat = 127 - QueenHead.tails; + pSprite->yrepeat = 127 - QueenHead.tails; - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; // DEMO-TODO: in disassembly angle was used without masking and thus causing OOB issue. // This behavior probably would be needed emulated for demo compatibility @@ -1025,9 +1036,9 @@ __MOVEQS: mychangespritesect(nSprite, nSector); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; if (QueenHead.tails < 10) { for (int i = (10 - QueenHead.tails) * 2; i > 0; i--) @@ -1053,7 +1064,7 @@ __MOVEQS: BuildLavaLimb(nSprite, i, GetSpriteHeight(nSprite)); } - runlist_SubRunRec(sprite[nSprite].owner); + runlist_SubRunRec(pSprite->owner); runlist_SubRunRec(QueenHead.field_8); mydeletesprite(nSprite); runlist_ChangeChannel(QueenChan[0], 1); @@ -1065,7 +1076,7 @@ __MOVEQS: } case 0xA0000: - if (sprite[nRadialSpr].statnum != 121 && (sprite[nSprite].cstat & 0x101) != 0) + if (sprite[nRadialSpr].statnum != 121 && (pSprite->cstat & 0x101) != 0) { nDamage = runlist_CheckRadialDamage(nSprite); if (!nDamage) @@ -1101,7 +1112,7 @@ __MOVEQS: QueenHead.nFrame = 0; QueenHead.field_C = 0; QueenHead.tails = 80; - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; } } } @@ -1144,41 +1155,44 @@ int BuildQueen(int nSprite, int x, int y, int z, int nSector, int nAngle, int nC if (nQueen < 0) { return -1; } + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 121); + pSprite = &sprite[nSprite]; + } else { changespritestat(nSprite, 121); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + nAngle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].pal = 0; - sprite[nSprite].shade = -12; - sprite[nSprite].clipdist = 100; - sprite[nSprite].xrepeat = 80; - sprite[nSprite].yrepeat = 80; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = 1; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; - sprite[nSprite].hitag = 0; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->pal = 0; + pSprite->shade = -12; + pSprite->clipdist = 100; + pSprite->xrepeat = 80; + pSprite->yrepeat = 80; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = 1; + pSprite->ang = nAngle; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; + pSprite->hitag = 0; GrabTimeSlot(3); @@ -1195,7 +1209,7 @@ int BuildQueen(int nSprite, int x, int y, int z, int nSector, int nAngle, int nC nHeadVel = 800; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nQueen | 0x1A0000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nQueen | 0x1A0000); runlist_AddRunRec(NewRun, nQueen | 0x1A0000); @@ -1206,8 +1220,10 @@ int BuildQueen(int nSprite, int x, int y, int z, int nSector, int nAngle, int nC void SetQueenSpeed(short nSprite, int nSpeed) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -(2 - nSpeed)); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -(2 - nSpeed)); + auto pSprite = &sprite[nSprite]; + + pSprite->xvel = bcos(pSprite->ang, -(2 - nSpeed)); + pSprite->yvel = bsin(pSprite->ang, -(2 - nSpeed)); } void FuncQueen(int a, int nDamage, int nRun) @@ -1216,6 +1232,7 @@ void FuncQueen(int a, int nDamage, int nRun) assert(nQueen >= 0 && nQueen < kMaxQueens); short nSprite = QueenList[nQueen].nSprite; + auto pSprite = &sprite[nSprite]; short nAction = QueenList[nQueen].nAction; short si = QueenList[nQueen].field_A; short nTarget = QueenList[nQueen].nTarget; @@ -1241,7 +1258,7 @@ void FuncQueen(int a, int nDamage, int nRun) short nSeq = SeqOffsets[kSeqQueen] + QueenSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, QueenList[nQueen].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, QueenList[nQueen].nFrame); seq_MoveSequence(nSprite, nSeq, QueenList[nQueen].nFrame); @@ -1258,7 +1275,7 @@ void FuncQueen(int a, int nDamage, int nRun) { if (nAction < 7) { - if (!(sprite[nSprite].cstat & 0x101)) + if (!(pSprite->cstat & 0x101)) { nTarget = -1; QueenList[nQueen].nTarget = -1; @@ -1312,8 +1329,8 @@ void FuncQueen(int a, int nDamage, int nRun) if (QueenList[nQueen].field_C <= 0) { QueenList[nQueen].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; QueenList[nQueen].nAction = si + 4; QueenList[nQueen].field_C = RandomSize(6) + 30; break; @@ -1363,8 +1380,8 @@ void FuncQueen(int a, int nDamage, int nRun) } fallthrough__; case 0x8000: - sprite[nSprite].ang += 256; - sprite[nSprite].ang &= kAngleMask; + pSprite->ang += 256; + pSprite->ang &= kAngleMask; SetQueenSpeed(nSprite, si); break; @@ -1380,8 +1397,8 @@ void FuncQueen(int a, int nDamage, int nRun) QueenList[nQueen].field_C = 100; QueenList[nQueen].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } @@ -1406,7 +1423,7 @@ void FuncQueen(int a, int nDamage, int nRun) if (!si) { - BuildBullet(nSprite, 12, 0, 0, -1, sprite[nSprite].ang, nTarget + 10000, 1); + BuildBullet(nSprite, 12, 0, 0, -1, pSprite->ang, nTarget + 10000, 1); } else { @@ -1439,7 +1456,7 @@ void FuncQueen(int a, int nDamage, int nRun) QueenList[nQueen].field_C--; if (QueenList[nQueen].field_C <= 0) { - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; for (int i = 0; i < 20; i++) { @@ -1458,10 +1475,10 @@ void FuncQueen(int a, int nDamage, int nRun) PlayFXAtXYZ( StaticSound[kSound40], - sprite[nSprite].x, - sprite[nSprite].y, - sprite[nSprite].z, - sprite[nSprite].sectnum); + pSprite->x, + pSprite->y, + pSprite->z, + pSprite->sectnum); BuildQueenHead(nQueen); @@ -1477,7 +1494,7 @@ void FuncQueen(int a, int nDamage, int nRun) case 10: { - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; break; } } @@ -1486,7 +1503,7 @@ void FuncQueen(int a, int nDamage, int nRun) case 0xA0000: { - if (sprite[nRadialSpr].statnum != 121 && (sprite[nSprite].cstat & 0x101) != 0) + if (sprite[nRadialSpr].statnum != 121 && (pSprite->cstat & 0x101) != 0) { nDamage = runlist_CheckRadialDamage(nSprite); @@ -1508,9 +1525,9 @@ void FuncQueen(int a, int nDamage, int nRun) if (QueenList[nQueen].nHealth <= 0) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; QueenList[nQueen].field_A++; @@ -1520,7 +1537,7 @@ void FuncQueen(int a, int nDamage, int nRun) QueenList[nQueen].nHealth = 4000; QueenList[nQueen].nAction = 7; - BuildAnim(-1, 36, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - 7680, sprite[nSprite].sectnum, sprite[nSprite].xrepeat, 4); + BuildAnim(-1, 36, 0, pSprite->x, pSprite->y, pSprite->z - 7680, pSprite->sectnum, pSprite->xrepeat, 4); break; case 2: QueenList[nQueen].nHealth = 4000; diff --git a/source/games/exhumed/src/ra.cpp b/source/games/exhumed/src/ra.cpp index 00f80f0d9..0cba590dc 100644 --- a/source/games/exhumed/src/ra.cpp +++ b/source/games/exhumed/src/ra.cpp @@ -64,10 +64,11 @@ void FreeRa(short nPlayer) { int nRun = Ra[nPlayer].nRun; int nSprite = Ra[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; runlist_SubRunRec(nRun); - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); mydeletesprite(nSprite); } @@ -77,21 +78,22 @@ int BuildRa(short nPlayer) short nPlayerSprite = PlayerList[nPlayer].nSprite; int nSprite = insertsprite(sprite[nPlayerSprite].sectnum, 203); + auto pSprite = &sprite[nSprite]; - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].extra = -1; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nPlayer | 0x210000); - sprite[nSprite].pal = 1; - sprite[nSprite].xrepeat = 64; - sprite[nSprite].yrepeat = 64; - sprite[nSprite].x = sprite[nPlayerSprite].x; - sprite[nSprite].y = sprite[nPlayerSprite].y; - sprite[nSprite].z = sprite[nPlayerSprite].z; + pSprite->cstat = 0x8000; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->extra = -1; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->hitag = 0; + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nPlayer | 0x210000); + pSprite->pal = 1; + pSprite->xrepeat = 64; + pSprite->yrepeat = 64; + pSprite->x = sprite[nPlayerSprite].x; + pSprite->y = sprite[nPlayerSprite].y; + pSprite->z = sprite[nPlayerSprite].z; // GrabTimeSlot(3); @@ -117,6 +119,7 @@ void MoveRaToEnemy(short nPlayer) short nTarget = Ra[nPlayer].nTarget; short nSprite = Ra[nPlayer].nSprite; short nAction = Ra[nPlayer].nAction; + auto pSprite = &sprite[nSprite]; if (nTarget != -1) { @@ -133,7 +136,7 @@ void MoveRaToEnemy(short nPlayer) } else { - if (sprite[nSprite].sectnum != sprite[nTarget].sectnum) { + if (pSprite->sectnum != sprite[nTarget].sectnum) { mychangespritesect(nSprite, sprite[nTarget].sectnum); } } @@ -151,15 +154,15 @@ void MoveRaToEnemy(short nPlayer) return; } - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; nTarget = PlayerList[nPlayer].nSprite; } - sprite[nSprite].x = sprite[nTarget].x; - sprite[nSprite].y = sprite[nTarget].y; - sprite[nSprite].z = sprite[nTarget].z - GetSpriteHeight(nTarget); + pSprite->x = sprite[nTarget].x; + pSprite->y = sprite[nTarget].y; + pSprite->z = sprite[nTarget].z - GetSpriteHeight(nTarget); - if (sprite[nSprite].sectnum != sprite[nTarget].sectnum) { + if (pSprite->sectnum != sprite[nTarget].sectnum) { mychangespritesect(nSprite, sprite[nTarget].sectnum); } } @@ -171,6 +174,7 @@ void FuncRa(int a, int, int nRun) short nSeq = SeqOffsets[kSeqEyeHit] + RaSeq[Ra[nPlayer].nAction].a; short nSprite = Ra[nPlayer].nSprite; + auto pSprite = &sprite[nSprite]; bool bVal = false; @@ -191,7 +195,7 @@ void FuncRa(int a, int, int nRun) case 0x20000: { Ra[nPlayer].nTarget = sPlayerInput[nPlayer].nTarget; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, Ra[nPlayer].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, Ra[nPlayer].nFrame); if (Ra[nPlayer].nAction) { @@ -213,11 +217,11 @@ void FuncRa(int a, int, int nRun) if (!Ra[nPlayer].field_C || Ra[nPlayer].nTarget <= -1) { - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; } else { - sprite[nSprite].cstat &= 0x7FFF; + pSprite->cstat &= 0x7FFF; Ra[nPlayer].nAction = 1; Ra[nPlayer].nFrame = 0; } @@ -288,7 +292,7 @@ void FuncRa(int a, int, int nRun) { if (bVal) { - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; Ra[nPlayer].nAction = 0; Ra[nPlayer].nFrame = 0; Ra[nPlayer].field_C = 0; diff --git a/source/games/exhumed/src/rat.cpp b/source/games/exhumed/src/rat.cpp index 0f3768182..2a33f3ae5 100644 --- a/source/games/exhumed/src/rat.cpp +++ b/source/games/exhumed/src/rat.cpp @@ -101,45 +101,50 @@ void InitRats() void SetRatVel(short nSprite) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + auto pSprite = &sprite[nSprite]; + + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); } int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle) { auto nRat = RatList.Reserve(1); + auto pSprite = &sprite[nSprite]; + if (nSprite < 0) { nSprite = insertsprite(nSector, 108); assert(nSprite >= 0 && nSprite < kMaxSprites); + pSprite = &sprite[nSprite]; - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; } else { - nAngle = sprite[nSprite].ang; + nAngle = pSprite->ang; changespritestat(nSprite, 108); } - sprite[nSprite].cstat = 0x101; - sprite[nSprite].shade = -12; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].clipdist = 30; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xrepeat = 50; - sprite[nSprite].yrepeat = 50; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].extra = -1; + pSprite->cstat = 0x101; + pSprite->shade = -12; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = 1; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->clipdist = 30; + pSprite->ang = nAngle; + pSprite->xrepeat = 50; + pSprite->yrepeat = 50; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->hitag = 0; + pSprite->extra = -1; if (nAngle >= 0) { RatList[nRat].nAction = 2; @@ -154,7 +159,7 @@ int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle) RatList[nRat].nCount = RandomSize(5); RatList[nRat].nIndex = RandomSize(3); - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nRat | 0x240000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nRat | 0x240000); RatList[nRat].nRun = runlist_AddRunRec(NewRun, nRat | 0x240000); return 0; @@ -162,10 +167,12 @@ int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle) int FindFood(short nSprite) { - short nSector = sprite[nSprite].sectnum; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; + auto pSprite = &sprite[nSprite]; + + short nSector = pSprite->sectnum; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; int z2 = (z + sector[nSector].ceilingz) / 2; @@ -203,6 +210,7 @@ void FuncRat(int a, int nDamage, int nRun) short nRat = RunData[nRun].nVal; short nSprite = RatList[nRat].nSprite; short nAction = RatList[nRat].nAction; + auto pSprite = &sprite[nSprite]; bool bVal = false; @@ -226,9 +234,9 @@ void FuncRat(int a, int nDamage, int nRun) { if (nDamage) { - sprite[nSprite].cstat = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->cstat = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; RatList[nRat].nAction = 3; RatList[nRat].nFrame = 0; } @@ -244,7 +252,7 @@ void FuncRat(int a, int nDamage, int nRun) case 0x20000: { int nSeq = SeqOffsets[kSeqRat] + RatSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, RatList[nRat].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, RatList[nRat].nFrame); seq_MoveSequence(nSprite, nSeq, RatList[nRat].nFrame); @@ -271,8 +279,8 @@ void FuncRat(int a, int nDamage, int nRun) return; } - int xVal = abs(sprite[nSprite].x - sprite[nTarget].x); - int yVal = abs(sprite[nSprite].y - sprite[nTarget].y); + int xVal = abs(pSprite->x - sprite[nTarget].x); + int yVal = abs(pSprite->y - sprite[nTarget].y); if (xVal > 50 || yVal > 50) { @@ -280,8 +288,8 @@ void FuncRat(int a, int nDamage, int nRun) RatList[nRat].nFrame = 0; RatList[nRat].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } @@ -318,14 +326,14 @@ void FuncRat(int a, int nDamage, int nRun) RatList[nRat].nFrame = 0; RatList[nRat].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } MoveCreature(nSprite); - int xVal = abs(sprite[nSprite].x - sprite[nTarget].x); - int yVal = abs(sprite[nSprite].y - sprite[nTarget].y); + int xVal = abs(pSprite->x - sprite[nTarget].x); + int yVal = abs(pSprite->y - sprite[nTarget].y); if (xVal >= 50 || yVal >= 50) { @@ -345,13 +353,13 @@ void FuncRat(int a, int nDamage, int nRun) RatList[nRat].nFrame = 0; RatList[nRat].nIndex = RandomSize(3); - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } case 2: { - if (sprite[nSprite].xvel || sprite[nSprite].yvel || sprite[nSprite].zvel) { + if (pSprite->xvel || pSprite->yvel || pSprite->zvel) { MoveCreature(nSprite); } @@ -363,14 +371,14 @@ void FuncRat(int a, int nDamage, int nRun) if (RatList[nRat].nTarget <= -1) { RatList[nRat].nCount = RandomSize(6); - if (sprite[nSprite].xvel || sprite[nSprite].yvel) + if (pSprite->xvel || pSprite->yvel) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } - sprite[nSprite].ang = RandomSize(11); + pSprite->ang = RandomSize(11); SetRatVel(nSprite); return; } @@ -391,11 +399,11 @@ void FuncRat(int a, int nDamage, int nRun) { if (bVal) { - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); runlist_SubRunRec(RatList[nRat].nRun); - sprite[nSprite].cstat = 0x8000; + pSprite->cstat = 0x8000; mydeletesprite(nSprite); } return; diff --git a/source/games/exhumed/src/rex.cpp b/source/games/exhumed/src/rex.cpp index bffd9ec65..535697189 100644 --- a/source/games/exhumed/src/rex.cpp +++ b/source/games/exhumed/src/rex.cpp @@ -80,41 +80,43 @@ void InitRexs() int BuildRex(short nSprite, int x, int y, int z, short nSector, short nAngle, int nChannel) { int nRex = RexList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 119); + pSprite = &sprite[nSprite]; } else { changespritestat(nSprite, 119); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + nAngle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].clipdist = 80; - sprite[nSprite].shade = -12; - sprite[nSprite].xrepeat = 64; - sprite[nSprite].yrepeat = 64; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; - sprite[nSprite].hitag = 0; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->clipdist = 80; + pSprite->shade = -12; + pSprite->xrepeat = 64; + pSprite->yrepeat = 64; + pSprite->picnum = 1; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = nAngle; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; + pSprite->hitag = 0; GrabTimeSlot(3); @@ -127,7 +129,7 @@ int BuildRex(short nSprite, int x, int y, int z, short nSector, short nAngle, in RexList[nRex].nChannel = nChannel; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nRex | 0x180000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nRex | 0x180000); // this isn't stored anywhere. runlist_AddRunRec(NewRun, nRex | 0x180000); @@ -144,6 +146,7 @@ void FuncRex(int a, int nDamage, int nRun) short nAction = RexList[nRex].nAction; short nSprite = RexList[nRex].nSprite; + auto pSprite = &sprite[nSprite]; bool bVal = false; @@ -183,10 +186,10 @@ void FuncRex(int a, int nDamage, int nRun) if (RexList[nRex].nHealth <= 0) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->cstat &= 0xFEFE; RexList[nRex].nHealth = 0; @@ -215,7 +218,7 @@ void FuncRex(int a, int nDamage, int nRun) int nSeq = SeqOffsets[kSeqRex] + RexSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, RexList[nRex].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, RexList[nRex].nFrame); int ecx = 2; @@ -253,9 +256,9 @@ void FuncRex(int a, int nDamage, int nRun) { if (nTarget < 0) { - short nAngle = sprite[nSprite].ang; // make backup of this variable + short nAngle = pSprite->ang; // make backup of this variable RexList[nRex].nTarget = FindPlayer(nSprite, 60); - sprite[nSprite].ang = nAngle; + pSprite->ang = nAngle; } else { @@ -271,8 +274,8 @@ void FuncRex(int a, int nDamage, int nRun) RexList[nRex].nAction = 1; RexList[nRex].nFrame = 0; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); D3PlayFX(StaticSound[kSound48], nSprite); @@ -296,17 +299,17 @@ void FuncRex(int a, int nDamage, int nRun) { RexList[nRex].nAction = 5; RexList[nRex].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } else { if (((PlotCourseToSprite(nSprite, nTarget) >> 8) >= 60) || RexList[nRex].nCount > 0) { - int nAngle = sprite[nSprite].ang & 0xFFF8; - sprite[nSprite].xvel = bcos(nAngle, -2); - sprite[nSprite].yvel = bsin(nAngle, -2); + int nAngle = pSprite->ang & 0xFFF8; + pSprite->xvel = bcos(nAngle, -2); + pSprite->yvel = bsin(nAngle, -2); } else { @@ -336,9 +339,9 @@ void FuncRex(int a, int nDamage, int nRun) } case 0x8000: { - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); RexList[nRex].nAction = 1; RexList[nRex].nFrame = 0; nAction = 1; @@ -356,8 +359,8 @@ void FuncRex(int a, int nDamage, int nRun) { PlotCourseToSprite(nSprite, nTarget); - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); int nMov = MoveCreatureWithCaution(nSprite); @@ -368,9 +371,9 @@ void FuncRex(int a, int nDamage, int nRun) SetQuake(nSprite, 25); RexList[nRex].nCount = 60; - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -2); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -2); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -2); + pSprite->yvel = bsin(pSprite->ang, -2); RexList[nRex].nAction = 1; RexList[nRex].nFrame = 0; nAction = 1; @@ -385,7 +388,7 @@ void FuncRex(int a, int nDamage, int nRun) if (sprite[nSprite2].statnum && sprite[nSprite2].statnum < 107) { - short nAngle = sprite[nSprite].ang; + short nAngle = pSprite->ang; runlist_DamageEnemy(nSprite2, nSprite, 15); @@ -473,7 +476,7 @@ void FuncRex(int a, int nDamage, int nRun) case 7: { - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; return; } } @@ -487,8 +490,8 @@ void FuncRex(int a, int nDamage, int nRun) RexList[nRex].nFrame = 0; RexList[nRex].nCount = 0; RexList[nRex].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } return; diff --git a/source/games/exhumed/src/roach.cpp b/source/games/exhumed/src/roach.cpp index 5c482d7b6..d474c44b9 100644 --- a/source/games/exhumed/src/roach.cpp +++ b/source/games/exhumed/src/roach.cpp @@ -84,40 +84,42 @@ int BuildRoach(int nType, int nSprite, int x, int y, int z, short nSector, int a { auto RoachCount = RoachList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 105); + pSprite = &sprite[nSprite]; } else { changespritestat(nSprite, 105); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - angle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + angle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].shade = -12; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].clipdist = 60; - sprite[nSprite].ang = angle; - sprite[nSprite].xrepeat = 40; - sprite[nSprite].yrepeat = 40; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->shade = -12; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = 1; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->clipdist = 60; + pSprite->ang = angle; + pSprite->xrepeat = 40; + pSprite->yrepeat = 40; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -136,7 +138,7 @@ int BuildRoach(int nType, int nSprite, int x, int y, int z, short nSector, int a RoachList[RoachCount].nTarget = -1; RoachList[RoachCount].nHealth = 600; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, RoachCount | 0x1C0000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, RoachCount | 0x1C0000); RoachList[RoachCount].nRun = runlist_AddRunRec(NewRun, RoachCount | 0x1C0000); nCreaturesTotal++; @@ -146,8 +148,9 @@ int BuildRoach(int nType, int nSprite, int x, int y, int z, short nSector, int a void GoRoach(short nSprite) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1) - bcos(sprite[nSprite].ang, -3); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1) - bsin(sprite[nSprite].ang, -3); + auto pSprite = &sprite[nSprite]; + pSprite->xvel = bcos(pSprite->ang, -1) - bcos(pSprite->ang, -3); + pSprite->yvel = bsin(pSprite->ang, -1) - bsin(pSprite->ang, -3); } void FuncRoach(int a, int nDamage, int nRun) @@ -156,6 +159,7 @@ void FuncRoach(int a, int nDamage, int nRun) assert(nRoach >= 0 && nRoach < (int)RoachList.Size()); short nSprite = RoachList[nRoach].nSprite; + auto pSprite = &sprite[nSprite]; short nAction = RoachList[nRoach].nAction; bool bVal = false; @@ -192,10 +196,10 @@ void FuncRoach(int a, int nDamage, int nRun) RoachList[nRoach].nHealth -= dmgAdjust(nDamage); if (RoachList[nRoach].nHealth <= 0) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->cstat &= 0xFEFE; RoachList[nRoach].nHealth = 0; @@ -244,7 +248,7 @@ void FuncRoach(int a, int nDamage, int nRun) int nSeq = SeqOffsets[kSeqRoach] + RoachSeq[RoachList[nRoach].nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, RoachList[nRoach].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, RoachList[nRoach].nFrame); seq_MoveSequence(nSprite, nSeq, RoachList[nRoach].nFrame); RoachList[nRoach].nFrame++; @@ -329,21 +333,21 @@ void FuncRoach(int a, int nDamage, int nRun) RoachList[nRoach].nIndex = RandomSize(2) + 1; RoachList[nRoach].nAction = 3; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->ang = GetMyAngle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); RoachList[nRoach].nFrame = 0; } else { - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; + pSprite->ang = (pSprite->ang + 256) & kAngleMask; GoRoach(nSprite); } } else if ((nMov & 0xC000) == 0x8000) { - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; + pSprite->ang = (pSprite->ang + 256) & kAngleMask; GoRoach(nSprite); } else @@ -358,9 +362,9 @@ void FuncRoach(int a, int nDamage, int nRun) RoachList[nRoach].nIndex = RandomSize(2) + 1; RoachList[nRoach].nAction = 3; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->ang = GetMyAngle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); RoachList[nRoach].nFrame = 0; } @@ -372,8 +376,8 @@ void FuncRoach(int a, int nDamage, int nRun) RoachList[nRoach].nFrame = 0; RoachList[nRoach].nCount = 100; RoachList[nRoach].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } return; @@ -396,7 +400,7 @@ void FuncRoach(int a, int nDamage, int nRun) { if (nFlag & 0x80) { - BuildBullet(nSprite, 13, 0, 0, -1, sprite[nSprite].ang, nTarget + 10000, 1); + BuildBullet(nSprite, 13, 0, 0, -1, pSprite->ang, nTarget + 10000, 1); } } @@ -418,7 +422,7 @@ void FuncRoach(int a, int nDamage, int nRun) { if (bVal) { - sprite[nSprite].cstat = 0; + pSprite->cstat = 0; RoachList[nRoach].nAction = 6; RoachList[nRoach].nFrame = 0; } diff --git a/source/games/exhumed/src/runlist.cpp b/source/games/exhumed/src/runlist.cpp index 1be9eabab..a1dc25dff 100644 --- a/source/games/exhumed/src/runlist.cpp +++ b/source/games/exhumed/src/runlist.cpp @@ -1531,25 +1531,27 @@ void runlist_ProcessWallTag(int nWall, short nLotag, short nHitag) int runlist_CheckRadialDamage(short nSprite) { + auto pSprite = &sprite[nSprite]; + if (nSprite == nRadialSpr) { return 0; } - if (!(sprite[nSprite].cstat & 0x101)) { + if (!(pSprite->cstat & 0x101)) { return 0; } - if (sprite[nSprite].statnum >= kMaxStatus || sprite[nRadialSpr].statnum >= kMaxStatus) { + if (pSprite->statnum >= kMaxStatus || sprite[nRadialSpr].statnum >= kMaxStatus) { return 0; } - if (sprite[nSprite].statnum != 100 && nSprite == nRadialOwner) { + if (pSprite->statnum != 100 && nSprite == nRadialOwner) { return 0; } - int x = (sprite[nSprite].x - sprite[nRadialSpr].x) >> 8; - int y = (sprite[nSprite].y - sprite[nRadialSpr].y) >> 8; - int z = (sprite[nSprite].z - sprite[nRadialSpr].z) >> 12; + int x = (pSprite->x - sprite[nRadialSpr].x) >> 8; + int y = (pSprite->y - sprite[nRadialSpr].y) >> 8; + int z = (pSprite->z - sprite[nRadialSpr].z) >> 12; if (abs(x) > nDamageRadius) { return 0; @@ -1580,18 +1582,18 @@ int runlist_CheckRadialDamage(short nSprite) if (nDist < nDamageRadius) { - uint16_t nCStat = sprite[nSprite].cstat; - sprite[nSprite].cstat = 0x101; + uint16_t nCStat = pSprite->cstat; + pSprite->cstat = 0x101; - if (((kStatExplodeTarget - sprite[nSprite].statnum) <= 1) || + if (((kStatExplodeTarget - pSprite->statnum) <= 1) || cansee(sprite[nRadialSpr].x, sprite[nRadialSpr].y, sprite[nRadialSpr].z - 512, sprite[nRadialSpr].sectnum, - sprite[nSprite].x, - sprite[nSprite].y, - sprite[nSprite].z - 8192, - sprite[nSprite].sectnum)) + pSprite->x, + pSprite->y, + pSprite->z - 8192, + pSprite->sectnum)) { edi = (nRadialDamage * (nDamageRadius - nDist)) / nDamageRadius; @@ -1602,17 +1604,17 @@ int runlist_CheckRadialDamage(short nSprite) { int nAngle = GetMyAngle(x, y); - sprite[nSprite].xvel += (edi * bcos(nAngle)) >> 3; - sprite[nSprite].yvel += (edi * bsin(nAngle)) >> 3; - sprite[nSprite].zvel -= edi * 24; + pSprite->xvel += (edi * bcos(nAngle)) >> 3; + pSprite->yvel += (edi * bsin(nAngle)) >> 3; + pSprite->zvel -= edi * 24; - if (sprite[nSprite].zvel < -3584) { - sprite[nSprite].zvel = -3584; + if (pSprite->zvel < -3584) { + pSprite->zvel = -3584; } } } - sprite[nSprite].cstat = nCStat; + pSprite->cstat = nCStat; } if (edi > 0x7FFF) { @@ -1624,6 +1626,8 @@ int runlist_CheckRadialDamage(short nSprite) void runlist_RadialDamageEnemy(short nSprite, short nDamage, short nRadius) { + auto pSprite = &sprite[nSprite]; + if (!nRadius) { return; } @@ -1633,7 +1637,7 @@ void runlist_RadialDamageEnemy(short nSprite, short nDamage, short nRadius) nRadialDamage = nDamage * 4; nDamageRadius = nRadius; nRadialSpr = nSprite; - nRadialOwner = sprite[nSprite].owner; + nRadialOwner = pSprite->owner; runlist_ExplodeSignalRun(); @@ -1643,11 +1647,13 @@ void runlist_RadialDamageEnemy(short nSprite, short nDamage, short nRadius) void runlist_DamageEnemy(int nSprite, int nSprite2, short nDamage) { - if (sprite[nSprite].statnum >= kMaxStatus) { + auto pSprite = &sprite[nSprite]; + + if (pSprite->statnum >= kMaxStatus) { return; } - short nRun = sprite[nSprite].owner; + short nRun = pSprite->owner; if (nRun <= -1) { return; } diff --git a/source/games/exhumed/src/scorp.cpp b/source/games/exhumed/src/scorp.cpp index e2eda3680..3a627f1fc 100644 --- a/source/games/exhumed/src/scorp.cpp +++ b/source/games/exhumed/src/scorp.cpp @@ -91,41 +91,44 @@ int BuildScorp(short nSprite, int x, int y, int z, short nSector, short nAngle, { auto nScorp = scorpion.Reserve(1); + auto pSprite = &sprite[nSprite]; + if (nSprite == -1) { nSprite = insertsprite(nSector, 122); + pSprite = &sprite[nSprite]; } else { changespritestat(nSprite, 122); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + nAngle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].clipdist = 70; - sprite[nSprite].shade = -12; - sprite[nSprite].xrepeat = 80; - sprite[nSprite].yrepeat = 80; - sprite[nSprite].picnum = 1; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; - sprite[nSprite].hitag = 0; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->clipdist = 70; + pSprite->shade = -12; + pSprite->xrepeat = 80; + pSprite->yrepeat = 80; + pSprite->picnum = 1; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = nAngle; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; + pSprite->hitag = 0; // GrabTimeSlot(3); @@ -139,7 +142,7 @@ int BuildScorp(short nSprite, int x, int y, int z, short nSector, short nAngle, scorpion[nScorp].nChannel = nChannel; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nScorp | 0x220000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nScorp | 0x220000); scorpion[nScorp].nRun = runlist_AddRunRec(NewRun, nScorp | 0x220000); nCreaturesTotal++; @@ -154,6 +157,7 @@ void FuncScorp(int a, int nDamage, int nRun) short nSprite = scorpion[nScorp].nSprite; short nAction = scorpion[nScorp].nAction; + auto pSprite = &sprite[nSprite]; bool bVal = false; @@ -200,10 +204,10 @@ void FuncScorp(int a, int nDamage, int nRun) scorpion[nScorp].nFrame = 0; scorpion[nScorp].nCount = 10; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->cstat &= 0xFEFE; nCreaturesKilled++; return; @@ -214,7 +218,7 @@ void FuncScorp(int a, int nDamage, int nRun) if (nTarget >= 0) { - if (sprite[nSprite].statnum == 100 || (sprite[nSprite].statnum < 199 && !RandomSize(5))) + if (pSprite->statnum == 100 || (pSprite->statnum < 199 && !RandomSize(5))) { scorpion[nScorp].nTarget = nTarget; } @@ -245,7 +249,7 @@ void FuncScorp(int a, int nDamage, int nRun) int nSeq = SeqOffsets[kSeqScorp] + ScorpSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, scorpion[nScorp].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, scorpion[nScorp].nFrame); seq_MoveSequence(nSprite, nSeq, scorpion[nScorp].nFrame); scorpion[nScorp].nFrame++; @@ -283,8 +287,8 @@ void FuncScorp(int a, int nDamage, int nRun) D3PlayFX(StaticSound[kSound41], nSprite); scorpion[nScorp].nFrame = 0; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); scorpion[nScorp].nAction = 1; scorpion[nScorp].nTarget = nTarget; @@ -312,8 +316,8 @@ void FuncScorp(int a, int nDamage, int nRun) { if (nTarget == (nMov & 0x3FFF)) { - int nAngle = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); - if (AngleDiff(sprite[nSprite].ang, nAngle) < 64) + int nAngle = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); + if (AngleDiff(pSprite->ang, nAngle) < 64) { scorpion[nScorp].nAction = 2; scorpion[nScorp].nFrame = 0; @@ -368,8 +372,8 @@ void FuncScorp(int a, int nDamage, int nRun) { scorpion[nScorp].nAction = 1; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); scorpion[nScorp].nFrame = 0; return; @@ -380,7 +384,7 @@ void FuncScorp(int a, int nDamage, int nRun) return; } - short nBulletSprite = BuildBullet(nSprite, 16, 0, 0, -1, sprite[nSprite].ang, nTarget + 10000, 1) & 0xFFFF; + short nBulletSprite = BuildBullet(nSprite, 16, 0, 0, -1, pSprite->ang, nTarget + 10000, 1) & 0xFFFF; if (nBulletSprite > -1) { PlotCourseToSprite(nBulletSprite, nTarget); @@ -430,7 +434,7 @@ void FuncScorp(int a, int nDamage, int nRun) return; } - int nSpider = BuildSpider(-1, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].ang); + int nSpider = BuildSpider(-1, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->ang); if (nSpider != -1) { short nSpiderSprite = nSpider & 0xFFFF; @@ -449,13 +453,13 @@ void FuncScorp(int a, int nDamage, int nRun) case 9: { - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; if (bVal) { runlist_SubRunRec(scorpion[nScorp].nRun); - runlist_DoSubRunRec(sprite[nSprite].owner); - runlist_FreeRun(sprite[nSprite].lotag - 1); + runlist_DoSubRunRec(pSprite->owner); + runlist_FreeRun(pSprite->lotag - 1); mydeletesprite(nSprite); } @@ -470,11 +474,11 @@ void FuncScorp(int a, int nDamage, int nRun) FS_Pink_A: PlotCourseToSprite(nSprite, nTarget); - sprite[nSprite].ang += RandomSize(7) - 63; - sprite[nSprite].ang &= kAngleMask; + pSprite->ang += RandomSize(7) - 63; + pSprite->ang &= kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); FS_Pink_B: if (scorpion[nScorp].nCount) @@ -485,12 +489,12 @@ FS_Pink_B: { scorpion[nScorp].nCount = 45; - if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - GetSpriteHeight(nSprite), sprite[nSprite].sectnum, + if (cansee(pSprite->x, pSprite->y, pSprite->z - GetSpriteHeight(nSprite), pSprite->sectnum, sprite[nTarget].x, sprite[nTarget].y, sprite[nTarget].z - GetSpriteHeight(nTarget), sprite[nTarget].sectnum)) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->ang = GetMyAngle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); scorpion[nScorp].nIndex = RandomSize(2) + RandomSize(3); @@ -517,8 +521,8 @@ FS_Red: scorpion[nScorp].nCount = 30; scorpion[nScorp].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } END_PS_NS diff --git a/source/games/exhumed/src/set.cpp b/source/games/exhumed/src/set.cpp index eafc3b808..ece1f2d98 100644 --- a/source/games/exhumed/src/set.cpp +++ b/source/games/exhumed/src/set.cpp @@ -89,40 +89,42 @@ void InitSets() int BuildSet(short nSprite, int x, int y, int z, short nSector, short nAngle, int nChannel) { auto nSet = SetList.Reserve(1); + auto pSprite = &sprite[nSprite]; if (nSprite == -1) { nSprite = insertsprite(nSector, 120); + pSprite = &sprite[nSprite]; } else { changespritestat(nSprite, 120); - x = sprite[nSprite].x; - y = sprite[nSprite].y; - z = sector[sprite[nSprite].sectnum].floorz; - nAngle = sprite[nSprite].ang; + x = pSprite->x; + y = pSprite->y; + z = sector[pSprite->sectnum].floorz; + nAngle = pSprite->ang; } assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].shade = -12; - sprite[nSprite].clipdist = 110; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].xrepeat = 87; - sprite[nSprite].yrepeat = 96; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = nAngle; - sprite[nSprite].picnum = 1; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; + pSprite->cstat = 0x101; + pSprite->shade = -12; + pSprite->clipdist = 110; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->xrepeat = 87; + pSprite->yrepeat = 96; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = nAngle; + pSprite->picnum = 1; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -137,7 +139,7 @@ int BuildSet(short nSprite, int x, int y, int z, short nSector, short nAngle, in SetList[nSet].nChannel = nChannel; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nSet | 0x190000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nSet | 0x190000); // this isn't stored anywhere. runlist_AddRunRec(NewRun, nSet | 0x190000); @@ -151,35 +153,36 @@ int BuildSoul(int nSet) { int nSetSprite = SetList[nSet].nSprite; int nSprite = insertsprite(sprite[nSetSprite].sectnum, 0); + auto pSprite = &sprite[nSprite]; assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].cstat = 0x8000; - sprite[nSprite].shade = -127; - sprite[nSprite].xrepeat = 1; - sprite[nSprite].yrepeat = 1; - sprite[nSprite].pal = 0; - sprite[nSprite].clipdist = 5; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = seq_GetSeqPicnum(kSeqSet, 75, 0); - sprite[nSprite].ang = RandomSize(11); - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = (-256) - RandomSize(10); - sprite[nSprite].x = sprite[nSetSprite].x; - sprite[nSprite].y = sprite[nSetSprite].y; + pSprite->cstat = 0x8000; + pSprite->shade = -127; + pSprite->xrepeat = 1; + pSprite->yrepeat = 1; + pSprite->pal = 0; + pSprite->clipdist = 5; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = seq_GetSeqPicnum(kSeqSet, 75, 0); + pSprite->ang = RandomSize(11); + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = (-256) - RandomSize(10); + pSprite->x = sprite[nSetSprite].x; + pSprite->y = sprite[nSetSprite].y; - short nSector = sprite[nSprite].sectnum; - sprite[nSprite].z = (RandomSize(8) << 8) + 8192 + sector[nSector].ceilingz - GetSpriteHeight(nSprite); + short nSector = pSprite->sectnum; + pSprite->z = (RandomSize(8) << 8) + 8192 + sector[nSector].ceilingz - GetSpriteHeight(nSprite); - sprite[nSprite].hitag = nSet; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = 0; + pSprite->hitag = nSet; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = 0; // GrabTimeSlot(3); - sprite[nSprite].owner = runlist_AddRunRec(NewRun, nSprite | 0x230000); + pSprite->owner = runlist_AddRunRec(NewRun, nSprite | 0x230000); return nSprite | 0x230000; } @@ -187,6 +190,7 @@ int BuildSoul(int nSet) void FuncSoul(int a, int, int nRun) { short nSprite = RunData[nRun].nVal; + auto pSprite = &sprite[nSprite]; int nMessage = a & kMessageMask; @@ -196,28 +200,28 @@ void FuncSoul(int a, int, int nRun) { seq_MoveSequence(nSprite, SeqOffsets[kSeqSet] + 75, 0); - if (sprite[nSprite].xrepeat < 32) + if (pSprite->xrepeat < 32) { - sprite[nSprite].xrepeat++; - sprite[nSprite].yrepeat++; + pSprite->xrepeat++; + pSprite->yrepeat++; } - sprite[nSprite].extra += (nSprite & 0x0F) + 5; - sprite[nSprite].extra &= kAngleMask; + pSprite->extra += (nSprite & 0x0F) + 5; + pSprite->extra &= kAngleMask; - int nVel = bcos(sprite[nSprite].extra, -7); + int nVel = bcos(pSprite->extra, -7); - if (movesprite(nSprite, bcos(sprite[nSprite].ang) * nVel, bsin(sprite[nSprite].ang) * nVel, sprite[nSprite].zvel, 5120, 0, CLIPMASK0) & 0x10000) + if (movesprite(nSprite, bcos(pSprite->ang) * nVel, bsin(pSprite->ang) * nVel, pSprite->zvel, 5120, 0, CLIPMASK0) & 0x10000) { - int nSet = sprite[nSprite].hitag; + int nSet = pSprite->hitag; int nSetSprite = SetList[nSet].nSprite; - sprite[nSprite].cstat = 0; - sprite[nSprite].yrepeat = 1; - sprite[nSprite].xrepeat = 1; - sprite[nSprite].x = sprite[nSetSprite].x; - sprite[nSprite].y = sprite[nSetSprite].y; - sprite[nSprite].z = sprite[nSetSprite].z - (GetSpriteHeight(nSetSprite) >> 1); + pSprite->cstat = 0; + pSprite->yrepeat = 1; + pSprite->xrepeat = 1; + pSprite->x = sprite[nSetSprite].x; + pSprite->y = sprite[nSetSprite].y; + pSprite->z = sprite[nSetSprite].z - (GetSpriteHeight(nSetSprite) >> 1); mychangespritesect(nSprite, sprite[nSetSprite].sectnum); return; } @@ -240,6 +244,7 @@ void FuncSet(int a, int nDamage, int nRun) short nSprite = SetList[nSet].nSprite; short nAction = SetList[nSet].nAction; + auto pSprite = &sprite[nSprite]; bool bVal = false; @@ -274,10 +279,10 @@ void FuncSet(int a, int nDamage, int nRun) if (SetList[nSet].nHealth <= 0) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].cstat &= 0xFEFE; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->cstat &= 0xFEFE; SetList[nSet].nHealth = 0; @@ -309,7 +314,7 @@ void FuncSet(int a, int nDamage, int nRun) Gravity(nSprite); short nSeq = SeqOffsets[kSeqSet] + SetSeq[SetList[nSet].nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, SetList[nSet].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, SetList[nSet].nFrame); seq_MoveSequence(nSprite, nSeq, SetList[nSet].nFrame); if (nAction == 3) @@ -342,9 +347,9 @@ void FuncSet(int a, int nDamage, int nRun) int nMov = MoveCreature(nSprite); - pushmove_old(&sprite[nSprite].x, &sprite[nSprite].y, &sprite[nSprite].z, &sprite[nSprite].sectnum, sprite[nSprite].clipdist << 2, 5120, -5120, CLIPMASK0); + pushmove_old(&pSprite->x, &pSprite->y, &pSprite->z, &pSprite->sectnum, pSprite->clipdist << 2, 5120, -5120, CLIPMASK0); - if (sprite[nSprite].zvel > 4000) + if (pSprite->zvel > 4000) { if (nMov & 0x20000) { @@ -372,8 +377,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nFrame = 0; SetList[nSet].nTarget = nTarget; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); } } @@ -403,8 +408,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nIndex = 0; SetList[nSet].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; SetList[nSet].nTarget = FindPlayer(nSprite, 1000); } @@ -434,8 +439,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nIndex = 0; SetList[nSet].nAction = 7; SetList[nSet].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } case 1: @@ -445,8 +450,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nAction = 6; SetList[nSet].nFrame = 0; SetList[nSet].nRun = 5; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } default: @@ -465,14 +470,14 @@ void FuncSet(int a, int nDamage, int nRun) } // loc_338E2 - int nAngle = sprite[nSprite].ang & 0xFFF8; - sprite[nSprite].xvel = bcos(nAngle, -1); - sprite[nSprite].yvel = bsin(nAngle, -1); + int nAngle = pSprite->ang & 0xFFF8; + pSprite->xvel = bcos(nAngle, -1); + pSprite->yvel = bsin(nAngle, -1); if (SetList[nSet].nIndex2) { - sprite[nSprite].xvel *= 2; - sprite[nSprite].yvel *= 2; + pSprite->xvel *= 2; + pSprite->yvel *= 2; } if ((nMov & 0xC000) == 0x8000) @@ -482,31 +487,31 @@ void FuncSet(int a, int nDamage, int nRun) if (nSector >= 0) { - if ((sprite[nSprite].z - sector[nSector].floorz) < 55000) + if ((pSprite->z - sector[nSector].floorz) < 55000) { - if (sprite[nSprite].z > sector[nSector].ceilingz) + if (pSprite->z > sector[nSector].ceilingz) { SetList[nSet].nIndex = 1; SetList[nSet].nAction = 7; SetList[nSet].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } } } - sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang, -1); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang, -1); + pSprite->ang = (pSprite->ang + 256) & kAngleMask; + pSprite->xvel = bcos(pSprite->ang, -1); + pSprite->yvel = bsin(pSprite->ang, -1); break; } else if ((nMov & 0xC000) == 0xC000) { if (nTarget == (nMov & 0x3FFF)) { - int nAng = getangle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y); - if (AngleDiff(sprite[nSprite].ang, nAng) < 64) + int nAng = getangle(sprite[nTarget].x - pSprite->x, sprite[nTarget].y - pSprite->y); + if (AngleDiff(pSprite->ang, nAng) < 64) { SetList[nSet].nAction = 4; SetList[nSet].nFrame = 0; @@ -518,8 +523,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nIndex = 1; SetList[nSet].nAction = 7; SetList[nSet].nFrame = 0; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; return; } } @@ -571,7 +576,7 @@ void FuncSet(int a, int nDamage, int nRun) if (nFlag & 0x80) { // low 16 bits of returned var contains the sprite index, the high 16 the bullet number - int nBullet = BuildBullet(nSprite, 11, 0, 0, -1, sprite[nSprite].ang, nTarget + 10000, 1); + int nBullet = BuildBullet(nSprite, 11, 0, 0, -1, pSprite->ang, nTarget + 10000, 1); SetBulletEnemy(FixedToInt(nBullet), nTarget); // isolate the bullet number (shift off the sprite index) SetList[nSet].nRun--; @@ -590,18 +595,18 @@ void FuncSet(int a, int nDamage, int nRun) { if (SetList[nSet].nIndex) { - sprite[nSprite].zvel = -10000; + pSprite->zvel = -10000; } else { - sprite[nSprite].zvel = -(PlotCourseToSprite(nSprite, nTarget)); + pSprite->zvel = -(PlotCourseToSprite(nSprite, nTarget)); } SetList[nSet].nAction = 8; SetList[nSet].nFrame = 0; - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); } return; } @@ -624,13 +629,13 @@ void FuncSet(int a, int nDamage, int nRun) case 9: { - sprite[nSprite].xvel >>= 1; - sprite[nSprite].yvel >>= 1; + pSprite->xvel >>= 1; + pSprite->yvel >>= 1; if (bVal) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; PlotCourseToSprite(nSprite, nTarget); @@ -638,8 +643,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nFrame = 0; SetList[nSet].nRun = 5; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } return; } @@ -648,9 +653,9 @@ void FuncSet(int a, int nDamage, int nRun) { if (nFlag & 0x80) { - sprite[nSprite].z -= GetSpriteHeight(nSprite); + pSprite->z -= GetSpriteHeight(nSprite); BuildCreatureChunk(nSprite, seq_GetSeqPicnum(kSeqSet, 76, 0)); - sprite[nSprite].z += GetSpriteHeight(nSprite); + pSprite->z += GetSpriteHeight(nSprite); } if (bVal) @@ -670,7 +675,7 @@ void FuncSet(int a, int nDamage, int nRun) case 11: { - sprite[nSprite].cstat &= 0xFEFE; + pSprite->cstat &= 0xFEFE; return; } } @@ -686,8 +691,8 @@ void FuncSet(int a, int nDamage, int nRun) SetList[nSet].nFrame = 0; SetList[nSet].nCount = 100; SetList[nSet].nTarget = -1; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; } } } diff --git a/source/games/exhumed/src/snake.cpp b/source/games/exhumed/src/snake.cpp index 72985f612..d323b0742 100644 --- a/source/games/exhumed/src/snake.cpp +++ b/source/games/exhumed/src/snake.cpp @@ -75,9 +75,10 @@ void DestroySnake(int nSnake) for (int i = 0; i < kSnakeSprites; i++) { short nSprite = SnakeList[nSnake].nSprites[i]; + auto pSprite = &sprite[nSprite]; - runlist_DoSubRunRec(sprite[nSprite].lotag - 1); - runlist_DoSubRunRec(sprite[nSprite].owner); + runlist_DoSubRunRec(pSprite->lotag - 1); + runlist_DoSubRunRec(pSprite->owner); mydeletesprite(nSprite); } @@ -92,6 +93,7 @@ void DestroySnake(int nSnake) void ExplodeSnakeSprite(int nSprite, short nPlayer) { + auto pSprite = &sprite[nSprite]; short nDamage = BulletInfo[kWeaponStaff].nDamage; if (PlayerList[nPlayer].nDouble > 0) { @@ -99,16 +101,16 @@ void ExplodeSnakeSprite(int nSprite, short nPlayer) } // take a copy of this, to revert after call to runlist_RadialDamageEnemy() - short nOwner = sprite[nSprite].owner; - sprite[nSprite].owner = PlayerList[nPlayer].nSprite; + short nOwner = pSprite->owner; + pSprite->owner = PlayerList[nPlayer].nSprite; runlist_RadialDamageEnemy(nSprite, nDamage, BulletInfo[kWeaponStaff].nRadius); - sprite[nSprite].owner = nOwner; + pSprite->owner = nOwner; - BuildAnim(-1, 23, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, 40, 4); + BuildAnim(-1, 23, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, 40, 4); - AddFlash(sprite[nSprite].sectnum, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, 128); + AddFlash(pSprite->sectnum, pSprite->x, pSprite->y, pSprite->z, 128); StopSpriteSound(nSprite); } @@ -159,9 +161,10 @@ int BuildSnake(short nPlayer, short zVal) { BackUpBullet(&hitx, &hity, nAngle); nSprite = insertsprite(hitsect, 202); - sprite[nSprite].x = hitx; - sprite[nSprite].y = hity; - sprite[nSprite].z = hitz; + auto pSprite = &sprite[nSprite]; + pSprite->x = hitx; + pSprite->y = hity; + pSprite->z = hitz; ExplodeSnakeSprite(nSprite, nPlayer); mydeletesprite(nSprite); @@ -188,48 +191,49 @@ int BuildSnake(short nPlayer, short zVal) for (int i = 0; i < kSnakeSprites; i++) { nSprite = insertsprite(nViewSect, 202); + auto pSprite = &sprite[nSprite]; assert(nSprite >= 0 && nSprite < kMaxSprites); - sprite[nSprite].owner = nPlayerSprite; - sprite[nSprite].picnum = nPic; + pSprite->owner = nPlayerSprite; + pSprite->picnum = nPic; if (i == 0) { - sprite[nSprite].x = sprite[nPlayerSprite].x; - sprite[nSprite].y = sprite[nPlayerSprite].y; - sprite[nSprite].z = sprite[nPlayerSprite].z + zVal; - sprite[nSprite].xrepeat = 32; - sprite[nSprite].yrepeat = 32; - nViewSect = sprite[nSprite].sectnum; + pSprite->x = sprite[nPlayerSprite].x; + pSprite->y = sprite[nPlayerSprite].y; + pSprite->z = sprite[nPlayerSprite].z + zVal; + pSprite->xrepeat = 32; + pSprite->yrepeat = 32; + nViewSect = pSprite->sectnum; var_24 = nSprite; } else { - sprite[nSprite].x = sprite[var_24].x; - sprite[nSprite].y = sprite[var_24].y; - sprite[nSprite].z = sprite[var_24].z; - sprite[nSprite].xrepeat = 40 - 3*i; - sprite[nSprite].yrepeat = 40 - 3*i; + pSprite->x = sprite[var_24].x; + pSprite->y = sprite[var_24].y; + pSprite->z = sprite[var_24].z; + pSprite->xrepeat = 40 - 3*i; + pSprite->yrepeat = 40 - 3*i; } - sprite[nSprite].clipdist = 10; - sprite[nSprite].cstat = 0; - sprite[nSprite].shade = -64; - sprite[nSprite].pal = 0; - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].ang = sprite[nPlayerSprite].ang; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].hitag = 0; - sprite[nSprite].extra = -1; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].backuppos(); + pSprite->clipdist = 10; + pSprite->cstat = 0; + pSprite->shade = -64; + pSprite->pal = 0; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->ang = sprite[nPlayerSprite].ang; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->hitag = 0; + pSprite->extra = -1; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->backuppos(); SnakeList[nSnake].nSprites[i] = nSprite; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, ((nSnake << 8) | i) | 0x110000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, ((nSnake << 8) | i) | 0x110000); } SnakeList[nSnake].nRun = runlist_AddRunRec(NewRun, nSnake | 0x110000); @@ -265,9 +269,10 @@ int FindSnakeEnemy(short nSnake) short nPlayerSprite = PlayerList[nPlayer].nSprite; short nSprite = SnakeList[nSnake].nSprites[0]; // CHECKME + auto pSprite = &sprite[nSprite]; - short nAngle = sprite[nSprite].ang; - short nSector = sprite[nSprite].sectnum; + short nAngle = pSprite->ang; + short nSector = pSprite->sectnum; int esi = 2048; @@ -320,6 +325,7 @@ void FuncSnake(int a, int, int nRun) assert(nSnake >= 0 && nSnake < kMaxSnakes); short nSprite = SnakeList[nSnake].nSprites[0]; + auto pSprite = &sprite[nSprite]; seq_MoveSequence(nSprite, SeqOffsets[kSeqSnakehed], 0); @@ -332,8 +338,8 @@ void FuncSnake(int a, int, int nRun) { SEARCH_ENEMY: nMov = movesprite(nSprite, - 600 * bcos(sprite[nSprite].ang), - 600 * bsin(sprite[nSprite].ang), + 600 * bcos(pSprite->ang), + 600 * bsin(pSprite->ang), bsin(SnakeList[nSnake].sE, -5), 0, 0, CLIPMASK1); @@ -349,11 +355,11 @@ SEARCH_ENEMY: goto SEARCH_ENEMY; } - zVal = sprite[nSprite].z; + zVal = pSprite->z; nMov = AngleChase(nSprite, nEnemySprite, 1200, SnakeList[nSnake].sE, 32); - zVal = sprite[nSprite].z - zVal; + zVal = pSprite->z - zVal; } if (nMov) @@ -368,7 +374,7 @@ SEARCH_ENEMY: } else { - short nAngle = sprite[nSprite].ang; + short nAngle = pSprite->ang; int var_30 = -bcos(nAngle, 6); int var_34 = -bsin(nAngle, 6); @@ -377,11 +383,11 @@ SEARCH_ENEMY: SnakeList[nSnake].sE = (SnakeList[nSnake].sE + 64) & 0x7FF; int var_28 = (nAngle + 512) & kAngleMask; - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; - int x = sprite[nSprite].x; - int y = sprite[nSprite].y; - int z = sprite[nSprite].z; + int x = pSprite->x; + int y = pSprite->y; + int z = pSprite->z; for (int i = 7; i > 0; i--) { diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index d85559532..15b6f2991 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -212,18 +212,20 @@ void DrawView(double smoothRatio, bool sceneonly) pm_smoothratio = (int)smoothRatio; int nPlayerSprite = PlayerList[nLocalPlayer].nSprite; - int nPlayerOldCstat = sprite[nPlayerSprite].cstat; + auto pPlayerSprite = &sprite[nPlayerSprite]; + int nPlayerOldCstat = pPlayerSprite->cstat; int nDoppleOldCstat = sprite[nDoppleSprite[nLocalPlayer]].cstat; if (nSnakeCam >= 0 && !sceneonly) { int nSprite = SnakeList[nSnakeCam].nSprites[0]; + auto pSprite = &sprite[nSprite]; - playerX = sprite[nSprite].x; - playerY = sprite[nSprite].y; - playerZ = sprite[nSprite].z; - nSector = sprite[nSprite].sectnum; - nAngle = buildang(sprite[nSprite].ang); + playerX = pSprite->x; + playerY = pSprite->y; + playerZ = pSprite->z; + nSector = pSprite->sectnum; + nAngle = buildang(pSprite->ang); rotscrnang = buildang(0); SetGreenPal(); @@ -265,12 +267,12 @@ void DrawView(double smoothRatio, bool sceneonly) if (!bCamera) { - sprite[nPlayerSprite].cstat |= CSTAT_SPRITE_INVISIBLE; + pPlayerSprite->cstat |= CSTAT_SPRITE_INVISIBLE; sprite[nDoppleSprite[nLocalPlayer]].cstat |= CSTAT_SPRITE_INVISIBLE; } else { - sprite[nPlayerSprite].cstat |= CSTAT_SPRITE_TRANSLUCENT; + pPlayerSprite->cstat |= CSTAT_SPRITE_TRANSLUCENT; sprite[nDoppleSprite[nLocalPlayer]].cstat |= CSTAT_SPRITE_INVISIBLE; } pan = q16horiz(clamp(pan.asq16(), gi->playerHorizMin(), gi->playerHorizMax())); @@ -286,7 +288,7 @@ void DrawView(double smoothRatio, bool sceneonly) else { viewz = playerZ + nQuake[nLocalPlayer]; - int floorZ = sector[sprite[nPlayerSprite].sectnum].floorz; + int floorZ = sector[pPlayerSprite->sectnum].floorz; if (viewz > floorZ) viewz = floorZ; @@ -393,9 +395,9 @@ void DrawView(double smoothRatio, bool sceneonly) { nHeadStage = 5; - sprite[nPlayerSprite].cstat |= 0x8000; + pPlayerSprite->cstat |= 0x8000; - int ang2 = nCameraa.asbuild() - sprite[nPlayerSprite].ang; + int ang2 = nCameraa.asbuild() - pPlayerSprite->ang; if (ang2 < 0) ang2 = -ang2; @@ -451,7 +453,7 @@ void DrawView(double smoothRatio, bool sceneonly) twod->ClearScreen(); } - sprite[nPlayerSprite].cstat = nPlayerOldCstat; + pPlayerSprite->cstat = nPlayerOldCstat; sprite[nDoppleSprite[nLocalPlayer]].cstat = nDoppleOldCstat; RestoreInterpolations(); diff --git a/source/games/exhumed/src/wasp.cpp b/source/games/exhumed/src/wasp.cpp index ca04e0af6..0fff9f18b 100644 --- a/source/games/exhumed/src/wasp.cpp +++ b/source/games/exhumed/src/wasp.cpp @@ -88,8 +88,9 @@ void InitWasps() void SetWaspVel(short nSprite) { - sprite[nSprite].xvel = bcos(sprite[nSprite].ang); - sprite[nSprite].yvel = bsin(sprite[nSprite].ang); + auto pSprite = &sprite[nSprite]; + pSprite->xvel = bcos(pSprite->ang); + pSprite->yvel = bsin(pSprite->ang); } int BuildWasp(short nSprite, int x, int y, int z, short nSector, short nAngle) @@ -100,48 +101,50 @@ int BuildWasp(short nSprite, int x, int y, int z, short nSector, short nAngle) if (nSprite == -2) { bEggWasp = true; } + auto pSprite = &sprite[nSprite]; if (nSprite < 0) { nSprite = insertsprite(nSector, 107); assert(nSprite >= 0 && nSprite < kMaxSprites); + pSprite = &sprite[nSprite]; - sprite[nSprite].x = x; - sprite[nSprite].y = y; - sprite[nSprite].z = z; + pSprite->x = x; + pSprite->y = y; + pSprite->z = z; } else { - nAngle = sprite[nSprite].ang; + nAngle = pSprite->ang; changespritestat(nSprite, 107); } - sprite[nSprite].shade = -12; - sprite[nSprite].cstat = 0x101; - sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal; - sprite[nSprite].clipdist = 70; + pSprite->shade = -12; + pSprite->cstat = 0x101; + pSprite->pal = sector[pSprite->sectnum].ceilingpal; + pSprite->clipdist = 70; if (bEggWasp) { - sprite[nSprite].xrepeat = 20; - sprite[nSprite].yrepeat = 20; + pSprite->xrepeat = 20; + pSprite->yrepeat = 20; } else { - sprite[nSprite].xrepeat = 50; - sprite[nSprite].yrepeat = 50; + pSprite->xrepeat = 50; + pSprite->yrepeat = 50; } - sprite[nSprite].xoffset = 0; - sprite[nSprite].yoffset = 0; - sprite[nSprite].picnum = 1; - sprite[nSprite].ang = nAngle; - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; - sprite[nSprite].hitag = 0; - sprite[nSprite].lotag = runlist_HeadRun() + 1; - sprite[nSprite].extra = -1; + pSprite->xoffset = 0; + pSprite->yoffset = 0; + pSprite->picnum = 1; + pSprite->ang = nAngle; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; + pSprite->hitag = 0; + pSprite->lotag = runlist_HeadRun() + 1; + pSprite->extra = -1; // GrabTimeSlot(3); @@ -166,7 +169,7 @@ int BuildWasp(short nSprite, int x, int y, int z, short nSector, short nAngle) WaspList[nWasp].nVel = 0; WaspList[nWasp].nAngle2 = RandomSize(7) + 127; - sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nWasp | 0x1E0000); + pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nWasp | 0x1E0000); WaspList[nWasp].nRun = runlist_AddRunRec(NewRun, nWasp | 0x1E0000); @@ -178,6 +181,7 @@ void FuncWasp(int a, int nDamage, int nRun) { short nWasp = RunData[nRun].nVal; short nSprite = WaspList[nWasp].nSprite; + auto pSprite = &sprite[nSprite]; short nAction = WaspList[nWasp].nAction; short nTarget = -1; @@ -196,7 +200,7 @@ void FuncWasp(int a, int nDamage, int nRun) case 0xA0000: { - if (!(sprite[nSprite].cstat & 0x101)) + if (!(pSprite->cstat & 0x101)) return; nDamage = runlist_CheckRadialDamage(nSprite); @@ -223,12 +227,12 @@ void FuncWasp(int a, int nDamage, int nRun) } WaspList[nWasp].nAction = 1; - sprite[nSprite].ang += RandomSize(9) + 768; - sprite[nSprite].ang &= kAngleMask; + pSprite->ang += RandomSize(9) + 768; + pSprite->ang &= kAngleMask; WaspList[nWasp].nVel = 3000; - sprite[nSprite].zvel = (-20) - RandomSize(6); + pSprite->zvel = (-20) - RandomSize(6); } else { @@ -236,12 +240,12 @@ void FuncWasp(int a, int nDamage, int nRun) WaspList[nWasp].nAction = 4; WaspList[nWasp].nFrame = 0; - sprite[nSprite].cstat = 0; - sprite[nSprite].ang = (sprite[nSprite].ang + 1024) & kAngleMask; + pSprite->cstat = 0; + pSprite->ang = (pSprite->ang + 1024) & kAngleMask; SetWaspVel(nSprite); - sprite[nSprite].zvel = 512; + pSprite->zvel = 512; nCreaturesKilled++; } @@ -253,7 +257,7 @@ void FuncWasp(int a, int nDamage, int nRun) { short nSeq = SeqOffsets[kSeqWasp] + WaspSeq[nAction].a; - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, WaspList[nWasp].nFrame); + pSprite->picnum = seq_GetSeqPicnum2(nSeq, WaspList[nWasp].nFrame); seq_MoveSequence(nSprite, nSeq, WaspList[nWasp].nFrame); @@ -285,7 +289,7 @@ void FuncWasp(int a, int nDamage, int nRun) case 0: { - sprite[nSprite].zvel = bsin(WaspList[nWasp].nAngle, -4); + pSprite->zvel = bsin(WaspList[nWasp].nAngle, -4); WaspList[nWasp].nAngle += WaspList[nWasp].nAngle2; WaspList[nWasp].nAngle &= kAngleMask; @@ -301,7 +305,7 @@ void FuncWasp(int a, int nDamage, int nRun) } else { - sprite[nSprite].zvel = 0; + pSprite->zvel = 0; WaspList[nWasp].nAction = 1; WaspList[nWasp].nFrame = 0; WaspList[nWasp].nVel = 1500; @@ -346,8 +350,8 @@ void FuncWasp(int a, int nDamage, int nRun) short nSprite2 = (nChaseVal & 0x3FFF); if (nSprite2 == nTarget) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; runlist_DamageEnemy(nSprite2, nSprite, WaspList[nWasp].nDamage); WaspList[nWasp].nAction = 2; WaspList[nWasp].nFrame = 0; @@ -364,9 +368,9 @@ void FuncWasp(int a, int nDamage, int nRun) { if (bVal) { - sprite[nSprite].ang += RandomSize(9) + 768; - sprite[nSprite].ang &= kAngleMask; - sprite[nSprite].zvel = (-20) - RandomSize(6); + pSprite->ang += RandomSize(9) + 768; + pSprite->ang &= kAngleMask; + pSprite->zvel = (-20) - RandomSize(6); WaspList[nWasp].nAction = 1; WaspList[nWasp].nVel = 3000; @@ -380,9 +384,9 @@ void FuncWasp(int a, int nDamage, int nRun) if (nMove) { - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 1024; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 1024; WaspList[nWasp].nAction = 5; WaspList[nWasp].nFrame = 0; } @@ -391,21 +395,21 @@ void FuncWasp(int a, int nDamage, int nRun) } case 5: { - short nSector = sprite[nSprite].sectnum; + short nSector = pSprite->sectnum; - sprite[nSprite].z += sprite[nSprite].zvel; + pSprite->z += pSprite->zvel; - if (sprite[nSprite].z >= sector[nSector].floorz) + if (pSprite->z >= sector[nSector].floorz) { if (SectBelow[nSector] > -1) { BuildSplash(nSprite, nSector); - sprite[nSprite].cstat |= 0x8000; + pSprite->cstat |= 0x8000; } - sprite[nSprite].xvel = 0; - sprite[nSprite].yvel = 0; - sprite[nSprite].zvel = 0; + pSprite->xvel = 0; + pSprite->yvel = 0; + pSprite->zvel = 0; WaspList[nWasp].nAction = 6; WaspList[nWasp].nFrame = 0; runlist_SubRunRec(WaspList[nWasp].nRun); diff --git a/source/games/sw/src/rooms.cpp b/source/games/sw/src/rooms.cpp index 35c3ae366..3618c6da5 100644 --- a/source/games/sw/src/rooms.cpp +++ b/source/games/sw/src/rooms.cpp @@ -64,23 +64,24 @@ int COVERinsertsprite(short sectnum, short stat) { short spnum; spnum = insertsprite(sectnum, stat); + auto pSprite = &sprite[spnum]; PRODUCTION_ASSERT(spnum >= 0); - sprite[spnum].x = sprite[spnum].y = sprite[spnum].z = 0; - sprite[spnum].cstat = 0; - sprite[spnum].picnum = 0; - sprite[spnum].shade = 0; - sprite[spnum].pal = 0; - sprite[spnum].clipdist = 0; - sprite[spnum].xrepeat = sprite[spnum].yrepeat = 0; - sprite[spnum].xoffset = sprite[spnum].yoffset = 0; - sprite[spnum].ang = 0; - sprite[spnum].owner = -1; - sprite[spnum].xvel = sprite[spnum].yvel = sprite[spnum].zvel = 0; - sprite[spnum].lotag = 0; - sprite[spnum].hitag = 0; - sprite[spnum].extra = 0; + pSprite->x = sprite[spnum].y = sprite[spnum].z = 0; + pSprite->cstat = 0; + pSprite->picnum = 0; + pSprite->shade = 0; + pSprite->pal = 0; + pSprite->clipdist = 0; + pSprite->xrepeat = sprite[spnum].yrepeat = 0; + pSprite->xoffset = sprite[spnum].yoffset = 0; + pSprite->ang = 0; + pSprite->owner = -1; + pSprite->xvel = sprite[spnum].yvel = sprite[spnum].zvel = 0; + pSprite->lotag = 0; + pSprite->hitag = 0; + pSprite->extra = 0; return spnum; }