From 358423aa389927d84f1bd5825ae83a664204fa3e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 16 Sep 2019 15:30:38 +0200 Subject: [PATCH 01/38] 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); From 9bb916e99d19a949f9ed2f19ffc65d9aefc7f691 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 09:56:33 +0200 Subject: [PATCH 02/38] Set PutCampObject as static and commented some func decls Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 +- src/ArmsItem.h | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index c96f5a01..477dcfc3 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -275,7 +275,7 @@ static void MoveCampCursor() } } -void PutCampObject() +static void PutCampObject() { int i; RECT rcArms; diff --git a/src/ArmsItem.h b/src/ArmsItem.h index c09ec130..c7a2f453 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -40,13 +40,13 @@ extern int gSelectedItem; extern ARMS gArmsData[ARMS_MAX]; extern ITEM gItemData[ITEM_MAX]; -/// Clear the gArmsData array, reverting it to the default state (no weapons) +/// Clear the weapons array, reverting it to the default state (no weapons) void ClearArmsData(); -/// Clear the gItemData array, reverting it to the default state (no items) +/// Clear the item 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 +/// Add code to the weapons, 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. @@ -55,16 +55,22 @@ 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 +/// Add code to the items. Fails if no space is left BOOL AddItemData(long code); -/// Remove code from the item array. Fails if code was not found. +/// Remove code from the item array. Fails if code is not found. BOOL SubItemData(long code); -// Inventory loop +/// Inventory loop. Returns mode. int CampLoop(); + +/// Search for a in the items. Returns whether a was found. BOOL CheckItem(long a); + +/// Search for a in the weapons. Returns whether a was found. BOOL CheckArms(long a); + +/// Remove num ammo from the currently selected weapon. Returns whether there was any ammo left to fire. BOOL UseArmsEnergy(long num); BOOL ChargeArmsEnergy(long num); void FullArmsEnergy(); From f2a2b3fd0c69bec8d51ad99c1c0b7efebb021ef7 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 10:25:18 +0200 Subject: [PATCH 03/38] Commented some func decls in ArmsItem.h and changed a "32" to "0x20" in the cpp Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 +- src/ArmsItem.h | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 477dcfc3..d31ee892 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -569,6 +569,6 @@ int RotationArmsRev() void ChangeToFirstArms() { gSelectedArms = 0; - gArmsEnergyX = 32; + gArmsEnergyX = 0x20; PlaySoundObject(4, 1); } diff --git a/src/ArmsItem.h b/src/ArmsItem.h index c7a2f453..f45601bb 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -28,10 +28,13 @@ struct ITEM int code; }; + // Limits for the amount of weapons and items #define ARMS_MAX 8 #define ITEM_MAX 0x20 + +/// X coordinate for the weapons energy extern int gArmsEnergyX; extern int gSelectedArms; @@ -40,40 +43,59 @@ extern int gSelectedItem; extern ARMS gArmsData[ARMS_MAX]; extern ITEM gItemData[ITEM_MAX]; + /// Clear the weapons array, reverting it to the default state (no weapons) void ClearArmsData(); /// Clear the item array, reverting it to the default state (no items) void ClearItemData(); + /// Add code to the weapons, 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. +/// Remove code from the weapons. 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. +/// 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 items. Fails if no space is left BOOL AddItemData(long code); -/// Remove code from the item array. Fails if code is not found. +/// Remove code from the items. Fails if code is not found BOOL SubItemData(long code); + /// Inventory loop. Returns mode. int CampLoop(); -/// Search for a in the items. Returns whether a was found. + +/// Search for a in the items. Returns whether a was found BOOL CheckItem(long a); -/// Search for a in the weapons. Returns whether a was found. +/// Search for a in the weapons. Returns whether a was found BOOL CheckArms(long a); -/// Remove num ammo from the currently selected weapon. Returns whether there was any ammo left to fire. + +/// Remove num ammo from the currently selected weapon. Returns whether there was any ammo left to fire BOOL UseArmsEnergy(long num); + +/// Add num ammo to the currently selected weapon (capped at the maximum ammunition). Returns true BOOL ChargeArmsEnergy(long num); + +/// Set every weapons ammunition to its maximum ammunition void FullArmsEnergy(); + + +// "Rotation" means "Weapons currently owned by the player (present in the weapons array)" + +/// Change the current weapon to the next one in the rotation. Returns the ID of the newly selected weapon int RotationArms(); + +/// Change the current weapon to the previous one in the rotation. Returns the ID of the newly selected weapon int RotationArmsRev(); + +/// Change the current weapon to be the first one and play the usual rotation animation void ChangeToFirstArms(); From 6ffc8d74294334e84c7922a594937a71707788d3 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 10:31:07 +0200 Subject: [PATCH 04/38] Shorten long line Signed-off-by: Gabriel Ravier --- src/ArmsItem.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ArmsItem.h b/src/ArmsItem.h index f45601bb..6960fce3 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -51,7 +51,8 @@ void ClearArmsData(); void ClearItemData(); -/// Add code to the weapons, 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 +/// Add code to the weapons, 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 weapons. Fails if code is not found From 4766172c3b7307198ed3f8f580011c5e3e8f3937 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 10:48:05 +0200 Subject: [PATCH 05/38] Replaced tabs before comments with spaces, shortened a few lines and formatted some switches Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index d31ee892..643c5e72 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -51,7 +51,7 @@ BOOL AddArmsData(long code, long max_num) } if (i == ARMS_MAX) - return FALSE; // No space left + return FALSE; // No space left if (gArmsData[i].code == 0) { @@ -82,9 +82,9 @@ BOOL SubArmsData(long code) #ifdef FIX_BUGS if (i == ARMS_MAX) #else - if (i == ITEM_MAX) // Oops + if (i == ITEM_MAX) // Oops #endif - return FALSE; // Not found + return FALSE; // Not found // Shift all arms from the right to the left for (++i; i < ARMS_MAX; ++i) @@ -126,7 +126,7 @@ BOOL AddItemData(long code) while (i < ITEM_MAX) { if (gItemData[i].code == code) - break; // Really, this could just return as the following code won't do anything meaningful in this case + break; // Really, this could just return as the following code won't do anything meaningful in this case if (gItemData[i].code == 0) break; @@ -348,9 +348,11 @@ static void PutCampObject() // Draw items cursor if (gCampActive == TRUE) - PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[(flash / 2) % 2], SURFACE_ID_TEXT_BOX); + PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[(flash / 2) % 2], + SURFACE_ID_TEXT_BOX); else - PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[1], SURFACE_ID_TEXT_BOX); + PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[1], + SURFACE_ID_TEXT_BOX); for (i = 0; i < ITEM_MAX; ++i) { @@ -400,10 +402,10 @@ int CampLoop() { switch (Call_Escape(ghWnd)) { - case 0: - return 0; - case 2: - return 2; + case 0: + return 0; + case 2: + return 2; } } @@ -412,10 +414,10 @@ int CampLoop() switch (TextScriptProc()) { - case 0: - return 0; - case 2: - return 2; + case 0: + return 0; + case 2: + return 2; } PutBitmap4(&rcView, 0, 0, &rcView, SURFACE_ID_SCREEN_GRAB); From 3a837a109082ddff8363aa01a8cbc3fe23c66a5d Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 11:04:30 +0200 Subject: [PATCH 06/38] Commented some code Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 643c5e72..995f1dca 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -42,10 +42,10 @@ BOOL AddArmsData(long code, long max_num) while (i < ARMS_MAX) { if (gArmsData[i].code == code) - break; + break; // Found identical if (gArmsData[i].code == 0) - break; + break; // Found free slot ++i; } @@ -55,6 +55,7 @@ BOOL AddArmsData(long code, long max_num) if (gArmsData[i].code == 0) { + // Initialize new weapon memset(&gArmsData[i], 0, sizeof(ARMS)); gArmsData[i].level = 1; } @@ -77,12 +78,12 @@ BOOL SubArmsData(long code) int i; for (i = 0; i < ARMS_MAX; ++i) if (gArmsData[i].code == code) - break; + break; // Found #ifdef FIX_BUGS if (i == ARMS_MAX) #else - if (i == ITEM_MAX) // Oops + if (i == ITEM_MAX) // Wrong #endif return FALSE; // Not found @@ -103,14 +104,15 @@ BOOL TradeArms(long code1, long code2, long max_num) while (i < ARMS_MAX) { if (gArmsData[i].code == code1) - break; + break; // Found ++i; } if (i == ARMS_MAX) - return FALSE; + return FALSE; // Not found + // Initialize new weapon replacing old one, but adding the maximum ammunition to that of the old weapon. gArmsData[i].level = 1; gArmsData[i].code = code2; gArmsData[i].max_num += max_num; @@ -126,16 +128,16 @@ BOOL AddItemData(long code) while (i < ITEM_MAX) { if (gItemData[i].code == code) - break; // Really, this could just return as the following code won't do anything meaningful in this case + break; // Found identical. Really, this could just return as the following code won't do anything meaningful in this case if (gItemData[i].code == 0) - break; + break; // Found free slot ++i; } if (i == ITEM_MAX) - return FALSE; + return FALSE; // Not found gItemData[i].code = code; From 38a00ec88a41f3f12edce32753933eac78cb7a20 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 11:09:29 +0200 Subject: [PATCH 07/38] More tabs to spaces for trailing comments Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 995f1dca..4247e258 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -104,13 +104,13 @@ BOOL TradeArms(long code1, long code2, long max_num) while (i < ARMS_MAX) { if (gArmsData[i].code == code1) - break; // Found + break; // Found ++i; } if (i == ARMS_MAX) - return FALSE; // Not found + return FALSE; // Not found // Initialize new weapon replacing old one, but adding the maximum ammunition to that of the old weapon. gArmsData[i].level = 1; From 372872eeea3fff1f1f648ea7f00c809a3d1820ce Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 17 Sep 2019 11:54:00 +0200 Subject: [PATCH 08/38] Some comments and a FIX_BUGS Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 8 ++++++-- src/ArmsItem.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 4247e258..e0fcb936 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -27,6 +27,9 @@ static int gCampTitleY; void ClearArmsData() { +#ifdef FIX_BUGS + gSelectedArms = 0; // Should probably be done in order to avoid potential problems +#endif gArmsEnergyX = 0x20; memset(gArmsData, 0, sizeof(gArmsData)); } @@ -149,10 +152,10 @@ BOOL SubItemData(long code) int i; for (i = 0; i < ITEM_MAX; ++i) if (gItemData[i].code == code) - break; + break; // Found if (i == ITEM_MAX) - return FALSE; + return FALSE; // Not found // Shift all items from the right to the left for (++i; i < ITEM_MAX; ++i) @@ -164,6 +167,7 @@ BOOL SubItemData(long code) return TRUE; } +/// Handle the moving static void MoveCampCursor() { int arms_num = 0; diff --git a/src/ArmsItem.h b/src/ArmsItem.h index 6960fce3..ec74a0ed 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -44,10 +44,10 @@ extern ARMS gArmsData[ARMS_MAX]; extern ITEM gItemData[ITEM_MAX]; -/// Clear the weapons array, reverting it to the default state (no weapons) +/// Clear the weapons array, reverting it to the default state (no weapons) and adjust variables (initialize weapons basically) void ClearArmsData(); -/// Clear the item array, reverting it to the default state (no items) +/// Clear the item array, reverting it to the default state (no items) (initialize items basically) void ClearItemData(); From 6a9abb9a0d6de39b823976710bc955ae1e048b6b Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Wed, 18 Sep 2019 08:29:20 +0200 Subject: [PATCH 09/38] Moar commenting of stuff and macro-ing of certain things Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 106 +++++++++++++++++++++++++++++------------------ src/Sound.h | 5 +++ 2 files changed, 71 insertions(+), 40 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index e0fcb936..c21bd222 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -22,13 +22,49 @@ int gSelectedItem; ARMS gArmsData[ARMS_MAX]; ITEM gItemData[ITEM_MAX]; +/// True if we're in the items section of the inventory (and not in the weapons section) (only relevant when the inventory is open) 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 - gSelectedArms = 0; // Should probably be done in order to avoid potential problems + gSelectedArms = 0; // Should probably be done in order to avoid potential problems with the selected weapon being invalid (like is done in SubArmsData) #endif gArmsEnergyX = 0x20; memset(gArmsData, 0, sizeof(gArmsData)); @@ -42,16 +78,7 @@ void ClearItemData() BOOL AddArmsData(long code, long max_num) { int i = 0; - while (i < ARMS_MAX) - { - if (gArmsData[i].code == code) - break; // Found identical - - if (gArmsData[i].code == 0) - break; // Found free slot - - ++i; - } + FIND_CODE_OR_0(i, gArmsData, ARMS_MAX, code) if (i == ARMS_MAX) return FALSE; // No space left @@ -79,9 +106,7 @@ BOOL SubArmsData(long code) { // Find weapon index int i; - for (i = 0; i < ARMS_MAX; ++i) - if (gArmsData[i].code == code) - break; // Found + FIND_CODE(i, gArmsData, ARMS_MAX, code) #ifdef FIX_BUGS if (i == ARMS_MAX) @@ -104,13 +129,7 @@ BOOL SubArmsData(long code) BOOL TradeArms(long code1, long code2, long max_num) { int i = 0; - while (i < ARMS_MAX) - { - if (gArmsData[i].code == code1) - break; // Found - - ++i; - } + FIND_CODE_WHILE(i, gArmsData, ARMS_MAX, code1) if (i == ARMS_MAX) return FALSE; // Not found @@ -128,16 +147,7 @@ BOOL TradeArms(long code1, long code2, long max_num) BOOL AddItemData(long code) { int i = 0; - while (i < ITEM_MAX) - { - if (gItemData[i].code == code) - break; // Found identical. Really, this could just return as the following code won't do anything meaningful in this case - - if (gItemData[i].code == 0) - break; // Found free slot - - ++i; - } + FIND_CODE_OR_0(i, gItemData, ITEM_MAX, code) if (i == ITEM_MAX) return FALSE; // Not found @@ -167,9 +177,10 @@ BOOL SubItemData(long code) return TRUE; } -/// Handle the moving +/// Update the inventory cursor static void MoveCampCursor() { + // Compute the current amount of weapons and items int arms_num = 0; int item_num = 0; while (gArmsData[arms_num].code != 0) @@ -178,22 +189,26 @@ static void MoveCampCursor() ++item_num; if (arms_num == 0 && item_num == 0) - return; + return; // Empty inventory + // True if we're currently changing inventory mode (weapons->items / items->weapons) BOOL bChange = FALSE; if (gCampActive == FALSE) { + // Handle selected weapon if (gKeyTrg & gKeyLeft) { --gSelectedArms; bChange = TRUE; } + if (gKeyTrg & gKeyRight) { ++gSelectedArms; bChange = TRUE; } + if (gKeyTrg & (gKeyUp | gKeyDown)) { if (item_num) @@ -202,13 +217,16 @@ static void MoveCampCursor() bChange = TRUE; } + if (gSelectedArms < 0) gSelectedArms = arms_num - 1; + if (gSelectedArms > arms_num - 1) gSelectedArms = 0; } else { + // Handle selected item if (gKeyTrg & gKeyLeft) { if (gSelectedItem % 6 == 0) @@ -262,7 +280,8 @@ static void MoveCampCursor() { if (gCampActive == FALSE) { - PlaySoundObject(4, 1); + // Weapons to items + PlaySoundObject(SND_SWITCH_WEAPON, 1); if (arms_num) StartTextScript(gArmsData[gSelectedArms].code + 1000); @@ -271,7 +290,12 @@ static void MoveCampCursor() } else { - PlaySoundObject(1, 1); + // Items to weapons +#ifdef FIX_BUGS + PlaySoundObject(SND_SWITCH_WEAPON, 1); +#else + PlaySoundObject(SND_YES_NO_CHANGE_CHOICE, 1); // Pretty sure this is not intended +#endif if (item_num) StartTextScript(gItemData[gSelectedItem].code + 5000); @@ -281,16 +305,22 @@ static void MoveCampCursor() } } +/// Draw the inventory static void PutCampObject() { int i; + + /// Rect for the current weapon RECT rcArms; + + /// Rect for the current item RECT rcItem; - // Get rects RECT rcPer = {72, 48, 80, 56}; RECT rcNone = {80, 48, 96, 56}; RECT rcLv = {80, 80, 96, 88}; + + /// Final rect drawn on the screen RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; RECT rcCur1[2] = {{0, 88, 40, 128}, {40, 88, 80, 128}}; RECT rcCur2[2] = {{80, 88, 112, 104}, {80, 104, 112, 120}}; @@ -461,10 +491,8 @@ int CampLoop() BOOL CheckItem(long a) { for (int i = 0; i < ITEM_MAX; ++i) - { if (gItemData[i].code == a) return TRUE; - } return FALSE; } @@ -472,10 +500,8 @@ BOOL CheckItem(long a) BOOL CheckArms(long a) { for (int i = 0; i < ARMS_MAX; ++i) - { if (gArmsData[i].code == a) return TRUE; - } return FALSE; } diff --git a/src/Sound.h b/src/Sound.h index e2a3f9f5..65691e49 100644 --- a/src/Sound.h +++ b/src/Sound.h @@ -15,6 +15,11 @@ enum SoundEffectNames { + SND_YES_NO_CHANGE_CHOICE = 1, + SND_MESSAGE_TYPING = 2, + SND_QUOTE_BUMP_HEAD = 3, + SND_SWITCH_WEAPON = 4, + SND_YES_NO_PROMPT = 5, // To be continued SND_SILLY_EXPLOSION = 25, SND_LARGE_OBJECT_HIT_GROUND = 26, From 79d8e175a2c60e4cb5a2f6f4fdac7f05995b6db8 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Thu, 19 Sep 2019 10:30:14 +0200 Subject: [PATCH 10/38] Documented some variables and macro-ed some stuff Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index c21bd222..ea9f2f28 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -316,13 +316,22 @@ static void PutCampObject() /// Rect for the current item RECT rcItem; + /// Probably the rect for the slash RECT rcPer = {72, 48, 80, 56}; + + /// Rect for when there is no ammo (double dashes) RECT rcNone = {80, 48, 96, 56}; + + /// Rect for the "Lv" text! RECT rcLv = {80, 80, 96, 88}; /// Final rect drawn on the screen RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; + + /// Cursor rect array for weapons, element [1] being for when the cursor is flashing RECT rcCur1[2] = {{0, 88, 40, 128}, {40, 88, 80, 128}}; + + /// Cursor rect array for items, element [1] being for when the cursor is flashing RECT rcCur2[2] = {{80, 88, 112, 104}, {80, 104, 112, 120}}; RECT rcTitle1 = {80, 48, 144, 56}; RECT rcTitle2 = {80, 56, 144, 64}; @@ -353,16 +362,16 @@ static void PutCampObject() else PutBitmap3(&rcView, 40 * gSelectedArms + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT / 2) - 96, &rcCur1[1], SURFACE_ID_TEXT_BOX); - // Draw arms + // Draw weapons for (i = 0; i < ARMS_MAX; ++i) { if (gArmsData[i].code == 0) break; - rcArms.left = 16 * (gArmsData[i].code % 16); - rcArms.right = rcArms.left + 16; - rcArms.top = 16 * (gArmsData[i].code / 16); - rcArms.bottom = rcArms.top + 16; + rcArms.left = TILES_TO_PIXELS(gArmsData[i].code % 0x10); + rcArms.right = rcArms.left + TILES_TO_PIXELS(1); + rcArms.top = TILES_TO_PIXELS(PIXELS_TO_TILES(gArmsData[i].code)); + rcArms.bottom = rcArms.top + TILES_TO_PIXELS(1); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 192) / 2, &rcArms, SURFACE_ID_ARMS_IMAGE); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, &rcPer, SURFACE_ID_TEXT_BOX); From 453ce04e8b6fae24da2fbb87302edb5dfcbd2078 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Fri, 20 Sep 2019 19:16:31 +0200 Subject: [PATCH 11/38] Added a few comments and a newline Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index ea9f2f28..bcc23b61 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -333,6 +333,7 @@ static void PutCampObject() /// Cursor rect array for items, element [1] being for when the cursor is flashing RECT rcCur2[2] = {{80, 88, 112, 104}, {80, 104, 112, 120}}; + RECT rcTitle1 = {80, 48, 144, 56}; RECT rcTitle2 = {80, 56, 144, 64}; RECT rcBoxTop = {0, 0, 244, 8}; @@ -366,13 +367,15 @@ static void PutCampObject() for (i = 0; i < ARMS_MAX; ++i) { if (gArmsData[i].code == 0) - break; + break; // Not a weapon + // Get rect for current weapon rcArms.left = TILES_TO_PIXELS(gArmsData[i].code % 0x10); rcArms.right = rcArms.left + TILES_TO_PIXELS(1); rcArms.top = TILES_TO_PIXELS(PIXELS_TO_TILES(gArmsData[i].code)); rcArms.bottom = rcArms.top + TILES_TO_PIXELS(1); + // Draw the icon, slash and "Lv" PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 192) / 2, &rcArms, SURFACE_ID_ARMS_IMAGE); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, &rcPer, SURFACE_ID_TEXT_BOX); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 160) / 2, &rcLv, SURFACE_ID_TEXT_BOX); From 55cc349dd60d7464b313a93d060970f59c4ac816 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Fri, 20 Sep 2019 20:25:51 +0200 Subject: [PATCH 12/38] Moar commenting stuff Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index bcc23b61..b4da6ae6 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -367,9 +367,9 @@ static void PutCampObject() for (i = 0; i < ARMS_MAX; ++i) { if (gArmsData[i].code == 0) - break; // Not a weapon + break; // Invalid weapon - // Get rect for current weapon + // Get icon rect for next weapon rcArms.left = TILES_TO_PIXELS(gArmsData[i].code % 0x10); rcArms.right = rcArms.left + TILES_TO_PIXELS(1); rcArms.top = TILES_TO_PIXELS(PIXELS_TO_TILES(gArmsData[i].code)); @@ -389,6 +389,7 @@ static void PutCampObject() } else { + // Weapon doesn't use ammunition PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 192) / 2, (WINDOW_HEIGHT - 144) / 2, &rcNone, SURFACE_ID_TEXT_BOX); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 192) / 2, (WINDOW_HEIGHT - 128) / 2, &rcNone, SURFACE_ID_TEXT_BOX); } @@ -405,8 +406,9 @@ static void PutCampObject() for (i = 0; i < ITEM_MAX; ++i) { if (gItemData[i].code == 0) - break; + break; // Invalid item + // Get rect for next item rcItem.left = 32 * (gItemData[i].code % 8); rcItem.right = rcItem.left + 32; rcItem.top = 16 * (gItemData[i].code / 8); From 7de9ecf1e7afd3a01403ceaa992afb63f73ac22e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 12:14:17 +0200 Subject: [PATCH 13/38] Some commenting Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index b4da6ae6..4fcec026 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -425,16 +425,16 @@ int CampLoop() RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; - // Load the inventory script + // Save the current script path (to restore it when we get out of the inventory) GetTextScriptPath(old_script_path); + // Load the inventory script LoadTextScript2("ArmsItem.tsc"); gCampTitleY = (WINDOW_HEIGHT - 192) / 2; gCampActive = FALSE; gSelectedItem = 0; - // Run script arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; From f68ee5c4e5e33abae34e36a1f295954b1b144b9e Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 15:22:42 +0200 Subject: [PATCH 14/38] Added an enum for g_GameFlags and a few comments in CampLoop Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 +++- src/Game.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 4fcec026..8221b7ad 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -435,6 +435,7 @@ int CampLoop() gCampActive = FALSE; gSelectedItem = 0; + // Compute current amount of weapons arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; @@ -448,6 +449,7 @@ int CampLoop() { GetTrg(); + // Handle ESC if (gKeyTrg & KEY_ESCAPE) { switch (Call_Escape(ghWnd)) @@ -459,7 +461,7 @@ int CampLoop() } } - if (g_GameFlags & 2) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED) MoveCampCursor(); switch (TextScriptProc()) diff --git a/src/Game.h b/src/Game.h index e821ed8c..65c20bce 100644 --- a/src/Game.h +++ b/src/Game.h @@ -2,6 +2,11 @@ #include "WindowsWrapper.h" +enum GameFlagsValues +{ + GAME_FLAG_IS_CONTROL_ENABLED = 2, // Idk tbh +}; + extern int g_GameFlags; extern int gCounter; From ac5439cdf53e6c23b1903f87e53903836f9b2dd1 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 15:25:36 +0200 Subject: [PATCH 15/38] Added TBD notes to GameFlag enum Signed-off-by: Gabriel Ravier --- src/Game.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Game.h b/src/Game.h index 65c20bce..9ab95863 100644 --- a/src/Game.h +++ b/src/Game.h @@ -4,7 +4,9 @@ enum GameFlagsValues { + // To be continued GAME_FLAG_IS_CONTROL_ENABLED = 2, // Idk tbh + // To be continued }; extern int g_GameFlags; From 63a8385c54644895ae67ecdcaea1fe4707a53d94 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 18:40:24 +0200 Subject: [PATCH 16/38] Documented bit 2 of g_GameFlags Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 +- src/Game.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 8221b7ad..d16989e6 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -479,7 +479,7 @@ int CampLoop() if (gCampActive) { - if (g_GameFlags & 2 && gKeyTrg & (gKeyCancel | gKeyItem)) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED && gKeyTrg & (gKeyCancel | gKeyItem)) { StopTextScript(); break; diff --git a/src/Game.h b/src/Game.h index 9ab95863..9623063f 100644 --- a/src/Game.h +++ b/src/Game.h @@ -5,7 +5,24 @@ enum GameFlagsValues { // To be continued - GAME_FLAG_IS_CONTROL_ENABLED = 2, // Idk tbh + + /** + * While this bit is set, the game will : + * - Disable manual movement of the character + * - Disable shooting bullets + * - Disable shooting Curly's nemesis + * - Disable changing weapons + * - Disable speeding up the display of text in TSC scripts + * - Disable damage of the character + * - Not display the HUD (Life, EXP, air, weapons) + * - Disable animation of the character + * - Disable movement of the inventory cursor + * - Disable getting out of the inventory while on the item section + * - Create a bullet if some other conditions are fullfilled while iterating over the stars in ActStar (If you have any idea of how that actually works, you may + * want to replace this line with a better explanation) + */ + GAME_FLAG_IS_CONTROL_ENABLED = 2, + // To be continued }; From 337c81da4dd5af85a65b9207de360dabd233f5ac Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 18:48:12 +0200 Subject: [PATCH 17/38] Changed GAME_FLAG_IS_CONTROL_ENABLED to GAME_FLAG_IS_CONTROL_DISABLED Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 ++-- src/Game.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index d16989e6..78fc7f2a 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -461,7 +461,7 @@ int CampLoop() } } - if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_DISABLED) MoveCampCursor(); switch (TextScriptProc()) @@ -479,7 +479,7 @@ int CampLoop() if (gCampActive) { - if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED && gKeyTrg & (gKeyCancel | gKeyItem)) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_DISABLED && gKeyTrg & (gKeyCancel | gKeyItem)) { StopTextScript(); break; diff --git a/src/Game.h b/src/Game.h index 9623063f..9b4d32ff 100644 --- a/src/Game.h +++ b/src/Game.h @@ -21,7 +21,7 @@ enum GameFlagsValues * - Create a bullet if some other conditions are fullfilled while iterating over the stars in ActStar (If you have any idea of how that actually works, you may * want to replace this line with a better explanation) */ - GAME_FLAG_IS_CONTROL_ENABLED = 2, + GAME_FLAG_IS_CONTROL_DISABLED = 2, // To be continued }; From 986ab280e473ed35ed420103a277f6b3708f1dec Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 19:26:58 +0200 Subject: [PATCH 18/38] Revert change from GAME_FLAG_IS_CONTROL_ENABLED to GAME_FLAG_IS_CONTROL_DISABLED and clarify its documentation Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 ++-- src/Game.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 78fc7f2a..d16989e6 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -461,7 +461,7 @@ int CampLoop() } } - if (g_GameFlags & GAME_FLAG_IS_CONTROL_DISABLED) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED) MoveCampCursor(); switch (TextScriptProc()) @@ -479,7 +479,7 @@ int CampLoop() if (gCampActive) { - if (g_GameFlags & GAME_FLAG_IS_CONTROL_DISABLED && gKeyTrg & (gKeyCancel | gKeyItem)) + if (g_GameFlags & GAME_FLAG_IS_CONTROL_ENABLED && gKeyTrg & (gKeyCancel | gKeyItem)) { StopTextScript(); break; diff --git a/src/Game.h b/src/Game.h index 9b4d32ff..07c26336 100644 --- a/src/Game.h +++ b/src/Game.h @@ -7,7 +7,7 @@ enum GameFlagsValues // To be continued /** - * While this bit is set, the game will : + * While this bit is NOT set, the game will : * - Disable manual movement of the character * - Disable shooting bullets * - Disable shooting Curly's nemesis @@ -21,7 +21,7 @@ enum GameFlagsValues * - Create a bullet if some other conditions are fullfilled while iterating over the stars in ActStar (If you have any idea of how that actually works, you may * want to replace this line with a better explanation) */ - GAME_FLAG_IS_CONTROL_DISABLED = 2, + GAME_FLAG_IS_CONTROL_ENABLED = 2, // To be continued }; From f6ed183687d60c4d8c7bf20c5e9f38b09e52203c Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 20:04:54 +0200 Subject: [PATCH 19/38] Remove macros for searching for codes Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 88 ++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index d16989e6..8b0ca15c 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -26,41 +26,6 @@ ITEM gItemData[ITEM_MAX]; 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,7 +43,14 @@ void ClearItemData() 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 @@ BOOL SubArmsData(long code) { // 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 SubArmsData(long code) 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,7 +126,16 @@ BOOL TradeArms(long code1, long code2, long max_num) 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 @@ int CampLoop() LoadTextScript2("ArmsItem.tsc"); gCampTitleY = (WINDOW_HEIGHT - 192) / 2; + + // Put the cursor on the first weapon gCampActive = FALSE; gSelectedItem = 0; @@ -455,9 +445,9 @@ int CampLoop() 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 @@ int CampLoop() 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,22 +487,22 @@ int CampLoop() } 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) { 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) From eb46198635fde10abd14ec48b5241fe97ff38c94 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sat, 21 Sep 2019 20:06:09 +0200 Subject: [PATCH 20/38] Add some comments for the searching of codes Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 8b0ca15c..852d7f79 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -42,6 +42,7 @@ void ClearItemData() BOOL AddArmsData(long code, long max_num) { + // Search for code int i = 0; while (i < ARMS_MAX) { @@ -76,7 +77,7 @@ BOOL AddArmsData(long code, long max_num) BOOL SubArmsData(long code) { - // Find weapon index + // Search for code int i; for (i = 0; i < ARMS_MAX; ++i) if (gArmsData[i].code == code) @@ -102,6 +103,7 @@ BOOL SubArmsData(long code) BOOL TradeArms(long code1, long code2, long max_num) { + // Search for code1 int i = 0; while (i < ARMS_MAX) { @@ -125,6 +127,7 @@ BOOL TradeArms(long code1, long code2, long max_num) BOOL AddItemData(long code) { + // Search for code int i = 0; while (i < ITEM_MAX) { @@ -147,6 +150,7 @@ BOOL AddItemData(long code) BOOL SubItemData(long code) { + // Search for code int i; for (i = 0; i < ITEM_MAX; ++i) if (gItemData[i].code == code) From 9d8018e901e1380042c26ce30697c64c0b6087ad Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 07:28:48 +0200 Subject: [PATCH 21/38] More comments in ArmsItem Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 852d7f79..609bff00 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -203,13 +203,14 @@ static void MoveCampCursor() if (gKeyTrg & (gKeyUp | gKeyDown)) { + // If there are any items, we're changing to the items section, since the weapons section has only 1 row if (item_num) gCampActive = TRUE; bChange = TRUE; } - + // Loop around gSelectedArms if needed if (gSelectedArms < 0) gSelectedArms = arms_num - 1; @@ -513,24 +514,24 @@ BOOL CheckArms(long a) { for (int i = 0; i < ARMS_MAX; ++i) if (gArmsData[i].code == a) - return TRUE; + return TRUE; // Found - return FALSE; + return FALSE; // Not found } BOOL UseArmsEnergy(long num) { if (gArmsData[gSelectedArms].max_num == 0) - return TRUE; + return TRUE; // No ammo needed if (gArmsData[gSelectedArms].num == 0) - return FALSE; + return FALSE; // No ammo left gArmsData[gSelectedArms].num -= num; if (gArmsData[gSelectedArms].num < 0) gArmsData[gSelectedArms].num = 0; - return TRUE; + return TRUE; // Was able to spend ammo } BOOL ChargeArmsEnergy(long num) From 6cd2a498295ab952c18ed8dff83b35a98a93ce95 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 08:46:38 +0200 Subject: [PATCH 22/38] Corrected comment Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 609bff00..14ed98e2 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -183,7 +183,7 @@ static void MoveCampCursor() if (arms_num == 0 && item_num == 0) return; // Empty inventory - // True if we're currently changing inventory mode (weapons->items / items->weapons) + /// True if we're currently changing cursor position BOOL bChange = FALSE; if (gCampActive == FALSE) @@ -538,10 +538,11 @@ BOOL ChargeArmsEnergy(long num) { gArmsData[gSelectedArms].num += num; + // Cap the ammo to the maximum ammunition if (gArmsData[gSelectedArms].num > gArmsData[gSelectedArms].max_num) gArmsData[gSelectedArms].num = gArmsData[gSelectedArms].max_num; - return TRUE; + return TRUE; // Always successfull } void FullArmsEnergy() From c94d1f1379c4ddbdbd2407f2df30dd00b59e2018 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 09:25:55 +0200 Subject: [PATCH 23/38] Corrected some comments in ArmsItem Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 14ed98e2..b65c78e8 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -273,7 +273,7 @@ static void MoveCampCursor() { if (gCampActive == FALSE) { - // Weapons to items + // Switch to a weapon PlaySoundObject(SND_SWITCH_WEAPON, 1); if (arms_num) @@ -283,7 +283,7 @@ static void MoveCampCursor() } else { - // Items to weapons + // Switch to an item #ifdef FIX_BUGS PlaySoundObject(SND_SWITCH_WEAPON, 1); #else From d73f82cfcf62a585ea9d17cfc7734ccab6356e65 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 10:32:23 +0200 Subject: [PATCH 24/38] Removed wrong FIX_BUGS Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index b65c78e8..56597a2c 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -284,11 +284,7 @@ static void MoveCampCursor() else { // Switch to an item -#ifdef FIX_BUGS - PlaySoundObject(SND_SWITCH_WEAPON, 1); -#else - PlaySoundObject(SND_YES_NO_CHANGE_CHOICE, 1); // Pretty sure this is not intended -#endif + PlaySoundObject(SND_YES_NO_CHANGE_CHOICE, 1); if (item_num) StartTextScript(gItemData[gSelectedItem].code + 5000); From b4ef218dcae2827a176f57cbac7455a64c3170d4 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 10:34:07 +0200 Subject: [PATCH 25/38] Removed unnecessary "and" from comment Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 56597a2c..e2e10f83 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -22,7 +22,7 @@ int gSelectedItem; ARMS gArmsData[ARMS_MAX]; ITEM gItemData[ITEM_MAX]; -/// True if we're in the items section of the inventory (and not in the weapons section) (only relevant when the inventory is open) +/// True if we're in the items section of the inventory (not in the weapons section) (only relevant when the inventory is open) static BOOL gCampActive; static int gCampTitleY; From 4fc38593d2f686004bc4021f1106ff7c99aae9a0 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 19:47:34 +0200 Subject: [PATCH 26/38] More comments in ArmsItem Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index e2e10f83..6051a297 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -233,9 +233,9 @@ static void MoveCampCursor() if (gKeyTrg & gKeyRight) { if (gSelectedItem == item_num - 1) - gSelectedItem = 6 * (gSelectedItem / 6); + gSelectedItem = 6 * (gSelectedItem / 6); // Round down to multiple of 6 else if (gSelectedItem % 6 == 5) - gSelectedItem -= 5; + gSelectedItem -= 5; // Loop around row else ++gSelectedItem; @@ -245,7 +245,7 @@ static void MoveCampCursor() if (gKeyTrg & gKeyUp) { if (gSelectedItem / 6 == 0) - gCampActive = FALSE; + gCampActive = FALSE; // We're on the first row, transition to weapons else gSelectedItem -= 6; @@ -255,7 +255,7 @@ static void MoveCampCursor() if (gKeyTrg & gKeyDown) { if (gSelectedItem / 6 == (item_num - 1) / 6) - gCampActive = FALSE; + gCampActive = FALSE; // We're on the last row, transition to weapons else gSelectedItem += 6; @@ -263,7 +263,7 @@ static void MoveCampCursor() } if (gSelectedItem >= item_num) - gSelectedItem = item_num - 1; + gSelectedItem = item_num - 1; // Don't allow selecting a non-existing item if (gCampActive && gKeyTrg & gKeyOk) StartTextScript(gItemData[gSelectedItem].code + 6000); From ba8f2138b8c19a91dd275a38c98e4c116c4eac62 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 19:52:34 +0200 Subject: [PATCH 27/38] Finished commenting ArmsItem basically Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 6051a297..63365e22 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -546,7 +546,7 @@ void FullArmsEnergy() for (int a = 0; a < ARMS_MAX; a++) { if (gArmsData[a].code == 0) - continue; + continue; // Don't change empty weapons gArmsData[a].num = gArmsData[a].max_num; } @@ -554,6 +554,7 @@ void FullArmsEnergy() int RotationArms() { + // Get amount of weapons int arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; @@ -563,6 +564,7 @@ int RotationArms() ResetSpurCharge(); + // Select next valid weapon ++gSelectedArms; while (gSelectedArms < arms_num) @@ -577,13 +579,14 @@ int RotationArms() gSelectedArms = 0; gArmsEnergyX = 0x20; - PlaySoundObject(4, 1); + PlaySoundObject(SND_SWITCH_WEAPON, 1); return gArmsData[gSelectedArms].code; } int RotationArmsRev() { + // Get amount of weapons int arms_num = 0; while (gArmsData[arms_num].code != 0) ++arms_num; @@ -593,6 +596,7 @@ int RotationArmsRev() ResetSpurCharge(); + // Select previous valid weapon if (--gSelectedArms < 0) gSelectedArms = arms_num - 1; @@ -605,7 +609,7 @@ int RotationArmsRev() } gArmsEnergyX = 0; - PlaySoundObject(4, 1); + PlaySoundObject(SND_SWITCH_WEAPON, 1); return gArmsData[gSelectedArms].code; } @@ -614,5 +618,5 @@ void ChangeToFirstArms() { gSelectedArms = 0; gArmsEnergyX = 0x20; - PlaySoundObject(4, 1); + PlaySoundObject(SND_SWITCH_WEAPON, 1); } From 3f6c744e16aa1460efa9f57e1e9e2f05973ddcff Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 19:57:00 +0200 Subject: [PATCH 28/38] Re-added accidentally removed statement Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 63365e22..0d4b405e 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -51,6 +51,8 @@ BOOL AddArmsData(long code, long max_num) if (gArmsData[i].code == 0) break; // Found free slot + + ++i; } if (i == ARMS_MAX) From e5e01b2b3eba5e14dd8a68d2251a46334a8f20bc Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 19:59:16 +0200 Subject: [PATCH 29/38] Re-added accidentally removed spacing Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 0d4b405e..5b57a938 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -111,6 +111,7 @@ BOOL TradeArms(long code1, long code2, long max_num) { if (gArmsData[i].code == code1) break; // Found identical + ++i; } From 07dc0aff9f9081a71686d750303131811f3071a4 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:12:20 +0200 Subject: [PATCH 30/38] Removed static from MoveArmsCursor to fix function ordering Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 5b57a938..1545cb51 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -173,7 +173,7 @@ BOOL SubItemData(long code) } /// Update the inventory cursor -static void MoveCampCursor() +void MoveCampCursor() { // Compute the current amount of weapons and items int arms_num = 0; From 5ca917bc97de25b736b9341757d10483a0a94c11 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:16:09 +0200 Subject: [PATCH 31/38] Removed usage of TILES_TO_PIXELS/PIXELS_TO_TILES in PutCampObject Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 1545cb51..71fc7935 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -362,10 +362,10 @@ static void PutCampObject() break; // Invalid weapon // Get icon rect for next weapon - rcArms.left = TILES_TO_PIXELS(gArmsData[i].code % 0x10); - rcArms.right = rcArms.left + TILES_TO_PIXELS(1); - rcArms.top = TILES_TO_PIXELS(PIXELS_TO_TILES(gArmsData[i].code)); - rcArms.bottom = rcArms.top + TILES_TO_PIXELS(1); + rcArms.left = (gArmsData[i].code % 16) * 16; + rcArms.right = rcArms.left + 16; + rcArms.top = ((gArmsData[i].code) / 16) * 16; + rcArms.bottom = rcArms.top + 16; // Draw the icon, slash and "Lv" PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 192) / 2, &rcArms, SURFACE_ID_ARMS_IMAGE); From 818640781bbd618728cf5814e283d1f52bc04c8a Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:18:49 +0200 Subject: [PATCH 32/38] Fixed switch formatting Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 71fc7935..c5a74842 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -448,10 +448,10 @@ int CampLoop() { switch (Call_Escape(ghWnd)) { - case 0: - return 0; // Quit game - case 2: - return 2; // Go to game intro + case 0: + return 0; // Quit game + case 2: + return 2; // Go to game intro } } @@ -460,10 +460,10 @@ int CampLoop() switch (TextScriptProc()) { - case 0: - return 0; // Quit game - case 2: - return 2; // Go to game intro + case 0: + return 0; // Quit game + case 2: + return 2; // Go to game intro } // Get currently displayed image From e2c7ea8996561f17cf026939d4097de1f5f4a6ab Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:22:49 +0200 Subject: [PATCH 33/38] Left long lines long instead of making them take several lines Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index c5a74842..4fb60649 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -389,11 +389,9 @@ static void PutCampObject() // Draw items cursor if (gCampActive == TRUE) - PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[(flash / 2) % 2], - SURFACE_ID_TEXT_BOX); + PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[(flash / 2) % 2], SURFACE_ID_TEXT_BOX); else - PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[1], - SURFACE_ID_TEXT_BOX); + PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[1], SURFACE_ID_TEXT_BOX); for (i = 0; i < ITEM_MAX; ++i) { From 417fce45b31ff833f4cf0d42abc51ca8d8519cef Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:25:55 +0200 Subject: [PATCH 34/38] Fixed other static function --- src/ArmsItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 4fb60649..52ba98aa 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -298,7 +298,7 @@ void MoveCampCursor() } /// Draw the inventory -static void PutCampObject() +void PutCampObject() { int i; From b2b9d8ab128e5f2c126300697816e447593d2141 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Mon, 23 Sep 2019 20:29:09 +0200 Subject: [PATCH 35/38] Used tabs instead of spaces before trailing comments Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 52ba98aa..05339d72 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -47,16 +47,16 @@ BOOL AddArmsData(long code, long max_num) while (i < ARMS_MAX) { if (gArmsData[i].code == code) - break; // Found identical + break; // Found identical if (gArmsData[i].code == 0) - break; // Found free slot + break; // Found free slot ++i; } if (i == ARMS_MAX) - return FALSE; // No space left + return FALSE; // No space left if (gArmsData[i].code == 0) { @@ -83,14 +83,14 @@ BOOL SubArmsData(long code) int i; for (i = 0; i < ARMS_MAX; ++i) if (gArmsData[i].code == code) - break; // Found + break; // Found #ifdef FIX_BUGS if (i == ARMS_MAX) #else - if (i == ITEM_MAX) // Wrong + if (i == ITEM_MAX) // Wrong #endif - return FALSE; // Not found + return FALSE; // Not found // Shift all arms from the right to the left for (++i; i < ARMS_MAX; ++i) @@ -110,13 +110,13 @@ BOOL TradeArms(long code1, long code2, long max_num) while (i < ARMS_MAX) { if (gArmsData[i].code == code1) - break; // Found identical + break; // Found identical ++i; } if (i == ARMS_MAX) - return FALSE; // Not found + return FALSE; // Not found // Initialize new weapon replacing old one, but adding the maximum ammunition to that of the old weapon. gArmsData[i].level = 1; @@ -135,16 +135,16 @@ BOOL AddItemData(long code) while (i < ITEM_MAX) { if (gItemData[i].code == code) - break; // Found identical + break; // Found identical if (gItemData[i].code == 0) - break; // Found free slot + break; // Found free slot ++i; } if (i == ITEM_MAX) - return FALSE; // Not found + return FALSE; // Not found gItemData[i].code = code; @@ -157,10 +157,10 @@ BOOL SubItemData(long code) int i; for (i = 0; i < ITEM_MAX; ++i) if (gItemData[i].code == code) - break; // Found + break; // Found if (i == ITEM_MAX) - return FALSE; // Not found + return FALSE; // Not found // Shift all items from the right to the left for (++i; i < ITEM_MAX; ++i) @@ -236,9 +236,9 @@ void MoveCampCursor() if (gKeyTrg & gKeyRight) { if (gSelectedItem == item_num - 1) - gSelectedItem = 6 * (gSelectedItem / 6); // Round down to multiple of 6 + gSelectedItem = 6 * (gSelectedItem / 6); // Round down to multiple of 6 else if (gSelectedItem % 6 == 5) - gSelectedItem -= 5; // Loop around row + gSelectedItem -= 5; // Loop around row else ++gSelectedItem; @@ -248,7 +248,7 @@ void MoveCampCursor() if (gKeyTrg & gKeyUp) { if (gSelectedItem / 6 == 0) - gCampActive = FALSE; // We're on the first row, transition to weapons + gCampActive = FALSE; // We're on the first row, transition to weapons else gSelectedItem -= 6; @@ -258,7 +258,7 @@ void MoveCampCursor() if (gKeyTrg & gKeyDown) { if (gSelectedItem / 6 == (item_num - 1) / 6) - gCampActive = FALSE; // We're on the last row, transition to weapons + gCampActive = FALSE; // We're on the last row, transition to weapons else gSelectedItem += 6; @@ -266,7 +266,7 @@ void MoveCampCursor() } if (gSelectedItem >= item_num) - gSelectedItem = item_num - 1; // Don't allow selecting a non-existing item + gSelectedItem = item_num - 1; // Don't allow selecting a non-existing item if (gCampActive && gKeyTrg & gKeyOk) StartTextScript(gItemData[gSelectedItem].code + 6000); @@ -359,7 +359,7 @@ void PutCampObject() for (i = 0; i < ARMS_MAX; ++i) { if (gArmsData[i].code == 0) - break; // Invalid weapon + break; // Invalid weapon // Get icon rect for next weapon rcArms.left = (gArmsData[i].code % 16) * 16; @@ -396,7 +396,7 @@ void PutCampObject() for (i = 0; i < ITEM_MAX; ++i) { if (gItemData[i].code == 0) - break; // Invalid item + break; // Invalid item // Get rect for next item rcItem.left = 32 * (gItemData[i].code % 8); @@ -447,9 +447,9 @@ int CampLoop() switch (Call_Escape(ghWnd)) { case 0: - return 0; // Quit game + return 0; // Quit game case 2: - return 2; // Go to game intro + return 2; // Go to game intro } } @@ -459,9 +459,9 @@ int CampLoop() switch (TextScriptProc()) { case 0: - return 0; // Quit game + return 0; // Quit game case 2: - return 2; // Go to game intro + return 2; // Go to game intro } // Get currently displayed image @@ -489,46 +489,46 @@ int CampLoop() } if (!Flip_SystemTask(ghWnd)) - return 0; // Quit game + return 0; // Quit game } // Resume original script LoadTextScript_Stage(old_script_path); gArmsEnergyX = 0x20; // ? - return 1; // Go to game + return 1; // Go to game } BOOL CheckItem(long a) { for (int i = 0; i < ITEM_MAX; ++i) if (gItemData[i].code == a) - return TRUE; // Found + return TRUE; // Found - return FALSE; // Not found + return FALSE; // Not found } BOOL CheckArms(long a) { for (int i = 0; i < ARMS_MAX; ++i) if (gArmsData[i].code == a) - return TRUE; // Found + return TRUE; // Found - return FALSE; // Not found + return FALSE; // Not found } BOOL UseArmsEnergy(long num) { if (gArmsData[gSelectedArms].max_num == 0) - return TRUE; // No ammo needed + return TRUE; // No ammo needed if (gArmsData[gSelectedArms].num == 0) - return FALSE; // No ammo left + return FALSE; // No ammo left gArmsData[gSelectedArms].num -= num; if (gArmsData[gSelectedArms].num < 0) gArmsData[gSelectedArms].num = 0; - return TRUE; // Was able to spend ammo + return TRUE; // Was able to spend ammo } BOOL ChargeArmsEnergy(long num) @@ -539,7 +539,7 @@ BOOL ChargeArmsEnergy(long num) if (gArmsData[gSelectedArms].num > gArmsData[gSelectedArms].max_num) gArmsData[gSelectedArms].num = gArmsData[gSelectedArms].max_num; - return TRUE; // Always successfull + return TRUE; // Always successfull } void FullArmsEnergy() @@ -547,7 +547,7 @@ void FullArmsEnergy() for (int a = 0; a < ARMS_MAX; a++) { if (gArmsData[a].code == 0) - continue; // Don't change empty weapons + continue; // Don't change empty weapons gArmsData[a].num = gArmsData[a].max_num; } From 6645b85139985d61a2b1f54041b952f031e06a89 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 24 Sep 2019 09:30:44 +0200 Subject: [PATCH 36/38] Change gArmsEnergyX stuff from hexadecimal to decimal. Also commented some more stuff. Signed-off-by: Gabriel Ravier --- src/ArmsItem.cpp | 10 +++++----- src/ArmsItem.h | 9 ++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 05339d72..0723db39 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -14,7 +14,7 @@ #include "Sound.h" #include "TextScr.h" -int gArmsEnergyX = 0x10; +int gArmsEnergyX = 16; int gSelectedArms; int gSelectedItem; @@ -31,7 +31,7 @@ void ClearArmsData() #ifdef FIX_BUGS gSelectedArms = 0; // Should probably be done in order to avoid potential problems with the selected weapon being invalid (like is done in SubArmsData) #endif - gArmsEnergyX = 0x20; + gArmsEnergyX = 32; memset(gArmsData, 0, sizeof(gArmsData)); } @@ -494,7 +494,7 @@ int CampLoop() // Resume original script LoadTextScript_Stage(old_script_path); - gArmsEnergyX = 0x20; // ? + gArmsEnergyX = 32; // Displays weapon rotation animation in case the weapon was changed return 1; // Go to game } @@ -579,7 +579,7 @@ int RotationArms() if (gSelectedArms == arms_num) gSelectedArms = 0; - gArmsEnergyX = 0x20; + gArmsEnergyX = 32; PlaySoundObject(SND_SWITCH_WEAPON, 1); return gArmsData[gSelectedArms].code; @@ -618,6 +618,6 @@ int RotationArmsRev() void ChangeToFirstArms() { gSelectedArms = 0; - gArmsEnergyX = 0x20; + gArmsEnergyX = 32; PlaySoundObject(SND_SWITCH_WEAPON, 1); } diff --git a/src/ArmsItem.h b/src/ArmsItem.h index ec74a0ed..0bfbe041 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -34,13 +34,20 @@ struct ITEM #define ITEM_MAX 0x20 -/// X coordinate for the weapons energy +/// X coordinate for the weapons HUD section. Set it to 32 for the forward weapon rotation "animation", 0 for the reverse weapon rotation "animation" and 16 to immobilise it extern int gArmsEnergyX; + +/// Currently selected weapon extern int gSelectedArms; + +// Currently selected item extern int gSelectedItem; +/// Contains data for all the weapons the character currently has extern ARMS gArmsData[ARMS_MAX]; + +/// Contains data for all the items the character currently has extern ITEM gItemData[ITEM_MAX]; From bf1239c4a18d9732eda63998ecf7de7b255635ca Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 24 Sep 2019 09:32:21 +0200 Subject: [PATCH 37/38] Commented all members of ARMS Signed-off-by: Gabriel Ravier --- src/ArmsItem.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ArmsItem.h b/src/ArmsItem.h index 0bfbe041..4ec5b407 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -12,7 +12,10 @@ struct ARMS /// ID of the weapon int code; + /// Current level of the weapon int level; + + /// Current EXP of the weapon, is reset to 0 at each level up int exp; /// Maximum ammunition From a67700d92709c332ae7f345767b353d122b7c8e0 Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 24 Sep 2019 10:12:05 +0200 Subject: [PATCH 38/38] Clarify vague comment Signed-off-by: Gabriel Ravier --- src/ArmsItem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArmsItem.h b/src/ArmsItem.h index 4ec5b407..811a1b05 100644 --- a/src/ArmsItem.h +++ b/src/ArmsItem.h @@ -15,7 +15,7 @@ struct ARMS /// Current level of the weapon int level; - /// Current EXP of the weapon, is reset to 0 at each level up + /// Current EXP of the weapon. It is counted from the current level (it's reset to 0 at each level up) int exp; /// Maximum ammunition