Пример #1
0
void CBaseButton:: ButtonTouch( CBaseEntity *pOther )
{
	// ignore touches by anything but players
	if( !pOther->IsPlayer( )) return;

	m_hActivator = pOther;

	BUTTON_CODE code = ButtonResponseToTouch();
	if( code == BUTTON_NOTHING ) return;

	if( IsLockedByMaster( ))
	{
		// play button locked sound
		PlayLockSounds( pev, &m_ls, TRUE, TRUE );
		return;
	}

	// temporarily disable the touch function, until movement is finished.
	SetTouch( NULL );

	if( code == BUTTON_RETURN )
	{
		EMIT_SOUND( edict(), CHAN_VOICE, STRING( pev->noise ), 1, ATTN_NORM );
		SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
		ButtonReturn();
	}
	else
	{
		ButtonActivate( );
	}
}
Пример #2
0
void CBaseButton :: ButtonActivate( void )
{
	EMIT_SOUND( edict(), CHAN_VOICE, STRING( pev->noise ), 1, ATTN_NORM );
	
	if( IsLockedByMaster( ))
	{
		// button is locked, play locked sound
		PlayLockSounds( pev, &m_ls, TRUE, TRUE );
		return;
	}
	else
	{
		// button is unlocked, play unlocked sound
		PlayLockSounds( pev, &m_ls, FALSE, TRUE );
	}

	ASSERT( m_iState == STATE_OFF );
	m_iState = STATE_TURN_ON;
	
	if( pev->spawnflags & SF_BUTTON_DONTMOVE )
	{
		TriggerAndWait();
	}
	else
	{
		SetMoveDone( &CBaseButton::TriggerAndWait );

		if( !m_fRotating )
			LinearMove( m_vecPosition2, pev->speed );
		else AngularMove( m_vecAngle2, pev->speed );
	}
}
Пример #3
0
void CFuncConveyor :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator ))
		return;

	if( ShouldToggle( useType ))
	{
		if( useType == USE_SET )
		{
			if( value != 0 ) 
			{
				pev->impulse = value < 0 ? true : false;
				value = fabs( value );
				pev->dmg = bound( 0.1, value, 1 ) * m_flMaxSpeed;
			}
			else UpdateSpeed( 0 ); // stop
			return;
		}
		else if( useType == USE_RESET )
		{
			// restore last speed
			UpdateSpeed( pev->dmg );
			return;
		}
  
		pev->impulse = !pev->impulse;
		UpdateSpeed( m_flMaxSpeed );
	}
}
Пример #4
0
void CBaseDoor::DoorTouch( CBaseEntity *pOther )
{
	if( !FStringNull( m_iChainTarget ))
		ChainTouch( pOther );

	m_bDoorTouched = true;

	// ignore touches by anything but players and pushables
	if( !pOther->IsPlayer() && !pOther->IsPushable()) return;

	m_hActivator = pOther; // remember who activated the door

	// If door has master, and it's not ready to trigger, 
	// play 'locked' sound
	if( IsLockedByMaster( ))
		PlayLockSounds( pev, &m_ls, TRUE, FALSE );
	
	// If door is somebody's target, then touching does nothing.
	// You have to activate the owner (e.g. button).
	// g-cont. but allow touch for chain doors
	if( !FStringNull( pev->targetname ) && FStringNull( m_iChainTarget ))
	{
		// play locked sound
		PlayLockSounds( pev, &m_ls, TRUE, FALSE );
		return; 
	}

	if( DoorActivate( ))
	{
		// temporarily disable the touch function, until movement is finished.
		SetTouch( NULL );
	}
}
Пример #5
0
void CFuncWall :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator ))
		return;

	if( ShouldToggle( useType ))
	{
		if( GetState() == STATE_ON )
			TurnOff();
		else TurnOn();

		// LRC (support generic switchable texlight)
		if( m_iStyle >= 32 )
		{
			if( pev->frame )
				LIGHT_STYLE( m_iStyle, "z" );
			else
				LIGHT_STYLE( m_iStyle, "a" );
		}
		else if( m_iStyle <= -32 )
		{
			if( pev->frame )
				LIGHT_STYLE( -m_iStyle, "a" );
			else
				LIGHT_STYLE( -m_iStyle, "z" );
		}
	}
}
Пример #6
0
void CPendulum :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator ) || m_distance == 0 )
		return;

	if( pev->speed )
	{
		// pendulum is moving, stop it and auto-return if necessary
		if( FBitSet( pev->spawnflags, SF_PENDULUM_AUTO_RETURN ))
		{		
			float delta = CBaseToggle::AxisDelta( pev->spawnflags, GetLocalAngles(), m_start );

			SetLocalAvelocity( m_maxSpeed * pev->movedir );
			SetNextThink( delta / m_maxSpeed );
			SetThink( Stop );
		}
		else
		{
			pev->speed = 0; // dead stop
			SetThink( NULL );
			SetLocalAvelocity( g_vecZero );
			m_iState = STATE_OFF;
		}
	}
	else
	{
		SetNextThink( 0.1f );		// start the pendulum moving
		SetThink( Swing );
		m_time = gpGlobals->time;		// save time to calculate dt
		m_dampSpeed = m_maxSpeed;
	}
}
Пример #7
0
void CMomentaryRotButton :: ButtonUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator )) return;

	// always update target for direct use
	m_bUpdateTarget = true;

	if( useType == USE_SET )
	{
		if( pActivator->IsPlayer( ))
		{
			CBasePlayer *pPlayer = (CBasePlayer *)pActivator;

			if( pPlayer->m_afPhysicsFlags & PFLAG_USING )
				UpdateAllButtons();
			else SetPosition( value );	// just targetting "from player" indirect
		}
		else SetPosition( value );	// not from player
	}
	else if( useType == USE_RESET )
	{
		// stop moving immediately
		UseMoveDone();
	}
}
Пример #8
0
	void FireOnEntry( CBaseEntity *pOther )
	{
		if ( !IsLockedByMaster(pOther))
		{
			UTIL_FireTargets( pev->target, pOther, this, USE_TOGGLE );
			SetThink( Remove );
			SetNextThink( 0 );
		}
	}
