Skip to content

Commit

Permalink
Use MAX_WEAPONS constant instead of magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVanheer committed Dec 1, 2021
1 parent fd87712 commit e01645e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cl_dll/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void DLLEXPORT HUD_TxferPredictionData(struct entity_state_s* ps, const struct e
VectorCopy(ppcd->vuser3, pcd->vuser3);
VectorCopy(ppcd->vuser4, pcd->vuser4);

memcpy(wd, pwd, 32 * sizeof(weapon_data_t));
memcpy(wd, pwd, MAX_WEAPONS * sizeof(weapon_data_t));
}

#if defined(BEAM_TEST)
Expand Down
8 changes: 4 additions & 4 deletions cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
extern int g_iUser1;

// Pool of client side entities/entvars_t
static entvars_t ev[32];
static entvars_t ev[MAX_WEAPONS];
static int num_ents = 0;

// The entity we'll use to represent the local client
Expand All @@ -42,7 +42,7 @@ static CBasePlayer player;
// Local version of game .dll global variables ( time, etc. )
static globalvars_t Globals;

static CBasePlayerWeapon* g_pWpns[32];
static CBasePlayerWeapon* g_pWpns[MAX_WEAPONS];

float g_flApplyVel = 0.0;
bool g_irunninggausspred = false;
Expand Down Expand Up @@ -609,7 +609,7 @@ void HUD_WeaponsPostThink(local_state_s* from, local_state_s* to, usercmd_t* cmd
if (!pWeapon)
return;

for (i = 0; i < 32; i++)
for (i = 0; i < MAX_WEAPONS; i++)
{
pCurrent = g_pWpns[i];
if (!pCurrent)
Expand Down Expand Up @@ -772,7 +772,7 @@ void HUD_WeaponsPostThink(local_state_s* from, local_state_s* to, usercmd_t* cmd
HUD_SendWeaponAnim(to->client.weaponanim, pWeapon->pev->body, true);
}

for (i = 0; i < 32; i++)
for (i = 0; i < MAX_WEAPONS; i++)
{
pCurrent = g_pWpns[i];

Expand Down
8 changes: 3 additions & 5 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,8 @@ void RegisterEncoders()

int GetWeaponData(struct edict_s* player, struct weapon_data_s* info)
{
memset(info, 0, MAX_WEAPONS * sizeof(weapon_data_t));

#if defined(CLIENT_WEAPONS)
int i;
weapon_data_t* item;
Expand All @@ -1577,8 +1579,6 @@ int GetWeaponData(struct edict_s* player, struct weapon_data_s* info)

ItemInfo II;

memset(info, 0, 32 * sizeof(weapon_data_t));

if (!pl)
return 1;

Expand All @@ -1599,7 +1599,7 @@ int GetWeaponData(struct edict_s* player, struct weapon_data_s* info)
memset(&II, 0, sizeof(II));
gun->GetItemInfo(&II);

if (II.iId >= 0 && II.iId < 32)
if (II.iId >= 0 && II.iId < MAX_WEAPONS)
{
item = &info[II.iId];

Expand All @@ -1626,8 +1626,6 @@ int GetWeaponData(struct edict_s* player, struct weapon_data_s* info)
}
}
}
#else
memset(info, 0, 32 * sizeof(weapon_data_t));
#endif
return 1;
}
Expand Down
3 changes: 0 additions & 3 deletions dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class CGrenade : public CBaseMonster

#define WEAPON_SUIT 31 // ?????

#define MAX_WEAPONS 32


#define MAX_NORMAL_BATTERY 100


Expand Down

0 comments on commit e01645e

Please sign in to comment.