//----------------------------------------------------------------------------- // Purpose: Ramp pitch and volume up to maximum values, based on the difference // between how fast we're going vs how fast we can go. //----------------------------------------------------------------------------- void CFuncRotating::RampPitchVol( void ) { // // Calc volume and pitch as % of maximum vol and pitch. // float fpct = fabs(m_flSpeed) / m_flMaxSpeed; float fvol = clamp(m_flVolume * fpct, 0, 1); // slowdown volume ramps down to 0 float fpitch = FANPITCHMIN + (FANPITCHMAX - FANPITCHMIN) * fpct; int pitch = clamp(fpitch, 0, 255); if (pitch == PITCH_NORM) { pitch = PITCH_NORM - 1; } // // Update the fan's volume and pitch. // CPASAttenuationFilter filter( GetAbsOrigin(), m_flAttenuation ); filter.MakeReliable(); EmitSound_t ep; ep.m_nChannel = CHAN_STATIC; ep.m_pSoundName = STRING(m_NoiseRunning); ep.m_flVolume = fvol; ep.m_SoundLevel = ATTN_TO_SNDLVL( m_flAttenuation ); ep.m_nFlags = SND_CHANGE_PITCH | SND_CHANGE_VOL; ep.m_nPitch = pitch; EmitSound( filter, entindex(), ep ); }
CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEntIndex, int channel, const char *pSoundName, float attenuation ) { CSoundPatch *pSound = new CSoundPatch; EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL; pSound->Init( &filter, hEnt.Get(), channel, pSoundName, ATTN_TO_SNDLVL( attenuation ) ); return pSound; }
void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChannel, const char *pSample, float flVolume, float flAttenuation, int iFlags, int iPitch, const Vector *pOrigin, const Vector *pDirection, CUtlVector<Vector> *pUtlVecOrigins, bool bUpdatePositions, float soundtime, int speakerentity) { SoundHookIter iter; IPluginFunction *pFunc; cell_t res = static_cast<ResultType>(Pl_Continue); cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation)); char buffer[PLATFORM_MAX_PATH]; strcpy(buffer, pSample); for (iter=m_NormalFuncs.begin(); iter!=m_NormalFuncs.end(); iter++) { int players[64], size; size = _FillInPlayers(players, &filter); pFunc = (*iter); pFunc->PushArray(players, 64, SM_PARAM_COPYBACK); pFunc->PushCellByRef(&size); pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); pFunc->PushCellByRef(&iEntIndex); pFunc->PushCellByRef(&iChannel); pFunc->PushFloatByRef(&flVolume); pFunc->PushCellByRef(&sndlevel); pFunc->PushCellByRef(&iPitch); pFunc->PushCellByRef(&iFlags); g_InSoundHook = true; pFunc->Execute(&res); g_InSoundHook = false; switch (res) { case Pl_Handled: case Pl_Stop: { RETURN_META(MRES_SUPERCEDE); } case Pl_Changed: { CellRecipientFilter crf; crf.Initialize(players, size); RETURN_META_NEWPARAMS( MRES_IGNORED, static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, float, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound), (crf, iEntIndex, iChannel, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)), iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity) ); } } } }
//----------------------------------------------------------------------------- // Purpose: Input handler for showing the message and/or playing the sound. //----------------------------------------------------------------------------- void CMessage::InputShowMessage( inputdata_t &inputdata ) { CBaseEntity *pPlayer = NULL; if ( m_spawnflags & SF_MESSAGE_ALL ) { UTIL_ShowMessageAll( STRING( m_iszMessage ) ); } else { if ( inputdata.pActivator && inputdata.pActivator->IsPlayer() ) { pPlayer = inputdata.pActivator; } else { pPlayer = (gpGlobals->maxClients > 1) ? NULL : UTIL_GetLocalPlayer(); } if ( pPlayer && pPlayer->IsPlayer() ) { UTIL_ShowMessage( STRING( m_iszMessage ), ToBasePlayer( pPlayer ) ); } } if ( m_sNoise != NULL_STRING ) { CPASAttenuationFilter filter( this ); EmitSound_t ep; ep.m_nChannel = CHAN_BODY; ep.m_pSoundName = (char*)STRING(m_sNoise); ep.m_flVolume = m_MessageVolume; ep.m_SoundLevel = ATTN_TO_SNDLVL( m_Radius ); EmitSound( filter, entindex(), ep ); } if ( m_spawnflags & SF_MESSAGE_ONCE ) { UTIL_Remove( this ); } m_OnShowMessage.FireOutput( inputdata.pActivator, this ); }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CFuncTankPulseLaser::Fire( int bulletCount, const Vector &barrelEnd, const Vector &vecForward, CBaseEntity *pAttacker ) { // -------------------------------------------------- // Get direction vectors for spread // -------------------------------------------------- Vector vecUp = Vector(0,0,1); Vector vecRight; CrossProduct ( vecForward, vecUp, vecRight ); CrossProduct ( vecForward, -vecRight, vecUp ); for ( int i = 0; i < bulletCount; i++ ) { // get circular gaussian spread float x, y, z; do { x = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); y = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); z = x*x+y*y; } while (z > 1); Vector vecDir = vecForward + x * gTankSpread[m_spread].x * vecRight + y * gTankSpread[m_spread].y * vecUp; CGrenadeBeam *pPulse = CGrenadeBeam::Create( pAttacker, barrelEnd); pPulse->Format(m_flPulseColor, m_flPulseWidth); pPulse->Shoot(vecDir,m_flPulseSpeed,m_flPulseLife,m_flPulseLag,m_iBulletDamage); if ( m_sPulseFireSound != NULL_STRING ) { CPASAttenuationFilter filter( this, 0.6f ); EmitSound_t ep; ep.m_nChannel = CHAN_WEAPON; ep.m_pSoundName = (char*)STRING(m_sPulseFireSound); ep.m_flVolume = 1.0f; ep.m_SoundLevel = ATTN_TO_SNDLVL( 0.6 ); EmitSound( filter, entindex(), ep ); } } CFuncTank::Fire( bulletCount, barrelEnd, vecForward, pAttacker ); }
void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChannel, const char *pSample, float flVolume, float flAttenuation, int iFlags, int iPitch, const Vector *pOrigin, const Vector *pDirection, CUtlVector<Vector> *pUtlVecOrigins, bool bUpdatePositions, float soundtime, int speakerentity) #endif { SoundHookIter iter; IPluginFunction *pFunc; cell_t res = static_cast<ResultType>(Pl_Continue); cell_t sndlevel = static_cast<cell_t>(ATTN_TO_SNDLVL(flAttenuation)); char buffer[PLATFORM_MAX_PATH]; strcpy(buffer, pSample); char soundEntry[PLATFORM_MAX_PATH] = ""; #if SOURCE_ENGINE >= SE_PORTAL2 Q_strncpy(soundEntry, pSoundEntry, sizeof(soundEntry)); #endif #if SOURCE_ENGINE < SE_PORTAL2 int nSeed = 0; #endif for (iter=m_NormalFuncs.begin(); iter!=m_NormalFuncs.end(); iter++) { int players[SM_MAXPLAYERS], size; size = _FillInPlayers(players, &filter); pFunc = (*iter); pFunc->PushArray(players, SM_ARRAYSIZE(players), SM_PARAM_COPYBACK); pFunc->PushCellByRef(&size); pFunc->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); pFunc->PushCellByRef(&iEntIndex); pFunc->PushCellByRef(&iChannel); pFunc->PushFloatByRef(&flVolume); pFunc->PushCellByRef(&sndlevel); pFunc->PushCellByRef(&iPitch); pFunc->PushCellByRef(&iFlags); pFunc->PushStringEx(soundEntry, sizeof(soundEntry), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); pFunc->PushCellByRef(&nSeed); g_InSoundHook = true; pFunc->Execute(&res); g_InSoundHook = false; switch (res) { case Pl_Handled: case Pl_Stop: { #if SOURCE_ENGINE >= SE_PORTAL2 RETURN_META_VALUE(MRES_SUPERCEDE, -1); #else RETURN_META(MRES_SUPERCEDE); #endif } case Pl_Changed: { /* Client validation */ for (int i = 0; i < size; i++) { int client = players[i]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client); } else if (!pPlayer->IsInGame()) { pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client); } else { continue; } #if SOURCE_ENGINE >= SE_PORTAL2 RETURN_META_VALUE(MRES_IGNORED, -1 ); #else return; #endif } #if SOURCE_ENGINE >= SE_PORTAL2 if (strcmp(pSoundEntry, soundEntry) != 0 || strcmp(pSample, buffer) != 0) { if (strcmp(soundEntry, buffer) == 0) nSoundEntryHash = -1; else if (strcmp(soundEntry, "") != 0) nSoundEntryHash = GenerateSoundEntryHash(soundEntry); } #endif CellRecipientFilter crf; crf.Initialize(players, size); #if SOURCE_ENGINE >= SE_PORTAL2 RETURN_META_VALUE_NEWPARAMS( MRES_IGNORED, -1, static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char *, unsigned int, const char *, float, float, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound), (crf, iEntIndex, iChannel, soundEntry, nSoundEntryHash, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)), nSeed, iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity) ); #elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_SDK2013 \ || SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2 RETURN_META_NEWPARAMS( MRES_IGNORED, static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char *, float, float, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound), (crf, iEntIndex, iChannel, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)), iFlags, iPitch, iSpecialDSP, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity) ); #else RETURN_META_NEWPARAMS( MRES_IGNORED, static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char *, float, float, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>(&IEngineSound::EmitSound), (crf, iEntIndex, iChannel, buffer, flVolume, SNDLVL_TO_ATTN(static_cast<soundlevel_t>(sndlevel)), iFlags, iPitch, pOrigin, pDirection, pUtlVecOrigins, bUpdatePositions, soundtime, speakerentity) ); #endif } } } #if SOURCE_ENGINE >= SE_PORTAL2 RETURN_META_VALUE(MRES_IGNORED, -1 ); #endif }
//----------------------------------------------------------------------------- // Purpose: Sets the current speed to the given value and manages the sound effects. // Input : flNewSpeed - New speed in degrees per second. //----------------------------------------------------------------------------- void CFuncRotating::UpdateSpeed( float flNewSpeed ) { float flOldSpeed = m_flSpeed; m_flSpeed = clamp( flNewSpeed, -m_flMaxSpeed, m_flMaxSpeed ); if ( m_bStopAtStartPos ) { int checkAxis = 2; // See if we got close to the starting orientation if ( m_vecMoveAng[0] != 0 ) { checkAxis = 0; } else if ( m_vecMoveAng[1] != 0 ) { checkAxis = 1; } float angDelta = anglemod( GetLocalAngles()[ checkAxis ] - m_angStart[ checkAxis ] ); if ( angDelta > 180.0f ) { angDelta -= 360.0f; } if ( flNewSpeed < 100 ) { if ( flNewSpeed <= 25 && fabs( angDelta ) < 1.0f ) { m_flTargetSpeed = 0; m_bStopAtStartPos = false; m_flSpeed = 0.0f; SetLocalAngles( m_angStart ); } else if ( fabs( angDelta ) > 90.0f ) { // Keep rotating at same speed for now m_flSpeed = flOldSpeed; } else { float minSpeed = fabs( angDelta ); if ( minSpeed < 20 ) minSpeed = 20; m_flSpeed = flOldSpeed > 0.0f ? minSpeed : -minSpeed; } } } if ( ( flOldSpeed == 0 ) && ( m_flSpeed != 0 ) ) { // Starting to move - emit the sound. CPASAttenuationFilter filter( GetAbsOrigin(), m_flAttenuation ); filter.MakeReliable(); EmitSound_t ep; ep.m_nChannel = CHAN_STATIC; ep.m_pSoundName = STRING(m_NoiseRunning); ep.m_flVolume = 0.01; ep.m_SoundLevel = ATTN_TO_SNDLVL( m_flAttenuation ); ep.m_nPitch = FANPITCHMIN; EmitSound( filter, entindex(), ep ); RampPitchVol(); } else if ( ( flOldSpeed != 0 ) && ( m_flSpeed == 0 ) ) { // Stopping - stop the sound. StopSound( entindex(), CHAN_STATIC, STRING(m_NoiseRunning) ); } else { // Changing speed - adjust the pitch and volume. RampPitchVol(); } SetLocalAngularVelocity( m_vecMoveAng * m_flSpeed ); }
void C_PlantedC4::ClientThink( void ) { BaseClass::ClientThink(); // If it's dormant, don't beep or anything.. if ( IsDormant() ) return; if ( !m_bBombTicking ) { // disbale C4 thinking if not armed SetNextClientThink( CLIENT_THINK_NEVER ); return; } if( gpGlobals->curtime > m_flNextBeep ) { // as it gets closer to going off, increase the radius CLocalPlayerFilter filter; float attenuation; float freq; //the percent complete of the bomb timer float fComplete = ( ( m_flC4Blow - gpGlobals->curtime ) / m_flTimerLength ); fComplete = clamp( fComplete, 0.0f, 1.0f ); attenuation = min( 0.3 + 0.6 * fComplete, 1.0 ); CSoundParameters params; if ( GetParametersForSound( "C4.PlantSound", params, NULL ) ) { EmitSound_t ep( params ); ep.m_SoundLevel = ATTN_TO_SNDLVL( attenuation ); ep.m_pOrigin = &GetAbsOrigin(); EmitSound( filter, SOUND_FROM_WORLD, ep ); } freq = max( 0.1 + 0.9 * fComplete, 0.15 ); m_flNextBeep = gpGlobals->curtime + freq; } if( gpGlobals->curtime > m_flNextGlow ) { int modelindex = modelinfo->GetModelIndex( "sprites/ledglow.vmt" ); float scale = 0.8f; Vector vPos = GetAbsOrigin(); const Vector offset( 0, 0, 4 ); // See if the c4 ended up underwater - we need to pull the flash up, or it won't get seen if ( enginetrace->GetPointContents( vPos ) & (CONTENTS_WATER|CONTENTS_SLIME) ) { C_CSPlayer *player = GetLocalOrInEyeCSPlayer(); if ( player ) { const Vector& eyes = player->EyePosition(); if ( ( enginetrace->GetPointContents( eyes ) & (CONTENTS_WATER|CONTENTS_SLIME) ) == 0 ) { // trace from the player to the water trace_t waterTrace; UTIL_TraceLine( eyes, vPos, (CONTENTS_WATER|CONTENTS_SLIME), player, COLLISION_GROUP_NONE, &waterTrace ); if( waterTrace.allsolid != 1 ) { // now trace from the C4 to the edge of the water (in case there was something solid in the water) trace_t solidTrace; UTIL_TraceLine( vPos, waterTrace.endpos, MASK_SOLID, this, COLLISION_GROUP_NONE, &solidTrace ); if( solidTrace.allsolid != 1 ) { float waterDist = (solidTrace.endpos - vPos).Length(); float remainingDist = (solidTrace.endpos - eyes).Length(); scale = scale * remainingDist / ( remainingDist + waterDist ); vPos = solidTrace.endpos; } } } } } vPos += offset; tempents->TempSprite( vPos, vec3_origin, scale, modelindex, kRenderTransAdd, 0, 1.0, 0.05, FTENT_SPRANIMATE | FTENT_SPRANIMATELOOP ); if( cl_c4dynamiclight.GetBool() ) { dlight_t *dl; dl = effects->CL_AllocDlight( entindex() ); if( dl ) { dl->origin = GetAbsOrigin() + offset; // can't use vPos because it might have been moved dl->color.r = 255; dl->color.g = 0; dl->color.b = 0; dl->radius = 64; dl->die = gpGlobals->curtime + 0.01; } } float freq = 0.1 + 0.9 * ( ( m_flC4Blow - gpGlobals->curtime ) / m_flTimerLength ); if( freq < 0.15 ) freq = 0.15; m_flNextGlow = gpGlobals->curtime + freq; } }
//----------------------------------------------------------------------------- // Purpose: // Input : *soundname - // params - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CSoundEmitterSystemBase::InitSoundInternalParameters( const char *soundname, KeyValues *kv, CSoundParametersInternal& params ) { KeyValues *pKey = kv->GetFirstSubKey(); while ( pKey ) { if ( !Q_strcasecmp( pKey->GetName(), "channel" ) ) { params.ChannelFromString( pKey->GetString() ); } else if ( !Q_strcasecmp( pKey->GetName(), "volume" ) ) { params.VolumeFromString( pKey->GetString() ); } else if ( !Q_strcasecmp( pKey->GetName(), "pitch" ) ) { params.PitchFromString( pKey->GetString() ); } else if ( !Q_strcasecmp( pKey->GetName(), "wave" ) ) { CUtlSymbol sym = m_Waves.AddString( pKey->GetString() ); params.soundnames.AddToTail( sym ); } else if ( !Q_strcasecmp( pKey->GetName(), "rndwave" ) ) { KeyValues *pWaves = pKey->GetFirstSubKey(); while ( pWaves ) { CUtlSymbol sym = m_Waves.AddString( pWaves->GetString() ); params.soundnames.AddToTail( sym ); pWaves = pWaves->GetNextKey(); } } else if ( !Q_strcasecmp( pKey->GetName(), "attenuation" ) ) { if ( !Q_strncasecmp( pKey->GetString(), "SNDLVL_", strlen( "SNDLVL_" ) ) ) { DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: sound %s has \"attenuation\" with %s value!\n", soundname, pKey->GetString() ); } if ( !Q_strncasecmp( pKey->GetString(), "ATTN_", strlen( "ATTN_" ) ) ) { params.soundlevel.start = ATTN_TO_SNDLVL( TranslateAttenuation( pKey->GetString() ) ); params.soundlevel.range = 0.0f; } else { interval_t interval; interval = ReadInterval( pKey->GetString() ); // Translate from attenuation to soundlevel float start = interval.start; float end = interval.start + interval.range; params.soundlevel.start = ATTN_TO_SNDLVL( start ); params.soundlevel.range = ATTN_TO_SNDLVL( end ) - ATTN_TO_SNDLVL( start ); } } else if ( !Q_strcasecmp( pKey->GetName(), "soundlevel" ) ) { if ( !Q_strncasecmp( pKey->GetString(), "ATTN_", strlen( "ATTN_" ) ) ) { DevMsg( "CSoundEmitterSystemBase::GetParametersForSound: sound %s has \"soundlevel\" with %s value!\n", soundname, pKey->GetString() ); } params.SoundLevelFromString( pKey->GetString() ); } else if ( !Q_strcasecmp( pKey->GetName(), "play_to_owner_only" ) ) { params.play_to_owner_only = pKey->GetInt() ? true : false; } else if ( !Q_strcasecmp( pKey->GetName(), "precache" ) ) { params.precache = pKey->GetInt() ? true : false; } pKey = pKey->GetNextKey(); } return true; }