shithub: cstory

Download patch

ref: 358423aa389927d84f1bd5825ae83a664204fa3e
parent: 602315fa39f97c819f1fa0722faa87a91c8dcc70
author: Gabriel Ravier <gabravier@gmail.com>
date: Mon Sep 16 11:30:38 EDT 2019

Some nice commenting and reordering of stuff and staticing of stuff

Signed-off-by: Gabriel Ravier <gabravier@gmail.com>

--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -14,18 +14,20 @@
 #include "Sound.h"
 #include "TextScr.h"
 
-int gArmsEnergyX = 16;
+int gArmsEnergyX = 0x10;
 
-ARMS gArmsData[ARMS_MAX];
-ITEM gItemData[ITEM_MAX];
 int gSelectedArms;
 int gSelectedItem;
-int gCampTitleY;
-BOOL gCampActive;
 
+ARMS gArmsData[ARMS_MAX];
+ITEM gItemData[ITEM_MAX];
+
+static BOOL gCampActive;
+static int gCampTitleY;
+
 void ClearArmsData()
 {
-	gArmsEnergyX = 32;
+	gArmsEnergyX = 0x20;
 	memset(gArmsData, 0, sizeof(gArmsData));
 }
 
@@ -49,7 +51,7 @@
 	}
 
 	if (i == ARMS_MAX)
-		return FALSE;
+		return FALSE;	// No space left
 
 	if (gArmsData[i].code == 0)
 	{
@@ -62,6 +64,7 @@
 	gArmsData[i].max_num += max_num;
 	gArmsData[i].num += max_num;
 
+	// Cap the amount of current ammo to the maximum amount of ammo
 	if (gArmsData[i].num > gArmsData[i].max_num)
 		gArmsData[i].num = gArmsData[i].max_num;
 
@@ -70,6 +73,7 @@
 
 BOOL SubArmsData(long code)
 {
+	// Find weapon index
 	int i;
 	for (i = 0; i < ARMS_MAX; ++i)
 		if (gArmsData[i].code == code)
@@ -80,7 +84,7 @@
 #else
 	if (i == ITEM_MAX)	// Oops
 #endif
-		return FALSE;
+		return FALSE;	// Not found
 
 	// Shift all arms from the right to the left
 	for (++i; i < ARMS_MAX; ++i)
@@ -122,7 +126,7 @@
 	while (i < ITEM_MAX)
 	{
 		if (gItemData[i].code == code)
-			break;
+			break;	// Really, this could just return as the following code won't do anything meaningful in this case
 
 		if (gItemData[i].code == 0)
 			break;
@@ -158,7 +162,7 @@
 	return TRUE;
 }
 
-void MoveCampCursor()
+static void MoveCampCursor()
 {
 	int arms_num = 0;
 	int item_num = 0;
@@ -442,7 +446,7 @@
 
 	// Resume original script
 	LoadTextScript_Stage(old_script_path);
-	gArmsEnergyX = 32;
+	gArmsEnergyX = 0x20;
 	return 1;
 }
 
@@ -528,7 +532,7 @@
 	if (gSelectedArms == arms_num)
 		gSelectedArms = 0;
 
-	gArmsEnergyX = 32;
+	gArmsEnergyX = 0x20;
 	PlaySoundObject(4, 1);
 
 	return gArmsData[gSelectedArms].code;
--- a/src/ArmsItem.h
+++ b/src/ArmsItem.h
@@ -2,22 +2,35 @@
 
 #include "WindowsWrapper.h"
 
+// "Arms" is a synonym of "weapon" here
+// "Code" means "ID" here
+// "Num" often means "ammo" here
+
+/// Weapon struct
 struct ARMS
 {
+	/// ID of the weapon
 	int code;
+
 	int level;
 	int exp;
+
+	/// Maximum ammunition
 	int max_num;
+
+	/// Current ammunition
 	int num;
 };
 
 struct ITEM
 {
+	/// ID of the item
 	int code;
 };
 
+// Limits for the amount of weapons and items
 #define ARMS_MAX 8
-#define ITEM_MAX 32
+#define ITEM_MAX 0x20
 
 extern int gArmsEnergyX;
 
@@ -26,18 +39,29 @@
 
 extern ARMS gArmsData[ARMS_MAX];
 extern ITEM gItemData[ITEM_MAX];
-extern int gSelectedArms;
-extern int gSelectedItem;
-extern int gCampTitleY;
-extern BOOL gCampActive;
 
+/// Clear the gArmsData array, reverting it to the default state (no weapons)
 void ClearArmsData();
+
+/// Clear the gItemData array, reverting it to the default state (no items)
 void ClearItemData();
+
+/// Add code to the weapon array, setting max_num as the max ammo, or find code and add max_num to its ammo. Fails if no space is available and the weapon isn't already present
 BOOL AddArmsData(long code, long max_num);
+
+/// Remove code from the weapon array. Fails if code is not found.
 BOOL SubArmsData(long code);
+
+/// Replace code1 with code2, setting max_num as its max ammo. Fails if code1 is not found.
 BOOL TradeArms(long code1, long code2, long max_num);
+
+/// Add code to the item array. Fails if no space is left
 BOOL AddItemData(long code);
+
+/// Remove code from the item array. Fails if code was not found.
 BOOL SubItemData(long code);
+
+// Inventory loop
 int CampLoop();
 BOOL CheckItem(long a);
 BOOL CheckArms(long a);