shithub: cstory

Download patch

ref: bcbab0745c5c7b53747cb6d2dc64ac0b3c5e3602
parent: 519acb5db1669ea288d3d27392339d8810723f92
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Nov 17 10:10:33 EST 2019

Clean-up BossAlmo2.cpp

Pixel's way of converting tiles to units is inconsistent: the ASM
shows he sometimes does '* 0x200 * 0x10', other times it's
'* 0x10 * 0x200', and in this file he does '* 0x2000'.

This means TILES_TO_UNITS won't be usable for every case, so I'm not
sure if we should even have it. It's pretty clear that Pixel just
multiplied things manually, without a macro to keep things
consistent. And if we're getting rid of that, then what does that
mean for PIXELS_TO_UNITS?

--- a/src/BossAlmo2.cpp
+++ b/src/BossAlmo2.cpp
@@ -27,11 +27,11 @@
 			npc->act_no = 11;
 			npc->ani_no = 2;
 			npc->bits = NPC_IGNORE_SOLIDITY;
-			npc->view.front = 0x4800;
-			npc->view.top = 0x7000;
+			npc->view.front = 36 * 0x200;
+			npc->view.top = 56 * 0x200;
 			// Fallthrough
 		case 11:
-			npc->x = gBoss[0].x - 0x4800;
+			npc->x = gBoss[0].x - (36 * 0x200);
 			npc->y = gBoss[0].y;
 			break;
 
@@ -40,7 +40,9 @@
 			npc->act_wait = 112;
 			// Fallthrough
 		case 51:
-			if (--npc->act_wait == 0)
+			--npc->act_wait;
+
+			if (npc->act_wait == 0)
 			{
 				npc->act_no = 100;
 				npc->ani_no = 3;
@@ -56,7 +58,7 @@
 	npc->rect = rect[npc->ani_no];
 
 	if (npc->act_no == 51)
-		npc->rect.bottom = npc->act_wait + npc->rect.top;
+		npc->rect.bottom = npc->rect.top + npc->act_wait;
 }
 
 static void ActBossCharA_Tail(NPCHAR *npc)
@@ -73,11 +75,11 @@
 			npc->act_no = 11;
 			npc->ani_no = 0;
 			npc->bits = NPC_IGNORE_SOLIDITY;
-			npc->view.front = 0x5800;
-			npc->view.top = 0x7000;
+			npc->view.front = 44 * 0x200;
+			npc->view.top = 56 * 0x200;
 			// Fallthrough
 		case 11:
-			npc->x = gBoss[0].x + 0x5800;
+			npc->x = gBoss[0].x + (44 * 0x200);
 			npc->y = gBoss[0].y;
 			break;
 
@@ -86,7 +88,9 @@
 			npc->act_wait = 112;
 			// Fallthrough
 		case 51:
-			if (--npc->act_wait == 0)
+			--npc->act_wait;
+
+			if (npc->act_wait == 0)
 			{
 				npc->act_no = 100;
 				npc->ani_no = 2;
@@ -102,7 +106,7 @@
 	npc->rect = rect[npc->ani_no];
 
 	if (npc->act_no == 51)
-		npc->rect.bottom = npc->act_wait + npc->rect.top;
+		npc->rect.bottom = npc->rect.top + npc->act_wait;
 }
 
 static void ActBossCharA_Face(NPCHAR *npc)
@@ -135,15 +139,17 @@
 			npc->act_wait = 100;
 			// Fallthrough
 		case 31:
-			if (++npc->act_wait > 300)
+			++npc->act_wait;
+
+			if (npc->act_wait > 300)
 				npc->act_wait = 0;
 
-			if (npc->act_wait > 250 && (npc->act_wait % 0x10) == 1)
+			if (npc->act_wait > 250 && npc->act_wait % 0x10 == 1)
 				PlaySoundObject(26, 1);
 
-			if (npc->act_wait > 250 && (npc->act_wait % 0x10) == 7)
+			if (npc->act_wait > 250 && npc->act_wait % 0x10 == 7)
 			{
-				SetNpChar(293, npc->x, npc->y, 0, 0, 0, 0, 0x80);
+				SetNpChar(293, npc->x, npc->y, 0, 0, 0, NULL, 0x80);
 				PlaySoundObject(101, 1);
 			}
 
