shithub: cstory

Download patch

ref: f6ed183687d60c4d8c7bf20c5e9f38b09e52203c
parent: 986ab280e473ed35ed420103a277f6b3708f1dec
author: Gabriel Ravier <[email protected]>
date: Sat Sep 21 16:04:54 EDT 2019

Remove macros for searching for codes

Signed-off-by: Gabriel Ravier <[email protected]>

--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -26,41 +26,6 @@
 static BOOL gCampActive;
 static int gCampTitleY;
 
-#define FIND_CODE_OR_0(iterator, array, arrayCount, codeVariable) \
-	while ((iterator) < (arrayCount)) \
-	{ \
-		if ((array)[(iterator)].code == (codeVariable)) \
-			break; /* Found identical */ \
-\
-		if ((array)[(iterator)].code == 0) \
-			break; /* Found free slot */ \
-\
-		++(iterator); \
-	}
-
-#define FIND_CODE(iterator, array, arrayCount, codeVariable) \
-	for ((iterator) = 0; (iterator) < (arrayCount); ++(iterator)) \
-		if ((array)[(iterator)].code == (codeVariable)) \
-			break; // Found
-
-// Special version of FIND_CODE using while for accurate code
-#define FIND_CODE_WHILE(iterator, array, arrayCount, codeVariable) \
-	while ((iterator) < (arrayCount)) \
-	{ \
-		if ((array)[(iterator)].code == (codeVariable)) \
-			break; /* Found */ \
-		++(iterator); \
-	} \
-
-/*
-	while (i < ARMS_MAX)
-	{
-		if (gArmsData[i].code == code1)
-			break; // Found
-
-		++i;
-	} */
-
 void ClearArmsData()
 {
 #ifdef FIX_BUGS
@@ -78,8 +43,15 @@
 BOOL AddArmsData(long code, long max_num)
 {
 	int i = 0;
-	FIND_CODE_OR_0(i, gArmsData, ARMS_MAX, code)
+	while (i < ARMS_MAX)
+	{
+		if (gArmsData[i].code == code)
+			break; // Found identical
 
+		if (gArmsData[i].code == 0)
+			break; // Found free slot
+	}
+
 	if (i == ARMS_MAX)
 		return FALSE; // No space left
 
@@ -106,7 +78,9 @@
 {
 	// Find weapon index
 	int i;
-	FIND_CODE(i, gArmsData, ARMS_MAX, code)
+	for (i = 0; i < ARMS_MAX; ++i)
+		if (gArmsData[i].code == code)
+			break; // Found
 
 #ifdef FIX_BUGS
 	if (i == ARMS_MAX)
@@ -129,7 +103,12 @@
 BOOL TradeArms(long code1, long code2, long max_num)
 {
 	int i = 0;
-	FIND_CODE_WHILE(i, gArmsData, ARMS_MAX, code1)
+	while (i < ARMS_MAX)
+	{
+		if (gArmsData[i].code == code1)
+			break; // Found identical
+		++i;
+	}
 
 	if (i == ARMS_MAX)
 		return FALSE; // Not found
@@ -147,8 +126,17 @@
 BOOL AddItemData(long code)
 {
 	int i = 0;
-	FIND_CODE_OR_0(i, gItemData, ITEM_MAX, code)
+	while (i < ITEM_MAX)
+	{
+		if (gItemData[i].code == code)
+			break; // Found identical
 
+		if (gItemData[i].code == 0)
+			break; // Found free slot
+
+		++i;
+	}
+
 	if (i == ITEM_MAX)
 		return FALSE; // Not found
 
@@ -432,6 +420,8 @@
 	LoadTextScript2("ArmsItem.tsc");
 
 	gCampTitleY = (WINDOW_HEIGHT - 192) / 2;
+
+	// Put the cursor on the first weapon
 	gCampActive = FALSE;
 	gSelectedItem = 0;
 
@@ -455,9 +445,9 @@
 			switch (Call_Escape(ghWnd))
 			{
 			case 0:
-				return 0;
+				return 0; // Quit game
 			case 2:
-				return 2;
+				return 2; // Go to game intro
 			}
 		}
 
@@ -467,16 +457,18 @@
 		switch (TextScriptProc())
 		{
 		case 0:
-			return 0;
+			return 0; // Quit game
 		case 2:
-			return 2;
+			return 2; // Go to game intro
 		}
 
+		// Get currently displayed image
 		PutBitmap4(&rcView, 0, 0, &rcView, SURFACE_ID_SCREEN_GRAB);
 		PutCampObject();
 		PutTextScript();
 		PutFramePerSecound();
 
+		// Check whether we're getting out of the loop
 		if (gCampActive)
 		{
 			if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED && gKeyTrg & (gKeyCancel | gKeyItem))
@@ -495,13 +487,13 @@
 		}
 
 		if (!Flip_SystemTask(ghWnd))
-			return 0;
+			return 0; // Quit game
 	}
 
 	// Resume original script
 	LoadTextScript_Stage(old_script_path);
-	gArmsEnergyX = 0x20;
-	return 1;
+	gArmsEnergyX = 0x20; // ?
+	return 1; // Go to game
 }
 
 BOOL CheckItem(long a)
@@ -508,9 +500,9 @@
 {
 	for (int i = 0; i < ITEM_MAX; ++i)
 		if (gItemData[i].code == a)
-			return TRUE;
+			return TRUE; // Found
 
-	return FALSE;
+	return FALSE; // Not found
 }
 
 BOOL CheckArms(long a)