int CPlayer::GetUserId()
{
	if (m_UserId == -1)
	{
		m_UserId = engine->GetPlayerUserId(GetEdict());
	}

	return m_UserId;
}
//-----------------------------------------------------------------------------
// After we built the touch list, deal with all the impacts...
//-----------------------------------------------------------------------------
void CMoveHelperServer::ProcessImpacts( void )
{
	Assert( m_pHostPlayer );

	// Relink in order to build absorigin and absmin/max to reflect any changes
	//  from prediction.  Relink will early out on SOLID_NOT
	engine->RelinkEntity( m_pHostPlayer->pev, true );

	// Don't bother if the player ain't solid
	if ( m_pHostPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
	{
		return;
	}

	// Save off the velocity, cause we need to temporarily reset it
	Vector vel = m_pHostPlayer->GetAbsVelocity();

	// Touch other objects that were intersected during the movement.
	for (int i = 0 ; i < m_TouchList.Size(); i++)
	{
		CBaseHandle entindex = m_TouchList[i].trace.m_pEnt->GetRefEHandle();

		// We should have culled negative indices by now
		Assert( entindex.IsValid() );

		edict_t* ent = GetEdict( entindex );
		if (!ent)
			continue;

		// Run the impact function as if we had run it during movement.
		CBaseEntity *entity = GetContainingEntity( ent );
		if ( !entity )
			continue;

		Assert( entity != m_pHostPlayer );
		// Don't ever collide with self!!!!
		if ( entity == m_pHostPlayer )
			continue;

		// Reconstruct trace results.
		m_TouchList[i].trace.m_pEnt = CBaseEntity::Instance( ent );

		// Use the velocity we had when we collided, so boxes will move, etc.
		m_pHostPlayer->SetAbsVelocity( m_TouchList[i].deltavelocity );
		
		entity->PhysicsImpact( m_pHostPlayer, m_TouchList[i].trace );
	}

	// Restore the velocity
	m_pHostPlayer->SetAbsVelocity( vel );

	// So no stuff is ever left over, sigh...
	ResetTouchList();
}
Beispiel #3
0
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;
}
char const* CMoveHelperServer::GetName( EntityHandle_t handle ) const
{
	// This ain't pertickulerly fast, but it's for debugging anyways
	edict_t* pEdict = GetEdict(handle);
	CBaseEntity *ent = CBaseEntity::Instance( pEdict );
	
	// Is it the world?
	if (ENTINDEX(pEdict) == 0)
		return STRING(gpGlobals->mapname);

	// Is it a model?
	if ( ent && ent->GetModelName() != NULL_STRING )
		return STRING( ent->GetModelName() );

	if ( pEdict->classname != NULL_STRING )
	{
		return STRING( pEdict->classname );
	}

	return "?";
}	
void CAI_Motor::UpdateYaw( int yawSpeed )
{
	float ideal, current, newYaw;
	
	if ( yawSpeed = -1 )
		yawSpeed = GetYawSpeed();
		
	// NOTE: GetIdealYaw() will never exactly be reached because UTIL_AngleMod
	// also truncates the angle to 16 bits of resolution. So lets truncate it here.
	current = UTIL_AngleMod( GetLocalAngles().y );
	ideal = UTIL_AngleMod( GetIdealYaw() );
	
	newYaw = AI_ClampYaw( (float)yawSpeed * 10.0, current, ideal, gpGlobals->curtime - GetLastThink() );
		
	if (newYaw != current)
	{
		QAngle angles = GetLocalAngles();
		angles.y = newYaw;
		SetLocalAngles( angles );

		// ENTITY MUST BE RELINKED to recompute absangles
		engine->RelinkEntity( GetEdict(), false );
	}
}
Beispiel #6
0
int const NczPlayer::aimingAt ()
{
	SourceSdk::CTraceFilterWorldAndPropsOnly filter;

	SourceSdk::edict_t* edict ( GetEdict () );
	if( !edict ) return -1;

	MathInfo const & player_maths ( MathCache::GetInstance ()->RT_GetCachedMaths ( GetIndex () ) );

	SourceSdk::Vector eyePos;
	GetAbsEyePos ( eyePos );

	SourceSdk::Vector vEnd;
	AngleVectors ( player_maths.m_eyeangles, &vEnd );
	VectorMultiply ( vEnd, 8192.0f );
	VectorAdd ( eyePos, vEnd );

	SourceSdk::edict_t* target;
	bool allsolid;
	if( SourceSdk::InterfacesProxy::m_game == SourceSdk::CounterStrikeGlobalOffensive )
	{
		static SourceSdk::CGameTrace_csgo trace;
		static SourceSdk::Ray_t_csgo ray;
		ray.Init ( eyePos, vEnd );
		SourceSdk::InterfacesProxy::Call_TraceRay ( ( void* ) &ray, MASK_VISIBLE | CONTENTS_HITBOX, &filter, ( void* ) &trace );
		target = SourceSdk::InterfacesProxy::Call_BaseEntityToEdict ( trace.m_pEnt );
		allsolid = trace.allsolid;
	}
	else
	{
		static SourceSdk::CGameTrace trace;
		static SourceSdk::Ray_t ray;
		ray.Init ( eyePos, vEnd );
		SourceSdk::InterfacesProxy::Call_TraceRay ( ( void* ) &ray, MASK_VISIBLE | CONTENTS_HITBOX, &filter, ( void* ) &trace );
		target = SourceSdk::InterfacesProxy::Call_BaseEntityToEdict ( trace.m_pEnt );
		allsolid = trace.allsolid;
	}

	if( target && !Helpers::IndexOfEdict ( target ) == 0 && !allsolid )
	{
		if( !Helpers::isValidEdict ( target ) ) return -1;
#undef GetClassName
		if( strcmp ( target->GetClassName (), "player" ) == 0 )
		{
			SourceSdk::IPlayerInfo* const targetinfo ( static_cast< SourceSdk::IPlayerInfo* >( SourceSdk::InterfacesProxy::Call_GetPlayerInfo ( target ) ) );
			if( targetinfo )
			{
				const int ta ( targetinfo->GetTeamIndex () );
				const int tb ( static_cast< SourceSdk::IPlayerInfo* >( SourceSdk::InterfacesProxy::Call_GetPlayerInfo ( edict ) )->GetTeamIndex () );
				if( ta != tb )
				{
					if( targetinfo->IsPlayer () && !targetinfo->IsHLTV () && !targetinfo->IsObserver () )
					{
						return Helpers::IndexOfEdict ( target );
					}
				}
			}
		}
	}
	return -1;
}