@@ -150,7 +156,7 @@
 			if (npc->act_wait == 200)
 				PlaySoundObject(116, 1);
 
-			if (npc->act_wait > 200 && npc->act_wait % 2)
+			if (npc->act_wait > 200 && npc->act_wait % 2 != 0)
 				npc->ani_no = 4;
 			else
 				npc->ani_no = 3;
@@ -158,12 +164,12 @@
 			break;
 	}
 
-	npc->view.back = 0x4800;
-	npc->view.front = 0x4800;
-	npc->view.top = 0x2800;
+	npc->view.back = 36 * 0x200;
+	npc->view.front = 36 * 0x200;
+	npc->view.top = 20 * 0x200;
 
-	npc->x = gBoss[0].x - 0x4800;
-	npc->y = gBoss[0].y + 0x800;
+	npc->x = gBoss[0].x - (36 * 0x200);
+	npc->y = gBoss[0].y + (4 * 0x200);
 
 	npc->bits = NPC_IGNORE_SOLIDITY;
 
@@ -238,13 +244,13 @@
 
 	if (npc->act_no < 50)
 	{
-		if (npc->count1)
+		if (npc->count1 != 0)
 			deg = npc->count2 + 0x80;
 		else
 			deg = npc->count2 + 0x180;
 
-		npc->x = npc->pNpc->x - 0x1000 + 0x30 * GetCos(deg / 2);
-		npc->y = npc->pNpc->y + 0x50 * GetSin(deg / 2);
+		npc->x = npc->pNpc->x - (8 * 0x200) + (GetCos(deg / 2) * 0x30);
+		npc->y = npc->pNpc->y + (GetSin(deg / 2) * 0x50);
 	}
 
 	npc->rect = rect[npc->ani_no];
@@ -256,22 +262,22 @@
 	{
 		case 0:
 			npc->x = gBoss[0].x;
-			npc->y = gBoss[0].y - 0x4000;
+			npc->y = gBoss[0].y - (32 * 0x200);
 			break;
 
 		case 1:
-			npc->x = gBoss[0].x + 0x3800;
+			npc->x = gBoss[0].x + (28 * 0x200);
 			npc->y = gBoss[0].y;
 			break;
 
 		case 2:
-			npc->x = gBoss[0].x + 0x800;
-			npc->y = gBoss[0].y + 0x4000;
+			npc->x = gBoss[0].x + (4 * 0x200);
+			npc->y = gBoss[0].y + (32 * 0x200);
 			break;
 
 		case 3:
-			npc->x = gBoss[0].x - 0x3800;
-			npc->y = gBoss[0].y + 0x800;
+			npc->x = gBoss[0].x - (28 * 0x200);
+			npc->y = gBoss[0].y + (4 * 0x200);
 			break;
 	}
 }
@@ -298,8 +304,8 @@
 			npc->bits = (NPC_INVULNERABLE | NPC_IGNORE_SOLIDITY | NPC_SHOW_DAMAGE);
 			npc->life = 700;
 			npc->hit_voice = 114;
-			npc->x = 0x4A000;
-			npc->y = 0xF000;
+			npc->x = 592 * 0x200;
+			npc->y = 120 * 0x200;
 			npc->xm = 0;
 			npc->ym = 0;
 			npc->code_event = 1000;
@@ -318,28 +324,28 @@
 			gBoss[8].bits = NPC_IGNORE_SOLIDITY;
 			gBoss[8].view.front = 0;
 			gBoss[8].view.top = 0;
-			gBoss[8].hit.back = 0x5000;
-			gBoss[8].hit.top = 0x2000;
-			gBoss[8].hit.bottom = 0x2000;
+			gBoss[8].hit.back = 40 * 0x200;
+			gBoss[8].hit.top = 16 * 0x200;
+			gBoss[8].hit.bottom = 16 * 0x200;
 			gBoss[8].count1 = 0;
 
 			gBoss[9] = gBoss[8];
-			gBoss[9].hit.back = 0x4800;
-			gBoss[9].hit.top = 0x3000;
-			gBoss[9].hit.bottom = 0x3000;
+			gBoss[9].hit.back = 36 * 0x200;
+			gBoss[9].hit.top = 24 * 0x200;
+			gBoss[9].hit.bottom = 24 * 0x200;
 			gBoss[9].count1 = 1;
 
 			gBoss[10] = gBoss[8];
