Debian Codegraph @

engine/sound/unitsound.cpp

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 unitsound.cpp - The unit sounds. */
11 //
12 // (c) Copyright 1999-2007 by 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
29 //@{
30
31 /*----------------------------------------------------------------------------
32 -- Include
33 ----------------------------------------------------------------------------*/
34
35 #include "stratagus.h"
36 #include "sound.h"
37 #include "sound_server.h"
38 #include "unittype.h"
39 #include "animation.h"
40
41 /*----------------------------------------------------------------------------
42 -- Functions
43 ----------------------------------------------------------------------------*/
44
45 /**
46 ** Load all sounds for units.
47 */
48 void LoadUnitSounds(void)
49 {
50 }
51
52 /**
53 ** Map animation sounds
54 */
55 static void MapAnimSounds2(CAnimation *anim)
56 {
57 while (anim) {
58 if (anim->Type == AnimationSound) {
59 anim->D.Sound.Sound = SoundForName(anim->D.Sound.Name);
60 } else if (anim->Type == AnimationRandomSound) {
61 for (int i = 0; i < anim->D.RandomSound.NumSounds; ++i) {
62 anim->D.RandomSound.Sound[i] = SoundForName(anim->D.RandomSound.Name[i]);
63 }
64 }
65 anim = anim->Next;
66 }
67 }
68
69 /**
70 ** Map animation sounds for a unit type
71 */
72 static void MapAnimSounds(CUnitType *type)
73 {
74 if (!type->Animations) {
75 return;
76 }
77
78 MapAnimSounds2(type->Animations->Start);
79 MapAnimSounds2(type->Animations->Still);
80 MapAnimSounds2(type->Animations->Death);
81 MapAnimSounds2(type->Animations->Attack);
82 MapAnimSounds2(type->Animations->Move);
83 MapAnimSounds2(type->Animations->Repair);
84 MapAnimSounds2(type->Animations->Train);
85 MapAnimSounds2(type->Animations->Harvest);
86 }
87
88 /**
89 ** Map the sounds of all unit-types to the correct sound id.
90 ** And overwrite the sound ranges. @todo the sound ranges should be
91 ** configurable by user with lua.
92 */
93 void MapUnitSounds(void)
94 {
95 if (SoundEnabled()) {
96 //
97 // Parse all units sounds.
98 //
99 for (size_t i = 0; i < UnitTypes.size(); ++i) {
100 CUnitType *type = UnitTypes[i];
101
102 MapAnimSounds(type);
103
104 if (!type->Sound.Selected.Name.empty()) {
105 type->Sound.Selected.Sound =
106 SoundForName(type->Sound.Selected.Name);
107 }
108 if (!type->Sound.Acknowledgement.Name.empty()) {
109 type->Sound.Acknowledgement.Sound =
110 SoundForName(type->Sound.Acknowledgement.Name);
111 /*
112 // Acknowledge sounds have infinite range
113 SetSoundRange(type->Sound.Acknowledgement.Sound,
114 INFINITE_SOUND_RANGE);
115 */
116 }
117 if (!type->Sound.Ready.Name.empty()) {
118 type->Sound.Ready.Sound =
119 SoundForName(type->Sound.Ready.Name);
120 // Ready sounds have infinite range
121 SetSoundRange(type->Sound.Ready.Sound,
122 INFINITE_SOUND_RANGE);
123 }
124 if (!type->Sound.Help.Name.empty()) {
125 type->Sound.Help.Sound =
126 SoundForName(type->Sound.Help.Name);
127 // Help sounds have infinite range
128 SetSoundRange(type->Sound.Help.Sound,
129 INFINITE_SOUND_RANGE);
130 }
131 if (!type->Sound.Dead.Name.empty()) {
132 type->Sound.Dead.Sound =
133 SoundForName(type->Sound.Dead.Name);
134 }
135 }
136 }
137 }
138
139 //@}