shithub: cstory

Download patch

ref: 97107fee22fb71c9be950ba0a2d1006a592f9f66
parent: e99bc72209b9311af68f3f50fe5f00deffd11281
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Nov 14 17:22:21 EST 2019

Clean-up NpcAct020.cpp

So many ASM-inaccuracies lately

--- a/src/NpcAct020.cpp
+++ b/src/NpcAct020.cpp
@@ -1,5 +1,7 @@
 #include "NpcAct.h"
 
+#include <stddef.h>
+
 #include "WindowsWrapper.h"
 
 #include "Caret.h"
@@ -44,7 +46,7 @@
 		npc->act_no = 1;
 
 		if (npc->direct == 2)
-			npc->y += 0x2000;
+			npc->y += 16 * 0x200;
 	}
 
 	RECT rect = {224, 40, 240, 48};
@@ -126,11 +128,11 @@
 	switch (npc->act_no)
 	{
 		case 0:
-			npc->y += 0x600;
+			npc->y += 3 * 0x200;
 			npc->act_no = 1;
 			// Fallthrough
 		case 1:
-			if (npc->act_wait >= 8 && npc->x - 0x10000 < gMC.x && npc->x + 0x10000 > gMC.x && npc->y - 0x10000 < gMC.y && npc->y + 0x6000 > gMC.y)
+			if (npc->act_wait >= 8 && npc->x - (128 * 0x200) < gMC.x && npc->x + (128 * 0x200) > gMC.x && npc->y - (128 * 0x200) < gMC.y && npc->y + (48 * 0x200) > gMC.y)
 			{
 				if (npc->x > gMC.x)
 					npc->direct = 0;
@@ -154,7 +156,7 @@
 				npc->act_wait = 0;
 			}
 
-			if (npc->act_wait >= 8 && npc->x - 0xC000 < gMC.x && npc->x + 0xC000 > gMC.x && npc->y - 0xC000 < gMC.y && npc->y + 0x6000 > gMC.y)
+			if (npc->act_wait >= 8 && npc->x - (96 * 0x200) < gMC.x && npc->x + (96 * 0x200) > gMC.x && npc->y - (96 * 0x200) < gMC.y && npc->y + (48 * 0x200) > gMC.y)
 			{
 				npc->act_no = 2;
 				npc->ani_no = 0;
@@ -210,22 +212,21 @@
 				npc->act_no = 5;
 				npc->ani_no = 2;
 				npc->xm /= 2;
+				break;
 			}
-			else
-			{
-				if (npc->act_wait % 4 == 1)
-					PlaySoundObject(110, 1);
 
-				if (++npc->ani_wait > 0)
-				{
-					npc->ani_wait = 0;
-					++npc->ani_no;
-				}
+			if (npc->act_wait % 4 == 1)
+				PlaySoundObject(110, 1);
 
-				if (npc->ani_no > 5)
-					npc->ani_no = 3;
+			if (++npc->ani_wait > 0)
+			{
+				npc->ani_wait = 0;
+				++npc->ani_no;
 			}
 
+			if (npc->ani_no > 5)
+				npc->ani_no = 3;
+
 			break;
 
 		case 5:
@@ -295,7 +296,7 @@
 			npc->act_no = 1;
 			npc->ani_no = 0;
 			npc->ani_wait = 0;
-			npc->x += 0x1000;
+			npc->x += 8 * 0x200;
 			// Fallthrough
 		case 1:
 			if (++npc->act_wait > 150)
@@ -309,7 +310,7 @@
 		case 2:	// Identical to case 4
 			if (++npc->act_wait <= 0x40)
 			{
-				npc->y -= 0x200;
+				npc->y -= 1 * 0x200;
 			}
 			else
 			{
@@ -331,7 +332,7 @@
 		case 4:	// Identical to case 2
 			if (++npc->act_wait <= 0x40)
 			{
-				npc->y -= 0x200;
+				npc->y -= 1 * 0x200;
 			}
 			else
 			{
@@ -353,7 +354,7 @@
 		case 6:
 			if (++npc->act_wait <= 0x40)
 			{
-				npc->y += 0x200;
+				npc->y += 1 * 0x200;
 			}
 			else
 			{
@@ -375,7 +376,7 @@
 		case 8:
 			if (++npc->act_wait <= 0x40)
 			{
-				npc->y += 0x200;
+				npc->y += 1 * 0x200;
 			}
 			else
 			{
@@ -418,12 +419,12 @@
 			deg = Random(0, 0xFF);
 			npc->xm = GetCos(deg);
 			deg += 0x40;
-			npc->tgt_x = npc->x + 8 * GetCos(deg);
+			npc->tgt_x = npc->x + (GetCos(deg) * 8);
 
 			deg = Random(0, 0xFF);
 			npc->ym = GetSin(deg);
 			deg += 0x40;
-			npc->tgt_y = npc->y + 8 * GetSin(deg);
+			npc->tgt_y = npc->y + (GetSin(deg) * 8);
 
 			npc->act_no = 1;
 			npc->count1 = 120;
@@ -457,16 +458,15 @@
 			if (npc->count1 < 120)
 			{
 				++npc->count1;
+				break;
 			}
-			else
+
+			if (npc->x - (8 * 0x200) < gMC.x && npc->x + (8 * 0x200) > gMC.x && npc->y < gMC.y && npc->y + (96 * 0x200) > gMC.y)
 			{
-				if (npc->x - 0x1000 < gMC.x && npc->x + 0x1000 > gMC.x && npc->y < gMC.y && npc->y + 0xC000 > gMC.y)
-				{
-					npc->xm /= 2;
-					npc->ym = 0;
-					npc->act_no = 3;
-					npc->bits &= ~NPC_IGNORE_SOLIDITY;
-				}
+				npc->xm /= 2;
+				npc->ym = 0;
+				npc->act_no = 3;
+				npc->bits &= ~NPC_IGNORE_SOLIDITY;
 			}
 
 			break;
@@ -561,11 +561,11 @@
 	switch (npc->act_no)
 	{
 		case 0:
-			npc->y += 0x600;
+			npc->y += 3 * 0x200;
 			npc->act_no = 1;
 			// Fallthrough
 		case 1:
-			if (npc->act_wait >= 8 && npc->x - 0x10000 < gMC.x && npc->x + 0x10000 > gMC.x && npc->y - 0x10000 < gMC.y && npc->y + 0x6000 > gMC.y)
+			if (npc->act_wait >= 8 && npc->x - (128 * 0x200) < gMC.x && npc->x + (128 * 0x200) > gMC.x && npc->y - (128 * 0x200) < gMC.y && npc->y + (48 * 0x200) > gMC.y)
 			{
 				if (npc->x > gMC.x)
 					npc->direct = 0;
@@ -589,7 +589,7 @@
 				npc->act_wait = 0;
 			}
 
-			if (npc->act_wait >= 8 && npc->x - 0xC000 < gMC.x && npc->x + 0xC000 > gMC.x && npc->y - 0xC000 < gMC.y && npc->y + 0x6000 > gMC.y)
+			if (npc->act_wait >= 8 && npc->x - (96 * 0x200) < gMC.x && npc->x + (96 * 0x200) > gMC.x && npc->y - (96 * 0x200) < gMC.y && npc->y + (48 * 0x200) > gMC.y)
 			{
 				npc->act_no = 2;
 				npc->ani_no = 0;
@@ -603,7 +603,7 @@
 			{
 				npc->act_no = 3;
 				npc->ani_no = 2;
-				npc->ym = -1228;
+				npc->ym = -0x4CC;
 				PlaySoundObject(30, 1);
 
 				if (npc->x > gMC.x)
@@ -645,25 +645,24 @@
 				npc->act_no = 5;
 				npc->ani_no = 2;
 				npc->xm /= 2;
+				break;
 			}
-			else
-			{
-				if (npc->act_wait % 4 == 1)
-					PlaySoundObject(109, 1);
 
-				if (npc->flag & 8)
-					npc->ym = -0x200;
+			if (npc->act_wait % 4 == 1)
+				PlaySoundObject(109, 1);
 
-				if (++npc->ani_wait > 0)
-				{
-					npc->ani_wait = 0;
-					++npc->ani_no;
-				}
+			if (npc->flag & 8)
+				npc->ym = -0x200;
 
-				if (npc->ani_no > 5)
-					npc->ani_no = 3;
+			if (++npc->ani_wait > 0)
+			{
+				npc->ani_wait = 0;
+				++npc->ani_no;
 			}
 
+			if (npc->ani_no > 5)
+				npc->ani_no = 3;
+
 			break;
 
 		case 5:
@@ -739,7 +738,7 @@
 			npc->ani_wait = 0;
 			// Fallthrough
 		case 1:
-			if (npc->x - 0x6000 < gMC.x && npc->x + 0x6000 > gMC.x && npc->y - 0x6000 < gMC.y && npc->y + 0x2000 > gMC.y)
+			if (npc->x - (48 * 0x200) < gMC.x && npc->x + (48 * 0x200) > gMC.x && npc->y - (48 * 0x200) < gMC.y && npc->y + (16 * 0x200) > gMC.y)
 				npc->ani_no = 1;
 			else
 				npc->ani_no = 0;
@@ -797,7 +796,7 @@
 		if (npc->act_no == 0)
 		{
 			npc->act_no = 1;
-			npc->y += 0x2000;
+			npc->y += 16 * 0x200;
 			npc->ani_no = 2;
 		}
 
@@ -804,7 +803,7 @@
 		if (++npc->act_wait > 100)
 		{
 			npc->act_wait = 0;
-			SetCaret(npc->x, npc->y - 0x400, 5, 0);
+			SetCaret(npc->x, npc->y - (2 * 0x200), 5, 0);
 		}
 	}
 
@@ -843,7 +842,7 @@
 				npc->ani_no = 1;
 			}
 
-			if (npc->x - 0x1000 < gMC.x && npc->x + 0x1000 > gMC.x && npc->y - 0x1000 < gMC.y && npc->y + 0xC000 > gMC.y)
+			if (npc->x - (8 * 0x200) < gMC.x && npc->x + (8 * 0x200) > gMC.x && npc->y - (8 * 0x200) < gMC.y && npc->y + (96 * 0x200) > gMC.y)
 			{
 				npc->ani_no = 0;
 				npc->act_no = 3;
@@ -863,7 +862,7 @@
 		case 3:
 			npc->ani_no = 0;
 
-			if (npc->shock || npc->x - 0x2800 > gMC.x || npc->x + 0x2800 < gMC.x)
+			if (npc->shock || npc->x - (20 * 0x200) > gMC.x || npc->x + (20 * 0x200) < gMC.x)
 			{
 				npc->ani_no = 1;
 				npc->ani_wait = 0;
@@ -878,10 +877,10 @@
 			if (npc->ym > 0x5FF)
 				npc->ym = 0x5FF;
 
-			if (++npc->act_wait < 20 && (npc->flag & 8) == 0)
+			if (++npc->act_wait < 20 && !(npc->flag & 8))
 				break;
 
-			if (npc->flag & 8 || npc->y > gMC.y - 0x2000)
+			if (npc->flag & 8 || npc->y > gMC.y - (16 * 0x200))
 			{
 				npc->ani_wait = 0;
 				npc->ani_no = 2;
@@ -1040,9 +1039,9 @@
 			if (npc->shock)
 			{
 				if (npc->direct == 0)
-					SetNpChar(103, npc->x - 0x1000, npc->y + 0x1000, 0, 0, npc->direct, 0, 0x100);
+					SetNpChar(103, npc->x - (8 * 0x200), npc->y + (8 * 0x200), 0, 0, npc->direct, NULL, 0x100);
 				else
-					SetNpChar(103, npc->x + 0x1000, npc->y + 0x1000, 0, 0, npc->direct, 0, 0x100);
+					SetNpChar(103, npc->x + (8 * 0x200), npc->y + (8 * 0x200), 0, 0, npc->direct, NULL, 0x100);
 
 				npc->ani_no = 1;
 				npc->act_no = 2;
@@ -1124,12 +1123,12 @@
 				--npc->count1;
 				npc->act_wait = 0;
 
-				deg = GetArktan(npc->x - gMC.x, npc->y + 0x800 - gMC.y);
-				deg += (unsigned char)Random(-16, 16);
+				deg = GetArktan(npc->x - gMC.x, npc->y + (4 * 0x200) - gMC.y);
+				deg += (unsigned char)Random(-0x10, 0x10);
 				ym = GetSin(deg);
 				xm = GetCos(deg);
 
-				SetNpChar(11, npc->x, npc->y + 0x800, xm, ym, 0, 0, 0x100);
+				SetNpChar(11, npc->x, npc->y + 0x800, xm, ym, 0, NULL, 0x100);
 				PlaySoundObject(39, 1);
 
 				if (npc->count1 == 0)
@@ -1204,7 +1203,7 @@
 			break;
 
 		case 6:
-			if (npc->y + 0x2000 < gMC.y)
+			if (npc->y + (16 * 0x200) < gMC.y)
 				npc->damage = 10;
 			else
 				npc->damage = 0;
@@ -1220,10 +1219,10 @@
 				npc->damage = 0;
 
 				for (i = 0; i < 8; ++i)
-					SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, 0, 0x100);
+					SetNpChar(4, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-341, 341), Random(-0x600, 0), 0, NULL, 0x100);
 
 				for (i = 0; i < 8; ++i)
-					SetNpChar(33, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-0x400, 0x400), Random(-0x400, 0), 0, 0, 0x100);
+					SetNpChar(33, npc->x + (Random(-12, 12) * 0x200), npc->y + (Random(-12, 12) * 0x200), Random(-0x400, 0x400), Random(-0x400, 0), 0, NULL, 0x100);
 			}
 
 			break;