diff options
Diffstat (limited to 'engines/mohawk/myst_scripts.cpp')
-rw-r--r-- | engines/mohawk/myst_scripts.cpp | 135 |
1 files changed, 35 insertions, 100 deletions
diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp index 15d74a2253..596180ddb2 100644 --- a/engines/mohawk/myst_scripts.cpp +++ b/engines/mohawk/myst_scripts.cpp @@ -29,8 +29,8 @@ #include "mohawk/video.h" #include "common/system.h" +#include "common/memstream.h" #include "common/textconsole.h" -#include "gui/message.h" namespace Mohawk { @@ -38,7 +38,7 @@ MystScriptEntry::MystScriptEntry() { type = kMystScriptNone; var = 0; argc = 0; - argv = 0; + argv = nullptr; resourceId = 0; u1 = 0; } @@ -81,7 +81,7 @@ MystScriptParser::MystScriptParser(MohawkEngine_Myst *vm) : _vm(vm), _globals(vm->_gameState->_globals) { setupCommonOpcodes(); - _invokingResource = NULL; + _invokingResource = nullptr; _savedCardId = 0; _savedCursorId = 0; _tempVar = 0; @@ -154,7 +154,7 @@ void MystScriptParser::setupCommonOpcodes() { #undef OPCODE -void MystScriptParser::runScript(MystScript script, MystResource *invokingResource) { +void MystScriptParser::runScript(MystScript script, MystArea *invokingResource) { debugC(kDebugScript, "Script Size: %d", script->size()); // Scripted drawing takes more time to simulate older hardware @@ -260,15 +260,6 @@ bool MystScriptParser::setVarValue(uint16 var, uint16 value) { return false; } -// NOTE: Check to be used on Opcodes where var is thought -// not to be used. This emits a warning if var is nonzero. -// It is possible that the opcode does use var 0 in this case, -// but this will catch the majority of missed cases. -void MystScriptParser::varUnusedCheck(uint16 op, uint16 var) { - if (var != 0) - warning("Opcode %d: Unused Var %d", op, var); -} - void MystScriptParser::animatedUpdate(uint16 argc, uint16 *argv, uint16 delay) { uint16 argsRead = 0; @@ -331,7 +322,7 @@ void MystScriptParser::o_changeCardSwitch4(uint16 op, uint16 var, uint16 argc, u if (value) _vm->changeToCard(argv[value -1 ], kTransitionDissolve); - else if (_invokingResource != NULL) + else if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionDissolve); else warning("Missing invokingResource in altDest call"); @@ -344,7 +335,7 @@ void MystScriptParser::o_changeCardSwitchLtR(uint16 op, uint16 var, uint16 argc, if (value) _vm->changeToCard(argv[value -1 ], kTransitionLeftToRight); - else if (_invokingResource != NULL) + else if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionLeftToRight); else warning("Missing invokingResource in altDest call"); @@ -357,7 +348,7 @@ void MystScriptParser::o_changeCardSwitchRtL(uint16 op, uint16 var, uint16 argc, if (value) _vm->changeToCard(argv[value -1 ], kTransitionRightToLeft); - else if (_invokingResource != NULL) + else if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionRightToLeft); else warning("Missing invokingResource in altDest call"); @@ -398,7 +389,7 @@ void MystScriptParser::o_redrawCard(uint16 op, uint16 var, uint16 argc, uint16 * void MystScriptParser::o_goToDest(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Change To Dest of Invoking Resource", op); - if (_invokingResource != NULL) + if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionCopy); else warning("Opcode %d: Missing invokingResource", op); @@ -407,7 +398,7 @@ void MystScriptParser::o_goToDest(uint16 op, uint16 var, uint16 argc, uint16 *ar void MystScriptParser::o_goToDestForward(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Change To Dest of Invoking Resource", op); - if (_invokingResource != NULL) + if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionDissolve); else warning("Opcode %d: Missing invokingResource", op); @@ -416,7 +407,7 @@ void MystScriptParser::o_goToDestForward(uint16 op, uint16 var, uint16 argc, uin void MystScriptParser::o_goToDestLeft(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Change To Dest of Invoking Resource", op); - if (_invokingResource != NULL) + if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionPartToRight); else warning("Opcode %d: Missing invokingResource", op); @@ -425,7 +416,7 @@ void MystScriptParser::o_goToDestLeft(uint16 op, uint16 var, uint16 argc, uint16 void MystScriptParser::o_goToDestRight(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Change To Dest of Invoking Resource", op); - if (_invokingResource != NULL) + if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionPartToLeft); else warning("Opcode %d: Missing invokingResource", op); @@ -434,7 +425,7 @@ void MystScriptParser::o_goToDestRight(uint16 op, uint16 var, uint16 argc, uint1 void MystScriptParser::o_goToDestUp(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Change To Dest of Invoking Resource", op); - if (_invokingResource != NULL) + if (_invokingResource != nullptr) _vm->changeToCard(_invokingResource->getDest(), kTransitionTopToBottom); else warning("Opcode %d: Missing invokingResource", op); @@ -442,7 +433,10 @@ void MystScriptParser::o_goToDestUp(uint16 op, uint16 var, uint16 argc, uint16 * void MystScriptParser::o_triggerMovie(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Trigger Type 6 Resource Movie..", op); - // TODO: If movie has sound, pause background music + // The original has code to pause the background music before playing the movie, + // if the movie has a sound track, as well as code to resume it afterwards. But since + // the movie has not yet been loaded at this point, it is impossible to know + // if the movie actually has a sound track. The code is never executed. int16 direction = 1; if (argc == 1) @@ -451,11 +445,9 @@ void MystScriptParser::o_triggerMovie(uint16 op, uint16 var, uint16 argc, uint16 debugC(kDebugScript, "\tDirection: %d", direction); // Trigger resource 6 movie overriding play direction - MystResourceType6 *resource = static_cast<MystResourceType6 *>(_invokingResource); + MystAreaVideo *resource = getInvokingResource<MystAreaVideo>(); resource->setDirection(direction); resource->playMovie(); - - // TODO: If movie has sound, resume background music } void MystScriptParser::o_toggleVarNoRedraw(uint16 op, uint16 var, uint16 argc, uint16 *argv) { @@ -468,7 +460,7 @@ void MystScriptParser::o_drawAreaState(uint16 op, uint16 var, uint16 argc, uint1 debugC(kDebugScript, "Opcode %d: drawAreaState, state: %d", op, argv[0]); debugC(kDebugScript, "\tVar: %d", var); - MystResourceType8 *parent = static_cast<MystResourceType8 *>(_invokingResource->_parent); + MystAreaImageSwitch *parent = static_cast<MystAreaImageSwitch *>(getInvokingResource<MystArea>()->_parent); parent->drawConditionalDataToScreen(argv[0]); } @@ -517,6 +509,11 @@ void MystScriptParser::o_changeCardPop(uint16 op, uint16 var, uint16 argc, uint1 debugC(kDebugScript, "Opcode %d: Return To Stored Card Id", op); debugC(kDebugScript, "\tCardId: %d", _savedCardId); + if (_savedCardId == 0) { + warning("No pushed card to go back to"); + return; + } + TransitionType transition = static_cast<TransitionType>(argv[0]); _vm->changeToCard(_savedCardId, transition); @@ -531,7 +528,7 @@ void MystScriptParser::o_enableAreas(uint16 op, uint16 var, uint16 argc, uint16 for (uint16 i = 0; i < count; i++) { debugC(kDebugScript, "Enable hotspot index %d", argv[i + 1]); - MystResource *resource = 0; + MystArea *resource = nullptr; if (argv[i + 1] == 0xFFFF) resource = _invokingResource; else @@ -556,7 +553,7 @@ void MystScriptParser::o_disableAreas(uint16 op, uint16 var, uint16 argc, uint16 for (uint16 i = 0; i < count; i++) { debugC(kDebugScript, "Disable hotspot index %d", argv[i + 1]); - MystResource *resource = 0; + MystArea *resource = nullptr; if (argv[i + 1] == 0xFFFF) resource = _invokingResource; else @@ -587,7 +584,7 @@ void MystScriptParser::o_toggleAreasActivation(uint16 op, uint16 var, uint16 arg for (uint16 i = 0; i < count; i++) { debugC(kDebugScript, "Enable/Disable hotspot index %d", argv[i + 1]); - MystResource *resource = 0; + MystArea *resource = nullptr; if (argv[i + 1] == 0xFFFF) resource = _invokingResource; else @@ -682,82 +679,20 @@ void MystScriptParser::o_copyImageToBackBuffer(uint16 op, uint16 var, uint16 arg _vm->_gfx->copyImageSectionToBackBuffer(imageId, srcRect, dstRect); } -// TODO: Implement common engine function for read and processing of sound blocks -// for use by this opcode and VIEW sound block. -// TODO: Though the playSound and PlaySoundBlocking opcodes play sounds immediately, -// this opcode changes the main background sound playing.. -// Current behavior here and with VIEW sound block is not right as demonstrated -// by Channelwood Card 3280 (Tank Valve) and water flow sound behavior in pipe -// on cards leading from shed... void MystScriptParser::o_changeBackgroundSound(uint16 op, uint16 var, uint16 argc, uint16 *argv) { - int16 *soundList = NULL; - uint16 *soundListVolume = NULL; - // Used on Stoneship Card 2080 // Used on Channelwood Card 3225 with argc = 8 i.e. Conditional Sound List - if (argc == 1 || argc == 2 || argc == 8) { - debugC(kDebugScript, "Opcode %d: Process Sound Block", op); - uint16 decodeIdx = 0; - - int16 soundAction = argv[decodeIdx++]; - uint16 soundVolume = 65535; - if (soundAction == kMystSoundActionChangeVolume || soundAction > 0) { - soundVolume = argv[decodeIdx++]; - } else if (soundAction == kMystSoundActionConditional) { - debugC(kDebugScript, "Conditional sound list"); - uint16 condVar = argv[decodeIdx++]; - uint16 condVarValue = getVar(condVar); - uint16 condCount = argv[decodeIdx++]; - - debugC(kDebugScript, "\tcondVar: %d = %d", condVar, condVarValue); - debugC(kDebugScript, "\tcondCount: %d", condCount); - - soundList = new int16[condCount]; - soundListVolume = new uint16[condCount]; - - if (condVarValue >= condCount) - warning("Opcode %d: Conditional sound variable outside range", op); - else { - for (uint16 i = 0; i < condCount; i++) { - soundList[i] = argv[decodeIdx++]; - debugC(kDebugScript, "\t\tCondition %d: Action %d", i, soundList[i]); - if (soundAction == kMystSoundActionChangeVolume || soundAction > 0) { - soundListVolume[i] = argv[decodeIdx++]; - } else - soundListVolume[i] = 65535; - debugC(kDebugScript, "\t\tCondition %d: Volume %d", i, soundListVolume[i]); - } - - soundAction = soundList[condVarValue]; - soundVolume = soundListVolume[condVarValue]; - } - } + debugC(kDebugScript, "Opcode %d: Process Sound Block", op); - if (soundAction == kMystSoundActionContinue) - debugC(kDebugScript, "Continue current sound"); - else if (soundAction == kMystSoundActionChangeVolume) { - debugC(kDebugScript, "Continue current sound, change volume"); - debugC(kDebugScript, "\tVolume: %d", soundVolume); - _vm->_sound->changeBackgroundVolumeMyst(soundVolume); - } else if (soundAction == kMystSoundActionStop) { - debugC(kDebugScript, "Stop sound"); - _vm->_sound->stopBackgroundMyst(); - } else if (soundAction > 0) { - debugC(kDebugScript, "Play new Sound, change volume"); - debugC(kDebugScript, "\tSound: %d", soundAction); - debugC(kDebugScript, "\tVolume: %d", soundVolume); - _vm->_sound->replaceBackgroundMyst(soundAction, soundVolume); - } else { - debugC(kDebugScript, "Unknown"); - warning("Unknown sound control value in opcode %d", op); - } - } else - warning("Unknown arg count in opcode %d", op); + Common::MemoryWriteStreamDynamic writeStream = Common::MemoryWriteStreamDynamic(DisposeAfterUse::YES); + for (uint i = 0; i < argc; i++) { + writeStream.writeUint16LE(argv[i]); + } + + Common::MemoryReadStream readStream = Common::MemoryReadStream(writeStream.getData(), writeStream.size()); - delete[] soundList; - soundList = NULL; - delete[] soundListVolume; - soundListVolume = NULL; + MystSoundBlock soundBlock = _vm->readSoundBlock(&readStream); + _vm->applySoundBlock(soundBlock); } void MystScriptParser::o_soundPlaySwitch(uint16 op, uint16 var, uint16 argc, uint16 *argv) { |