ref: 6f8197d9ac6ff903b9e0c22ca550bdae4b9b7b16
parent: 65be197fdfa432957f7561ebec090a0ae21ee79d
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Feb 25 06:07:04 EST 2019
Made NpcAct200.cpp ASM-accurate
--- a/src/NpcAct200.cpp
+++ b/src/NpcAct200.cpp
@@ -15,6 +15,10 @@
//Dragon Zombie
void ActNpc200(NPCHAR *npc)
{
+ unsigned char deg;
+ int ym;
+ int xm;
+
RECT rcLeft[6] = {
{0, 0, 40, 40},
{40, 0, 80, 40},
@@ -97,10 +101,16 @@
case 31:
if (++npc->act_wait < 40 && npc->act_wait % 8 == 1)
{
- const unsigned char deg = npc->direct ? GetArktan(npc->x + 0x1C00 - npc->tgt_x, npc->y - npc->tgt_y) : GetArktan( npc->x - 0x1C00 - npc->tgt_x, npc->y - npc->tgt_y) + Random(-6, 6);
- const int ym = 3 * GetSin(deg);
- const int xm = 3 * GetCos(deg);
+ if (npc->direct == 0)
+ deg = GetArktan(npc->x - 0x1C00 - npc->tgt_x, npc->y - npc->tgt_y);
+ else
+ deg = GetArktan(npc->x + 0x1C00 - npc->tgt_x, npc->y - npc->tgt_y);
+ deg += (unsigned char)Random(-6, 6);
+
+ ym = 3 * GetSin(deg);
+ xm = 3 * GetCos(deg);
+
if (npc->direct == 0)
SetNpChar(202, npc->x - 0x1C00, npc->y, xm, ym, 0, 0, 0x100);
else
@@ -200,19 +210,20 @@
npc->act_no = 1;
// Fallthrough
case 1:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
- if (npc->act_wait >= 8 && gMC.x > npc->x - 0xE000 && gMC.x < npc->x + 0xE000 && gMC.y > npc->y - 0xA000 && gMC.y < npc->y + 0xA000)
+ if (npc->act_wait >= 8 && npc->x - 0xE000 < gMC.x && npc->x + 0xE000 > gMC.x && npc->y - 0xA000 < gMC.y && npc->y + 0xA000 > gMC.y)
{
npc->ani_no = 1;
}
else
{
- if ( npc->act_wait < 8 )
+ if (npc->act_wait < 8)
++npc->act_wait;
+
npc->ani_no = 0;
}
@@ -223,7 +234,7 @@
npc->act_wait = 0;
}
- if (npc->act_wait >= 8 && gMC.x > npc->x - 0x6000 && gMC.x < npc->x + 0x6000 && gMC.y > npc->y - 0xA000 && gMC.y < npc->y + 0x6000)
+ if (npc->act_wait >= 8 && npc->x - 0x6000 < gMC.x && npc->x + 0x6000 > gMC.x && npc->y - 0xA000 < gMC.y && npc->y + 0x6000 > gMC.y)
{
npc->act_no = 2;
npc->ani_no = 0;
@@ -430,13 +441,12 @@
npc->act_wait = Random(0, 50);
// Fallthrough
case 1:
- if (++npc->act_wait >= 50)
- {
- npc->act_wait = 0;
- npc->act_no = 2;
- npc->ym = 0x300;
- }
+ if (++npc->act_wait < 50)
+ break;
+ npc->act_wait = 0;
+ npc->act_no = 2;
+ npc->ym = 0x300;
break;
case 2:
@@ -623,7 +633,7 @@
return;
case 1:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
{
npc->direct = 0;
npc->xm -= 0x10;
@@ -639,7 +649,7 @@
if (npc->flag & 4)
npc->xm = -0x200;
- if (npc->tgt_y > npc->y)
+ if (npc->y < npc->tgt_y)
npc->ym += 8;
else
npc->ym -= 8;
@@ -688,7 +698,8 @@
{
if (++npc->count2 % 8 == 0 && npc->x < gMC.x + 0x14000 && npc->x > gMC.x - 0x14000)
{
- const unsigned char deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y) + Random(-6, 6);
+ unsigned char deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y);
+ deg += (unsigned char)Random(-6, 6);
const int ym = 3 * GetSin(deg);
const int xm = 3 * GetCos(deg);
SetNpChar(209, npc->x, npc->y, xm, ym, 0, 0, 0x100);
@@ -774,8 +785,27 @@
switch (npc->act_no)
{
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->bits |= 0x20;
+ npc->ym = -0x200;
+ npc->tgt_y = npc->y;
+ npc->act_no = 1;
+ npc->damage = 2;
+
+ if (npc->direct == 0)
+ {
+ npc->x = gMC.x + 0x20000;
+ npc->xm = -0x2FF;
+ }
+ else
+ {
+ npc->x = gMC.x - 0x20000;
+ npc->xm = 0x2FF;
+ }
+ }
+ else
+ {
npc->bits &= ~0x20;
npc->rect.right = 0;
npc->damage = 0;
@@ -784,27 +814,10 @@
return;
}
- npc->bits |= 0x20;
- npc->ym = -0x200;
- npc->tgt_y = npc->y;
- npc->act_no = 1;
- npc->damage = 2;
-
- if (npc->direct == 0)
- {
- npc->x = gMC.x + 0x20000;
- npc->xm = -0x2FF;
- }
- else
- {
- npc->x = gMC.x - 0x20000;
- npc->xm = 0x2FF;
- }
-
break;
case 1:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
{
npc->direct = 0;
npc->xm -= 0x10;
@@ -820,7 +833,7 @@
if (npc->xm < -0x2FF)
npc->xm = -0x2FF;
- if (npc->tgt_y > npc->y)
+ if (npc->y < npc->tgt_y)
npc->ym += 8;
else
npc->ym -= 8;
@@ -910,12 +923,12 @@
npc->bits |= 8;
// Fallthrough
case 11:
- if (npc->tgt_x > npc->x)
+ if (npc->x < npc->tgt_x)
npc->xm += 8;
else
npc->xm -= 8;
- if (npc->tgt_y > npc->y)
+ if (npc->y < npc->tgt_y)
npc->ym += 8;
else
npc->ym -= 8;
@@ -936,10 +949,10 @@
case 20:
npc->act_no = 21;
- npc->bits |= 8u;
+ npc->bits |= 8;
// Fallthrough
case 21:
- if (npc->tgt_y > npc->y)
+ if (npc->y < npc->tgt_y)
npc->ym += 0x10;
else
npc->ym -= 0x10;
@@ -1087,7 +1100,7 @@
break;
case 40:
- if (npc->tgt_y > npc->y)
+ if (npc->y < npc->tgt_y)
npc->ym += 0x40;
else
npc->ym -= 0x40;
@@ -1122,7 +1135,7 @@
if (npc->act_no >= 10 && npc->act_no <= 30)
{
- if (gMC.y > npc->y)
+ if (npc->y < gMC.y)
npc->ym += 25;
else
npc->ym -= 25;
@@ -1465,10 +1478,15 @@
{
RECT rc = {0, 0, 0, 0};
- if (npc->direct)
+ if (npc->direct == 0)
+ {
+ if (Random(0, 40) == 1)
+ SetNpChar(4, npc->x + (Random(-20, 20) * 0x200), npc->y, 0, -0x200, 0, 0, 0x100);
+ }
+ else
+ {
SetNpChar(199, npc->x + (Random(-0xA0, 0xA0) * 0x200), npc->y + (Random(-0x80, 0x80) * 0x200), 0, 0, 2, 0, 0x100);
- else if (Random(0, 40) == 1)
- SetNpChar(4, npc->x + (Random(-20, 20) * 0x200), npc->y, 0, -0x200, 0, 0, 0x100);
+ }
npc->rect = rc;
}