- added 0 checks to all divisions for calculating dudeSlope.

I had it happen once that an actor was targeting itself here which resulted in zero distance and a division by zero exception.
This commit is contained in:
Christoph Oelckers 2021-10-14 00:06:34 +02:00
parent 46d2c52b19
commit 88e86b4248
5 changed files with 5 additions and 5 deletions

View file

@ -281,7 +281,7 @@ static void beastThinkChase(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{
aiSetTarget(actor, actor->GetTarget());
actor->dudeSlope = DivScale(pTarget->z - pSprite->z, nDist, 10);
actor->dudeSlope = nDist == 0? 0 : DivScale(pTarget->z - pSprite->z, nDist, 10);
if (nDist < 0x1400 && nDist > 0xa00 && abs(nDeltaAngle) < 85 && (pTarget->flags & 2)
&& IsPlayerSprite(pTarget) && Chance(0x8000))
{

View file

@ -183,7 +183,7 @@ static void calebThinkChase(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{
aiSetTarget(actor, actor->GetTarget());
actor->dudeSlope = DivScale(pTarget->z - pSprite->z, nDist, 10);
actor->dudeSlope = nDist == 0 ? 0 : DivScale(pTarget->z-pSprite->z, nDist, 10);
if (nDist < 0x599 && abs(nDeltaAngle) < 28)
{
XSECTOR* pXSector;

View file

@ -297,7 +297,7 @@ static void cultThinkChase(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{
aiSetTarget(actor, actor->GetTarget());
actor->dudeSlope = DivScale(pTarget->z - pSprite->z, nDist, 10);
actor->dudeSlope = nDist == 0 ? 0 : DivScale(pTarget->z - pSprite->z, nDist, 10);
switch (pSprite->type) {
case kDudeCultistTommy:
if (nDist < 0x1e00 && nDist > 0xe00 && abs(nDeltaAngle) < 85 && !TargetNearExplosion(pTarget)

View file

@ -173,7 +173,7 @@ static void gillThinkChase(DBloodActor* actor)
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
{
aiSetTarget(actor, actor->GetTarget());
actor->dudeSlope = DivScale(pTarget->z - pSprite->z, nDist, 10);
actor->dudeSlope = nDist == 0 ? 0 : DivScale(pTarget->z - pSprite->z, nDist, 10);
if (nDist < 921 && abs(nDeltaAngle) < 28)
{
XSECTOR* pXSector;

View file

@ -568,7 +568,7 @@ static void unicultThinkChase(DBloodActor* actor)
if ((PlayClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(actor, false))
playGenDudeSound(actor, kGenDudeSndChasing);
actor->dudeSlope = DivScale(pTarget->z - pSprite->z, dist, 10);
actor->dudeSlope = dist == 0 ? 0 : DivScale(pTarget->z - pSprite->z, dist, 10);
int curWeapon = actor->genDudeExtra().curWeapon;
int weaponType = actor->genDudeExtra().weaponType;