2009-04-16 22:21:32 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-16 22:21:32 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: soundeffects.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Basic sound-management API.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-16 22:21:32 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum sound path length.
|
|
|
|
*/
|
|
|
|
#define SOUND_MAX_PATH 128
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ambient sound channel.
|
|
|
|
*/
|
|
|
|
#define SOUND_AMBIENT_CHANNEL 8
|
|
|
|
|
2009-08-21 21:47:32 +02:00
|
|
|
#include "zr/soundeffects/voice"
|
2009-04-17 01:09:52 +02:00
|
|
|
#include "zr/soundeffects/ambientsounds"
|
2009-04-16 22:21:32 +02:00
|
|
|
#include "zr/soundeffects/zombiesounds"
|
|
|
|
|
2009-04-17 01:09:52 +02:00
|
|
|
/**
|
|
|
|
* Load sound effects data.
|
|
|
|
*/
|
|
|
|
SEffectsLoad()
|
|
|
|
{
|
|
|
|
// Load ambient sound cvars.
|
|
|
|
AmbientSoundsLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map is starting.
|
|
|
|
*/
|
|
|
|
SEffectsOnMapStart()
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
AmbientSoundsOnMapStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client is joining the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsClientInit(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
AmbientSoundsClientInit(client);
|
|
|
|
ZombieSoundsClientInit(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The round is starting.
|
|
|
|
*/
|
|
|
|
SEffectsOnRoundStart()
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
AmbientSoundsOnRoundStart();
|
|
|
|
}
|
|
|
|
|
2009-05-05 07:40:15 +02:00
|
|
|
/**
|
|
|
|
* The round is ending.
|
|
|
|
*/
|
|
|
|
SEffectsOnRoundEnd()
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
AmbientSoundsOnRoundEnd();
|
|
|
|
}
|
|
|
|
|
2009-04-17 01:09:52 +02:00
|
|
|
/**
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientSpawn(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
2009-08-21 21:47:32 +02:00
|
|
|
VoiceOnClientSpawn(client);
|
2009-04-17 01:09:52 +02:00
|
|
|
ZombieSoundsOnClientSpawn(client);
|
|
|
|
}
|
|
|
|
|
2009-06-22 08:51:23 +02:00
|
|
|
/**
|
|
|
|
* Client is spawning into the game. *Post
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientSpawnPost(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
AmbientSoundsOnClientSpawnPost(client);
|
|
|
|
}
|
|
|
|
|
2009-04-17 01:09:52 +02:00
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientDeath(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
ZombieSoundsOnClientDeath(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been hurt.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientHurt(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
ZombieSoundsOnClientHurt(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been infected.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientInfected(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
2009-08-21 21:47:32 +02:00
|
|
|
VoiceOnClientInfected(client);
|
2009-04-17 01:09:52 +02:00
|
|
|
ZombieSoundsOnClientInfected(client);
|
|
|
|
}
|
2009-08-21 21:47:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been turned back human.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
SEffectsOnClientHuman(client)
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
VoiceOnClientHuman(client);
|
|
|
|
}
|
|
|
|
|
2009-04-16 22:21:32 +02:00
|
|
|
/**
|
|
|
|
* Emits an ambient sound
|
2009-04-17 01:09:52 +02:00
|
|
|
*
|
|
|
|
* @param sound The path to the sound file (relative to sounds/)
|
|
|
|
* @param soundvolume The volume of the sound (0.0 - 1.0)
|
|
|
|
* @param client (Optional) Client index to play sound to.
|
2009-04-16 22:21:32 +02:00
|
|
|
*/
|
2009-04-17 01:09:52 +02:00
|
|
|
SEffectsEmitAmbientSound(const String:sound[], Float:ambientvolume = 1.0, client = -1)
|
2009-04-16 22:21:32 +02:00
|
|
|
{
|
|
|
|
// Precache sound before playing.
|
|
|
|
PrecacheSound(sound);
|
|
|
|
|
2009-04-24 05:02:19 +02:00
|
|
|
if (ZRIsClientValid(client))
|
2009-04-17 01:09:52 +02:00
|
|
|
{
|
|
|
|
// Emit ambient sound.
|
|
|
|
EmitSoundToClient(client, sound, SOUND_FROM_PLAYER, SOUND_AMBIENT_CHANNEL, _, _, ambientvolume);
|
|
|
|
|
|
|
|
// Flag client that sound is playing.
|
|
|
|
bAmbientSoundsIsPlaying[client] = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit ambient sound.
|
2009-05-05 07:40:15 +02:00
|
|
|
EmitSoundToClient(x, sound, SOUND_FROM_PLAYER, SNDCHAN_AUTO, _, _, ambientvolume);
|
2009-04-17 01:09:52 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-16 22:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop an ambient sound
|
2009-04-17 01:09:52 +02:00
|
|
|
*
|
|
|
|
* @param sound The path to the sound file (relative to sounds/)
|
2009-04-16 22:21:32 +02:00
|
|
|
*/
|
|
|
|
SEffectsStopAmbientSound(const String:sound[])
|
|
|
|
{
|
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop ambient sound.
|
|
|
|
StopSound(x, SOUND_AMBIENT_CHANNEL, sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 01:09:52 +02:00
|
|
|
/**
|
|
|
|
* Replay an ambient sound
|
|
|
|
*
|
|
|
|
* @param sound The path to the sound file (relative to sounds/)
|
|
|
|
*/
|
|
|
|
|
2009-04-16 22:21:32 +02:00
|
|
|
/**
|
|
|
|
* Emits a sound from a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param sound The sound file relative to the sound/ directory.
|
|
|
|
* @param level The attenuation of the sound.
|
|
|
|
*/
|
|
|
|
SEffectsEmitSoundFromClient(client, const String:sound[], level = SNDLEVEL_NORMAL)
|
|
|
|
{
|
|
|
|
// Precache sound before playing.
|
|
|
|
PrecacheSound(sound);
|
|
|
|
|
|
|
|
// Emit sound from client.
|
|
|
|
EmitSoundToAll(sound, client, _, level);
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|