void CBaseViewModel::CalcIronsights( Vector &pos, QAngle &ang )
{
	CBaseCombatWeapon *pWeapon = GetOwningWeapon();

	if (!pWeapon)
		return;

	//get delta time for interpolation
	float delta = (gpGlobals->curtime - pWeapon->m_flIronsightedTime) * 2.5f; //modify this value to adjust how fast the interpolation is
	float exp = (pWeapon->IsIronsighted()) ?
		(delta > 1.0f) ? 1.0f : delta : //normal blending
		(delta > 1.0f) ? 0.0f : 1.0f - delta; //reverse interpolation

	if (exp <= 0.001f) //fully not ironsighted; save performance
		return;

	Vector newPos = pos;
	QAngle newAng = ang;

	Vector vForward, vRight, vUp, vOffset;
	AngleVectors(newAng, &vForward, &vRight, &vUp);
	vOffset = pWeapon->GetIronsightPositionOffset();

	newPos += vForward * vOffset.x;
	newPos += vRight * vOffset.y;
	newPos += vUp * vOffset.z;
	newAng += pWeapon->GetIronsightAngleOffset();
	//fov is handled by CBaseCombatWeapon

	pos += (newPos - pos) * exp;
	ang += (newAng - ang) * exp;
}
//
//	Name: CC_SwitchToPhyscannon
//	Author: Hekar Khani
//	Description: Concommand. Switches between Physcannon and last weapon
//	Notes:
//
void CC_SwitchToPhyscannon( void )
{
	CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
	
	if ( pPlayer )
	{
		CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon();

		if ( pWeapon )
		{
			// Tell the client to stop selecting weapons
			engine->ClientCommand( UTIL_GetCommandClient()->edict(), "cancelselect" );

			const char *strWeaponName = pWeapon->GetName();

			if ( !Q_stricmp( strWeaponName, "weapon_lf_combat_cannon" ) )
			{
				pPlayer->SelectLastItem();
			}
			else
			{
				pPlayer->SelectItem( "weapon_lf_combat_cannon" );
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Called every usercmd by the player PreThink
//-----------------------------------------------------------------------------
void CBasePlayer::ItemPreFrame()
{
	// Handle use events
	PlayerUse();

	CBaseCombatWeapon *pActive = GetActiveWeapon();

	// Allow all the holstered weapons to update
	for ( int i = 0; i < WeaponCount(); ++i )
	{
		CBaseCombatWeapon *pWeapon = GetWeapon( i );

		if ( pWeapon == NULL )
			continue;

		if ( pActive == pWeapon )
			continue;

		pWeapon->ItemHolsterFrame();
	}

    if ( gpGlobals->curtime < m_flNextAttack )
		return;

	if (!pActive)
		return;

#if defined( CLIENT_DLL )
	// Not predicting this weapon
	if ( !pActive->IsPredicted() )
		return;
#endif

	pActive->ItemPreFrame();
}
Exemple #4
0
CBaseEntity * CEntHost::GiveNamedItem( const char * szName, int iSubType, bool removeIfNotCarried )
{
    // If I already own this type don't create one
    if ( GetHost()->Weapon_OwnsThisType( szName, iSubType ) )
        return NULL;

    CBaseEntity *pEntity = CreateEntityByName( szName );

    if ( !pEntity ) {
        Msg( "NULL Ent in GiveNamedItem!\n" );
        return NULL;
    }

    pEntity->SetLocalOrigin( GetLocalOrigin() );
    pEntity->AddSpawnFlags( SF_NORESPAWN );

    CBaseCombatWeapon *pWeapon = dynamic_cast<CBaseCombatWeapon *>(pEntity);

    DispatchSpawn( pEntity );

    if ( pWeapon ) {
        pWeapon->SetSubType( iSubType );
        GetHost()->Weapon_Equip( pWeapon );
    }
    else {
        if ( pEntity && !(pEntity->IsMarkedForDeletion()) ) {
            pEntity->Touch( GetHost() );
        }
    }

    return pEntity;
}
//-----------------------------------------------------------------------------
// Purpose: Called on each respawn
//-----------------------------------------------------------------------------
void CPlayerClass::RespawnClass( void )
{
	ResupplyAmmo( 100.0f, RESUPPLY_ALL_FROM_STATION );
	GainedNewTechnology( NULL );
	SetMaxHealth( GetMaxHealthCVarValue() );
	SetMaxSpeed( GetMaxSpeed() );
	CheckDeterioratingObjects();

	SetupSizeData();

	// Refill the clips of all my weapons
	for (int i = 0; i < MAX_WEAPONS; i++)
	{
		CBaseCombatWeapon *pWeapon = m_pPlayer->GetWeapon(i);
		if ( pWeapon )
		{
			if ( pWeapon->UsesClipsForAmmo1() )
			{
				pWeapon->m_iClip1 = pWeapon->GetDefaultClip1();
			}
			if ( pWeapon->UsesClipsForAmmo2() )
			{
				pWeapon->m_iClip2 = pWeapon->GetDefaultClip2();
			}
		}
	}
}
int CBaseCombatWeapon::GetAvailableWeaponsInBox( CBaseCombatWeapon **pList, int listMax, const Vector &mins, const Vector &maxs )
{
	// linear search all weapons
	int count = 0;
	int index = g_WeaponList.m_list.Head();
	while ( index != g_WeaponList.m_list.InvalidIndex() )
	{
		CBaseCombatWeapon *pWeapon = g_WeaponList.m_list[index];
		// skip any held weapon
		if ( !pWeapon->GetOwner() )
		{
			// restrict to mins/maxs
			if ( IsPointInBox( pWeapon->GetAbsOrigin(), mins, maxs ) )
			{
				if ( count < listMax )
				{
					pList[count] = pWeapon;
					count++;
				}
			}
		}
		index = g_WeaponList.m_list.Next( index );
	}

	return count;
}
Exemple #7
0
void CHL2MP_Player::Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity )
{
	//Drop a grenade if it's primed.
	if ( GetActiveWeapon() )
	{
		CBaseCombatWeapon *pGrenade = Weapon_OwnsThisType("weapon_frag");

		if ( GetActiveWeapon() == pGrenade )
		{
			if ( ( m_nButtons & IN_ATTACK ) || (m_nButtons & IN_ATTACK2) )
			{
				DropPrimedFragGrenade( this, pGrenade );
				return;
			}
			//DHL - Skillet
			else
			{
				pGrenade->Drop( *pVelocity );
				return;
			}
		}
	}

	BaseClass::Weapon_Drop( pWeapon, pvecTarget, pVelocity );
}
void CJaS_Marine_Jack::Spawn()
{
	CASW_Marine_Resource *pResource = dynamic_cast<CASW_Marine_Resource *>( CreateEntityByName( "asw_marine_resource" ) );
	pResource->SetProfileIndex( 6 );
	pResource->SetMarineEntity( this );
	SetMarineResource( pResource );
	pResource->Spawn();
	m_pProfileOverride = pResource->GetProfile();
	SelectModelFromProfile();
	SetModelFromProfile();

	CBaseCombatWeapon *pWeapon = dynamic_cast<CBaseCombatWeapon *>( CreateEntityByName( "asw_weapon_sniper_rifle" ) );
	if ( pWeapon )
	{
		pWeapon->Spawn();
		pWeapon->GiveDefaultAmmo();
		pWeapon->m_iClip1 = 9999;
		GiveAmmo(9999, pWeapon->GetPrimaryAmmoType());
		Weapon_Equip_In_Index( pWeapon, 0 );
		Weapon_Switch( pWeapon );
	}
	m_bConstantSlowHeal = true;

	m_hSquadFormation = static_cast<CASW_SquadFormation *>( CreateEntityByName( "asw_squadformation" ) );
	m_hSquadFormation->Leader( this );

	SetRenderColor( 0x99, 0x40, 0x40 );

	BaseClass::Spawn();
}
void CHL2MP_Player::PostThink( void )
{
	BaseClass::PostThink();
	
	if ( GetFlags() & FL_DUCKING )
	{
		SetCollisionBounds( VEC_CROUCH_TRACE_MIN, VEC_CROUCH_TRACE_MAX );
	}

	m_PlayerAnimState.Update();

	// Store the eye angles pitch so the client can compute its animation state correctly.
	m_angEyeAngles = EyeAngles();

	QAngle angles = GetLocalAngles();
	angles[PITCH] = 0;
	SetLocalAngles( angles );

	if (!IsDead())
	{
		if (m_afButtonReleased & IN_KICK && m_flNextKickAttack < gpGlobals->curtime /* && m_flNextKickAttack < gpGlobals->curtime  && !m_bIsKicking*/)
		{
			KickAttack();
			m_bIsKicking = true;
		}
	}

	CBaseCombatWeapon *pWeapon = this->GetActiveWeapon();
	if (pWeapon != NULL)
	{
		if (m_afButtonPressed & IN_IRONSIGHT)
		{
			pWeapon->EnableIronsights();
		}
		else if (m_afButtonReleased & IN_IRONSIGHT)
		{
			pWeapon->DisableIronsights();
		}
	}

	if (!IsDead())
	{
		if (m_flNextKickAttack < gpGlobals->curtime)
		{
			m_bIsKicking = false;
			CBaseViewModel *vm = GetViewModel(1);

			if (vm)
			{
				int	idealSequence = vm->SelectWeightedSequence(ACT_VM_IDLE);

				if (idealSequence >= 0)
				{
					vm->SendViewModelMatchingSequence(idealSequence);
				}
			}
		}
	}
}
static int CBaseCombatWeapon___tostring (lua_State *L) {
  CBaseCombatWeapon *pWeapon = lua_toweapon(L, 1);
  if (pWeapon == NULL)
    lua_pushstring(L, "NULL");
  else
    lua_pushfstring(L, "CBaseCombatWeapon: %d %s", pWeapon->entindex(), pWeapon->GetClassname());
  return 1;
}
Exemple #11
0
//-----------------------------------------------------------------------------
// Purpose: Dissolve all weapons within our volume
//-----------------------------------------------------------------------------
void CTriggerWeaponDissolve::DissolveThink( void )
{
	int	numWeapons = m_pWeapons.Count();

	// Dissolve all the items within the volume
	for ( int i = 0; i < numWeapons; i++ )
	{
		CBaseCombatWeapon *pWeapon = m_pWeapons[i];
		Vector vecConduit = GetConduitPoint( pWeapon );
		
		// The physcannon upgrades when this happens
		if ( FClassnameIs( pWeapon, "weapon_physcannon" ) )
		{
			// This must be the last weapon for us to care
			if ( numWeapons > 1 )
				continue;

			//FIXME: Make them do this on a stagger!

			// All conduits send power to the weapon
			for ( int i = 0; i < m_pConduitPoints.Count(); i++ )
			{
				CreateBeam( m_pConduitPoints[i]->GetAbsOrigin(), pWeapon, 4.0f );
			}

			PhysCannonBeginUpgrade( pWeapon );
			m_OnChargingPhyscannon.FireOutput( this, this );

			EmitSound( "WeaponDissolve.Beam" );

			// We're done
			m_pWeapons.Purge();
			m_pConduitPoints.Purge();
			SetContextThink( NULL, 0, s_pDissolveThinkContext );
			return;
		}

		// Randomly dissolve them all
		float flLifetime = random->RandomFloat( 2.5f, 4.0f );
		CreateBeam( vecConduit, pWeapon, flLifetime );
		pWeapon->Dissolve( NULL, gpGlobals->curtime + ( 3.0f - flLifetime ), false );

		m_OnDissolveWeapon.FireOutput( this, this );

		CPASAttenuationFilter filter( pWeapon );
		EmitSound( filter, pWeapon->entindex(), "WeaponDissolve.Dissolve" );
		
		// Beam looping sound
		EmitSound( "WeaponDissolve.Beam" );

		m_pWeapons.Remove( i );
		SetContextThink( &CTriggerWeaponDissolve::DissolveThink, gpGlobals->curtime + random->RandomFloat( 0.5f, 1.5f ), s_pDissolveThinkContext );
		return;
	}

	SetContextThink( &CTriggerWeaponDissolve::DissolveThink, gpGlobals->curtime + 0.1f, s_pDissolveThinkContext );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : event -
//-----------------------------------------------------------------------------
void CPortalPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
{
    Activity iWeaponActivity = ACT_INVALID;

    switch( event )
    {
    case PLAYERANIMEVENT_ATTACK_PRIMARY:
    case PLAYERANIMEVENT_ATTACK_SECONDARY:
    {
        CPortal_Player *pPlayer = GetPortalPlayer();
        if ( !pPlayer )
            return;

        CWeaponPortalBase *pWpn = pPlayer->GetActivePortalWeapon();

        if ( pWpn )
        {
            // Weapon primary fire.
            if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
            {
                RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_CROUCH_PRIMARYFIRE );
            }
            else
            {
                RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_STAND_PRIMARYFIRE );
            }

            iWeaponActivity = ACT_VM_PRIMARYATTACK;
        }
        else	// unarmed player
        {

        }

        break;
    }

    default:
    {
        BaseClass::DoAnimationEvent( event, nData );
        break;
    }
    }

#ifdef CLIENT_DLL
    // Make the weapon play the animation as well
    if ( iWeaponActivity != ACT_INVALID )
    {
        CBaseCombatWeapon *pWeapon = GetPortalPlayer()->GetActiveWeapon();
        if ( pWeapon )
        {
            pWeapon->SendWeaponAnim( iWeaponActivity );
        }
    }
#endif
}
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles )
{
	// UNDONE: Calc this on the server?  Disabled for now as it seems unnecessary to have this info on the server
#if defined( CLIENT_DLL )
	QAngle vmangoriginal = eyeAngles;
	QAngle vmangles = eyeAngles;
	Vector vmorigin = eyePosition;

	Vector vecRight;
	Vector vecUp;
	Vector vecForward;
	AngleVectors( vmangoriginal, &vecForward, &vecRight, &vecUp );
	//Vector vecOffset = Vector( viewmodel_offset_x.GetFloat(), viewmodel_offset_y.GetFloat(), viewmodel_offset_z.GetFloat() ); 
	vmorigin += (vecForward * viewmodel_offset_y.GetFloat()) + (vecUp * viewmodel_offset_z.GetFloat()) + (vecRight * viewmodel_offset_x.GetFloat());

	// TrackIR
	if ( IsHeadTrackingEnabled() )
	{
		vmorigin = owner->EyePosition();
		VectorAngles( owner->GetAutoaimVector( AUTOAIM_5DEGREES ), vmangoriginal );
		vmangles = vmangoriginal;
	}
	// TrackIR

	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	//Allow weapon lagging
	if ( pWeapon != NULL )
	{
#if defined( CLIENT_DLL )
		if ( !prediction->InPrediction() )
#endif
		{
			// add weapon-specific bob 
			pWeapon->AddViewmodelBob( this, vmorigin, vmangles );
		}
	}
	// Add model-specific bob even if no weapon associated (for head bob for off hand models)
	AddViewModelBob( owner, vmorigin, vmangles );
	// Add lag
	CalcViewModelLag( vmorigin, vmangles, vmangoriginal );

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// Let the viewmodel shake at about 10% of the amplitude of the player's view
		ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( GetOwner() );
		GetViewEffects()->ApplyShake( vmorigin, vmangles, 0.1 );	
	}
#endif

	CalcIronsights( vmorigin, vmangles );
	SetLocalOrigin( vmorigin );
	SetLocalAngles( vmangles );

#endif
}
void CTFPlayerAnimState::RestartGesture( int iGestureSlot, Activity iGestureActivity, bool bAutoKill )
{
	CBaseCombatWeapon *pWeapon = m_pTFPlayer->GetActiveWeapon();

	if ( pWeapon )
	{
		iGestureActivity = pWeapon->GetItem()->GetActivityOverride( m_pTFPlayer->GetTeamNumber(), iGestureActivity );
	}

	BaseClass::RestartGesture( iGestureSlot, iGestureActivity, bAutoKill );
}
inline bool C_BaseViewModel::ShouldFlipViewModel()
{
	// If cl_righthand is set, then we want them all right-handed.
	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	if (pWeapon)
	{
		const FileWeaponInfo_t *pInfo = &pWeapon->GetWpnData();
		return pInfo->m_bAllowFlipping && pInfo->m_bBuiltRightHanded != cl_righthand.GetBool();
	}
	
	return false;
}
//-----------------------------------------------------------------------------
// Purpose: Returns weapons with the appropriate weapon slot.
//-----------------------------------------------------------------------------
CBaseCombatWeapon* CBaseCombatCharacter::GetWeaponAtSlot( int m_iSlot ) const
{
	for ( int i = 0; i < MAX_WEAPONS; i++ ) 
	{
		CBaseEntity *pWep = dynamic_cast< CBaseEntity* >( m_hMyWeapons[i].Get() );
		CBaseCombatWeapon *Weapon = dynamic_cast< CBaseCombatWeapon* >( pWep );

		if ( m_hMyWeapons[i].Get() && m_iSlot == Weapon->GetSlot() )
		{
			return m_hMyWeapons[i];
		}
	}
	return NULL;
}
void CAI_StandoffBehavior::UpdateTranslateActivityMap()
{
	struct ActivityMapping
	{
		AI_Posture_t	posture;
		Activity		activity;
		const char *	pszWeapon;
		Activity		translation;
	};
	
	static ActivityMapping mappings[] =
	{
		{	AIP_CROUCHING, 	ACT_IDLE, 				NULL, 				ACT_COVER_LOW 				},
		{	AIP_CROUCHING, 	ACT_WALK, 				NULL, 				ACT_WALK_CROUCH 			},
		{	AIP_CROUCHING, 	ACT_RUN, 				NULL, 				ACT_RUN_CROUCH 				},
		{	AIP_CROUCHING, 	ACT_WALK_AIM, 			NULL, 				ACT_WALK_CROUCH_AIM 		},
		{	AIP_CROUCHING, 	ACT_RUN_AIM, 			NULL, 				ACT_RUN_CROUCH_AIM 			},
		{	AIP_CROUCHING,	ACT_RELOAD_PISTOL, 		NULL, 				ACT_RELOAD_PISTOL_LOW		},
		{	AIP_CROUCHING,	ACT_RELOAD_SMG1, 		NULL, 				ACT_RELOAD_SMG1_LOW			},
		//----
		{	AIP_STANDING,	ACT_COVER_LOW,			NULL, 				ACT_IDLE 					},
		//----
		{	AIP_PEEKING, 	ACT_IDLE, 				"weapon_smg1", 		ACT_RANGE_AIM_SMG1_LOW		},
		{	AIP_PEEKING, 	ACT_COVER_LOW, 			"weapon_smg1", 		ACT_RANGE_AIM_SMG1_LOW		},
		{	AIP_PEEKING, 	ACT_IDLE,				"weapon_pistol",	ACT_RANGE_AIM_PISTOL_LOW	},
		{	AIP_PEEKING, 	ACT_COVER_LOW,			"weapon_pistol",	ACT_RANGE_AIM_PISTOL_LOW	},
		{	AIP_PEEKING,	ACT_IDLE,				"weapon_ar2",		ACT_RANGE_AIM_AR2_LOW		},
		{	AIP_PEEKING,	ACT_COVER_LOW,			"weapon_ar2",		ACT_RANGE_AIM_AR2_LOW		},
		{	AIP_PEEKING, 	ACT_RANGE_ATTACK_PISTOL, NULL, 				ACT_RANGE_ATTACK_PISTOL_LOW },
		{	AIP_PEEKING, 	ACT_RANGE_ATTACK_SMG1, 	NULL, 				ACT_RANGE_ATTACK_SMG1_LOW	},
		{	AIP_PEEKING,	ACT_RELOAD_PISTOL, 		NULL, 				ACT_RELOAD_PISTOL_LOW		},
		{	AIP_PEEKING,	ACT_RELOAD_SMG1, 		NULL, 				ACT_RELOAD_SMG1_LOW			},
	};

	m_ActivityMap.RemoveAll();
	
	CBaseCombatWeapon *pWeapon = GetOuter()->GetActiveWeapon();
	const char *pszWeaponClass = ( pWeapon ) ? pWeapon->GetClassname() : "";
	for ( int i = 0; i < ARRAYSIZE(mappings); i++ )
	{
		if ( !mappings[i].pszWeapon || stricmp( mappings[i].pszWeapon, pszWeaponClass ) == 0 )
		{
			if ( HaveSequenceForActivity( mappings[i].translation ) )
				m_ActivityMap.Insert( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ), mappings[i].translation );
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Only send the LocalWeaponData to the player carrying the weapon
//-----------------------------------------------------------------------------
void* SendProxy_SendCombatShieldLocalWeaponDataTable( const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID )
{
	// Get the weapon entity
	CBaseCombatWeapon *pWeapon = (CBaseCombatWeapon*)pVarData;
	if ( pWeapon )
	{
		// Only send this chunk of data to the player carrying this weapon
		CBasePlayer *pPlayer = ToBasePlayer( pWeapon->GetOwner() );
		if ( pPlayer )
		{
			pRecipients->SetOnly( pPlayer->GetClientIndex() );
			return (void*)pVarData;
		}
	}
	
	return NULL;
}
void CBaseViewModel::CalcAdjustedView(Vector &pos, QAngle &ang)
{
	CBaseCombatWeapon *pWeapon = GetOwningWeapon();

	if (!pWeapon)
		return;

	Vector vForward, vRight, vUp, vOffset;
	AngleVectors(ang, &vForward, &vRight, &vUp);
	vOffset = pWeapon->GetAdjustPositionOffset();

	pos += vForward * vOffset.x;
	pos += vRight * vOffset.y;
	pos += vUp * vOffset.z;
	ang += pWeapon->GetAdjustAngleOffset();
	//fov is handled by CBaseCombatWeapon
}
Exemple #20
0
Activity C_DHL_Player::Weapon_TranslateActivity( Activity baseAct, bool *pRequired )
{
	Activity translated = baseAct;

	CBaseCombatWeapon *pWeapon = GetActiveWeapon();

	if ( pWeapon )
	{
		translated = pWeapon->ActivityOverride( baseAct, pRequired );
	}
	else if (pRequired)
	{
		*pRequired = false;
	}

	return translated;
}
Exemple #21
0
//-----------------------------------------------------------------------------
// Purpose: Override base class so player can reset autoaim
// Input  :
// Output :
//-----------------------------------------------------------------------------
bool CBasePlayer::Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex /*=0*/ ) 
{
	CBaseCombatWeapon *pLastWeapon = GetActiveWeapon();

	if ( BaseClass::Weapon_Switch( pWeapon, viewmodelindex ))
	{
		if ( pLastWeapon && Weapon_ShouldSetLast( pLastWeapon, GetActiveWeapon() ) )
		{
			Weapon_SetLast( pLastWeapon->GetLastWeapon() );
		}

		CBaseViewModel *pViewModel = GetViewModel( viewmodelindex );
		Assert( pViewModel );
		if ( pViewModel )
			pViewModel->RemoveEffects( EF_NODRAW );
		ResetAutoaim( );
		return true;
	}
	return false;
}
//-----------------------------------------------------------------------------
// Purpose: allows the crate to open up when hit by a crowbar
//-----------------------------------------------------------------------------
int CItem_AmmoCrate::OnTakeDamage( const CTakeDamageInfo &info )
{
	// if it's the player hitting us with a crowbar, open up
	CBasePlayer *player = ToBasePlayer(info.GetAttacker());
	if (player)
	{
		CBaseCombatWeapon *weapon = player->GetActiveWeapon();

		if (weapon && !stricmp(weapon->GetName(), "weapon_crowbar"))
		{
			// play the normal use sound
			player->EmitSound( "HL2Player.Use" );
			// open the crate
			Use(info.GetAttacker(), info.GetAttacker(), USE_TOGGLE, 0.0f);
		}
	}

	// don't actually take any damage
	return 0;
}
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles )
{
	// UNDONE: Calc this on the server?  Disabled for now as it seems unnecessary to have this info on the server
#if defined( CLIENT_DLL )
	QAngle vmangoriginal = eyeAngles;
	QAngle vmangles = eyeAngles;
	Vector vmorigin = eyePosition;

	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	//Allow weapon lagging
	//if ( pWeapon != NULL )
	if( pWeapon != NULL && !pWeapon->IsIronsighted() ) //
	{
#if defined( CLIENT_DLL )
		if ( !prediction->InPrediction() )
#endif
		{
			// add weapon-specific bob 
			pWeapon->AddViewmodelBob( this, vmorigin, vmangles );
		}
	}
	// Add model-specific bob even if no weapon associated (for head bob for off hand models)
	AddViewModelBob( owner, vmorigin, vmangles ); //So this is the function that does the model movement when you move around.
	// Add lag
	CalcViewModelLag( vmorigin, vmangles, vmangoriginal );

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// Let the viewmodel shake at about 10% of the amplitude of the player's view
		vieweffects->ApplyShake( vmorigin, vmangles, 0.1 );	
	}
