Exemplo n.º 1
0
void CPendulum :: PendulumUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if (!ShouldToggle(useType)) return;

	if ( pev->speed )		// Pendulum is moving, stop it and auto-return if necessary
	{
		if ( FBitSet( pev->spawnflags, SF_PENDULUM_AUTO_RETURN ) )
		{		
			float	delta;

			delta = CBaseToggle :: AxisDelta( pev->spawnflags, pev->angles, m_start );

			UTIL_SetAvelocity(this, m_maxSpeed * pev->movedir); //LRC
			//pev->avelocity = m_maxSpeed * pev->movedir;
			SetNextThink(delta / m_maxSpeed);
			SetThink(&CPendulum ::StopThink);
		}
		else
		{
			pev->speed = 0;		// Dead stop
			DontThink();
			UTIL_SetAvelocity(this, g_vecZero); //LRC
			//pev->avelocity = g_vecZero;
		}
	}
	else
	{
		SetNextThink(0.1); // start the pendulum moving
		SetThink(&CPendulum ::SwingThink);
		m_time = gpGlobals->time;		// Save time to calculate dt
		m_dampSpeed = m_maxSpeed;
	}
}
Exemplo n.º 2
0
//
// SpinDown - decelerates a moving func_rotating to a standstill.
//
void CFuncRotating :: SpinDown( void )
{
	SetNextThink( 0.1 );

	m_fCurSpeed = m_fCurSpeed - ( pev->speed * m_flFanFriction );
	UTIL_SetAvelocity(this, pev->movedir * m_fCurSpeed);
	//pev->avelocity = pev->avelocity - ( pev->movedir * ( pev->speed * m_flFanFriction ) );//spin down slower than spinup

	// if we've met or exceeded target speed, set target speed and stop thinking
	if (m_fCurSpeed <= 0)
	{
		m_iState = STATE_OFF;
		m_fCurSpeed = 0;
		UTIL_SetAvelocity(this, g_vecZero);
		//pev->avelocity = g_vecZero;// set speed in case we overshot
		
		// stop sound, we're done
		EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, (char *)STRING(pev->noiseRunning /* Stop */), 
				0, 0, SND_STOP, m_pitch);

		SetThink(&CFuncRotating :: Rotate );
		Rotate();
	} 
	else
	{
		RampPitchVol(FALSE);
	}
}
Exemplo n.º 3
0
//
// SpinUp - accelerates a non-moving func_rotating up to it's speed
//
void CFuncRotating :: SpinUp( void )
{
	//Vector	vecAVel;//rotational velocity

	SetNextThink( 0.1 );
	m_fCurSpeed = m_fCurSpeed + ( pev->speed * m_flFanFriction );
	UTIL_SetAvelocity(this, pev->movedir * m_fCurSpeed);
	//pev->avelocity = pev->avelocity + ( pev->movedir * ( pev->speed * m_flFanFriction ) );

	//vecAVel = pev->avelocity;// cache entity's rotational velocity

	// if we've met or exceeded target speed, set target speed and stop thinking
	if ( m_fCurSpeed >= pev->speed )
	{
		m_iState = STATE_ON;
		m_fCurSpeed = pev->speed;
		UTIL_SetAvelocity(this, pev->movedir * pev->speed);
		//pev->avelocity = pev->movedir * pev->speed;// set speed in case we overshot
		EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, (char *)STRING(pev->noiseRunning), 
			m_flVolume, m_flAttenuation, SND_CHANGE_PITCH | SND_CHANGE_VOL, FANPITCHMAX);
		
		SetThink(&CFuncRotating :: Rotate );
		Rotate();
	} 
	else
	{
		RampPitchVol(TRUE);
	}
}
Exemplo n.º 4
0
void CPendulum :: SwingThink( void )
{
	float delta, dt;
	
	delta = CBaseToggle :: AxisDelta( pev->spawnflags, pev->angles, m_center );
	dt = gpGlobals->time - m_time;	// How much time has passed?
	m_time = gpGlobals->time;		// Remember the last time called

	if ( delta > 0 && m_accel > 0 )
		pev->speed -= m_accel * dt;	// Integrate velocity
	else 
		pev->speed += m_accel * dt;

	if ( pev->speed > m_maxSpeed )
		pev->speed = m_maxSpeed;
	else if ( pev->speed < -m_maxSpeed )
		pev->speed = -m_maxSpeed;

	// scale the destdelta vector by the time spent traveling to get velocity
	UTIL_SetAvelocity(this, pev->speed * pev->movedir); //LRC
	//pev->avelocity = pev->speed * pev->movedir;

//	ALERT(at_console, "m_damp %f, m_dampSpeed %f\n", m_damp, m_dampSpeed);
//	ALERT(at_console, "SwingThink: delta %f, dt %f, speed %f, avel %f %f %f\n", delta, dt, pev->speed, pev->avelocity.x, pev->avelocity.y, pev->avelocity.z);

	// Call this again
	SetNextThink(0.1);
	SetThink(&CPendulum ::SwingThink);

//	if (m_pMoveWith) // correct MoveWith problems associated with fast-thinking entities
//		UTIL_AssignOrigin(this, m_vecMoveWithOffset + m_pMoveWith->pev->origin);

	if ( m_damp )
	{
		m_dampSpeed -= m_damp * m_dampSpeed * dt;
		if ( m_dampSpeed < 30.0 )
		{
			UTIL_SetAngles(this, m_center); //LRC
			//pev->angles = m_center;
			pev->speed = 0;
			ALERT(at_debug, "**CANCELLING pendulum think!\n");
			DontThink();
			UTIL_SetAvelocity(this, g_vecZero); //LRC
			//pev->avelocity = g_vecZero;
		}
		else if ( pev->speed > m_dampSpeed )
			pev->speed = m_dampSpeed;
		else if ( pev->speed < -m_dampSpeed )
			pev->speed = -m_dampSpeed;

	}
}
void CBaseToggle :: AngularMoveNow()
{
//	ALERT(at_console, "AngularMoveNow %f\n", pev->ltime);
	Vector vecDestAngle;

	if (m_pMoveWith)
	    vecDestAngle = m_vecFinalAngle + m_pMoveWith->pev->angles;
	else
	    vecDestAngle = m_vecFinalAngle;

	// Already there?
	if (vecDestAngle == pev->angles)
	{
		AngularMoveDone();
		return;
	}
	
	// set destdelta to the vector needed to move
	Vector vecDestDelta = vecDestAngle - pev->angles;
	
	// divide by speed to get time to reach dest
	float flTravelTime = vecDestDelta.Length() / m_flAngularMoveSpeed;

	// set nextthink to trigger a call to AngularMoveDone when dest is reached
	SetNextThink( flTravelTime, TRUE );
	SetThink(&CBaseToggle :: AngularMoveDone );

	// scale the destdelta vector by the time spent traveling to get velocity
	UTIL_SetAvelocity(this, vecDestDelta / flTravelTime );
}
Exemplo n.º 6
0
//=========================================================
// Rotating Use - when a rotating brush is triggered
//=========================================================
void CFuncRotating :: RotatingUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if (!ShouldToggle(useType)) return;

	// is this a brush that should accelerate and decelerate when turned on/off (fan)?
	if ( FBitSet ( pev->spawnflags, SF_BRUSH_ACCDCC ) )
	{
		// fan is spinning, so stop it.
		if ( m_fCurSpeed != 0 )
//		if ( pev->avelocity != g_vecZero )
		{
			m_iState = STATE_TURN_OFF;
			SetThink(&CFuncRotating :: SpinDown );
			//EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, (char *)STRING(pev->noiseStop), 
			//	m_flVolume, m_flAttenuation, 0, m_pitch);

			SetNextThink( 0.1 );
		}
		else// fan is not moving, so start it
		{
			m_iState = STATE_TURN_ON;
			SetThink(&CFuncRotating :: SpinUp );
			EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, (char *)STRING(pev->noiseRunning), 
				0.01, m_flAttenuation, 0, FANPITCHMIN);

			SetNextThink( 0.1 );
		}
	}
	else // if ( !FBitSet ( pev->spawnflags, SF_BRUSH_ACCDCC ) )//this is a normal start/stop brush.
	{
		if ( m_fCurSpeed != 0 ) //LRC
//		if ( pev->avelocity != g_vecZero )
		{
			m_iState = STATE_OFF;
			// play stopping sound here
			SetThink(&CFuncRotating :: SpinDown );

			// EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, (char *)STRING(pev->noiseStop), 
			//	m_flVolume, m_flAttenuation, 0, m_pitch);
			
			SetNextThink( 0.1 );
			// pev->avelocity = g_vecZero;
		}
		else
		{
			m_iState = STATE_ON;
			EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, (char *)STRING(pev->noiseRunning), 
				m_flVolume, m_flAttenuation, 0, FANPITCHMAX);

			//LRC
			m_fCurSpeed = pev->speed;
			UTIL_SetAvelocity(this, pev->movedir * pev->speed);
//			pev->avelocity = pev->movedir * pev->speed;

			SetThink(&CFuncRotating :: Rotate );
			Rotate();
		}
	}
}
Exemplo n.º 7
0
void CPendulum :: StopThink( void )
{
	UTIL_SetAngles(this, m_start); //LRC
	//pev->angles = m_start;
	pev->speed = 0;
	DontThink();
	UTIL_SetAvelocity(this, g_vecZero); //LRC
	//pev->avelocity = g_vecZero;
}
Exemplo n.º 8
0
void CTriggerCamera::TurnOff( void )
{
	if( m_pGoalEnt ) m_pGoalEnt = m_pGoalEnt->GetPrev();
	UTIL_SetVelocity( this, g_vecZero );
	UTIL_SetAvelocity( this, g_vecZero );
	UpdatePlayerView();
	m_iState = STATE_OFF;
	DontThink();
}
/*
============
After rotating, set angle to exact final angle, call "move done" function
============
*/
void CBaseToggle :: AngularMoveDoneNow( void )
{
//	ALERT(at_console, "AngularMoveDone %f\n", pev->ltime);
	UTIL_SetAvelocity(this, g_vecZero);
	if (m_pMoveWith)
	{
		UTIL_SetAngles(this, m_vecFinalAngle + m_pMoveWith->pev->angles);
	}
	else
	{
		UTIL_SetAngles(this, m_vecFinalAngle);
	}
	DontThink();
	if ( m_pfnCallWhenMoveDone )
		(this->*m_pfnCallWhenMoveDone)();
}
void CBaseDoor::Blocked( CBaseEntity *pOther )
{
	CBaseEntity	*pTarget	= NULL;
	CBaseDoor	*pDoor		= NULL;

//	ALERT(at_debug, "%s blocked\n", STRING(pev->targetname));

	// Hurt the blocker a little.
	if ( pev->dmg )
		if (m_hActivator)
			pOther->TakeDamage( pev, m_hActivator->pev, pev->dmg, DMG_CRUSH );	//AJH Attribute damage to he who switched me.
		else
			pOther->TakeDamage( pev, pev, pev->dmg, DMG_CRUSH );

	// if a door has a negative wait, it would never come back if blocked,
	// so let it just squash the object to death real fast

	if (m_flWait >= 0)
	{
		//LRC - thanks to [insert name here] for this
		if ( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) )
			STOP_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMoving) );
		if (m_toggle_state == TS_GOING_DOWN)
		{
			DoorGoUp();
		}
		else
		{
			DoorGoDown();
		}
	}

	// Block all door pieces with the same targetname here.
	//LRC - in immediate mode don't do this, doors are expected to do it themselves.
	if ( !m_iImmediateMode && !FStringNull ( pev->targetname ) )
	{
		for (;;)
		{
			pTarget = UTIL_FindEntityByTargetname(pTarget, STRING(pev->targetname));

			if ( !pTarget )
				break;

			if ( VARS( pTarget->pev ) != pev && FClassnameIs ( pTarget->pev, "func_door" ) ||
						FClassnameIs ( pTarget->pev, "func_door_rotating" ) )
			{
				pDoor = GetClassPtr( (CBaseDoor *) VARS(pTarget->pev) );
				if ( pDoor->m_flWait >= 0)
				{
					// avelocity == velocity!? LRC
					if (pDoor->pev->velocity == pev->velocity && pDoor->pev->avelocity == pev->velocity)
					{
						// this is the most hacked, evil, bastardized thing I've ever seen. kjb
						if ( FClassnameIs ( pTarget->pev, "func_door" ) )
						{// set origin to realign normal doors
							pDoor->pev->origin = pev->origin;
							UTIL_SetVelocity(pDoor, g_vecZero);// stop!
						}
						else
						{// set angles to realign rotating doors
							pDoor->pev->angles = pev->angles;
							UTIL_SetAvelocity(pDoor, g_vecZero);
						}
					}
					if ( pDoor->m_toggle_state == TS_GOING_DOWN)
						pDoor->DoorGoUp();
					else
						pDoor->DoorGoDown();
				}
			}
		}
	}
}