shithub: cstory

Download patch

ref: 7df1eb9c58299683141f4a687f7177722d039002
parent: dcc0f14266e6c8656f76509a9c9b80d910532bad
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Nov 14 18:58:33 EST 2019

Clean-up MycHit.cpp

Found some ASM-inaccuracies in here too

--- a/src/MycHit.cpp
+++ b/src/MycHit.cpp
@@ -14,12 +14,12 @@
 #include "Sound.h"
 #include "TextScr.h"
 
-void ResetMyCharFlag()
+void ResetMyCharFlag(void)
 {
 	gMC.flag = 0;
 }
 
-void PutlittleStar()
+void PutlittleStar(void)
 {
 	if (!(gMC.cond & 2) && gMC.ym < -0x200)
 	{
@@ -407,7 +407,7 @@
 	return hit;
 }
 
-void HitMyCharMap()
+void HitMyCharMap(void)
 {
 	int i;
 
@@ -428,7 +428,7 @@
 	offy[3] = 1;
 
 	unsigned char atrb[4];
-	for (i = 0; i < 4; i++)
+	for (i = 0; i < 4; ++i)
 	{
 		atrb[i] = GetAttribute(x + offx[i], y + offy[i]);
 
@@ -581,7 +581,7 @@
 		}
 	}
 
-	if (gMC.y > gWaterY + 0x800)
+	if (gMC.y > gWaterY + (4 * 0x200))
 		gMC.flag |= 0x100;
 }
 
@@ -589,8 +589,8 @@
 {
 	int hit = 0;
 
-	if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom - 0x600
-		&& gMC.y + gMC.hit.bottom > npc->y - npc->hit.top + 0x600
+	if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom - (3 * 0x200)
+		&& gMC.y + gMC.hit.bottom > npc->y - npc->hit.top + (3 * 0x200)
 		&& gMC.x - gMC.hit.back < npc->x + npc->hit.back
 		&& gMC.x - gMC.hit.back > npc->x)
 	{
@@ -599,8 +599,8 @@
 		hit |= 1;
 	}
 
-	if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom - 0x600
-		&& gMC.y + gMC.hit.bottom > npc->y - npc->hit.top + 0x600
+	if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom - (3 * 0x200)
+		&& gMC.y + gMC.hit.bottom > npc->y - npc->hit.top + (3 * 0x200)
 		&& gMC.x + gMC.hit.back - 0x200 > npc->x - npc->hit.back
 		&& gMC.x + gMC.hit.back - 0x200 < npc->x)
 	{
@@ -609,8 +609,8 @@
 		hit |= 4;
 	}
 
-	if (gMC.x - gMC.hit.back < npc->x + npc->hit.back - 0x600
-		&& gMC.x + gMC.hit.back > npc->x - npc->hit.back + 0x600
+	if (gMC.x - gMC.hit.back < npc->x + npc->hit.back - (3 * 0x200)
+		&& gMC.x + gMC.hit.back > npc->x - npc->hit.back + (3 * 0x200)
 		&& gMC.y - gMC.hit.top < npc->y + npc->hit.bottom
 		&& gMC.y - gMC.hit.top > npc->y)
 	{
@@ -619,10 +619,10 @@
 		hit |= 2;
 	}
 
-	if (gMC.x - gMC.hit.back < npc->x + npc->hit.back - 0x600
-		&& gMC.x + gMC.hit.back > npc->x - npc->hit.back + 0x600
+	if (gMC.x - gMC.hit.back < npc->x + npc->hit.back - (3 * 0x200)
+		&& gMC.x + gMC.hit.back > npc->x - npc->hit.back + (3 * 0x200)
 		&& gMC.y + gMC.hit.bottom > npc->y - npc->hit.top
-		&& gMC.hit.bottom + gMC.y < npc->y + 0x600)
+		&& gMC.hit.bottom + gMC.y < npc->y + (3 * 0x200))
 	{
 		if (npc->bits & NPC_BOUNCY)
 		{
@@ -637,6 +637,7 @@
 			hit |= 8;
 		}
 	}
+
 	return hit;
 }
 
