ref: 1a0cb626f89e3db102b5285da57e125869d9f411
parent: 5914ce01efe150ba5fd14823eaa92d8d2d788866
author: Clownacy <[email protected]>
date: Sun Nov 17 11:51:44 EST 2019
Clean-up ArmsItem.cpp
--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -26,7 +26,7 @@
static BOOL gCampActive;
static int gCampTitleY;
-void ClearArmsData()
+void ClearArmsData(void)
{
#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)
@@ -35,7 +35,7 @@
memset(gArmsData, 0, sizeof(gArmsData));
}
-void ClearItemData()
+void ClearItemData(void)
{
memset(gItemData, 0, sizeof(gItemData));
}
@@ -173,7 +173,7 @@
}
/// Update the inventory cursor
-void MoveCampCursor()
+void MoveCampCursor(void)
{
// Compute the current amount of weapons and items
int arms_num = 0;
@@ -186,10 +186,10 @@
if (arms_num == 0 && item_num == 0)
return; // Empty inventory
- /// True if we're currently changing cursor position
+ // True if we're currently changing cursor position
BOOL bChange = FALSE;
- if (gCampActive == FALSE)
+ if (!gCampActive)
{
// Handle selected weapon
if (gKeyTrg & gKeyLeft)
@@ -207,7 +207,7 @@
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)
+ if (item_num != 0)
gCampActive = TRUE;
bChange = TRUE;
@@ -228,7 +228,7 @@
if (gSelectedItem % 6 == 0)
gSelectedItem += 5;
else
- --gSelectedItem;
+ gSelectedItem -= 1;
bChange = TRUE;
}
@@ -236,11 +236,11 @@
if (gKeyTrg & gKeyRight)
{
if (gSelectedItem == item_num - 1)
- gSelectedItem = 6 * (gSelectedItem / 6); // Round down to multiple of 6
+ gSelectedItem = (gSelectedItem / 6) * 6; // Round down to multiple of 6
else if (gSelectedItem % 6 == 5)
gSelectedItem -= 5; // Loop around row
else
- ++gSelectedItem;
+ gSelectedItem += 1;
bChange = TRUE;
}
@@ -269,7 +269,7 @@
gSelectedItem = item_num - 1; // Don't allow selecting a non-existing item
if (gCampActive && gKeyTrg & gKeyOk)
- StartTextScript(gItemData[gSelectedItem].code + 6000);
+ StartTextScript(6000 + gItemData[gSelectedItem].code);
}
if (bChange)
@@ -279,8 +279,8 @@
// Switch to a weapon
PlaySoundObject(SND_SWITCH_WEAPON, 1);
- if (arms_num)
- StartTextScript(gArmsData[gSelectedArms].code + 1000);
+ if (arms_num != 0)
+ StartTextScript(1000 + gArmsData[gSelectedArms].code);
else
StartTextScript(1000);
}
@@ -289,8 +289,8 @@
// Switch to an item
PlaySoundObject(SND_YES_NO_CHANGE_CHOICE, 1);
- if (item_num)
- StartTextScript(gItemData[gSelectedItem].code + 5000);
+ if (item_num != 0)
+ StartTextScript(5000 + gItemData[gSelectedItem].code);
else
StartTextScript(5000);
}
@@ -298,7 +298,7 @@
}
/// Draw the inventory
-void PutCampObject()
+void PutCampObject(void)
{
int i;
@@ -333,18 +333,18 @@
RECT rcBoxBottom = {0, 16, 244, 24};
// Draw box
- PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, (WINDOW_HEIGHT - 224) / 2, &rcBoxTop, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 122, (WINDOW_HEIGHT / 2) - 112, &rcBoxTop, SURFACE_ID_TEXT_BOX);
for (i = 1; i < 18; ++i)
- PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (i + 1)), &rcBoxBody, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (i + 1)), &rcBoxBottom, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 122, ((WINDOW_HEIGHT / 2) - 120) + ((i + 1) * 8), &rcBoxBody, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 122, ((WINDOW_HEIGHT / 2) - 120) + ((i + 1) * 8), &rcBoxBottom, SURFACE_ID_TEXT_BOX);
// Move titles
- if (gCampTitleY > (WINDOW_HEIGHT - 208) / 2)
+ if (gCampTitleY > (WINDOW_HEIGHT / 2) - 104)
--gCampTitleY;
// Draw titles
- PutBitmap3(&rcView, (WINDOW_WIDTH - 224) / 2, gCampTitleY, &rcTitle1, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&rcView, (WINDOW_WIDTH - 224) / 2, gCampTitleY + 52, &rcTitle2, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 112, gCampTitleY, &rcTitle1, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 112, gCampTitleY + 52, &rcTitle2, SURFACE_ID_TEXT_BOX);
// Draw arms cursor
static unsigned int flash;
@@ -351,9 +351,9 @@
++flash;
if (gCampActive == FALSE)
- PutBitmap3(&rcView, 40 * gSelectedArms + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT / 2) - 96, &rcCur1[(flash / 2) % 2], SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (gSelectedArms * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 96, &rcCur1[(flash / 2) % 2], SURFACE_ID_TEXT_BOX);
else
- PutBitmap3(&rcView, 40 * gSelectedArms + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT / 2) - 96, &rcCur1[1], SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (gSelectedArms * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 96, &rcCur1[1], SURFACE_ID_TEXT_BOX);
// Draw weapons
for (i = 0; i < ARMS_MAX; ++i)
@@ -368,30 +368,30 @@
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);
- 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);
- PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 160) / 2, gArmsData[i].level, FALSE);
+ PutBitmap3(&rcView, (i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 96, &rcArms, SURFACE_ID_ARMS_IMAGE);
+ PutBitmap3(&rcView, (i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 64, &rcPer, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 80, &rcLv, SURFACE_ID_TEXT_BOX);
+ PutNumber4((i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 80, gArmsData[i].level, FALSE);
// Draw ammo
if (gArmsData[i].max_num)
{
- PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 144) / 2, gArmsData[i].num, FALSE);
- PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, gArmsData[i].max_num, FALSE);
+ PutNumber4((i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 72, gArmsData[i].num, FALSE);
+ PutNumber4((i * 40) + (WINDOW_WIDTH / 2) - 112, (WINDOW_HEIGHT / 2) - 64, gArmsData[i].max_num, FALSE);
}
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);
+ PutBitmap3(&rcView, (i * 40) + (WINDOW_WIDTH - 192) / 2, (WINDOW_HEIGHT / 2) - 72, &rcNone, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&rcView, (i * 40) + (WINDOW_WIDTH - 192) / 2, (WINDOW_HEIGHT / 2) - 64, &rcNone, SURFACE_ID_TEXT_BOX);
}
}
// 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, ((gSelectedItem % 6) * 32) + (WINDOW_WIDTH / 2) - 112, ((gSelectedItem / 6) * 16) + (WINDOW_HEIGHT / 2) - 44, &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, ((gSelectedItem % 6) * 32) + (WINDOW_WIDTH / 2) - 112, ((gSelectedItem / 6) * 16) + (WINDOW_HEIGHT / 2) - 44, &rcCur2[1], SURFACE_ID_TEXT_BOX);
for (i = 0; i < ITEM_MAX; ++i)
{
@@ -399,16 +399,16 @@
break; // Invalid item
// Get rect for next item
- rcItem.left = 32 * (gItemData[i].code % 8);
+ rcItem.left = (gItemData[i].code % 8) * 32;
rcItem.right = rcItem.left + 32;
- rcItem.top = 16 * (gItemData[i].code / 8);
+ rcItem.top = (gItemData[i].code / 8) * 16;
rcItem.bottom = rcItem.top + 16;
- PutBitmap3(&rcView, 32 * (i % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (i / 6) + (WINDOW_HEIGHT - 88) / 2, &rcItem, SURFACE_ID_ITEM_IMAGE);
+ PutBitmap3(&rcView, ((i % 6) * 32) + (WINDOW_WIDTH / 2) - 112, ((i / 6) * 16) + (WINDOW_HEIGHT / 2) - 44, &rcItem, SURFACE_ID_ITEM_IMAGE);
}
}
-int CampLoop()
+int CampLoop(void)
{
int arms_num;
char old_script_path[MAX_PATH];
@@ -421,7 +421,7 @@
// Load the inventory script
LoadTextScript2("ArmsItem.tsc");
- gCampTitleY = (WINDOW_HEIGHT - 192) / 2;
+ gCampTitleY = (WINDOW_HEIGHT / 2) - 96;
// Put the cursor on the first weapon
gCampActive = FALSE;
@@ -432,10 +432,10 @@
while (gArmsData[arms_num].code != 0)
++arms_num;
- if (arms_num)
- StartTextScript(gArmsData[gSelectedArms].code + 1000);
+ if (arms_num != 0)
+ StartTextScript(1000 + gArmsData[gSelectedArms].code);
else
- StartTextScript(gItemData[gSelectedItem].code + 5000);
+ StartTextScript(5000 + gItemData[gSelectedItem].code);
for (;;)
{
@@ -500,7 +500,9 @@
BOOL CheckItem(long a)
{
- for (int i = 0; i < ITEM_MAX; ++i)
+ int i;
+
+ for (i = 0; i < ITEM_MAX; ++i)
if (gItemData[i].code == a)
return TRUE; // Found
@@ -509,7 +511,9 @@
BOOL CheckArms(long a)
{
- for (int i = 0; i < ARMS_MAX; ++i)
+ int i;
+
+ for (i = 0; i < ARMS_MAX; ++i)
if (gArmsData[i].code == a)
return TRUE; // Found
@@ -542,9 +546,11 @@
return TRUE; // Always successfull
}
-void FullArmsEnergy()
+void FullArmsEnergy(void)
{
- for (int a = 0; a < ARMS_MAX; a++)
+ int a;
+
+ for (a = 0; a < ARMS_MAX; ++a)
{
if (gArmsData[a].code == 0)
continue; // Don't change empty weapons
@@ -553,7 +559,7 @@
}
}
-int RotationArms()
+int RotationArms(void)
{
// Get amount of weapons
int arms_num = 0;
@@ -585,7 +591,7 @@
return gArmsData[gSelectedArms].code;
}
-int RotationArmsRev()
+int RotationArmsRev(void)
{
// Get amount of weapons
int arms_num = 0;
@@ -598,7 +604,9 @@
ResetSpurCharge();
// Select previous valid weapon
- if (--gSelectedArms < 0)
+ --gSelectedArms;
+
+ if (gSelectedArms < 0)
gSelectedArms = arms_num - 1;
while (gSelectedArms < arms_num)
@@ -615,7 +623,7 @@
return gArmsData[gSelectedArms].code;
}
-void ChangeToFirstArms()
+void ChangeToFirstArms(void)
{
gSelectedArms = 0;
gArmsEnergyX = 32;
--- a/src/ArmsItem.h
+++ b/src/ArmsItem.h
@@ -55,10 +55,10 @@
/// Clear the weapons array, reverting it to the default state (no weapons) and adjust variables (initialize weapons basically)
-void ClearArmsData();
+void ClearArmsData(void);
/// Clear the item array, reverting it to the default state (no items) (initialize items basically)
-void ClearItemData();
+void ClearItemData(void);
/// 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
@@ -80,7 +80,7 @@
/// Inventory loop. Returns mode.
-int CampLoop();
+int CampLoop(void);
/// Search for a in the items. Returns whether a was found
@@ -97,16 +97,16 @@
BOOL ChargeArmsEnergy(long num);
/// Set every weapons ammunition to its maximum ammunition
-void FullArmsEnergy();
+void FullArmsEnergy(void);
// "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();
+int RotationArms(void);
/// Change the current weapon to the previous one in the rotation. Returns the ID of the newly selected weapon
-int RotationArmsRev();
+int RotationArmsRev(void);
/// Change the current weapon to be the first one and play the usual rotation animation
-void ChangeToFirstArms();
+void ChangeToFirstArms(void);