Beispiel #1
0
/*
* Cmd_Use_f
* Use an inventory item
*/
static void Cmd_Use_f( edict_t *ent )
{
	gsitem_t	*it;

	assert( ent && ent->r.client );

	it = GS_Cmd_UseItem( &ent->r.client->ps, trap_Cmd_Args(), 0 );
	if( !it )
		return;

	G_UseItem( ent, it );
}
Beispiel #2
0
/*
* CG_Cmd_PrevWeapon_f
*/
static void CG_Cmd_LastWeapon_f( void )
{
	gsitem_t *item;

	if( !cg.frame.valid || cgs.demoPlaying )
		return;

	if( cg.lastWeapon != WEAP_NONE && cg.lastWeapon != cg.predictedPlayerState.stats[STAT_PENDING_WEAPON] )
	{
		item = GS_Cmd_UseItem( &cg.frame.playerState, va( "%i", cg.lastWeapon ), IT_WEAPON );
		if( item )
		{
			if( item->type & IT_WEAPON )
				CG_Predict_ChangeWeapon( item->tag );

			trap_Cmd_ExecuteText( EXEC_NOW, va( "cmd use %i", item->tag ) );
			cg.lastWeapon = cg.predictedPlayerState.stats[STAT_PENDING_WEAPON];
		}
	}
}
Beispiel #3
0
/*
* CG_UseItem
*/
void CG_UseItem( const char *name )
{
	gsitem_t *item;

	if( !cg.frame.valid || cgs.demoPlaying )
		return;

	if( !name )
		return;

	item = GS_Cmd_UseItem( &cg.frame.playerState, name, 0 );
	if( item )
	{
		if( item->type & IT_WEAPON )
		{
			CG_Predict_ChangeWeapon( item->tag );
			cg.lastWeapon = cg.predictedPlayerState.stats[STAT_PENDING_WEAPON];
		}

		trap_Cmd_ExecuteText( EXEC_NOW, va( "cmd use %i", item->tag ) );
	}
}
Beispiel #4
0
/*
* GS_Cmd_UseWeaponStep_f
*/
static gsitem_t *GS_Cmd_UseWeaponStep_f( player_state_t *playerState, int step, int predictedWeaponSwitch )
{
	gsitem_t *item;
	int curSlot, newSlot;

	assert( playerState );

	if( playerState->pmove.pm_type >= PM_SPECTATOR )
		return NULL;

	if( !( playerState->pmove.stats[PM_STAT_FEATURES] & PMFEAT_WEAPONSWITCH ) )
		return NULL;

	if( step != -1 && step != 1 )
		step = 1;

	if( predictedWeaponSwitch && predictedWeaponSwitch != playerState->stats[STAT_PENDING_WEAPON] )
		curSlot = predictedWeaponSwitch;
	else
		curSlot = playerState->stats[STAT_PENDING_WEAPON];

	clamp( curSlot, 0, WEAP_TOTAL - 1 );
	newSlot = curSlot;
	do
	{
		newSlot += step;
		if( newSlot >= WEAP_TOTAL )
			newSlot = 0;
		if( newSlot < 0 )
			newSlot = WEAP_TOTAL - 1;

		if( ( item = GS_Cmd_UseItem( playerState, va( "%i", newSlot ), IT_WEAPON ) ) != NULL )
			return item;
	}
	while( newSlot != curSlot );

	return NULL;
}