shithub: cstory

Download patch

ref: 93e5812e6ccff0abaeaa583e89a54b762d28d2d4
parent: 16c03115c91c1de2b535fdb0a15b61e94ec9ae0a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Nov 15 19:33:25 EST 2019

Clean-up BulHit.cpp

--- a/src/BulHit.cpp
+++ b/src/BulHit.cpp
@@ -13,6 +13,7 @@
 		PlaySoundObject(28, 1);
 	else
 		SetCaret(bul->x, bul->y, 2, 1);
+
 	bul->cond = 0;
 	SetCaret(bul->x, bul->y, 2, 2);
 }
@@ -21,20 +22,23 @@
 {
 	int i;
 	int hit = 0;
-	if (bul->x - bul->blockXL < (0x10 * x + 8) * 0x200
-		&& bul->x + bul->blockXL > (0x10 * x - 8) * 0x200
-		&& bul->y - bul->blockYL < (0x10 * y + 8) * 0x200
-		&& bul->y + bul->blockYL > (0x10 * y - 8) * 0x200)
+	if (bul->x - bul->blockXL < ((x * 16) + 8) * 0x200
+		&& bul->x + bul->blockXL > ((x * 16) - 8) * 0x200
+		&& bul->y - bul->blockYL < ((y * 16) + 8) * 0x200
+		&& bul->y + bul->blockYL > ((y * 16) - 8) * 0x200)
 		hit |= 0x200;
 
-	if (hit && (bul->bbits & 0x60) && GetAttribute(x, y) == 0x43)
+	if (hit && bul->bbits & 0x60 && GetAttribute(x, y) == 0x43)
 	{
 		if (!(bul->bbits & 0x40))
 			bul->cond = 0;
+
 		SetCaret(bul->x, bul->y, 2, 0);
 		PlaySoundObject(12, 1);
-		for (i = 0; i < 4; i++)
-			SetNpChar(4, x * 0x200 * 0x10, y * 0x200 * 0x10, Random(-0x200, 0x200), Random(-0x200, 0x200), 0, 0, 256);
+
+		for (i = 0; i < 4; ++i)
+			SetNpChar(4, x * 0x200 * 0x10, y * 0x200 * 0x10, Random(-0x200, 0x200), Random(-0x200, 0x200), 0, NULL, 0x100);
+
 		ShiftMapParts(x, y);
 	}
 
@@ -48,15 +52,15 @@
 	int workY;
 	int hit = 0;
 
-	int block[4];
+	BOOL block[4];
 	if (bul->bbits & 0x40)
 	{
-		for (i = 0; i < 4; i++)
+		for (i = 0; i < 4; ++i)
 		{
 			if (*atrb == 0x41 || *atrb == 0x61)
-				block[i] = 1;
+				block[i] = TRUE;
 			else
-				block[i] = 0;
+				block[i] = FALSE;
 
 			++atrb;
 		}
@@ -63,19 +67,19 @@
 	}
 	else
 	{
-		for (i = 0; i < 4; i++)
+		for (i = 0; i < 4; ++i)
 		{
 			if (*atrb == 0x41 || *atrb == 0x43 || *atrb == 0x61)
-				block[i] = 1;
+				block[i] = TRUE;
 			else
-				block[i] = 0;
+				block[i] = FALSE;
 
 			++atrb;
 		}
 	}
 
-	workX = (0x10 * x + 8) * 0x200;
-	workY = (0x10 * y + 8) * 0x200;
+	workX = ((x * 16) + 8) * 0x200;
+	workY = ((y * 16) + 8) * 0x200;
 
 	// Left wall
 	if (block[0] && block[2])
@@ -85,12 +89,12 @@
 	}
 	else if (block[0] && !block[2])
 	{
-		if (bul->x - bul->blockXL < workX && bul->y - bul->blockYL < workY - 0x600)
+		if (bul->x - bul->blockXL < workX && bul->y - bul->blockYL < workY - (3 * 0x200))
 			hit |= 1;
 	}
 	else if (!block[0] && block[2])
 	{
-		if (bul->x - bul->blockXL < workX && bul->y + bul->blockYL > workY + 0x600)
+		if (bul->x - bul->blockXL < workX && bul->y + bul->blockYL > workY + (3 * 0x200))
 			hit |= 1;
 	}
 
