2015-10-25 21:07:56 +06:00
/***
*
* Copyright ( c ) 1996 - 2002 , Valve LLC . All rights reserved .
2015-12-27 14:06:55 +03:00
*
* This product contains software technology licensed from Id
* Software , Inc . ( " Id Technology " ) . Id Technology ( c ) 1996 Id Software , Inc .
2015-10-25 21:07:56 +06:00
* All Rights Reserved .
*
* Use , distribution , and modification of this source code and / or resulting
* object code is restricted to non - commercial enhancements to products from
* Valve LLC . All other use , distribution , or modification is prohibited
* without written permission from Valve LLC .
*
* * * */
2015-12-27 14:06:55 +03:00
# include "stdafx.h"
2015-10-25 21:07:56 +06:00
# include "cbase.h"
# include "weapons.h"
# include "player.h"
# include "talkmonster.h"
# include "gamerules.h"
# include <ctype.h>
2015-12-27 14:06:55 +03:00
# ifndef min
# define min(a,b) (((a) < (b)) ? (a) : (b))
# endif
# ifndef max
# define max(a,b) (((a) > (b)) ? (a) : (b))
# endif
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
static char * memfgets ( byte * pMemFile , int fileSize , int & filePos , char * pBuffer , int bufferSize ) ;
2015-10-25 21:07:56 +06:00
typedef struct dynpitchvol
{
int preset ;
2015-12-27 14:06:55 +03:00
int pitchrun ;
int pitchstart ;
int spinup ;
int spindown ;
int volrun ;
int volstart ;
int fadein ;
int fadeout ;
int lfotype ;
int lforate ;
int lfomodpitch ;
int lfomodvol ;
int cspinup ;
int cspincount ;
int pitch ;
2015-10-25 21:07:56 +06:00
int spinupsav ;
int spindownsav ;
int pitchfrac ;
int vol ;
int fadeinsav ;
int fadeoutsav ;
int volfrac ;
2015-12-27 14:06:55 +03:00
int lfofrac ;
int lfomult ;
}
dynpitchvol_t ;
2015-10-25 21:07:56 +06:00
# define CDPVPRESETMAX 27
2015-12-27 14:06:55 +03:00
dynpitchvol_t rgdpvpreset [ CDPVPRESETMAX ] =
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
{ 1 , 255 , 75 , 95 , 95 , 10 , 1 , 50 , 95 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 2 , 255 , 85 , 70 , 88 , 10 , 1 , 20 , 88 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 3 , 255 , 100 , 50 , 75 , 10 , 1 , 10 , 75 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 4 , 100 , 100 , 0 , 0 , 10 , 1 , 90 , 90 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 5 , 100 , 100 , 0 , 0 , 10 , 1 , 80 , 80 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 6 , 100 , 100 , 0 , 0 , 10 , 1 , 50 , 70 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 7 , 100 , 100 , 0 , 0 , 5 , 1 , 40 , 50 , 1 , 50 , 0 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 8 , 100 , 100 , 0 , 0 , 5 , 1 , 40 , 50 , 1 , 150 , 0 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 9 , 100 , 100 , 0 , 0 , 5 , 1 , 40 , 50 , 1 , 750 , 0 , 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 10 , 128 , 100 , 50 , 75 , 10 , 1 , 30 , 40 , 2 , 8 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 11 , 128 , 100 , 50 , 75 , 10 , 1 , 30 , 40 , 2 , 25 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 12 , 128 , 100 , 50 , 75 , 10 , 1 , 30 , 40 , 2 , 70 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 13 , 50 , 50 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 14 , 70 , 70 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 15 , 90 , 90 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 16 , 120 , 120 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 17 , 180 , 180 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 18 , 255 , 255 , 0 , 0 , 10 , 1 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 19 , 200 , 75 , 90 , 90 , 10 , 1 , 50 , 90 , 2 , 100 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 20 , 255 , 75 , 97 , 90 , 10 , 1 , 50 , 90 , 1 , 40 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 21 , 100 , 100 , 0 , 0 , 10 , 1 , 30 , 50 , 3 , 15 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 22 , 160 , 160 , 0 , 0 , 10 , 1 , 50 , 50 , 3 , 500 , 25 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 23 , 255 , 75 , 88 , 0 , 10 , 1 , 40 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 24 , 200 , 20 , 95 , 70 , 10 , 1 , 70 , 70 , 3 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 25 , 180 , 100 , 50 , 60 , 10 , 1 , 40 , 60 , 2 , 90 , 100 , 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 26 , 60 , 60 , 0 , 0 , 10 , 1 , 40 , 70 , 3 , 80 , 20 , 50 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ,
{ 27 , 128 , 90 , 10 , 10 , 10 , 1 , 20 , 40 , 1 , 5 , 10 , 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
2015-10-25 21:07:56 +06:00
} ;
class CAmbientGeneric : public CBaseEntity
{
public :
2015-12-27 14:06:55 +03:00
void KeyValue ( KeyValueData * pkvd ) ;
void Spawn ( void ) ;
void Restart ( void ) ;
void Precache ( void ) ;
int Save ( CSave & save ) ;
int Restore ( CRestore & restore ) ;
int ObjectCaps ( void ) { return ( CBaseEntity : : ObjectCaps ( ) & ~ FCAP_ACROSS_TRANSITION ) ; }
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
public :
void EXPORT ToggleUse ( CBaseEntity * pActivator , CBaseEntity * pCaller , USE_TYPE useType , float value ) ;
void EXPORT RampThink ( void ) ;
void InitModulationParms ( void ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
public :
static TYPEDESCRIPTION m_SaveData [ ] ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
public :
float m_flAttenuation ;
dynpitchvol_t m_dpv ;
BOOL m_fActive ;
BOOL m_fLooping ;
2015-10-25 21:07:56 +06:00
} ;
2015-12-27 14:06:55 +03:00
LINK_ENTITY_TO_CLASS ( ambient_generic , CAmbientGeneric ) ;
TYPEDESCRIPTION CAmbientGeneric : : m_SaveData [ ] =
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
DEFINE_FIELD ( CAmbientGeneric , m_flAttenuation , FIELD_FLOAT ) ,
DEFINE_FIELD ( CAmbientGeneric , m_fActive , FIELD_BOOLEAN ) ,
DEFINE_FIELD ( CAmbientGeneric , m_fLooping , FIELD_BOOLEAN ) ,
DEFINE_ARRAY ( CAmbientGeneric , m_dpv , FIELD_CHARACTER , sizeof ( dynpitchvol_t ) ) ,
2015-10-25 21:07:56 +06:00
} ;
2015-12-27 14:06:55 +03:00
IMPLEMENT_SAVERESTORE ( CAmbientGeneric , CBaseEntity ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : Spawn ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( FBitSet ( pev - > spawnflags , AMBIENT_SOUND_EVERYWHERE ) )
2015-10-25 21:07:56 +06:00
m_flAttenuation = ATTN_NONE ;
2015-12-27 14:06:55 +03:00
else if ( FBitSet ( pev - > spawnflags , AMBIENT_SOUND_SMALLRADIUS ) )
2015-10-25 21:07:56 +06:00
m_flAttenuation = ATTN_IDLE ;
2015-12-27 14:06:55 +03:00
else if ( FBitSet ( pev - > spawnflags , AMBIENT_SOUND_MEDIUMRADIUS ) )
2015-10-25 21:07:56 +06:00
m_flAttenuation = ATTN_STATIC ;
2015-12-27 14:06:55 +03:00
else if ( FBitSet ( pev - > spawnflags , AMBIENT_SOUND_LARGERADIUS ) )
2015-10-25 21:07:56 +06:00
m_flAttenuation = ATTN_NORM ;
2015-12-27 14:06:55 +03:00
else
2015-10-25 21:07:56 +06:00
m_flAttenuation = ATTN_STATIC ;
2015-12-27 14:06:55 +03:00
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
if ( FStringNull ( pev - > message ) | | strlen ( szSoundFile ) < 1 )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
ALERT ( at_error , " EMPTY AMBIENT AT: %f, %f, %f \n " , pev - > origin . x , pev - > origin . y , pev - > origin . z ) ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
2015-12-27 14:06:55 +03:00
SetThink ( & CBaseEntity : : SUB_Remove ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
pev - > solid = SOLID_NOT ;
pev - > movetype = MOVETYPE_NONE ;
SetThink ( & CAmbientGeneric : : RampThink ) ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = 0 ;
2015-12-27 14:06:55 +03:00
SetUse ( & CAmbientGeneric : : ToggleUse ) ;
2015-10-25 21:07:56 +06:00
m_fActive = FALSE ;
2015-12-27 14:06:55 +03:00
if ( FBitSet ( pev - > spawnflags , AMBIENT_SOUND_NOT_LOOPING ) )
2015-10-25 21:07:56 +06:00
m_fLooping = FALSE ;
else
m_fLooping = TRUE ;
2015-12-27 14:06:55 +03:00
Precache ( ) ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : Restart ( void )
{
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
m_flAttenuation = ATTN_STATIC ;
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
if ( FStringNull ( pev - > message ) | | strlen ( szSoundFile ) < 1 )
{
ALERT ( at_error , " EMPTY AMBIENT AT: %f, %f, %f \n " , pev - > origin . x , pev - > origin . y , pev - > origin . z ) ;
pev - > nextthink = gpGlobals - > time + 0.1 ;
SetThink ( & CBaseEntity : : SUB_Remove ) ;
return ;
}
pev - > solid = SOLID_NOT ;
pev - > movetype = MOVETYPE_NONE ;
SetThink ( & CAmbientGeneric : : RampThink ) ;
pev - > nextthink = 0 ;
SetUse ( & CAmbientGeneric : : ToggleUse ) ;
m_fActive = FALSE ;
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_STOP , 0 ) ;
InitModulationParms ( ) ;
pev - > nextthink = gpGlobals - > time + 0.1 ;
if ( ! FBitSet ( pev - > spawnflags , AMBIENT_SOUND_NOT_LOOPING ) )
{
m_fLooping = TRUE ;
m_fActive = TRUE ;
}
else
m_fLooping = FALSE ;
if ( m_fActive )
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , ( m_dpv . vol * 0.01 ) , m_flAttenuation , 0 , m_dpv . pitch ) ;
}
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : Precache ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( ! FStringNull ( pev - > message ) & & strlen ( szSoundFile ) > 1 )
2015-10-25 21:07:56 +06:00
{
if ( * szSoundFile ! = ' ! ' )
PRECACHE_SOUND ( szSoundFile ) ;
}
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
InitModulationParms ( ) ;
2015-12-27 14:06:55 +03:00
if ( ! FBitSet ( pev - > spawnflags , AMBIENT_SOUND_START_SILENT ) )
2015-10-25 21:07:56 +06:00
{
if ( m_fLooping )
m_fActive = TRUE ;
}
2015-12-27 14:06:55 +03:00
if ( m_fActive )
{
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , ( m_dpv . vol * 0.01 ) , m_flAttenuation , SND_SPAWNING , m_dpv . pitch ) ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
}
}
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : RampThink ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
int pitch = m_dpv . pitch ;
2015-10-25 21:07:56 +06:00
int vol = m_dpv . vol ;
int flags = 0 ;
2015-12-27 14:06:55 +03:00
int fChanged = 0 ;
int prev ;
2015-10-25 21:07:56 +06:00
if ( ! m_dpv . spinup & & ! m_dpv . spindown & & ! m_dpv . fadein & & ! m_dpv . fadeout & & ! m_dpv . lfotype )
2015-12-27 14:06:55 +03:00
return ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . spinup | | m_dpv . spindown )
{
prev = m_dpv . pitchfrac > > 8 ;
if ( m_dpv . spinup > 0 )
m_dpv . pitchfrac + = m_dpv . spinup ;
else if ( m_dpv . spindown > 0 )
m_dpv . pitchfrac - = m_dpv . spindown ;
pitch = m_dpv . pitchfrac > > 8 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( pitch > m_dpv . pitchrun )
{
pitch = m_dpv . pitchrun ;
2015-12-27 14:06:55 +03:00
m_dpv . spinup = 0 ;
2015-10-25 21:07:56 +06:00
}
if ( pitch < m_dpv . pitchstart )
{
pitch = m_dpv . pitchstart ;
2015-12-27 14:06:55 +03:00
m_dpv . spindown = 0 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_STOP , 0 ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( pitch > 255 )
pitch = 255 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( pitch < 1 )
pitch = 1 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
m_dpv . pitch = pitch ;
2015-10-25 21:07:56 +06:00
fChanged | = ( prev ! = pitch ) ;
flags | = SND_CHANGE_PITCH ;
}
if ( m_dpv . fadein | | m_dpv . fadeout )
{
prev = m_dpv . volfrac > > 8 ;
if ( m_dpv . fadein > 0 )
m_dpv . volfrac + = m_dpv . fadein ;
else if ( m_dpv . fadeout > 0 )
m_dpv . volfrac - = m_dpv . fadeout ;
vol = m_dpv . volfrac > > 8 ;
if ( vol > m_dpv . volrun )
{
vol = m_dpv . volrun ;
2015-12-27 14:06:55 +03:00
m_dpv . fadein = 0 ;
2015-10-25 21:07:56 +06:00
}
if ( vol < m_dpv . volstart )
{
vol = m_dpv . volstart ;
2015-12-27 14:06:55 +03:00
m_dpv . fadeout = 0 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_STOP , 0 ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( vol > 100 )
vol = 100 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( vol < 1 )
vol = 1 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
m_dpv . vol = vol ;
2015-10-25 21:07:56 +06:00
fChanged | = ( prev ! = vol ) ;
flags | = SND_CHANGE_VOL ;
}
if ( m_dpv . lfotype )
{
int pos ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . lfofrac > 0x6FFFFFFF )
2015-10-25 21:07:56 +06:00
m_dpv . lfofrac = 0 ;
m_dpv . lfofrac + = m_dpv . lforate ;
pos = m_dpv . lfofrac > > 8 ;
if ( m_dpv . lfofrac < 0 )
{
m_dpv . lfofrac = 0 ;
m_dpv . lforate = abs ( m_dpv . lforate ) ;
pos = 0 ;
}
else if ( pos > 255 )
{
pos = 255 ;
m_dpv . lfofrac = ( 255 < < 8 ) ;
m_dpv . lforate = - abs ( m_dpv . lforate ) ;
}
2015-12-27 14:06:55 +03:00
switch ( m_dpv . lfotype )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
case LFO_SQUARE :
{
if ( pos < 128 )
m_dpv . lfomult = 255 ;
else
m_dpv . lfomult = 0 ;
break ;
}
case LFO_RANDOM :
{
if ( pos = = 255 )
m_dpv . lfomult = RANDOM_LONG ( 0 , 255 ) ;
break ;
}
case LFO_TRIANGLE :
default : m_dpv . lfomult = pos ; break ;
2015-10-25 21:07:56 +06:00
}
if ( m_dpv . lfomodpitch )
{
prev = pitch ;
pitch + = ( ( m_dpv . lfomult - 128 ) * m_dpv . lfomodpitch ) / 100 ;
2015-12-27 14:06:55 +03:00
if ( pitch > 255 )
pitch = 255 ;
if ( pitch < 1 )
pitch = 1 ;
2015-10-25 21:07:56 +06:00
fChanged | = ( prev ! = pitch ) ;
flags | = SND_CHANGE_PITCH ;
}
if ( m_dpv . lfomodvol )
{
prev = vol ;
vol + = ( ( m_dpv . lfomult - 128 ) * m_dpv . lfomodvol ) / 100 ;
2015-12-27 14:06:55 +03:00
if ( vol > 100 )
vol = 100 ;
if ( vol < 0 )
vol = 0 ;
2015-10-25 21:07:56 +06:00
fChanged | = ( prev ! = vol ) ;
flags | = SND_CHANGE_VOL ;
}
}
2015-12-27 14:06:55 +03:00
if ( flags & & fChanged )
2015-10-25 21:07:56 +06:00
{
if ( pitch = = PITCH_NORM )
2015-12-27 14:06:55 +03:00
pitch = PITCH_NORM + 1 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , ( vol * 0.01 ) , m_flAttenuation , flags , pitch ) ;
2015-10-25 21:07:56 +06:00
}
pev - > nextthink = gpGlobals - > time + 0.2 ;
return ;
}
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : InitModulationParms ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
m_dpv . volrun = ( int ) ( pev - > health * 10 ) ;
if ( m_dpv . volrun > 100 )
m_dpv . volrun = 100 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( m_dpv . volrun < 0 )
m_dpv . volrun = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . preset ! = 0 & & m_dpv . preset < = CDPVPRESETMAX )
{
m_dpv = rgdpvpreset [ m_dpv . preset - 1 ] ;
if ( m_dpv . spindown > 0 )
m_dpv . spindown = ( 101 - m_dpv . spindown ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( m_dpv . spinup > 0 )
m_dpv . spinup = ( 101 - m_dpv . spinup ) * 64 ;
m_dpv . volstart * = 10 ;
m_dpv . volrun * = 10 ;
if ( m_dpv . fadein > 0 )
m_dpv . fadein = ( 101 - m_dpv . fadein ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( m_dpv . fadeout > 0 )
m_dpv . fadeout = ( 101 - m_dpv . fadeout ) * 64 ;
m_dpv . lforate * = 256 ;
m_dpv . fadeinsav = m_dpv . fadein ;
m_dpv . fadeoutsav = m_dpv . fadeout ;
m_dpv . spinupsav = m_dpv . spinup ;
m_dpv . spindownsav = m_dpv . spindown ;
}
m_dpv . fadein = m_dpv . fadeinsav ;
2015-12-27 14:06:55 +03:00
m_dpv . fadeout = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . fadein )
m_dpv . vol = m_dpv . volstart ;
else
m_dpv . vol = m_dpv . volrun ;
m_dpv . spinup = m_dpv . spinupsav ;
2015-12-27 14:06:55 +03:00
m_dpv . spindown = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . spinup )
m_dpv . pitch = m_dpv . pitchstart ;
else
m_dpv . pitch = m_dpv . pitchrun ;
if ( m_dpv . pitch = = 0 )
m_dpv . pitch = PITCH_NORM ;
m_dpv . pitchfrac = m_dpv . pitch < < 8 ;
m_dpv . volfrac = m_dpv . vol < < 8 ;
m_dpv . lfofrac = 0 ;
m_dpv . lforate = abs ( m_dpv . lforate ) ;
m_dpv . cspincount = 1 ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . cspinup )
{
int pitchinc = ( 255 - m_dpv . pitchstart ) / m_dpv . cspinup ;
2015-10-25 21:07:56 +06:00
m_dpv . pitchrun = m_dpv . pitchstart + pitchinc ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . pitchrun > 255 )
m_dpv . pitchrun = 255 ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
if ( ( m_dpv . spinupsav | | m_dpv . spindownsav | | ( m_dpv . lfotype & & m_dpv . lfomodpitch ) ) & & ( m_dpv . pitch = = PITCH_NORM ) )
m_dpv . pitch = PITCH_NORM + 1 ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : ToggleUse ( CBaseEntity * pActivator , CBaseEntity * pCaller , USE_TYPE useType , float value )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( useType ! = USE_TOGGLE )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( ( m_fActive & & useType = = USE_ON ) | | ( ! m_fActive & & useType = = USE_OFF ) )
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( useType = = USE_SET & & m_fActive )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
float fraction = value ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( fraction > 1 )
fraction = 1 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( fraction < 0 )
fraction = 0.01 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
m_dpv . pitch = ( int ) ( fraction * 255 ) ;
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_CHANGE_PITCH , m_dpv . pitch ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( m_fActive )
{
2015-10-25 21:07:56 +06:00
if ( m_dpv . cspinup )
{
if ( m_dpv . cspincount < = m_dpv . cspinup )
2015-12-27 14:06:55 +03:00
{
2015-10-25 21:07:56 +06:00
m_dpv . cspincount + + ;
2015-12-27 14:06:55 +03:00
int pitchinc = ( 255 - m_dpv . pitchstart ) / m_dpv . cspinup ;
2015-10-25 21:07:56 +06:00
m_dpv . spinup = m_dpv . spinupsav ;
m_dpv . spindown = 0 ;
m_dpv . pitchrun = m_dpv . pitchstart + pitchinc * m_dpv . cspincount ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . pitchrun > 255 )
m_dpv . pitchrun = 255 ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
}
}
else
{
m_fActive = FALSE ;
pev - > spawnflags | = AMBIENT_SOUND_START_SILENT ;
if ( m_dpv . spindownsav | | m_dpv . fadeoutsav )
{
m_dpv . spindown = m_dpv . spindownsav ;
m_dpv . spinup = 0 ;
m_dpv . fadeout = m_dpv . fadeoutsav ;
m_dpv . fadein = 0 ;
pev - > nextthink = gpGlobals - > time + 0.1 ;
}
else
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_STOP , 0 ) ;
2015-10-25 21:07:56 +06:00
}
}
2015-12-27 14:06:55 +03:00
else
{
2015-10-25 21:07:56 +06:00
if ( m_fLooping )
m_fActive = TRUE ;
else
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , 0 , 0 , SND_STOP , 0 ) ;
2015-10-25 21:07:56 +06:00
InitModulationParms ( ) ;
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , ( m_dpv . vol * 0.01 ) , m_flAttenuation , 0 , m_dpv . pitch ) ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
void CAmbientGeneric : : KeyValue ( KeyValueData * pkvd )
2015-10-25 21:07:56 +06:00
{
if ( FStrEq ( pkvd - > szKeyName , " preset " ) )
{
m_dpv . preset = atoi ( pkvd - > szValue ) ;
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " pitch " ) )
{
m_dpv . pitchrun = atoi ( pkvd - > szValue ) ;
pkvd - > fHandled = TRUE ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . pitchrun > 255 )
m_dpv . pitchrun = 255 ;
if ( m_dpv . pitchrun < 0 )
m_dpv . pitchrun = 0 ;
}
2015-10-25 21:07:56 +06:00
else if ( FStrEq ( pkvd - > szKeyName , " pitchstart " ) )
{
m_dpv . pitchstart = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
pkvd - > fHandled = TRUE ;
if ( m_dpv . pitchstart > 255 )
m_dpv . pitchstart = 255 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( m_dpv . pitchstart < 0 )
m_dpv . pitchstart = 0 ;
}
2015-10-25 21:07:56 +06:00
else if ( FStrEq ( pkvd - > szKeyName , " spinup " ) )
{
m_dpv . spinup = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . spinup > 100 )
m_dpv . spinup = 100 ;
if ( m_dpv . spinup < 0 )
m_dpv . spinup = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . spinup > 0 )
m_dpv . spinup = ( 101 - m_dpv . spinup ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
m_dpv . spinupsav = m_dpv . spinup ;
pkvd - > fHandled = TRUE ;
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
else if ( FStrEq ( pkvd - > szKeyName , " spindown " ) )
{
m_dpv . spindown = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . spindown > 100 )
m_dpv . spindown = 100 ;
if ( m_dpv . spindown < 0 )
m_dpv . spindown = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . spindown > 0 )
m_dpv . spindown = ( 101 - m_dpv . spindown ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
m_dpv . spindownsav = m_dpv . spindown ;
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " volstart " ) )
{
m_dpv . volstart = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . volstart > 10 )
m_dpv . volstart = 10 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( m_dpv . volstart < 0 )
m_dpv . volstart = 0 ;
m_dpv . volstart * = 10 ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " fadein " ) )
{
m_dpv . fadein = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . fadein > 100 )
m_dpv . fadein = 100 ;
if ( m_dpv . fadein < 0 )
m_dpv . fadein = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . fadein > 0 )
m_dpv . fadein = ( 101 - m_dpv . fadein ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
m_dpv . fadeinsav = m_dpv . fadein ;
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " fadeout " ) )
{
m_dpv . fadeout = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . fadeout > 100 )
m_dpv . fadeout = 100 ;
if ( m_dpv . fadeout < 0 )
m_dpv . fadeout = 0 ;
2015-10-25 21:07:56 +06:00
if ( m_dpv . fadeout > 0 )
m_dpv . fadeout = ( 101 - m_dpv . fadeout ) * 64 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
m_dpv . fadeoutsav = m_dpv . fadeout ;
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " lfotype " ) )
{
m_dpv . lfotype = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . lfotype > 4 )
m_dpv . lfotype = LFO_TRIANGLE ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " lforate " ) )
{
m_dpv . lforate = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . lforate > 1000 )
m_dpv . lforate = 1000 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( m_dpv . lforate < 0 )
m_dpv . lforate = 0 ;
m_dpv . lforate * = 256 ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " lfomodpitch " ) )
{
m_dpv . lfomodpitch = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . lfomodpitch > 100 )
m_dpv . lfomodpitch = 100 ;
if ( m_dpv . lfomodpitch < 0 )
m_dpv . lfomodpitch = 0 ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " lfomodvol " ) )
{
m_dpv . lfomodvol = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . lfomodvol > 100 )
m_dpv . lfomodvol = 100 ;
if ( m_dpv . lfomodvol < 0 )
m_dpv . lfomodvol = 0 ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else if ( FStrEq ( pkvd - > szKeyName , " cspinup " ) )
{
m_dpv . cspinup = atoi ( pkvd - > szValue ) ;
2015-12-27 14:06:55 +03:00
if ( m_dpv . cspinup > 100 )
m_dpv . cspinup = 100 ;
if ( m_dpv . cspinup < 0 )
m_dpv . cspinup = 0 ;
2015-10-25 21:07:56 +06:00
pkvd - > fHandled = TRUE ;
}
else
2015-12-27 14:06:55 +03:00
CBaseEntity : : KeyValue ( pkvd ) ;
2015-10-25 21:07:56 +06:00
}
class CEnvSound : public CPointEntity
{
public :
2015-12-27 14:06:55 +03:00
void KeyValue ( KeyValueData * pkvd ) ;
void Spawn ( void ) ;
void Think ( void ) ;
int Save ( CSave & save ) ;
int Restore ( CRestore & restore ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
public :
static TYPEDESCRIPTION m_SaveData [ ] ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
public :
2015-10-25 21:07:56 +06:00
float m_flRadius ;
float m_flRoomtype ;
} ;
2015-12-27 14:06:55 +03:00
LINK_ENTITY_TO_CLASS ( env_sound , CEnvSound ) ;
TYPEDESCRIPTION CEnvSound : : m_SaveData [ ] =
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
DEFINE_FIELD ( CEnvSound , m_flRadius , FIELD_FLOAT ) ,
DEFINE_FIELD ( CEnvSound , m_flRoomtype , FIELD_FLOAT ) ,
2015-10-25 21:07:56 +06:00
} ;
2015-12-27 14:06:55 +03:00
IMPLEMENT_SAVERESTORE ( CEnvSound , CBaseEntity ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
void CEnvSound : : KeyValue ( KeyValueData * pkvd )
2015-10-25 21:07:56 +06:00
{
if ( FStrEq ( pkvd - > szKeyName , " radius " ) )
{
m_flRadius = atof ( pkvd - > szValue ) ;
pkvd - > fHandled = TRUE ;
}
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( FStrEq ( pkvd - > szKeyName , " roomtype " ) )
{
m_flRoomtype = atof ( pkvd - > szValue ) ;
pkvd - > fHandled = TRUE ;
}
}
2015-12-27 14:06:55 +03:00
BOOL FEnvSoundInRange ( entvars_t * pev , entvars_t * pevTarget , float * pflRange )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
CEnvSound * pSound = GetClassPtr ( ( CEnvSound * ) pev ) ;
2015-10-25 21:07:56 +06:00
Vector vecSpot1 = pev - > origin + pev - > view_ofs ;
Vector vecSpot2 = pevTarget - > origin + pevTarget - > view_ofs ;
2015-12-27 14:06:55 +03:00
TraceResult tr ;
2015-10-25 21:07:56 +06:00
UTIL_TraceLine ( vecSpot1 , vecSpot2 , ignore_monsters , ENT ( pev ) , & tr ) ;
if ( ( tr . fInOpen & & tr . fInWater ) | | tr . flFraction ! = 1 )
return FALSE ;
2015-12-27 14:06:55 +03:00
Vector vecRange = tr . vecEndPos - vecSpot1 ;
float flRange = vecRange . Length ( ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( pSound - > m_flRadius < flRange )
2015-10-25 21:07:56 +06:00
return FALSE ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( pflRange )
* pflRange = flRange ;
return TRUE ;
}
2015-12-27 14:06:55 +03:00
void CEnvSound : : Think ( void )
2015-10-25 21:07:56 +06:00
{
edict_t * pentPlayer = FIND_CLIENT_IN_PVS ( edict ( ) ) ;
CBasePlayer * pPlayer = NULL ;
if ( FNullEnt ( pentPlayer ) )
2015-12-27 14:06:55 +03:00
goto env_sound_Think_slow ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
float flRange ;
pPlayer = GetClassPtr ( ( CBasePlayer * ) VARS ( pentPlayer ) ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( ! FNullEnt ( pPlayer - > m_pentSndLast ) & & ( pPlayer - > m_pentSndLast = = ENT ( pev ) ) )
{
if ( pPlayer - > m_flSndRoomtype ! = 0 & & pPlayer - > m_flSndRange ! = 0 )
{
if ( FEnvSoundInRange ( pev , VARS ( pentPlayer ) , & flRange ) )
{
2015-10-25 21:07:56 +06:00
pPlayer - > m_flSndRange = flRange ;
goto env_sound_Think_fast ;
2015-12-27 14:06:55 +03:00
}
else
{
2015-10-25 21:07:56 +06:00
pPlayer - > m_flSndRange = 0 ;
pPlayer - > m_flSndRoomtype = 0 ;
goto env_sound_Think_slow ;
}
}
2015-12-27 14:06:55 +03:00
else
goto env_sound_Think_slow ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
if ( FEnvSoundInRange ( pev , VARS ( pentPlayer ) , & flRange ) )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( flRange < pPlayer - > m_flSndRange | | pPlayer - > m_flSndRange = = 0 )
2015-10-25 21:07:56 +06:00
{
pPlayer - > m_pentSndLast = ENT ( pev ) ;
pPlayer - > m_flSndRoomtype = m_flRoomtype ;
pPlayer - > m_flSndRange = flRange ;
2015-12-27 14:06:55 +03:00
MESSAGE_BEGIN ( MSG_ONE , SVC_ROOMTYPE , NULL , pentPlayer ) ;
WRITE_SHORT ( ( short ) m_flRoomtype ) ;
MESSAGE_END ( ) ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
env_sound_Think_fast :
pev - > nextthink = gpGlobals - > time + 0.25 ;
return ;
env_sound_Think_slow :
pev - > nextthink = gpGlobals - > time + 0.75 ;
return ;
}
2015-12-27 14:06:55 +03:00
void CEnvSound : : Spawn ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
pev - > nextthink = gpGlobals - > time + RANDOM_FLOAT ( 0.0 , 0.5 ) ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
# define CSENTENCE_LRU_MAX 32
2015-10-25 21:07:56 +06:00
typedef struct sentenceg
{
char szgroupname [ CBSENTENCENAME_MAX ] ;
int count ;
unsigned char rgblru [ CSENTENCE_LRU_MAX ] ;
2015-12-27 14:06:55 +03:00
}
SENTENCEG ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
# define CSENTENCEG_MAX 200
2015-10-25 21:07:56 +06:00
SENTENCEG rgsentenceg [ CSENTENCEG_MAX ] ;
int fSentencesInit = FALSE ;
char gszallsentencenames [ CVOXFILESENTENCEMAX ] [ CBSENTENCENAME_MAX ] ;
int gcallsentences = 0 ;
void USENTENCEG_InitLRU ( unsigned char * plru , int count )
{
2015-12-27 14:06:55 +03:00
int i ;
2015-10-25 21:07:56 +06:00
unsigned char temp ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! fSentencesInit )
return ;
if ( count > CSENTENCE_LRU_MAX )
count = CSENTENCE_LRU_MAX ;
for ( i = 0 ; i < count ; i + + )
2015-12-27 14:06:55 +03:00
plru [ i ] = ( unsigned char ) i ;
2015-10-25 21:07:56 +06:00
for ( i = 0 ; i < ( count * 4 ) ; i + + )
{
2015-12-27 14:06:55 +03:00
int j = RANDOM_LONG ( 0 , count - 1 ) ;
int k = RANDOM_LONG ( 0 , count - 1 ) ;
2015-10-25 21:07:56 +06:00
temp = plru [ j ] ;
plru [ j ] = plru [ k ] ;
plru [ k ] = temp ;
}
}
int USENTENCEG_PickSequential ( int isentenceg , char * szfound , int ipick , int freset )
{
if ( ! fSentencesInit )
return - 1 ;
if ( isentenceg < 0 )
return - 1 ;
2015-12-27 14:06:55 +03:00
char * szgroupname = rgsentenceg [ isentenceg ] . szgroupname ;
unsigned char count = rgsentenceg [ isentenceg ] . count ;
2015-10-25 21:07:56 +06:00
if ( count = = 0 )
return - 1 ;
if ( ipick > = count )
ipick = count - 1 ;
2015-12-27 14:06:55 +03:00
char sznum [ 8 ] ;
2015-10-25 21:07:56 +06:00
strcpy ( szfound , " ! " ) ;
strcat ( szfound , szgroupname ) ;
sprintf ( sznum , " %d " , ipick ) ;
strcat ( szfound , sznum ) ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ipick > = count )
{
if ( freset )
return 0 ;
else
return count ;
}
return ipick + 1 ;
}
int USENTENCEG_Pick ( int isentenceg , char * szfound )
{
unsigned char ipick ;
int ffound = FALSE ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! fSentencesInit )
return - 1 ;
if ( isentenceg < 0 )
return - 1 ;
2015-12-27 14:06:55 +03:00
char * szgroupname = rgsentenceg [ isentenceg ] . szgroupname ;
unsigned char count = rgsentenceg [ isentenceg ] . count ;
unsigned char * plru = rgsentenceg [ isentenceg ] . rgblru ;
2015-10-25 21:07:56 +06:00
while ( ! ffound )
{
2015-12-27 14:06:55 +03:00
for ( unsigned char i = 0 ; i < count ; i + + )
{
2015-10-25 21:07:56 +06:00
if ( plru [ i ] ! = 0xFF )
{
ipick = plru [ i ] ;
plru [ i ] = 0xFF ;
ffound = TRUE ;
break ;
}
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
if ( ! ffound )
USENTENCEG_InitLRU ( plru , count ) ;
else
{
2015-12-27 14:06:55 +03:00
char sznum [ 8 ] ;
2015-10-25 21:07:56 +06:00
strcpy ( szfound , " ! " ) ;
strcat ( szfound , szgroupname ) ;
sprintf ( sznum , " %d " , ipick ) ;
strcat ( szfound , sznum ) ;
return ipick ;
}
}
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
return - 1 ;
}
int SENTENCEG_GetIndex ( const char * szgroupname )
{
if ( ! fSentencesInit | | ! szgroupname )
return - 1 ;
2015-12-27 14:06:55 +03:00
int i = 0 ;
2015-10-25 21:07:56 +06:00
while ( rgsentenceg [ i ] . count )
{
if ( ! strcmp ( szgroupname , rgsentenceg [ i ] . szgroupname ) )
return i ;
2015-12-27 14:06:55 +03:00
i + + ;
2015-10-25 21:07:56 +06:00
}
return - 1 ;
}
2015-12-27 14:06:55 +03:00
int SENTENCEG_PlayRndI ( edict_t * entity , int isentenceg , float volume , float attenuation , int flags , int pitch )
2015-10-25 21:07:56 +06:00
{
if ( ! fSentencesInit )
return - 1 ;
2015-12-27 14:06:55 +03:00
char name [ 64 ] ;
name [ 0 ] = ' \0 ' ;
int ipick = USENTENCEG_Pick ( isentenceg , name ) ;
2015-10-25 21:07:56 +06:00
2016-03-05 22:29:55 +03:00
if ( ipick > 0 & & * name ) //Похоже, тут хотели проверить не указатель на name, а записалось ли туда что-нибудь. Поэтому *name будет правильнее, чем просто name.
2015-10-25 21:07:56 +06:00
EMIT_SOUND_DYN ( entity , CHAN_VOICE , name , volume , attenuation , flags , pitch ) ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
return ipick ;
}
2015-12-27 14:06:55 +03:00
int SENTENCEG_PlayRndSz ( edict_t * entity , const char * szgroupname , float volume , float attenuation , int flags , int pitch )
2015-10-25 21:07:56 +06:00
{
if ( ! fSentencesInit )
return - 1 ;
2015-12-27 14:06:55 +03:00
char name [ 64 ] ;
name [ 0 ] = ' \0 ' ;
int isentenceg = SENTENCEG_GetIndex ( szgroupname ) ;
2015-10-25 21:07:56 +06:00
if ( isentenceg < 0 )
{
2015-12-27 14:06:55 +03:00
ALERT ( at_console , " No such sentence group %s \n " , szgroupname ) ;
2015-10-25 21:07:56 +06:00
return - 1 ;
}
2015-12-27 14:06:55 +03:00
int ipick = USENTENCEG_Pick ( isentenceg , name ) ;
2015-10-25 21:07:56 +06:00
if ( ipick > = 0 & & name [ 0 ] )
EMIT_SOUND_DYN ( entity , CHAN_VOICE , name , volume , attenuation , flags , pitch ) ;
return ipick ;
}
2015-12-27 14:06:55 +03:00
int SENTENCEG_PlaySequentialSz ( edict_t * entity , const char * szgroupname , float volume , float attenuation , int flags , int pitch , int ipick , int freset )
2015-10-25 21:07:56 +06:00
{
if ( ! fSentencesInit )
return - 1 ;
2015-12-27 14:06:55 +03:00
char name [ 64 ] ;
name [ 0 ] = ' \0 ' ;
int isentenceg = SENTENCEG_GetIndex ( szgroupname ) ;
2015-10-25 21:07:56 +06:00
if ( isentenceg < 0 )
return - 1 ;
2015-12-27 14:06:55 +03:00
int ipicknext = USENTENCEG_PickSequential ( isentenceg , name , ipick , freset ) ;
2015-10-25 21:07:56 +06:00
if ( ipicknext > = 0 & & name [ 0 ] )
EMIT_SOUND_DYN ( entity , CHAN_VOICE , name , volume , attenuation , flags , pitch ) ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
return ipicknext ;
}
void SENTENCEG_Stop ( edict_t * entity , int isentenceg , int ipick )
{
if ( ! fSentencesInit )
return ;
if ( isentenceg < 0 | | ipick < 0 )
return ;
2015-12-27 14:06:55 +03:00
char buffer [ 64 ] , sznum [ 8 ] ;
2015-10-25 21:07:56 +06:00
strcpy ( buffer , " ! " ) ;
strcat ( buffer , rgsentenceg [ isentenceg ] . szgroupname ) ;
sprintf ( sznum , " %d " , ipick ) ;
strcat ( buffer , sznum ) ;
STOP_SOUND ( entity , CHAN_VOICE , buffer ) ;
}
2015-12-27 14:06:55 +03:00
void SENTENCEG_Init ( void )
2015-10-25 21:07:56 +06:00
{
int i , j ;
if ( fSentencesInit )
return ;
memset ( gszallsentencenames , 0 , CVOXFILESENTENCEMAX * CBSENTENCENAME_MAX ) ;
gcallsentences = 0 ;
memset ( rgsentenceg , 0 , CSENTENCEG_MAX * sizeof ( SENTENCEG ) ) ;
2015-12-27 14:06:55 +03:00
char buffer [ 512 ] , szgroup [ 64 ] ;
2015-10-25 21:07:56 +06:00
memset ( buffer , 0 , 512 ) ;
memset ( szgroup , 0 , 64 ) ;
2015-12-27 14:06:55 +03:00
int isentencegs = - 1 ;
2015-10-25 21:07:56 +06:00
int filePos = 0 , fileSize ;
2015-12-27 14:06:55 +03:00
byte * pMemFile = g_engfuncs . pfnLoadFileForMe ( " sound/sentences.txt " , & fileSize ) ;
if ( ! pMemFile )
2015-10-25 21:07:56 +06:00
return ;
2015-12-27 14:06:55 +03:00
while ( memfgets ( pMemFile , fileSize , filePos , buffer , 511 ) ! = NULL )
2015-10-25 21:07:56 +06:00
{
i = 0 ;
2015-12-27 14:06:55 +03:00
while ( buffer [ i ] & & buffer [ i ] = = ' ' )
2015-10-25 21:07:56 +06:00
i + + ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! buffer [ i ] )
continue ;
if ( buffer [ i ] = = ' / ' | | ! isalpha ( buffer [ i ] ) )
continue ;
j = i ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
while ( buffer [ j ] & & buffer [ j ] ! = ' ' )
j + + ;
if ( ! buffer [ j ] )
continue ;
if ( gcallsentences > CVOXFILESENTENCEMAX )
{
2015-12-27 14:06:55 +03:00
ALERT ( at_error , " Too many sentences in sentences.txt! \n " ) ;
2015-10-25 21:07:56 +06:00
break ;
}
2015-12-27 14:06:55 +03:00
buffer [ j ] = ' \0 ' ;
2015-10-25 21:07:56 +06:00
const char * pString = buffer + i ;
2015-12-27 14:06:55 +03:00
if ( strlen ( pString ) > = CBSENTENCENAME_MAX )
ALERT ( at_warning , " Sentence %s longer than %d letters \n " , pString , CBSENTENCENAME_MAX - 1 ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
strcpy ( gszallsentencenames [ gcallsentences + + ] , pString ) ;
2015-10-25 21:07:56 +06:00
j - - ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( j < = i )
continue ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! isdigit ( buffer [ j ] ) )
continue ;
while ( j > i & & isdigit ( buffer [ j ] ) )
j - - ;
if ( j < = i )
continue ;
2015-12-27 14:06:55 +03:00
buffer [ j + 1 ] = ' \0 ' ;
2015-10-25 21:07:56 +06:00
if ( strcmp ( szgroup , & ( buffer [ i ] ) ) )
{
isentencegs + + ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( isentencegs > = CSENTENCEG_MAX )
{
2015-12-27 14:06:55 +03:00
ALERT ( at_error , " Too many sentence groups in sentences.txt! \n " ) ;
2015-10-25 21:07:56 +06:00
break ;
}
strcpy ( rgsentenceg [ isentencegs ] . szgroupname , & ( buffer [ i ] ) ) ;
rgsentenceg [ isentencegs ] . count = 1 ;
strcpy ( szgroup , & ( buffer [ i ] ) ) ;
continue ;
}
else
{
if ( isentencegs > = 0 )
rgsentenceg [ isentencegs ] . count + + ;
}
}
2015-12-27 14:06:55 +03:00
g_engfuncs . pfnFreeFile ( pMemFile ) ;
2015-10-25 21:07:56 +06:00
fSentencesInit = TRUE ;
i = 0 ;
while ( rgsentenceg [ i ] . count & & i < CSENTENCEG_MAX )
{
USENTENCEG_InitLRU ( & ( rgsentenceg [ i ] . rgblru [ 0 ] ) , rgsentenceg [ i ] . count ) ;
i + + ;
}
}
int SENTENCEG_Lookup ( const char * sample , char * sentencenum )
{
2015-12-27 14:06:55 +03:00
for ( int i = 0 ; i < gcallsentences ; i + + )
{
if ( ! stricmp ( gszallsentencenames [ i ] , sample + 1 ) )
2015-10-25 21:07:56 +06:00
{
if ( sentencenum )
{
2015-12-27 14:06:55 +03:00
char sznum [ 8 ] ;
2015-10-25 21:07:56 +06:00
strcpy ( sentencenum , " ! " ) ;
sprintf ( sznum , " %d " , i ) ;
strcat ( sentencenum , sznum ) ;
}
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
return i ;
}
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
return - 1 ;
}
2015-12-27 14:06:55 +03:00
void EMIT_SOUND_DYN ( edict_t * entity , int channel , const char * sample , float volume , float attenuation , int flags , int pitch )
2015-10-25 21:07:56 +06:00
{
if ( sample & & * sample = = ' ! ' )
{
char name [ 32 ] ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( SENTENCEG_Lookup ( sample , name ) > = 0 )
2015-12-27 14:06:55 +03:00
EMIT_SOUND_DYN2 ( entity , channel , name , volume , attenuation , flags , pitch ) ;
2015-10-25 21:07:56 +06:00
else
2015-12-27 14:06:55 +03:00
ALERT ( at_aiconsole , " Unable to find %s in sentences.txt \n " , sample ) ;
2015-10-25 21:07:56 +06:00
}
else
EMIT_SOUND_DYN2 ( entity , channel , sample , volume , attenuation , flags , pitch ) ;
}
void EMIT_SOUND_SUIT ( edict_t * entity , const char * sample )
{
int pitch = PITCH_NORM ;
2015-12-27 14:06:55 +03:00
float fvol = CVAR_GET_FLOAT ( " suitvolume " ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( RANDOM_LONG ( 0 , 1 ) )
pitch = RANDOM_LONG ( 0 , 6 ) + 98 ;
2015-10-25 21:07:56 +06:00
if ( fvol > 0.05 )
EMIT_SOUND_DYN ( entity , CHAN_STATIC , sample , fvol , ATTN_NORM , 0 , pitch ) ;
}
void EMIT_GROUPID_SUIT ( edict_t * entity , int isentenceg )
{
int pitch = PITCH_NORM ;
2015-12-27 14:06:55 +03:00
float fvol = CVAR_GET_FLOAT ( " suitvolume " ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( RANDOM_LONG ( 0 , 1 ) )
pitch = RANDOM_LONG ( 0 , 6 ) + 98 ;
2015-10-25 21:07:56 +06:00
if ( fvol > 0.05 )
SENTENCEG_PlayRndI ( entity , isentenceg , fvol , ATTN_NORM , 0 , pitch ) ;
}
void EMIT_GROUPNAME_SUIT ( edict_t * entity , const char * groupname )
{
int pitch = PITCH_NORM ;
2015-12-27 14:06:55 +03:00
float fvol = CVAR_GET_FLOAT ( " suitvolume " ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( RANDOM_LONG ( 0 , 1 ) )
pitch = RANDOM_LONG ( 0 , 6 ) + 98 ;
2015-10-25 21:07:56 +06:00
if ( fvol > 0.05 )
SENTENCEG_PlayRndSz ( entity , groupname , fvol , ATTN_NORM , 0 , pitch ) ;
}
int fTextureTypeInit = FALSE ;
2015-12-27 14:06:55 +03:00
# define CTEXTURESMAX 1024
2015-10-25 21:07:56 +06:00
int gcTextures = 0 ;
2015-12-27 14:06:55 +03:00
char grgszTextureName [ CTEXTURESMAX ] [ CBTEXTURENAMEMAX ] ;
char grgchTextureType [ CTEXTURESMAX ] ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
static char * memfgets ( byte * pMemFile , int fileSize , int & filePos , char * pBuffer , int bufferSize )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( ! pMemFile | | ! pBuffer )
2015-10-25 21:07:56 +06:00
return NULL ;
2015-12-27 14:06:55 +03:00
if ( filePos > = fileSize )
2015-10-25 21:07:56 +06:00
return NULL ;
int i = filePos ;
int last = fileSize ;
2015-12-27 14:06:55 +03:00
if ( last - filePos > ( bufferSize - 1 ) )
last = filePos + ( bufferSize - 1 ) ;
2015-10-25 21:07:56 +06:00
int stop = 0 ;
2015-12-27 14:06:55 +03:00
while ( i < last & & ! stop )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( pMemFile [ i ] = = ' \n ' )
2015-10-25 21:07:56 +06:00
stop = 1 ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
i + + ;
}
2015-12-27 14:06:55 +03:00
if ( i ! = filePos )
2015-10-25 21:07:56 +06:00
{
int size = i - filePos ;
2015-12-27 14:06:55 +03:00
memcpy ( pBuffer , pMemFile + filePos , sizeof ( byte ) * size ) ;
if ( size < bufferSize )
pBuffer [ size ] = ' \0 ' ;
2015-10-25 21:07:56 +06:00
filePos = i ;
return pBuffer ;
}
return NULL ;
}
2015-12-27 14:06:55 +03:00
void TEXTURETYPE_Init ( void )
2015-10-25 21:07:56 +06:00
{
int i , j ;
if ( fTextureTypeInit )
return ;
memset ( & ( grgszTextureName [ 0 ] [ 0 ] ) , 0 , CTEXTURESMAX * CBTEXTURENAMEMAX ) ;
memset ( grgchTextureType , 0 , CTEXTURESMAX ) ;
2015-12-27 14:06:55 +03:00
char buffer [ 512 ] ;
2015-10-25 21:07:56 +06:00
gcTextures = 0 ;
memset ( buffer , 0 , 512 ) ;
2015-12-27 14:06:55 +03:00
int fileSize = 0 , filePos = 0 ;
byte * pMemFile = g_engfuncs . pfnLoadFileForMe ( " sound/materials.txt " , & fileSize ) ;
if ( ! pMemFile )
2015-10-25 21:07:56 +06:00
return ;
while ( memfgets ( pMemFile , fileSize , filePos , buffer , 511 ) ! = NULL & & ( gcTextures < CTEXTURESMAX ) )
{
i = 0 ;
2015-12-27 14:06:55 +03:00
while ( buffer [ i ] & & isspace ( buffer [ i ] ) )
2015-10-25 21:07:56 +06:00
i + + ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! buffer [ i ] )
continue ;
if ( buffer [ i ] = = ' / ' | | ! isalpha ( buffer [ i ] ) )
continue ;
grgchTextureType [ gcTextures ] = toupper ( buffer [ i + + ] ) ;
2015-12-27 14:06:55 +03:00
while ( buffer [ i ] & & isspace ( buffer [ i ] ) )
2015-10-25 21:07:56 +06:00
i + + ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( ! buffer [ i ] )
continue ;
j = i ;
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
while ( buffer [ j ] & & ! isspace ( buffer [ j ] ) )
j + + ;
if ( ! buffer [ j ] )
continue ;
2015-12-27 14:06:55 +03:00
j = min ( j , CBTEXTURENAMEMAX - 1 + i ) ;
buffer [ j ] = ' \0 ' ;
2015-10-25 21:07:56 +06:00
strcpy ( & ( grgszTextureName [ gcTextures + + ] [ 0 ] ) , & ( buffer [ i ] ) ) ;
}
2015-12-27 14:06:55 +03:00
g_engfuncs . pfnFreeFile ( pMemFile ) ;
2015-10-25 21:07:56 +06:00
fTextureTypeInit = TRUE ;
}
char TEXTURETYPE_Find ( char * name )
{
for ( int i = 0 ; i < gcTextures ; i + + )
{
2015-12-27 14:06:55 +03:00
if ( ! strnicmp ( name , & ( grgszTextureName [ i ] [ 0 ] ) , CBTEXTURENAMEMAX - 1 ) )
2015-10-25 21:07:56 +06:00
return ( grgchTextureType [ i ] ) ;
}
return CHAR_TEX_CONCRETE ;
}
2015-12-27 14:06:55 +03:00
float TEXTURETYPE_PlaySound ( TraceResult * ptr , Vector vecSrc , Vector vecEnd , int iBulletType )
2015-10-25 21:07:56 +06:00
{
char * rgsz [ 4 ] ;
2015-12-27 14:06:55 +03:00
float fvol , fvolbar ;
const char * pTextureName ;
2015-10-25 21:07:56 +06:00
int cnt ;
float fattn = ATTN_NORM ;
2015-12-27 14:06:55 +03:00
if ( ! g_pGameRules - > PlayTextureSounds ( ) )
return 0 ;
2015-10-25 21:07:56 +06:00
CBaseEntity * pEntity = CBaseEntity : : Instance ( ptr - > pHit ) ;
2015-12-27 14:06:55 +03:00
char chTextureType = 0 ;
2015-10-25 21:07:56 +06:00
if ( pEntity & & pEntity - > Classify ( ) ! = CLASS_NONE & & pEntity - > Classify ( ) ! = CLASS_MACHINE )
2015-12-27 14:06:55 +03:00
{
2015-10-25 21:07:56 +06:00
chTextureType = CHAR_TEX_FLESH ;
2015-12-27 14:06:55 +03:00
}
2015-10-25 21:07:56 +06:00
else
{
2015-12-27 14:06:55 +03:00
float rgfl1 [ 3 ] , rgfl2 [ 3 ] ;
2015-10-25 21:07:56 +06:00
vecSrc . CopyToArray ( rgfl1 ) ;
vecEnd . CopyToArray ( rgfl2 ) ;
if ( pEntity )
2015-12-27 14:06:55 +03:00
pTextureName = TRACE_TEXTURE ( ENT ( pEntity - > pev ) , rgfl1 , rgfl2 ) ;
2015-10-25 21:07:56 +06:00
else
2015-12-27 14:06:55 +03:00
pTextureName = TRACE_TEXTURE ( ENT ( 0 ) , rgfl1 , rgfl2 ) ;
if ( pTextureName )
2015-10-25 21:07:56 +06:00
{
if ( * pTextureName = = ' - ' | | * pTextureName = = ' + ' )
pTextureName + = 2 ;
if ( * pTextureName = = ' { ' | | * pTextureName = = ' ! ' | | * pTextureName = = ' ~ ' | | * pTextureName = = ' ' )
pTextureName + + ;
2015-12-27 14:06:55 +03:00
char szbuffer [ 64 ] ;
strcpy ( szbuffer , pTextureName ) ;
szbuffer [ CBTEXTURENAMEMAX - 1 ] = ' \0 ' ;
chTextureType = TEXTURETYPE_Find ( szbuffer ) ;
2015-10-25 21:07:56 +06:00
}
}
switch ( chTextureType )
{
2015-12-27 14:06:55 +03:00
default :
case CHAR_TEX_CONCRETE :
{
fvol = 0.9 ;
fvolbar = 0.6 ;
rgsz [ 0 ] = " player/pl_step1.wav " ;
rgsz [ 1 ] = " player/pl_step2.wav " ;
cnt = 2 ;
break ;
}
case CHAR_TEX_METAL :
{
fvol = 0.9 ;
fvolbar = 0.3 ;
rgsz [ 0 ] = " player/pl_metal1.wav " ;
rgsz [ 1 ] = " player/pl_metal2.wav " ;
cnt = 2 ;
break ;
}
case CHAR_TEX_DIRT :
{
fvol = 0.9 ;
fvolbar = 0.1 ;
rgsz [ 0 ] = " player/pl_dirt1.wav " ;
rgsz [ 1 ] = " player/pl_dirt2.wav " ;
rgsz [ 2 ] = " player/pl_dirt3.wav " ;
cnt = 3 ;
break ;
}
case CHAR_TEX_VENT :
{
fvol = 0.5 ;
fvolbar = 0.3 ;
rgsz [ 0 ] = " player/pl_duct1.wav " ;
rgsz [ 1 ] = " player/pl_duct1.wav " ;
cnt = 2 ;
break ;
}
case CHAR_TEX_GRATE :
{
fvol = 0.9 ;
fvolbar = 0.5 ;
rgsz [ 0 ] = " player/pl_grate1.wav " ;
rgsz [ 1 ] = " player/pl_grate4.wav " ;
cnt = 2 ;
break ;
}
case CHAR_TEX_TILE :
{
fvol = 0.8 ;
fvolbar = 0.2 ;
rgsz [ 0 ] = " player/pl_tile1.wav " ;
rgsz [ 1 ] = " player/pl_tile3.wav " ;
rgsz [ 2 ] = " player/pl_tile2.wav " ;
rgsz [ 3 ] = " player/pl_tile4.wav " ;
cnt = 4 ;
break ;
}
case CHAR_TEX_SLOSH :
{
fvol = 0.9 ;
fvolbar = 0 ;
rgsz [ 0 ] = " player/pl_slosh1.wav " ;
rgsz [ 1 ] = " player/pl_slosh3.wav " ;
rgsz [ 2 ] = " player/pl_slosh2.wav " ;
rgsz [ 3 ] = " player/pl_slosh4.wav " ;
cnt = 4 ;
break ;
}
case CHAR_TEX_SNOW :
{
fvol = 0.7 ;
fvolbar = 0.4 ;
rgsz [ 0 ] = " debris/pl_snow1.wav " ;
rgsz [ 1 ] = " debris/pl_snow2.wav " ;
rgsz [ 2 ] = " debris/pl_snow3.wav " ;
rgsz [ 3 ] = " debris/pl_snow4.wav " ;
cnt = 4 ;
break ;
}
case CHAR_TEX_WOOD :
{
fvol = 0.9 ;
fvolbar = 0.2 ;
rgsz [ 0 ] = " debris/wood1.wav " ;
rgsz [ 1 ] = " debris/wood2.wav " ;
rgsz [ 2 ] = " debris/wood3.wav " ;
cnt = 3 ;
break ;
}
case CHAR_TEX_GLASS :
case CHAR_TEX_COMPUTER :
{
fvol = 0.8 ;
fvolbar = 0.2 ;
rgsz [ 0 ] = " debris/glass1.wav " ;
rgsz [ 1 ] = " debris/glass2.wav " ;
rgsz [ 2 ] = " debris/glass3.wav " ;
cnt = 3 ;
break ;
}
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
case CHAR_TEX_FLESH :
{
if ( iBulletType = = BULLET_PLAYER_CROWBAR )
return 0 ;
fvol = 1.0 ; fvolbar = 0.2 ;
rgsz [ 0 ] = " weapons/bullet_hit1.wav " ;
rgsz [ 1 ] = " weapons/bullet_hit2.wav " ;
fattn = 1.0 ;
cnt = 2 ;
break ;
}
}
2015-10-25 21:07:56 +06:00
if ( pEntity & & FClassnameIs ( pEntity - > pev , " func_breakable " ) )
{
fvol / = 1.5 ;
2015-12-27 14:06:55 +03:00
fvolbar / = 2 ;
2015-10-25 21:07:56 +06:00
}
else if ( chTextureType = = CHAR_TEX_COMPUTER )
{
2015-12-27 14:06:55 +03:00
if ( ptr - > flFraction ! = 1 & & RANDOM_LONG ( 0 , 1 ) )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
UTIL_Sparks ( ptr - > vecEndPos ) ;
float flVolume = RANDOM_FLOAT ( 0.7 , 1 ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
switch ( RANDOM_LONG ( 0 , 1 ) )
2015-10-25 21:07:56 +06:00
{
case 0 : UTIL_EmitAmbientSound ( ENT ( 0 ) , ptr - > vecEndPos , " buttons/spark5.wav " , flVolume , ATTN_NORM , 0 , 100 ) ; break ;
case 1 : UTIL_EmitAmbientSound ( ENT ( 0 ) , ptr - > vecEndPos , " buttons/spark6.wav " , flVolume , ATTN_NORM , 0 , 100 ) ; break ;
}
}
}
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( 0 ) , ptr - > vecEndPos , rgsz [ RANDOM_LONG ( 0 , cnt - 1 ) ] , fvol , fattn , 0 , 96 + RANDOM_LONG ( 0 , 0xF ) ) ;
2015-10-25 21:07:56 +06:00
return fvolbar ;
}
class CSpeaker : public CBaseEntity
{
public :
2015-12-27 14:06:55 +03:00
void KeyValue ( KeyValueData * pkvd ) ;
void Spawn ( void ) ;
void Precache ( void ) ;
int Save ( CSave & save ) ;
int Restore ( CRestore & restore ) ;
int ObjectCaps ( void ) { return ( CBaseEntity : : ObjectCaps ( ) & ~ FCAP_ACROSS_TRANSITION ) ; }
public :
void EXPORT ToggleUse ( CBaseEntity * pActivator , CBaseEntity * pCaller , USE_TYPE useType , float value ) ;
void EXPORT SpeakerThink ( void ) ;
public :
static TYPEDESCRIPTION m_SaveData [ ] ;
public :
int m_preset ;
2015-10-25 21:07:56 +06:00
} ;
2015-12-27 14:06:55 +03:00
LINK_ENTITY_TO_CLASS ( speaker , CSpeaker ) ;
TYPEDESCRIPTION CSpeaker : : m_SaveData [ ] =
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
DEFINE_FIELD ( CSpeaker , m_preset , FIELD_INTEGER ) ,
2015-10-25 21:07:56 +06:00
} ;
2015-12-27 14:06:55 +03:00
IMPLEMENT_SAVERESTORE ( CSpeaker , CBaseEntity ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
void CSpeaker : : Spawn ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
char * szSoundFile = ( char * ) STRING ( pev - > message ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( ! m_preset & & ( FStringNull ( pev - > message ) | | strlen ( szSoundFile ) < 1 ) )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
ALERT ( at_error , " SPEAKER with no Level/Sentence! at: %f, %f, %f \n " , pev - > origin . x , pev - > origin . y , pev - > origin . z ) ;
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
2015-12-27 14:06:55 +03:00
SetThink ( & CBaseEntity : : SUB_Remove ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
pev - > solid = SOLID_NOT ;
pev - > movetype = MOVETYPE_NONE ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
SetThink ( & CSpeaker : : SpeakerThink ) ;
pev - > nextthink = 0 ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
SetUse ( & CSpeaker : : ToggleUse ) ;
Precache ( ) ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
# define ANNOUNCE_MINUTES_MIN 0.25
# define ANNOUNCE_MINUTES_MAX 2.25
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
void CSpeaker : : Precache ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( ! FBitSet ( pev - > spawnflags , SPEAKER_START_SILENT ) )
pev - > nextthink = gpGlobals - > time + RANDOM_FLOAT ( 5 , 15 ) ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
void CSpeaker : : SpeakerThink ( void )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
char * szSoundFile = NULL ;
2015-10-25 21:07:56 +06:00
float flvolume = pev - > health * 0.1 ;
float flattenuation = 0.3 ;
int flags = 0 ;
int pitch = 100 ;
if ( gpGlobals - > time < = CTalkMonster : : g_talkWaitTime )
{
2015-12-27 14:06:55 +03:00
pev - > nextthink = CTalkMonster : : g_talkWaitTime + RANDOM_FLOAT ( 5 , 10 ) ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
2015-10-25 21:07:56 +06:00
if ( m_preset )
{
switch ( m_preset )
{
2015-12-27 14:06:55 +03:00
case 1 : szSoundFile = " C1A0_ " ; break ;
case 2 : szSoundFile = " C1A1_ " ; break ;
case 3 : szSoundFile = " C1A2_ " ; break ;
case 4 : szSoundFile = " C1A3_ " ; break ;
case 5 : szSoundFile = " C1A4_ " ; break ;
case 6 : szSoundFile = " C2A1_ " ; break ;
case 7 : szSoundFile = " C2A2_ " ; break ;
case 8 : szSoundFile = " C2A3_ " ; break ;
case 9 : szSoundFile = " C2A4_ " ; break ;
case 10 : szSoundFile = " C2A5_ " ; break ;
case 11 : szSoundFile = " C3A1_ " ; break ;
case 12 : szSoundFile = " C3A2_ " ; break ;
2015-10-25 21:07:56 +06:00
}
2015-12-27 14:06:55 +03:00
}
else
szSoundFile = ( char * ) STRING ( pev - > message ) ;
2015-10-25 21:07:56 +06:00
if ( szSoundFile [ 0 ] = = ' ! ' )
{
2015-12-27 14:06:55 +03:00
UTIL_EmitAmbientSound ( ENT ( pev ) , pev - > origin , szSoundFile , flvolume , flattenuation , flags , pitch ) ;
pev - > nextthink = 0 ;
2015-10-25 21:07:56 +06:00
}
else
{
if ( SENTENCEG_PlayRndSz ( ENT ( pev ) , szSoundFile , flvolume , flattenuation , flags , pitch ) < 0 )
2015-12-27 14:06:55 +03:00
ALERT ( at_console , " Level Design Error! \n SPEAKER has bad sentence group name: %s \n " , szSoundFile ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
pev - > nextthink = gpGlobals - > time + RANDOM_FLOAT ( ANNOUNCE_MINUTES_MIN * 60 , ANNOUNCE_MINUTES_MAX * 60 ) ;
CTalkMonster : : g_talkWaitTime = gpGlobals - > time + 5 ;
2015-10-25 21:07:56 +06:00
}
return ;
}
2015-12-27 14:06:55 +03:00
void CSpeaker : : ToggleUse ( CBaseEntity * pActivator , CBaseEntity * pCaller , USE_TYPE useType , float value )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
int fActive = ( pev - > nextthink > 0 ) ;
2015-10-25 21:07:56 +06:00
2015-12-27 14:06:55 +03:00
if ( useType ! = USE_TOGGLE )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
if ( ( fActive & & useType = = USE_ON ) | | ( ! fActive & & useType = = USE_OFF ) )
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( useType = = USE_ON )
2015-10-25 21:07:56 +06:00
{
pev - > nextthink = gpGlobals - > time + 0.1 ;
return ;
}
2015-12-27 14:06:55 +03:00
if ( useType = = USE_OFF )
2015-10-25 21:07:56 +06:00
{
2015-12-27 14:06:55 +03:00
pev - > nextthink = 0 ;
2015-10-25 21:07:56 +06:00
return ;
}
2015-12-27 14:06:55 +03:00
if ( fActive )
pev - > nextthink = 0 ;
else
2015-10-25 21:07:56 +06:00
pev - > nextthink = gpGlobals - > time + 0.1 ;
}
2015-12-27 14:06:55 +03:00
void CSpeaker : : KeyValue ( KeyValueData * pkvd )
2015-10-25 21:07:56 +06:00
{
if ( FStrEq ( pkvd - > szKeyName , " preset " ) )
{
m_preset = atoi ( pkvd - > szValue ) ;
pkvd - > fHandled = TRUE ;
}
else
2015-12-27 14:06:55 +03:00
CBaseEntity : : KeyValue ( pkvd ) ;
2015-10-25 21:07:56 +06:00
}