From 358423aa389927d84f1bd5825ae83a664204fa3e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 16 Sep 2019 15:30:38 +0200 Subject: [PATCH] Some nice commenting and reordering of stuff and staticing of stuff Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 28 ++++++++++++++++------------ src/ArmsItem.h | 34 +++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index d4a8d710..c96f5a01 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -14,18 +14,20 @@ #include "Sound.h" #include "TextScr.h" -int gArmsEnergyX = 16; +int gArmsEnergyX = 0x10; + +int gSelectedArms; +int gSelectedItem; ARMS gArmsData[ARMS_MAX]; ITEM gItemData[ITEM_MAX]; -int gSelectedArms; -int gSelectedItem; -int gCampTitleY; -BOOL gCampActive; + +static BOOL gCampActive; +static int gCampTitleY; void ClearArmsData() { - gArmsEnergyX = 32; + gArmsEnergyX = 0x20; memset(gArmsData, 0, sizeof(gArmsData)); } @@ -49,7 +51,7 @@ BOOL AddArmsData(long code, long max_num) } if (i == ARMS_MAX) - return FALSE; + return FALSE; // No space left if (gArmsData[i].code == 0) { @@ -62,6 +64,7 @@ BOOL AddArmsData(long code, long max_num) 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 AddArmsData(long code, long max_num) 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 @@ BOOL SubArmsData(long code) #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 @@ BOOL AddItemData(long code) 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 @@ BOOL SubItemData(long code) return TRUE; } -void MoveCampCursor() +static void MoveCampCursor() { int arms_num = 0; int item_num = 0; @@ -442,7 +446,7 @@ int CampLoop() // Resume original script LoadTextScript_Stage(old_script_path); - gArmsEnergyX = 32; + gArmsEnergyX = 0x20; return 1; } @@ -528,7 +532,7 @@ int RotationArms() if (gSelectedArms == arms_num) gSelectedArms = 0; - gArmsEnergyX = 32; + gArmsEnergyX = 0x20; PlaySoundObject(4, 1); return gArmsData[gSelectedArms].code; diff --git a/src/ArmsItem.h b/src/ArmsItem.h index bc4bf01d..c09ec130 100644 --- 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 int gSelectedItem; 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);