#endif

	CalcIronsights( vmorigin, vmangles ); //BG2 -Added for Iron Sights Testing. Credits to Jorg for the code. -HairyPotter

	SetLocalOrigin( Vector( vmorigin.x, vmorigin.y, vmorigin.z ) );
	SetLocalAngles( vmangles );

#endif
}
Exemple #24
0
/**
 * Plant the bomb.
 */
void PlantBombState::OnUpdate( CCFBot *me )
{
	CBaseCombatWeapon *gun = me->GetActiveWeapon();
	bool holdingC4 = false;
	if (gun)
	{
		if (FStrEq( gun->GetClassname(), "weapon_c4" ))
			holdingC4 = true;
	}

	// if we aren't holding the C4, grab it, otherwise plant it
	if (holdingC4)
		me->PrimaryAttack();
	else
		me->SelectItem( "weapon_c4" );

	// if we time out, it's because we slipped into a non-plantable area
	const float timeout = 5.0f;
	if (gpGlobals->curtime - me->GetStateTimestamp() > timeout)
		me->Idle();
}
bool Dota_Resupply::ReSupplyPlayer( CHL2MP_Player * pPlayer )
{
	CBaseCombatWeapon * weapon;
	int weaponLevel;
	int iAmmoIndex;
	bool gotSomething = false;
	
	for ( int i = 1; i < MAX_AMMO_TYPES; i++ )
	{
		Item_t * item = GetItemDef()->GetItemOfIndex(i);
		if ( item && item->pWeaponNeeded == NULL  )
		{
			weapon = pPlayer->Weapon_OwnsThisType( item->pName );
			weaponLevel = pPlayer->GetWeaponLevel( item->pName );
			if ( weapon && weaponLevel > 0 )
			{
				iAmmoIndex = weapon->GetPrimaryAmmoType();
				if ( iAmmoIndex < 0 || iAmmoIndex >= MAX_AMMO_SLOTS )
					continue;

				int iMax = (GetAmmoDef()->MaxCarry(iAmmoIndex) / 4) * weaponLevel;

				if ( weapon->UsesClipsForAmmo1() ) {
					int missingFromClip1 = weapon->GetMaxClip1() - weapon->Clip1();
					iMax += missingFromClip1;
				}
								
				int iAdd = iMax - pPlayer->GetAmmoCount(iAmmoIndex);
				if ( iAdd >= 1 )
					gotSomething |= (pPlayer->GiveAmmo( iAdd, weapon->GetPrimaryAmmoType() ) != 0);						
			}
		}
	}	
	return gotSomething;
}
Exemple #26
0
inline bool C_BaseViewModel::ShouldFlipViewModel()
{
#if defined ( CSTRIKE_DLL ) || defined ( MYMOD_CLIENT_DLL )
	// If cl_righthand is set, then we want them all right-handed.
	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	if ( pWeapon )
	{
		const FileWeaponInfo_t *pInfo = &pWeapon->GetWpnData();
		return pInfo->m_bAllowFlipping && pInfo->m_bBuiltRightHanded != cl_righthand.GetBool();
	}
#endif

#ifdef TF_CLIENT_DLL
	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	if ( pWeapon )
	{
		return pWeapon->m_bFlipViewModel != cl_flipviewmodels.GetBool();
	}
#endif

	return false;
}
Exemple #27
0
//-----------------------------------------------------------------------------
// Purpose: Called every usercmd by the player PreThink
//-----------------------------------------------------------------------------
void CBasePlayer::ItemPreFrame()
{
	// Handle use events
	PlayerUse();

	//Tony; re-ordered this for efficiency and to make sure that certain things happen in the correct order!
    if ( gpGlobals->curtime < m_flNextAttack )
	{
		return;
	}

	if (!GetActiveWeapon())
		return;

#if defined( CLIENT_DLL )
	// Not predicting this weapon
	if ( !GetActiveWeapon()->IsPredicted() )
		return;
#endif

	GetActiveWeapon()->ItemPreFrame();

	CBaseCombatWeapon *pWeapon;

	CBaseCombatWeapon *pActive = GetActiveWeapon();
	// Allow all the holstered weapons to update
	for ( int i = 0; i < WeaponCount(); ++i )
	{
		pWeapon = GetWeapon( i );

		if ( pWeapon == NULL )
			continue;

		if ( pActive == pWeapon )
			continue;

		pWeapon->ItemHolsterFrame();
	}
}
void CAI_MappedActivityBehavior_Temporary::UpdateTranslateActivityMap()
{
	AI_ActivityMapping_t mappings[] =		// This array cannot be static, as some activity values are set on a per-map-load basis
	{
		{	AIP_CROUCHING, 	ACT_IDLE, 				NULL, 				ACT_COVER_LOW, 				},
		{	AIP_CROUCHING, 	ACT_IDLE_ANGRY,			NULL, 				ACT_COVER_LOW, 				},
		{	AIP_CROUCHING, 	ACT_WALK, 				NULL, 				ACT_WALK_CROUCH, 			},
		{	AIP_CROUCHING, 	ACT_RUN, 				NULL, 				ACT_RUN_CROUCH, 			},
		{	AIP_CROUCHING, 	ACT_WALK_AIM, 			NULL, 				ACT_WALK_CROUCH_AIM, 		},
		{	AIP_CROUCHING, 	ACT_RUN_AIM, 			NULL, 				ACT_RUN_CROUCH_AIM, 		},
		{	AIP_CROUCHING,	ACT_RELOAD,				NULL, 				ACT_RELOAD_LOW,				},
		{	AIP_CROUCHING,	ACT_RANGE_ATTACK_SMG1,	NULL,				ACT_RANGE_ATTACK_SMG1_LOW,	},
		{	AIP_CROUCHING,	ACT_RANGE_ATTACK_AR2,	NULL,				ACT_RANGE_ATTACK_AR2_LOW,	},
		
		//----
		{	AIP_PEEKING, 	ACT_IDLE,				NULL,				ACT_RANGE_AIM_LOW,			},
		{	AIP_PEEKING, 	ACT_IDLE_ANGRY,			NULL,				ACT_RANGE_AIM_LOW,			},
		{	AIP_PEEKING, 	ACT_COVER_LOW,			NULL,				ACT_RANGE_AIM_LOW,			},
		{	AIP_PEEKING, 	ACT_RANGE_ATTACK1,		NULL, 				ACT_RANGE_ATTACK1_LOW,		},
		{	AIP_PEEKING,	ACT_RELOAD, 			NULL, 				ACT_RELOAD_LOW,				},
	};

	m_ActivityMap.RemoveAll();
	
	CBaseCombatWeapon *pWeapon = GetOuter()->GetActiveWeapon();
	const char *pszWeaponClass = ( pWeapon ) ? pWeapon->GetClassname() : "";
	for ( int i = 0; i < ARRAYSIZE(mappings); i++ )
	{
		if ( !mappings[i].pszWeapon || stricmp( mappings[i].pszWeapon, pszWeaponClass ) == 0 )
		{
			if ( HaveSequenceForActivity( mappings[i].translation ) || HaveSequenceForActivity( GetOuter()->Weapon_TranslateActivity( mappings[i].translation ) ) )
			{
				Assert( m_ActivityMap.Find( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ) ) == m_ActivityMap.InvalidIndex() );
				m_ActivityMap.Insert( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ), mappings[i].translation );
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Catches the monster-specific messages that occur when tagged
//			animation frames are played.
// Input  : *pEvent - 
//-----------------------------------------------------------------------------
void CItem_AmmoCrate::HandleAnimEvent( animevent_t *pEvent )
{
	if ( pEvent->event == AE_AMMOCRATE_PICKUP_AMMO )
	{
		if ( m_hActivator )
		{
			if ( m_pGiveWeapon[m_nAmmoType] && !m_hActivator->Weapon_OwnsThisType( m_pGiveWeapon[m_nAmmoType] ) )
			{
				CBaseEntity *pEntity = CreateEntityByName( m_pGiveWeapon[m_nAmmoType] );
				CBaseCombatWeapon *pWeapon = dynamic_cast<CBaseCombatWeapon*>(pEntity);
				if ( pWeapon )
				{
					pWeapon->SetAbsOrigin( m_hActivator->GetAbsOrigin() );
					pWeapon->m_iPrimaryAmmoType = 0;
					pWeapon->m_iSecondaryAmmoType = 0;
					pWeapon->Spawn();
					if ( !m_hActivator->BumpWeapon( pWeapon ) )
					{
						UTIL_Remove( pEntity );
					}
					else
					{
						SetBodygroup( 1, false );
					}
				}
			}

			if ( m_hActivator->GiveAmmo( m_nAmmoAmounts[m_nAmmoType], m_nAmmoIndex ) != 0 )
			{
				SetBodygroup( 1, false );
			}
			m_hActivator = NULL;
		}
		return;
	}

	BaseClass::HandleAnimEvent( pEvent );
}
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles )
{
	// UNDONE: Calc this on the server?  Disabled for now as it seems unnecessary to have this info on the server
#if defined( CLIENT_DLL )
	QAngle vmangoriginal = eyeAngles;
	QAngle vmangles = eyeAngles;
	Vector vmorigin = eyePosition;

	CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
	//Allow weapon lagging
	if ( pWeapon != NULL )
	{
#if defined( CLIENT_DLL )
		if ( !prediction->InPrediction() )
#endif
		{
			// add weapon-specific bob 
			pWeapon->AddViewmodelBob( this, vmorigin, vmangles );
		}
	}
	// Add model-specific bob even if no weapon associated (for head bob for off hand models)
	AddViewModelBob( owner, vmorigin, vmangles );
	// Add lag
	CalcViewModelLag( vmorigin, vmangles, vmangoriginal );

#if defined( CLIENT_DLL )
	if ( !prediction->InPrediction() )
	{
		// Let the viewmodel shake at about 10% of the amplitude of the player's view
		vieweffects->ApplyShake( vmorigin, vmangles, 0.1 );	
	}
#endif

	SetLocalOrigin( vmorigin );
	SetLocalAngles( vmangles );

#endif
}