2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
// BROKEN SWORD 2
|
|
|
|
//
|
2003-09-20 12:43:52 +00:00
|
|
|
// SOUND.CPP Contains the sound engine, fx & music functions
|
|
|
|
// Some very 'sound' code in here ;)
|
2003-07-28 01:44:38 +00:00
|
|
|
//
|
|
|
|
// (16Dec96 JEL)
|
|
|
|
//
|
2003-09-20 12:43:52 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/file.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/defs.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/interpreter.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/resman.h"
|
|
|
|
#include "sword2/driver/d_sound.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
// initialise the fxq by clearing all the entries
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
void Sword2Engine::initFxQueue(void) {
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
_fxQueue[i].resource = 0; // 0 resource means 'empty' slot
|
|
|
|
_fxQueue[i].fetchId = 0; // Not being fetched.
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// process the fx queue once every game cycle
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
void Sword2Engine::processFxQueue(void) {
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (!_fxQueue[i].resource)
|
2003-09-20 12:43:52 +00:00
|
|
|
continue;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
switch (_fxQueue[i].type) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case FX_RANDOM:
|
|
|
|
// 1 in 'delay' chance of this fx occurring
|
2003-11-03 07:47:42 +00:00
|
|
|
if (_rnd.getRandomNumber(_fxQueue[i].delay) == 0)
|
|
|
|
triggerFx(i);
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FX_SPOT:
|
2003-11-03 07:47:42 +00:00
|
|
|
if (_fxQueue[i].delay)
|
|
|
|
_fxQueue[i].delay--;
|
2003-09-21 16:11:26 +00:00
|
|
|
else {
|
2003-11-03 07:47:42 +00:00
|
|
|
triggerFx(i);
|
|
|
|
_fxQueue[i].type = FX_SPOT2;
|
2003-09-21 16:11:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FX_SPOT2:
|
|
|
|
// Once the Fx has finished remove it from the queue.
|
2004-01-03 11:24:39 +00:00
|
|
|
if (!_sound->isFxPlaying(i + 1)) {
|
2003-11-03 07:47:42 +00:00
|
|
|
_fxQueue[i].resource = 0;
|
2004-01-03 11:24:39 +00:00
|
|
|
_sound->closeFx(i + 1);
|
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// called from processFxQueue only
|
2003-09-26 10:07:18 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
void Sword2Engine::triggerFx(uint8 j) {
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *data;
|
2003-07-28 01:44:38 +00:00
|
|
|
int32 id;
|
|
|
|
uint32 rv;
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
id = (uint32) j + 1; // because 0 is not a valid id
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
if (_fxQueue[j].type == FX_SPOT) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// load in the sample
|
2003-11-16 14:18:29 +00:00
|
|
|
data = _resman->openResource(_fxQueue[j].resource);
|
2003-12-28 15:08:12 +00:00
|
|
|
data += sizeof(StandardHeader);
|
2003-09-20 12:43:52 +00:00
|
|
|
// wav data gets copied to sound memory
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _sound->playFx(id, data, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
|
2003-09-20 12:43:52 +00:00
|
|
|
// release the sample
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(_fxQueue[j].resource);
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
|
|
|
// random & looped fx are already loaded into sound memory
|
2003-10-18 08:11:50 +00:00
|
|
|
// by fnPlayFx()
|
2003-09-20 12:43:52 +00:00
|
|
|
// - to be referenced by 'j', so pass NULL data
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
if (_fxQueue[j].type == FX_RANDOM) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// Not looped
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXSPOT);
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
|
|
|
// Looped
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _sound->playFx(id, NULL, _fxQueue[j].volume, _fxQueue[j].pan, RDSE_FXLOOP);
|
2003-09-20 12:43:52 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv)
|
2003-10-01 06:36:25 +00:00
|
|
|
debug(5, "SFX ERROR: playFx() returned %.8x", rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// Stops all looped & random fx and clears the entire queue
|
|
|
|
|
|
|
|
void Sword2Engine::clearFxQueue(void) {
|
|
|
|
// stop all fx & remove the samples from sound memory
|
2003-11-16 14:18:29 +00:00
|
|
|
_sound->clearAllFx();
|
2003-11-03 07:47:42 +00:00
|
|
|
|
|
|
|
// clean out the queue
|
|
|
|
initFxQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::killMusic(void) {
|
|
|
|
_loopingMusicId = 0; // clear the 'looping' flag
|
2003-11-16 14:18:29 +00:00
|
|
|
_sound->stopMusic();
|
2003-11-03 07:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::pauseAllSound(void) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_sound->pauseMusic();
|
|
|
|
_sound->pauseSpeech();
|
|
|
|
_sound->pauseFx();
|
2003-11-03 07:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sword2Engine::unpauseAllSound(void) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_sound->unpauseMusic();
|
|
|
|
_sound->unpauseSpeech();
|
|
|
|
_sound->unpauseFx();
|
2003-11-03 07:47:42 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 10:07:18 +00:00
|
|
|
// called from script only
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnPlayFx(int32 *params) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// params: 0 sample resource id
|
2003-09-20 12:43:52 +00:00
|
|
|
// 1 type (FX_SPOT, FX_RANDOM, FX_LOOP)
|
|
|
|
// 2 delay (0..65535)
|
|
|
|
// 3 volume (0..16)
|
|
|
|
// 4 pan (-16..16)
|
|
|
|
|
|
|
|
// example script:
|
2003-10-18 08:11:50 +00:00
|
|
|
// fnPlayFx (FXWATER, FX_LOOP, 0, 10, 15);
|
2003-09-20 12:43:52 +00:00
|
|
|
// // fx_water is just a local script flag
|
|
|
|
// fx_water = result;
|
|
|
|
// .
|
|
|
|
// .
|
|
|
|
// .
|
2003-10-18 08:11:50 +00:00
|
|
|
// fnStopFx (fx_water);
|
2003-09-20 12:43:52 +00:00
|
|
|
|
|
|
|
uint8 j = 0;
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *data;
|
2003-09-20 12:43:52 +00:00
|
|
|
uint32 id;
|
2003-07-28 01:44:38 +00:00
|
|
|
uint32 rv;
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-12-28 15:08:12 +00:00
|
|
|
StandardHeader *header;
|
2003-10-26 15:42:49 +00:00
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_wantSfxDebug) {
|
2003-10-26 15:42:49 +00:00
|
|
|
char type[10];
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
switch (params[1]) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case FX_SPOT:
|
|
|
|
strcpy(type, "SPOT");
|
|
|
|
break;
|
|
|
|
case FX_LOOP:
|
|
|
|
strcpy(type, "LOOPED");
|
|
|
|
break;
|
|
|
|
case FX_RANDOM:
|
|
|
|
strcpy(type, "RANDOM");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(type, "INVALID");
|
2004-01-03 11:24:39 +00:00
|
|
|
break;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-24 12:29:35 +00:00
|
|
|
byte buf[NAME_LEN];
|
|
|
|
|
|
|
|
debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", _vm->fetchObjectName(params[0], buf), params[3], params[4], params[2], type);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
while (j < FXQ_LENGTH && _vm->_fxQueue[j].resource != 0)
|
2003-07-28 01:44:38 +00:00
|
|
|
j++;
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
if (j == FXQ_LENGTH)
|
|
|
|
return IR_CONT;
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_fxQueue[j].resource = params[0]; // wav resource id
|
|
|
|
_vm->_fxQueue[j].type = params[1]; // FX_SPOT, FX_LOOP or FX_RANDOM
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_fxQueue[j].type == FX_RANDOM) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// 'delay' param is the intended average no. seconds between
|
2003-10-08 18:02:53 +00:00
|
|
|
// playing this effect
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_fxQueue[j].delay = params[2] * 12;
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
|
|
|
// FX_SPOT or FX_LOOP:
|
|
|
|
// 'delay' is no. frames to wait before playing
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_fxQueue[j].delay = params[2];
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_fxQueue[j].volume = params[3]; // 0..16
|
|
|
|
_vm->_fxQueue[j].pan = params[4]; // -16..16
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_fxQueue[j].type == FX_SPOT) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// "pre-load" the sample; this gets it into memory
|
2003-11-16 14:18:29 +00:00
|
|
|
data = _vm->_resman->openResource(_vm->_fxQueue[j].resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-12-28 15:08:12 +00:00
|
|
|
header = (StandardHeader *) data;
|
2003-09-20 12:43:52 +00:00
|
|
|
if (header->fileType != WAV_FILE)
|
2003-10-26 15:42:49 +00:00
|
|
|
error("fnPlayFx given invalid resource");
|
2003-09-20 12:43:52 +00:00
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// but then releases it to "age" out if the space is needed
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(_vm->_fxQueue[j].resource);
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
|
|
|
// random & looped fx
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
id = (uint32) j + 1; // because 0 is not a valid id
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// load in the sample
|
2003-11-16 14:18:29 +00:00
|
|
|
data = _vm->_resman->openResource(_vm->_fxQueue[j].resource);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-12-28 15:08:12 +00:00
|
|
|
header = (StandardHeader *) data;
|
2003-09-20 12:43:52 +00:00
|
|
|
if (header->fileType != WAV_FILE)
|
2003-10-26 15:42:49 +00:00
|
|
|
error("fnPlayFx given invalid resource");
|
2003-09-20 12:43:52 +00:00
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
data += sizeof(StandardHeader);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// copy it to sound memory, using position in queue as 'id'
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _vm->_sound->openFx(id, data);
|
2003-09-20 12:43:52 +00:00
|
|
|
|
|
|
|
if (rv)
|
2003-10-01 06:36:25 +00:00
|
|
|
debug(5, "SFX ERROR: openFx() returned %.8x", rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// release the sample
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_resman->closeResource(_vm->_fxQueue[j].resource);
|
2003-09-20 12:43:52 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_fxQueue[j].type == FX_LOOP) {
|
2004-01-03 11:24:39 +00:00
|
|
|
// play now, rather than in processFxQueue where it was
|
2003-09-20 12:43:52 +00:00
|
|
|
// getting played again & again!
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->triggerFx(j);
|
2003-09-20 12:43:52 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// in case we want to call fnStopFx() later, to kill this fx
|
2003-09-20 12:43:52 +00:00
|
|
|
// (mainly for FX_LOOP & FX_RANDOM)
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-03-17 09:03:15 +00:00
|
|
|
_scriptVars[RESULT] = j;
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnSoundFetch(int32 *params) {
|
|
|
|
// params: 0 id of sound to fetch [guess]
|
2003-10-10 16:14:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// to alter the volume and pan of a currently playing fx
|
2003-09-26 10:07:18 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnSetFxVolAndPan(int32 *params) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// params: 0 id of fx (ie. the id returned in 'result' from
|
2003-10-18 08:11:50 +00:00
|
|
|
// fnPlayFx
|
2003-09-20 12:43:52 +00:00
|
|
|
// 1 new volume (0..16)
|
|
|
|
// 2 new pan (-16..16)
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
debug(5, "fnSetFxVolAndPan(%d, %d, %d)", params[0], params[1], params[2]);
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2003-10-01 06:36:25 +00:00
|
|
|
// setFxIdVolumePan(int32 id, uint8 vol, uint8 pan);
|
2003-09-20 12:43:52 +00:00
|
|
|
// driver fx_id is 1 + <pos in queue>
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->setFxIdVolumePan(1 + params[0], params[1], params[2]);
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// to alter the volume of a currently playing fx
|
2003-09-26 10:07:18 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnSetFxVol(int32 *params) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// params: 0 id of fx (ie. the id returned in 'result' from
|
2003-10-18 08:11:50 +00:00
|
|
|
// fnPlayFx
|
2003-09-20 12:43:52 +00:00
|
|
|
// 1 new volume (0..16)
|
|
|
|
|
|
|
|
// SetFxIdVolume(int32 id, uint8 vol);
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->setFxIdVolume(1 + params[0], params[1]);
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2003-09-26 10:07:18 +00:00
|
|
|
// called from script only
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnStopFx(int32 *params) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// params: 0 position in queue
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// This will stop looped & random fx instantly, and remove the fx
|
|
|
|
// from the queue. So although it doesn't stop spot fx, it will
|
|
|
|
// remove them from the queue if they haven't yet played
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
uint8 j = (uint8) params[0];
|
|
|
|
uint32 id;
|
|
|
|
uint32 rv;
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_fxQueue[j].type == FX_RANDOM || _vm->_fxQueue[j].type == FX_LOOP) {
|
2003-09-20 12:43:52 +00:00
|
|
|
id = (uint32) j + 1; // because 0 is not a valid id
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// stop fx & remove sample from sound memory
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _vm->_sound->closeFx(id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
if (rv)
|
2003-10-01 06:36:25 +00:00
|
|
|
debug(5, "SFX ERROR: closeFx() returned %.8x", rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// remove from queue
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_fxQueue[j].resource = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 10:07:18 +00:00
|
|
|
// called from script only
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnStopAllFx(int32 *params) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// Stops all looped & random fx and clears the entire queue
|
2003-10-18 08:11:50 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// params: none
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->clearFxQueue();
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnPrepareMusic(int32 *params) {
|
|
|
|
// params: 1 id of music to prepare [guess]
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// Start a tune playing, to play once or to loop until stopped or next one
|
|
|
|
// played
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnPlayMusic(int32 *params) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// params: 0 tune id
|
|
|
|
// 1 loop flag (0 or 1)
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
char filename[128];
|
2003-09-21 14:26:25 +00:00
|
|
|
bool loopFlag;
|
2003-09-20 12:43:52 +00:00
|
|
|
uint32 rv;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
if (params[1] == FX_LOOP) {
|
2003-09-21 14:26:25 +00:00
|
|
|
loopFlag = true;
|
2003-09-20 12:43:52 +00:00
|
|
|
|
|
|
|
// keep a note of the id, for restarting after an
|
|
|
|
// interruption to gameplay
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_loopingMusicId = params[0];
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
2003-11-08 19:47:20 +00:00
|
|
|
loopFlag = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// don't need to restart this tune after control panel or
|
|
|
|
// restore
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_loopingMusicId = 0;
|
2003-09-20 12:43:52 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
|
|
|
// add the appropriate file extension & play it
|
|
|
|
|
2004-03-17 09:03:15 +00:00
|
|
|
if (_scriptVars[DEMO]) {
|
2003-08-31 18:09:21 +00:00
|
|
|
// The demo I found didn't come with any music file, but you
|
|
|
|
// could use the music from the first CD of the complete game,
|
|
|
|
// I suppose...
|
|
|
|
strcpy(filename, "music.clu");
|
2003-09-20 12:43:52 +00:00
|
|
|
} else {
|
2003-08-31 18:09:21 +00:00
|
|
|
File f;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
sprintf(filename, "music%d.clu", _vm->_resman->whichCd());
|
2003-09-17 21:06:16 +00:00
|
|
|
if (f.open(filename))
|
2003-08-31 18:09:21 +00:00
|
|
|
f.close();
|
|
|
|
else
|
|
|
|
strcpy(filename, "music.clu");
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
rv = _vm->_sound->streamCompMusic(filename, params[0], loopFlag);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-27 11:02:58 +00:00
|
|
|
if (rv)
|
2003-10-01 06:36:25 +00:00
|
|
|
debug(5, "ERROR: streamCompMusic(%s, %d, %d) returned error 0x%.8x", filename, params[0], loopFlag, rv);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// called from script only
|
|
|
|
|
|
|
|
int32 Logic::fnStopMusic(int32 *params) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// params: none
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_vm->_loopingMusicId = 0; // clear the 'looping' flag
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_sound->stopMusic();
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
int32 Logic::fnCheckMusicPlaying(int32 *params) {
|
2003-09-20 12:43:52 +00:00
|
|
|
// params: none
|
|
|
|
|
2003-07-28 01:44:38 +00:00
|
|
|
// sets result to no. of seconds of current tune remaining
|
|
|
|
// or 0 if no music playing
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// in seconds, rounded up to the nearest second
|
2004-03-17 09:03:15 +00:00
|
|
|
_scriptVars[RESULT] = _vm->_sound->musicTimeRemaining();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
return IR_CONT;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|