ref: 2d0607df32549ad5d6d587e7552cee659045752e
parent: d9217298207b703fb05f7d303c0d231b096acb6b
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Feb 25 12:02:21 EST 2019
Made NpcAct300.cpp ASM-accurate
--- a/src/Bullet.cpp
+++ b/src/Bullet.cpp
@@ -2,6 +2,8 @@
#include <string.h>
+#include "WindowsWrapper.h"
+
#include "Draw.h"
#include "Caret.h"
#include "Game.h"
@@ -2397,7 +2399,7 @@
}
}
-bool IsActiveSomeBullet(void)
+BOOL IsActiveSomeBullet(void)
{
for (int i = 0; i < 0x40; ++i)
{
@@ -2421,10 +2423,10 @@
case 0x1F:
case 0x20:
case 0x21:
- return true;
+ return TRUE;
}
}
}
- return false;
+ return FALSE;
}
\ No newline at end of file
--- a/src/Bullet.h
+++ b/src/Bullet.h
@@ -58,4 +58,4 @@
void PutBullet(int fx, int fy);
void SetBullet(int no, int x, int y, int dir);
void ActBullet();
-bool IsActiveSomeBullet(void);
+BOOL IsActiveSomeBullet(void);
--- a/src/NpcAct300.cpp
+++ b/src/NpcAct300.cpp
@@ -1,5 +1,7 @@
#include "NpcAct.h"
+#include <stddef.h>
+
#include "WindowsWrapper.h"
#include "Back.h"
@@ -19,12 +21,10 @@
{
RECT rc = {192, 80, 208, 96};
- switch (npc->act_no)
+ if (npc->act_no == 0)
{
- case 0:
- npc->act_no = 1;
- npc->y += 0xC00;
- break;
+ npc->act_no = 1;
+ npc->y += 0xC00;
}
if (++npc->ani_wait % 8 == 1)
@@ -163,8 +163,8 @@
}
// Fallthrough
case 101:
- npc->x = (npc->pNpc->x + gMC.x) / 2;
- npc->y = (npc->pNpc->y + gMC.y) / 2;
+ npc->x = (gMC.x + npc->pNpc->x) / 2;
+ npc->y = (gMC.y + npc->pNpc->y) / 2;
break;
}
}
@@ -182,32 +182,33 @@
{232, 168, 248, 184},
};
- if (npc->pNpc)
+ if (npc->pNpc == NULL)
+ return;
+
+ //Set position
+ if (npc->pNpc->direct == 0)
{
- //Set position
- if (npc->pNpc->direct)
- {
- npc->direct = 2;
- npc->x = npc->pNpc->x + 0x1000;
- }
- else
- {
- npc->direct = 0;
- npc->x = npc->pNpc->x - 0x1000;
- }
- npc->y = npc->pNpc->y;
-
- //Animation
- npc->ani_no = 0;
- if (npc->pNpc->ani_no == 3 || npc->pNpc->ani_no == 5)
- npc->y -= 0x200;
-
- //Set framerect
- if (npc->direct)
- npc->rect = rcRight[npc->ani_no];
- else
- npc->rect = rcLeft[npc->ani_no];
+ npc->direct = 0;
+ npc->x = npc->pNpc->x - 0x1000;
}
+ else
+ {
+ npc->direct = 2;
+ npc->x = npc->pNpc->x + 0x1000;
+ }
+
+ npc->y = npc->pNpc->y;
+
+ //Animation
+ npc->ani_no = 0;
+ if (npc->pNpc->ani_no == 3 || npc->pNpc->ani_no == 5)
+ npc->y -= 0x200;
+
+ //Set framerect
+ if (npc->direct == 0)
+ npc->rect = rcLeft[npc->ani_no];
+ else
+ npc->rect = rcRight[npc->ani_no];
}
//Gaudi in hospital
@@ -286,10 +287,10 @@
break;
}
- if (npc->direct)
- npc->rect = rcRight[npc->ani_no];
- else
+ if (npc->direct == 0)
npc->rect = rcLeft[npc->ani_no];
+ else
+ npc->rect = rcRight[npc->ani_no];
}
//Balrog (nurse)
@@ -418,7 +419,7 @@
npc->xm2 = 0;
npc->ym2 = 0;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -446,7 +447,8 @@
npc->act_no = 21;
npc->act_wait = 0;
- deg = GetArktan(npc->x - gMC.x, npc->y - gMC.y) + Random(-3, 3);
+ deg = (unsigned char)GetArktan(npc->x - gMC.x, npc->y - gMC.y);
+ deg += (unsigned char)Random(-3, 3);
npc->ym2 = 2 * GetSin(deg);
npc->xm2 = 2 * GetCos(deg);
@@ -459,19 +461,19 @@
if (npc->xm2 < 0 && npc->flag & 1)
{
npc->direct = 2;
- npc->xm2 = -npc->xm2;
+ npc->xm2 *= -1;
}
if (npc->xm2 > 0 && npc->flag & 4)
{
npc->direct = 0;
- npc->xm2 = -npc->xm2;
+ npc->xm2 *= -1;
}
if (npc->ym2 < 0 && npc->flag & 2)
- npc->ym2 = -npc->ym2;
+ npc->ym2 *= -1;
if (npc->ym2 > 0 && npc->flag & 8)
- npc->ym2 = -npc->ym2;
+ npc->ym2 *= -1;
if (npc->flag & 0x100)
npc->ym2 = -0x200;
@@ -515,20 +517,22 @@
case 1:
if (npc->direct == 0)
{
- if (gMC.x <= npc->x - 0x24000 || gMC.x >= npc->x - 0x22000)
- return;
-
- npc->act_no = 10;
+ if (gMC.x > npc->x - 0x24000 && gMC.x < npc->x - 0x22000)
+ {
+ npc->act_no = 10;
+ break;
+ }
}
else
{
- if (gMC.x >= npc->x + 0x24000 || gMC.x <= npc->x + 0x22000)
- return;
-
- npc->act_no = 10;
+ if (gMC.x < npc->x + 0x24000 && gMC.x > npc->x + 0x22000)
+ {
+ npc->act_no = 10;
+ break;
+ }
}
- break;
+ return;
case 10:
npc->act_no = 11;
@@ -536,7 +540,7 @@
npc->damage = 5;
// Fallthrough
case 11:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -546,20 +550,20 @@
else
npc->xm2 += 0x10;
- if (gMC.y < npc->y)
+ if (npc->y > gMC.y)
npc->ym2 -= 0x10;
else
npc->ym2 += 0x10;
if (npc->xm2 < 0 && npc->flag & 1)
- npc->xm2 = -npc->xm2;
+ npc->xm2 *= -1;
if (npc->xm2 > 0 && npc->flag & 4)
- npc->xm2 = -npc->xm2;
+ npc->xm2 *= -1;
if (npc->ym2 < 0 && npc->flag & 2)
- npc->ym2 = -npc->ym2;
+ npc->ym2 *= -1;
if (npc->ym2 > 0 && npc->flag & 8)
- npc->ym2 = -npc->ym2;
+ npc->ym2 *= -1;
if (npc->xm2 < -0x5FF)
npc->xm2 = -0x5FF;
@@ -626,7 +630,7 @@
npc->damage = 0;
// Fallthrough
case 1:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -660,7 +664,7 @@
npc->bits |= 0x20;
npc->damage = 0;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -795,7 +799,7 @@
npc->act_no = 11;
// Fallthrough
case 11:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -821,15 +825,15 @@
npc->act_wait = 0;
// Fallthrough
case 21:
- if (npc->count1)
+ if (npc->count1 == 0)
{
- if (++npc->ani_no > 5)
- npc->ani_no = 4;
+ if (++npc->ani_no > 2)
+ npc->ani_no = 1;
}
else
{
- if (++npc->ani_no > 2)
- npc->ani_no = 1;
+ if (++npc->ani_no > 5)
+ npc->ani_no = 4;
}
if (++npc->act_wait > 30)
@@ -841,23 +845,23 @@
npc->act_no = 31;
npc->act_wait = 0;
- if (npc->count1)
+ if (npc->count1 == 0)
{
if (npc->direct == 0)
- SetNpChar(312, npc->x, npc->y, -0x600, -0x600, 0, 0, 0x100);
+ SetNpChar(312, npc->x, npc->y, -0x600, 0, 0, 0, 0x100);
else
- SetNpChar(312, npc->x, npc->y, 0x600, -0x600, 2, 0, 0x100);
+ SetNpChar(312, npc->x, npc->y, 0x600, 0, 2, 0, 0x100);
- npc->ani_no = 6;
+ npc->ani_no = 3;
}
else
{
if (npc->direct == 0)
- SetNpChar(312, npc->x, npc->y, -0x600, 0, 0, 0, 0x100);
+ SetNpChar(312, npc->x, npc->y, -0x600, -0x600, 0, 0, 0x100);
else
- SetNpChar(312, npc->x, npc->y, 0x600, 0, 2, 0, 0x100);
+ SetNpChar(312, npc->x, npc->y, 0x600, -0x600, 2, 0, 0x100);
- npc->ani_no = 3;
+ npc->ani_no = 6;
}
// Fallthrough
case 31:
@@ -984,7 +988,10 @@
// Fallthrough
case 31:
if (++npc->act_wait > 30)
+ {
npc->cond = 0;
+ return;
+ }
break;
}
@@ -1002,7 +1009,7 @@
if (npc->act_no == 31)
{
- if (npc->act_wait / 2 & 1)
+ if (npc->act_wait / 2 % 2)
{
npc->rect.left = 0;
npc->rect.right = 0;
@@ -1065,9 +1072,9 @@
npc->ani_no = 1;
}
- if (gMC.x > npc->x - 0x4000 && gMC.x < npc->x + 0x4000)
+ if (npc->x - 0x4000 < gMC.x && npc->x + 0x4000 > gMC.x)
{
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1093,7 +1100,7 @@
case 110:
npc->damage = 1;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1136,11 +1143,11 @@
npc->bits &= ~8;
if (npc->xm < 0 && npc->flag & 1)
- npc->xm = -npc->xm;
+ npc->xm *= -1;
if (npc->xm > 0 && npc->flag & 4)
- npc->xm = -npc->xm;
+ npc->xm *= -1;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1222,7 +1229,7 @@
npc->ani_no = 6;
if (++npc->act_wait % 6 == 0)
- SetNpChar(314, Random(4, 16) * 0x2000, 0x2000, 0, 0, 0, 0, 0x100);
+ SetNpChar(314, Random(4, 16) * 0x200 * 0x10, 0x200 * 0x10, 0, 0, 0, 0, 0x100);
if (npc->act_wait > 30)
{
@@ -1239,7 +1246,7 @@
npc->act_no = 301;
npc->ani_no = 9;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1301,7 +1308,7 @@
npc->ani_no = 12;
if (++npc->act_wait % 6 == 0)
- SetNpChar(315, Random(4, 16) * 0x2000, 0, 0, 0, 0, 0, 0x100);
+ SetNpChar(315, Random(4, 16) * 0x200 * 0x10, 0, 0, 0, 0, 0, 0x100);
if (npc->act_wait > 30)
{
@@ -1403,7 +1410,7 @@
case 110:
npc->ym += 0x40;
- if (npc->y > (gMap.length * 0x2000) + 0x4000)
+ if (npc->y > (gMap.length * 0x200 * 0x10) + (2 * 0x200 * 0x10))
{
npc->cond = 0;
return;
@@ -1469,7 +1476,7 @@
npc->bits |= 0x20;
// Fallthrough
case 110:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1502,11 +1509,11 @@
npc->ym += 0x80;
if (npc->xm < 0 && npc->flag & 1)
- npc->xm = -npc->xm;
+ npc->xm *= -1;
if (npc->xm > 0 && npc->flag & 4)
- npc->xm = -npc->xm;
+ npc->xm *= -1;
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;
@@ -1683,7 +1690,7 @@
npc->count1 = 0;
// Fallthrough
case 2:
- if (gMC.x < npc->x)
+ if (npc->x > gMC.x)
npc->direct = 0;
else
npc->direct = 2;