- HitScan

This commit is contained in:
Christoph Oelckers 2021-09-04 20:09:56 +02:00
parent c2916259d7
commit 0466186440
17 changed files with 49 additions and 48 deletions

View file

@ -6629,7 +6629,7 @@ DBloodActor* actFireThing(DBloodActor* actor, int a2, int a3, int a4, int thingT
int z = pSprite->z + a3;
x += MulScale(pSprite->clipdist, Cos(pSprite->ang), 28);
y += MulScale(pSprite->clipdist, Sin(pSprite->ang), 28);
if (HitScan(pSprite, z, x - pSprite->x, y - pSprite->y, 0, CLIPMASK0, pSprite->clipdist) != -1)
if (HitScan(actor, z, x - pSprite->x, y - pSprite->y, 0, CLIPMASK0, pSprite->clipdist) != -1)
{
x = gHitInfo.hitx - MulScale(pSprite->clipdist << 1, Cos(pSprite->ang), 28);
y = gHitInfo.hity - MulScale(pSprite->clipdist << 1, Sin(pSprite->ang), 28);
@ -6746,7 +6746,7 @@ DBloodActor* actFireMissile(DBloodActor* actor, int a2, int a3, int a4, int a5,
int clipdist = pMissileInfo->clipDist + pSprite->clipdist;
x += MulScale(clipdist, Cos(pSprite->ang), 28);
y += MulScale(clipdist, Sin(pSprite->ang), 28);
int hit = HitScan(pSprite, z, x - pSprite->x, y - pSprite->y, 0, CLIPMASK0, clipdist);
int hit = HitScan(actor, z, x - pSprite->x, y - pSprite->y, 0, CLIPMASK0, clipdist);
if (hit != -1)
{
if (hit == 3 || hit == 0)
@ -7073,7 +7073,7 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6,
a4 += Random3(4000);
a5 += Random3(4000);
a6 += Random3(4000);
if (HitScan(pSprite, gHitInfo.hitz, a4, a5, a6, CLIPMASK1, t) == 0)
if (HitScan(actor, gHitInfo.hitz, a4, a5, a6, CLIPMASK1, t) == 0)
{
if (approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y) <= t)
{

View file

@ -138,7 +138,7 @@ bool CanMove(DBloodActor* actor, DBloodActor* target, int nAngle, int nRange)
int x = pSprite->x;
int y = pSprite->y;
int z = pSprite->z;
HitScan(pSprite, z, bcos(nAngle), bsin(nAngle), 0, CLIPMASK0, nRange);
HitScan(actor, z, bcos(nAngle), bsin(nAngle), 0, CLIPMASK0, nRange);
int nDist = approxDist(x - gHitInfo.hitx, y - gHitInfo.hity);
if (nDist - (pSprite->clipdist << 2) < nRange)
{

View file

@ -98,7 +98,7 @@ void StompSeqCallback(int, DBloodActor* actor1)
const bool newSectCheckMethod = !cl_bloodvanillaenemies && !VanillaMode(); // use new sector checking logic
GetClosestSpriteSectors(nSector, x, y, vc, sectmap, nullptr, newSectCheckMethod);
char v4 = 0;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor1, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
DBloodActor* actor2 = nullptr;
actHitcodeToData(hit, &gHitInfo, &actor2);
if (hit == 3 && actor2)
@ -291,7 +291,7 @@ static void beastThinkChase(DBloodActor* actor)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
if (pXTarget->health > (unsigned)gPlayerTemplate[0].startHealth / 2)
{
switch (hit)
@ -329,7 +329,7 @@ static void beastThinkChase(DBloodActor* actor)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -192,7 +192,7 @@ static void calebThinkChase(DBloodActor* actor)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -422,7 +422,7 @@ static void cerberusThinkChase(DBloodActor* actor)
}
else if (nDist < 0x200 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (pSprite->type) {
case kDudeCerberusTwoHead:
switch (hit) {

View file

@ -304,7 +304,7 @@ static void cultThinkChase(DBloodActor* actor)
&& (pTarget->flags & 2) && gGameOptions.nDifficulty > 2 && IsPlayerSprite(pTarget) && gPlayer[pTarget->type - kDudePlayer1].isRunning
&& Chance(0x8000))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -325,7 +325,7 @@ static void cultThinkChase(DBloodActor* actor)
}
else if (nDist < 0x4600 && abs(nDeltaAngle) < 28)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -372,7 +372,7 @@ static void cultThinkChase(DBloodActor* actor)
&& (pTarget->flags & 2) && gGameOptions.nDifficulty >= 2 && IsPlayerSprite(pTarget) && !gPlayer[pTarget->type - kDudePlayer1].isRunning
&& Chance(0x8000))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -393,7 +393,7 @@ static void cultThinkChase(DBloodActor* actor)
}
else if (nDist < 0x3200 && abs(nDeltaAngle) < 28)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -440,7 +440,7 @@ static void cultThinkChase(DBloodActor* actor)
&& (pTarget->flags & 2) && gGameOptions.nDifficulty > 2 && IsPlayerSprite(pTarget) && gPlayer[pTarget->type - kDudePlayer1].isRunning
&& Chance(0x8000))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -461,7 +461,7 @@ static void cultThinkChase(DBloodActor* actor)
}
else if (nDist < 0x3200 && abs(nDeltaAngle) < 28)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -507,7 +507,7 @@ static void cultThinkChase(DBloodActor* actor)
if (nDist < 0x2c00 && nDist > 0x1400 && abs(nDeltaAngle) < 85
&& (pTarget->flags & 2) && IsPlayerSprite(pTarget))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -528,7 +528,7 @@ static void cultThinkChase(DBloodActor* actor)
else if (nDist < 0x1400 && abs(nDeltaAngle) < 85
&& (pTarget->flags & 2) && IsPlayerSprite(pTarget))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -552,7 +552,7 @@ static void cultThinkChase(DBloodActor* actor)
&& (pTarget->flags & 2) && gGameOptions.nDifficulty > 2 && IsPlayerSprite(pTarget) && gPlayer[pTarget->type - kDudePlayer1].isRunning
&& Chance(0x8000))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -573,7 +573,7 @@ static void cultThinkChase(DBloodActor* actor)
}
else if (nDist < 0x3200 && abs(nDeltaAngle) < 28)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -401,7 +401,7 @@ static void gargThinkChase(DBloodActor* actor)
case kDudeGargoyleFlesh:
if (nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -426,7 +426,7 @@ static void gargThinkChase(DBloodActor* actor)
}
else if (nDist < 0x400 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -460,7 +460,7 @@ static void gargThinkChase(DBloodActor* actor)
case kDudeGargoyleStone:
if (nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -485,7 +485,7 @@ static void gargThinkChase(DBloodActor* actor)
}
else if (nDist < 0x400 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -378,7 +378,7 @@ static void ghostThinkChase(DBloodActor* actor)
switch (pSprite->type) {
case kDudePhantasm:
if (nDist < 0x2000 && nDist > 0x1000 && abs(nDeltaAngle) < 85) {
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -398,7 +398,7 @@ static void ghostThinkChase(DBloodActor* actor)
}
else if (nDist < 0x400 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -182,7 +182,7 @@ static void gillThinkChase(DBloodActor* actor)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -78,7 +78,7 @@ void SpidBiteSeqCallback(int, DBloodActor* actor)
XSPRITE* pXTarget = &target->x();
if (IsPlayerSprite(pTarget))
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
if (hit == 3 && gHitInfo.hitactor->IsPlayerActor())
{
dz += pTarget->z - pSprite->z;

View file

@ -149,7 +149,7 @@ static bool genDudeAdjustSlope(DBloodActor* actor, int dist, int weaponType, int
for (int i = -8191; i < 8192; i += by)
{
HitScan(pSprite, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), i, clipMask, dist);
HitScan(actor, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), i, clipMask, dist);
if (!fStart && actor->GetTarget() == gHitInfo.hitactor) fStart = i;
else if (fStart && actor->GetTarget() != gHitInfo.hitactor)
{
@ -587,7 +587,7 @@ static void unicultThinkChase(DBloodActor* actor)
}
else if (dist < 12264 && dist > 7680 && !spriteIsUnderwater(actor, false) && curWeapon != kModernThingEnemyLifeLeech)
{
int pHit = HitScan(pSprite, pSprite->z, dx, dy, 0, 16777280, 0);
int pHit = HitScan(actor, pSprite->z, dx, dy, 0, 16777280, 0);
switch (pHit) {
case 0:
case 4:
@ -776,9 +776,9 @@ static void unicultThinkChase(DBloodActor* actor)
{
int objDist = -1; int targetDist = -1; int hit = -1;
if (weaponType == kGenDudeWeaponHitscan)
hit = HitScan(pSprite, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), actor->dudeSlope, CLIPMASK1, dist);
hit = HitScan(actor, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), actor->dudeSlope, CLIPMASK1, dist);
else if (weaponType == kGenDudeWeaponMissile)
hit = HitScan(pSprite, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), actor->dudeSlope, CLIPMASK0, dist);
hit = HitScan(actor, pSprite->z, bcos(pSprite->ang), bsin(pSprite->ang), actor->dudeSlope, CLIPMASK0, dist);
if (hit >= 0)
{

View file

@ -149,7 +149,7 @@ static void zombfThinkChase(DBloodActor* actor)
aiSetTarget(actor, actor->GetTarget());
if (nDist < 0x1400 && nDist > 0xe00 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -168,7 +168,7 @@ static void zombfThinkChase(DBloodActor* actor)
}
else if (nDist < 0x1400 && nDist > 0x600 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
@ -187,7 +187,7 @@ static void zombfThinkChase(DBloodActor* actor)
}
else if (nDist < 0x400 && abs(nDeltaAngle) < 85)
{
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
int hit = HitScan(actor, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:

View file

@ -378,9 +378,10 @@ bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int
return 1;
}
int HitScan(spritetype *pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int nRange)
int HitScan(DBloodActor *actor, int z, int dx, int dy, int dz, unsigned int nMask, int nRange)
{
assert(pSprite != NULL);
assert(actor != NULL);
auto pSprite = &actor->s();
assert(dx != 0 || dy != 0);
gHitInfo.clearObj();
int x = pSprite->x;

View file

@ -81,7 +81,7 @@ int GetWallAngle(int nWall);
int GetWallAngle(walltype* pWall);
void GetWallNormal(int nWall, int *pX, int *pY);
bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int x2, int y2, int z2, int *ix, int *iy, int *iz);
int HitScan(spritetype *pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8);
int HitScan(DBloodActor *pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8);
int VectorScan(spritetype *pSprite, int nOffset, int nZOffset, int dx, int dy, int dz, int nRange, int ac);
void GetZRange(spritetype *pSprite, int *ceilZ, Collision *ceilHit, int *floorZ, Collision *floorHit, int nDist, unsigned int nMask, unsigned int nClipParallax = 0);
void GetZRangeAtXYZ(int x, int y, int z, int nSector, int *ceilZ, Collision *ceilHit, int *floorZ, Collision *floorHit, int nDist, unsigned int nMask, unsigned int nClipParallax = 0);

View file

@ -1334,7 +1334,7 @@ void nnExtProcessSuperSprites()
if (!vector)
pSightSpr->cstat |= CSTAT_SPRITE_BLOCK_HITSCAN;
HitScan(pPlaySprite, pPlayer->zWeapon, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, CLIPMASK0 | CLIPMASK1, 0);
HitScan(pPlayer->actor(), pPlayer->zWeapon, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, CLIPMASK0 | CLIPMASK1, 0);
//VectorScan(pPlaySprite, 0, pPlayer->zWeapon, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, 0, 1);
@ -4600,17 +4600,17 @@ bool condCheckSprite(DBloodActor* aCond, int cmpOp, bool PUSH)
}
if ((pPlayer = getPlayerById(pSpr->type)) != NULL)
var = HitScan(pSpr, pPlayer->zWeapon, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, arg1, arg3 << 1);
var = HitScan(objActor, pPlayer->zWeapon, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, arg1, arg3 << 1);
else if (objActor->IsDudeActor())
var = HitScan(pSpr, pSpr->z, bcos(pSpr->ang), bsin(pSpr->ang), (!objActor->hasX()) ? 0 : objActor->dudeSlope, arg1, arg3 << 1);
else if ((var2 & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FLOOR) {
var = HitScan(objActor, pSpr->z, bcos(pSpr->ang), bsin(pSpr->ang), (!objActor->hasX()) ? 0 : objActor->dudeSlope, arg1, arg3 << 1);
else if ((var2 & CSTAT_SPRITE_ALIGNMENT_MASK) == CSTAT_SPRITE_ALIGNMENT_FLOOR)
{
var3 = (var2 & 0x0008) ? 0x10000 << 1 : -(0x10000 << 1);
var = HitScan(pSpr, pSpr->z, Cos(pSpr->ang) >> 16, Sin(pSpr->ang) >> 16, var3, arg1, arg3 << 1);
var = HitScan(objActor, pSpr->z, Cos(pSpr->ang) >> 16, Sin(pSpr->ang) >> 16, var3, arg1, arg3 << 1);
}
else
{
var = HitScan(pSpr, pSpr->z, bcos(pSpr->ang), bsin(pSpr->ang), 0, arg1, arg3 << 1);
var = HitScan(objActor, pSpr->z, bcos(pSpr->ang), bsin(pSpr->ang), 0, arg1, arg3 << 1);
}
if (var >= 0)
@ -7638,7 +7638,7 @@ bool nnExtCanMove(DBloodActor* actor, DBloodActor* target, int nAngle, int nRang
{
auto pSprite = &actor->s();
int x = pSprite->x, y = pSprite->y, z = pSprite->z, nSector = pSprite->sectnum;
HitScan(pSprite, z, Cos(nAngle) >> 16, Sin(nAngle) >> 16, 0, CLIPMASK0, nRange);
HitScan(actor, z, Cos(nAngle) >> 16, Sin(nAngle) >> 16, 0, CLIPMASK0, nRange);
int nDist = approxDist(x - gHitInfo.hitx, y - gHitInfo.hity);
if (target != nullptr && nDist - (pSprite->clipdist << 2) < nRange)
return (target == gHitInfo.hitactor);

View file

@ -1248,7 +1248,7 @@ int ActionScan(PLAYER *pPlayer, int *a2, int *a3)
int x = bcos(pSprite->ang);
int y = bsin(pSprite->ang);
int z = pPlayer->slope;
int hit = HitScan(pSprite, pPlayer->zView, x, y, z, 0x10000040, 128);
int hit = HitScan(pPlayer->actor(), pPlayer->zView, x, y, z, 0x10000040, 128);
int hitDist = approxDist(pSprite->x-gHitInfo.hitx, pSprite->y-gHitInfo.hity)>>4;
if (hitDist < 64)
{

View file

@ -118,7 +118,7 @@ void viewDrawAimedPlayerName(void)
if (!cl_idplayers || (gView->aim.dx == 0 && gView->aim.dy == 0))
return;
int hit = HitScan(gView->pSprite, gView->zView, gView->aim.dx, gView->aim.dy, gView->aim.dz, CLIPMASK0, 512);
int hit = HitScan(gView->actor(), gView->zView, gView->aim.dx, gView->aim.dy, gView->aim.dz, CLIPMASK0, 512);
if (hit == 3)
{
if (gHitInfo.hitactor && gHitInfo.hitactor->IsPlayerActor())