void CMomentaryDoor::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if ( useType != USE_SET )		// Momentary buttons will pass down a float in here
		return;

	if ( value > 1.0 )
		value = 1.0;

	if (IsLockedByMaster()) return;

	Vector move = m_vecPosition1 + (value * (m_vecPosition2 - m_vecPosition1));

	float speed = 0;
	Vector delta;

/*	if ((value == 1) || (value == 0))
	{
         		STOP_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMoving));//G-Cont. fix sound bug (original HL).
		return;
	}
*/
	if (pev->speed)
	{
		//LRC- move at the given speed, if any.
		speed = pev->speed;
	}
	else
	{
		// default: get there in 0.1 secs
		delta = move - pev->origin;

		speed = delta.Length() * 10;
	}

	//FIXME: allow for it being told to move at the same speed in the _opposite_ direction!
	if ( speed != 0 )
	{
		// This entity only thinks when it moves
		//LRC- nope, in a MoveWith world you can't rely on that. Check the state instead.
		if ( m_iState == STATE_OFF )
		{
			//ALERT(at_console,"USE: start moving to %f %f %f.\n", move.x, move.y, move.z);
			m_iState = STATE_ON;
			EMIT_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMoving), 1, ATTN_NORM);
		}

		m_fLastPos = value;
		LinearMove( move, speed );
	          //LinearMove( m_vecPosition1, pev->speed, m_fAcceleration, m_fDeceleration);
		SetMoveDone(&CMomentaryDoor:: MomentaryMoveDone );
	}
}
Пример #10
0
void CBaseDoor::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	m_hActivator = pActivator;

	if( !FStringNull( m_iChainTarget ))
		ChainUse( useType, value );

	m_bDoorTouched = false;

	if( IsLockedByMaster( ))
	{
		PlayLockSounds( pev, &m_ls, TRUE, FALSE );
		return;
	}

	if( FBitSet( pev->spawnflags, SF_DOOR_ONOFF_MODE ))
	{
		if( useType == USE_ON )
		{
			if( m_iState == STATE_OFF )
			{
				// door should open
				if( m_hActivator != NULL && m_hActivator->IsPlayer( ))
					m_hActivator->TakeHealth( m_bHealthValue, DMG_GENERIC );

		 		PlayLockSounds( pev, &m_ls, FALSE, FALSE );
		 		DoorGoUp();
			}
			return;
		}
		else if( useType == USE_OFF )
		{
			if( m_iState == STATE_ON )
			{
		         		DoorGoDown();
			}
	         		return;
		}
		else if( useType == USE_SET )
		{
			// change texture
			pev->frame = !pev->frame;
			return;
		}
	}

	// if not ready to be used, ignore "use" command.
	if( m_iState == STATE_OFF || FBitSet( pev->spawnflags, SF_DOOR_NO_AUTO_RETURN ) && m_iState == STATE_ON )
		DoorActivate();
}
Пример #11
0
//=========================================================
// Rotating Use - when a rotating brush is triggered
//=========================================================
void CFuncRotating :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator ))
		return;

	m_bStopAtStartPos = false;

	if( useType == USE_SET )
	{
		if( value != 0 ) 
		{
			// never toggle direction from momentary entities
			if( pCaller && !FClassnameIs( pCaller, "momentary_rot_button" ) && !FClassnameIs( pCaller, "momentary_rot_door" ))
				pev->impulse = (value < 0) ? true : false;
			value = fabs( value );
			SetTargetSpeed( bound( 0, value, 1 ) * m_flMaxSpeed );
		}
		else
		{
			SetTargetSpeed( 0 );
		}
		return;
	}

	// a liitle easter egg
	if( useType == USE_RESET )
	{
		if( value == 0.0f )
		{
			if( m_iState == STATE_OFF )
				pev->impulse = !pev->impulse;
			return;
		}

		if( m_iState == STATE_OFF )
		{
			// apply angular impulse (XashXT feature)
			SetLocalAvelocity( pev->movedir * (bound( -1, value, 1 ) * m_flMaxSpeed ));
			SetMoveDone( RotateFriction );
			pev->friction = 1.0f;
			RotateFriction();
		}
		return;
	}

	if( pev->speed != 0 )
		SetTargetSpeed( 0 );
	else SetTargetSpeed( m_flMaxSpeed );
}
Пример #12
0
void CFuncLight :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	m_hActivator = pActivator;
	
	if( IsLockedByMaster( ))
		return;

	if( m_iState == STATE_DEAD )
		return; // lamp is broken

	if( useType == USE_TOGGLE )
	{
		if( m_iState == STATE_OFF )
			useType = USE_ON;
		else useType = USE_OFF;
	}

	if( useType == USE_ON )
	{
		if( m_flDelay )
		{
			// make flickering delay
			m_iState = STATE_TURN_ON;
			LIGHT_STYLE( m_iStyle, "mmamammmmammamamaaamammma" );
			pev->frame = 0; // light texture is on
			SetThink( Flicker );
			SetNextThink( m_flDelay );
		}
		else
		{         // instant enable
			m_iState = STATE_ON;
			LIGHT_STYLE( m_iStyle, "k" );
			pev->frame = 0; // light texture is on
			UTIL_FireTargets( pev->target, this, this, USE_ON );
		}
	}
	else if( useType == USE_OFF )
	{
		LIGHT_STYLE( m_iStyle, "a" );
		UTIL_FireTargets( pev->target, this, this, USE_OFF );
		pev->frame = 1;// light texture is off
		m_iState = STATE_OFF;
	}
	else if( useType == USE_SET )
	{
		// a script die (dramatic effect)
		Die();
	}
}
Пример #13
0
void CBaseButton::TriggerAndWait( void )
{
	ASSERT( m_iState == STATE_TURN_ON );

	if( IsLockedByMaster( )) return;

	m_iState = STATE_ON;
	
	// if button automatically comes back out, start it moving out.
	// else re-instate touch method
	if( m_fStayPushed || FBitSet( pev->spawnflags, SF_BUTTON_TOGGLE ))
	{ 
		// this button only works if USED, not touched!
		if( !FBitSet( pev->spawnflags, SF_BUTTON_TOUCH_ONLY ))
		{
			// all buttons are now use only
			SetTouch( NULL );
		}
		else
		{
			SetTouch( &CBaseButton::ButtonTouch );
		}
	}
	else
	{
		SetThink( &CBaseButton::ButtonReturn );
		if( m_flWait )
		{
			SetNextThink( m_flWait );
		}
		else
		{
			ButtonReturn();
		}
	}

	// use alternate textures	
	pev->frame = 1;

	SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 );
}
Пример #14
0
BOOL CBaseDoor::DoorActivate( void )
{
	if( IsLockedByMaster( ))
		return 0;

	if( FBitSet(pev->spawnflags, SF_DOOR_NO_AUTO_RETURN ) && m_iState == STATE_ON )
	{
		// door should close
		DoorGoDown();
	}
	else
	{
		// door should open
		if( m_hActivator != NULL && m_hActivator->IsPlayer( ))
			m_hActivator->TakeHealth( m_bHealthValue, DMG_GENERIC );

		// play door unlock sounds
		PlayLockSounds( pev, &m_ls, FALSE, FALSE );
		DoorGoUp();
	}
	return 1;
}
Пример #15
0
	void FireOnEntry( CBaseEntity *pOther )
	{
		if(!IsLockedByMaster(pOther))
			UTIL_FireTargets(pev->target, pOther, this, USE_TOGGLE );
	}
