void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { m_hActivator = pActivator; if (pActivator && pActivator->pev->flags & FL_CLIENT); else pActivator = UTIL_PlayerByIndex( 1 ); if (useType == USE_TOGGLE) { if(m_iState == STATE_ON) useType = USE_OFF; else useType = USE_ON; } if (useType == USE_ON) { ((CBasePlayer *)((CBaseEntity *)pActivator))->EnableControl(FALSE); m_iState = STATE_ON; if(m_flDelay) SetNextThink( m_flDelay ); } else if(useType == USE_OFF) { ((CBasePlayer *)((CBaseEntity *)pActivator))->EnableControl(TRUE); m_iState = STATE_OFF; DontThink(); } else if(useType == USE_SHOWINFO) { DEBUGHEAD; } }
void CFuncShine :: TurnOff ( void ) { ALERT(at_console, "CFuncShine :: TurnOff\n"); SendData(); ALERT(at_console, "CFuncShine :: DontThink();\n"); DontThink(); }
void CItem::Materialize( void ) { if ( pev->effects & EF_NODRAW ) { // changing from invisible state to visible. pev->effects &= ~EF_NODRAW; pev->renderfx = kRenderFxGlowShell; pev->renderamt = 40; pev->frags = 0; pev->rendercolor.x = RANDOM_LONG(25, 255); pev->rendercolor.y = RANDOM_LONG(25, 255); pev->rendercolor.z = RANDOM_LONG(25, 255); pev->scale = 0.01; SetNextThink (0.001); } if( pev->scale > 1.2 ) pev->frags = 1; if ( pev->frags == 1 ) { //set effects for respawn item if(pev->scale > 1.0) pev->scale -= 0.05; else { pev->renderfx = kRenderFxNone; pev->frags = 0; SetTouch( ItemTouch ); EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, "items/respawn.wav", 1, ATTN_NORM, 0, 150 ); SetThink( NULL ); DontThink(); } } else pev->scale += 0.05; SetNextThink (0.001); }
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; } }
void CParticleEmitter :: TurnOff ( void ) { ALERT(at_console, "CParticleEmitter :: TurnOff Call Treated as MakeAware\n"); // increment the count just in case iID = ++iParticleIDCount; // lets give them everything if ( CVAR_GET_FLOAT("r_particles" ) != 0 ) { MESSAGE_BEGIN(MSG_ALL, gmsgParticles);//enviar a todos... qué importa?? WRITE_SHORT(iID); WRITE_BYTE(0); WRITE_COORD(pev->origin.x); WRITE_COORD(pev->origin.y); WRITE_COORD(pev->origin.z); WRITE_COORD(pev->angles.x); WRITE_COORD(pev->angles.y); WRITE_COORD(pev->angles.z); WRITE_SHORT(0); WRITE_STRING(STRING(pev->message)); WRITE_STRING(sParticleDefintionFile); MESSAGE_END(); } ALERT(at_console, "CParticleEmitter :: DontThink();\n"); DontThink(); }
void CFuncLight :: Flicker( void ) { if( m_iState == STATE_TURN_ON ) { LIGHT_STYLE( m_iStyle, "k" ); UTIL_FireTargets( pev->target, this, this, USE_ON ); m_iState = STATE_ON; DontThink(); return; } if( m_iFlickerMode == 1 ) { pev->frame = 1; LIGHT_STYLE( m_iStyle, "a" ); SetThink( NULL ); return; } if( m_iFlickerMode == 2 ) { switch( RANDOM_LONG( 0, 3 )) { case 0: LIGHT_STYLE( m_iStyle, "abcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ); break; case 1: LIGHT_STYLE( m_iStyle, "acaaabaaaaaaaaaaaaaaaaaaaaaaaaaaa" ); break; case 2: LIGHT_STYLE( m_iStyle, "aaafbaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ); break; case 3: LIGHT_STYLE( m_iStyle, "aaaaaaaaaaaaagaaaaaaaaacaaaacaaaa" ); break; } m_flNextFlickerTime = RANDOM_FLOAT( 0.5f, 10.0f ); UTIL_Sparks( m_vecLastDmgPoint ); switch( RANDOM_LONG( 0, 2 )) { case 0: EMIT_SOUND( edict(), CHAN_VOICE, "buttons/spark1.wav", 0.4, ATTN_IDLE ); break; case 1: EMIT_SOUND( edict(), CHAN_VOICE, "buttons/spark2.wav", 0.3, ATTN_IDLE ); break; case 2: EMIT_SOUND( edict(), CHAN_VOICE, "buttons/spark3.wav", 0.35, ATTN_IDLE ); break; } if( m_flNextFlickerTime > 6.5f ) m_iFlickerMode = 1; // stop sparking } SetNextThink( m_flNextFlickerTime ); }
void CBaseTrigger :: Update( void ) { // Prune handles all Intersects tests and fires targets as appropriate m_pRegister = m_pRegister->Prune(); if (m_pRegister->IsEmpty()) DontThink(); else SetNextThink( 0.1 ); }
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; }
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(); }
// // The door has reached the "up" position. Either go back down, or wait for another activation. // void CBaseDoor::DoorHitTop( void ) { if ( !FBitSet( pev->spawnflags, SF_DOOR_SILENT ) ) { STOP_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMoving) ); EMIT_SOUND(ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseArrived), 1, ATTN_NORM); } // ALERT(at_debug, "%s hit top\n", STRING(pev->targetname)); ASSERT(m_toggle_state == TS_GOING_UP); m_toggle_state = TS_AT_TOP; // toggle-doors don't come down automatically, they wait for refire. if (FBitSet(pev->spawnflags, SF_DOOR_NO_AUTO_RETURN)) { // Re-instate touch method, movement is complete if ( !FBitSet ( pev->spawnflags, SF_DOOR_USE_ONLY ) || FBitSet ( pev->spawnflags, SF_DOOR_FORCETOUCHABLE ) ) SetTouch(&CBaseDoor:: DoorTouch ); } else { // In flWait seconds, DoorGoDown will fire, unless wait is -1, then door stays open SetNextThink( m_flWait ); SetThink(&CBaseDoor:: DoorGoDown ); if ( m_flWait == -1 ) { DontThink(); } } // Fire the close target (if startopen is set, then "top" is closed) - netname is the close target if (pev->spawnflags & SF_DOOR_START_OPEN) { if (pev->netname) FireTargets( STRING(pev->netname), m_hActivator, this, USE_TOGGLE, 0 ); } else { if (pev->message) FireTargets( STRING(pev->message), m_hActivator, this, USE_TOGGLE, 0 ); } // LRC if (!m_iImmediateMode) { if (m_iOnOffMode) SUB_UseTargets( m_hActivator, USE_OFF, 0 ); else SUB_UseTargets( m_hActivator, USE_TOGGLE, 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 CBaseButton::ButtonBackHome( void ) { ASSERT( m_iState == STATE_TURN_OFF ); m_iState = STATE_OFF; if( FBitSet( pev->spawnflags, SF_BUTTON_TOGGLE )) { SUB_UseTargets( m_hActivator, USE_TOGGLE, 0 ); } if( !FStringNull( pev->target )) { CBaseEntity *pTarget = NULL; while( 1 ) { pTarget = UTIL_FindEntityByTargetname( pTarget, STRING( pev->target )); if( FNullEnt( pTarget )) break; if( !FClassnameIs( pTarget->pev, "multisource" )) continue; pTarget->Use( m_hActivator, this, USE_TOGGLE, 0 ); } } // Re-instate touch method, movement cycle is complete. // 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 ); } // reset think for a sparking button if( FBitSet( pev->spawnflags, SF_BUTTON_SPARK_IF_OFF )) { SetThink( &CBaseButton::ButtonSpark ); SetNextThink( 0.5 ); } else { DontThink(); } }
void CFuncLight :: Die( void ) { // lamp is random choose die style if( m_iState == STATE_OFF ) { pev->frame = 1; // light texture is off LIGHT_STYLE( m_iStyle, "a" ); DontThink(); } else { // simple randomization m_iFlickerMode = RANDOM_LONG( 1, 2 ); SetThink( Flicker ); SetNextThink( 0.1f + RANDOM_LONG( 0.1f, 0.2f )); } m_iState = STATE_DEAD; pev->health = 0; pev->takedamage = DAMAGE_NO; UTIL_FireTargets( pev->target, this, this, USE_OFF ); switch( RANDOM_LONG( 0, 1 )) { case 0: EMIT_SOUND( edict(), CHAN_VOICE, "debris/bustglass1.wav", 0.7, ATTN_IDLE ); break; case 1: EMIT_SOUND( edict(), CHAN_VOICE, "debris/bustglass2.wav", 0.8, ATTN_IDLE ); break; } Vector vecSpot = GetAbsOrigin() + (pev->mins + pev->maxs) * 0.5f; MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_BREAKMODEL ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z ); WRITE_COORD( pev->size.x ); WRITE_COORD( pev->size.y ); WRITE_COORD( pev->size.z ); WRITE_COORD( 0 ); WRITE_COORD( 0 ); WRITE_COORD( 0 ); WRITE_BYTE( 10 ); WRITE_SHORT( m_idShard ); WRITE_BYTE( 0 ); WRITE_BYTE( 25 ); WRITE_BYTE( BREAK_GLASS ); MESSAGE_END(); }
void CEnvLocal :: Think( void ) { if( m_iState == STATE_TURN_ON ) { m_iState = STATE_ON; UTIL_FireTargets( pev->target, m_hActivator, this, USE_ON, pev->scale ); } else if( m_iState == STATE_TURN_OFF ) { m_iState = STATE_OFF; UTIL_FireTargets( pev->target, m_hActivator, this, USE_OFF, pev->scale ); } DontThink(); // break thinking }
/* ============ 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 CTriggerHurt :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { if (useType == USE_TOGGLE) { if(m_iState) useType = USE_OFF; else useType = USE_ON; } if (useType == USE_ON) { pev->solid = SOLID_TRIGGER; gpGlobals->force_retouch++; UTIL_SetOrigin( this, pev->origin ); if (pev->button & DMG_RADIATION) SetNextThink( RANDOM_FLOAT(0.0, 0.5) ); m_iState = STATE_ON; } else if (useType == USE_OFF) { pev->solid = SOLID_NOT; UTIL_SetOrigin( this, pev->origin ); if (pev->button & DMG_RADIATION) DontThink(); m_iState = STATE_OFF; } else if (useType == USE_SET) { pev->dmg = value;//set dmg level } else if (useType == USE_RESET) { pev->dmg = 0;//reset dmg level } else if (useType == USE_SHOWINFO) { DEBUGHEAD; ALERT( at_console, "State: %s, Dmg value %g\n", GetStringForState( GetState()), pev->dmg ); PrintStringForDamage( pev->button ); } }
void CBaseToggle :: LinearMoveDoneNow( void ) { Vector vecDest; // ALERT(at_console, "LMDone %s\n", STRING(pev->targetname)); UTIL_SetVelocity(this, g_vecZero);//, TRUE); // pev->velocity = g_vecZero; if (m_pMoveWith) { vecDest = m_vecFinalDest + m_pMoveWith->pev->origin; // ALERT(at_console, "LMDone %s: p.origin = %f %f %f, origin = %f %f %f. Set it to %f %f %f\n", STRING(pev->targetname), m_pMoveWith->pev->origin.x, m_pMoveWith->pev->origin.y, m_pMoveWith->pev->origin.z, pev->origin.x, pev->origin.y, pev->origin.z, vecDest.x, vecDest.y, vecDest.z); } else { vecDest = m_vecFinalDest; // ALERT(at_console, "LMDone %s: origin = %f %f %f. Set it to %f %f %f\n", STRING(pev->targetname), pev->origin.x, pev->origin.y, pev->origin.z, vecDest.x, vecDest.y, vecDest.z); } UTIL_AssignOrigin(this, vecDest); DontThink(); //LRC //pev->nextthink = -1; if ( m_pfnCallWhenMoveDone ) (this->*m_pfnCallWhenMoveDone)(); }
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 } }
// // ambient_generic - general-purpose user-defined static sound // void CAmbientGeneric :: Spawn( void ) { /* -1 : "Default" 0 : "Everywhere" 200 : "Small Radius" 125 : "Medium Radius" 80 : "Large Radius" */ if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_EVERYWHERE) ) { m_flAttenuation = ATTN_NONE; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_SMALLRADIUS) ) { m_flAttenuation = ATTN_IDLE; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_MEDIUMRADIUS) ) { m_flAttenuation = ATTN_STATIC; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_LARGERADIUS) ) { m_flAttenuation = ATTN_NORM; } else {// if the designer didn't set a sound attenuation, default to one. m_flAttenuation = ATTN_STATIC; } if( !pev->health ) pev->health = 10; // just get full volume char* szSoundFile = (char*) STRING(pev->message); if ( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) { ALERT( at_error, "ambient_generic \"%s\" at (%f, %f, %f) has no sound file\n", STRING(pev->targetname), pev->origin.x, pev->origin.y, pev->origin.z ); SetNextThink( 0.1 ); SetThink( Remove ); return; } pev->solid = SOLID_NOT; pev->movetype = MOVETYPE_NONE; // Set up think function for dynamic modification // of ambient sound's pitch or volume. Don't // start thinking yet. SetThink(RampThink); DontThink(); // allow on/off switching via 'use' function. SetUse( ToggleUse ); m_fActive = FALSE; if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_NOT_LOOPING ) ) m_fLooping = FALSE; else m_fLooping = TRUE; Precache( ); }