Debian Codegraph @

engine/include/sound.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name sound.h - The sound header file. */
11 //
12 // (c) Copyright 1998-2007 by Lutz Sammer, Fabrice Rossi, and Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef __SOUND_H__
29 #define __SOUND_H__
30
31 //@{
32
33 /*----------------------------------------------------------------------------
34 -- Includes
35 ----------------------------------------------------------------------------*/
36
37 #include <vector>
38
39 #include "unit.h"
40 #include "unitsound.h"
41 #include "player.h"
42
43 /*----------------------------------------------------------------------------
44 -- Declarations
45 ----------------------------------------------------------------------------*/
46
47 class CUnit;
48 class Missile;
49 class CSample;
50 class LuaActionListener;
51
52 /*----------------------------------------------------------------------------
53 -- Definitons
54 ----------------------------------------------------------------------------*/
55
56 #define MaxSampleVolume 255 /// Maximum sample volume
57 #define NO_SOUND 0 /// No valid sound ID
58
59 /**
60 ** Global game sounds, not associated to any unit-type
61 */
62 class GameSound
63 {
64 public:
65 SoundConfig PlacementError; /// used by ui
66 SoundConfig PlacementSuccess; /// used by ui
67 SoundConfig Click; /// used by ui
68 SoundConfig Docking; /// ship reaches coast
69 SoundConfig BuildingConstruction; /// building under construction
70 SoundConfig Rescue; /// rescue units
71 SoundConfig ChatMessage; /// chat message
72 };
73
74 /**
75 ** Sound definition.
76 */
77 class CSound {
78 public:
79 CSound() : Range(0), Number(0)
80 {
81 memset(&Sound, 0, sizeof(Sound));
82 }
83 ~CSound();
84
85 /**
86 ** Range is a multiplier for ::DistanceSilent.
87 ** 255 means infinite range of the sound.
88 */
89 unsigned char Range; /// Range is a multiplier for DistanceSilent
90 unsigned char Number; /// single, group, or table of sounds.
91 union {
92 CSample *OneSound; /// if it's only a simple sound
93 CSample **OneGroup; /// when it's a simple group
94 struct {
95 CSound *First; /// first group: selected sound
96 CSound *Second; /// second group: annoyed sound
97 } TwoGroups; /// when it's a double group
98 } Sound;
99 };
100
101 /**
102 ** A possible value for Number in the Sound struct: means a simple sound
103 */
104 #define ONE_SOUND 0
105 /**
106 ** A possible value for Number in the Sound struct: means a double group (for
107 ** selection/annoyed sounds)
108 */
109 #define TWO_GROUPS 1
110
111 /**
112 ** the range value that makes a sound volume distance independent
113 */
114 #define INFINITE_SOUND_RANGE 255
115 /**
116 ** the maximum range value
117 */
118 #define MAX_SOUND_RANGE 254
119
120 /**
121 ** Origin of a sound
122 */
123 struct Origin {
124 const void *Base; /// pointer on a Unit
125 int Id; /// unique identifier (if the pointer has been shared)
126 };
127
128
129 /*----------------------------------------------------------------------------
130 -- Variables
131 ----------------------------------------------------------------------------*/
132
133 extern GameSound GameSounds; /// Game sound configuration
134
135 extern bool CallbackMusic; /// flag true callback ccl if stops
136
137 /// global range control (max cut off distance for sound)
138 extern int DistanceSilent;
139
140 /*----------------------------------------------------------------------------
141 -- Functions
142 ----------------------------------------------------------------------------*/
143
144 /// Play a unit sound
145 extern void PlayUnitSound(const CUnit *unit, UnitVoiceGroup unit_voice_group);
146 /// Play a unit sound
147 extern void PlayUnitSound(const CUnit *unit, CSound *sound);
148 /// Play a missile sound
149 extern void PlayMissileSound(const Missile *missile, CSound *sound);
150 /// Play a game sound
151 extern void PlayGameSound(CSound *sound, unsigned char volume);
152
153 /// Play a sound file
154 extern int PlayFile(const std::string &name, LuaActionListener *listener = NULL);
155
156 /// Modify the range of a given sound.
157 extern void SetSoundRange(CSound *sound, unsigned char range);
158
159 /// Register a sound (can be a simple sound or a group)
160 extern CSound *RegisterSound(const char *files[], unsigned number);
161
162 /// Create a special sound group with two sounds
163 extern CSound *RegisterTwoGroups(CSound *first, CSound *second);
164
165 /// Initialize client side of the sound layer.
166 extern void InitSoundClient(void);
167
168
169 // music.cpp
170
171 /// Check if music is finished and play the next song
172 extern void CheckMusicFinished(bool force = false);
173
174 /// Initialize music
175 extern void InitMusic(void);
176
177 /// Turn music stopped callback on
178 #define CallbackMusicOn() \
179 CallbackMusic = true;
180 /// Turn music stopped callback off
181 #define CallbackMusicOff() \
182 CallbackMusic = false;
183
184
185 // sound_id.cpp
186
187 /// Map sound to identifier
188 extern void MapSound(const std::string &sound_name, CSound *id);
189 /// Get the sound id bound to an identifier
190 extern CSound *SoundForName(const std::string &sound_name);
191 /// Make a sound bound to identifier
192 extern CSound *MakeSound(const std::string &sound_name, const char *file[], int nb);
193 /// Make a sound group bound to identifier
194 extern CSound *MakeSoundGroup(const std::string &name, CSound *first, CSound *second);
195 #ifdef DEBUG
196 extern void FreeSounds();
197 #endif
198
199
200 // script_sound.cpp
201
202 /// register ccl features
203 extern void SoundCclRegister(void);
204
205
206 //@}
207
208 #endif // !__SOUND_H__