コード例 #1
0
//-----------------------------------------------------------------------------
// Computes ambient lighting along a specified ray.
//-----------------------------------------------------------------------------
void CalcRayAmbientLighting(
	const Vector &vStart,
	const Vector &vEnd,
	Vector color[MAX_LIGHTSTYLES],
	Vector &colorSum )
{
	Ray_t ray;
	ray.Init( vStart, vEnd, vec3_origin, vec3_origin );

	directlight_t *pSkyLight = FindAmbientSkyLight();

	colorSum.Init();

	CLightSurface surfEnum;
	if (!surfEnum.FindIntersection( ray ))
		return;

	// This is the faster path; it looks slightly different though
	if (surfEnum.m_pSurface->dispinfo == -1)
	{
		ComputeLightmapColorFromAverage( surfEnum.m_pSurface, pSkyLight, color, colorSum );
	}
	else
	{
		ComputeLightmapColorDisplacement( surfEnum.m_pSurface, pSkyLight, surfEnum.m_LuxelCoord, color, colorSum );
	}
}
コード例 #2
0
void CPortalGameMovement::TracePlayerBBox( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm )
{
	VPROF( "CGameMovement::TracePlayerBBox" );
	
	CPortal_Player *pPortalPlayer = (CPortal_Player *)((CBaseEntity *)mv->m_nPlayerHandle.Get());

	Ray_t ray;
	ray.Init( start, end, GetPlayerMins(), GetPlayerMaxs() );

#ifdef CLIENT_DLL
	CTraceFilterSimple traceFilter( mv->m_nPlayerHandle.Get(), collisionGroup );
#else
	CTraceFilterSimple baseFilter( mv->m_nPlayerHandle.Get(), collisionGroup );
	CTraceFilterTranslateClones traceFilter( &baseFilter );
#endif

	UTIL_Portal_TraceRay_With( pPortalPlayer->m_hPortalEnvironment, ray, fMask, &traceFilter, &pm );

	// If we're moving through a portal and failed to hit anything with the above ray trace
	// Use UTIL_Portal_TraceEntity to test this movement through a portal and override the trace with the result
	if ( pm.fraction == 1.0f && UTIL_DidTraceTouchPortals( ray, pm ) && sv_player_trace_through_portals.GetBool() )
	{
		trace_t tempTrace;
		UTIL_Portal_TraceEntity( pPortalPlayer, start, end, fMask, &traceFilter, &tempTrace );

		if ( tempTrace.DidHit() && tempTrace.fraction < pm.fraction && !tempTrace.startsolid && !tempTrace.allsolid )
		{
			pm = tempTrace;
		}
	}
}
コード例 #3
0
ファイル: c_te_decal.cpp プロジェクト: Bubbasacs/FinalProj
//-----------------------------------------------------------------------------
// Tempent 
//-----------------------------------------------------------------------------
void TE_Decal( IRecipientFilter& filter, float delay,
	const Vector* pos, const Vector* start, int entity, int hitbox, int index )
{
	RecordDecal( *pos, *start, entity, hitbox, index );

	trace_t tr;

	// Special case for world entity with hitbox:
	if ( (entity == 0) && (hitbox != 0) )
	{
		Ray_t ray;
		ray.Init( *start, *pos );
		staticpropmgr->AddDecalToStaticProp( *start, *pos, hitbox - 1, index, false, tr );
	}
	else
	{
		// Only decal the world + brush models
		// Here we deal with decals on entities.
		C_BaseEntity* ent;
		if ( ( ent = cl_entitylist->GetEnt( entity ) ) == false )
			return;

		ent->AddDecal( *start, *pos, *pos, hitbox, 
			index, false, tr );
	}
}
コード例 #4
0
ファイル: vraddetailprops.cpp プロジェクト: hitmen047/CM2013
bool CastRayInLeaf( int iThread, const Vector &start, const Vector &end, int leafIndex, float *pFraction, Vector *pNormal )
{
	pFraction[0] = 1.0f;

	Ray_t ray;
	ray.Init( start, end, vec3_origin, vec3_origin );
	CBaseTrace trace;
	if ( TraceLeafBrushes( leafIndex, start, end, trace ) != 1.0f )
	{
		pFraction[0] = trace.fraction;
		*pNormal = trace.plane.normal;
	}
	else
	{
		Assert(!trace.startsolid && !trace.allsolid);
	}
	StaticDispMgr()->StartRayTest( s_DispTested[iThread] );
	// Now try to clip against all displacements in the leaf
	float dist;
	Vector normal;
	StaticDispMgr()->ClipRayToDispInLeaf( s_DispTested[iThread], ray, leafIndex, dist, &normal );
	if ( dist < pFraction[0] )
	{
		pFraction[0] = dist;
		*pNormal = normal;
	}
	return pFraction[0] != 1.0f ? true : false;
}
コード例 #5
0
ファイル: visuals.cpp プロジェクト: auraGB/aurawareSelfLeak
void Visuals::Misc::ThirdPerson() {
	if (!g_LocalPlayer)
		return;

	if (g_Options.misc_thirdperson && g_LocalPlayer->IsAlive())
	{
		if (!g_Input->m_fCameraInThirdPerson)
		{
			g_Input->m_fCameraInThirdPerson = true;
		}

		float dist = g_Options.misc_thirdperson_dist;

		QAngle *view = g_LocalPlayer->GetVAngles();
		trace_t tr;
		Ray_t ray;

		Vector desiredCamOffset = Vector(cos(DEG2RAD(view->yaw)) * dist,
			sin(DEG2RAD(view->yaw)) * dist,
			sin(DEG2RAD(-view->pitch)) * dist
		);

		//cast a ray from the Current camera Origin to the Desired 3rd person Camera origin
		ray.Init(g_LocalPlayer->GetEyePos(), (g_LocalPlayer->GetEyePos() - desiredCamOffset));
		CTraceFilter traceFilter;
		traceFilter.pSkip = g_LocalPlayer;
		g_EngineTrace->TraceRay(ray, MASK_SHOT, &traceFilter, &tr);

		Vector diff = g_LocalPlayer->GetEyePos() - tr.endpos;
		float distance2D = sqrt(abs(diff.x * diff.x) + abs(diff.y * diff.y));// Pythagorean

		bool horOK = distance2D > (dist - 2.0f);
		bool vertOK = (abs(diff.z) - abs(desiredCamOffset.z) < 3.0f);

		float cameraDistance;

		if (horOK && vertOK)  // If we are clear of obstacles
		{
			cameraDistance = dist; // go ahead and set the distance to the setting
		}
		else
		{
			if (vertOK) // if the Vertical Axis is OK
			{
				cameraDistance = distance2D * 0.95f;
			}
			else// otherwise we need to move closer to not go into the floor/ceiling
			{
				cameraDistance = abs(diff.z) * 0.95f;
			}
		}
		g_Input->m_fCameraInThirdPerson = true;

		g_Input->m_vecCameraOffset.z = cameraDistance;
	}
	else
	{
		g_Input->m_fCameraInThirdPerson = false;
	}
}
コード例 #6
0
ファイル: c_asw_alien.cpp プロジェクト: Au-heppa/swarm-sdk
surfacedata_t* C_ASW_Alien::GetGroundSurface()
{
	//
	// Find the name of the material that lies beneath the player.
	//
	Vector start, end;
	VectorCopy( GetAbsOrigin(), start );
	VectorCopy( start, end );

	// Straight down
	end.z -= 38; // was 64

	// Fill in default values, just in case.
	
	Ray_t ray;
	ray.Init( start, end, GetCollideable()->OBBMins(), GetCollideable()->OBBMaxs() );

	trace_t	trace;
	UTIL_TraceRay( ray, MASK_NPCSOLID_BRUSHONLY, this, COLLISION_GROUP_NPC, &trace );

	if ( trace.fraction == 1.0f )
		return NULL;	// no ground
	
	return physprops->GetSurfaceData( trace.surface.surfaceProps );
}
コード例 #7
0
ファイル: mom_gamemovement.cpp プロジェクト: Ravennholm/game
void CMomentumGameMovement::PlayerMove()
{
    BaseClass::PlayerMove();

    if (player->IsAlive())
    {
        // Check if our eye height is too close to the ceiling and lower it.
        // This is needed because we have taller models with the old collision bounds.

        const float eyeClearance = 12.0f; // eye pos must be this far below the ceiling

        Vector offset = player->GetViewOffset();

        Vector vHullMin = GetPlayerMins(player->m_Local.m_bDucked);
        vHullMin.z = 0.0f;
        Vector vHullMax = GetPlayerMaxs(player->m_Local.m_bDucked);

        Vector start = player->GetAbsOrigin();
        start.z += vHullMax.z;
        Vector end = start;
        end.z += eyeClearance - vHullMax.z;
        end.z += player->m_Local.m_bDucked ? VEC_DUCK_VIEW.z : VEC_VIEW.z;

        vHullMax.z = 0.0f;

        Vector fudge(1, 1, 0);
        vHullMin += fudge;
        vHullMax -= fudge;

        trace_t trace;
        Ray_t ray;
        ray.Init(start, end, vHullMin, vHullMax);
        UTIL_TraceRay(ray, PlayerSolidMask(), mv->m_nPlayerHandle.Get(), COLLISION_GROUP_PLAYER_MOVEMENT, &trace);

        if (trace.fraction < 1.0f)
        {
            float est = start.z + trace.fraction * (end.z - start.z) - player->GetAbsOrigin().z - eyeClearance;
            if ((player->GetFlags() & FL_DUCKING) == 0 && !player->m_Local.m_bDucking && !player->m_Local.m_bDucked)
            {
                offset.z = est;
            }
            else
            {
                offset.z = min(est, offset.z);
            }
            player->SetViewOffset(offset);
        }
        else
        {
            if ((player->GetFlags() & FL_DUCKING) == 0 && !player->m_Local.m_bDucking && !player->m_Local.m_bDucked)
            {
                player->SetViewOffset(VEC_VIEW);
            }
            else if (player->m_Local.m_bDucked && !player->m_Local.m_bDucking)
            {
                player->SetViewOffset(VEC_DUCK_VIEW);
            }
        }
    }
}
コード例 #8
0
static cell_t smn_TRTraceHullEx(IPluginContext *pContext, const cell_t *params)
{
	cell_t *startaddr, *endaddr, *mins, *maxs;
	pContext->LocalToPhysAddr(params[1], &startaddr);
	pContext->LocalToPhysAddr(params[2], &endaddr);
	pContext->LocalToPhysAddr(params[3], &mins);
	pContext->LocalToPhysAddr(params[4], &maxs);

	Ray_t ray;
	Vector StartVec, EndVec, vmins, vmaxs;

	StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
	vmins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2]));
	vmaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2]));
	EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));

	ray.Init(StartVec, EndVec, vmins, vmaxs);

	sm_trace_t *tr = new sm_trace_t;
	enginetrace->TraceRay(ray, params[5], &g_HitAllFilter, tr);
	tr->UpdateEntRef();

	HandleError herr;
	Handle_t hndl;
	if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr)))
	{
		delete tr;
		return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr);
	}

	return hndl;
}
コード例 #9
0
void ProcessUserCommand_ViewESP( CUserCmd *cmd )
{
	QAngle Angles = cmd->viewangles;

	Vector Eyes, Forward;
	

	Eyes = NetVar__GetEyePosition( g_pLocalEntity );

	if ( Eyes.x == 0 && Eyes.y == 0 && Eyes.z == 0 )
		return;

	Vector vDirection;

	AngleVectors( Angles, &vDirection );

	vDirection = vDirection * 8192 + Eyes;

	if ( vDirection.x == 0 && vDirection.y == 0 && vDirection.z == 0 )
		return;
	
	trace_t tr;
	CTraceFilterHitAll filter;

	Ray_t pRay;
	pRay.Init( Eyes, vDirection );

	g_pEngineTrace->TraceRay( pRay, 0x46004003, &filter, &tr);

	if ( !tr.m_pEnt || tr.m_pEnt->entindex() == 0 )
	{
		g_viewClassName = NULL;
	}else{

		Vector org = NetVar__GetOrigin( tr.m_pEnt );

		if ( org.x == 0 && org.y == 0 && org.z == 0 )
		{
			g_viewClassName = NULL;
		}else{

			ClientClass *trClientClass = tr.m_pEnt->GetClientClass();
			
			if ( !trClientClass )
			{
				g_viewClassName = NULL;
				return;
			}

			if ( g_AppID == 4000 )
				g_viewClassName = NetVar__GetClassname( tr.m_pEnt );
			else
				g_viewClassName = trClientClass->m_pNetworkName;

			if ( !g_viewClassName )
				g_viewClassName = NULL;
		}
	}
}
コード例 #10
0
ファイル: vhelpers.cpp プロジェクト: 50Wliu/sourcemod
int GetClientAimTarget(edict_t *pEdict, bool only_players)
{
	CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL;

	if (pEntity == NULL)
	{
		return -1;
	}

	Vector eye_position;
	QAngle eye_angles;

	/* Get the private information we need */
#if SOURCE_ENGINE == SE_DOTA
	serverClients->ClientEarPosition(IndexOfEdict(pEdict), &eye_position);
#else
	serverClients->ClientEarPosition(pEdict, &eye_position);
#endif

	if (!GetEyeAngles(pEntity, &eye_angles))
	{
		return -2;
	}

	Vector aim_dir;
	AngleVectors(eye_angles, &aim_dir);
	VectorNormalize(aim_dir);

	Vector vec_end = eye_position + aim_dir * 8000;

	Ray_t ray;
	ray.Init(eye_position, vec_end);

	trace_t tr;
	CTraceFilterSimple simple(pEdict->GetIServerEntity());

	enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr);

	if (tr.fraction == 1.0f || tr.m_pEnt == NULL)
	{
		return -1;
	}

	int ent_ref = gamehelpers->EntityToBCompatRef(tr.m_pEnt);
	int ent_index = gamehelpers->ReferenceToIndex(ent_ref);

	IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index);
	if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame())
	{
		return -1;
	}
	else if (only_players && pTargetPlayer == NULL)
	{
		return -1;
	}

	return ent_ref;
}
コード例 #11
0
void StickRagdollNowFlechette( const Vector &vecOrigin, const Vector &vecDirection, int nSkin )
{
	Ray_t	shotRay;
	Vector vecEnd = vecOrigin - vecDirection * 128;
	shotRay.Init( vecOrigin, vecEnd );
	CRagdollBoltEnumerator	ragdollEnum( shotRay, vecOrigin );
	partition->EnumerateElementsAlongRay( PARTITION_CLIENT_RESPONSIVE_EDICTS, shotRay, false, &ragdollEnum );
	CreateFlechette( vecOrigin, vecDirection, nSkin );
}
コード例 #12
0
void U::TraceLine( const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, CBaseEntity* ignore, trace_t* ptr )
{
	Ray_t ray;
	ray.Init( vecAbsStart, vecAbsEnd );
	CTraceFilter filter;
	filter.pSkip = ignore;

	I::EngineTrace->TraceRay( ray, mask, &filter, ptr );
}
コード例 #13
0
ファイル: func_no_build.cpp プロジェクト: TenmaPL/TF2Classic
//-----------------------------------------------------------------------------
// Purpose: Return true if the specified point is within this zone
//-----------------------------------------------------------------------------
bool CFuncNoBuild::PointIsWithin( const Vector &vecPoint )
{
	Ray_t ray;
	trace_t tr;
	ICollideable *pCollide = CollisionProp();
	ray.Init( vecPoint, vecPoint );
	enginetrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &tr );
	return ( tr.startsolid );
}
コード例 #14
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool AffectRagdolls( Vector vecOrigin, Vector vecStart, int iDamageType )
{
	Ray_t shotRay;
	shotRay.Init( vecStart, vecOrigin );

	CRagdollEnumerator ragdollEnum( shotRay, CLIENT_SHOT_FORCE, iDamageType );
	partition->EnumerateElementsAlongRay( PARTITION_CLIENT_RESPONSIVE_EDICTS, shotRay, false, &ragdollEnum );

	return ragdollEnum.Hit();
}
コード例 #15
0
// drops us down from the specified position, to the floor
bool CASW_Simple_Alien::ApplyGravity(Vector &vecSrc, float deltatime)
{
	// decide if we're on the ground or not	
	Ray_t ray;
	trace_t trace;
	CTraceFilterSimple traceFilter(this, GetCollisionGroup() );
	ray.Init( vecSrc, vecSrc - Vector(0,0,2), GetHullMins(), GetHullMaxs() );
	enginetrace->TraceRay( ray, MASK_NPCSOLID, &traceFilter, &trace );	
	
	m_bOnGround = (trace.fraction < 1.0f);

	// if we're on the ground, just drop us down as much as we can
	if (m_bOnGround)
	{
		Vector vecGravityTarget = vecSrc;
		vecGravityTarget.z -= sv_gravity.GetFloat() * deltatime;
		// do a trace to the floor
		Ray_t ray;
		trace_t trace;
		CTraceFilterSimple traceFilter(this, GetCollisionGroup() );
		ray.Init( vecSrc, vecGravityTarget, GetHullMins(), GetHullMaxs() );
		enginetrace->TraceRay( ray, MASK_NPCSOLID, &traceFilter, &trace );

		if (trace.fraction > 0 && fabs(trace.endpos.z - vecSrc.z) > 1) // if we moved up/down
		{
			vecSrc = trace.endpos;
			
			return true;
		}
		m_fFallSpeed = 0;  // clear fall speed if we can't fall any further

		return false;
	}

	// we're falling, so apply the fall speed and increase the fall speed over time
	m_fFallSpeed -= sv_gravity.GetFloat() * 1.5f * deltatime;

	Vector vecGravityTarget = vecSrc;
	vecGravityTarget.z += m_fFallSpeed * deltatime;

	// do a trace to the floor
	Ray_t ray2;
	trace_t trace2;
	CTraceFilterSimple traceFilter2(this, GetCollisionGroup() );
	ray2.Init( vecSrc, vecGravityTarget, GetHullMins(), GetHullMaxs() );
	enginetrace->TraceRay( ray2, MASK_NPCSOLID, &traceFilter2, &trace2 );

	if (trace2.fraction > 0 && fabs(trace2.endpos.z - vecSrc.z) > 1) // if we moved up/down
	{
		vecSrc = trace2.endpos;
		return true;
	}
	m_fFallSpeed = 0;  // clear fall speed if we can't fall any further
	return false;
}
コード例 #16
0
bool CASW_Simple_Alien::TryMove(const Vector &vecSrc, Vector &vecTarget, float deltatime, bool bStepMove)
{
	// do a trace to the dest
	Ray_t ray;
	trace_t trace;
	CTraceFilterSimple traceFilter(this, GetCollisionGroup() );
	ray.Init( vecSrc, vecTarget, GetHullMins(), GetHullMaxs() );
	enginetrace->TraceRay( ray, MASK_NPCSOLID, &traceFilter, &trace );
	if (trace.startsolid)
	{
		// doh, we're stuck in something!
		//  todo: move us to a safe spot? wait for push out phys props?
		if (asw_debug_simple_alien.GetBool())
			Msg("CASW_Simple_Alien stuck!\n");
		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;
		return false;
	}
	if (trace.fraction < 0.1f)	 // barely/didn't move
	{
		// try and do a 'stepped up' move to the target
		if (!bStepMove)
		{
			Vector vecStepSrc = vecSrc;
			vecStepSrc.z += 24;
			Vector vecStepTarget = vecTarget;
			vecTarget.z += 24;
			if (TryMove(vecStepSrc, vecStepTarget, deltatime, true))
			{
				vecTarget = vecStepTarget;
				return true;
			}
		}

		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;

		return false;
	}
	else if (trace.fraction < 1)  // we hit something early, but we did move
	{
		// we hit something early
		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;

		vecTarget = trace.endpos;		
	}

	return true;
}
コード例 #17
0
ファイル: tf_gamemovement.cpp プロジェクト: Navton/TF2Classic
//-----------------------------------------------------------------------------
// Traces player movement + position
//-----------------------------------------------------------------------------
void CTFGameMovement::TracePlayerBBox( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm )
{
	if( tf_solidobjects.GetBool() == false )
		return BaseClass::TracePlayerBBox( start, end, fMask, collisionGroup, pm );

	Ray_t ray;
	ray.Init( start, end, GetPlayerMins(), GetPlayerMaxs() );
	
	CTraceFilterObject traceFilter( mv->m_nPlayerHandle.Get(), collisionGroup );

	enginetrace->TraceRay( ray, fMask, &traceFilter, &pm );
}
コード例 #18
0
//-----------------------------------------------------------------------------
// Purpose: Checks collisions against other entities
//-----------------------------------------------------------------------------
void CTFFlameEntity::CheckCollision( CBaseEntity *pOther, bool *pbHitWorld )
{
	*pbHitWorld = false;

	// if we've already burnt this entity, don't do more damage, so skip even checking for collision with the entity
	int iIndex = m_hEntitiesBurnt.Find( pOther );
	if ( iIndex != m_hEntitiesBurnt.InvalidIndex() )
		return;

	// Do a bounding box check against the entity
	Vector vecMins, vecMaxs;
	pOther->GetCollideable()->WorldSpaceSurroundingBounds( &vecMins, &vecMaxs );
	CBaseTrace trace;
	Ray_t ray;
	float flFractionLeftSolid;				
	ray.Init( m_vecPrevPos, GetAbsOrigin(), WorldAlignMins(), WorldAlignMaxs() );
	if ( IntersectRayWithBox( ray, vecMins, vecMaxs, 0.0, &trace, &flFractionLeftSolid ) )
	{
		// if bounding box check passes, check player hitboxes
		trace_t trHitbox;
		trace_t trWorld;
		bool bTested = pOther->GetCollideable()->TestHitboxes( ray, MASK_SOLID | CONTENTS_HITBOX, trHitbox );
		if ( !bTested || !trHitbox.DidHit() )
			return;

		// now, let's see if the flame visual could have actually hit this player.  Trace backward from the
		// point of impact to where the flame was fired, see if we hit anything.  Since the point of impact was
		// determined using the flame's bounding box and we're just doing a ray test here, we extend the
		// start point out by the radius of the box.
		Vector vDir = ray.m_Delta;
		vDir.NormalizeInPlace();
		UTIL_TraceLine( GetAbsOrigin() + vDir * WorldAlignMaxs().x, m_vecInitialPos, MASK_SOLID, this, COLLISION_GROUP_DEBRIS, &trWorld );			

		if ( tf_debug_flamethrower.GetInt() )
		{
			NDebugOverlay::Line( trWorld.startpos, trWorld.endpos, 0, 255, 0, true, 3.0f );
		}
		
		if ( trWorld.fraction == 1.0 )
		{						
			// if there is nothing solid in the way, damage the entity
			OnCollide( pOther );
		}					
		else
		{
			// we hit the world, remove ourselves
			*pbHitWorld = true;
			UTIL_Remove( this );
		}
	}

}
コード例 #19
0
void SizzlingStats::CheckPlayerDropped( CSizzPluginContext *pPluginContext, int victimIndex )
{
	for (int i = 0; i < m_vecMedics.Count(); ++i)
	{
		int medIndex = m_vecMedics[i];
		SS_PlayerData *pMedData = m_PlayerDataManager.GetPlayerData(medIndex).m_pPlayerData;
		SS_PlayerData *pVictimData = m_PlayerDataManager.GetPlayerData(victimIndex).m_pPlayerData;

		IPlayerInfo *pMedPlayerInfo = pPluginContext->GetPlayerInfo(medIndex);
		IPlayerInfo *pVictimPlayerInfo = pPluginContext->GetPlayerInfo(victimIndex);
		if ( pMedPlayerInfo->GetTeamIndex() == pVictimPlayerInfo->GetTeamIndex() )
		{
			using namespace SCHelpers;
			CTFPlayerWrapper medic(pMedData->GetBaseEntity());
			
			//CBaseEntity *pMedigun = pPluginContext->BaseEntityFromBaseHandle(hMedigun);

			//const char *szWeapon = SCHelpers::GetClassName(pMedigun);
			//if ( szWeapon && SCHelpers::FStrEq(szWeapon, "tf_weapon_medigun") )
			//{
				float flChargeLevel = medic.GetChargeLevel(pPluginContext);
				bool bReleasingCharge = medic.IsReleasingCharge();

				if (flChargeLevel == 1.0f || bReleasingCharge)
				{
					CTFPlayerWrapper victim(pVictimData->GetBaseEntity());
					Vector *victimPos = victim.GetPlayerOrigin();
					Vector *medPos = medic.GetPlayerOrigin();
		
					vec_t distance = victimPos->DistToSqr( *medPos );
					SS_AllUserChatMessage( pPluginContext, UTIL_VarArgs("distance: %.2f\n", distance) );
					if (distance <= 230400.0f) // ~480 units is max target distance for medigun
					{
						IHandleEntity *pMedHandleEnt = pPluginContext->HandleEntityFromEntIndex(medIndex);
						// slot 2 because we want the medigun
						IHandleEntity *pMedigunHandleEnt = pPluginContext->HandleEntityFromEntIndex(medic.GetWeapon(2)->GetEntryIndex());

						Ray_t ray;
						ray.Init(*medPos, *victimPos);
						CTraceFilterSkipTwo traceFilter(pMedHandleEnt, pMedigunHandleEnt);
						trace_t trace;
						enginetrace->TraceRay(ray, MASK_SHOT_HULL, &traceFilter, &trace);
						if (!trace.DidHit())
						{
							SS_AllUserChatMessage( pPluginContext, "player dropped\n" );
						}
					}
				}
			//}
		}
	}
}
コード例 #20
0
inline void CSDKGameMovement::TracePlayerBBoxWithStep( const Vector &vStart, const Vector &vEnd, 
							unsigned int fMask, int collisionGroup, trace_t &trace )
{
	VPROF( "CSDKGameMovement::TracePlayerBBoxWithStep" );

	Vector vHullMin = GetPlayerMins( player->m_Local.m_bDucked );
	vHullMin.z += player->m_Local.m_flStepSize;
	Vector vHullMax = GetPlayerMaxs( player->m_Local.m_bDucked );

	Ray_t ray;
	ray.Init( vStart, vEnd, vHullMin, vHullMax );
	UTIL_TraceRay( ray, fMask, mv->m_nPlayerHandle.Get(), collisionGroup, &trace );
}
コード例 #21
0
ファイル: fx_impact.cpp プロジェクト: Davideogame/TheHunted
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool FX_AffectRagdolls( Vector vecOrigin, Vector vecStart, int iDamageType )
{
	// don't do this when lots of ragdolls are simulating
	if ( s_RagdollLRU.CountRagdolls(true) > 1 )
		return false;
	Ray_t shotRay;
	shotRay.Init( vecStart, vecOrigin );

	CRagdollEnumerator ragdollEnum( shotRay, iDamageType );
	partition->EnumerateElementsAlongRay( PARTITION_CLIENT_RESPONSIVE_EDICTS, shotRay, false, &ragdollEnum );

	return ragdollEnum.Hit();
}
コード例 #22
0
void Bot_UpdateDirection( CPluginBot *pBot )
{
	float angledelta = 15.0;

	int maxtries = (int)360.0/angledelta;

	if ( pBot->m_bLastTurnToRight )
	{
		angledelta = -angledelta;
	}

	QAngle angle( pBot->m_BotInterface->GetLocalAngles() );

	trace_t trace;
	Vector vecSrc, vecEnd, forward;
	while ( --maxtries >= 0 )
	{
		AngleVectors( angle, &forward );

		vecSrc =  pBot->m_BotInterface->GetLocalOrigin() + Vector( 0, 0, 36 ); 
		vecEnd = vecSrc + forward * 10;

		Ray_t ray;
		ray.Init( vecSrc, vecEnd, 	Vector(-16, -16, 0 ), Vector( 16,  16,  72 ) );
		CTraceFilterWorldAndPropsOnly traceFilter;
		enginetrace->TraceRay( ray, MASK_PLAYERSOLID, &traceFilter, &trace );

		if ( trace.fraction == 1.0 )
		{
			if ( gpGlobals->curtime < pBot->m_flNextTurnTime )
			{
				break;
			}
		}

		angle.y += angledelta;

		if ( angle.y > 180 )
			angle.y -= 360;
		else if ( angle.y < -180 )
			angle.y += 360;

		pBot->m_flNextTurnTime = gpGlobals->curtime + 2.0;
		pBot->m_bLastTurnToRight = randomStr->RandomInt( 0, 1 ) == 0 ? true : false;

		pBot->m_ForwardAngle = angle;
		pBot->m_LastAngles = angle;
	}
	
	pBot->m_BotInterface->SetLocalAngles( angle );
}
コード例 #23
0
	IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
	{
		ICollideable *pCollide;
		const char *pDbgName;
		m_pEngineTrace->HandleEntityToCollideable( pHandleEntity, &pCollide, &pDbgName );
		if (!pCollide)
			return ITERATION_CONTINUE;

		// Deal with static props
		// NOTE: I could have added static props to a different list and
		// enumerated them separately, but that would have been less efficient
		if ( StaticPropMgr()->IsStaticProp( pHandleEntity ) )
		{
			Ray_t ray;
			trace_t trace;
			ray.Init( m_Pos, m_Pos );
			m_pEngineTrace->ClipRayToCollideable( ray, MASK_ALL, pCollide, &trace );
			if (trace.startsolid)
			{
				// We're in a static prop; that's solid baby
				// Pretend we hit the world
				m_Contents = CONTENTS_SOLID;
				m_pCollide = m_pEngineTrace->GetWorldCollideable();
				return ITERATION_STOP;
			}
			return ITERATION_CONTINUE;
		}
		
		// We only care about solid volumes
		if ((pCollide->GetSolidFlags() & FSOLID_VOLUME_CONTENTS) == 0)
			return ITERATION_CONTINUE;

		model_t* pModel = (model_t*)pCollide->GetCollisionModel();
		if ( pModel && pModel->type == mod_brush )
		{
			Assert( pCollide->GetCollisionModelIndex() < MAX_MODELS && pCollide->GetCollisionModelIndex() >= 0 );
			int nHeadNode = GetModelHeadNode( pCollide );
			int contents = CM_TransformedPointContents( m_Pos, nHeadNode, 
				pCollide->GetCollisionOrigin(), pCollide->GetCollisionAngles() );

			if (contents != CONTENTS_EMPTY)
			{
				// Return the contents of the first thing we hit
				m_Contents = contents;
				m_pCollide = pCollide;
				return ITERATION_STOP;
			}
		}

		return ITERATION_CONTINUE;
	}
