From 8d91e9b4c09f4cb79b3043c4289a30a23e00e71e Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Wed, 27 Jul 2022 08:24:22 +0300 Subject: [PATCH] Use MAX_WEAPONS constant instead of magic numbers (#294) --- cl_dll/entity.cpp | 2 +- cl_dll/hl/hl_weapons.cpp | 8 ++++---- dlls/client.cpp | 7 ++----- dlls/weapons.h | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cl_dll/entity.cpp b/cl_dll/entity.cpp index ba524f6a..36705466 100644 --- a/cl_dll/entity.cpp +++ b/cl_dll/entity.cpp @@ -222,7 +222,7 @@ void DLLEXPORT HUD_TxferPredictionData( struct entity_state_s *ps, const struct 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) ); } /* diff --git a/cl_dll/hl/hl_weapons.cpp b/cl_dll/hl/hl_weapons.cpp index b982fa7f..f8473eaa 100644 --- a/cl_dll/hl/hl_weapons.cpp +++ b/cl_dll/hl/hl_weapons.cpp @@ -36,7 +36,7 @@ extern globalvars_t *gpGlobals; 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 @@ -45,7 +45,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; int g_irunninggausspred = 0; @@ -752,7 +752,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm if( !pWeapon ) return; - for( i = 0; i < 32; i++ ) + for( i = 0; i < MAX_WEAPONS; i++ ) { pCurrent = g_pWpns[i]; if( !pCurrent ) @@ -921,7 +921,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm HUD_SendWeaponAnim( to->client.weaponanim, body, 1 ); } - for( i = 0; i < 32; i++ ) + for( i = 0; i < MAX_WEAPONS; i++ ) { pCurrent = g_pWpns[i]; diff --git a/dlls/client.cpp b/dlls/client.cpp index 5c0d8392..2ca1de59 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1627,6 +1627,7 @@ void RegisterEncoders( void ) int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ) { + memset( info, 0, MAX_WEAPONS * sizeof(weapon_data_t) ); #if CLIENT_WEAPONS int i; weapon_data_t *item; @@ -1634,8 +1635,6 @@ int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ) CBasePlayer *pl = (CBasePlayer *)CBasePlayer::Instance( pev ); CBasePlayerWeapon *gun; - memset( info, 0, 32 * sizeof(weapon_data_t) ); - if( !pl ) return 1; @@ -1656,7 +1655,7 @@ int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ) // Get The ID. gun->GetItemInfo( &II ); - if( II.iId >= 0 && II.iId < 32 ) + if( II.iId >= 0 && II.iId < MAX_WEAPONS ) { item = &info[II.iId]; @@ -1682,8 +1681,6 @@ int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ) } } } -#else - memset( info, 0, 32 * sizeof(weapon_data_t) ); #endif return 1; } diff --git a/dlls/weapons.h b/dlls/weapons.h index 396f3724..2963afa6 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -83,8 +83,6 @@ public: #define WEAPON_SUIT 31 // ????? -#define MAX_WEAPONS 32 - #define MAX_NORMAL_BATTERY 100 // weapon weight factors (for auto-switching) (-1 = noswitch)