diff options
author | Torbjörn Andersson | 2015-01-26 19:34:21 +0100 |
---|---|---|
committer | Torbjörn Andersson | 2015-01-26 19:34:21 +0100 |
commit | 51e90b2422f0bf3b4b9b1a71c23ae12a359dead2 (patch) | |
tree | e78f29f22be42ee59f3b86d7859c8703d4c12144 /engines/zvision/scripting | |
parent | 8f551202f6c0029773524fe4686c1147f51b4ee6 (diff) | |
download | scummvm-rg350-51e90b2422f0bf3b4b9b1a71c23ae12a359dead2.tar.gz scummvm-rg350-51e90b2422f0bf3b4b9b1a71c23ae12a359dead2.tar.bz2 scummvm-rg350-51e90b2422f0bf3b4b9b1a71c23ae12a359dead2.zip |
ZVISION: Fix ActionMusic volume
The volume can be either a constant or a state value. The latter is
used by ZGI to simulate a sound being heard at different distances,
e.g. the beehive in the Dungeon Master's hideout.
Diffstat (limited to 'engines/zvision/scripting')
-rw-r--r-- | engines/zvision/scripting/actions.cpp | 63 | ||||
-rw-r--r-- | engines/zvision/scripting/actions.h | 3 |
2 files changed, 42 insertions, 24 deletions
diff --git a/engines/zvision/scripting/actions.cpp b/engines/zvision/scripting/actions.cpp index 9a2f1d10ff..81d6655fa9 100644 --- a/engines/zvision/scripting/actions.cpp +++ b/engines/zvision/scripting/actions.cpp @@ -21,6 +21,7 @@ */ #include "common/scummsys.h" +#include "common/tokenizer.h" #include "video/video_decoder.h" #include "zvision/scripting/actions.h" @@ -449,33 +450,40 @@ ActionMusic::ActionMusic(ZVision *engine, int32 slotkey, const Common::String &l _note(0), _prog(0), _universe(global) { - uint type = 0; - char fileNameBuffer[25]; - uint loop = 0; - uint volume = 255; + Common::StringTokenizer tokenizer(line); - sscanf(line.c_str(), "%u %24s %u %u", &type, fileNameBuffer, &loop, &volume); + // Parse the type of action. Type 4 actions are MIDI commands, not + // files. These are only used by Zork: Nemesis, for the flute and piano + // puzzles (tj4e and ve6f, as well as vr) + uint type = atoi(tokenizer.nextToken().c_str()); - // Type 4 actions are MIDI commands, not files. These are only used by - // Zork: Nemesis, for the flute and piano puzzles (tj4e and ve6f, as well - // as vr) if (type == 4) { _midi = true; - int note; - int prog; - sscanf(line.c_str(), "%u %d %d %u", &type, &prog, ¬e, &volume); - _volume = volume; - _note = note; - _prog = prog; + _prog = atoi(tokenizer.nextToken().c_str()); + _note = atoi(tokenizer.nextToken().c_str()); + _volume = atoi(tokenizer.nextToken().c_str()); + _volumeIsAKey = false; } else { _midi = false; - _fileName = Common::String(fileNameBuffer); - _loop = loop == 1 ? true : false; - - // Volume is optional. If it doesn't appear, assume full volume - if (volume != 255) { - // Volume in the script files is mapped to [0, 100], but the ScummVM mixer uses [0, 255] - _volume = volume * 255 / 100; + _fileName = tokenizer.nextToken(); + _loop = atoi(tokenizer.nextToken().c_str()) == 1; + if (!tokenizer.empty()) { + Common::String token = tokenizer.nextToken(); + if (token.contains('[')) { + sscanf(token.c_str(), "[%u]", &_volume); + _volumeIsAKey = true; + } else { + _volume = atoi(token.c_str()); + if (_volume > 100) { + warning("ActionMusic: Adjusting volume for %s from %d to 100", _fileName.c_str(), _volume); + _volume = 100; + } + _volumeIsAKey = false; + } + } else { + // Volume is optional. If it doesn't appear, assume full volume + _volume = 100; + _volumeIsAKey = false; } } } @@ -491,13 +499,22 @@ bool ActionMusic::execute() { _engine->getScriptManager()->setStateValue(_slotKey, 2); } + uint volume; + if (_volumeIsAKey) { + volume = _engine->getScriptManager()->getStateValue(_volume); + } else { + volume = _volume; + } + if (_midi) { - _engine->getScriptManager()->addSideFX(new MusicMidiNode(_engine, _slotKey, _prog, _note, _volume)); + _engine->getScriptManager()->addSideFX(new MusicMidiNode(_engine, _slotKey, _prog, _note, volume)); } else { if (!_engine->getSearchManager()->hasFile(_fileName)) return true; - _engine->getScriptManager()->addSideFX(new MusicNode(_engine, _slotKey, _fileName, _loop, _volume)); + // Volume in the script files is mapped to [0, 100], but the ScummVM mixer uses [0, 255] + + _engine->getScriptManager()->addSideFX(new MusicNode(_engine, _slotKey, _fileName, _loop, volume * 255 / 100)); } return true; diff --git a/engines/zvision/scripting/actions.h b/engines/zvision/scripting/actions.h index 8d43309b74..cbb91fa8d3 100644 --- a/engines/zvision/scripting/actions.h +++ b/engines/zvision/scripting/actions.h @@ -224,7 +224,8 @@ public: private: Common::String _fileName; bool _loop; - byte _volume; + uint32 _volume; + bool _volumeIsAKey; bool _universe; bool _midi; int8 _note; |