Index: trunk/src/game/g_local.h =================================================================== --- trunk/src/game/g_local.h (revision 809) +++ trunk/src/game/g_local.h (working copy) @@ -833,6 +833,7 @@ gentity_t *effectChannel; } zap_t; +int G_FindNonBlasterWeapon( gentity_t *ent ); void G_ForceWeaponChange( gentity_t *ent, weapon_t weapon ); void G_GiveClientMaxAmmo( gentity_t *ent, qboolean buyingEnergyAmmo ); void CalcMuzzlePoint( gentity_t *ent, vec3_t forward, vec3_t right, vec3_t up, vec3_t muzzlePoint ); Index: trunk/src/game/g_cmds.c =================================================================== --- trunk/src/game/g_cmds.c (revision 809) +++ trunk/src/game/g_cmds.c (working copy) @@ -1759,7 +1759,7 @@ void Cmd_ToggleItem_f( gentity_t *ent ) { char s[ MAX_TOKEN_CHARS ]; - int upgrade, weapon, i; + int upgrade, weapon; trap_Argv( 1, s, sizeof( s ) ); upgrade = BG_FindUpgradeNumForName( s ); @@ -1776,24 +1776,8 @@ if( ent->client->ps.weapon != WP_BLASTER ) weapon = WP_BLASTER; else - { - //find a held weapon which isn't the blaster - for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ ) - { - if( i == WP_BLASTER ) - continue; + weapon = G_FindNonBlasterWeapon( ent ); - if( BG_InventoryContainsWeapon( i, ent->client->ps.stats ) ) - { - weapon = i; - break; - } - } - - if( i == WP_NUM_WEAPONS ) - weapon = WP_BLASTER; - } - G_ForceWeaponChange( ent, weapon ); } else if( BG_InventoryContainsUpgrade( upgrade, ent->client->ps.stats ) ) Index: trunk/src/game/g_weapon.c =================================================================== --- trunk/src/game/g_weapon.c (revision 809) +++ trunk/src/game/g_weapon.c (working copy) @@ -28,7 +28,26 @@ static vec3_t forward, right, up; static vec3_t muzzle; +/* +================ +G_FindNonblasterWeapon +================ +*/ +int G_FindNonBlasterWeapon( gentity_t *ent ) { + int i; + for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ ) { + if( i == WP_BLASTER ) + continue; + + if( BG_InventoryContainsWeapon( i, ent->client->ps.stats ) ) { + return i; + } + } + + return WP_BLASTER; +} + /* ================ G_ForceWeaponChange @@ -36,8 +55,6 @@ */ void G_ForceWeaponChange( gentity_t *ent, weapon_t weapon ) { - int i; - if( ent ) { ent->client->ps.pm_flags |= PMF_WEAPON_SWITCH; @@ -46,21 +63,7 @@ || !BG_InventoryContainsWeapon( weapon, ent->client->ps.stats )) { //switch to the first non blaster weapon - for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ ) - { - if( i == WP_BLASTER ) - continue; - - if( BG_InventoryContainsWeapon( i, ent->client->ps.stats ) ) - { - ent->client->ps.persistant[ PERS_NEWWEAPON ] = i; - break; - } - } - - //only got the blaster to switch to - if( i == WP_NUM_WEAPONS ) - ent->client->ps.persistant[ PERS_NEWWEAPON ] = WP_BLASTER; + ent->client->ps.persistant[ PERS_NEWWEAPON ] = G_FindNonBlasterWeapon( ent ); } else ent->client->ps.persistant[ PERS_NEWWEAPON ] = weapon;