-			gBoss[10].hit.back = 0x5800;
-			gBoss[10].hit.top = 0x1000;
-			gBoss[10].hit.bottom = 0x1000;
+			gBoss[10].hit.back = 44 * 0x200;
+			gBoss[10].hit.top = 8 * 0x200;
+			gBoss[10].hit.bottom = 8 * 0x200;
 			gBoss[10].count1 = 2;
 
 			gBoss[11] = gBoss[8];
 			gBoss[11].cond |= 0x10;
-			gBoss[11].hit.back = 0x2800;
-			gBoss[11].hit.top = 0x2800;
-			gBoss[11].hit.bottom = 0x2800;
+			gBoss[11].hit.back = 20 * 0x200;
+			gBoss[11].hit.top = 20 * 0x200;
+			gBoss[11].hit.bottom = 20 * 0x200;
 			gBoss[11].count1 = 3;
 
 			gBoss[1].cond = 0x80;
@@ -347,11 +353,11 @@
 			gBoss[1].bits = (NPC_IGNORE_SOLIDITY | NPC_SHOOTABLE);
 			gBoss[1].life = 1000;
 			gBoss[1].hit_voice = 54;
-			gBoss[1].hit.back = 0x3000;
-			gBoss[1].hit.top = 0x2000;
-			gBoss[1].hit.bottom = 0x2000;
-			gBoss[1].view.front = 0x4000;
-			gBoss[1].view.top = 0x2800;
+			gBoss[1].hit.back = 24 * 0x200;
+			gBoss[1].hit.top = 16 * 0x200;
+			gBoss[1].hit.bottom = 16 * 0x200;
+			gBoss[1].view.front = 32 * 0x200;
+			gBoss[1].view.top = 20 * 0x200;
 			gBoss[1].pNpc = npc;
 
 			gBoss[2] = gBoss[1];
@@ -403,21 +409,24 @@
 		case 201:
 			++npc->act_wait;
 
-			if ((npc->direct == 2 || npc->ani_no > 0 || npc->life < 200) && npc->act_wait > 200)
+			if (npc->direct == 2 || npc->ani_no > 0 || npc->life < 200)
 			{
-				++npc->count1;
-				PlaySoundObject(115, 1);
-
-				if (npc->life < 200)
+				if (npc->act_wait > 200)
 				{
-					npc->act_no = 230;
-				}
-				else
-				{
-					if (npc->count1 > 2)
-						npc->act_no = 220;
+					++npc->count1;
+					PlaySoundObject(115, 1);
+
+					if (npc->life < 200)
+					{
+						npc->act_no = 230;
+					}
 					else
-						npc->act_no = 210;
+					{
+						if (npc->count1 > 2)
+							npc->act_no = 220;
+						else
+							npc->act_no = 210;
+					}
 				}
 			}
 
@@ -437,7 +446,7 @@
 		case 211:
 			++flash;
 
-			if (npc->shock && flash / 2 % 2)
+			if (npc->shock != 0 && flash / 2 % 2)
 			{
 				gBoss[4].ani_no = 1;
 				gBoss[5].ani_no = 1;
@@ -448,7 +457,9 @@
 				gBoss[5].ani_no = 0;
 			}
 
