Some nice commenting and reordering of stuff and staticing of stuff

Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
This commit is contained in:
Gabriel Ravier 2019-09-16 15:30:38 +02:00
parent 602315fa39
commit 358423aa38
No known key found for this signature in database
GPG key ID: 1E75F156884F3DCE
2 changed files with 45 additions and 17 deletions

View file

@ -14,18 +14,20 @@
#include "Sound.h" #include "Sound.h"
#include "TextScr.h" #include "TextScr.h"
int gArmsEnergyX = 16; int gArmsEnergyX = 0x10;
int gSelectedArms;
int gSelectedItem;
ARMS gArmsData[ARMS_MAX]; ARMS gArmsData[ARMS_MAX];
ITEM gItemData[ITEM_MAX]; ITEM gItemData[ITEM_MAX];
int gSelectedArms;
int gSelectedItem; static BOOL gCampActive;
int gCampTitleY; static int gCampTitleY;
BOOL gCampActive;
void ClearArmsData() void ClearArmsData()
{ {
gArmsEnergyX = 32; gArmsEnergyX = 0x20;
memset(gArmsData, 0, sizeof(gArmsData)); memset(gArmsData, 0, sizeof(gArmsData));
} }
@ -49,7 +51,7 @@ BOOL AddArmsData(long code, long max_num)
} }
if (i == ARMS_MAX) if (i == ARMS_MAX)
return FALSE; return FALSE; // No space left
if (gArmsData[i].code == 0) if (gArmsData[i].code == 0)
{ {
@ -62,6 +64,7 @@ BOOL AddArmsData(long code, long max_num)
gArmsData[i].max_num += max_num; gArmsData[i].max_num += max_num;
gArmsData[i].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) if (gArmsData[i].num > gArmsData[i].max_num)
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) BOOL SubArmsData(long code)
{ {
// Find weapon index
int i; int i;
for (i = 0; i < ARMS_MAX; ++i) for (i = 0; i < ARMS_MAX; ++i)
if (gArmsData[i].code == code) if (gArmsData[i].code == code)
@ -80,7 +84,7 @@ BOOL SubArmsData(long code)
#else #else
if (i == ITEM_MAX) // Oops if (i == ITEM_MAX) // Oops
#endif #endif
return FALSE; return FALSE; // Not found
// Shift all arms from the right to the left // Shift all arms from the right to the left
for (++i; i < ARMS_MAX; ++i) for (++i; i < ARMS_MAX; ++i)
@ -122,7 +126,7 @@ BOOL AddItemData(long code)
while (i < ITEM_MAX) while (i < ITEM_MAX)
{ {
if (gItemData[i].code == code) 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) if (gItemData[i].code == 0)
break; break;
@ -158,7 +162,7 @@ BOOL SubItemData(long code)
return TRUE; return TRUE;
} }
void MoveCampCursor() static void MoveCampCursor()
{ {
int arms_num = 0; int arms_num = 0;
int item_num = 0; int item_num = 0;
@ -442,7 +446,7 @@ int CampLoop()
// Resume original script // Resume original script
LoadTextScript_Stage(old_script_path); LoadTextScript_Stage(old_script_path);
gArmsEnergyX = 32; gArmsEnergyX = 0x20;
return 1; return 1;
} }
@ -528,7 +532,7 @@ int RotationArms()
if (gSelectedArms == arms_num) if (gSelectedArms == arms_num)
gSelectedArms = 0; gSelectedArms = 0;
gArmsEnergyX = 32; gArmsEnergyX = 0x20;
PlaySoundObject(4, 1); PlaySoundObject(4, 1);
return gArmsData[gSelectedArms].code; return gArmsData[gSelectedArms].code;

View file

@ -2,22 +2,35 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
// "Arms" is a synonym of "weapon" here
// "Code" means "ID" here
// "Num" often means "ammo" here
/// Weapon struct
struct ARMS struct ARMS
{ {
/// ID of the weapon
int code; int code;
int level; int level;
int exp; int exp;
/// Maximum ammunition
int max_num; int max_num;
/// Current ammunition
int num; int num;
}; };
struct ITEM struct ITEM
{ {
/// ID of the item
int code; int code;
}; };
// Limits for the amount of weapons and items
#define ARMS_MAX 8 #define ARMS_MAX 8
#define ITEM_MAX 32 #define ITEM_MAX 0x20
extern int gArmsEnergyX; extern int gArmsEnergyX;
@ -26,18 +39,29 @@ extern int gSelectedItem;
extern ARMS gArmsData[ARMS_MAX]; extern ARMS gArmsData[ARMS_MAX];
extern ITEM gItemData[ITEM_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(); void ClearArmsData();
/// Clear the gItemData array, reverting it to the default state (no items)
void ClearItemData(); 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); BOOL AddArmsData(long code, long max_num);
/// Remove code from the weapon array. Fails if code is not found.
BOOL SubArmsData(long code); 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); 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); BOOL AddItemData(long code);
/// Remove code from the item array. Fails if code was not found.
BOOL SubItemData(long code); BOOL SubItemData(long code);
// Inventory loop
int CampLoop(); int CampLoop();
BOOL CheckItem(long a); BOOL CheckItem(long a);
BOOL CheckArms(long a); BOOL CheckArms(long a);