@@ -644,18 +645,18 @@
 {
 	if (npc->direct == 0)
 	{
-		if (gMC.x + 0x400 > npc->x - npc->hit.front
-			&& gMC.x - 0x400 < npc->x + npc->hit.back
-			&& gMC.y + 0x400 > npc->y - npc->hit.top
-			&& gMC.y - 0x400 < npc->y + npc->hit.bottom)
+		if (gMC.x + (2 * 0x200) > npc->x - npc->hit.front
+			&& gMC.x - (2 * 0x200) < npc->x + npc->hit.back
+			&& gMC.y + (2 * 0x200) > npc->y - npc->hit.top
+			&& gMC.y - (2 * 0x200) < npc->y + npc->hit.bottom)
 			return 1;
 	}
 	else
 	{
-		if (gMC.x + 0x400 > npc->x - npc->hit.back
-			&& gMC.x - 0x400 < npc->x + npc->hit.front
-			&& gMC.y + 0x400 > npc->y - npc->hit.top
-			&& gMC.y - 0x400 < npc->y + npc->hit.bottom)
+		if (gMC.x + (2 * 0x200) > npc->x - npc->hit.back
+			&& gMC.x - (2 * 0x200) < npc->x + npc->hit.front
+			&& gMC.y + (2 * 0x200) > npc->y - npc->hit.top
+			&& gMC.y - (2 * 0x200) < npc->y + npc->hit.bottom)
 			return 1;
 	}
 
@@ -698,7 +699,7 @@
 			{
 				if (gMC.ym < npc->ym)
 				{
-					gMC.y = npc->hit.bottom + npc->y + gMC.hit.top + 0x200;
+					gMC.y = npc->y + npc->hit.bottom + gMC.hit.top + 0x200;
 					gMC.ym = npc->ym;
 				}
 				else
@@ -710,9 +711,9 @@
 				hit |= 2;
 			}
 
-			if (gMC.y + gMC.hit.bottom > npc->y - npc->hit.top && gMC.hit.bottom + gMC.y < npc->y + 0x600)
+			if (gMC.y + gMC.hit.bottom > npc->y - npc->hit.top && gMC.hit.bottom + gMC.y < npc->y + (3 * 0x200))
 			{
-				if (gMC.ym - npc->ym > 0x400)
+				if (gMC.ym - npc->ym > 2 * 0x200)
 					PlaySoundObject(23, 1);
 
 				if (gMC.unit == 1)
@@ -744,7 +745,7 @@
 				if (gMC.xm < npc->xm)
 					gMC.xm = npc->xm;
 
-				gMC.x = npc->hit.back + npc->x + gMC.hit.back;
+				gMC.x = npc->x + npc->hit.back + gMC.hit.back;
 
 				hit |= 1;
 			}
@@ -764,18 +765,18 @@
 	return hit;
 }
 
