Tidy spider AI code

This commit is contained in:
sirlemonhead 2019-12-05 19:40:53 +00:00 committed by Christoph Oelckers
parent 0ddfbba8a0
commit 6cf5bd1f16
2 changed files with 151 additions and 153 deletions

View file

@ -48,15 +48,8 @@ struct Spider
Spider SpiderList[kMaxSpiders];
static actionSeq ActionSeq[] = {
{16, 0},
{8, 0},
{32, 0},
{24, 0},
{0, 0},
{40, 1},
{41, 1},
};
static actionSeq ActionSeq[] = { {16, 0}, {8, 0}, {32, 0}, {24, 0}, {0, 0}, {40, 1}, {41, 1} };
void InitSpider()
{
@ -64,11 +57,9 @@ void InitSpider()
SpiderSprite = 1;
}
int BuildSpider(int nSprite, int x, int y, int z, short nSector, int angle)
int BuildSpider(int nSprite, int x, int y, int z, short nSector, int nAngle)
{
SpiderCount++;
int nSpider = SpiderCount;
int nSpider = SpiderCount++;
if (nSpider >= kMaxSpiders) {
return -1;
}
@ -83,7 +74,7 @@ int BuildSpider(int nSprite, int x, int y, int z, short nSector, int angle)
x = sprite[nSprite].x;
y = sprite[nSprite].y;
z = sprite[nSprite].z;
angle = sprite[nSprite].ang;
nAngle = sprite[nSprite].ang;
}
assert(nSprite >= 0 && nSprite < kMaxSprites);
@ -91,7 +82,7 @@ int BuildSpider(int nSprite, int x, int y, int z, short nSector, int angle)
sprite[nSprite].x = x;
sprite[nSprite].y = y;
sprite[nSprite].z = z;
sprite[nSprite].cstat = 257;
sprite[nSprite].cstat = 0x101;
sprite[nSprite].shade = -12;
sprite[nSprite].clipdist = 15;
sprite[nSprite].xvel = 0;
@ -102,7 +93,7 @@ int BuildSpider(int nSprite, int x, int y, int z, short nSector, int angle)
sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal;
sprite[nSprite].xoffset = 0;
sprite[nSprite].yoffset = 0;
sprite[nSprite].ang = angle;
sprite[nSprite].ang = nAngle;
sprite[nSprite].picnum = 1;
sprite[nSprite].hitag = 0;
sprite[nSprite].lotag = runlist_HeadRun() + 1;
@ -174,6 +165,9 @@ void FuncSpider(int a, int nDamage, int nRun)
{
switch (nAction)
{
default:
return;
case 0:
{
if ((nSpider & 0x1F) == (totalmoves & 0x1F))
@ -188,8 +182,8 @@ void FuncSpider(int a, int nDamage, int nRun)
SpiderList[nSpider].b = 0;
SpiderList[nSpider].nTarget = nTarget;
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512);
sprite[nSprite].yvel = sintable[sprite[nSprite].ang];
sprite[nSprite].xvel = Cos(sprite[nSprite].ang);
sprite[nSprite].yvel = sintable[sprite[nSprite].ang]; // NOTE - not angle masking here in original code
return;
}
}
@ -240,13 +234,13 @@ case_3:
if (RandomSize(3))
{
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512);
sprite[nSprite].xvel = Cos(sprite[nSprite].ang);
sprite[nSprite].yvel = Sin(sprite[nSprite].ang);
}
else
{
sprite[nSprite].yvel = 0;
sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0;
}
if (SpiderList[nSpider].nAction == 1 && RandomBit())
@ -316,9 +310,10 @@ case_3:
{
SpiderList[nSpider].nTarget = -1;
SpiderList[nSpider].nAction = 0;
sprite[nSprite].yvel = 0;
sprite[nSprite].xvel = 0;
SpiderList[nSpider].b = 0;
sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0;
}
int nMov = movesprite(nSprite, sprite[nSprite].xvel << var_14, sprite[nSprite].yvel << var_14, sprite[nSprite].zvel, 1280, -1280, CLIPMASK0);
@ -346,7 +341,7 @@ case_3:
case 0x8000:
{
sprite[nSprite].ang = (sprite[nSprite].ang + 256) & 0x7EF;
sprite[nSprite].xvel = Sin(sprite[nSprite].ang + 512);
sprite[nSprite].xvel = Cos(sprite[nSprite].ang);
sprite[nSprite].yvel = Sin(sprite[nSprite].ang);
return;
}
@ -363,6 +358,8 @@ case_3:
}
return;
}
default:
break;
}
if (SpiderList[nSpider].nAction == 3)
@ -419,12 +416,13 @@ case_3:
{
// creature is dead, make some chunks
SpiderList[nSpider].nHealth = 0;
sprite[nSprite].cstat &= 0x0FEFE;
SpiderList[nSpider].nAction = 5;
nCreaturesLeft--;
SpiderList[nSpider].b = 0;
sprite[nSprite].cstat &= 0xFEFE;
nCreaturesLeft--;
for (int i = 0; i < 7; i++)
{
BuildCreatureChunk(nSprite, seq_GetSeqPicnum(kSeqSpider, i + 41, 0));

View file

@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
void InitSpider();
int BuildSpider(int nSprite, int x, int y, int z, short nSector, int angle);
int BuildSpider(int nSprite, int x, int y, int z, short nSector, int nAngle);
void FuncSpider(int a, int b, int nRun);
END_PS_NS