From 1b1643ad6f7f0c8cda743d92321dedf2c1373fda Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Jul 2015 22:36:38 -0400 Subject: SHERLOCK: RT: Implement cmdPlaySong opcode --- engines/sherlock/music.h | 1 + engines/sherlock/sound.h | 1 - engines/sherlock/tattoo/tattoo_scene.cpp | 6 +++--- engines/sherlock/tattoo/tattoo_talk.cpp | 31 +++++++++++++++++++++++++++---- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/engines/sherlock/music.h b/engines/sherlock/music.h index da1bca83e1..dc2ed0244f 100644 --- a/engines/sherlock/music.h +++ b/engines/sherlock/music.h @@ -72,6 +72,7 @@ public: bool _musicOn; int _musicVolume; bool _midiOption; + Common::String _currentSongName, _nextSongName; public: Music(SherlockEngine *vm, Audio::Mixer *mixer); ~Music(); diff --git a/engines/sherlock/sound.h b/engines/sherlock/sound.h index e82d94bbe0..a2e7715b21 100644 --- a/engines/sherlock/sound.h +++ b/engines/sherlock/sound.h @@ -59,7 +59,6 @@ public: bool _soundPlaying; bool *_soundIsOn; byte *_digiBuf; - Common::String _currentSongName, _nextSongName; public: Sound(SherlockEngine *vm, Audio::Mixer *mixer); diff --git a/engines/sherlock/tattoo/tattoo_scene.cpp b/engines/sherlock/tattoo/tattoo_scene.cpp index f19eb73a54..5803a0ace0 100644 --- a/engines/sherlock/tattoo/tattoo_scene.cpp +++ b/engines/sherlock/tattoo/tattoo_scene.cpp @@ -85,11 +85,11 @@ bool TattooScene::loadScene(const Common::String &filename) { // Handle loading music for the scene if (music._musicOn) { if (talk._scriptMoreFlag != 1 && talk._scriptMoreFlag != 3) - sound._nextSongName = Common::String::format("res%02d", _currentScene); + music._nextSongName = Common::String::format("res%02d", _currentScene); // If it's a new song, then start it up - if (sound._currentSongName.compareToIgnoreCase(sound._nextSongName)) { - if (music.loadSong(sound._nextSongName)) { + if (music._currentSongName.compareToIgnoreCase(music._nextSongName)) { + if (music.loadSong(music._nextSongName)) { music.setMIDIVolume(music._musicVolume); if (music._musicOn) music.startSong(); diff --git a/engines/sherlock/tattoo/tattoo_talk.cpp b/engines/sherlock/tattoo/tattoo_talk.cpp index 84a7924c69..48f49a4ed8 100644 --- a/engines/sherlock/tattoo/tattoo_talk.cpp +++ b/engines/sherlock/tattoo/tattoo_talk.cpp @@ -292,14 +292,14 @@ OpcodeReturn TattooTalk::cmdGotoScene(const byte *&str) { } OpcodeReturn TattooTalk::cmdNextSong(const byte *&str) { - Sound &sound = *_vm->_sound; + Music &music = *_vm->_music; // Get the name of the next song to play ++str; - sound._nextSongName = ""; + music._nextSongName = ""; for (int idx = 0; idx < 8; ++idx) { if (str[idx] != '~') - sound._nextSongName += str[idx]; + music._nextSongName += str[idx]; else break; } @@ -368,7 +368,30 @@ OpcodeReturn TattooTalk::cmdNPCLabelSet(const byte *&str) { } OpcodeReturn TattooTalk::cmdPassword(const byte *&str) { error("TODO: script opcode (cmdPassword)"); } -OpcodeReturn TattooTalk::cmdPlaySong(const byte *&str) { error("TODO: script opcode (cmdPlaySong)"); } + +OpcodeReturn TattooTalk::cmdPlaySong(const byte *&str) { + Music &music = *_vm->_music; + Common::String currentSong = music._currentSongName; + + // Get the name of the song to play + music._currentSongName = ""; + str++; + for (int idx = 0; idx < 8; ++idx) { + if (str[idx] != '~') + music._currentSongName += str[idx]; + else + break; + } + str += 7; + + // Play the song + music.playMusic(music._currentSongName); + + // Copy the old song name to _nextSongName so that when the new song is finished, the old song will restart + music._nextSongName = currentSong; + + return RET_SUCCESS; +} OpcodeReturn TattooTalk::cmdRestorePeopleSequence(const byte *&str) { int npcNum = *++str - 1; -- cgit v1.2.3