Пример #16
0
	void FireOnLeave( CBaseEntity *pOther )
	{
		if (!IsLockedByMaster(pOther))
			UTIL_FireTargets(pev->netname, pOther, this, USE_TOGGLE );
	}
Пример #17
0
void CBaseTrainDoor :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	m_hActivator = pActivator;

	if( IsLockedByMaster( ))
		return;

	if( m_pTrain )
	{
		if( m_pTrain->GetLocalVelocity() != g_vecZero || m_pTrain->GetLocalAvelocity() != g_vecZero )
		{	
			if( !FBitSet( pev->spawnflags, SF_TRAINDOOR_OPEN_IN_MOVING ))
			{
				// very dangerous open the doors while train is moving :-)
				return;
			}
		}
	}

	if( !FBitSet( pev->spawnflags, SF_TRAINDOOR_OPEN_IN_MOVING ))
	{
		if( useType == USE_SET )
		{
			if( value == 2.0f )
			{
				// start train after door is closing 
				pev->impulse = 1;
			}
			else if( value == 3.0f )
			{
				// start train after door is closing 
				pev->impulse = 2;
			}
		}
	}

	if( FBitSet( pev->spawnflags, SF_TRAINDOOR_ONOFF_MODE ))
          {
		if( useType == USE_ON )
		{
			if( door_state != TD_CLOSED )
				return;
		}
		else if( useType == USE_OFF )
		{
			if( door_state != TD_OPENED )
				return;
		}
          }

	if( door_state == TD_OPENED )
	{
		// door should close
		DoorSlideDown();
	}
	else if( door_state == TD_CLOSED )
	{
		// door should open
		DoorGoUp();
	}
}
Пример #18
0
void CEnvLocal :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if( IsLockedByMaster( pActivator ))
		return;

	m_hActivator = pActivator;
	pev->scale = value;

	if( useType == USE_TOGGLE )
	{
		// set use type
		if( m_iState == STATE_TURN_OFF || m_iState == STATE_OFF )
			useType = USE_ON;
		else if( m_iState == STATE_TURN_ON || m_iState == STATE_ON )
			useType = USE_OFF;
	}

	if( useType == USE_ON )
	{
		// enable entity
		if( m_iState == STATE_TURN_OFF || m_iState == STATE_OFF )
		{
 			if( m_flDelay )
 			{
 				// we have time to turning on
				m_iState = STATE_TURN_ON;
				SetNextThink( m_flDelay );
			}
			else
			{
				// just enable entity
				m_iState = STATE_ON;
				UTIL_FireTargets( pev->target, pActivator, this, USE_ON, pev->scale );
				DontThink(); // break thinking
			}
		}
	}
	else if( useType == USE_OFF )
	{
		// disable entity
		if( m_iState == STATE_TURN_ON || m_iState == STATE_ON ) // activate turning off entity
		{
 			if( m_flWait )
 			{
 				// we have time to turning off
				m_iState = STATE_TURN_OFF;
				SetNextThink( m_flWait );
			}
			else
			{
				// just enable entity
				m_iState = STATE_OFF;
				UTIL_FireTargets( pev->target, pActivator, this, USE_OFF, pev->scale );
				DontThink(); // break thinking
			}
		}
	}
 	else if( useType == USE_SET )
 	{
 		// just set state
 		if( value != 0.0f )
			m_iState = STATE_ON;
		else m_iState = STATE_OFF;
		DontThink(); // break thinking
	}
}
Пример #19
0
void CMomentaryDoor :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	m_hActivator = pActivator;

	if( IsLockedByMaster( pActivator ))
		return;

	if( useType == USE_RESET )
	{
		// stop moving immediately
		MoveDone();
		return;
	}

	float speed = 0.0f;

	// allow on-off mode that simulate standard door
	if( FBitSet( pev->spawnflags, SF_DOOR_ONOFF_MODE ))
	{
		if( useType == USE_ON )
		{
			useType = USE_SET;
			value = 1.0f;
		}
		else if( useType == USE_OFF )
		{
			useType = USE_SET;
			value = 0.0f;
		}
	}

	// momentary buttons will pass down a float in here
	if( useType != USE_SET ) return;

	value = bound( 0.0f, value, 1.0f );
	Vector move = m_vecPosition1 + (value * ( m_vecPosition2 - m_vecPosition1 ));

	// NOTE: historically momentary_door is completely ignore pev->speed
	// and get local speed that based on distance between new and current position
	// with interval 0.1 secs. This flag is allow constant speed like for func_door
	if( FBitSet( pev->spawnflags, SF_DOOR_CONSTANT_SPEED ))
	{
		speed = pev->speed;
	}
	else
	{	
		// classic Valve method to determine speed
		Vector delta = move - GetLocalOrigin();
		speed = delta.Length() * 10;
	}

	if( move != g_vecZero )
	{
		// This entity only thinks when it moves, so if it's thinking, it's in the process of moving
		// play the sound when it starts moving
		if( m_iState == STATE_OFF ) EMIT_SOUND( edict(), CHAN_STATIC, STRING( pev->noise ), 1, ATTN_NORM );

		m_iState = STATE_ON; // we are "in-moving"

		// clear think (that stops sounds)
		SetThink( NULL );

		LinearMove( move, speed );
	}
}