@@ -102,12 +106,12 @@
 	}
 	else if (block[1] && !block[3])
 	{
-		if (bul->x + bul->blockXL > workX && bul->y - bul->blockYL < workY - 0x600)
+		if (bul->x + bul->blockXL > workX && bul->y - bul->blockYL < workY - (3 * 0x200))
 			hit |= 4;
 	}
 	else if (!block[1] && block[3])
 	{
-		if (bul->x + bul->blockXL > workX && bul->y + bul->blockYL > workY + 0x600)
+		if (bul->x + bul->blockXL > workX && bul->y + bul->blockYL > workY + (3 * 0x200))
 			hit |= 4;
 	}
 
@@ -119,12 +123,12 @@
 	}
 	else if (block[0] && !block[1])
 	{
-		if (bul->y - bul->blockYL < workY && bul->x - bul->blockXL < workX - 0x600)
+		if (bul->y - bul->blockYL < workY && bul->x - bul->blockXL < workX - (3 * 0x200))
 			hit |= 2;
 	}
 	else if (!block[0] && block[1])
 	{
-		if (bul->y - bul->blockYL < workY && bul->x + bul->blockXL > workX + 0x600)
+		if (bul->y - bul->blockYL < workY && bul->x + bul->blockXL > workX + (3 * 0x200))
 			hit |= 2;
 	}
 
@@ -136,12 +140,12 @@
 	}
 	else if (block[2] && !block[3])
 	{
-		if (bul->y + bul->blockYL > workY && bul->x - bul->blockXL < workX - 0x600)
+		if (bul->y + bul->blockYL > workY && bul->x - bul->blockXL < workX - (3 * 0x200))
 			hit |= 8;
 	}
 	else if (!block[2] && block[3])
 	{
-		if (bul->y + bul->blockYL > workY && bul->x + bul->blockXL > workX + 0x600)
+		if (bul->y + bul->blockYL > workY && bul->x + bul->blockXL > workX + (3 * 0x200))
 			hit |= 8;
 	}
 
@@ -157,9 +161,10 @@
 		else if (hit & 8)
 			bul->y = workY - bul->blockYL;
 	}
-	else if (hit & 0xF)
+	else
 	{
-		Vanish(bul);
+		if (hit & 0xF)
+			Vanish(bul);
 	}
 
 	return hit;