コード例 #24
0
ファイル: Util.cpp プロジェクト: Buxthefag/glow
bool CUtil::IsVisible(void* pLocal, void* pEntity, Vector vStart, Vector vEnd)
{
	trace_t Trace;
	Ray_t Ray;			 // the future of variable naming
	CTraceFilter Filter;

	Filter.pSkip = pLocal;

	Ray.Init(vStart, vEnd);

	gInts.EngineTrace->TraceRay(Ray, MASK_SHOT, &Filter, &Trace);

	return (Trace.m_pEnt == pEntity);
}
コード例 #25
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool Impact( Vector &vecOrigin, Vector &vecStart, int iMaterial, int iDamageType, int iHitbox, int iEntIndex, trace_t &tr, bool bDecal, int maxLODToDecal )
{
	// Clear out the trace
	memset( &tr, 0, sizeof(trace_t));
	tr.fraction = 1.f;

	// Setup our shot information
	Vector shotDir = vecOrigin - vecStart;
	float flLength = VectorNormalize( shotDir );
	Vector traceExt;
	VectorMA( vecStart, flLength + 8.0f, shotDir, traceExt );

	// Attempt to hit ragdolls
	bool bHitRagdoll = AffectRagdolls( vecOrigin, vecStart, iDamageType );

	// Get the entity we hit, according to the server
	C_BaseEntity *pEntity = ClientEntityList().GetEnt( iEntIndex );

	if ( bDecal )
	{
		int decalNumber = decalsystem->GetDecalIndexForName( GetImpactDecal( pEntity, iMaterial, iDamageType ) );
		if ( decalNumber == -1 )
			return false;

		if ( (iEntIndex == 0) && (iHitbox != 0) )
		{
			// Special case for world entity with hitbox (that's a static prop):
			// In this case, we've hit a static prop. Decal it!
			staticpropmgr->AddDecalToStaticProp( vecStart, traceExt, iHitbox - 1, decalNumber, true, tr );
		}
		else if ( pEntity )
		{
			// Here we deal with decals on entities.
			pEntity->AddDecal( vecStart, traceExt, vecOrigin, iHitbox, decalNumber, true, tr, maxLODToDecal );
		}
	}
	else
	{
		// Perform the trace ourselves
		Ray_t ray;
		ray.Init( vecStart, traceExt );
		enginetrace->ClipRayToEntity( ray, MASK_SHOT, pEntity, &tr );
	}

	// If we found the surface, emit debris flecks
	if ( ( tr.fraction == 1.0f ) || ( bHitRagdoll ) )
		return false;

	return true;
}
コード例 #26
0
//-----------------------------------------------------------------------------
// Adds decals to static props, returns point of decal in trace_t
//-----------------------------------------------------------------------------
void CStaticPropMgr::AddDecalToStaticProp( Vector const& rayStart, Vector const& rayEnd,
		int staticPropIndex, int decalIndex, bool doTrace, trace_t& tr )
{
#ifndef SWDS
	// Invalid static prop? Blow it off! 
	if (staticPropIndex >= m_StaticProps.Size())
	{
		memset( &tr, 0, sizeof(trace_t) );
		tr.fraction = 1.0f;
		return;
	}

	Ray_t ray;
	ray.Init( rayStart, rayEnd );
	if (doTrace)
	{
		// Trace the ray against the prop
		TraceRayAgainstStaticProp( ray, staticPropIndex, tr );
		if (tr.fraction == 1.0f)
			return;
	}

	// Get the prop
	CStaticProp& prop = m_StaticProps[staticPropIndex];

	// Found the point, now lets apply the decals
	if (prop.GetModelInstance() == MODEL_INSTANCE_INVALID)
	{
		prop.SetModelInstance( modelrender->CreateInstance( &prop ) );
	}

	// Choose a new ray along which to project the decal based on
	// surface normal. This prevents decal skewing
	bool noPokethru = false;
	if (doTrace && (prop.GetSolid() == SOLID_VPHYSICS) && !tr.startsolid && !tr.allsolid)
	{
		Vector temp;
		VectorSubtract( tr.endpos, tr.plane.normal, temp );
		ray.Init( tr.endpos, temp );
		noPokethru = true;
	}

	// FIXME: Pass in decal up?
	// FIXME: What to do about the body parameter?
	Vector up(0, 0, 1);
	modelrender->AddDecal( prop.GetModelInstance(), ray, up, decalIndex, 0, noPokethru );
#endif
}
コード例 #27
0
//-----------------------------------------------------------------------------
// Sweeps against a particular model, using collision rules 
//-----------------------------------------------------------------------------
void UTIL_TraceModel( const Vector &vecStart, const Vector &vecEnd, const Vector &hullMin, 
					  const Vector &hullMax, CBaseEntity *pentModel, int collisionGroup, trace_t *ptr )
{
	// Cull it....
	if ( pentModel && pentModel->ShouldCollide( collisionGroup, MASK_ALL ) )
	{
		Ray_t ray;
		ray.Init( vecStart, vecEnd, hullMin, hullMax );
		enginetrace->ClipRayToEntity( ray, MASK_ALL, pentModel, ptr ); 
	}
	else
	{
		memset( ptr, 0, sizeof(trace_t) );
		ptr->fraction = 1.0f;
	}
}
コード例 #28
0
static cell_t smn_TRTraceHullFilter(IPluginContext *pContext, const cell_t *params)
{
	cell_t data;
	IPluginFunction *pFunc;
	cell_t *startaddr, *endaddr, *mins, *maxs;

	pFunc = pContext->GetFunctionById(params[6]);
	if (!pFunc)
	{
		return pContext->ThrowNativeError("Invalid function id (%X)", params[5]);
	}

	data = params[7];

	g_SMTraceFilter.SetFunctionPtr(pFunc, data);
	pContext->LocalToPhysAddr(params[1], &startaddr);
	pContext->LocalToPhysAddr(params[2], &endaddr);
	pContext->LocalToPhysAddr(params[3], &mins);
	pContext->LocalToPhysAddr(params[4], &maxs);

	g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
	g_HullMins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2]));
	g_HullMaxs.Init(sp_ctof(maxs[0]), sp_ctof(maxs[1]), sp_ctof(maxs[2]));
	g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));

	g_Ray.Init(g_StartVec, g_EndVec, g_HullMins, g_HullMaxs);
	enginetrace->TraceRay(g_Ray, params[5], &g_SMTraceFilter, &g_Trace);
	g_Trace.UpdateEntRef();

	return 1;
}
コード例 #29
0
static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params)
{
	cell_t *startaddr, *endaddr;
	pContext->LocalToPhysAddr(params[1], &startaddr);
	pContext->LocalToPhysAddr(params[2], &endaddr);

	g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));

	switch (params[4])
	{
	case RayType_EndPoint:
		{
			g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
			break;
		}
	case RayType_Infinite:
		{
			g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2]));
			AngleVectors(g_DirAngles, &g_EndVec);

			/* Make it unitary and get the ending point */
			g_EndVec.NormalizeInPlace();
			g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH;
			break;
		}
	}

	g_Ray.Init(g_StartVec, g_EndVec);
	enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace);
	g_Trace.UpdateEntRef();

	return 1;
}
コード例 #30
0
ファイル: NczPlayer.cpp プロジェクト: kanekikun420/NoCheatZ-3
int NczPlayer::aimingAt()
{
	trace_t trace;
	Ray_t ray;

	edict_t* edict = GetEdict();
	if(!edict) return -1;
	IPlayerInfo* playerinfo = GetPlayerInfo();
	if(!playerinfo) return -1;
	CBotCmd cmd = playerinfo->GetLastUserCommand();

	Vector earPos;
	CIFaceManager::GetInstance()->GetIclients()->ClientEarPosition(edict, &earPos);
	Vector eyePos = earPos;

	QAngle eyeAngles = cmd.viewangles;
	Vector vEnd;
	AngleVectors(eyeAngles, &vEnd);
	vEnd = vEnd * 8192.0f + eyePos;
	
	ray.Init(eyePos,vEnd);
	CIFaceManager::GetInstance()->GetItrace()->TraceRay( ray, (CONTENTS_SOLID | CONTENTS_MOVEABLE | CONTENTS_MONSTER | CONTENTS_DEBRIS | CONTENTS_HITBOX), NULL, &trace );
	
	edict_t* target = CIFaceManager::GetInstance()->GetIents()->BaseEntityToEdict(trace.m_pEnt);
	if ( target && !Helpers::IndexOfEdict(target) == 0 && !trace.allsolid )
	{
		if(!Helpers::isValidEdict(target)) return -1;
#undef GetClassName
		if(strcmp(target->GetClassName(), "player") == 0)
		{
			IPlayerInfo* targetinfo = CIFaceManager::GetInstance()->GetIplayers()->GetPlayerInfo(target);
			if(targetinfo)
			{
				int ta = targetinfo->GetTeamIndex();
				int tb = playerinfo->GetTeamIndex();
				if( ta != tb )
				{
					if( targetinfo->IsPlayer() && !targetinfo->IsHLTV() && !targetinfo->IsObserver() )
					{
						return Helpers::IndexOfEdict(target);
					}
				} 
			}
		}
	}
	return -1;
}