____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "SDL.h"
#include "sound.h"
#include "video.h"
#include "unitsound.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "sound_server.h"
#include "missile.h"
#include "map.h"
#include "ui.h"
#include "widgets.h"
Go to the source code of this file.
Classes | |
| struct | SelectionHandling |
Functions | |
| static CSample * | SimpleChooseSample (const CSound *sound) |
| static CSample * | ChooseSample (CSound *sound, bool selection, Origin &source) |
| static CSound * | ChooseUnitVoiceSound (const CUnit *unit, UnitVoiceGroup voice) |
| static unsigned char | VolumeForDistance (unsigned short d, unsigned char range) |
| static unsigned char | CalculateVolume (bool isVolume, int power, unsigned char range) |
| static char | CalculateStereo (const CUnit *unit) |
| void | PlayUnitSound (const CUnit *unit, UnitVoiceGroup voice) |
| < Play a unit sound | |
| void | PlayUnitSound (const CUnit *unit, CSound *sound) |
| Play a missile sound. | |
| void | PlayMissileSound (const Missile *missile, CSound *sound) |
| Play a game sound. | |
| void | PlayGameSound (CSound *sound, unsigned char volume) |
| Play a sound file. | |
| static void | PlaySoundFileCallback (int channel) |
| int | PlayFile (const std::string &name, LuaActionListener *listener) |
| Modify the range of a given sound. | |
| void | SetSoundRange (CSound *sound, unsigned char range) |
| Register a sound (can be a simple sound or a group). | |
| CSound * | RegisterSound (const char *files[], unsigned number) |
| Create a special sound group with two sounds. | |
| CSound * | RegisterTwoGroups (CSound *first, CSound *second) |
| Initialize client side of the sound layer. | |
| void | InitSoundClient (void) |
Variables | |
| GameSound | GameSounds |
| Game sound configuration. | |
| SelectionHandling | SelectionHandler |
| static int | ViewPointOffset |
| Distance to Volume Mapping. | |
| int | DistanceSilent |
| silent distance | |
| static std::map< int, LuaActionListener * > | ChannelMap |
Definition in file sound.cpp.
| static char CalculateStereo | ( | const CUnit * | unit | ) | [static] |
Calculate the stereo value for a unit
Definition at line 256 of file sound.cpp.
References CUnit::IX, CViewport::MapWidth, CViewport::MapX, CUserInterface::SelectedViewport, TileSizeX, CUnitType::TileWidth, CUnit::Type, UI, and CUnit::X.
Referenced by PlayUnitSound().
| static unsigned char CalculateVolume | ( | bool | isVolume, | |
| int | power, | |||
| unsigned char | range | |||
| ) | [static] |
Calculate the volume associated with a request, either by clipping the range parameter of this request, or by mapping this range to a volume.
Definition at line 238 of file sound.cpp.
References MaxVolume, and VolumeForDistance().
Referenced by PlayGameSound(), PlayMissileSound(), and PlayUnitSound().
Choose the sample to play
Definition at line 113 of file sound.cpp.
References Origin::Base, SelectionHandling::HowMany, Origin::Id, CSound::Number, CSound::OneGroup, CSound::OneSound, SimpleChooseSample(), CSound::Sound, SelectionHandling::Sound, SoundEnabled(), SelectionHandling::Source, TWO_GROUPS, and CSound::TwoGroups.
Referenced by PlayGameSound(), PlayMissileSound(), and PlayUnitSound().
| static CSound* ChooseUnitVoiceSound | ( | const CUnit * | unit, | |
| UnitVoiceGroup | voice | |||
| ) | [static] |
Maps a UnitVoiceGroup to a CSound*.
| unit | Sound initiator | |
| voice | Type of sound wanted |
Definition at line 172 of file sound.cpp.
References CUnitSound::Acknowledgement, GameSound::BuildingConstruction, CUnitSound::Dead, GameSound::Docking, GameSounds, CUnitSound::Harvest, CUnitSound::Help, NO_SOUND, CUnitSound::Ready, CUnitSound::Repair, CUnitSound::Selected, SoundConfig::Sound, CUnitType::Sound, CUnit::Type, VoiceAcknowledging, VoiceBuilding, VoiceDocking, VoiceDying, VoiceHarvesting, VoiceHelpMe, VoiceReady, VoiceRepairing, VoiceSelected, VoiceWorkCompleted, and GameSound::WorkComplete.
Referenced by PlayUnitSound().
| void InitSoundClient | ( | void | ) |
Lookup the sound id's for the game sounds.
Definition at line 482 of file sound.cpp.
References GameSound::BuildingConstruction, GameSound::ChatMessage, GameSound::Click, DistanceSilent, GameSound::Docking, CMapArea::EndX, CMapArea::EndY, GameSounds, CUserInterface::MapArea, SoundConfig::Name, GameSound::PlacementError, GameSound::PlacementSuccess, GameSound::Rescue, SoundConfig::Sound, SoundEnabled(), SoundForName(), TileSizeX, TileSizeY, UI, ViewPointOffset, GameSound::WorkComplete, CMapArea::X, and CMapArea::Y.
Referenced by CreateGame(), and LoadModules().
| int PlayFile | ( | const std::string & | name, | |
| LuaActionListener * | listener | |||
| ) |
Modify the range of a given sound.
Play a sound file
| name | Filename of a sound to play | |
| listener | Optional lua callback |
Definition at line 386 of file sound.cpp.
References ChannelMap, LoadSample(), MaxVolume, PlaySample(), PlaySoundFileCallback(), SetChannelFinishedCallback(), and SetChannelVolume().
Referenced by tolua_stratagus_PlayFile00().
| void PlayGameSound | ( | CSound * | sound, | |
| unsigned char | volume | |||
| ) |
Play a sound file.
Play a game sound
| sound | Sound to play | |
| volume | Volume level to play the sound |
Definition at line 352 of file sound.cpp.
References CalculateVolume(), ChooseSample(), PlaySample(), CSound::Range, and SetChannelVolume().
Referenced by CclPlaySound(), CButtonPanel::DoClicked(), EditorCallbackButtonDown(), ParseNetworkCommand(), RescueUnits(), SpellCast(), UIHandleButtonDown(), and UIHandleButtonUp().
Play a game sound.
Ask the sound server to play a sound for a missile.
| missile | Sound initiator, missile exploding | |
| sound | Sound to be generated |
Definition at line 323 of file sound.cpp.
References CalculateVolume(), ChooseSample(), MissileType::G, CViewport::MapWidth, CViewport::MapX, PlaySample(), CSound::Range, CUserInterface::SelectedViewport, SetChannelStereo(), SetChannelVolume(), TileSizeX, Missile::Type, UI, ViewPointDistanceToMissile(), CGraphic::Width, and Missile::X.
Referenced by MissileHit().
| static void PlaySoundFileCallback | ( | int | channel | ) | [static] |
Callback for PlaySoundFile
Definition at line 368 of file sound.cpp.
References LuaActionListener::action(), ChannelMap, and GetChannelSample().
Referenced by PlayFile().
Play a missile sound.
Ask to the sound server to play a sound attached to a unit. The sound server may discard the sound if needed (e.g., when the same unit is already speaking).
| unit | Sound initiator, unit speaking | |
| sound | Sound to be generated |
Definition at line 306 of file sound.cpp.
References CalculateStereo(), CalculateVolume(), ChooseSample(), PlaySample(), CSound::Range, SetChannelStereo(), SetChannelVolume(), CUnit::Slot, and ViewPointDistanceToUnit().
| void PlayUnitSound | ( | const CUnit * | unit, | |
| UnitVoiceGroup | voice | |||
| ) |
< Play a unit sound
Ask to the sound server to play a sound attached to a unit. The sound server may discard the sound if needed (e.g., when the same unit is already speaking).
| unit | Sound initiator, unit speaking | |
| voice | Type of sound wanted (Ready,Die,Yes,...) |
Definition at line 280 of file sound.cpp.
References CalculateStereo(), CalculateVolume(), ChooseSample(), ChooseUnitVoiceSound(), PlaySample(), CSound::Range, SetChannelStereo(), SetChannelVolume(), CUnit::Slot, ViewPointDistanceToUnit(), VoiceBuilding, and VoiceSelected.
Referenced by DoActionMove(), DoRightButton(), HandleActionBuilt(), HandleActionTrain(), HitUnit(), LetUnitDie(), SendCommand(), UiFindIdleWorker(), UIHandleButtonUp(), and UnitShowAnimationScaled().
| CSound* RegisterSound | ( | const char * | files[], | |
| unsigned | number | |||
| ) |
Create a special sound group with two sounds.
Ask the sound server to register a sound (and currently to load it) and to return an unique identifier for it. The unique identifier is memory pointer of the server.
| files | An array of wav files. | |
| number | Number of files belonging together. |
Definition at line 427 of file sound.cpp.
References LoadSample(), MAX_SOUND_RANGE, NO_SOUND, ONE_SOUND, CSound::OneGroup, CSound::OneSound, and CSound::Sound.
Referenced by MakeSound().
Initialize client side of the sound layer.
Ask the sound server to put together two sounds to form a special sound.
| first | first part of the group | |
| second | second part of the group |
Definition at line 463 of file sound.cpp.
References MAX_SOUND_RANGE, NO_SOUND, CSound::Range, CSound::Sound, TWO_GROUPS, and CSound::TwoGroups.
Referenced by MakeSoundGroup().
| void SetSoundRange | ( | CSound * | sound, | |
| unsigned char | range | |||
| ) |
Register a sound (can be a simple sound or a group).
Ask the sound server to change the range of a sound.
| sound | the id of the sound to modify. | |
| range | the new range for this sound. |
Definition at line 410 of file sound.cpp.
References NO_SOUND, and CSound::Range.
Referenced by CclSetSoundRange(), and MapUnitSounds().
"Randomly" choose a sample from a sound group.
Definition at line 101 of file sound.cpp.
References FrameCounter, CSound::Number, ONE_SOUND, CSound::OneGroup, CSound::OneSound, and CSound::Sound.
Referenced by ChooseSample().
| static unsigned char VolumeForDistance | ( | unsigned short | d, | |
| unsigned char | range | |||
| ) | [static] |
Compute a suitable volume for something taking place at a given distance from the current view point.
| d | distance | |
| range | range |
Definition at line 209 of file sound.cpp.
References DistanceSilent, INFINITE_SOUND_RANGE, MAX_SOUND_RANGE, MaxVolume, and ViewPointOffset.
Referenced by CalculateVolume().
std::map<int, LuaActionListener *> ChannelMap [static] |
| int DistanceSilent |
silent distance
Definition at line 92 of file sound.cpp.
Referenced by CclSetGlobalSoundRange(), InitSoundClient(), and VolumeForDistance().
Initial value:
{
SoundConfig("placement error"),
SoundConfig("placement success"),
SoundConfig("click"),
SoundConfig("transport docking"),
SoundConfig("building construction"),
SoundConfig("basic human voices work complete"),
SoundConfig("rescue (human) UNUSED"),
}
Various sounds used in game.
FIXME:
Definition at line 68 of file sound.cpp.
Referenced by CclDefineGameSounds(), ChooseUnitVoiceSound(), CButtonPanel::DoClicked(), EditorCallbackButtonDown(), InitSoundClient(), ParseNetworkCommand(), RescueUnits(), UIHandleButtonDown(), and UIHandleButtonUp().
int ViewPointOffset [static] |
Distance to Volume Mapping.
Definition at line 91 of file sound.cpp.
Referenced by InitSoundClient(), and VolumeForDistance().
1.5.6