_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

sound.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2007 by Lutz Sammer, Fabrice Rossi, and Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __SOUND_H__
31 #define __SOUND_H__
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include "unitsound.h"
40 #include "SDL.h"
41 #include "SDL_mixer.h"
42 
43 /*----------------------------------------------------------------------------
44 -- Declarations
45 ----------------------------------------------------------------------------*/
46 
47 class CUnit;
48 class Missile;
49 class LuaActionListener;
50 
51 /*----------------------------------------------------------------------------
52 -- Definitons
53 ----------------------------------------------------------------------------*/
54 
55 #define MaxSampleVolume 255
56 #define NO_SOUND 0
57 
58 
74 };
75 
76 
80 class GameSound
81 {
82 public:
94 };
95 
99 class CSound
100 {
101 public:
102  CSound() : Mapref(0), Range(0), Number(0)
103  {
104  memset(&Sound, 0, sizeof(Sound));
105  }
106  ~CSound();
107  unsigned int Mapref;
112  unsigned char Range;
113  unsigned char Number;
114  union {
115  Mix_Chunk *OneSound;
116  Mix_Chunk **OneGroup;
117  struct {
120  } TwoGroups;
121  } Sound;
122 };
123 
127 #define ONE_SOUND 0
128 
132 #define TWO_GROUPS 1
133 
137 #define INFINITE_SOUND_RANGE 255
138 
141 #define MAX_SOUND_RANGE 254
142 
146 struct Origin {
147  const void *Base;
148  unsigned Id;
149 };
150 
151 
152 /*----------------------------------------------------------------------------
153 -- Variables
154 ----------------------------------------------------------------------------*/
155 
156 extern GameSound GameSounds;
157 
159 extern int DistanceSilent;
160 
161 /*----------------------------------------------------------------------------
162 -- Functions
163 ----------------------------------------------------------------------------*/
164 
166 extern unsigned char CalculateVolume(bool isVolume, int power, unsigned char range);
168 extern void PlayUnitSound(const CUnit &unit, UnitVoiceGroup unit_voice_group, bool sampleUnique = false);
170 extern void PlayUnitSound(const CUnit &unit, CSound *sound);
172 extern void PlayMissileSound(const Missile &missile, CSound *sound);
174 extern void PlayGameSound(CSound *sound, unsigned char volume, bool always = false);
175 
177 extern int PlayFile(const std::string &name, LuaActionListener *listener = NULL);
178 
180 extern void SetSoundRange(CSound *sound, unsigned char range);
181 
183 extern CSound *RegisterSound(const std::vector<std::string> &files);
184 
186 extern CSound *RegisterTwoGroups(CSound *first, CSound *second);
187 
189 extern void InitSoundClient();
190 
191 
192 // music.cpp
193 
195 extern void InitMusic();
196 
198 extern void CallbackMusicEnable();
199 
201 extern void CallbackMusicDisable();
202 
204 extern void CallbackMusicTrigger();
205 
206 // sound_id.cpp
207 
209 extern void MapSound(const std::string &sound_name, CSound *id);
211 extern CSound *SoundForName(const std::string &sound_name);
213 extern CSound *MakeSound(const std::string &sound_name, const std::vector<std::string> &files);
215 extern CSound *MakeSoundGroup(const std::string &name, CSound *first, CSound *second);
216 
217 extern void FreeSounds();
218 
219 // script_sound.cpp
220 
222 extern void SoundCclRegister();
223 
224 
226 
227 #endif // !__SOUND_H__
InitSoundClient
void InitSoundClient()
Initialize client side of the sound layer.
Definition: sound.cpp:526
SetSoundRange
void SetSoundRange(CSound *sound, unsigned char range)
Modify the range of a given sound.
Definition: sound.cpp:453
VoiceDying
@ VoiceDying
If attacked.
Definition: sound.h:66
CSound::OneSound
Mix_Chunk * OneSound
Definition: sound.h:115
CSound::Mapref
unsigned int Mapref
Definition: sound.h:107
GameSound::NotEnoughRes
SoundConfig NotEnoughRes[MAX_RACES][MaxCosts]
research complete message
Definition: sound.h:92
MaxCosts
@ MaxCosts
resource 6
Definition: upgrade_structs.h:70
LuaActionListener
Definition: widgets.h:50
CSound::~CSound
~CSound()
Definition: sound.cpp:594
CSound
Definition: sound.h:99
CallbackMusicDisable
void CallbackMusicDisable()
Skip the next music stopped callback invocation.
Definition: music.cpp:122
UnitVoiceGroup
UnitVoiceGroup
Definition: sound.h:61
CSound::Number
unsigned char Number
Range is a multiplier for DistanceSilent.
Definition: sound.h:113
CSound::Sound
union CSound::@38 Sound
single, group, or table of sounds.
Origin::Base
const void * Base
Definition: sound.h:147
GameSound
Definition: sound.h:80
CallbackMusicTrigger
void CallbackMusicTrigger()
Turn music stopped callback on and trigger it immediately.
Definition: music.cpp:126
VoiceBuilding
@ VoiceBuilding
only worker, work completed
Definition: sound.h:68
SoundConfig
Definition: unitsound.h:54
VoiceBuild
@ VoiceBuild
Attack command.
Definition: sound.h:73
GameSounds
GameSound GameSounds
Definition: sound.cpp:57
VoiceReady
@ VoiceReady
Acknowledge command.
Definition: sound.h:64
VoiceWorkCompleted
@ VoiceWorkCompleted
If killed.
Definition: sound.h:67
GameSound::BuildingConstruction
SoundConfig BuildingConstruction[MAX_RACES]
ship reaches coast
Definition: sound.h:87
VoiceHarvesting
@ VoiceHarvesting
repairing
Definition: sound.h:71
CSound::OneGroup
Mix_Chunk ** OneGroup
if it's only a simple sound
Definition: sound.h:116
PlayUnitSound
void PlayUnitSound(const CUnit &unit, UnitVoiceGroup unit_voice_group, bool sampleUnique=false)
Play a unit sound.
Definition: sound.cpp:281
InitMusic
void InitMusic()
Initialize music.
Definition: music.cpp:109
GameSound::NotEnoughFood
SoundConfig NotEnoughFood[MAX_RACES]
not enough resources message
Definition: sound.h:93
CSound::Range
unsigned char Range
Definition: sound.h:112
MapSound
void MapSound(const std::string &sound_name, CSound *id)
Map sound to identifier.
Definition: sound_id.cpp:71
SoundForName
CSound * SoundForName(const std::string &sound_name)
Get the sound id bound to an identifier.
Definition: sound_id.cpp:88
PlayFile
int PlayFile(const std::string &name, LuaActionListener *listener=NULL)
Play a sound file.
Definition: sound.cpp:429
VoiceSelected
@ VoiceSelected
Definition: sound.h:62
VoiceHelpMe
@ VoiceHelpMe
Command completed.
Definition: sound.h:65
VoiceAcknowledging
@ VoiceAcknowledging
If selected.
Definition: sound.h:63
VoiceAttack
@ VoiceAttack
harvesting
Definition: sound.h:72
DistanceSilent
int DistanceSilent
Game sound configuration.
Definition: sound.cpp:72
PlayMissileSound
void PlayMissileSound(const Missile &missile, CSound *sound)
Play a missile sound.
Definition: sound.cpp:350
CSound::First
CSound * First
Definition: sound.h:118
GameSound::PlacementSuccess
SoundConfig PlacementSuccess[MAX_RACES]
used by ui
Definition: sound.h:84
GameSound::PlacementError
SoundConfig PlacementError[MAX_RACES]
Definition: sound.h:83
CSound::Second
CSound * Second
first group: selected sound
Definition: sound.h:119
CSound::TwoGroups
struct CSound::@38::@39 TwoGroups
when it's a simple group
CallbackMusicEnable
void CallbackMusicEnable()
Turn music stopped callback on.
Definition: music.cpp:118
RegisterSound
CSound * RegisterSound(const std::vector< std::string > &files)
Register a sound (can be a simple sound or a group)
Definition: sound.cpp:472
RegisterTwoGroups
CSound * RegisterTwoGroups(CSound *first, CSound *second)
Create a special sound group with two sounds.
Definition: sound.cpp:509
MakeSound
CSound * MakeSound(const std::string &sound_name, const std::vector< std::string > &files)
Make a sound bound to identifier.
Definition: sound_id.cpp:111
GameSound::ResearchComplete
SoundConfig ResearchComplete[MAX_RACES]
chat message
Definition: sound.h:91
GameSound::Click
SoundConfig Click
used by ui
Definition: sound.h:85
FreeSounds
void FreeSounds()
Definition: sound_id.cpp:156
VoiceRepairing
@ VoiceRepairing
only for transport reaching coast
Definition: sound.h:70
GameSound::WorkComplete
SoundConfig WorkComplete[MAX_RACES]
building under construction
Definition: sound.h:88
CSound::CSound
CSound()
Definition: sound.h:102
PlayGameSound
void PlayGameSound(CSound *sound, unsigned char volume, bool always=false)
Play a game sound.
Definition: sound.cpp:380
unitsound.h
GameSound::ChatMessage
SoundConfig ChatMessage
rescue units
Definition: sound.h:90
Origin
Definition: sound.h:146
SoundCclRegister
void SoundCclRegister()
register ccl features
Definition: script_sound.cpp:364
GameSound::Docking
SoundConfig Docking
used by ui
Definition: sound.h:86
CalculateVolume
unsigned char CalculateVolume(bool isVolume, int power, unsigned char range)
Calculates volume level.
Definition: sound.cpp:251
MAX_RACES
constexpr unsigned char MAX_RACES
How many upgrades supported.
Definition: settings.h:65
Origin::Id
unsigned Id
pointer on a Unit
Definition: sound.h:148
MakeSoundGroup
CSound * MakeSoundGroup(const std::string &name, CSound *first, CSound *second)
Make a sound group bound to identifier.
Definition: sound_id.cpp:140
VoiceDocking
@ VoiceDocking
only for building under construction
Definition: sound.h:69
GameSound::Rescue
SoundConfig Rescue[MAX_RACES]
building ready
Definition: sound.h:89
CUnit
The big unit structure.
Definition: unit.h:135
Missile
Missile on the map.
Definition: missile.h:413
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.