Made NpcAct040.cpp ASM-accurate

This commit is contained in:
Clownacy 2019-02-24 20:18:54 +00:00
parent eaf37729ad
commit 6adcff2614

View file

@ -34,7 +34,7 @@ void ActNpc040(NPCHAR *npc)
{64, 48, 80, 64}, {64, 48, 80, 64},
}; };
switch ( npc->act_no ) switch (npc->act_no)
{ {
case 0: case 0:
npc->act_no = 1; npc->act_no = 1;
@ -48,21 +48,25 @@ void ActNpc040(NPCHAR *npc)
npc->act_wait = 0; npc->act_wait = 0;
npc->ani_no = 1; npc->ani_no = 1;
} }
if (npc->x - 0x4000 < gMC.x && npc->x + 0x4000 > gMC.x && npc->y - 0x4000 < gMC.y && npc->y + 0x2000 > gMC.y) if (npc->x - 0x4000 < gMC.x && npc->x + 0x4000 > gMC.x && npc->y - 0x4000 < gMC.y && npc->y + 0x2000 > gMC.y)
{ {
if (npc->x <= gMC.x) if (npc->x > gMC.x)
npc->direct = 2;
else
npc->direct = 0; npc->direct = 0;
else
npc->direct = 2;
} }
break; break;
case 2: case 2:
if (++npc->act_wait > 8) if (++npc->act_wait > 8)
{ {
npc->act_no = 1; npc->act_no = 1;
npc->ani_no = 0; npc->ani_no = 0;
} }
break; break;
case 3: case 3:
npc->act_no = 4; npc->act_no = 4;
npc->ani_no = 2; npc->ani_no = 2;
@ -74,18 +78,20 @@ void ActNpc040(NPCHAR *npc)
npc->ani_wait = 0; npc->ani_wait = 0;
npc->ani_no++; npc->ani_no++;
} }
if (npc->ani_no > 5) if (npc->ani_no > 5)
npc->ani_no = 2; npc->ani_no = 2;
if (npc->direct)
npc->x += 0x200; if (npc->direct == 0)
else
npc->x -= 0x200; npc->x -= 0x200;
else
npc->x += 0x200;
break; break;
case 5: case 5:
npc->ani_no = 6; npc->ani_no = 6;
break; break;
default:
break;
} }
if (npc->direct == 0) if (npc->direct == 0)
@ -97,7 +103,7 @@ void ActNpc040(NPCHAR *npc)
//Busted Door //Busted Door
void ActNpc041(NPCHAR *npc) void ActNpc041(NPCHAR *npc)
{ {
RECT rect[1] = {0, 80, 48, 112}; RECT rect = {0, 80, 48, 112};
if (npc->act_no == 0) if (npc->act_no == 0)
{ {
@ -105,7 +111,7 @@ void ActNpc041(NPCHAR *npc)
npc->y -= 0x2000; // Move a tile up npc->y -= 0x2000; // Move a tile up
} }
npc->rect = rect[0]; npc->rect = rect;
} }
//Sue //Sue
@ -143,6 +149,8 @@ void ActNpc042(NPCHAR *npc)
{160, 48, 176, 64}, {160, 48, 176, 64},
}; };
int n;
switch (npc->act_no) switch (npc->act_no)
{ {
case 0: case 0:
@ -265,17 +273,18 @@ void ActNpc042(NPCHAR *npc)
npc->ym = 0; npc->ym = 0;
npc->act_no = 14; npc->act_no = 14;
int i; for (n = 0; n < 0x200; ++n)
for (i = 0; i < 0x200 && gNPC[i].code_event != 501; ++i); if (gNPC[n].code_event == 501)
break;
if (i == 0x200) if (n == 0x200)
{ {
npc->act_no = 0; npc->act_no = 0;
break; break;
} }
else else
{ {
npc->pNpc = &gNPC[i]; npc->pNpc = &gNPC[n];
} }
// Fallthrough // Fallthrough
case 14: case 14:
@ -400,10 +409,12 @@ void ActNpc043(NPCHAR *npc)
RECT rcLeft = {128, 80, 168, 112}; RECT rcLeft = {128, 80, 168, 112};
RECT rcRight = {168, 80, 208, 112}; RECT rcRight = {168, 80, 208, 112};
if (npc->act_no == 0) switch (npc->act_no)
{ {
case 0:
npc->act_no = 1; npc->act_no = 1;
npc->y -= 0x2000; npc->y -= 0x2000;
break;
} }
if (npc->direct == 0) if (npc->direct == 0)
@ -630,14 +641,14 @@ void ActNpc045(NPCHAR *npc)
} }
if (npc->xm2 < 0 && npc->flag & 1) if (npc->xm2 < 0 && npc->flag & 1)
npc->xm2 = -npc->xm2; npc->xm2 *= -1;
if (npc->xm2 > 0 && npc->flag & 4) if (npc->xm2 > 0 && npc->flag & 4)
npc->xm2 = -npc->xm2; npc->xm2 *= -1;
if (npc->ym2 < 0 && npc->flag & 2) if (npc->ym2 < 0 && npc->flag & 2)
npc->ym2 = -npc->ym2; npc->ym2 *= -1;
if (npc->ym2 > 0 && npc->flag & 8) if (npc->ym2 > 0 && npc->flag & 8)
npc->ym2 = -npc->ym2; npc->ym2 *= -1;
if (npc->xm2 > 0x200) if (npc->xm2 > 0x200)
npc->xm2 = 0x200; npc->xm2 = 0x200;
@ -672,17 +683,17 @@ void ActNpc046(NPCHAR *npc)
if (npc->direct == 0) if (npc->direct == 0)
{ {
if (npc->x >= gMC.x) if (npc->x < gMC.x)
npc->x -= 0x5FF;
else
npc->x += 0x5FF; npc->x += 0x5FF;
else
npc->x -= 0x5FF;
} }
else else
{ {
if (npc->y >= gMC.y) if (npc->y < gMC.y)
npc->y -= 0x5FF;
else
npc->y += 0x5FF; npc->y += 0x5FF;
else
npc->y -= 0x5FF;
} }
npc->rect = rect; npc->rect = rect;
@ -711,10 +722,10 @@ void ActNpc047(NPCHAR *npc)
PlaySoundObject(102, 1); PlaySoundObject(102, 1);
} }
if (gMC.x > npc->x) if (npc->x < gMC.x)
npc->x += 0x400; npc->x += 0x400;
if (gMC.x < npc->x) if (npc->x > gMC.x)
npc->x -= 0x400; npc->x -= 0x400;
break; break;
@ -796,23 +807,23 @@ void ActNpc048(NPCHAR *npc)
{ {
if (npc->flag & 1 && npc->xm < 0) if (npc->flag & 1 && npc->xm < 0)
{ {
npc->xm = -npc->xm; npc->xm *= -1;
} }
else if (npc->flag & 4 && npc->xm > 0) else if (npc->flag & 4 && npc->xm > 0)
{ {
npc->xm = -npc->xm; npc->xm *= -1;
} }
else if (npc->flag & 8) else if (npc->flag & 8)
{ {
if (++npc->count1 <= 2 && npc->direct != 2) if (++npc->count1 > 2 || npc->direct == 2)
{
npc->ym = -0x100;
}
else
{ {
VanishNpChar(npc); VanishNpChar(npc);
SetCaret(npc->x, npc->y, 2, 0); SetCaret(npc->x, npc->y, 2, 0);
} }
else
{
npc->ym = -0x100;
}
} }
if (npc->direct == 2) if (npc->direct == 2)
@ -848,15 +859,19 @@ void ActNpc048(NPCHAR *npc)
npc->cond = 0; npc->cond = 0;
} }
if (npc->direct) if (npc->direct == 0)
npc->rect = rcRight[npc->ani_no];
else
npc->rect = rcLeft[npc->ani_no]; npc->rect = rcLeft[npc->ani_no];
else
npc->rect = rcRight[npc->ani_no];
} }
//Skullhead //Skullhead
void ActNpc049(NPCHAR *npc) void ActNpc049(NPCHAR *npc)
{ {
unsigned char deg;
int ym;
int xm;
if (npc->act_no >= 10 && npc->pNpc->code_char == 3) if (npc->act_no >= 10 && npc->pNpc->code_char == 3)
{ {
npc->act_no = 3; npc->act_no = 3;
@ -892,20 +907,20 @@ void ActNpc049(NPCHAR *npc)
npc->act_no = 3; npc->act_no = 3;
npc->ani_no = 2; npc->ani_no = 2;
if (npc->count2 == 0) if (npc->count2)
{
if (npc->direct == 0)
npc->xm = -0x100;
else
npc->xm = 0x100;
}
else
{ {
if (npc->direct == 0) if (npc->direct == 0)
npc->xm = -0x200; npc->xm = -0x200;
else else
npc->xm = 0x200; npc->xm = 0x200;
} }
else
{
if (npc->direct == 0)
npc->xm = -0x100;
else
npc->xm = 0x100;
}
} }
npc->ani_no = 1; npc->ani_no = 1;
@ -933,7 +948,7 @@ void ActNpc049(NPCHAR *npc)
} }
else else
{ {
if (gMC.x > npc->x - 0x10000 && gMC.x < npc->x + 0x10000 && gMC.y > npc->y - 0xC000 && gMC.y < npc->y + 0xC000) if (npc->x - 0x10000 < gMC.x && npc->x + 0x10000 > gMC.x && npc->y - 0xC000 < gMC.y && npc->y + 0xC000 > gMC.y)
{ {
npc->act_no = 11; npc->act_no = 11;
npc->act_wait = 0; npc->act_wait = 0;
@ -946,9 +961,9 @@ void ActNpc049(NPCHAR *npc)
case 11: case 11:
if (++npc->act_wait == 30 || npc->act_wait == 35) if (++npc->act_wait == 30 || npc->act_wait == 35)
{ {
const unsigned char deg = GetArktan(npc->x - gMC.x, npc->y + 0x800 - gMC.y); deg = GetArktan(npc->x - gMC.x, npc->y + 0x800 - gMC.y);
const int ym = 2 * GetSin(deg); ym = 2 * GetSin(deg);
const int xm = 2 * GetCos(deg); xm = 2 * GetCos(deg);
SetNpChar(50, npc->x, npc->y, xm, ym, 0, 0, 0x100); SetNpChar(50, npc->x, npc->y, xm, ym, 0, 0, 0x100);
PlaySoundObject(39, 1); PlaySoundObject(39, 1);
} }
@ -1103,11 +1118,16 @@ void ActNpc051(NPCHAR *npc)
switch (npc->act_no) switch (npc->act_no)
{ {
case 0: case 0:
if (gMC.x > npc->x - (WINDOW_WIDTH * 0x200) && gMC.x < npc->x + (WINDOW_WIDTH * 0x200) && gMC.y > npc->y - (WINDOW_WIDTH * 0x200) && gMC.y < npc->y + (WINDOW_WIDTH * 0x200)) if (npc->x - (WINDOW_WIDTH * 0x200) < gMC.x && npc->x + (WINDOW_WIDTH * 0x200) > gMC.x && npc->y - (WINDOW_WIDTH * 0x200) < gMC.y && npc->y + (WINDOW_WIDTH * 0x200) > gMC.y)
{ {
npc->tgt_x = npc->x; npc->tgt_x = npc->x;
npc->tgt_y = npc->y; npc->tgt_y = npc->y;
if (npc->direct == 0)
npc->ym = 0x400; npc->ym = 0x400;
else
npc->ym = 0x400;
npc->act_no = 1; npc->act_no = 1;
SetNpChar(49, 0, 0, 0, 0, 0, npc, 0); SetNpChar(49, 0, 0, 0, 0, 0, npc, 0);
} }
@ -1300,7 +1320,7 @@ void ActNpc053(NPCHAR *npc)
npc->pNpc->xm += 0x80; npc->pNpc->xm += 0x80;
} }
deg = npc->xm + npc->pNpc->count2; deg = (unsigned char)npc->xm + (unsigned char)npc->pNpc->count2;
npc->x = npc->pNpc->x + npc->count1 * GetCos(deg); npc->x = npc->pNpc->x + npc->count1 * GetCos(deg);
npc->y = npc->pNpc->y + npc->count1 * GetSin(deg); npc->y = npc->pNpc->y + npc->count1 * GetSin(deg);
npc->direct = npc->pNpc->direct; npc->direct = npc->pNpc->direct;
@ -1308,7 +1328,10 @@ void ActNpc053(NPCHAR *npc)
} }
npc->direct = npc->pNpc->direct; npc->direct = npc->pNpc->direct;
npc->ani_no = deg < 20 || deg > 108; if (deg >= 20 && deg <= 108)
npc->ani_no = 0;
else
npc->ani_no = 1;
if (npc->direct == 0) if (npc->direct == 0)
npc->rect = rcLeft[npc->ani_no]; npc->rect = rcLeft[npc->ani_no];
@ -1370,7 +1393,7 @@ void ActNpc054(NPCHAR *npc)
if (++npc->count1 > 8) if (++npc->count1 > 8)
{ {
npc->direct = 2; npc->direct = 2;
npc->xm = -npc->xm; npc->xm *= -1;
} }
} }
else if (npc->direct == 2 && npc->flag & 4) else if (npc->direct == 2 && npc->flag & 4)
@ -1378,7 +1401,7 @@ void ActNpc054(NPCHAR *npc)
if (++npc->count1 > 8) if (++npc->count1 > 8)
{ {
npc->direct = 0; npc->direct = 0;
npc->xm = -npc->xm; npc->xm *= -1;
} }
} }
else else
@ -1390,7 +1413,7 @@ void ActNpc054(NPCHAR *npc)
case 2: case 2:
++npc->act_wait; ++npc->act_wait;
npc->shock += npc->act_wait; npc->shock += (unsigned char)npc->act_wait;
if (npc->act_wait > 50) if (npc->act_wait > 50)
{ {
@ -1423,7 +1446,7 @@ void ActNpc054(NPCHAR *npc)
npc->rect = rcRight[npc->ani_no]; npc->rect = rcRight[npc->ani_no];
} }
//Kazuka //Kazuma
void ActNpc055(NPCHAR *npc) void ActNpc055(NPCHAR *npc)
{ {
RECT rcLeft[6] = { RECT rcLeft[6] = {
@ -1616,11 +1639,13 @@ void ActNpc057(NPCHAR *npc)
case 0: case 0:
deg = Random(0, 0xFF); deg = Random(0, 0xFF);
npc->xm = GetCos(deg); npc->xm = GetCos(deg);
npc->tgt_x = npc->x + 8 * GetCos(deg + 0x40); deg += 0x40;
npc->tgt_x = npc->x + 8 * GetCos(deg);
deg = Random(0, 0xFF); deg = Random(0, 0xFF);
npc->ym = GetSin(deg); npc->ym = GetSin(deg);
npc->tgt_y = npc->y + 8 * GetSin(deg + 0x40); deg += 0x40;
npc->tgt_y = npc->y + 8 * GetSin(deg);
npc->act_no = 1; npc->act_no = 1;
npc->count1 = 120; npc->count1 = 120;
@ -1782,15 +1807,7 @@ void ActNpc058(NPCHAR *npc)
switch (npc->act_no) switch (npc->act_no)
{ {
case 0: case 0:
if ( gMC.x >= npc->x + 0x2000 || gMC.x <= npc->x - 0x2000 ) if (gMC.x < npc->x + 0x2000 && gMC.x > npc->x - 0x2000)
{
npc->rect.right = 0;
npc->damage = 0;
npc->xm = 0;
npc->ym = 0;
npc->bits &= ~0x20;
}
else
{ {
npc->bits |= 0x20; npc->bits |= 0x20;
npc->ym = -0x100; npc->ym = -0x100;
@ -1813,20 +1830,28 @@ void ActNpc058(NPCHAR *npc)
npc->xm = 0x2FF; npc->xm = 0x2FF;
} }
} }
else
{
npc->rect.right = 0;
npc->damage = 0;
npc->xm = 0;
npc->ym = 0;
npc->bits &= ~0x20;
}
break; break;
case 1: case 1:
if (npc->x <= gMC.x) if (npc->x > gMC.x)
{
npc->direct = 2;
npc->xm += 0x10;
}
else
{ {
npc->direct = 0; npc->direct = 0;
npc->xm -= 0x10; npc->xm -= 0x10;
} }
else
{
npc->direct = 2;
npc->xm += 0x10;
}
if (npc->flag & 1) if (npc->flag & 1)
npc->xm = 0x200; npc->xm = 0x200;
@ -1834,10 +1859,10 @@ void ActNpc058(NPCHAR *npc)
if (npc->flag & 4) if (npc->flag & 4)
npc->xm = -0x200; npc->xm = -0x200;
if (npc->y >= npc->tgt_y) if (npc->y < npc->tgt_y)
npc->ym -= 8;
else
npc->ym += 8; npc->ym += 8;
else
npc->ym -= 8;
if (npc->xm > 0x2FF) if (npc->xm > 0x2FF)
npc->xm = 0x2FF; npc->xm = 0x2FF;
@ -1871,8 +1896,6 @@ void ActNpc058(NPCHAR *npc)
break; break;
} }
// Fallthrough
case 2:
if (npc->act_no) if (npc->act_no)
{ {
if (npc->act_wait < 150) if (npc->act_wait < 150)
@ -1883,9 +1906,9 @@ void ActNpc058(NPCHAR *npc)
if ((++npc->count2 % 8) == 0 && npc->x < gMC.x + 0x14000 && npc->x > gMC.x - 0x14000) // TODO: Maybe do something about this for tallscreen if ((++npc->count2 % 8) == 0 && npc->x < gMC.x + 0x14000 && npc->x > gMC.x - 0x14000) // TODO: Maybe do something about this for tallscreen
{ {
unsigned char deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y); unsigned char deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y);
unsigned char rand_deg = Random(-6, 6) + deg; deg += (unsigned char)Random(-6, 6);
int ym = 2 * GetSin(rand_deg); int ym = 2 * GetSin(deg);
int xm = 2 * GetCos(rand_deg); int xm = 2 * GetCos(deg);
SetNpChar(84, npc->x, npc->y, xm, ym, 0, 0, 0x100); SetNpChar(84, npc->x, npc->y, xm, ym, 0, 0, 0x100);
PlaySoundObject(39, 1); PlaySoundObject(39, 1);
} }
@ -1957,11 +1980,11 @@ void ActNpc059(NPCHAR *npc)
break; break;
case 3: case 3:
if (npc->x - 0x8000 >= gMC.x || npc->x + 0x8000 <= gMC.x || npc->y - 0x8000 >= gMC.y || npc->y + 0x8000 <= gMC.y) if (npc->x - 0x8000 < gMC.x && npc->x + 0x8000 > gMC.x && npc->y - 0x8000 < gMC.y && npc->y + 0x8000 > gMC.y)
{ break;
npc->act_no = 4; npc->act_no = 4;
npc->ani_wait = 0; npc->ani_wait = 0;
}
break; break;