void
Powerup::pickup (CBaseEntity *other)
{
	const int MAXENTS = 64;
	CDAPlayer *ents[MAXENTS];
	CDAPlayer *taker;
	int len;
	int i;

	if (!other->IsPlayer ())
	{
		return;
	}
	/*Fire off 'Denied!' to relevant players; award taker style for it*/
	taker = (CDAPlayer *)other;
	len = UTIL_EntitiesInSphere ((CBaseEntity **)ents, 
								 MAXENTS, 
								 GetAbsOrigin (), 
								 96, 
								 FL_CLIENT);
	for (i = 0; i < len; i++)
	{
		if (ents[i] != taker) 
		{
			Vector org, forward;

			AngleVectors (ents[i]->EyeAngles (), &forward);
			VectorSubtract (ents[i]->GetAbsOrigin (), GetAbsOrigin (), org);
			VectorNormalize (org);
			if (fabs (DotProduct (forward, org)) < 0.7)
			{
				/*ents[i]->SendNotice (NOTICE_DENIED);*/
			}
		}
		else if (len != 1) 
		{
			//taker->SendAnnouncement (ANNOUNCEMENT_COOL, STYLE_POINT_STYLISH);
		}
	}
	CPASFilter filter (GetAbsOrigin ());
	filter.UsePredictionRules ();
	EmitSound (filter, entindex (), "HealthVial.Touch");
	/*Impart pickup bonus*/
	switch (type)
	{
	case POWERUP_HEALTH: taker->TakeHealth (100, DMG_GENERIC); break;
	case POWERUP_REGEN: Msg ("Regen\n"); break;
	case POWERUP_RAMBO: Msg ("Rambo mode\n"); break;
	case POWERUP_SLOWMO: taker->GiveSlowMo (5); break;
	case POWERUP_GRENADE: taker->GiveAmmo (1, "grenade", true); break;
	case POWERUP_DOUBLEACTION: Msg ("Double action\n"); break;
	default: /*Shouldn't get here*/ break;
	}
	/*Go inactive until respawn timer expires*/
	AddEffects (EF_NODRAW);
	AddSolidFlags (FSOLID_NOT_SOLID);
	SetTouch (NULL);
	SetThink (&Powerup::manifest);
	SetNextThink (gpGlobals->curtime + delay);
}
void CMapAddLabel::Think()
{
	BaseClass::Think(); // Always do this if you override Think()
 
	

	//What this does, is look through entities in a sphere, and then
	//checks to see if they are valid, and if they are
	//adds them to a second list of valid entities.
	//Create an array of CBaseEntity pointers
	CBaseEntity *ppEnts[256];
	int nEntCount = UTIL_EntitiesInSphere( ppEnts, 256, this->GetAbsOrigin(), m_nTriggerArea, 0 );
	int i;
	for ( i = 0; i < nEntCount; i++ )
	{
			//Look through the entities it found
		if ( ppEnts[i] != NULL )
			if(ppEnts[i]->IsPlayer())
			{
				Msg( "mapadd_trig was triggered!\n" );
				m_OnTrigger.FireOutput(ppEnts[i],this);
			//	if(m_bDeleteOnFire)
			//	{
				//	SetNextThink( gpGlobals->curtime + 1 ); // Think again in 1 second
					UTIL_Remove( this );
			//	}
			//	SetNextThink( gpGlobals->curtime + 1 ); // Think again in 1 second
			}
	}
	SetNextThink( gpGlobals->curtime + 1 ); // Think again in 1 second
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CRallyPoint *CAI_AssaultBehavior::FindBestRallyPointInRadius( const Vector &vecCenter, float flRadius )
{
	VPROF_BUDGET( "CAI_AssaultBehavior::FindBestRallyPointInRadius", VPROF_BUDGETGROUP_NPCS );

	const int RALLY_SEARCH_ENTS	= 30;
	CBaseEntity *pEntities[RALLY_SEARCH_ENTS];
	int iNumEntities = UTIL_EntitiesInSphere( pEntities, RALLY_SEARCH_ENTS, vecCenter, flRadius, 0 );

	CRallyPoint *pBest = NULL;
	int iBestPriority = -1;

	for ( int i = 0; i < iNumEntities; i++ )
	{
		CRallyPoint *pRallyEnt = dynamic_cast<CRallyPoint *>(pEntities[i]);

		if( pRallyEnt )
		{
			if( !pRallyEnt->IsLocked() )
			{
				// Consider this point.
				if( pRallyEnt->m_iPriority > iBestPriority )
				{
					pBest = pRallyEnt;
					iBestPriority = pRallyEnt->m_iPriority;
				}
			}
		}
	}

	return pBest;
}
void CFlechette::DoAOEDamage()
{
	CBaseEntity *ppEnts[256];
	Vector vecCenter = WorldSpaceCenter();
	 
	float flRadius = flechette_radius.GetFloat();
	vecCenter.z -= flRadius * 0.8f;
	int nEntCount = UTIL_EntitiesInSphere( ppEnts, 256, vecCenter, flRadius, 0 );
	int i;
	for ( i = 0; i < nEntCount; i++ )
	{
		if ( ppEnts[i] == NULL )
			continue;
		bool bDoDamage = true;
		if(ppEnts[i]->IsPlayer() || ppEnts[i]->IsNPC())
		{
			CBasePlayer *pOtherPlayer  = ToBasePlayer(ppEnts[i]);
			CBasePlayer *pPlayer  = ToBasePlayer(GetOwnerEntity());
			if(pOtherPlayer != NULL && pPlayer != NULL)
			{
				if((HL2MPRules()->IsTeamplay() && (pPlayer->GetTeamNumber() == pOtherPlayer->GetTeamNumber()))
					|| HL2MPRules()->GetGameType() == GAME_COOP)
				{
					const int oldHealth = pOtherPlayer->GetHealth();
					pOtherPlayer->TakeHealth( HEAL_AMOUNT, DMG_GENERIC );
					bDoDamage = false;
					if(oldHealth <= HEAL_AMOUNT)
						pOtherPlayer->PlayAutovocal(HEALED,0);
					if(oldHealth != pOtherPlayer->GetHealth()) // Si on a vraiment heal
						pOtherPlayer->EmitSound("Tranqu.Heal");
				}
			}
			if(bDoDamage && ppEnts[i] != GetOwnerEntity())
			{
				int iApplyDamage = 0;
				if(ppEnts[i]->IsNPC())
					iApplyDamage = 70;
				else
				{
					if(ppEnts[i]->GetHealth() < m_iDamage + 10)
						iApplyDamage = 100;
					else
						iApplyDamage = ppEnts[i]->GetHealth() - m_iDamage;
				}

				CTakeDamageInfo	dmgInfo( this, GetOwnerEntity(), GetOwnerEntity(), iApplyDamage, DMG_POISON | DMG_NEVERGIB );
				//CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
				dmgInfo.SetDamagePosition( vecCenter );
				ppEnts[i]->TakeDamage(dmgInfo);
				//ppEnts[i]->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
			}
		}

		ApplyMultiDamage();

	}
}
Exemple #5
0
boost::python::object UTIL_PyEntitiesInSphere( int listMax, const Vector &center, float radius, int flagMask )
{
	int i, n;
	CBaseEntity **pList;
	boost::python::list pylist = boost::python::list();

	pList = (CBaseEntity **)malloc(listMax*sizeof(CBaseEntity *));
	n = UTIL_EntitiesInSphere(pList, listMax, center, radius, flagMask);
	for( i=0; i < n; i++)
		pylist.append(*pList[i]);
	free(pList);
	return pylist;
}
bool CMapAdd::HandleRemoveEnitity( KeyValues *mapaddValue)
{
	if(AllocPooledString(mapaddValue->GetName()) == AllocPooledString("remove:sphere"))
	{
		Vector RemoveVector = Vector(0,0,0);
		CBaseEntity *ppEnts[256];
//		CBaseEntity *ppCandidates[256];
		RemoveVector.x = mapaddValue->GetFloat("x", RemoveVector.x);
		RemoveVector.y = mapaddValue->GetFloat("y", RemoveVector.y);
		RemoveVector.z = mapaddValue->GetFloat("z", RemoveVector.z);
		int nEntCount = UTIL_EntitiesInSphere( ppEnts, 256, RemoveVector, mapaddValue->GetFloat("radius", 0), 0 );

				//Look through the entities it found
			KeyValues *pEntKeyValues = mapaddValue->FindKey("entities");
			if(pEntKeyValues)
			{
				KeyValues *pEntKeyValuesRemove = pEntKeyValues->GetFirstValue();
				while(pEntKeyValuesRemove)
				{
					int i;
					for ( i = 0; i < nEntCount; i++ )
					{
			
						if ( ppEnts[i] == NULL )
							continue;
						if(AllocPooledString(pEntKeyValuesRemove->GetName()) == AllocPooledString("classname")) // || ( AllocPooledString(pEntKeyValuesRemove->GetName()) == ppEnts[i]->GetEntityName())
						{
							if(AllocPooledString(pEntKeyValuesRemove->GetString()) == AllocPooledString(ppEnts[i]->GetClassname()))
							{
								UTIL_Remove(ppEnts[i]);
								continue;
							}
						}
						if(AllocPooledString(pEntKeyValuesRemove->GetName()) == AllocPooledString("targetname")) // || ( AllocPooledString(pEntKeyValuesRemove->GetName()) == ppEnts[i]->GetEntityName())
						{
							if(AllocPooledString(pEntKeyValuesRemove->GetString()) == ppEnts[i]->GetEntityName())
							{
								UTIL_Remove(ppEnts[i]);
								continue;
							}
						}
					}
					pEntKeyValuesRemove = pEntKeyValuesRemove->GetNextValue();
				}
			}
			return true;
	}
	return false;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPhysMagnet::DoMagnetSuck( CBaseEntity *pOther )
{
	if ( !HasSpawnFlags( SF_MAGNET_SUCK ) )
		return;

	if ( !m_bActive )
		return;

	// Don't repeatedly suck
	if ( m_flNextSuckTime > gpGlobals->curtime )
		return;
	
	// Look for physics objects underneath the magnet and suck them onto it
	Vector vecCheckPos, vecSuckPoint;
	VectorTransform( Vector(0,0,-96), EntityToWorldTransform(), vecCheckPos );
	VectorTransform( Vector(0,0,-64), EntityToWorldTransform(), vecSuckPoint );

	CBaseEntity *pEntities[20];
	int iNumEntities = UTIL_EntitiesInSphere( pEntities, 20, vecCheckPos, 80.0, 0 );
	for ( int i = 0; i < iNumEntities; i++ )
	{
		CBaseEntity *pEntity = pEntities[i];
		if ( !pEntity || pEntity == pOther )
			continue;

		IPhysicsObject *pPhys = pEntity->VPhysicsGetObject();
		if ( pPhys && pEntity->GetMoveType() == MOVETYPE_VPHYSICS && pPhys->GetMass() < 5000 )
		{
			// Do we have line of sight to it?
			trace_t tr;
			UTIL_TraceLine( GetAbsOrigin(), pEntity->GetAbsOrigin(), MASK_SHOT, this, 0, &tr );
			if ( tr.fraction == 1.0 || tr.m_pEnt == pEntity )
			{
				// Pull it towards the magnet
				Vector vecVelocity = (vecSuckPoint - pEntity->GetAbsOrigin());
				VectorNormalize(vecVelocity);
				vecVelocity *= 5 * pPhys->GetMass();
				pPhys->AddVelocity( &vecVelocity, NULL );
			}
		}
	}

	m_flNextSuckTime = gpGlobals->curtime + 2.0;
}
Exemple #8
0
CEntitySphereQuery::CEntitySphereQuery( const Vector &center, float radius, int flagMask, int partitionMask )
{
	m_listIndex = 0;
	m_listCount = UTIL_EntitiesInSphere( m_pList, ARRAYSIZE(m_pList), center, radius, flagMask, partitionMask );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFGrenadeEmpProjectile::Detonate()
{
	if ( ShouldNotDetonate() )
	{
		RemoveGrenade();
		return;
	}

	// Explosion effect on client
	// SendDispatchEffect();

	float flRadius = 180;
	float flDamage = 1;

	if ( tf_grenade_show_radius.GetBool() )
	{
		DrawRadius( flRadius );
	}

	// Apply some amount of EMP damage to every entity in the radius. They will calculate 
	// their own damage based on how much ammo they have or some other wacky calculation.

	CTakeDamageInfo info( this, GetThrower(), vec3_origin, GetAbsOrigin(), flDamage, /* DMG_EMP |*/ DMG_PREVENT_PHYSICS_FORCE );

	CBaseEntity *pEntityList[100];
	int nEntityCount = UTIL_EntitiesInSphere( pEntityList, 100, GetAbsOrigin(), flRadius, 0 );
	int iEntity;
	for ( iEntity = 0; iEntity < nEntityCount; ++iEntity )
	{
		CBaseEntity *pEntity = pEntityList[iEntity];

		if ( pEntity == this )
			continue;

		if ( pEntity && pEntity->IsPlayer() )
			continue;

		if ( pEntity && ( pEntity->m_takedamage == DAMAGE_YES || pEntity->m_takedamage == DAMAGE_EVENTS_ONLY ) )
		{
			pEntity->TakeDamage( info );

			//if ( pEntity->IsPlayer() /* || is ammo box || is enemy object */ )
			{
				CBeam *pBeam = CBeam::BeamCreate( "sprites/physcannon_bluelight1b.vmt", 3.0 );
				if ( !pBeam )
					return;

				pBeam->PointsInit( GetAbsOrigin(), pEntity->WorldSpaceCenter() );

				pBeam->SetColor( 255, 255, 255 );
				pBeam->SetBrightness( 128 );
				pBeam->SetNoise( 12.0f );
				pBeam->SetEndWidth( 3.0f );
				pBeam->SetWidth( 3.0f );
				pBeam->LiveForTime( 0.5f );	// Fail-safe
				pBeam->SetFrameRate( 25.0f );
				pBeam->SetFrame( random->RandomInt( 0, 2 ) );
			}
		}
	}

	DispatchParticleEffect( "emp_shockwave", GetAbsOrigin(), vec3_angle );

	UTIL_Remove( this );

#if 0
	// Tell the bots an HE grenade has exploded
	CTFPlayer *pPlayer = ToTFPlayer( GetThrower() );
	if ( pPlayer )
	{
		KeyValues *pEvent = new KeyValues( "tf_weapon_grenade_detonate" );
		pEvent->SetInt( "userid", pPlayer->GetUserID() );
		gameeventmanager->FireEventServerOnly( pEvent );
	}
#endif
}