1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #include "engines/icb/common/ptr_util.h"
29 #include "engines/icb/debug.h"
30 #include "engines/icb/mission.h"
31 #include "engines/icb/global_objects.h"
32 #include "engines/icb/sound.h"
33 
34 namespace ICB {
35 
fn_play_sfx(int32 & result,int32 * params)36 mcodeFunctionReturnCodes fn_play_sfx(int32 &result, int32 *params) { return (MS->fn_play_sfx(result, params)); }
37 
fn_stop_sfx(int32 & result,int32 * params)38 mcodeFunctionReturnCodes fn_stop_sfx(int32 &result, int32 *params) { return (MS->fn_stop_sfx(result, params)); }
39 
fn_play_sfx_xyz(int32 & result,int32 * params)40 mcodeFunctionReturnCodes fn_play_sfx_xyz(int32 &result, int32 *params) { return (MS->fn_play_sfx_xyz(result, params)); }
41 
fn_play_sfx_offset(int32 & result,int32 * params)42 mcodeFunctionReturnCodes fn_play_sfx_offset(int32 &result, int32 *params) { return (MS->fn_play_sfx_offset(result, params)); }
43 
fn_play_sfx_time(int32 & result,int32 * params)44 mcodeFunctionReturnCodes fn_play_sfx_time(int32 &result, int32 *params) { return (MS->fn_play_sfx_time(result, params)); }
45 
fn_play_sfx_offset_time(int32 & result,int32 * params)46 mcodeFunctionReturnCodes fn_play_sfx_offset_time(int32 &result, int32 *params) { return (MS->fn_play_sfx_offset_time(result, params)); }
47 
fn_play_sfx_special(int32 & result,int32 * params)48 mcodeFunctionReturnCodes fn_play_sfx_special(int32 &result, int32 *params) { return (MS->fn_play_sfx_special(result, params)); }
49 
fn_set_sfx(int32 & result,int32 * params)50 mcodeFunctionReturnCodes fn_set_sfx(int32 &result, int32 *params) { return (MS->fn_set_sfx(result, params)); }
51 
52 // fn_set_sfx("sfx name","sfx");
53 // where name can be:
54 // gunshot      0
55 // ricochet     1
56 // tinkle       2
57 // open         0
58 // close        1
fn_set_sfx(int32 &,int32 * params)59 mcodeFunctionReturnCodes _game_session::fn_set_sfx(int32 &, int32 *params) {
60 	int32 whichVar;
61 
62 	const char *name = (const char *)MemoryUtil::resolvePtr(params[0]);
63 	const char *sfx = (const char *)MemoryUtil::resolvePtr(params[1]);
64 
65 	// none
66 	whichVar = -1;
67 
68 	// check for them all
69 	if (strcmp(name, "gunshot") == 0)
70 		whichVar = GUNSHOT_SFX_VAR;
71 	if (strcmp(name, "ricochet") == 0)
72 		whichVar = RICOCHET_SFX_VAR;
73 	if (strcmp(name, "tinkle") == 0)
74 		whichVar = TINKLE_SFX_VAR;
75 	if (strcmp(name, "open") == 0)
76 		whichVar = OPEN_SFX_VAR;
77 	if (strcmp(name, "close") == 0)
78 		whichVar = CLOSE_SFX_VAR;
79 
80 	if (whichVar == -1)
81 		Fatal_error("error message, in fn_sound.cpp, quite friendly and polite. You are trying to do "
82 		            "fn_set_sfx(\"%s\",\"%s\"), but I don't know what you mean by \"%s\". I support gunshot, ricochet, tinkle, "
83 		            "open and close\n",
84 		            name, sfx, name);
85 
86 	logic_structs[cur_id]->sfxVars[whichVar] = HashString(sfx);
87 
88 	return IR_CONT;
89 }
90 
91 // fn_play_sfx_xyz("sfx","id");
fn_play_sfx(int32 &,int32 * params)92 mcodeFunctionReturnCodes _game_session::fn_play_sfx(int32 &, int32 *params) {
93 	const char *sfx = (const char *)MemoryUtil::resolvePtr(params[0]);
94 	const char *id = (const char *)MemoryUtil::resolvePtr(params[1]);
95 
96 	RegisterSound(cur_id, sfx, id);
97 	return (IR_CONT);
98 }
99 
100 // fn_play_sfx_xyz("sfx","id",x,y,z);
fn_play_sfx_xyz(int32 &,int32 * params)101 mcodeFunctionReturnCodes _game_session::fn_play_sfx_xyz(int32 &, int32 *params) {
102 	const char *sfx = (const char *)MemoryUtil::resolvePtr(params[0]);
103 	const char *id = (const char *)MemoryUtil::resolvePtr(params[1]);
104 	RegisterSoundAbsolute(cur_id, sfx, id, (PXreal)params[2], (PXreal)params[3], (PXreal)params[4]);
105 	return (IR_CONT);
106 }
107 
108 // fn_play_sfx_offset("object","sound","id",x,y,z,is_nico);
fn_play_sfx_offset(int32 &,int32 * params)109 mcodeFunctionReturnCodes _game_session::fn_play_sfx_offset(int32 &, int32 *params) {
110 	const char *obj = (const char *)MemoryUtil::resolvePtr(params[0]);
111 	const char *sound = (const char *)MemoryUtil::resolvePtr(params[1]);
112 	const char *id = (const char *)MemoryUtil::resolvePtr(params[2]);
113 
114 	RegisterSoundOffset(cur_id, obj, sound, id, (PXreal)params[3], (PXreal)params[4], (PXreal)params[5], (int32)params[6], 0);
115 	return (IR_CONT);
116 }
117 
118 // fn_play_sfx_time("sfx","id",time);
fn_play_sfx_time(int32 &,int32 * params)119 mcodeFunctionReturnCodes _game_session::fn_play_sfx_time(int32 &, int32 *params) {
120 	const char *sfx = (const char *)MemoryUtil::resolvePtr(params[0]);
121 	const char *id = (const char *)MemoryUtil::resolvePtr(params[1]);
122 	RegisterSoundTime(cur_id, sfx, id, (int32)params[2]);
123 	return (IR_CONT);
124 }
125 
126 // fn_play_sfx_offset_time("object","sound","id",x,y,z,is_nico,time);
fn_play_sfx_offset_time(int32 &,int32 * params)127 mcodeFunctionReturnCodes _game_session::fn_play_sfx_offset_time(int32 &, int32 *params) {
128 	const char *obj = (const char *)MemoryUtil::resolvePtr(params[0]);
129 	const char *sound = (const char *)MemoryUtil::resolvePtr(params[1]);
130 	const char *id = (const char *)MemoryUtil::resolvePtr(params[2]);
131 
132 	RegisterSoundOffset(cur_id, obj, sound, id, (PXreal)params[3], (PXreal)params[4], (PXreal)params[5], (int32)params[6], (int32)params[7]);
133 	return (IR_CONT);
134 }
135 
136 // fn_play_sfx_special("sfx","id",volume,pan);
fn_play_sfx_special(int32 &,int32 * params)137 mcodeFunctionReturnCodes _game_session::fn_play_sfx_special(int32 &, int32 *params) {
138 	const char *sfx = (const char *)MemoryUtil::resolvePtr(params[0]);
139 	const char *id = (const char *)MemoryUtil::resolvePtr(params[1]);
140 
141 	int32 vol, pan;
142 
143 	vol = params[2];
144 	pan = params[3];
145 
146 	if ((vol < 0) || (vol > 127))
147 		Fatal_error("volume out of range in fn_play_sfx_special (you did %d max is 127)", vol);
148 
149 	if ((pan < -127) || (pan > 127))
150 		Fatal_error("pan out of range in fn_play_sfx_special (you did %d range is -127-127)", pan);
151 
152 	RegisterSoundSpecial(sfx, id, vol, pan);
153 	return (IR_CONT);
154 }
155 
156 // fn_stop_sfx("id");
fn_stop_sfx(int32 &,int32 * params)157 mcodeFunctionReturnCodes _game_session::fn_stop_sfx(int32 &, int32 *params) {
158 	// snd is full string
159 	const char *snd = (const char *)MemoryUtil::resolvePtr(params[0]);
160 
161 	// see if :: in filename...
162 	const char *sub = strstr(const_cast<char *>(snd), "::");
163 
164 	// if object name is given in form obj::snd then extract both parts
165 	if (sub != NULL) {
166 		char tempObj[64];
167 		char tempSnd[64];
168 
169 		// first part (obj)
170 		strncpy(tempObj, const_cast<char *>(snd), sub - snd);
171 		tempObj[sub - snd] = 0; // null terminate
172 
173 		strcpy(tempSnd, sub + strlen("::"));
174 
175 		int32 obj = MS->objects->Fetch_item_number_by_name(tempObj);
176 
177 		if (obj != -1)
178 			RemoveRegisteredSound(obj, tempSnd);
179 	}
180 	// otherwise sound is of this object
181 	else
182 		RemoveRegisteredSound(cur_id, snd);
183 
184 	return (IR_CONT);
185 }
186 
fn_play_common_xa_music(int32 &,int32 *)187 mcodeFunctionReturnCodes fn_play_common_xa_music(int32 &, int32 * /*params*/) {
188 	Fatal_error("fn_play_common_xa_music() no longer supported");
189 	return (IR_CONT);
190 }
191 
fn_play_common_vag_music(int32 &,int32 *)192 mcodeFunctionReturnCodes fn_play_common_vag_music(int32 &, int32 * /*params*/) {
193 	Fatal_error("fn_play_common_vag_music() no longer supported");
194 	return (IR_CONT);
195 }
196 
fn_play_mission_xa_music(int32 &,int32 *)197 mcodeFunctionReturnCodes fn_play_mission_xa_music(int32 &, int32 * /*params*/) {
198 	Fatal_error("fn_play_mission_xa_music() no longer supported");
199 	return (IR_CONT);
200 }
201 
fn_play_mission_vag_music(int32 &,int32 *)202 mcodeFunctionReturnCodes fn_play_mission_vag_music(int32 &, int32 * /*params*/) {
203 	Fatal_error("fn_play_mission_vag_music() no longer supported");
204 	return (IR_CONT);
205 }
206 
fn_play_common_fx(int32 &,int32 *)207 mcodeFunctionReturnCodes fn_play_common_fx(int32 &, int32 * /*params*/) {
208 	Fatal_error("fn_play_common_fx() no longer supported");
209 	return (IR_CONT);
210 }
211 
fn_play_mission_fx(int32 &,int32 *)212 mcodeFunctionReturnCodes fn_play_mission_fx(int32 &, int32 * /*params*/) {
213 	Fatal_error("fn_play_mission_fx() no longer supported");
214 	return (IR_CONT);
215 }
216 
217 } // End of namespace ICB
218