allow any CompoundPart to gain focus, if it canGainFocus()
[openc2e.git] / caosVM_sounds.cpp
blobf4d9e3fe0746cdbdf7851e22f1980719ce1b982e
1 /*
2 * caosVM_sounds.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Tue Jun 01 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "openc2e.h"
21 #include "caosVM.h"
22 #include "Agent.h"
23 #include "World.h"
24 #include "Engine.h"
25 #include "AudioBackend.h"
26 #include <iostream>
27 using std::cout;
28 using std::cerr;
30 #include "Backend.h" // hack for now
32 bool agentOnCamera(Agent *targ, bool checkall = false); // caosVM_camera.cpp
34 /**
35 SNDE (command) filename (string)
36 %status maybe
38 Play an uncontrolled sound at the target agent's current position.
40 void caosVM::c_SNDE() {
41 VM_VERIFY_SIZE(1)
42 VM_PARAM_STRING(filename)
44 valid_agent(targ);
45 if (world.camera.getMetaRoom() != world.map.metaRoomAt(targ->x, targ->y) || !agentOnCamera(targ)) return; // TODO: is it correct behaviour for only onscreen agents to play?
46 targ->playAudio(filename, false, false);
49 /**
50 SNDE (command) filename (bareword)
51 %status maybe
52 %pragma variants c1 c2
53 %cost c1,c2 0
55 Play an uncontrolled sound at the target agent's current position.
58 /**
59 SNDV (command) filename (string)
60 %status maybe
61 %pragma variants c1
62 %pragma implementation caosVM::c_SNDE
63 %cost c1,c2 0
65 Play an uncontrolled sound at the target agent's current position.
68 /**
69 SNDC (command) filename (string)
70 %status maybe
72 Start playing a controlled sound with the target agent, which will follow the agent as it moves.
74 void caosVM::c_SNDC() {
75 VM_VERIFY_SIZE(1)
76 VM_PARAM_STRING(filename)
78 valid_agent(targ);
79 if (world.camera.getMetaRoom() != world.map.metaRoomAt(targ->x, targ->y) || !agentOnCamera(targ)) return; // TODO: is it correct behaviour for only onscreen agents to play?
80 targ->playAudio(filename, true, false);
83 /**
84 SNDC (command) filename (bareword)
85 %status maybe
86 %pragma variants c1 c2
87 %cost c1,c2 0
89 Start playing a controlled sound with the target agent, which will follow the agent as it moves.
92 /**
93 SNDL (command) filename (string)
94 %status maybe
96 Start playing a looping controlled sound with the target agent, which will follow the agent as it moves.
98 void caosVM::c_SNDL() {
99 VM_VERIFY_SIZE(1)
100 VM_PARAM_STRING(filename)
102 valid_agent(targ);
103 targ->playAudio(filename, true, true);
107 SNDL (command) filename (bareword)
108 %status maybe
109 %pragma variants c1 c2
110 %cost c1,c2 0
112 Start playing a looping controlled sound with the target agent, which will follow the agent as it moves.
116 MMSC (command) x (integer) y (integer) track_name (string)
117 %status stub
119 void caosVM::c_MMSC() {
120 VM_VERIFY_SIZE(3)
121 VM_PARAM_STRING(track_name)
122 VM_PARAM_INTEGER(y)
123 VM_PARAM_INTEGER(x)
124 // TODO
128 MMSC (string) x (integer) y (integer)
129 %status stub
131 void caosVM::v_MMSC() {
132 VM_VERIFY_SIZE(2)
133 VM_PARAM_INTEGER(y)
134 VM_PARAM_INTEGER(x)
135 // TODO
136 result.setString("");
140 RMSC (command) x (integer) y (integer) track_name (string)
141 %status stub
143 void caosVM::c_RMSC() {
144 VM_VERIFY_SIZE(3)
145 VM_PARAM_STRING(track_name)
146 VM_PARAM_INTEGER(y)
147 VM_PARAM_INTEGER(x)
148 // TODO
152 RMSC (string) x (integer) y (integer)
153 %status stub
155 void caosVM::v_RMSC() {
156 VM_VERIFY_SIZE(2)
157 VM_PARAM_INTEGER(y)
158 VM_PARAM_INTEGER(x)
159 // TODO
160 result.setString("");
164 FADE (command)
165 %status maybe
166 %pragma variants c1 c2 cv c3 sm
167 %cost c1,c2 0
169 void caosVM::c_FADE() {
170 VM_VERIFY_SIZE(0)
172 valid_agent(targ);
173 if (targ->sound)
174 targ->sound->fadeOut();
178 STPC (command)
179 %status maybe
180 %pragma variants c1 c2 cv c3 sm
181 %cost c1,c2 0
183 void caosVM::c_STPC() {
184 valid_agent(targ);
185 targ->sound.reset();
189 STRK (command) latency (integer) track (string)
190 %status stub
192 Play the specified music track. It will play for at least latency seconds.
194 void caosVM::c_STRK() {
195 VM_PARAM_STRING(track)
196 VM_PARAM_INTEGER(latency)
198 // TODO
202 VOLM (command) type (integer) volume (integer)
203 %status stub
205 Changes the volume of the specified type of audio; 0 for sound effects, 1 for midi or 2 for dynamic music.
206 Volume is from -10000 (silent) to 0 (maximum).
208 void caosVM::c_VOLM() {
209 VM_PARAM_INTEGER(volume)
210 VM_PARAM_INTEGER(type)
212 // TODO
216 VOLM (integer) type (integer)
217 %status stub
219 Return the volumne of the specified type of audio; 0 for sound effects, 1 for midi or 2 for dynamic music.
220 Volume is from -10000 (silent) to 0 (maximum).
222 void caosVM::v_VOLM() {
223 VM_PARAM_INTEGER(type)
225 result.setInt(0); // TODO
229 MUTE (integer) andmask (integer) eormask (integer)
230 %status maybe
232 This returns/sets information about which types of in-game audio are muted.
233 Set andmask for the information you want returned, and eormask for the information you want changed.
234 1 is for normal sound, and 2 is for music (so 3 is for both combined).
236 void caosVM::v_MUTE() {
237 VM_PARAM_INTEGER(eormask)
238 VM_PARAM_INTEGER(andmask)
240 // TODO: we should maintain state despite having no audio engine, probably
241 // (UI scripting assumes changes were successful)
242 if (!engine.audio) {
243 result.setInt(0);
244 return;
247 // TODO: music
249 if (eormask & 1) engine.audio->setMute(!engine.audio->isMuted());
251 int r = 0;
252 if (andmask & 1 && engine.audio->isMuted()) r += 1;
253 result.setInt(r);
257 SEZZ (command) text (string)
258 %status stub
260 void caosVM::c_SEZZ() {
261 VM_PARAM_STRING(text)
263 valid_agent(targ);
265 // TODO
269 VOIS (command) voice (string)
270 %status stub
272 void caosVM::c_VOIS() {
273 VM_PARAM_STRING(voice)
275 valid_agent(targ);
277 // TODO
281 MIDI (command) midifile (string)
282 %status stub
284 Plays the MIDI file specified, or stops playing if passed an empty string.
286 void caosVM::c_MIDI() {
287 VM_PARAM_STRING(midifile)
289 // TODO
293 PLDS (command) filename (bareword)
294 %status stub
295 %pragma variants c1 c2
297 Preload the specified sound file if TARG is visible or just offscreen.
299 void caosVM::c_PLDS() {
300 VM_PARAM_STRING(filename)
302 valid_agent(targ);
303 if (world.camera.getMetaRoom() != world.map.metaRoomAt(targ->x, targ->y)) return; // TODO: needs better check ;)
305 // TODO
308 /* vim: set noet: */