diff --git a/source/blood/src/aibeast.cpp b/source/blood/src/aibeast.cpp index 1341a6152..5d1c1efbc 100644 --- a/source/blood/src/aibeast.cpp +++ b/source/blood/src/aibeast.cpp @@ -293,8 +293,7 @@ static void beastThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - int nXSprite = sprite[pXSprite->reference].extra; - gDudeSlope[nXSprite] = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope() = divscale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 0x1400 && nDist > 0xa00 && klabs(nDeltaAngle) < 85 && (pTarget->flags&2) && IsPlayerSprite(pTarget) && Chance(0x8000)) { diff --git a/source/blood/src/aicaleb.cpp b/source/blood/src/aicaleb.cpp index 44e8aef59..8f9a5d62c 100644 --- a/source/blood/src/aicaleb.cpp +++ b/source/blood/src/aicaleb.cpp @@ -196,8 +196,7 @@ static void calebThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - int nXSprite = sprite[pXSprite->reference].extra; - gDudeSlope[nXSprite] = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope() = divscale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 0x599 && klabs(nDeltaAngle) < 28) { XSECTOR *pXSector; diff --git a/source/blood/src/aicult.cpp b/source/blood/src/aicult.cpp index 38d0c3e05..6783f800a 100644 --- a/source/blood/src/aicult.cpp +++ b/source/blood/src/aicult.cpp @@ -314,8 +314,7 @@ static void cultThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - int nXSprite = sprite[pXSprite->reference].extra; - gDudeSlope[nXSprite] = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope() = divscale(pTarget->z-pSprite->z, nDist, 10); switch (pSprite->type) { case kDudeCultistTommy: if (nDist < 0x1e00 && nDist > 0xe00 && klabs(nDeltaAngle) < 85 && !TargetNearExplosion(pTarget) diff --git a/source/blood/src/aigilbst.cpp b/source/blood/src/aigilbst.cpp index 318c1b510..9e8ebfff5 100644 --- a/source/blood/src/aigilbst.cpp +++ b/source/blood/src/aigilbst.cpp @@ -185,8 +185,7 @@ static void gillThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - int nXSprite = sprite[pXSprite->reference].extra; - gDudeSlope[nXSprite] = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope() = divscale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 921 && klabs(nDeltaAngle) < 28) { XSECTOR *pXSector; diff --git a/source/blood/src/aiunicult.cpp b/source/blood/src/aiunicult.cpp index 3e91aafcc..06070932e 100644 --- a/source/blood/src/aiunicult.cpp +++ b/source/blood/src/aiunicult.cpp @@ -140,26 +140,40 @@ static void forcePunch(DBloodActor* actor) return true; }*/ -bool genDudeAdjustSlope(spritetype* pSprite, XSPRITE* pXSprite, int dist, int weaponType, int by) { - if (spriRangeIsFine(pXSprite->target)) { - int fStart = 0; int fEnd = 0; GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); +static bool genDudeAdjustSlope(DBloodActor* actor, int dist, int weaponType, int by = 64) +{ + spritetype* pSprite = &actor->s(); + XSPRITE* pXSprite = &actor->x(); + if (spriRangeIsFine(pXSprite->target)) + { + int fStart = 0; + int fEnd = 0; + GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); unsigned int clipMask = (weaponType == kGenDudeWeaponMissile) ? CLIPMASK0 : CLIPMASK1; - for (int i = -8191; i < 8192; i += by) { + + for (int i = -8191; i < 8192; i += by) + { HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), i, clipMask, dist); if (!fStart && pXSprite->target == gHitInfo.hitsprite) fStart = i; - else if (fStart && pXSprite->target != gHitInfo.hitsprite) { fEnd = i; break; } + else if (fStart && pXSprite->target != gHitInfo.hitsprite) + { + fEnd = i; + break; + } } - if (fStart != fEnd) { - + if (fStart != fEnd) + { if (weaponType == kGenDudeWeaponHitscan) - gDudeSlope[pSprite->extra] = fStart - ((fStart - fEnd) >> 2); - else if (weaponType == kGenDudeWeaponMissile) { + { + actor->dudeSlope() = fStart - ((fStart - fEnd) >> 2); + } + else if (weaponType == kGenDudeWeaponMissile) + { const MissileType* pMissile = &missileInfo[pExtra->curWeapon - kMissileBase]; - gDudeSlope[pSprite->extra] = (fStart - ((fStart - fEnd) >> 2)) - (pMissile->clipDist << 1); + actor->dudeSlope() = (fStart - ((fStart - fEnd) >> 2)) - (pMissile->clipDist << 1); } - //viewSetSystemMessage("!!!! FOUND, SLOPE %d, RANGE %d,%d", gDudeSlope[pSprite->extra], fStart, fEnd); return true; } } @@ -415,8 +429,8 @@ static void unicultThinkGoto(DBloodActor* actor) static void unicultThinkChase(DBloodActor* actor) { - auto pXSprite = &actor->x(); - auto pSprite = &actor->s(); + auto const pXSprite = &actor->x(); + auto const pSprite = &actor->s(); if (pSprite->type < kDudeBase || pSprite->type >= kDudeMax) return; else if (pXSprite->target < 0 || pXSprite->target >= kMaxSprites) { if(spriteIsUnderwater(pSprite,false)) aiGenDudeNewState(pSprite, &genDudeGotoW); @@ -499,7 +513,7 @@ static void unicultThinkChase(DBloodActor* actor) if ((gFrameClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(pSprite, false)) playGenDudeSound(pSprite, kGenDudeSndChasing); - gDudeSlope[pSprite->extra] = divscale(pTarget->z - pSprite->z, dist, 10); + actor->dudeSlope() = divscale(pTarget->z - pSprite->z, dist, 10); short curWeapon = gGenDudeExtra[pSprite->index].curWeapon; short weaponType = gGenDudeExtra[pSprite->index].weaponType; spritetype* pLeech = leechIsDropped(pSprite); const VECTORDATA* meleeVector = &gVectorData[22]; @@ -668,9 +682,9 @@ static void unicultThinkChase(DBloodActor* actor) if (pExtra->canWalk) { int objDist = -1; int targetDist = -1; int hit = -1; if (weaponType == kGenDudeWeaponHitscan) - hit = HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), gDudeSlope[pSprite->extra], CLIPMASK1, dist); + hit = HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope(), CLIPMASK1, dist); else if (weaponType == kGenDudeWeaponMissile) - hit = HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), gDudeSlope[pSprite->extra], CLIPMASK0, dist); + hit = HitScan(pSprite, pSprite->z, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope(), CLIPMASK0, dist); if (hit >= 0) { targetDist = dist - (pTarget->clipdist << 2); @@ -705,7 +719,7 @@ static void unicultThinkChase(DBloodActor* actor) fallthrough__; case 2: //if (hit == 2) viewSetSystemMessage("FLOOR HIT %d", gHitInfo.hitsect); - if (weaponType != kGenDudeWeaponMissile && genDudeAdjustSlope(pSprite, pXSprite, dist, weaponType) + if (weaponType != kGenDudeWeaponMissile && genDudeAdjustSlope(actor, dist, weaponType) && dist < (int)(6000 + Random(2000)) && pExtra->baseDispersion < kGenDudeMaxDispersion >> 1) break; else if (spriteIsUnderwater(pSprite)) aiGenDudeNewState(pSprite, &genDudeChaseW); @@ -741,20 +755,26 @@ static void unicultThinkChase(DBloodActor* actor) } break; } - if (pSprite->x < pHSprite->x) { + if (pSprite->x < pHSprite->x) + { if (Chance(0x9000) && pTarget->x > pHSprite->x) pXSprite->dodgeDir = -1; else pXSprite->dodgeDir = 1; - } else { + } + else + { if (Chance(0x9000) && pTarget->x > pHSprite->x) pXSprite->dodgeDir = 1; else pXSprite->dodgeDir = -1; } } break; default: - if (pSprite->x < pHSprite->x) { + if (pSprite->x < pHSprite->x) + { if (Chance(0x9000) && pTarget->x > pHSprite->x) pXSprite->dodgeDir = -1; else pXSprite->dodgeDir = 1; - } else { + } + else + { if (Chance(0x9000) && pTarget->x > pHSprite->x) pXSprite->dodgeDir = 1; else pXSprite->dodgeDir = -1; } @@ -763,17 +783,19 @@ static void unicultThinkChase(DBloodActor* actor) return; } break; - } else if (weaponType == kGenDudeWeaponHitscan && hscn) { - if (genDudeAdjustSlope(pSprite, pXSprite, dist, weaponType)) break; - VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), gDudeSlope[pSprite->extra], dist, 1); + } + else if (weaponType == kGenDudeWeaponHitscan && hscn) + { + if (genDudeAdjustSlope(actor, dist, weaponType)) break; + VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope(), dist, 1); if (pXSprite->target == gHitInfo.hitsprite) break; bool immune = nnExtIsImmune(pHSprite, gVectorData[curWeapon].dmgType); - if (!(pXHSprite != NULL && (!immune || (immune && pHSprite->statnum == kStatThing && pXHSprite->Vector)) && !pXHSprite->locked)) { - + if (!(pXHSprite != NULL && (!immune || (immune && pHSprite->statnum == kStatThing && pXHSprite->Vector)) && !pXHSprite->locked)) + { if ((approxDist(gHitInfo.hitx - pSprite->x, gHitInfo.hity - pSprite->y) <= 1500 && !blck) - || (dist <= (int)(pExtra->fireDist / ClipLow(Random(4), 1)))) { - + || (dist <= (int)(pExtra->fireDist / ClipLow(Random(4), 1)))) + { //viewSetSystemMessage("GO CHASE"); if (spriteIsUnderwater(pSprite)) aiGenDudeNewState(pSprite, &genDudeChaseW); else aiGenDudeNewState(pSprite, &genDudeChaseL); @@ -817,7 +839,7 @@ static void unicultThinkChase(DBloodActor* actor) case 4: if (hit == 4 && weaponType == kGenDudeWeaponHitscan && hscn) { bool masked = (pHWall->cstat & CSTAT_WALL_MASKED); - if (masked) VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), gDudeSlope[pSprite->extra], dist, 1); + if (masked) VectorScan(pSprite, 0, 0, CosScale16(pSprite->ang), SinScale16(pSprite->ang), actor->dudeSlope(), dist, 1); //viewSetSystemMessage("WALL VHIT: %d", gHitInfo.hitwall); if ((pXSprite->target != gHitInfo.hitsprite) && (pHWall->type != kWallGib || !masked || pXHWall == NULL || !pXHWall->triggerVector || pXHWall->locked)) { diff --git a/source/blood/src/aiunicult.h b/source/blood/src/aiunicult.h index 78bcaa2dc..44ba1fc3f 100644 --- a/source/blood/src/aiunicult.h +++ b/source/blood/src/aiunicult.h @@ -233,7 +233,6 @@ int getDispersionModifier(spritetype* pSprite, int minDisp, int maxDisp); void scaleDamage(XSPRITE* pXSprite); bool genDudePrepare(spritetype* pSprite, int propId); void genDudeUpdate(spritetype* pSprite); -bool genDudeAdjustSlope(spritetype* pSprite, XSPRITE* pXSprite, int dist, int weaponType, int by = 64); void genDudePostDeath(spritetype* pSprite, DAMAGE_TYPE damageType, int damage); void aiGenDudeInitSprite(spritetype* pSprite, XSPRITE* pXSprite); #endif diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index 79d1e4cd2..9c107de2b 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -3040,7 +3040,7 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) { bool condCheckSprite(XSPRITE* pXCond, int cmpOp, bool PUSH) { UNREFERENCED_PARAMETER(PUSH); - + auto actor = &bloodActors[pXCond->reference]; int var = -1; PLAYER* pPlayer = NULL; bool retn = false; int cond = pXCond->data1 - kCondSpriteBase; int arg1 = pXCond->data2; int arg2 = pXCond->data3; int arg3 = pXCond->data4; @@ -3094,7 +3094,7 @@ bool condCheckSprite(XSPRITE* pXCond, int cmpOp, bool PUSH) { if ((pPlayer = getPlayerById(pSpr->type)) != NULL) var = HitScan(pSpr, pPlayer->zWeapon - pSpr->z, pPlayer->aim.dx, pPlayer->aim.dy, pPlayer->aim.dz, arg1, arg3 << 1); else if (IsDudeSprite(pSpr)) - var = HitScan(pSpr, pSpr->z, CosScale16(pSpr->ang), SinScale16(pSpr->ang), gDudeSlope[pSpr->extra], arg1, arg3 << 1); + var = HitScan(pSpr, pSpr->z, CosScale16(pSpr->ang), SinScale16(pSpr->ang), actor->dudeSlope(), arg1, arg3 << 1); else var = HitScan(pSpr, pSpr->z, CosScale16(pSpr->ang), SinScale16(pSpr->ang), 0, arg1, arg3 << 1);