Ejemplo n.º 1
0
//Pose la mine sur son support une fois l'animation terminée
void CWeaponMine::FinishAttach( void ){
	CHL2MP_Player *pOwner = ToHL2MPPlayer( GetOwner() );
	if (!pOwner)
		return;

	Vector vecSrc, vecAiming;
	vecSrc = pOwner->EyePosition();
	QAngle angles = pOwner->GetLocalAngles();
	AngleVectors( angles, &vecAiming );
	trace_t tr;
	UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 60), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr );
	
	if (tr.fraction < 1.0)
	{		
		if (tr.m_pEnt)
		{
			//On attache pas la mine sur une entité vivante
			CBaseEntity *pEntity = tr.m_pEnt;
			CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity );
			if (pBCC){
				m_bAttachMine  = false;
				m_bNeedReload = true;
				return;
			}

#ifndef CLIENT_DLL
			//On vérifie qu'il n 'y a pas déjà une mine sur le support visé
			CBaseEntity* pResult = gEntList.FindEntityByClassname(NULL,"npc_mine");
			while (pResult)
			{
				if((pResult->GetAbsOrigin() - tr.endpos).Length() < MINE_DISTANCE){
					m_bAttachMine  = false;
					m_bNeedReload = true;
					return;
				}

				pResult = gEntList.FindEntityByClassname(pResult,"npc_mine");
			}

			if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR))
			{
				QAngle angles;
				VectorAngles(tr.plane.normal, angles);
				angles.x += 90;

				CBaseEntity *pEnt = CBaseEntity::Create( "npc_mine", tr.endpos + tr.plane.normal * 3, angles, NULL );
				CNPCMine *pMine = (CNPCMine *)pEnt;
				pMine->m_hOwner = GetOwner();
				ChooseMineColor(pMine);
				pMine->AttachToEntity( pEntity );

				pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType );
			}
#endif
		}
	}

	m_bAttachMine  = false;
	m_bNeedReload = true;
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose:
// Input  :
// Output :
//-----------------------------------------------------------------------------
void CWeapon_SLAM::TripmineAttach( void )
{
	CHL2MP_Player *pOwner  = ToHL2MPPlayer( GetOwner() );
	if (!pOwner)
	{
		return;
	}

	m_bAttachTripmine = false;

	Vector vecSrc, vecAiming;

	// Take the eye position and direction
	vecSrc = pOwner->EyePosition();
	
	QAngle angles = pOwner->GetLocalAngles();

	AngleVectors( angles, &vecAiming );

	trace_t tr;

	UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr );
	
	if (tr.fraction < 1.0)
	{
		CBaseEntity *pEntity = tr.m_pEnt;
		if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR))
		{

#ifndef CLIENT_DLL
			QAngle angles;
			VectorAngles(tr.plane.normal, angles);

			angles.x += 90;

			CBaseEntity *pEnt = CBaseEntity::Create( "npc_tripmine", tr.endpos + tr.plane.normal * 3, angles, NULL );

			CTripmineGrenade *pMine = (CTripmineGrenade *)pEnt;
			pMine->m_hOwner = GetOwner();
			// Attempt to attach to entity, or just sit still in place.
			pMine->AttachToEntity( pEntity );

#endif

			pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType );
		}
	}
}