@@ -168,17 +173,19 @@
 int JudgeHitBulletTriangleA(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y - 0x400 < (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x800
-		&& bul->y + 0x400 > (0x10 * y - 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y - (2 * 0x200) < ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) + (4 * 0x200)
+		&& bul->y + (2 * 0x200) > ((y * 16) - 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0xC00;
+			bul->y = ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) + (6 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x82;
 	}
+
 	return hit;
 }
 
@@ -185,17 +192,19 @@
 int JudgeHitBulletTriangleB(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y - 0x400 < (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x800
-		&& bul->y + 0x400 > (0x10 * y - 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y - (2 * 0x200) < ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) - (4 * 0x200)
+		&& bul->y + (2 * 0x200) > ((y * 16) - 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x400;
+			bul->y = ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) - (2 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x82;
 	}
+
 	return hit;
 }
 
@@ -202,17 +211,19 @@
 int JudgeHitBulletTriangleC(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y - 0x400 < (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x800
-		&& bul->y + 0x400 > (0x10 * y - 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y - (2 * 0x200) < ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) - (4 * 0x200)
+		&& bul->y + (2 * 0x200) > ((y * 16) - 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x400;
+			bul->y = ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) - (2 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x42;
 	}
+
 	return hit;
 }
 
@@ -219,17 +230,19 @@
 int JudgeHitBulletTriangleD(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y - 0x400 < (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x800
-		&& bul->y + 0x400 > (0x10 * y - 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y - (2 * 0x200) < ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) + (4 * 0x200)
+		&& bul->y + (2 * 0x200) > ((y * 16) - 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0xC00;
+			bul->y = ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) + (6 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x42;
 	}
+
 	return hit;
 }
 
@@ -236,17 +249,19 @@
 int JudgeHitBulletTriangleE(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x - 0x200 > (0x10 * x - 8) * 0x200
-		&& bul->y + 0x400 > (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0x800
-		&& bul->y - 0x400 < (0x10 * y + 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x - (1 * 0x200) > ((x * 16) - 8) * 0x200
+		&& bul->y + (2 * 0x200) > ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) - (4 * 0x200)
+		&& bul->y - (2 * 0x200) < ((y * 16) + 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 - 0xC00;
+			bul->y = ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) - (6 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x28;
 	}
+
 	return hit;
 }
 
@@ -253,17 +268,19 @@
 int JudgeHitBulletTriangleF(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y + 0x400 > (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x800
-		&& bul->y - 0x400 < (0x10 * y + 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y + (2 * 0x200) > ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) + (4 * 0x200)
+		&& bul->y - (2 * 0x200) < ((y * 16) + 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) + (bul->x - x * 0x10 * 0x200) / 2 + 0x400;
+			bul->y = ((y * 16) * 0x200) + ((bul->x - ((x * 16) * 0x200)) / 2) + (2 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x28;
 	}
+
 	return hit;
 }
 
@@ -270,17 +287,19 @@
 int JudgeHitBulletTriangleG(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y + 0x400 > (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x800
-		&& bul->y - 0x400 < (0x10 * y + 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y + (2 * 0x200) > ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) + (4 * 0x200)
+		&& bul->y - (2 * 0x200) < ((y * 16) + 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 + 0x400;
+			bul->y = ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) + (2 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x18;
 	}
+
 	return hit;
 }
 
@@ -287,21 +306,23 @@
 int JudgeHitBulletTriangleH(int x, int y, BULLET *bul)
 {
 	int hit = 0;
-	if (bul->x < (0x10 * x + 8) * 0x200
-		&& bul->x > (0x10 * x - 8) * 0x200
-		&& bul->y + 0x400 > (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0x800
-		&& bul->y - 0x400 < (0x10 * y + 8) * 0x200)
+	if (bul->x < ((x * 16) + 8) * 0x200
+		&& bul->x > ((x * 16) - 8) * 0x200
+		&& bul->y + (2 * 0x200) > ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) - (4 * 0x200)
+		&& bul->y - (2 * 0x200) < ((y * 16) + 8) * 0x200)
 	{
 		if (bul->bbits & 8)
-			bul->y = (y * 0x10 * 0x200) - (bul->x - x * 0x10 * 0x200) / 2 - 0xC00;
+			bul->y = ((y * 16) * 0x200) - ((bul->x - ((x * 16) * 0x200)) / 2) - (6 * 0x200);
 		else
 			Vanish(bul);
+
 		hit |= 0x18;
 	}
+
 	return hit;
 }
 
-void HitBulletMap()
+void HitBulletMap(void)
 {
 	int i;
 	int j;
@@ -309,12 +330,12 @@
 	int y;
 	unsigned char atrb[4];
 
-	for (i = 0; i < BULLET_MAX; i++)
+	for (i = 0; i < BULLET_MAX; ++i)
 	{
 		int offx[4];
 		int offy[4];
 
-		if ((gBul[i].cond & 0x80) == 0)
+		if (!(gBul[i].cond & 0x80))
 			continue;
 
 		x = gBul[i].x / 0x10 / 0x200;
@@ -340,14 +361,13 @@
 
 		if (gBul[i].bbits & 4)
 		{
-			// Using "continue" here doesn't produce accurate assembly
-			// TODO Figure out what Pixel actually did (it's unlikely he left the brackets empty)
+			// There probably used to be commented-out code here
 		}
 		else
 		{
-			for (j = 0; j < 4; j++)
+			for (j = 0; j < 4; ++j)
 			{
-				if ((gBul[i].cond & 0x80) == 0)
+				if (!(gBul[i].cond & 0x80))
 					continue;
 
 				switch (atrb[j])
@@ -359,34 +379,42 @@
 					case 0x64:
 						gBul[i].flag |= JudgeHitBulletBlock(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x50:
 					case 0x70:
 						gBul[i].flag |= JudgeHitBulletTriangleA(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x51:
 					case 0x71:
 						gBul[i].flag |= JudgeHitBulletTriangleB(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x52:
 					case 0x72:
 						gBul[i].flag |= JudgeHitBulletTriangleC(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x53:
 					case 0x73:
 						gBul[i].flag |= JudgeHitBulletTriangleD(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x54:
 					case 0x74:
 						gBul[i].flag |= JudgeHitBulletTriangleE(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x55:
 					case 0x75:
 						gBul[i].flag |= JudgeHitBulletTriangleF(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x56:
 					case 0x76:
 						gBul[i].flag |= JudgeHitBulletTriangleG(x + offx[j], y + offy[j], &gBul[i]);
 						break;
+
 					case 0x57:
 					case 0x77:
 						gBul[i].flag |= JudgeHitBulletTriangleH(x + offx[j], y + offy[j], &gBul[i]);
@@ -398,4 +426,3 @@
 		}
 	}
 }
-
--- a/src/BulHit.h
+++ b/src/BulHit.h
@@ -1,3 +1,3 @@
 #pragma once
 
-void HitBulletMap();
+void HitBulletMap(void);