-void HitMyCharNpChar()
+void HitMyCharNpChar(void)
 {
 	int i;
 
 	int hit = 0;
 
-	if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
+	if (!(gMC.cond & 0x80) || gMC.cond & 2)
 		return;
 
-	for (i = 0; i < NPC_MAX; i++)
+	for (i = 0; i < NPC_MAX; ++i)
 	{
-		if ((gNPC[i].cond & 0x80) == 0)
+		if (!(gNPC[i].cond & 0x80))
 			continue;
 
 		hit = 0;
@@ -796,7 +797,7 @@
 		}
 
 		// Special NPCs (pickups)
-		if (hit && gNPC[i].code_char == 1)
+		if (hit != 0 && gNPC[i].code_char == 1)
 		{
 			PlaySoundObject(14, 1);
 			AddExpMyChar(gNPC[i].exp);
@@ -803,7 +804,7 @@
 			gNPC[i].cond = 0;
 		}
 
-		if (hit && gNPC[i].code_char == 86)
+		if (hit != 0 && gNPC[i].code_char == 86)
 		{
 			PlaySoundObject(42, 1);
 			AddBulletMyChar(gNPC[i].code_event, gNPC[i].exp);
@@ -810,7 +811,7 @@
 			gNPC[i].cond = 0;
 		}
 
-		if (hit && gNPC[i].code_char == 87)
+		if (hit != 0 && gNPC[i].code_char == 87)
 		{
 			PlaySoundObject(20, 1);
 			AddLifeMyChar(gNPC[i].exp);
@@ -818,11 +819,11 @@
 		}
 
 		// Run event on contact
-		if ((g_GameFlags & 4) == 0 && hit && gNPC[i].bits & NPC_EVENT_WHEN_TOUCHED)
+		if (!(g_GameFlags & 4) && hit != 0 && gNPC[i].bits & NPC_EVENT_WHEN_TOUCHED)
 			StartTextScript(gNPC[i].code_event);
 
 		// NPC damage
-		if (g_GameFlags & 2 && (gNPC[i].bits & NPC_INTERACTABLE) == 0)
+		if (g_GameFlags & 2 && !(gNPC[i].bits & NPC_INTERACTABLE))
 		{
 			if (gNPC[i].bits & NPC_REAR_AND_TOP_DONT_HURT)
 			{
@@ -835,7 +836,7 @@
 				if (hit & 2 && gNPC[i].ym > 0)
 					DamageMyChar(gNPC[i].damage);
 			}
-			else if (hit && gNPC[i].damage && !(g_GameFlags & 4))
+			else if (hit != 0 && gNPC[i].damage && !(g_GameFlags & 4))
 			{
 				DamageMyChar(gNPC[i].damage);
 			}
@@ -842,7 +843,7 @@
 		}
 
 		// Interaction
-		if ((g_GameFlags & 4) == 0 && hit && gMC.cond & 1 && gNPC[i].bits & NPC_INTERACTABLE)
+		if (!(g_GameFlags & 4) && hit != 0 && gMC.cond & 1 && gNPC[i].bits & NPC_INTERACTABLE)
 		{
 			StartTextScript(gNPC[i].code_event);
 			gMC.xm = 0;
@@ -855,16 +856,18 @@
 		SetCaret(gMC.x, gMC.y, 9, 0);
 }
 
-void HitMyCharBoss()
+void HitMyCharBoss(void)
 {
+	int b;
+
 	int hit = 0;
 
-	if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
+	if (!(gMC.cond & 0x80) || gMC.cond & 2)
 		return;
 
-	for (int b = 0; b < BOSS_MAX; b++)
+	for (b = 0; b < BOSS_MAX; ++b)
 	{
-		if ((gBoss[b].cond & 0x80) == 0)
+		if (!(gBoss[b].cond & 0x80))
 			continue;
 
 		hit = 0;
@@ -884,7 +887,7 @@
 			hit = JudgeHitMyCharNPC3(&gBoss[b]);
 		}
 
-		if (!(g_GameFlags & 4) && hit && gBoss[b].bits & NPC_EVENT_WHEN_TOUCHED)
+		if (!(g_GameFlags & 4) && hit != 0 && gBoss[b].bits & NPC_EVENT_WHEN_TOUCHED)
 		{
 			StartTextScript(gBoss[b].code_event);
 			gMC.ques = 0;
@@ -897,12 +900,12 @@
 			if (hit & 1 && gBoss[b].xm > 0)
 				DamageMyChar(gBoss[b].damage);
 		}
-		else if (hit && gBoss[b].damage && !(g_GameFlags & 4))
+		else if (hit != 0 && gBoss[b].damage != 0 && !(g_GameFlags & 4))
 		{
 			DamageMyChar(gBoss[b].damage);
 		}
 
-		if (!(g_GameFlags & 4) && hit && (gMC.cond & 1) && gBoss[b].bits & NPC_INTERACTABLE)
+		if (!(g_GameFlags & 4) && hit != 0 && gMC.cond & 1 && gBoss[b].bits & NPC_INTERACTABLE)
 		{
 			StartTextScript(gBoss[b].code_event);
 			gMC.xm = 0;
--- a/src/MycHit.h
+++ b/src/MycHit.h
@@ -1,6 +1,6 @@
 #pragma once
 
-void ResetMyCharFlag();
-void HitMyCharMap();
-void HitMyCharNpChar();
-void HitMyCharBoss();
+void ResetMyCharFlag(void);
+void HitMyCharMap(void);
+void HitMyCharNpChar(void);
+void HitMyCharBoss(void);