//-----------------------------------------------------------------------------
// Retrives the current skycamera
//-----------------------------------------------------------------------------
CSkyCamera*	GetCurrentSkyCamera()
{
	if (g_hActiveSkybox.Get() == NULL)
	{
		g_hActiveSkybox = GetSkyCameraList();
	}
	return g_hActiveSkybox.Get();
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CGameUI::Deactivate( CBaseEntity *pActivator )
{
	CBasePlayer *pPlayer = m_player;

	AssertMsg(pPlayer, "CGameUI deactivated without a player!");

	if (pPlayer)
	{
		// Re-enable player motion
		if ( FBitSet( m_spawnflags, SF_GAMEUI_FREEZE_PLAYER ) )
		{
			m_player->RemoveFlag( FL_ATCONTROLS );
		}

		// Restore weapons
		if ( FBitSet( m_spawnflags, SF_GAMEUI_HIDE_WEAPON ) )
		{
			// Turn the hud back on
			pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_WEAPONSELECTION;

			if ( m_hSaveWeapon.Get() )
			{
				m_player->Weapon_Switch( m_hSaveWeapon.Get() );
				m_hSaveWeapon = NULL;
			}

			if ( pPlayer->GetActiveWeapon() )
			{
				pPlayer->GetActiveWeapon()->Deploy();
			}
		}

		// Announce that the player is no longer controlling through us
		m_playerOff.FireOutput( pPlayer, this, 0 );

		// Clear out the axis controls
		m_xaxis.Set( 0, pPlayer, this );
		m_yaxis.Set( 0, pPlayer, this );
		m_attackaxis.Set( 0, pPlayer, this );
		m_attack2axis.Set( 0, pPlayer, this );
		m_nLastButtonState = 0;
		m_player = NULL;
	}
	else
	{
		Warning("%s Deactivate(): I have no player when called by %s!\n", GetEntityName().ToCStr(), pActivator->GetEntityName().ToCStr());
	}
	
	// Stop thinking
	SetNextThink( TICK_NEVER_THINK );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
C_BaseCombatCharacter *C_PropCannon::GetPassenger( int nRole )
{
	if ( nRole == VEHICLE_ROLE_DRIVER )
		return m_hPlayer.Get();

	return NULL;
}
//-----------------------------------------------------------------------------
// Returns the role of the passenger
//-----------------------------------------------------------------------------
int	C_PropCannon::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
{
	if ( m_hPlayer.Get() == pPassenger )
		return VEHICLE_ROLE_DRIVER;

	return VEHICLE_ROLE_NONE;
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if our target has moved beyond our length
//-----------------------------------------------------------------------------
void CHarpoon::ConstrainThink( void )
{
	if ( !GetImpaledTarget() || !m_hLinkedHarpoon.Get() )
		return;

	// Moved too far away?
	float flDistSq = m_hLinkedHarpoon->GetAbsOrigin().DistToSqr( GetImpaledTarget()->GetAbsOrigin() ); 
	if ( flDistSq > m_flConstrainLength )
	{
		// Break the rope
		if ( m_hRope )
		{
			m_hRope->DetachPoint(1);
			m_hRope->DieAtNextRest();
			m_hRope = NULL;
		}

		// If we're impaling a player, remove his movement constraint
		if ( GetImpaledTarget()->IsPlayer() )
		{
			CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)GetImpaledTarget();
			pPlayer->DeactivateMovementConstraint();
		}

		SetThink( NULL );
	}
	else
	{
		SetNextThink( gpGlobals->curtime + 0.1f );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
C_BaseCombatCharacter *C_PropVehiclePrisonerPod::GetPassenger( int nRole )
{
	if ( nRole == VEHICLE_ROLE_DRIVER )
		return m_hPlayer.Get();

	return NULL;
}
//-----------------------------------------------------------------------------
// Returns the role of the passenger
//-----------------------------------------------------------------------------
int	C_PropVehiclePrisonerPod::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
{
	if ( m_hPlayer.Get() == pPassenger )
		return VEHICLE_ROLE_DRIVER;

	return VEHICLE_ROLE_NONE;
}
void CPointEntityFinder::FindByRandom( void )
{
	// TODO: optimize the case where there is no filter
	m_hEntity = NULL;
	CBaseFilter *pFilter = m_hFilter.Get();
	CUtlVector<CBaseEntity *> ValidEnts;

	CBaseEntity *pEntity = gEntList.FirstEnt();
	do	   // note all valid entities.
	{
		if ( pFilter &&  pFilter->PassesFilter( this, pEntity ) )
		{
			ValidEnts.AddToTail( pEntity );
		}

		pEntity = gEntList.NextEnt( pEntity );

	} while ( pEntity );

	// pick one at random
	if ( ValidEnts.Count() != 0 )
	{
		m_hEntity = ValidEnts[ RandomInt( 0, ValidEnts.Count() - 1 )];
	}
}
int	C_QUA_Strider::GetPassengerRole( C_BaseCombatCharacter *pEnt )
{
	if (m_hPlayer.Get() == pEnt)
	{
		return VEHICLE_ROLE_DRIVER;
	}
	return -1;
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CGameUI::Deactivate( CBaseEntity *pActivator )
{
	CBasePlayer *pPlayer = m_player;

	// If deactivated by the player using me
	if ( pPlayer == pActivator )
	{
		// Re-enable player motion
		if (FBitSet(m_spawnflags, SF_GAMEUI_FREEZE_PLAYER))
		{
			m_player->RemoveFlag( FL_ATCONTROLS );
		}

		// Restore weapons
		if (FBitSet(m_spawnflags, SF_GAMEUI_HIDE_WEAPON))
		{
			// Turn the hud back on
			pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_WEAPONS;

			if (m_hSaveWeapon.Get())
			{
				m_player->Weapon_Switch( m_hSaveWeapon.Get() );
				m_hSaveWeapon = NULL;
			}

			if ( pPlayer->GetActiveWeapon() )
			{
				pPlayer->GetActiveWeapon()->Deploy();
			}
		}

		m_playerOff.FireOutput( pPlayer, this, 0 );

		// clear out the axis controls
		m_xaxis.Set( 0, pPlayer, this );
		m_yaxis.Set( 0, pPlayer, this );
		m_attackaxis.Set( 0, pPlayer, this );
		m_attack2axis.Set( 0, pPlayer, this );

		m_player = NULL;
		SetNextThink( TICK_NEVER_THINK );
	}
}
Exemple #11
0
bool CFuncVPhysicsClip::EntityPassesFilter( CBaseEntity *pOther )
{
	CBaseFilter* pFilter = (CBaseFilter*)(m_hFilter.Get());

	if ( pFilter )
		return pFilter->PassesFilter( this, pOther );

	if ( pOther->GetMoveType() == MOVETYPE_VPHYSICS && pOther->VPhysicsGetObject()->IsMoveable() )
		return true;
	
	return false;
}
bool CPhysicsNPCSolver::CheckTouching()
{
	CAI_BaseNPC *pNPC = m_hNPC.Get();
	if ( !pNPC )
		return false;

	CBaseEntity *pPhysicsEnt = m_hEntity.Get();
	if ( !pPhysicsEnt )
		return false;

	IPhysicsObject *pPhysics = pPhysicsEnt->VPhysicsGetObject();
	IPhysicsObject *pNPCPhysics = pNPC->VPhysicsGetObject();
	if ( !pNPCPhysics || !pPhysics )
		return false;

	IPhysicsFrictionSnapshot *pSnapshot = pPhysics->CreateFrictionSnapshot();
	bool found = false;
	bool penetrate = false;

	while ( pSnapshot->IsValid() )
	{
		IPhysicsObject *pOther = pSnapshot->GetObject(1);
		if ( pOther == pNPCPhysics )
		{
			found = true;
			if ( IsContactOnNPCHead(pSnapshot, pPhysics, pNPC ) )
			{
				penetrate = true;
				pSnapshot->MarkContactForDelete();
			}
			break;
		}
		pSnapshot->NextFrictionData();
	}
	pSnapshot->DeleteAllMarkedContacts( true );
	pPhysics->DestroyFrictionSnapshot( pSnapshot );

	// if the object is penetrating something, check to see if it's intersecting this NPC
	// if so, go ahead and switch over to penetration solver mode
	if ( !penetrate && (pPhysics->GetGameFlags() & FVPHYSICS_PENETRATING) )
	{
		penetrate = IsIntersecting();
	}

	if ( penetrate )
	{
		pPhysicsEnt->ClearNavIgnore();
		BecomePenetrationSolver();
	}

	return found;
}
//------------------------------------------------------------------------------
// Purpose :
//------------------------------------------------------------------------------
void CGameUI::InputActivate( inputdata_t &inputdata )
{
	// If already in use, ignore activatation by others
	if (( m_player.Get() != NULL ) && ( m_player.Get() != inputdata.pActivator ))
	{
		return;
	}

	if ( inputdata.pActivator && inputdata.pActivator->IsPlayer() )
	{
		m_player = (CBasePlayer *)inputdata.pActivator;
		m_playerOn.FireOutput( inputdata.pActivator, this, 0 );

		// Turn the hud off
		SetNextThink( gpGlobals->curtime );

		// Disable player motion
		if (FBitSet(m_spawnflags, SF_GAMEUI_FREEZE_PLAYER))
		{
			m_player->AddFlag( FL_ATCONTROLS );
		}

		if (FBitSet(m_spawnflags, SF_GAMEUI_HIDE_WEAPON))
		{
			m_player->m_Local.m_iHideHUD |= HIDEHUD_WEAPONS;

			if ( m_player->GetActiveWeapon() )
			{
				m_hSaveWeapon = m_player->GetActiveWeapon();

				m_player->GetActiveWeapon()->Holster();
				m_player->ClearActiveWeapon();
				m_player->HideViewModels();
			}
		}
	}

	m_bForceUpdate = true;
}
//-----------------------------------------------------------------------------
// Purpose: The act has finished
//-----------------------------------------------------------------------------
void CInfoAct::FinishAct( )
{
	if ( g_hCurrentAct.Get() != this )
	{
		DevWarning( 2, "Attempted to finish an act which wasn't started!\n" );
		return;
	}

	ShutdownRespawnTimers();

	switch( m_iWinners)
	{
	case 0:
		m_OnFinishedTeamNone.FireOutput( this, this );
		break;

	case 1:
		m_OnFinishedTeam1.FireOutput( this, this );
		break;

	case 2:
		m_OnFinishedTeam2.FireOutput( this, this );
		break;

	default:
		Assert(0);
		break;
	}

	g_hCurrentAct = NULL;

	// Tell all the clients
	CRelieableBroadcastRecipientFilter filter;
	UserMessageBegin( filter, "ActEnd" );
		WRITE_BYTE( m_iWinners );
	MessageEnd();

	// Am I an intermission?
	if ( HasSpawnFlags( SF_ACT_INTERMISSION ) )
	{
		// Cycle through all players and end the intermission for them
		for ( int i = 1; i <= gpGlobals->maxClients; i++ )
		{
			CBaseTFPlayer *pPlayer = (CBaseTFPlayer*)UTIL_PlayerByIndex( i );
			if ( pPlayer  )
			{
				EndIntermission( pPlayer );
			}
		}
	}
}
Exemple #15
0
//-----------------------------------------------------------------------------
// Creates the efficient spotlight 
//-----------------------------------------------------------------------------
void CPointSpotlight::CreateEfficientSpotlight()
{
	if ( m_hSpotlightTarget.Get() != NULL )
		return;

	SpotlightCreate();
	m_vSpotlightCurrentPos = SpotlightCurrentPos();
	m_hSpotlightTarget->SetAbsOrigin( m_vSpotlightCurrentPos );
	m_hSpotlightTarget->m_vSpotlightOrg = GetAbsOrigin();
	VectorSubtract( m_hSpotlightTarget->GetAbsOrigin(), m_hSpotlightTarget->m_vSpotlightOrg, m_hSpotlightTarget->m_vSpotlightDir );
	m_flSpotlightCurLength = VectorNormalize( m_hSpotlightTarget->m_vSpotlightDir );
	m_hSpotlightTarget->SetMoveType( MOVETYPE_NONE );
	ComputeRenderInfo();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void COrder::SetOwner( CBaseTFPlayer *pPlayer )
{
	// Null out our m_hOwningPlayer so we don't recurse infinitely.
	CHandle<CBaseTFPlayer> hPlayer = m_hOwningPlayer;
	m_hOwningPlayer = 0;

	if ( hPlayer.Get() && (hPlayer != pPlayer) )
	{
		Assert( hPlayer->GetOrder() == this );
		hPlayer->SetOrder( NULL );	
	}
	
	m_hOwningPlayer = pPlayer;
}
	// The test runs this command.
	void CC_Test_EHandle()
	{
		if ( g_HandleTest.Get() )
		{
			g_HandleTest->m_bSendHandle = !g_HandleTest->m_bSendHandle;
		}
		else
		{
			CHandleTest *pHolder = CREATE_ENTITY( CHandleTest, "handle_test" );
			pHolder->m_Handle = CREATE_ENTITY( CHandleDummy, "handle_dummy" );
			pHolder->Spawn();
			g_HandleTest = pHolder;
			Msg( "Created EHANDLE test entity. Run this command again to transmit the second ent.\n" );
		}
	}
//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CPointSpotlight::SpotlightCreate(void)
{
	if ( m_hSpotlightTarget.Get() != NULL )
		return;

	AngleVectors( GetAbsAngles(), &m_vSpotlightDir );

	trace_t tr;
	UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + m_vSpotlightDir * m_flSpotlightMaxLength, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);

	m_hSpotlightTarget = (CSpotlightEnd*)CreateEntityByName( "spotlight_end" );
	m_hSpotlightTarget->Spawn();
	m_hSpotlightTarget->SetAbsOrigin( tr.endpos );
	m_hSpotlightTarget->SetOwnerEntity( this );
	m_hSpotlightTarget->m_clrRender = m_clrRender;
	m_hSpotlightTarget->m_Radius = m_flSpotlightMaxLength;

	if ( FBitSet (m_spawnflags, SF_SPOTLIGHT_NO_DYNAMIC_LIGHT) )
	{
		m_hSpotlightTarget->m_flLightScale = 0.0;
	}

	//m_hSpotlight = CBeam::BeamCreate( "sprites/spotlight.vmt", m_flSpotlightGoalWidth );
	m_hSpotlight = CBeam::BeamCreate( "sprites/glow_test02.vmt", m_flSpotlightGoalWidth );
	// Set the temporary spawnflag on the beam so it doesn't save (we'll recreate it on restore)
	m_hSpotlight->SetHDRColorScale( m_flHDRColorScale );
	m_hSpotlight->AddSpawnFlags( SF_BEAM_TEMPORARY );
	m_hSpotlight->SetColor( m_clrRender->r, m_clrRender->g, m_clrRender->b ); 
	m_hSpotlight->SetHaloTexture(m_nHaloSprite);
	m_hSpotlight->SetHaloScale(60);
	m_hSpotlight->SetEndWidth(m_flSpotlightGoalWidth);
	m_hSpotlight->SetBeamFlags( (FBEAM_SHADEOUT|FBEAM_NOTILE) );
	m_hSpotlight->SetBrightness( 64 );
	m_hSpotlight->SetNoise( 0 );
	m_hSpotlight->SetMinDXLevel( m_nMinDXLevel );

	if ( m_bEfficientSpotlight )
	{
		m_hSpotlight->PointsInit( GetAbsOrigin(), m_hSpotlightTarget->GetAbsOrigin() );
	}
	else
	{
		m_hSpotlight->EntsInit( this, m_hSpotlightTarget );
	}
}
bool CPhysicsNPCSolver::IsIntersecting()
{
	CAI_BaseNPC *pNPC = m_hNPC.Get();
	CBaseEntity *pPhysics = m_hEntity.Get();
	if ( pNPC && pPhysics )
	{
		Ray_t ray;
		// bloated bounds to force slight separation
		Vector mins = pNPC->WorldAlignMins() - Vector(1,1,1);
		Vector maxs = pNPC->WorldAlignMaxs() + Vector(1,1,1);

		ray.Init( pNPC->GetAbsOrigin(), pNPC->GetAbsOrigin(), mins, maxs );
		trace_t tr;
		enginetrace->ClipRayToEntity( ray, pNPC->PhysicsSolidMaskForEntity(), pPhysics, &tr );
		if ( tr.startsolid )
			return true;
	}
	return false;
}
//-----------------------------------------------------------------------------
// Purpose: Give the harpoon a yank
//-----------------------------------------------------------------------------
void CWeaponHarpoon::YankHarpoon( void )
{
	CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
	if ( !pPlayer )
		return;

#if !defined( CLIENT_DLL )
	if ( m_bActiveHarpoon && m_hHarpoon.Get() )
	{
		// If the harpoon's impaled something, pull it towards me
		CBaseEntity *pTarget = m_hHarpoon->GetImpaledTarget();
		if ( pTarget )
		{
			if ( !pTarget->IsBSPModel() && pTarget->GetMoveType() != MOVETYPE_NONE )
			{
				// Bring him to me!
				EmitSound( "Harpoon.Yank" );

				// Get a yank vector, and raise it a little to get them off the ground if they're on it
				Vector vecOverHere = ( pPlayer->GetAbsOrigin() - pTarget->GetAbsOrigin() );
				VectorNormalize( vecOverHere );
				if ( pTarget->GetFlags() & FL_ONGROUND )
				{
					pTarget->SetGroundEntity( NULL );
					vecOverHere.z = 0.5;
				}
				pTarget->ApplyAbsVelocityImpulse( vecOverHere * 500 );

				PlayAttackAnimation( ACT_VM_HAULBACK );
			}
		}
		m_hHarpoon->SetThink( SUB_Remove );
		m_hHarpoon->SetNextThink( gpGlobals->curtime + 5.0 );
		m_hHarpoon = NULL;
		m_bActiveHarpoon = false;
	}

	DetachRope();
#endif
}
Exemple #21
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEnvLaserDesignation::GetLaserDesignation( int iTeamNumber, int iDesignator, Vector *vecOrigin )
{
    Assert( iTeamNumber > 0 && iTeamNumber <= MAX_TF_TEAMS );

    CHandle<CEnvLaserDesignation> hLaser;
    if ( iTeamNumber == 1 )
    {
        Assert( iDesignator < m_LaserDesignatorsTeam1.Count() );
        hLaser = m_LaserDesignatorsTeam1[iDesignator];
    }
    else
    {
        Assert( iDesignator < m_LaserDesignatorsTeam2.Count() );
        hLaser = m_LaserDesignatorsTeam2[iDesignator];
    }

    // Active?
    if ( !hLaser.Get() || !hLaser->IsActive() )
        return false;

    *vecOrigin = hLaser->GetAbsOrigin();
    return true;
}
void CPointEntityFinder::FindByDistance( void )
{
	m_hEntity = NULL;
	CBaseFilter *pFilter = m_hFilter.Get();

// go through each entity and determine whether it's closer or farther from the current entity.  Pick according to Method selected.

	float flBestDist = 0;
	CBaseEntity *pEntity = gEntList.FirstEnt();
	while ( pEntity )
	{
		if ( FStrEq( STRING( pEntity->m_iClassname ), "worldspawn" ) 
			|| FStrEq( STRING( pEntity->m_iClassname ), "soundent" ) 
			|| FStrEq( STRING( pEntity->m_iClassname ), "player_manager" ) 
			|| FStrEq( STRING( pEntity->m_iClassname ), "bodyque" ) 
			|| FStrEq( STRING( pEntity->m_iClassname ), "ai_network" ) 
			|| pEntity == this
			|| ( pFilter && !( pFilter->PassesFilter( this, pEntity ) ) ) )	   
		{
			pEntity = gEntList.NextEnt( pEntity );
			continue;
		}

		// if we have a reference entity, use that, otherwise, check against 'this'
		Vector vecStart;
		if ( m_hReference )
		{
			vecStart = m_hReference->GetAbsOrigin();
		}
		else
		{
			vecStart = GetAbsOrigin();
		}

		// init m_hEntity with a valid entity.
		if (m_hEntity == NULL )
		{
			m_hEntity = pEntity;
			flBestDist = ( pEntity->GetAbsOrigin() - vecStart ).LengthSqr();
		}

		float flNewDist = ( pEntity->GetAbsOrigin() - vecStart ).LengthSqr();

		switch ( m_FindMethod )
		{

		case ( ENT_FIND_METHOD_NEAREST ):
			if ( flNewDist < flBestDist )
			{
				m_hEntity = pEntity;
				flBestDist = flNewDist;
			}
			break;

		case ( ENT_FIND_METHOD_FARTHEST ):
			if ( flNewDist > flBestDist )
			{
				m_hEntity = pEntity;
				flBestDist = flNewDist;
			}
			break;

		default:
			Assert( false );
			break;
		}

		pEntity = gEntList.NextEnt( pEntity );
	}
}
Exemple #23
0
//------------------------------------------------------------------------------
// Purpose :
//------------------------------------------------------------------------------
void CGameUI::InputActivate( inputdata_t &inputdata )
{
	CBasePlayer *pPlayer;

	// Determine if we're specifying this as an override parameter
	if ( inputdata.value.StringID() != NULL_STRING )
	{
		CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller );
		if ( pEntity == NULL || pEntity->IsPlayer() == false )
		{
			Warning( "%s InputActivate: entity %s not found or is not a player!\n", STRING(GetEntityName()), inputdata.value.String() );
			return;
		}

		pPlayer = ToBasePlayer( pEntity );
	}
	else
	{
		// Otherwise try to use the activator
		if ( inputdata.pActivator == NULL || inputdata.pActivator->IsPlayer() == false )
		{
			Warning( "%s InputActivate: invalid or missing !activator!\n", STRING(GetEntityName()), inputdata.value.String() );
			return;
		}

		pPlayer = ToBasePlayer( inputdata.pActivator );
	}

	// If another player is already using these controls3, ignore this activation
	if ( m_player.Get() != NULL && pPlayer != m_player.Get() )
	{
		// TODO: We could allow this by calling Deactivate() at this point and continuing on -- jdw
		return;
	}

	// Setup our internal data
	m_player = pPlayer;
	m_playerOn.FireOutput( pPlayer, this, 0 );

	// Turn the hud off
	SetNextThink( gpGlobals->curtime );

	// Disable player's motion
	if ( FBitSet( m_spawnflags, SF_GAMEUI_FREEZE_PLAYER ) )
	{
		m_player->AddFlag( FL_ATCONTROLS );
	}

	// Store off and hide the currently held weapon
	if ( FBitSet( m_spawnflags, SF_GAMEUI_HIDE_WEAPON ) )
	{
		m_player->m_Local.m_iHideHUD |= HIDEHUD_WEAPONSELECTION;

		if ( m_player->GetActiveWeapon() )
		{
			m_hSaveWeapon = m_player->GetActiveWeapon();

			m_player->GetActiveWeapon()->Holster();
			m_player->ClearActiveWeapon();
			m_player->HideViewModels();
		}
	}

	// We must update our state
	m_bForceUpdate = true;
}