Tidy Mummy AI code and fix incorrect branch

This commit is contained in:
sirlemonhead 2019-12-05 20:34:52 +00:00 committed by Christoph Oelckers
parent 63120a1ca4
commit 77a2625a85

View file

@ -146,26 +146,13 @@ void CheckMummyRevive(short nMummy)
continue; continue;
} }
int x = sprite[nSprite2].x - sprite[nSprite].x; int x = klabs(sprite[nSprite2].x - sprite[nSprite].x) >> 8;
if (x < 0) { int y = klabs(sprite[nSprite2].y - sprite[nSprite].y) >> 8;
x = -x;
}
x = x >> 8;
int y = sprite[nSprite2].y - sprite[nSprite].y;
if (y < 0) {
y = -y;
}
y = y >> 8;
if (x <= 20 && y <= 20) if (x <= 20 && y <= 20)
{ {
int bCanSee = cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - 8192, sprite[nSprite].sectnum, if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - 8192, sprite[nSprite].sectnum,
sprite[nSprite2].x, sprite[nSprite2].y, sprite[nSprite2].z - 8192, sprite[nSprite2].sectnum); sprite[nSprite2].x, sprite[nSprite2].y, sprite[nSprite2].z - 8192, sprite[nSprite2].sectnum))
if (bCanSee)
{ {
sprite[nSprite2].cstat = 0; sprite[nSprite2].cstat = 0;
MummyList[i].nAction = 6; MummyList[i].nAction = 6;
@ -215,7 +202,7 @@ void FuncMummy(int a, int nDamage, int nRun)
if (nTarget != -1 && nAction < 4) if (nTarget != -1 && nAction < 4)
{ {
if (!sprite[nTarget].cstat && nAction) if ((!sprite[nTarget].cstat) && nAction)
{ {
MummyList[nMummy].nAction = 0; MummyList[nMummy].nAction = 0;
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
@ -233,21 +220,23 @@ void FuncMummy(int a, int nDamage, int nRun)
{ {
case 0: case 0:
{ {
if ((MummyList[nMummy].F & 31) == (totalmoves & 31)) if ((MummyList[nMummy].F & 0x1F) == (totalmoves & 0x1F))
{ {
sprite[nSprite].cstat = 0x101; sprite[nSprite].cstat = 0x101;
if (nTarget < 0) if (nTarget < 0)
{ {
int nPlayerSprite = FindPlayer(nSprite, 100); int nTarget = FindPlayer(nSprite, 100);
if (nPlayerSprite >= 0) if (nTarget >= 0)
{ {
D3PlayFX(StaticSound[kSound7], nSprite); D3PlayFX(StaticSound[kSound7], nSprite);
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
MummyList[nMummy].nTarget = nPlayerSprite; MummyList[nMummy].nTarget = nTarget;
MummyList[nMummy].nAction = 1; MummyList[nMummy].nAction = 1;
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512) >> 2;
sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> 2;
MummyList[nMummy].G = 90; MummyList[nMummy].G = 90;
sprite[nSprite].xvel = Cos(sprite[nSprite].ang) >> 2;
sprite[nSprite].yvel = sintable[sprite[nSprite].ang] >> 2; // NOTE no angle masking in original code
} }
} }
} }
@ -261,7 +250,7 @@ void FuncMummy(int a, int nDamage, int nRun)
MummyList[nMummy].G--; MummyList[nMummy].G--;
} }
if ((MummyList[nMummy].F & 31) == (totalmoves & 31)) if ((MummyList[nMummy].F & 0x1F) == (totalmoves & 0x1F))
{ {
sprite[nSprite].cstat = 0x101; sprite[nSprite].cstat = 0x101;
@ -271,23 +260,24 @@ void FuncMummy(int a, int nDamage, int nRun)
{ {
if (RandomBit()) if (RandomBit())
{ {
int nTargetHeight = GetSpriteHeight(nTarget); if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - GetSpriteHeight(nSprite), sprite[nSprite].sectnum,
int nSpriteHeight = GetSpriteHeight(nSprite); sprite[nTarget].x, sprite[nTarget].y, sprite[nTarget].z - GetSpriteHeight(nTarget), sprite[nTarget].sectnum))
if (cansee(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z - nSpriteHeight, sprite[nSprite].sectnum, sprite[nTarget].x, sprite[nTarget].y, sprite[nTarget].z - nTargetHeight, sprite[nTarget].sectnum))
{ {
MummyList[nMummy].nAction = 3; MummyList[nMummy].nAction = 3;
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
sprite[nSprite].yvel = 0;
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0;
return; return;
} }
} }
} }
}
// loc_2B5A8
if (!MummyList[nMummy].B) if (!MummyList[nMummy].B)
{ {
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512) >> 1; sprite[nSprite].xvel = Cos(sprite[nSprite].ang) >> 1;
sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> 1; sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> 1;
} }
@ -331,7 +321,7 @@ void FuncMummy(int a, int nDamage, int nRun)
case 0x8000: case 0x8000:
{ {
sprite[nSprite].ang = (sprite[nSprite].ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask; sprite[nSprite].ang = (sprite[nSprite].ang + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask;
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512) >> 2; sprite[nSprite].xvel = Cos(sprite[nSprite].ang) >> 2;
sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> 2; sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> 2;
return; return;
} }
@ -345,6 +335,7 @@ void FuncMummy(int a, int nDamage, int nRun)
{ {
MummyList[nMummy].nAction = 2; MummyList[nMummy].nAction = 2;
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0; sprite[nSprite].yvel = 0;
} }
@ -353,7 +344,6 @@ void FuncMummy(int a, int nDamage, int nRun)
} }
} }
} }
}
break; break;
} }
@ -451,11 +441,12 @@ void FuncMummy(int a, int nDamage, int nRun)
if (ecx) if (ecx)
{ {
sprite[nSprite].yvel = 0;
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0;
sprite[nSprite].cstat = 0x101;
MummyList[nMummy].nAction = 0; MummyList[nMummy].nAction = 0;
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
sprite[nSprite].cstat = 0x101;
MummyList[nMummy].nTarget = -1; MummyList[nMummy].nTarget = -1;
} }
@ -514,6 +505,7 @@ void FuncMummy(int a, int nDamage, int nRun)
{ {
MummyList[nMummy].nAction = 7; MummyList[nMummy].nAction = 7;
MummyList[nMummy].B = 0; MummyList[nMummy].B = 0;
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0; sprite[nSprite].yvel = 0;
} }