diff options
author | Ben Millwood <thebenmachine@gmail.com> | 2011-02-19 16:31:46 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:18:00 +0000 |
commit | 96646474568865ca40cbe0ced34f8143c3dfc2d4 (patch) | |
tree | afcf14fbbc315c3a9392ea7286b6a549793b79f9 /src/cgame/cg_weapons.c | |
parent | 99ea876ed85f3e6bff53960ad861a35505ada9c2 (diff) |
* Cleanups to weapon/upgrade registration
Diffstat (limited to 'src/cgame/cg_weapons.c')
-rw-r--r-- | src/cgame/cg_weapons.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/cgame/cg_weapons.c b/src/cgame/cg_weapons.c index 16c2d578..49c9e284 100644 --- a/src/cgame/cg_weapons.c +++ b/src/cgame/cg_weapons.c @@ -38,18 +38,24 @@ void CG_RegisterUpgrade( int upgradeNum ) upgradeInfo_t *upgradeInfo; char *icon; - upgradeInfo = &cg_upgrades[ upgradeNum ]; - - if( upgradeNum == 0 ) + if( upgradeNum <= UP_NONE || upgradeNum >= UP_NUM_UPGRADES ) + { + CG_Error( "CG_RegisterUpgrade: out of range: %d", upgradeNum ); return; + } + + upgradeInfo = &cg_upgrades[ upgradeNum ]; if( upgradeInfo->registered ) + { + CG_Printf( "CG_RegisterUpgrade: already registered: (%d) %s\n", upgradeNum, + BG_Upgrade( upgradeNum )->name ); return; + } - Com_Memset( upgradeInfo, 0, sizeof( *upgradeInfo ) ); upgradeInfo->registered = qtrue; - if( strlen( BG_Upgrade( upgradeNum )->name ) <= 0 ) + if( !BG_Upgrade( upgradeNum )->name[ 0 ] ) CG_Error( "Couldn't find upgrade %i", upgradeNum ); upgradeInfo->humanName = BG_Upgrade( upgradeNum )->humanName; @@ -731,18 +737,24 @@ void CG_RegisterWeapon( int weaponNum ) vec3_t mins, maxs; int i; - weaponInfo = &cg_weapons[ weaponNum ]; - - if( weaponNum == 0 ) + if( weaponNum <= WP_NONE || weaponNum >= WP_NUM_WEAPONS ) + { + CG_Error( "CG_RegisterWeapon: out of range: %d", weaponNum ); return; + } + + weaponInfo = &cg_weapons[ weaponNum ]; if( weaponInfo->registered ) + { + CG_Printf( "CG_RegisterWeapon: already registered: (%d) %s\n", weaponNum, + BG_Weapon( weaponNum )->name ); return; + } - Com_Memset( weaponInfo, 0, sizeof( *weaponInfo ) ); weaponInfo->registered = qtrue; - if( strlen( BG_Weapon( weaponNum )->name ) <= 0 ) + if( !BG_Weapon( weaponNum )->name[ 0 ] ) CG_Error( "Couldn't find weapon %i", weaponNum ); Com_sprintf( path, MAX_QPATH, "models/weapons/%s/weapon.cfg", BG_Weapon( weaponNum )->name ); @@ -761,10 +773,6 @@ void CG_RegisterWeapon( int weaponNum ) trap_R_ModelBounds( weaponInfo->weaponModel, mins, maxs ); for( i = 0 ; i < 3 ; i++ ) weaponInfo->weaponMidpoint[ i ] = mins[ i ] + 0.5 * ( maxs[ i ] - mins[ i ] ); - - //FIXME: - for( i = WPM_NONE + 1; i < WPM_NUM_WEAPONMODES; i++ ) - weaponInfo->wim[ i ].loopFireSound = qfalse; } /* @@ -995,8 +1003,8 @@ void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent else firing = qfalse; - CG_RegisterWeapon( weaponNum ); weapon = &cg_weapons[ weaponNum ]; + assert( weapon->registered ); // add the weapon Com_Memset( &gun, 0, sizeof( gun ) ); @@ -1211,20 +1219,20 @@ void CG_AddViewWeapon( playerState_t *ps ) weapon_t weapon = ps->weapon; weaponMode_t weaponMode = ps->generic1; + // no weapon carried - can't draw it + if( weapon == WP_NONE ) + return; + if( weaponMode <= WPM_NONE || weaponMode >= WPM_NUM_WEAPONMODES ) weaponMode = WPM_PRIMARY; - CG_RegisterWeapon( weapon ); wi = &cg_weapons[ weapon ]; + assert( wi->registered ); cent = &cg.predictedPlayerEntity; // &cg_entities[cg.snap->ps.clientNum]; if( ps->persistant[PERS_SPECSTATE] != SPECTATOR_NOT ) return; - // no weapon carried - can't draw it - if( weapon == WP_NONE ) - return; - if( ps->pm_type == PM_INTERMISSION ) return; @@ -1419,7 +1427,7 @@ void CG_DrawItemSelect( rectDef_t *rect, vec4_t color ) if( i == cg.weaponSelect ) selectedItem = numItems; - CG_RegisterWeapon( i ); + assert( cg_weapons[ i ].registered ); items[ numItems ] = i; numItems++; } @@ -1436,7 +1444,7 @@ void CG_DrawItemSelect( rectDef_t *rect, vec4_t color ) if( i == cg.weaponSelect - 32 ) selectedItem = numItems; - CG_RegisterUpgrade( i ); + assert( cg_upgrades[ i ].registered ); items[ numItems ] = i + 32; numItems++; } |