-			if (++npc->act_wait % 100 == 1)
+			++npc->act_wait;
+
+			if (npc->act_wait % 100 == 1)
 			{
 				gCurlyShoot_wait = Random(80, 100);
 				gCurlyShoot_x = gBoss[11].x;
@@ -458,10 +469,10 @@
 			if (npc->act_wait < 300)
 			{
 				if (npc->act_wait % 120 == 1)
-					SetNpChar(288, npc->x - 0x4000, npc->y - 0x2000, 0, 0, 1, 0, 0x20);
+					SetNpChar(288, npc->x - (32 * 0x200), npc->y - (16 * 0x200), 0, 0, 1, NULL, 0x20);
 
 				if (npc->act_wait % 120 == 61)
-					SetNpChar(288, npc->x - 0x4000, npc->y + 0x2000, 0, 0, 3, 0, 0x20);
+					SetNpChar(288, npc->x - (32 * 0x200), npc->y + (16 * 0x200), 0, 0, 3, NULL, 0x20);
 			}
 
 			if (npc->life < life - 50 || npc->act_wait > 400)
@@ -484,7 +495,9 @@
 			bShock = TRUE;
 			// Fallthrough
 		case 221:
-			if (++npc->act_wait % 40 == 1)
+			++npc->act_wait;
+
+			if (npc->act_wait % 40 == 1)
 			{
 				switch (Random(0, 3))
 				{
@@ -507,13 +520,13 @@
 				}
 
 				PlaySoundObject(25, 1);
-				SetNpChar(285, x - 0x2000, y, 0, 0, 0, 0, 0x100);
-				SetNpChar(285, x - 0x2000, y, 0, 0, 0x400, 0, 0x100);
+				SetNpChar(285, x - (16 * 0x200), y, 0, 0, 0, NULL, 0x100);
+				SetNpChar(285, x - (16 * 0x200), y, 0, 0, 0x400, NULL, 0x100);
 			}
 
 			++flash;
 
-			if (npc->shock && flash / 2 % 2)
+			if (npc->shock != 0 && flash / 2 % 2)
 			{
 				gBoss[4].ani_no = 1;
 				gBoss[5].ani_no = 1;
@@ -542,12 +555,12 @@
 
 			PlaySoundObject(25, 1);
 
-			SetNpChar(285, gBoss[3].x - 0x2000, gBoss[3].y, 0, 0, 0, 0, 0x100);
-			SetNpChar(285, gBoss[3].x - 0x2000, gBoss[3].y, 0, 0, 0x400, 0, 0x100);
-			SetNpChar(285, gBoss[3].x, gBoss[3].y - 0x2000, 0, 0, 0, 0, 0x100);
-			SetNpChar(285, gBoss[3].x, gBoss[3].y - 0x2000, 0, 0, 0x400, 0, 0x100);
-			SetNpChar(285, gBoss[3].x, gBoss[3].y + 0x2000, 0, 0, 0, 0, 0x100);
-			SetNpChar(285, gBoss[3].x, gBoss[3].y + 0x2000, 0, 0, 0x400, 0, 0x100);
+			SetNpChar(285, gBoss[3].x - (16 * 0x200), gBoss[3].y, 0, 0, 0, NULL, 0x100);
+			SetNpChar(285, gBoss[3].x - (16 * 0x200), gBoss[3].y, 0, 0, 0x400, NULL, 0x100);
+			SetNpChar(285, gBoss[3].x, gBoss[3].y - (16 * 0x200), 0, 0, 0, NULL, 0x100);
+			SetNpChar(285, gBoss[3].x, gBoss[3].y - (16 * 0x200), 0, 0, 0x400, NULL, 0x100);
+			SetNpChar(285, gBoss[3].x, gBoss[3].y + (16 * 0x200), 0, 0, 0, NULL, 0x100);
+			SetNpChar(285, gBoss[3].x, gBoss[3].y + (16 * 0x200), 0, 0, 0x400, NULL, 0x100);
 
 			life = npc->life;
 			bShock = TRUE;
@@ -555,7 +568,7 @@
 		case 231:
 			++flash;
 
-			if (npc->shock && flash / 2 % 2)
+			if (npc->shock != 0 && flash / 2 % 2)
 			{
 				gBoss[4].ani_no = 1;
 				gBoss[5].ani_no = 1;
@@ -574,10 +587,10 @@
 			}
 
 			if (npc->act_wait % 120 == 1)
-				SetNpChar(288, npc->x - 0x4000, npc->y - 0x2000, 0, 0, 1, 0, 0x20);
+				SetNpChar(288, npc->x - (32 * 0x200), npc->y - (16 * 0x200), 0, 0, 1, NULL, 0x20);
 
 			if (npc->act_wait % 120 == 61)
-				SetNpChar(288, npc->x - 0x4000, npc->y + 0x2000, 0, 0, 3, 0, 0x20);
+				SetNpChar(288, npc->x - (32 * 0x200), npc->y + (16 * 0x200), 0, 0, 3, NULL, 0x20);
 
 			break;
 
@@ -597,7 +610,7 @@
 			SetQuake(20);
 
 			for (i = 0; i < 100; ++i)
-				SetNpChar(4, npc->x + (Random(-0x80, 0x80) * 0x200), npc->y + (Random(-0x40, 0x40) * 0x200), Random(-0x80, 0x80) * 0x200, Random(-0x80, 0x80) * 0x200, 0, 0, 0);
+				SetNpChar(4, npc->x + (Random(-128, 128) * 0x200), npc->y + (Random(-64, 64) * 0x200), Random(-128, 128) * 0x200, Random(-128, 128) * 0x200, 0, NULL, 0);
 
 			DeleteNpCharCode(282, 1);
 			gBoss[11].bits &= ~NPC_SHOOTABLE;
@@ -608,8 +621,8 @@
 		case 501:
 			++npc->act_wait;
 
-			if (npc->act_wait % 0x10)
-				SetNpChar(4, npc->x + (Random(-0x40, 0x40) * 0x200), npc->y + (Random(-0x20, 0x20) * 0x200), Random(-0x80, 0x80) * 0x200, Random(-0x80, 0x80) * 0x200, 0, 0, 0x100);
+			if (npc->act_wait % 0x10 != 0)
+				SetNpChar(4, npc->x + (Random(-64, 64) * 0x200), npc->y + (Random(-32, 32) * 0x200), Random(-128, 128) * 0x200, Random(-128, 128) * 0x200, 0, NULL, 0x100);
 
 			npc->x += 0x40;
 			npc->y += 0x80;
@@ -630,7 +643,7 @@
 			if (gBoss[0].act_wait % 8 == 0)
 				PlaySoundObject(44, 1);
 
-			SetDestroyNpChar(gBoss[0].x + (Random(-0x48, 0x48) * 0x200), gBoss[0].y + (Random(-0x40, 0x40) * 0x200), 1, 1);
+			SetDestroyNpChar(gBoss[0].x + (Random(-72, 72) * 0x200), gBoss[0].y + (Random(-64, 64) * 0x200), 1, 1);
 
 			if (gBoss[0].act_wait > 100)
 			{
@@ -675,14 +688,14 @@
 		PlaySoundObject(26, 1);
 
 		for (i = 0; i < 8; ++i)
-			SetNpChar(4, gBoss[4].x + (Random(-0x20, 0x10) * 0x200), gBoss[4].y, Random(-0x200, 0x200), Random(-0x100, 0x100), 0, 0, 0x100);
+			SetNpChar(4, gBoss[4].x + (Random(-32, 16) * 0x200), gBoss[4].y, Random(-0x200, 0x200), Random(-0x100, 0x100), 0, NULL, 0x100);
 	}
 
 	if (npc->act_no >= 200 && npc->act_no < 300)
 	{
-		if (npc->x < 0x18000)
+		if (npc->x < 192 * 0x200)
 			npc->direct = 2;
-		if (npc->x > (gMap.width - 4) * 0x2000)
+		if (npc->x > (gMap.width - 4) * 0x2000)	// Pixel is inconsistent: the assembly code indicates he really used '0x2000' instead of '0x200 * 0x10', which he usually uses
 			npc->direct = 0;
 
 		if (npc->direct == 0)
@@ -697,14 +710,16 @@
 		case 211:
 		case 221:
 		case 231:
-			if (++npc->count2 == 150)
+			++npc->count2;
+
+			if (npc->count2 == 150)
 			{
 				npc->count2 = 0;
-				SetNpChar(282, (gMap.width * 0x200 * 0x10) + 0x40, (Random(-1, 3) + 10) * 0x2000, 0, 0, 0, 0, 0x30);
+				SetNpChar(282, (gMap.width * 0x200 * 0x10) + 0x40, (Random(-1, 3) + 10) * 0x2000, 0, 0, 0, NULL, 0x30);
 			}
 			else if (npc->count2 == 75)
 			{
-				SetNpChar(282, (gMap.width * 0x200 * 0x10) + 0x40, (Random(-3, 0) + 3) * 0x2000, 0, 0, 0, 0, 0x30);
+				SetNpChar(282, (gMap.width * 0x200 * 0x10) + 0x40, (Random(-3, 0) + 3) * 0x2000, 0, 0, 0, NULL, 0x30);
 			}
 
 			break;