shithub: cstory

Download patch

ref: 30ad5189f6b3070a4a9528b4dbf3af0f3b1f4896
parent: 7df1eb9c58299683141f4a687f7177722d039002
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Nov 15 07:32:35 EST 2019

Clean-up MyChar.cpp

--- a/src/MyChar.cpp
+++ b/src/MyChar.cpp
@@ -22,21 +22,21 @@
 int noise_no;
 unsigned int noise_freq;
 
-void InitMyChar()
+void InitMyChar(void)
 {
 	memset(&gMC, 0, sizeof(MYCHAR));
 	gMC.cond = 0x80;
 	gMC.direct = 2;
 
-	gMC.view.back = 0x1000;
-	gMC.view.top = 0x1000;
-	gMC.view.front = 0x1000;
-	gMC.view.bottom = 0x1000;
+	gMC.view.back = 8 * 0x200;
+	gMC.view.top = 8 * 0x200;
+	gMC.view.front = 8 * 0x200;
+	gMC.view.bottom = 8 * 0x200;
 
-	gMC.hit.back = 0xA00;
-	gMC.hit.top = 0x1000;
-	gMC.hit.front = 0xA00;
-	gMC.hit.bottom = 0x1000;
+	gMC.hit.back = 5 * 0x200;
+	gMC.hit.top = 8 * 0x200;
+	gMC.hit.front = 5 * 0x200;
+	gMC.hit.bottom = 8 * 0x200;
 
 	gMC.life = 3;
 	gMC.max_life = 3;
@@ -84,7 +84,7 @@
 		{
 			gMC.ani_no = 11;
 		}
-		else if (gKey & gKeyUp && (gKeyRight | gKeyLeft) & gKey && bKey)
+		else if (gKey & gKeyUp && gKey & (gKeyLeft | gKeyRight) && bKey)
 		{
 			gMC.cond |= 4;
 
@@ -91,6 +91,7 @@
 			if (++gMC.ani_wait > 4)
 			{
 				gMC.ani_wait = 0;
+
 				if (++gMC.ani_no == 7 || gMC.ani_no == 9)
 					PlaySoundObject(24, 1);
 			}
@@ -98,7 +99,7 @@
 			if (gMC.ani_no > 9 || gMC.ani_no < 6)
 				gMC.ani_no = 6;
 		}
-		else if ((gKeyRight | gKeyLeft) & gKey && bKey)
+		else if (gKey & (gKeyLeft | gKeyRight) && bKey)
 		{
 			gMC.cond |= 4;
 
@@ -105,6 +106,7 @@
 			if (++gMC.ani_wait > 4)
 			{
 				gMC.ani_wait = 0;
+
 				if (++gMC.ani_no == 2 || gMC.ani_no == 4)
 					PlaySoundObject(24, 1);
 			}
@@ -163,13 +165,13 @@
 {
 	int arms_offset_y;
 
-	if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
+	if (!(gMC.cond & 0x80) || gMC.cond & 2)
 		return;
 
 	// Draw weapon
-	gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13);
+	gMC.rect_arms.left = (gArmsData[gSelectedArms].code % 13) * 24;
 	gMC.rect_arms.right = gMC.rect_arms.left + 24;
-	gMC.rect_arms.top = 96 * (gArmsData[gSelectedArms].code / 13);
+	gMC.rect_arms.top = (gArmsData[gSelectedArms].code / 13) * 96;
 	gMC.rect_arms.bottom = gMC.rect_arms.top + 16;
 
 	if (gMC.direct == 2)
@@ -201,19 +203,19 @@
 	if (gMC.direct == 0)
 		PutBitmap3(
 			&grcGame,
-			(gMC.x - gMC.view.front) / 0x200 - fx / 0x200 - 8,
-			(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
+			((gMC.x - gMC.view.front) / 0x200) - (fx / 0x200) - 8,
+			((gMC.y - gMC.view.top) / 0x200) - (fy / 0x200) + arms_offset_y,
 			&gMC.rect_arms,
 			SURFACE_ID_ARMS);
 	else
 		PutBitmap3(
 			&grcGame,
-			(gMC.x - gMC.view.front) / 0x200 - fx / 0x200,
-			(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
+			((gMC.x - gMC.view.front) / 0x200) - (fx / 0x200),
+			((gMC.y - gMC.view.top) / 0x200) - (fy / 0x200) + arms_offset_y,
 			&gMC.rect_arms,
 			SURFACE_ID_ARMS);
 
-	if ((gMC.shock / 2) % 2)
+	if (gMC.shock / 2 % 2)
 		return;
 
 	// Draw player
@@ -224,7 +226,7 @@
 		rect.bottom += 32;
 	}
 
-	PutBitmap3(&grcGame, (gMC.x - gMC.view.front) / 0x200 - fx / 0x200, (gMC.y - gMC.view.top) / 0x200 - fy / 0x200, &rect, SURFACE_ID_MY_CHAR);
+	PutBitmap3(&grcGame, ((gMC.x - gMC.view.front) / 0x200) - (fx / 0x200), ((gMC.y - gMC.view.top) / 0x200) - (fy / 0x200), &rect, SURFACE_ID_MY_CHAR);
 
 	// Draw air tank
 	RECT rcBubble[2] = {
@@ -234,9 +236,9 @@
 
 	++gMC.bubble;
 	if (gMC.equip & 0x10 && gMC.flag & 0x100)
-		PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
+		PutBitmap3(&grcGame, (gMC.x / 0x200) - 12 - (fx / 0x200), (gMC.y / 0x200) - 12 - (fy / 0x200), &rcBubble[gMC.bubble / 2 % 2], SURFACE_ID_CARET);
 	else if (gMC.unit == 1)
-		PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
+		PutBitmap3(&grcGame, (gMC.x / 0x200) - 12 - (fx / 0x200), (gMC.y / 0x200) - 12 - (fy / 0x200), &rcBubble[gMC.bubble / 2 % 2], SURFACE_ID_CARET);
 }
 
 void ActMyChar_Normal(BOOL bKey)
@@ -281,7 +283,7 @@
 	}
 
 	// Don't create "?" effect
-	gMC.ques = 0;
+	gMC.ques = FALSE;
 
 	// If can't control player, stop boosting
 	if (!bKey)
@@ -309,14 +311,14 @@
 		// Move in direction held
 		if (bKey)
 		{
-			if (gKeyTrg == gKeyDown && gKey == gKeyDown && (gMC.cond & 1) == 0 && (g_GameFlags & 4) == 0)
+			if (gKeyTrg == gKeyDown && gKey == gKeyDown && !(gMC.cond & 1) && !(g_GameFlags & 4))
 			{
 				gMC.cond |= 1;
-				gMC.ques = 1;
+				gMC.ques = TRUE;
 			}
 			else if (gKey == gKeyDown)
 			{
-				
+				// There probably used to be commented-out code here
 			}
 			else
 			{
@@ -356,12 +358,13 @@
 		// Start boosting
 		if (bKey)
 		{
-			if (gMC.equip & 0x21 && gKeyTrg & gKeyJump && gMC.boost_cnt)
+			if (gMC.equip & 0x21 && gKeyTrg & gKeyJump && gMC.boost_cnt != 0)
 			{
 				// Booster 0.8
 				if (gMC.equip & 1)
 				{
 					gMC.boost_sw = 1;
+
 					if (gMC.ym > 0x100)
 						gMC.ym /= 2;
 				}
@@ -415,7 +418,7 @@
 		}
 
 		// Slow down when stopped boosting (Booster 2.0)
-		if (gMC.equip & 0x20 && gMC.boost_sw && (!(gKey & gKeyJump) || !gMC.boost_cnt))
+		if (gMC.equip & 0x20 && gMC.boost_sw != 0 && (!(gKey & gKeyJump) || gMC.boost_cnt == 0))
 		{
 			if (gMC.boost_sw == 1)
 				gMC.xm /= 2;
@@ -424,7 +427,7 @@
 		}
 
 		// Stop boosting
-		if (!gMC.boost_cnt || !(gKey & gKeyJump))
+		if (gMC.boost_cnt == 0 || !(gKey & gKeyJump))
 			gMC.boost_sw = 0;
 	}
 
@@ -437,17 +440,17 @@
 		else
 			gMC.up = FALSE;
 
-		if (gKey & gKeyDown && (gMC.flag & 8) == 0)
+		if (gKey & gKeyDown && !(gMC.flag & 8))
 			gMC.down = TRUE;
 		else
 			gMC.down = FALSE;
 
-		if (gKeyTrg & gKeyJump
-			&& (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20))
+		if (gKeyTrg & gKeyJump && (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20))
 		{
 			if (gMC.flag & 0x2000)
 			{
-				// Another weird empty case needed for accurate assembly
+				// Another weird empty case needed for accurate assembly.
+				// There probably used to be some commented-out code here.
 			}
 			else
 			{
@@ -458,11 +461,11 @@
 	}
 
 	// Stop interacting when moved
-	if (bKey && (gKeyShot | gKeyJump | gKeyUp | gKeyRight | gKeyLeft) & gKey)
+	if (bKey && gKey & (gKeyLeft | gKeyRight | gKeyUp | gKeyJump | gKeyShot))
 		gMC.cond &= ~1;
 
 	// Booster losing fuel
-	if (gMC.boost_sw && gMC.boost_cnt)
+	if (gMC.boost_sw != 0 && gMC.boost_cnt != 0)
 		--gMC.boost_cnt;
 
 	// Wind / current forces
@@ -476,7 +479,7 @@
 		gMC.ym += 0x55;
 
 	// Booster 2.0 forces and effects
-	if (gMC.equip & 0x20 && gMC.boost_sw)
+	if (gMC.equip & 0x20 && gMC.boost_sw != 0)
 	{
 		if (gMC.boost_sw == 1)
 		{
@@ -485,7 +488,7 @@
 				gMC.ym = -0x100;
 
 			// Move in direction facing
-			if (!gMC.direct)
+			if (gMC.direct == 0)
 				gMC.xm -= 0x20;
 			if (gMC.direct == 2)
 				gMC.xm += 0x20;
@@ -493,10 +496,10 @@
 			// Boost particles (and sound)
 			if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
 			{
-				if (!gMC.direct)
-					SetCaret(gMC.x + 0x400, gMC.y + 0x400, 7, 2);
+				if (gMC.direct == 0)
+					SetCaret(gMC.x + (2 * 0x200), gMC.y + (2 * 0x200), 7, 2);
 				if (gMC.direct == 2)
-					SetCaret(gMC.x - 0x400, gMC.y + 0x400, 7, 0);
+					SetCaret(gMC.x - (2 * 0x200), gMC.y + (2 * 0x200), 7, 0);
 
 				PlaySoundObject(113, 1);
 			}
@@ -509,7 +512,7 @@
 			// Boost particles (and sound)
 			if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
 			{
-				SetCaret(gMC.x, gMC.y + 0xC00, 7, 3);
+				SetCaret(gMC.x, gMC.y + (6 * 0x200), 7, 3);
 				PlaySoundObject(113, 1);
 			}
 		}
@@ -516,7 +519,7 @@
 		else if (gMC.boost_sw == 3 && (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1))
 		{
 			// Boost particles (and sound)
-			SetCaret(gMC.x, gMC.y - 0xC00, 7, 1);
+			SetCaret(gMC.x, gMC.y - (6 * 0x200), 7, 1);
 			PlaySoundObject(113, 1);
 		}
 	}
@@ -526,14 +529,14 @@
 		gMC.ym += gravity1;
 	}
 	// Booster 0.8
-	else if (gMC.equip & 1 && gMC.boost_sw && gMC.ym > -0x400)
+	else if (gMC.equip & 1 && gMC.boost_sw != 0 && gMC.ym > -0x400)
 	{
 		// Upwards force
 		gMC.ym -= 0x20;
 
-		if (!(gMC.boost_cnt % 3))
+		if (gMC.boost_cnt % 3 == 0)
 		{
-			SetCaret(gMC.x, gMC.hit.bottom / 2 + gMC.y, 7, 3);
+			SetCaret(gMC.x, gMC.y + (gMC.hit.bottom / 2), 7, 3);
 			PlaySoundObject(113, 1);
 		}
 
@@ -569,13 +572,13 @@
 
 	if (0)
 	{
-		// There used to be an if here that didn't do anything, but the compiler optimised it out.
-		// We only know this was here because empty ifs mess with the register usage.
+		// There used to be an if-statement here that didn't do anything, but the compiler optimised it out.
+		// We only know this was here because empty if-statements affect the register usage.
 		// Since there's no code, we have no idea what the original condition actually was.
 	}
 
 	// Limit speed
-	if ((gMC.flag & 0x100) && (gMC.flag & 0xF000) == 0)
+	if (gMC.flag & 0x100 && !(gMC.flag & 0xF000))
 	{
 		if (gMC.xm < -0x2FF)
 			gMC.xm = -0x2FF;
@@ -602,17 +605,18 @@
 	if (!gMC.sprash && gMC.flag & 0x100)
 	{
 		int dir;
+
 		if (gMC.flag & 0x800)
 			dir = 2;
 		else
 			dir = 0;
 
-		if ((gMC.flag & 8) == 0 && gMC.ym > 0x200)
+		if (!(gMC.flag & 8) && gMC.ym > 0x200)
 		{
-			for (a = 0; a < 8; a++)
+			for (a = 0; a < 8; ++a)
 			{
 				x = gMC.x + (Random(-8, 8) * 0x200);
-				SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - gMC.ym / 2, dir, 0, 0);
+				SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - (gMC.ym / 2), dir, NULL, 0);
 			}
 
 			PlaySoundObject(56, 1);
@@ -621,10 +625,10 @@
 		{
 			if (gMC.xm > 0x200 || gMC.xm < -0x200)
 			{
-				for (a = 0; a < 8; a++)
+				for (a = 0; a < 8; ++a)
 				{
 					x = gMC.x + (Random(-8, 8) * 0x200);
-					SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);
+					SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, NULL, 0);
 				}
 
 				PlaySoundObject(56, 1);
@@ -631,11 +635,11 @@
 			}
 		}
 
-		gMC.sprash = 1;
+		gMC.sprash = TRUE;
 	}
 
 	if (!(gMC.flag & 0x100))
-		gMC.sprash = 0;
+		gMC.sprash = FALSE;
 
 	// Spike damage
 	if (gMC.flag & 0x400)
@@ -697,7 +701,7 @@
 
 	if (bKey)
 	{
-		if (gKey & (gKeyRight | gKeyLeft))
+		if (gKey & (gKeyLeft | gKeyRight))
 		{
 			if (gKey & gKeyLeft)
 				gMC.xm -= 0x100;
@@ -718,7 +722,7 @@
 			gMC.xm += 0x80;
 		}
 
-		if (gKey & (gKeyDown | gKeyUp))
+		if (gKey & (gKeyUp | gKeyDown))
 		{
 			if (gKey & gKeyUp)
 				gMC.ym -= 0x100;
@@ -759,7 +763,7 @@
 	if (gMC.ym < -0x200 && gMC.flag & 2)
 		SetCaret(gMC.x, gMC.y - gMC.hit.top, 13, 5);
 	if (gMC.ym > 0x200 && gMC.flag & 8)
-		SetCaret(gMC.x, gMC.hit.bottom + gMC.y, 13, 5);
+		SetCaret(gMC.x, gMC.y + gMC.hit.bottom, 13, 5);
 
 	if (gMC.xm > 0x400)
 		gMC.xm = 0x400;
@@ -771,7 +775,7 @@
 	if (gMC.ym < -0x400)
 		gMC.ym = -0x400;
 
-	if ((gKey & (gKeyUp | gKeyLeft)) == (gKeyLeft | gKeyUp))
+	if ((gKey & (gKeyLeft | gKeyUp)) == (gKeyLeft | gKeyUp))
 	{
 		if (gMC.xm < -780)
 			gMC.xm = -780;
@@ -779,7 +783,7 @@
 			gMC.ym = -780;
 	}
 
-	if ((gKey & (gKeyUp | gKeyRight)) == (gKeyRight | gKeyUp))
+	if ((gKey & (gKeyRight | gKeyUp)) == (gKeyRight | gKeyUp))
 	{
 		if (gMC.xm > 780)
 			gMC.xm = 780;
@@ -787,7 +791,7 @@
 			gMC.ym = -780;
 	}
 
-	if ((gKey & (gKeyDown | gKeyLeft)) == (gKeyLeft | gKeyDown))
+	if ((gKey & (gKeyLeft | gKeyDown)) == (gKeyLeft | gKeyDown))
 	{
 		if (gMC.xm < -780)
 			gMC.xm = -780;
@@ -795,7 +799,7 @@
 			gMC.ym = 780;
 	}
 
-	if ((gKey & (gKeyDown | gKeyRight)) == (gKeyRight | gKeyDown))
+	if ((gKey & (gKeyRight | gKeyDown)) == (gKeyRight | gKeyDown))
 	{
 		if (gMC.xm > 780)
 			gMC.xm = 780;
@@ -807,7 +811,7 @@
 	gMC.y += gMC.ym;
 }
 
-void AirProcess()
+void AirProcess(void)
 {
 	if (gMC.equip & 0x10)
 	{
@@ -816,7 +820,7 @@
 	}
 	else
 	{
-		if ((gMC.flag & 0x100) == 0)
+		if (!(gMC.flag & 0x100))
 		{
 			gMC.air = 1000;
 		}
@@ -848,9 +852,10 @@
 		{
 			gMC.air_get = 60;
 		}
-		else if (gMC.air_get)
+		else
 		{
-			--gMC.air_get;
+			if (gMC.air_get != 0)
+				--gMC.air_get;
 		}
 	}
 }
@@ -857,17 +862,17 @@
 
 void ActMyChar(BOOL bKey)
 {
-	if ((gMC.cond & 0x80) == 0)
+	if (!(gMC.cond & 0x80))
 		return;
 
-	if (gMC.exp_wait)
+	if (gMC.exp_wait != 0)
 		--gMC.exp_wait;
 
-	if (gMC.shock)
+	if (gMC.shock != 0)
 	{
 		--gMC.shock;
 	}
-	else if (gMC.exp_count)
+	else if (gMC.exp_count != 0)
 	{
 		SetValueView(&gMC.x, &gMC.y, gMC.exp_count);
 		gMC.exp_count = 0;
@@ -878,6 +883,7 @@
 		case 0:
 			if (!(g_GameFlags & 4) && bKey)
 				AirProcess();
+
 			ActMyChar_Normal(bKey);
 			break;
 
@@ -915,12 +921,12 @@
 	gMC.y = y;
 }
 
-void ZeroMyCharXMove()
+void ZeroMyCharXMove(void)
 {
 	gMC.xm = 0;
 }
 
-int GetUnitMyChar()
+int GetUnitMyChar(void)
 {
 	return gMC.unit;
 }
@@ -942,7 +948,8 @@
 		else
 		{
 			int i;
-			for (i = 0; i < NPC_MAX; i++)
+
+			for (i = 0; i < NPC_MAX; ++i)
 				if (gNPC[i].code_event == dir)
 					break;
 
@@ -965,9 +972,9 @@
 	gMC.unit = a;
 }
 
-void PitMyChar()
+void PitMyChar(void)
 {
-	gMC.y += 0x4000;
+	gMC.y += 2 * 0x10 * 0x200;	// Shove player two tiles down. I wonder what this was meant for?
 }
 
 void EquipItem(int flag, BOOL b)
@@ -978,7 +985,7 @@
 		gMC.equip &= ~flag;
 }
 
-void ResetCheck()
+void ResetCheck(void)
 {
 	gMC.cond &= ~1;
 }
@@ -1003,7 +1010,7 @@
 	}
 }
 
-void CutNoise()
+void CutNoise(void)
 {
 	noise_no = 0;
 	PlaySoundObject(40, 0);
@@ -1011,7 +1018,7 @@
 	PlaySoundObject(58, 0);
 }
 
-void ResetNoise()
+void ResetNoise(void)
 {
 	switch (noise_no)
 	{
@@ -1028,7 +1035,7 @@
 	}
 }
 
-void SleepNoise()
+void SleepNoise(void)
 {
 	PlaySoundObject(40, 0);
 	PlaySoundObject(41, 0);
--- a/src/MyChar.h
+++ b/src/MyChar.h
@@ -2,6 +2,9 @@
 
 #include "WindowsWrapper.h"
 
+// TODO - When I add bitmask constants for gMC.flags...
+// 0x100 is a 'player is underwater' flag
+
 struct MYCHAR
 {
 	unsigned char cond;
@@ -52,8 +55,8 @@
 	int lifeBr_count;
 	int air;
 	int air_get;
-	signed char sprash;
-	signed char ques;
+	signed char sprash; // This is explicitly a char, but used like a BOOL
+	signed char ques;   // Same for this variable as well
 	signed char boost_sw;
 	int boost_cnt;
 };
@@ -60,7 +63,7 @@
 
 extern MYCHAR gMC;
 
-void InitMyChar();
+void InitMyChar(void);
 void AnimationMyChar(BOOL bKey);
 void ShowMyChar(BOOL bShow);
 void PutMyChar(int fx, int fy);
@@ -69,14 +72,14 @@
 void GetMyCharPosition(int *x, int *y);
 void SetMyCharPosition(int x, int y);
 void MoveMyChar(int x, int y);
-void ZeroMyCharXMove();
-int GetUnitMyChar();
+void ZeroMyCharXMove(void);
+int GetUnitMyChar(void);
 void SetMyCharDirect(unsigned char dir);
 void ChangeMyUnit(unsigned char a);
-void PitMyChar();
+void PitMyChar(void);
 void EquipItem(int flag, BOOL b);
-void ResetCheck();
+void ResetCheck(void);
 void SetNoise(int no, int freq);
-void CutNoise();
-void ResetNoise();
-void SleepNoise();
+void CutNoise(void);
+void ResetNoise(void);
+void SleepNoise(void);
--- a/src/MycHit.cpp
+++ b/src/MycHit.cpp
@@ -847,7 +847,7 @@
 		{
 			StartTextScript(gNPC[i].code_event);
 			gMC.xm = 0;
-			gMC.ques = 0;
+			gMC.ques = FALSE;
 		}
 	}
 
@@ -890,7 +890,7 @@
 		if (!(g_GameFlags & 4) && hit != 0 && gBoss[b].bits & NPC_EVENT_WHEN_TOUCHED)
 		{
 			StartTextScript(gBoss[b].code_event);
-			gMC.ques = 0;
+			gMC.ques = FALSE;
 		}
 
 		if (gBoss[b].bits & NPC_REAR_AND_TOP_DONT_HURT)
@@ -909,7 +909,7 @@
 		{
 			StartTextScript(gBoss[b].code_event);
 			gMC.xm = 0;
-			gMC.ques = 0;
+			gMC.ques = FALSE;
 		}
 	}