diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/console.cpp | 26 | ||||
-rw-r--r-- | engines/mohawk/module.mk | 1 | ||||
-rw-r--r-- | engines/mohawk/myst.cpp | 492 | ||||
-rw-r--r-- | engines/mohawk/myst.h | 104 | ||||
-rw-r--r-- | engines/mohawk/myst_areas.cpp | 13 | ||||
-rw-r--r-- | engines/mohawk/myst_card.cpp | 456 | ||||
-rw-r--r-- | engines/mohawk/myst_card.h | 185 | ||||
-rw-r--r-- | engines/mohawk/myst_scripts.cpp | 40 | ||||
-rw-r--r-- | engines/mohawk/myst_scripts.h | 4 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/channelwood.cpp | 15 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/credits.cpp | 3 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/mechanical.cpp | 39 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/myst.cpp | 173 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/selenitic.cpp | 48 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/stoneship.cpp | 29 |
15 files changed, 887 insertions, 741 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp index f24df96b55..2251ce097f 100644 --- a/engines/mohawk/console.cpp +++ b/engines/mohawk/console.cpp @@ -36,6 +36,7 @@ #ifdef ENABLE_MYST #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" #include "mohawk/myst_sound.h" @@ -88,7 +89,7 @@ bool MystConsole::Cmd_ChangeCard(int argc, const char **argv) { } bool MystConsole::Cmd_CurCard(int argc, const char **argv) { - debugPrintf("Current Card: %d\n", _vm->getCurCard()); + debugPrintf("Current Card: %d\n", _vm->getCard()->getId()); return true; } @@ -210,8 +211,8 @@ bool MystConsole::Cmd_DrawRect(int argc, const char **argv) { _vm->_gfx->drawRect(Common::Rect((uint16)atoi(argv[1]), (uint16)atoi(argv[2]), (uint16)atoi(argv[3]), (uint16)atoi(argv[4])), kRectEnabled); } else if (argc == 2) { uint16 resourceId = (uint16)atoi(argv[1]); - if (resourceId < _vm->_resources.size()) - _vm->_resources[resourceId]->drawBoundingRect(); + if (resourceId < _vm->getCard()->_resources.size()) + _vm->getCard()->_resources[resourceId]->drawBoundingRect(); } return false; @@ -223,7 +224,7 @@ bool MystConsole::Cmd_SetResourceEnable(int argc, const char **argv) { return true; } - _vm->setResourceEnabled((uint16)atoi(argv[1]), atoi(argv[2]) == 1); + _vm->getCard()->setResourceEnabled((uint16)atoi(argv[1]), atoi(argv[2]) == 1); return true; } @@ -316,10 +317,10 @@ bool MystConsole::Cmd_Cache(int argc, const char **argv) { } bool MystConsole::Cmd_Resources(int argc, const char **argv) { - debugPrintf("Resources in card %d:\n", _vm->getCurCard()); + debugPrintf("Resources in card %d:\n", _vm->getCard()->getId()); - for (uint i = 0; i < _vm->_resources.size(); i++) { - debugPrintf("#%2d %s\n", i, _vm->_resources[i]->describe().c_str()); + for (uint i = 0; i < _vm->getCard()->_resources.size(); i++) { + debugPrintf("#%2d %s\n", i, _vm->getCard()->_resources[i]->describe().c_str()); } return true; @@ -343,10 +344,13 @@ bool MystConsole::Cmd_QuickTest(int argc, const char **argv) { _vm->doFrame(); - int16 resIndex = _vm->_rnd->getRandomNumber(_vm->_resources.size()) - 1; - if (resIndex >= 0 && _vm->_resources[resIndex]->isEnabled()) { - _vm->_resources[resIndex]->handleMouseDown(); - _vm->_resources[resIndex]->handleMouseUp(); + { + MystCardPtr card = _vm->getCardPtr(); + int16 resIndex = _vm->_rnd->getRandomNumber(card->_resources.size()) - 1; + if (resIndex >= 0 && _vm->getCard()->_resources[resIndex]->isEnabled()) { + card->_resources[resIndex]->handleMouseDown(); + card->_resources[resIndex]->handleMouseUp(); + } } _vm->doFrame(); diff --git a/engines/mohawk/module.mk b/engines/mohawk/module.mk index e20638f881..4957ff3c2b 100644 --- a/engines/mohawk/module.mk +++ b/engines/mohawk/module.mk @@ -32,6 +32,7 @@ ifdef ENABLE_MYST MODULE_OBJS += \ myst.o \ myst_areas.o \ + myst_card.o \ myst_graphics.o \ myst_scripts.o \ myst_sound.o \ diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index 4ff1df2eb7..d0d3a3c30b 100644 --- a/engines/mohawk/myst.cpp +++ b/engines/mohawk/myst.cpp @@ -29,6 +29,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" #include "mohawk/myst_sound.h" @@ -71,13 +72,8 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription _mainCursor = kDefaultMystCursor; _showResourceRects = false; _curStack = 0; - _curCard = 0; _lastSaveTime = 0; - _hoverResource = nullptr; - _activeResource = nullptr; - _clickedResource = nullptr; - _sound = nullptr; _video = nullptr; _gfx = nullptr; @@ -93,7 +89,6 @@ MohawkEngine_Myst::MohawkEngine_Myst(OSystem *syst, const MohawkGameDescription _mouseMoved = false; _escapePressed = false; _waitingOnBlockingOperation = false; - _runExitScript = true; _needsPageDrop = false; _needsShowCredits = false; @@ -113,9 +108,6 @@ MohawkEngine_Myst::~MohawkEngine_Myst() { delete _optionsDialog; delete _prevStack; delete _rnd; - - for (uint32 i = 0; i < _resources.size(); i++) - delete _resources[i]; } // Uses cached data objects in preference to disk access @@ -133,7 +125,6 @@ Common::SeekableReadStream *MohawkEngine_Myst::getResource(uint32 tag, uint16 id } error("Could not find a \'%s\' resource with ID %04x", tag2str(tag), id); - return nullptr; } Common::Array<uint16> MohawkEngine_Myst::getResourceIDList(uint32 type) const { @@ -499,8 +490,16 @@ void MohawkEngine_Myst::doFrame() { } if (isInteractive()) { - updateActiveResource(); - checkCurrentResource(); + Common::Point mousePos = _system->getEventManager()->getMousePos(); + + // Keep a reference to the card so it is not freed if a script switches to another card + MystCardPtr card = _card; + card->updateActiveResource(mousePos); + card->updateResourcesForInput(mousePos, _mouseClicked, _mouseMoved); + + refreshCursor(); + + _mouseMoved = false; } _system->updateScreen(); @@ -566,6 +565,9 @@ void MohawkEngine_Myst::changeToStack(uint16 stack, uint16 card, uint16 linkSrcS if (linkSrcSound) playSoundBlocking(linkSrcSound); + _card->leave(); + _card.reset(); + // Delete the previous stack and move the current stack to the previous one // There's probably a better way to do this, but the script classes shouldn't // take up much memory. @@ -635,8 +637,6 @@ void MohawkEngine_Myst::changeToStack(uint16 stack, uint16 card, uint16 linkSrcS if (!_mhk[0]->openFile(mystFiles[_curStack])) error("Could not open %s", mystFiles[_curStack]); - _runExitScript = false; - // Clear the resource cache and the image cache _cache.clear(); _gfx->clearCache(); @@ -647,26 +647,6 @@ void MohawkEngine_Myst::changeToStack(uint16 stack, uint16 card, uint16 linkSrcS playSoundBlocking(linkDstSound); } -uint16 MohawkEngine_Myst::getCardBackgroundId() { - uint16 imageToDraw = 0; - - if (_view.conditionalImages.size() == 0) - imageToDraw = _view.mainImage; - else { - for (uint16 i = 0; i < _view.conditionalImages.size(); i++) { - uint16 varValue = _scriptParser->getVar(_view.conditionalImages[i].var); - if (varValue < _view.conditionalImages[i].values.size()) - imageToDraw = _view.conditionalImages[i].values[varValue]; - } - } - - return imageToDraw; -} - -void MohawkEngine_Myst::drawCardBackground() { - _gfx->copyImageToBackBuffer(getCardBackgroundId(), Common::Rect(0, 0, 544, 332)); -} - void MohawkEngine_Myst::changeToCard(uint16 card, TransitionType transition) { debug(2, "changeToCard(%d)", card); @@ -674,14 +654,6 @@ void MohawkEngine_Myst::changeToCard(uint16 card, TransitionType transition) { _video->stopVideos(); - // Run exit script from last card (if present) - if (_runExitScript) - runExitScript(); - - _runExitScript = true; - - unloadCard(); - // Clear the resource cache and image cache _cache.clear(); _gfx->clearCache(); @@ -689,30 +661,13 @@ void MohawkEngine_Myst::changeToCard(uint16 card, TransitionType transition) { _mouseClicked = false; _mouseMoved = false; _escapePressed = false; - _curCard = card; - - // Load a bunch of stuff - loadCard(); - loadResources(); - loadCursorHints(); - // Handle images - drawCardBackground(); - - // Handle sound - applySoundBlock(_view.soundBlock); - - if (_view.flags & kMystZipDestination) - _gameState->addZipDest(_curStack, card); - - // Run the entrance script (if present) - runInitScript(); - - // Update the images of each area too - drawResourceImages(); + if (_card) { + _card->leave(); + } - for (uint16 i = 0; i < _resources.size(); i++) - _resources[i]->handleCardChange(); + _card = MystCardPtr(new MystCard(this, card)); + _card->enter(); // The demo resets the cursor at each card change except when in the library if (getFeatures() & GF_DEMO @@ -731,310 +686,7 @@ void MohawkEngine_Myst::changeToCard(uint16 card, TransitionType transition) { // Debug: Show resource rects if (_showResourceRects) - drawResourceRects(); -} - -void MohawkEngine_Myst::drawResourceRects() { - for (uint16 i = 0; i < _resources.size(); i++) { - _resources[i]->getRect().debugPrint(0); - _resources[i]->drawBoundingRect(); - } -} - -void MohawkEngine_Myst::updateActiveResource() { - const Common::Point &mouse = _system->getEventManager()->getMousePos(); - - _activeResource = nullptr; - for (uint16 i = 0; i < _resources.size(); i++) { - if (_resources[i]->contains(mouse) && _resources[i]->canBecomeActive()) { - _activeResource = _resources[i]; - break; - } - } -} - -void MohawkEngine_Myst::checkCurrentResource() { - const Common::Point &mouse = _system->getEventManager()->getMousePos(); - - // Tell previous resource the mouse is no longer hovering it - if (_hoverResource && !_hoverResource->contains(mouse)) { - _hoverResource->handleMouseLeave(); - _hoverResource = nullptr; - } - - for (uint16 i = 0; i < _resources.size(); i++) { - if (_resources[i]->contains(mouse) && _resources[i]->hasType(kMystAreaHover) - && _hoverResource != _resources[i]) { - _hoverResource = static_cast<MystAreaHover *>(_resources[i]); - _hoverResource->handleMouseEnter(); - } - } - - if (!_mouseClicked && _clickedResource) { - if (_clickedResource->isEnabled()) { - _clickedResource->handleMouseUp(); - } - _clickedResource = nullptr; - } else if (_mouseMoved && _clickedResource) { - if (_clickedResource->isEnabled()) { - _clickedResource->handleMouseDrag(); - } - } else if (_mouseClicked && !_clickedResource) { - if (_activeResource && _activeResource->isEnabled()) { - _clickedResource = _activeResource; - _clickedResource->handleMouseDown(); - } - } - - _mouseMoved = false; - - checkCursorHints(); -} - -MystArea *MohawkEngine_Myst::forceUpdateClickedResource() { - updateActiveResource(); - - _clickedResource = _activeResource; - - return _clickedResource; -} - -void MohawkEngine_Myst::loadCard() { - debugC(kDebugView, "Loading Card View: %d", _curCard); - - Common::SeekableReadStream *viewStream = getResource(ID_VIEW, _curCard); - - // Card Flags - _view.flags = viewStream->readUint16LE(); - debugC(kDebugView, "Flags: 0x%04X", _view.flags); - - // The Image Block (Reminiscent of Riven PLST resources) - uint16 conditionalImageCount = viewStream->readUint16LE(); - debugC(kDebugView, "Conditional Image Count: %d", conditionalImageCount); - if (conditionalImageCount != 0) { - for (uint16 i = 0; i < conditionalImageCount; i++) { - MystCondition conditionalImage; - - debugC(kDebugView, "\tImage %d:", i); - conditionalImage.var = viewStream->readUint16LE(); - debugC(kDebugView, "\t\tVar: %d", conditionalImage.var); - uint16 numStates = viewStream->readUint16LE(); - debugC(kDebugView, "\t\tNumber of States: %d", numStates); - for (uint16 j = 0; j < numStates; j++) { - conditionalImage.values.push_back(viewStream->readUint16LE()); - debugC(kDebugView, "\t\tState %d -> Value %d", j, conditionalImage.values[j]); - } - - _view.conditionalImages.push_back(conditionalImage); - } - _view.mainImage = 0; - } else { - _view.mainImage = viewStream->readUint16LE(); - debugC(kDebugView, "Main Image: %d", _view.mainImage); - } - - // The Sound Block (Reminiscent of Riven SLST resources) - _view.soundBlock = readSoundBlock(viewStream); - - // Resources that scripts can call upon - uint16 scriptResCount = viewStream->readUint16LE(); - debugC(kDebugView, "Script Resource Count: %d", scriptResCount); - for (uint16 i = 0; i < scriptResCount; i++) { - MystView::ScriptResource scriptResource; - - debugC(kDebugView, "\tResource %d:", i); - scriptResource.type = (MystView::ScriptResourceType) viewStream->readUint16LE(); - debugC(kDebugView, "\t\t Type: %d", scriptResource.type); - - switch (scriptResource.type) { - case MystView::kResourceImage: - debugC(kDebugView, "\t\t\t\t= Image"); - break; - case MystView::kResourceSound: - debugC(kDebugView, "\t\t\t\t= Sound"); - break; - case MystView::kResourceSwitch: - debugC(kDebugView, "\t\t\t\t= Resource Switch"); - break; - case MystView::kResourceImageNoCache: - debugC(kDebugView, "\t\t\t\t= Image - Caching disabled"); - break; - case MystView::kResourceSoundNoCache: - debugC(kDebugView, "\t\t\t\t= Sound - Caching disabled"); - break; - default: - debugC(kDebugView, "\t\t\t\t= Unknown"); - warning("Unknown script resource type '%d' in card '%d'", scriptResource.type, _curCard); - break; - } - - if (scriptResource.type == MystView::kResourceSwitch) { - scriptResource.switchVar = viewStream->readUint16LE(); - debugC(kDebugView, "\t\t Var: %d", scriptResource.switchVar); - uint16 count = viewStream->readUint16LE(); - debugC(kDebugView, "\t\t Resource List Count: %d", count); - scriptResource.switchResourceType = (MystView::ScriptResourceType) viewStream->readUint16LE(); - debugC(kDebugView, "\t\t u0: %d", scriptResource.switchResourceType); - - for (uint16 j = 0; j < count; j++) { - scriptResource.switchResourceIds.push_back(viewStream->readSint16LE()); - debugC(kDebugView, "\t\t Resource List %d: %d", j, scriptResource.switchResourceIds[j]); - } - } else { - scriptResource.id = viewStream->readUint16LE(); - debugC(kDebugView, "\t\t Id: %d", scriptResource.id); - } - - _view.scriptResources.push_back(scriptResource); - } - - // Identifiers for other resources. 0 if non existent. There is always an RLST. - _view.rlst = viewStream->readUint16LE(); - if (!_view.rlst) - error("RLST Index missing"); - - _view.hint = viewStream->readUint16LE(); - _view.init = viewStream->readUint16LE(); - _view.exit = viewStream->readUint16LE(); - - delete viewStream; - - // Precache Card Resources - uint32 cacheImageType; - if (getFeatures() & GF_ME) - cacheImageType = ID_PICT; - else - cacheImageType = ID_WDIB; - - // Precache Image Block data - if (_view.conditionalImages.size() != 0) { - for (uint16 i = 0; i < _view.conditionalImages.size(); i++) { - uint16 value = _scriptParser->getVar(_view.conditionalImages[i].var); - cachePreload(cacheImageType, _view.conditionalImages[i].values[value]); - } - } else { - cachePreload(cacheImageType, _view.mainImage); - } - - // Precache Sound Block data - if (_view.soundBlock.sound > 0) - cachePreload(ID_MSND, _view.soundBlock.sound); - else if (_view.soundBlock.sound == kMystSoundActionConditional) { - uint16 value = _scriptParser->getVar(_view.soundBlock.soundVar); - if (_view.soundBlock.soundList[value].action > 0) { - cachePreload(ID_MSND, _view.soundBlock.soundList[value].action); - } - } - - // Precache Script Resources - for (uint16 i = 0; i < _view.scriptResources.size(); i++) { - MystView::ScriptResourceType type; - int16 id; - if (_view.scriptResources[i].type == MystView::kResourceSwitch) { - type = _view.scriptResources[i].switchResourceType; - uint16 value = _scriptParser->getVar(_view.scriptResources[i].switchVar); - id = _view.scriptResources[i].switchResourceIds[value]; - } else { - type = _view.scriptResources[i].type; - id = _view.scriptResources[i].id; - } - - if (id < 0) continue; - - switch (type) { - case MystView::kResourceImage: - cachePreload(cacheImageType, id); - break; - case MystView::kResourceSound: - cachePreload(ID_MSND, id); - break; - default: - // The other resource types should not be cached - break; - } - } -} - -void MohawkEngine_Myst::unloadCard() { - _view.conditionalImages.clear(); - _view.soundBlock.soundList.clear(); - _view.scriptResources.clear(); - _hoverResource = nullptr; - _activeResource = nullptr; - _clickedResource = nullptr; -} - -void MohawkEngine_Myst::runInitScript() { - if (!_view.init) { - debugC(kDebugINIT, "No INIT Present"); - return; - } - - debugC(kDebugINIT, "Running INIT script"); - - Common::SeekableReadStream *initStream = getResource(ID_INIT, _view.init); - MystScript script = _scriptParser->readScript(initStream, kMystScriptInit); - delete initStream; - - _scriptParser->runScript(script); -} - -void MohawkEngine_Myst::runExitScript() { - if (!_view.exit) { - debugC(kDebugEXIT, "No EXIT Present"); - return; - } - - debugC(kDebugEXIT, "Running EXIT script"); - - Common::SeekableReadStream *exitStream = getResource(ID_EXIT, _view.exit); - MystScript script = _scriptParser->readScript(exitStream, kMystScriptExit); - delete exitStream; - - _scriptParser->runScript(script); -} - -void MohawkEngine_Myst::loadCursorHints() { - _cursorHints.clear(); - - if (!_view.hint) { - debugC(kDebugHint, "No HINT Present"); - return; - } - - debugC(kDebugHint, "Loading Cursor Hints:"); - - Common::SeekableReadStream *hintStream = getResource(ID_HINT, _curCard); - uint16 cursorHintCount = hintStream->readUint16LE(); - debugC(kDebugHint, "Cursor Hint Count: %d", cursorHintCount); - - for (uint16 i = 0; i < cursorHintCount; i++) { - MystCursorHint hint; - - debugC(kDebugHint, "Cursor Hint %d:", i); - hint.id = hintStream->readUint16LE(); - debugC(kDebugHint, "\tId: %d", hint.id); - hint.cursor = hintStream->readSint16LE(); - debugC(kDebugHint, "\tCursor: %d", hint.cursor); - - if (hint.cursor == -1) { - debugC(kDebugHint, "\tConditional Cursor Hints:"); - hint.variableHint.var = hintStream->readUint16LE(); - debugC(kDebugHint, "\tVar: %d", hint.variableHint.var); - uint16 numStates = hintStream->readUint16LE(); - debugC(kDebugHint, "\tNumber of States: %d", numStates); - for (uint16 j = 0; j < numStates; j++) { - hint.variableHint.values.push_back(hintStream->readUint16LE()); - debugC(kDebugHint, "\t\t State %d: Cursor %d", j, hint.variableHint.values[j]); - } - } else { - hint.variableHint.var = 0; - } - - _cursorHints.push_back(hint); - } - - delete hintStream; + _card->drawResourceRects(); } void MohawkEngine_Myst::setMainCursor(uint16 cursor) { @@ -1042,70 +694,22 @@ void MohawkEngine_Myst::setMainCursor(uint16 cursor) { _cursor->setCursor(_currentCursor); } -void MohawkEngine_Myst::checkCursorHints() { - if (!_view.hint) { - // Default to the main cursor when no hints are present - if (_currentCursor != _mainCursor) { - _currentCursor = _mainCursor; - _cursor->setCursor(_currentCursor); - } - return; +void MohawkEngine_Myst::refreshCursor() { + int16 cursor = _card->getActiveResourceCursor(); + if (cursor == -1) { + cursor = _mainCursor; } - // Check all the cursor hints to see if we're in a hotspot that contains a hint. - for (uint16 i = 0; i < _cursorHints.size(); i++) - if (_activeResource && _resources[_cursorHints[i].id] == _activeResource && _activeResource->isEnabled()) { - if (_cursorHints[i].cursor == -1) { - uint16 var_value = _scriptParser->getVar(_cursorHints[i].variableHint.var); - - if (var_value >= _cursorHints[i].variableHint.values.size()) - warning("Variable %d Out of Range in variable HINT Resource %d", _cursorHints[i].variableHint.var, i); - else { - _currentCursor = _cursorHints[i].variableHint.values[var_value]; - if (_currentCursor == 0) - _currentCursor = _mainCursor; - _cursor->setCursor(_currentCursor); - } - } else if (_currentCursor != _cursorHints[i].cursor) { - if (_cursorHints[i].cursor == 0) - _currentCursor = _mainCursor; - else - _currentCursor = _cursorHints[i].cursor; - - _cursor->setCursor(_currentCursor); - } - return; - } - - if (_currentCursor != _mainCursor) { - _currentCursor = _mainCursor; - _cursor->setCursor(_currentCursor); + if (cursor != _currentCursor) { + _currentCursor = cursor; + _cursor->setCursor(cursor); } } -void MohawkEngine_Myst::setResourceEnabled(uint16 resourceId, bool enable) { - if (resourceId < _resources.size()) { - _resources[resourceId]->setEnabled(enable); - } else - warning("Attempt to change unknown resource enable state"); -} - -void MohawkEngine_Myst::drawResourceImages() { - for (uint16 i = 0; i < _resources.size(); i++) - if (_resources[i]->isDrawSubimages()) - _resources[i]->drawDataToScreen(); -} - void MohawkEngine_Myst::redrawResource(MystAreaImageSwitch *resource, bool update) { resource->drawConditionalDataToScreen(_scriptParser->getVar(resource->getImageSwitchVar()), update); } -void MohawkEngine_Myst::redrawArea(uint16 var, bool update) { - for (uint16 i = 0; i < _resources.size(); i++) - if (_resources[i]->hasType(kMystAreaImageSwitch) && _resources[i]->getImageSwitchVar() == var) - redrawResource(static_cast<MystAreaImageSwitch *>(_resources[i]), update); -} - MystArea *MohawkEngine_Myst::loadResource(Common::SeekableReadStream *rlstStream, MystArea *parent) { MystArea *resource = nullptr; ResourceType type = static_cast<ResourceType>(rlstStream->readUint16LE()); @@ -1146,29 +750,6 @@ MystArea *MohawkEngine_Myst::loadResource(Common::SeekableReadStream *rlstStream return resource; } -void MohawkEngine_Myst::loadResources() { - for (uint32 i = 0; i < _resources.size(); i++) - delete _resources[i]; - - _resources.clear(); - - if (!_view.rlst) { - debugC(kDebugResource, "No RLST present"); - return; - } - - Common::SeekableReadStream *rlstStream = getResource(ID_RLST, _view.rlst); - uint16 resourceCount = rlstStream->readUint16LE(); - debugC(kDebugResource, "RLST Resource Count: %d", resourceCount); - - for (uint16 i = 0; i < resourceCount; i++) { - debugC(kDebugResource, "Resource #%d:", i); - _resources.push_back(loadResource(rlstStream, nullptr)); - } - - delete rlstStream; -} - Common::Error MohawkEngine_Myst::loadGameState(int slot) { if (_gameState->load(slot)) return Common::kNoError; @@ -1208,8 +789,7 @@ bool MohawkEngine_Myst::canLoadGameStateCurrently() { return false; } - if (_clickedResource) { - // Can't save while dragging resources + if (_card->isDraggingResource()) { return false; } @@ -1255,28 +835,28 @@ void MohawkEngine_Myst::dropPage() { // Redraw page area if (whitePage && _gameState->_globals.currentAge == kMystLibrary) { _scriptParser->toggleVar(41); - redrawArea(41); + _card->redrawArea(41); } else if (bluePage) { if (page == kBlueFirePlacePage) { if (_gameState->_globals.currentAge == kMystLibrary) - redrawArea(24); + _card->redrawArea(24); } else { - redrawArea(103); + _card->redrawArea(103); } } else if (redPage) { if (page == kRedFirePlacePage) { if (_gameState->_globals.currentAge == kMystLibrary) - redrawArea(25); + _card->redrawArea(25); } else if (page == kRedStoneshipPage) { if (_gameState->_globals.currentAge == kStoneship) - redrawArea(35); + _card->redrawArea(35); } else { - redrawArea(102); + _card->redrawArea(102); } } setMainCursor(kDefaultMystCursor); - checkCursorHints(); + refreshCursor(); } MystSoundBlock MohawkEngine_Myst::readSoundBlock(Common::ReadStream *stream) const { @@ -1317,7 +897,7 @@ MystSoundBlock MohawkEngine_Myst::readSoundBlock(Common::ReadStream *stream) con soundBlock.soundList.push_back(sound); } } else { - error("Unknown sound control value '%d' in card '%d'", soundBlock.sound, _curCard); + error("Unknown sound control value '%d' in card '%d'", soundBlock.sound, _card->getId()); } return soundBlock; diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h index 64fee10fde..867131a712 100644 --- a/engines/mohawk/myst.h +++ b/engines/mohawk/myst.h @@ -47,6 +47,7 @@ class MystSound; class MystArea; class MystAreaImageSwitch; class MystAreaHover; +class MystCard; // Engine Debug Flags enum { @@ -121,52 +122,7 @@ enum { // Other positive values are PlayNewSound of that id }; -// View flags -enum { - kMystZipDestination = (1 << 0) -}; - -struct MystView { - uint16 flags; - - // Image Data - Common::Array<MystCondition> conditionalImages; - uint16 mainImage; - - // Sound Data - MystSoundBlock soundBlock; - - // Script Resources - enum ScriptResourceType { - kResourceImage = 1, - kResourceSound = 2, - kResourceSwitch = 3, - kResourceImageNoCache = 4, - kResourceSoundNoCache = 5 - }; - - struct ScriptResource { - ScriptResourceType type; - uint16 id; - uint16 switchVar; - ScriptResourceType switchResourceType; - Common::Array<int16> switchResourceIds; - }; - Common::Array<ScriptResource> scriptResources; - - // Resource ID's - uint16 rlst; - uint16 hint; - uint16 init; - uint16 exit; -}; - -struct MystCursorHint { - uint16 id; - int16 cursor; - - MystCondition variableHint; -}; +typedef Common::SharedPtr<MystCard> MystCardPtr; class MohawkEngine_Myst : public MohawkEngine { protected: @@ -178,15 +134,16 @@ public: Common::SeekableReadStream *getResource(uint32 tag, uint16 id) override; Common::Array<uint16> getResourceIDList(uint32 type) const; + void cachePreload(uint32 tag, uint16 id); void changeToStack(uint16 stack, uint16 card, uint16 linkSrcSound, uint16 linkDstSound); void changeToCard(uint16 card, TransitionType transition); - uint16 getCurCard() { return _curCard; } + MystCard *getCard() { return _card.get(); }; + MystCardPtr getCardPtr() { return _card; }; uint16 getCurStack() { return _curStack; } void setMainCursor(uint16 cursor); uint16 getMainCursor() { return _mainCursor; } - void checkCursorHints(); - MystArea *forceUpdateClickedResource(); + void refreshCursor(); bool wait(uint32 duration, bool skippable = false); /** Update the game state according to events and update the screen */ @@ -207,19 +164,10 @@ public: MystGraphics *_gfx; MystGameState *_gameState; MystScriptParser *_scriptParser; - Common::Array<MystArea *> _resources; Common::RandomSource *_rnd; MystArea *loadResource(Common::SeekableReadStream *rlstStream, MystArea *parent); - void setResourceEnabled(uint16 resourceId, bool enable); - void redrawArea(uint16 var, bool update = true); void redrawResource(MystAreaImageSwitch *resource, bool update = true); - void drawResourceImages(); - void drawCardBackground(); - uint16 getCardBackgroundId(); - - template<class T> - T *getViewResource(uint index); void setCacheState(bool state) { _cache.enabled = state; } bool getCacheState() { return _cache.enabled; } @@ -253,65 +201,29 @@ private: MystOptionsDialog *_optionsDialog; MystScriptParser *_prevStack; ResourceCache _cache; - void cachePreload(uint32 tag, uint16 id); uint16 _curStack; - uint16 _curCard; + MystCardPtr _card; uint32 _lastSaveTime; - MystView _view; - - bool _runExitScript; bool hasGameSaveSupport() const; void dropPage(); - void loadCard(); - void unloadCard(); - void runInitScript(); - void runExitScript(); - - void loadResources(); - void drawResourceRects(); - void checkCurrentResource(); - void updateActiveResource(); - Common::String wrapMovieFilename(const Common::String &movieName, uint16 stack); - /** Area of type kMystAreaHover being hovered by the mouse, if any */ - MystAreaHover *_hoverResource; - - /** Active area being hovered by the mouse, if any */ - MystArea *_activeResource; - - /** Active area being clicked on / dragged, if any */ - MystArea *_clickedResource; - // Input bool _mouseClicked; bool _mouseMoved; bool _escapePressed; bool _waitingOnBlockingOperation; - Common::Array<MystCursorHint> _cursorHints; - void loadCursorHints(); uint16 _currentCursor; uint16 _mainCursor; // Also defines the current page being held (white, blue, red, or none) - void pauseEngineIntern(bool) override; + void pauseEngineIntern(bool pause) override; }; -template<class T> -T *MohawkEngine_Myst::getViewResource(uint index) { - T *resource = dynamic_cast<T *>(_resources[index]); - - if (!resource) { - error("View resource '%d' has unexpected type", index); - } - - return resource; -} - } // End of namespace Mohawk #endif diff --git a/engines/mohawk/myst_areas.cpp b/engines/mohawk/myst_areas.cpp index eff51bf1c9..2d2d3467a9 100644 --- a/engines/mohawk/myst_areas.cpp +++ b/engines/mohawk/myst_areas.cpp @@ -21,6 +21,7 @@ */ #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" #include "mohawk/myst_sound.h" @@ -152,11 +153,11 @@ void MystAreaAction::handleMouseUp() { const Common::String MystAreaAction::describe() { Common::String desc = MystArea::describe(); - if (_script->size() != 0) { + if (!_script.empty()) { desc += " ops:"; - for (uint i = 0; i < _script->size(); i++) - desc += " " + _vm->_scriptParser->getOpcodeDesc((*_script)[i].opcode); + for (uint i = 0; i < _script.size(); i++) + desc += " " + _vm->_scriptParser->getOpcodeDesc(_script[i].opcode); } return desc; @@ -419,7 +420,7 @@ void MystAreaImageSwitch::drawDataToScreen() { // This special case means redraw background if (imageToDraw == 0xFFFF) - imageToDraw = _vm->getCardBackgroundId(); + imageToDraw = _vm->getCard()->getBackgroundImageId(); _vm->_gfx->copyImageSectionToBackBuffer(imageToDraw, _subImages[subImageId].rect, _rect); } @@ -448,7 +449,7 @@ void MystAreaImageSwitch::drawConditionalDataToScreen(uint16 state, bool update) // This special case means redraw background if (imageToDraw == 0xFFFF) - imageToDraw = _vm->getCardBackgroundId(); + imageToDraw = _vm->getCard()->getBackgroundImageId(); // Draw to screen if (update) { @@ -542,7 +543,7 @@ void MystAreaSlider::restoreBackground() { Common::Rect dest = boundingBox(); src.top = 332 - dest.bottom; src.bottom = 332 - dest.top; - _vm->_gfx->copyImageSectionToScreen(_vm->getCardBackgroundId(), src, dest); + _vm->_gfx->copyImageSectionToScreen(_vm->getCard()->getBackgroundImageId(), src, dest); } void MystAreaSlider::handleMouseDown() { diff --git a/engines/mohawk/myst_card.cpp b/engines/mohawk/myst_card.cpp new file mode 100644 index 0000000000..71b546c047 --- /dev/null +++ b/engines/mohawk/myst_card.cpp @@ -0,0 +1,456 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mohawk/myst_card.h" + +#include "mohawk/myst_areas.h" +#include "mohawk/myst_graphics.h" + +#include "mohawk/resource.h" + +namespace Mohawk { + +MystCard::MystCard(MohawkEngine_Myst *vm, uint16 id) : + _vm(vm), + _id(id), + _hoverResource(nullptr), + _activeResource(nullptr), + _clickedResource(nullptr) { + + loadView(); + loadResources(); + loadCursorHints(); +} + +void MystCard::enter() { + // Handle images + drawBackground(); + + // Handle sound + _vm->applySoundBlock(_soundBlock); + + if (_flags & kMystZipDestination) + _vm->_gameState->addZipDest(_vm->getCurStack(), _id); + + // Run the entrance script (if present) + runInitScript(); + + // Update the images of each area too + drawResourceImages(); + + for (uint16 i = 0; i < _resources.size(); i++) + _resources[i]->handleCardChange(); +} + +void MystCard::leave() { + runExitScript(); +} + +MystCard::~MystCard() { + for (uint32 i = 0; i < _resources.size(); i++) + delete _resources[i]; +} + +uint16 MystCard::getId() const { + return _id; +} + +void MystCard::loadView() { + debugC(kDebugView, "Loading Card View: %d", _id); + + Common::SeekableReadStream *viewStream = _vm->getResource(ID_VIEW, _id); + + // Card Flags + _flags = viewStream->readUint16LE(); + debugC(kDebugView, "Flags: 0x%04X", _flags); + + // The Image Block (Reminiscent of Riven PLST resources) + uint16 conditionalImageCount = viewStream->readUint16LE(); + debugC(kDebugView, "Conditional Image Count: %d", conditionalImageCount); + if (conditionalImageCount != 0) { + for (uint16 i = 0; i < conditionalImageCount; i++) { + MystCondition conditionalImage; + + debugC(kDebugView, "\tImage %d:", i); + conditionalImage.var = viewStream->readUint16LE(); + debugC(kDebugView, "\t\tVar: %d", conditionalImage.var); + uint16 numStates = viewStream->readUint16LE(); + debugC(kDebugView, "\t\tNumber of States: %d", numStates); + for (uint16 j = 0; j < numStates; j++) { + conditionalImage.values.push_back(viewStream->readUint16LE()); + debugC(kDebugView, "\t\tState %d -> Value %d", j, conditionalImage.values[j]); + } + + _conditionalImages.push_back(conditionalImage); + } + _mainImage = 0; + } else { + _mainImage = viewStream->readUint16LE(); + debugC(kDebugView, "Main Image: %d", _mainImage); + } + + // The Sound Block (Reminiscent of Riven SLST resources) + _soundBlock = _vm->readSoundBlock(viewStream); + + // Resources that scripts can call upon + uint16 scriptResCount = viewStream->readUint16LE(); + debugC(kDebugView, "Script Resource Count: %d", scriptResCount); + for (uint16 i = 0; i < scriptResCount; i++) { + ScriptResource scriptResource; + + debugC(kDebugView, "\tResource %d:", i); + scriptResource.type = (ScriptResourceType) viewStream->readUint16LE(); + debugC(kDebugView, "\t\t Type: %d", scriptResource.type); + + switch (scriptResource.type) { + case kResourceImage: + debugC(kDebugView, "\t\t\t\t= Image"); + break; + case kResourceSound: + debugC(kDebugView, "\t\t\t\t= Sound"); + break; + case kResourceSwitch: + debugC(kDebugView, "\t\t\t\t= Resource Switch"); + break; + case kResourceImageNoCache: + debugC(kDebugView, "\t\t\t\t= Image - Caching disabled"); + break; + case kResourceSoundNoCache: + debugC(kDebugView, "\t\t\t\t= Sound - Caching disabled"); + break; + default: + debugC(kDebugView, "\t\t\t\t= Unknown"); + warning("Unknown script resource type '%d' in card '%d'", scriptResource.type, _id); + break; + } + + if (scriptResource.type == kResourceSwitch) { + scriptResource.switchVar = viewStream->readUint16LE(); + debugC(kDebugView, "\t\t Var: %d", scriptResource.switchVar); + uint16 count = viewStream->readUint16LE(); + debugC(kDebugView, "\t\t Resource List Count: %d", count); + scriptResource.switchResourceType = (ScriptResourceType) viewStream->readUint16LE(); + debugC(kDebugView, "\t\t u0: %d", scriptResource.switchResourceType); + + for (uint16 j = 0; j < count; j++) { + scriptResource.switchResourceIds.push_back(viewStream->readSint16LE()); + debugC(kDebugView, "\t\t Resource List %d: %d", j, scriptResource.switchResourceIds[j]); + } + } else { + scriptResource.id = viewStream->readUint16LE(); + debugC(kDebugView, "\t\t Id: %d", scriptResource.id); + } + + _scriptResources.push_back(scriptResource); + } + + // Identifiers for other resources. 0 if non existent. There is always an RLST. + _resourceListId = viewStream->readUint16LE(); + if (!_resourceListId) + error("RLST Index missing"); + + _hintResourceId = viewStream->readUint16LE(); + _initScriptId = viewStream->readUint16LE(); + _exitScriptId = viewStream->readUint16LE(); + + delete viewStream; + + // Precache Card Resources + uint32 cacheImageType; + if (_vm->getFeatures() & GF_ME) + cacheImageType = ID_PICT; + else + cacheImageType = ID_WDIB; + + // Precache Image Block data + if (!_conditionalImages.empty()) { + for (uint16 i = 0; i < _conditionalImages.size(); i++) { + uint16 value = _vm->_scriptParser->getVar(_conditionalImages[i].var); + _vm->cachePreload(cacheImageType, _conditionalImages[i].values[value]); + } + } else { + _vm->cachePreload(cacheImageType, _mainImage); + } + + // Precache Sound Block data + if (_soundBlock.sound > 0) + _vm->cachePreload(ID_MSND, _soundBlock.sound); + else if (_soundBlock.sound == kMystSoundActionConditional) { + uint16 value = _vm->_scriptParser->getVar(_soundBlock.soundVar); + if (_soundBlock.soundList[value].action > 0) { + _vm->cachePreload(ID_MSND, _soundBlock.soundList[value].action); + } + } + + // Precache Script Resources + for (uint16 i = 0; i < _scriptResources.size(); i++) { + ScriptResourceType type; + int16 id; + if (_scriptResources[i].type == kResourceSwitch) { + type = _scriptResources[i].switchResourceType; + uint16 value = _vm->_scriptParser->getVar(_scriptResources[i].switchVar); + id = _scriptResources[i].switchResourceIds[value]; + } else { + type = _scriptResources[i].type; + id = _scriptResources[i].id; + } + + if (id < 0) continue; + + switch (type) { + case kResourceImage: + _vm->cachePreload(cacheImageType, id); + break; + case kResourceSound: + _vm->cachePreload(ID_MSND, id); + break; + default: + // The other resource types should not be cached + break; + } + } +} + +void MystCard::loadCursorHints() { + if (!_hintResourceId) { + debugC(kDebugHint, "No HINT Present"); + return; + } + + debugC(kDebugHint, "Loading Cursor Hints:"); + + Common::SeekableReadStream *hintStream = _vm->getResource(ID_HINT, _id); + uint16 cursorHintCount = hintStream->readUint16LE(); + debugC(kDebugHint, "Cursor Hint Count: %d", cursorHintCount); + + for (uint16 i = 0; i < cursorHintCount; i++) { + MystCursorHint hint; + + debugC(kDebugHint, "Cursor Hint %d:", i); + hint.id = hintStream->readUint16LE(); + debugC(kDebugHint, "\tId: %d", hint.id); + hint.cursor = hintStream->readSint16LE(); + debugC(kDebugHint, "\tCursor: %d", hint.cursor); + + if (hint.cursor == -1) { + debugC(kDebugHint, "\tConditional Cursor Hints:"); + hint.variableHint.var = hintStream->readUint16LE(); + debugC(kDebugHint, "\tVar: %d", hint.variableHint.var); + uint16 numStates = hintStream->readUint16LE(); + debugC(kDebugHint, "\tNumber of States: %d", numStates); + for (uint16 j = 0; j < numStates; j++) { + hint.variableHint.values.push_back(hintStream->readUint16LE()); + debugC(kDebugHint, "\t\t State %d: Cursor %d", j, hint.variableHint.values[j]); + } + } else { + hint.variableHint.var = 0; + } + + _cursorHints.push_back(hint); + } + + delete hintStream; +} + +void MystCard::loadResources() { + if (!_resourceListId) { + debugC(kDebugResource, "No RLST present"); + return; + } + + Common::SeekableReadStream *rlstStream = _vm->getResource(ID_RLST, _resourceListId); + uint16 resourceCount = rlstStream->readUint16LE(); + debugC(kDebugResource, "RLST Resource Count: %d", resourceCount); + + for (uint16 i = 0; i < resourceCount; i++) { + debugC(kDebugResource, "Resource #%d:", i); + _resources.push_back(_vm->loadResource(rlstStream, nullptr)); + } + + delete rlstStream; +} + +uint16 MystCard::getBackgroundImageId() { + uint16 imageToDraw = 0; + + if (_conditionalImages.empty()) + imageToDraw = _mainImage; + else { + for (uint16 i = 0; i < _conditionalImages.size(); i++) { + uint16 varValue = _vm->_scriptParser->getVar(_conditionalImages[i].var); + if (varValue < _conditionalImages[i].values.size()) + imageToDraw = _conditionalImages[i].values[varValue]; + } + } + + return imageToDraw; +} + +void MystCard::drawBackground() { + _vm->_gfx->copyImageToBackBuffer(getBackgroundImageId(), Common::Rect(0, 0, 544, 332)); +} + +void MystCard::runInitScript() { + if (!_initScriptId) { + debugC(kDebugINIT, "No INIT Present"); + return; + } + + debugC(kDebugINIT, "Running INIT script"); + + Common::SeekableReadStream *initStream = _vm->getResource(ID_INIT, _initScriptId); + MystScript script = _vm->_scriptParser->readScript(initStream, kMystScriptInit); + delete initStream; + + _vm->_scriptParser->runScript(script); +} + +void MystCard::runExitScript() { + if (!_exitScriptId) { + debugC(kDebugEXIT, "No EXIT Present"); + return; + } + + debugC(kDebugEXIT, "Running EXIT script"); + + Common::SeekableReadStream *exitStream = _vm->getResource(ID_EXIT, _exitScriptId); + MystScript script = _vm->_scriptParser->readScript(exitStream, kMystScriptExit); + delete exitStream; + + _vm->_scriptParser->runScript(script); +} + +void MystCard::drawResourceRects() { + for (uint16 i = 0; i < _resources.size(); i++) { + _resources[i]->getRect().debugPrint(0); + _resources[i]->drawBoundingRect(); + } +} + +void MystCard::updateActiveResource(const Common::Point &mouse) { + _activeResource = nullptr; + for (uint16 i = 0; i < _resources.size(); i++) { + if (_resources[i]->contains(mouse) && _resources[i]->canBecomeActive()) { + _activeResource = _resources[i]; + break; + } + } +} + +MystArea *MystCard::forceUpdateClickedResource(const Common::Point &mouse) { + updateActiveResource(mouse); + + _clickedResource = _activeResource; + + return _clickedResource; +} + +void MystCard::updateResourcesForInput(const Common::Point &mouse, bool mouseClicked, bool mouseMoved) { + // Tell previous resource the mouse is no longer hovering it + if (_hoverResource && !_hoverResource->contains(mouse)) { + _hoverResource->handleMouseLeave(); + _hoverResource = nullptr; + } + + for (uint16 i = 0; i < _resources.size(); i++) { + if (_resources[i]->contains(mouse) && _resources[i]->hasType(kMystAreaHover) + && _hoverResource != _resources[i]) { + _hoverResource = static_cast<MystAreaHover *>(_resources[i]); + _hoverResource->handleMouseEnter(); + } + } + + if (!mouseClicked && _clickedResource) { + if (_clickedResource->isEnabled()) { + _clickedResource->handleMouseUp(); + } + _clickedResource = nullptr; + } else if (mouseMoved && _clickedResource) { + if (_clickedResource->isEnabled()) { + _clickedResource->handleMouseDrag(); + } + } else if (mouseClicked && !_clickedResource) { + if (_activeResource && _activeResource->isEnabled()) { + _clickedResource = _activeResource; + _clickedResource->handleMouseDown(); + } + } +} + +int16 MystCard::getActiveResourceCursor() { + if (!_hintResourceId) { + // Default to the main cursor when no hints are present + return -1; + } + + // Check all the cursor hints to see if we're in a hotspot that contains a hint. + for (uint16 i = 0; i < _cursorHints.size(); i++) { + if (_activeResource && _resources[_cursorHints[i].id] == _activeResource && _activeResource->isEnabled()) { + if (_cursorHints[i].cursor == -1) { + uint16 var_value = _vm->_scriptParser->getVar(_cursorHints[i].variableHint.var); + + if (var_value >= _cursorHints[i].variableHint.values.size()) + warning("Variable %d Out of Range in variable HINT Resource %d", _cursorHints[i].variableHint.var, + i); + else { + uint16 cursor = _cursorHints[i].variableHint.values[var_value]; + if (cursor == 0) + return -1; + else + return cursor; + } + } else { + if (_cursorHints[i].cursor == 0) + return -1; + else + return _cursorHints[i].cursor; + } + } + } + + return -1; +} + +void MystCard::setResourceEnabled(uint16 resourceIndex, bool enable) { + if (resourceIndex < _resources.size()) { + _resources[resourceIndex]->setEnabled(enable); + } else + warning("Attempt to change unknown resource enable state"); +} + +void MystCard::drawResourceImages() { + for (uint16 i = 0; i < _resources.size(); i++) + if (_resources[i]->isDrawSubimages()) + _resources[i]->drawDataToScreen(); +} + +void MystCard::redrawArea(uint16 var, bool updateScreen) { + for (uint16 i = 0; i < _resources.size(); i++) + if (_resources[i]->hasType(kMystAreaImageSwitch) && _resources[i]->getImageSwitchVar() == var) + _vm->redrawResource(static_cast<MystAreaImageSwitch *>(_resources[i]), updateScreen); +} + +bool MystCard::isDraggingResource() const { + return _clickedResource != nullptr; +} + +} // End of namespace Mohawk diff --git a/engines/mohawk/myst_card.h b/engines/mohawk/myst_card.h new file mode 100644 index 0000000000..056d211682 --- /dev/null +++ b/engines/mohawk/myst_card.h @@ -0,0 +1,185 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MYST_CARD_H +#define MYST_CARD_H + +#include "common/rect.h" + +#include "mohawk/myst.h" + +namespace Mohawk { + +/** + * A game view + * + * The names Card and Stack are legacy from the HyperCard engine used in + * the original mac version. + * + * Cards contain resources (hotspots), images, sounds, and cursor hints. + */ +class MystCard { +public: + MystCard(MohawkEngine_Myst *vm, uint16 id); + ~MystCard(); + + /** Get the id of the card */ + uint16 getId() const; + + /** Initialization routine used to draw a card for the first time */ + void enter(); + + /** Run the card's leave scripts */ + void leave(); + + /** Get a card resource (hotspot) by its index in the resource list */ + template<class T> + T *getResource(uint index); + + /** The list of resources in the card */ + Common::Array<MystArea *> _resources; + + /** Enable or disable a card resource */ + void setResourceEnabled(uint16 resourceIndex, bool enable); + + /** Update the card's active resource according to the mouse position */ + void updateActiveResource(const Common::Point &mouse); + + /** Set the card's currently clicked resource to the currently active resource */ + MystArea *forceUpdateClickedResource(const Common::Point &mouse); + + /** + * Get the mouse cursor that should be used when hovering the currently active resource + * + * -1 means that no specific cursor is defined for the active resource, or that there is no + * currently active resource. In that case the default main cursor should be used by the caller. + */ + int16 getActiveResourceCursor(); + + /** + * Call the resource event handlers to account for the new specified input + * + * For example call the mouse down event handler for the currently active resource + * if the mouse is clicked and there was no clicked resource previously. + */ + void updateResourcesForInput(const Common::Point &mouse, bool mouseClicked, bool mouseMoved); + + /** Is there a currently clicked resource */ + bool isDraggingResource() const; + + /** Retrieve the id of the background image to use when drawing the card */ + uint16 getBackgroundImageId(); + + /** Draw the card's background image to the backbuffer */ + void drawBackground(); + + /** Draw the card's image resources to the backbuffer */ + void drawResourceImages(); + + /** Draw debug rectangles around the card's resources */ + void drawResourceRects(); + + /** Redraw the card's resources that are affected by the specified variable */ + void redrawArea(uint16 var, bool updateScreen = true); + +private: + // View flags + enum { + kMystZipDestination = (1 << 0) + }; + + struct MystCursorHint { + uint16 id; + int16 cursor; + + MystCondition variableHint; + }; + + MohawkEngine_Myst *_vm; + + // General card data + uint16 _id; + uint16 _flags; + + // Image Data + Common::Array<MystCondition> _conditionalImages; + uint16 _mainImage; + + // Sound Data + MystSoundBlock _soundBlock; + + // Script Resources + enum ScriptResourceType { + kResourceImage = 1, + kResourceSound = 2, + kResourceSwitch = 3, + kResourceImageNoCache = 4, + kResourceSoundNoCache = 5 + }; + + struct ScriptResource { + ScriptResourceType type; + uint16 id; + uint16 switchVar; + ScriptResourceType switchResourceType; + Common::Array<int16> switchResourceIds; + }; + Common::Array<ScriptResource> _scriptResources; + + uint16 _resourceListId; + uint16 _hintResourceId; + uint16 _initScriptId; + uint16 _exitScriptId; + + Common::Array<MystCursorHint> _cursorHints; + + /** Area of type kMystAreaHover being hovered by the mouse, if any */ + MystAreaHover *_hoverResource; + + /** Active area being hovered by the mouse, if any */ + MystArea *_activeResource; + + /** Active area being clicked on / dragged, if any */ + MystArea *_clickedResource; + + void loadView(); + void loadResources(); + void loadCursorHints(); + + void runInitScript(); + void runExitScript(); +}; + +template<class T> +T *MystCard::getResource(uint index) { + T *resource = dynamic_cast<T *>(_resources[index]); + + if (!resource) { + error("View resource '%d' has unexpected type", index); + } + + return resource; +} + +} // End of namespace Mohawk + +#endif diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp index c1a593b430..9403bebda7 100644 --- a/engines/mohawk/myst_scripts.cpp +++ b/engines/mohawk/myst_scripts.cpp @@ -23,6 +23,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" #include "mohawk/myst_sound.h" @@ -163,16 +164,16 @@ void MystScriptParser::overrideOpcode(uint16 op, const char *name, MystScriptPar warning("Unable to find opcode %d to override with '%s'", op, name); } -void MystScriptParser::runScript(MystScript script, MystArea *invokingResource) { +void MystScriptParser::runScript(const MystScript &script, MystArea *invokingResource) { _scriptNestingLevel++; - for (uint16 i = 0; i < script->size(); i++) { - MystScriptEntry &entry = (*script)[i]; + for (uint16 i = 0; i < script.size(); i++) { + const MystScriptEntry &entry = script[i]; if (entry.type == kMystScriptNormal) _invokingResource = invokingResource; else - _invokingResource = _vm->_resources[entry.resourceId]; + _invokingResource = _vm->getCard()->getResource<MystArea>(entry.resourceId); runOpcode(entry.opcode, entry.var, entry.args); } @@ -233,13 +234,12 @@ MystScript MystScriptParser::readScript(Common::SeekableReadStream *stream, Myst assert(stream); assert(type != kMystScriptNone); - MystScript script = MystScript(new Common::Array<MystScriptEntry>()); - uint16 opcodeCount = stream->readUint16LE(); - script->resize(opcodeCount); + + MystScript script(opcodeCount); for (uint16 i = 0; i < opcodeCount; i++) { - MystScriptEntry &entry = (*script)[i]; + MystScriptEntry &entry = script[i]; entry.type = type; // Resource ID only exists in INIT and EXIT scripts @@ -316,12 +316,12 @@ void MystScriptParser::NOP(uint16 var, const ArgumentsArray &args) { void MystScriptParser::o_toggleVar(uint16 var, const ArgumentsArray &args) { toggleVar(var); - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void MystScriptParser::o_setVar(uint16 var, const ArgumentsArray &args) { if (setVarValue(var, args[0])) - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void MystScriptParser::o_changeCardSwitch4(uint16 var, const ArgumentsArray &args) { @@ -385,7 +385,7 @@ void MystScriptParser::o_takePage(uint16 var, const ArgumentsArray &args) { if (oldPage != _globals.heldPage) { _vm->_cursor->hideCursor(); - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); // Set new cursor if (_globals.heldPage != kNoPage) @@ -398,8 +398,8 @@ void MystScriptParser::o_takePage(uint16 var, const ArgumentsArray &args) { } void MystScriptParser::o_redrawCard(uint16 var, const ArgumentsArray &args) { - _vm->drawCardBackground(); - _vm->drawResourceImages(); + _vm->getCard()->drawBackground(); + _vm->getCard()->drawResourceImages(); _vm->_gfx->copyBackBufferToScreen(Common::Rect(544, 333)); } @@ -464,7 +464,7 @@ void MystScriptParser::o_drawAreaState(uint16 var, const ArgumentsArray &args) { } void MystScriptParser::o_redrawAreaForVar(uint16 var, const ArgumentsArray &args) { - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void MystScriptParser::o_changeCardDirectional(uint16 var, const ArgumentsArray &args) { @@ -483,7 +483,7 @@ void MystScriptParser::o_changeCardDirectional(uint16 var, const ArgumentsArray // Opcode 18 then "pops" this stored CardId and returns to that card. void MystScriptParser::o_changeCardPush(uint16 var, const ArgumentsArray &args) { - _savedCardId = _vm->getCurCard(); + _savedCardId = _vm->getCard()->getId(); uint16 cardId = args[0]; TransitionType transition = static_cast<TransitionType>(args[1]); @@ -510,7 +510,7 @@ void MystScriptParser::o_enableAreas(uint16 var, const ArgumentsArray &args) { if (args[i + 1] == 0xFFFF) resource = _invokingResource; else - resource = _vm->_resources[args[i + 1]]; + resource = _vm->getCard()->getResource<MystArea>(args[i + 1]); if (resource) resource->setEnabled(true); @@ -527,7 +527,7 @@ void MystScriptParser::o_disableAreas(uint16 var, const ArgumentsArray &args) { if (args[i + 1] == 0xFFFF) resource = _invokingResource; else - resource = _vm->_resources[args[i + 1]]; + resource = _vm->getCard()->getResource<MystArea>(args[i + 1]); if (resource) resource->setEnabled(false); @@ -548,7 +548,7 @@ void MystScriptParser::o_toggleAreasActivation(uint16 var, const ArgumentsArray if (args[i + 1] == 0xFFFF) resource = _invokingResource; else - resource = _vm->_resources[args[i + 1]]; + resource = _vm->getCard()->getResource<MystArea>(args[i + 1]); if (resource) resource->setEnabled(!resource->isEnabled()); @@ -804,8 +804,8 @@ void MystScriptParser::o_quit(uint16 var, const ArgumentsArray &args) { } void MystScriptParser::showMap() { - if (_vm->getCurCard() != getMap()) { - _savedMapCardId = _vm->getCurCard(); + if (_vm->getCard()->getId() != getMap()) { + _savedMapCardId = _vm->getCard()->getId(); _vm->changeToCard(getMap(), kTransitionCopy); } } diff --git a/engines/mohawk/myst_scripts.h b/engines/mohawk/myst_scripts.h index a7a840b9d3..f89a76e63a 100644 --- a/engines/mohawk/myst_scripts.h +++ b/engines/mohawk/myst_scripts.h @@ -56,14 +56,14 @@ struct MystScriptEntry { uint16 u1; }; -typedef Common::SharedPtr<Common::Array<MystScriptEntry> > MystScript; +typedef Common::Array<MystScriptEntry> MystScript; class MystScriptParser { public: explicit MystScriptParser(MohawkEngine_Myst *vm); virtual ~MystScriptParser(); - void runScript(MystScript script, MystArea *invokingResource = nullptr); + void runScript(const MystScript &script, MystArea *invokingResource = nullptr); void runOpcode(uint16 op, uint16 var = 0, const ArgumentsArray &args = ArgumentsArray()); const Common::String getOpcodeDesc(uint16 op); MystScript readScript(Common::SeekableReadStream *stream, MystScriptType type); diff --git a/engines/mohawk/myst_stacks/channelwood.cpp b/engines/mohawk/myst_stacks/channelwood.cpp index 726b3d6526..d1281fa5e0 100644 --- a/engines/mohawk/myst_stacks/channelwood.cpp +++ b/engines/mohawk/myst_stacks/channelwood.cpp @@ -23,6 +23,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" #include "mohawk/myst_sound.h" @@ -409,7 +410,7 @@ void Channelwood::o_leverEndMove(uint16 var, const ArgumentsArray &args) { if (soundId) _vm->_sound->playEffect(soundId); - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Channelwood::o_leverEndMoveResumeBackground(uint16 var, const ArgumentsArray &args) { @@ -513,10 +514,10 @@ void Channelwood::o_valveHandleMoveStop(uint16 var, const ArgumentsArray &args) _vm->_sound->playEffect(soundId); // Redraw valve - _vm->redrawArea(_valveVar); + _vm->getCard()->redrawArea(_valveVar); // Restore cursor - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Channelwood::o_valveHandleMove2(uint16 var, const ArgumentsArray &args) { @@ -573,7 +574,7 @@ void Channelwood::o_hologramMonitor(uint16 var, const ArgumentsArray &args) { if (_state.holoprojectorSelection != button || !_vm->_video->isVideoPlaying()) { _state.holoprojectorSelection = button; - _vm->redrawArea(17); + _vm->getCard()->redrawArea(17); _vm->_video->stopVideos(); @@ -605,8 +606,8 @@ void Channelwood::o_hologramMonitor(uint16 var, const ArgumentsArray &args) { void Channelwood::o_drawerOpen(uint16 var, const ArgumentsArray &args) { _siriusDrawerState = 1; - _vm->redrawArea(18, false); - _vm->redrawArea(102, false); + _vm->getCard()->redrawArea(18, false); + _vm->getCard()->redrawArea(102, false); } void Channelwood::o_hologramTemple(uint16 var, const ArgumentsArray &args) { @@ -635,7 +636,7 @@ void Channelwood::o_hologramTemple(uint16 var, const ArgumentsArray &args) { } void Channelwood::o_executeMouseUp(uint16 var, const ArgumentsArray &args) { - MystArea *resource = _vm->getViewResource<MystArea>(args[0]); + MystArea *resource = _vm->getCard()->getResource<MystArea>(args[0]); resource->handleMouseUp(); } diff --git a/engines/mohawk/myst_stacks/credits.cpp b/engines/mohawk/myst_stacks/credits.cpp index 80ccf7fe9a..135aded96c 100644 --- a/engines/mohawk/myst_stacks/credits.cpp +++ b/engines/mohawk/myst_stacks/credits.cpp @@ -22,6 +22,7 @@ #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/cursors.h" #include "mohawk/sound.h" @@ -71,7 +72,7 @@ void Credits::runPersistentScripts() { } // Draw next image - _vm->drawCardBackground(); + _vm->getCard()->drawBackground(); _vm->_gfx->copyBackBufferToScreen(Common::Rect(544, 333)); _startTime = _vm->_system->getMillis(); diff --git a/engines/mohawk/myst_stacks/mechanical.cpp b/engines/mohawk/myst_stacks/mechanical.cpp index a58e278590..495f40bee2 100644 --- a/engines/mohawk/myst_stacks/mechanical.cpp +++ b/engines/mohawk/myst_stacks/mechanical.cpp @@ -23,6 +23,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" #include "mohawk/myst_sound.h" @@ -298,7 +299,7 @@ bool Mechanical::setVarValue(uint16 var, uint16 value) { } void Mechanical::o_throneEnablePassage(uint16 var, const ArgumentsArray &args) { - _vm->_resources[args[0]]->setEnabled(getVar(var)); + _vm->getCard()->getResource<MystArea>(args[0])->setEnabled(getVar(var)); } void Mechanical::o_birdCrankStart(uint16 var, const ArgumentsArray &args) { @@ -407,7 +408,7 @@ void Mechanical::o_elevatorRotationStop(uint16 var, const ArgumentsArray &args) if (_elevatorRotationGearPosition > 12) break; - _vm->redrawArea(12); + _vm->getCard()->redrawArea(12); _vm->wait(100); } @@ -415,10 +416,10 @@ void Mechanical::o_elevatorRotationStop(uint16 var, const ArgumentsArray &args) _state.elevatorRotation = (_state.elevatorRotation + 1) % 10; _vm->_sound->playEffect(_elevatorRotationSoundId); - _vm->redrawArea(11); + _vm->getCard()->redrawArea(11); } - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Mechanical::o_fortressRotationSpeedStart(uint16 var, const ArgumentsArray &args) { @@ -455,7 +456,7 @@ void Mechanical::o_fortressRotationSpeedStop(uint16 var, const ArgumentsArray &a _fortressRotationSpeed = 0; - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Mechanical::o_fortressRotationBrakeStart(uint16 var, const ArgumentsArray &args) { @@ -485,7 +486,7 @@ void Mechanical::o_fortressRotationBrakeStop(uint16 var, const ArgumentsArray &a MystVideoInfo *lever = getInvokingResource<MystVideoInfo>(); lever->drawFrame(_fortressRotationBrake); - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Mechanical::o_fortressSimulationSpeedStart(uint16 var, const ArgumentsArray &args) { @@ -522,7 +523,7 @@ void Mechanical::o_fortressSimulationSpeedStop(uint16 var, const ArgumentsArray _fortressSimulationSpeed = 0; - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Mechanical::o_fortressSimulationBrakeStart(uint16 var, const ArgumentsArray &args) { @@ -552,7 +553,7 @@ void Mechanical::o_fortressSimulationBrakeStop(uint16 var, const ArgumentsArray MystVideoInfo *lever = getInvokingResource<MystVideoInfo>(); lever->drawFrame(_fortressSimulationBrake); - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Mechanical::o_elevatorWindowMovie(uint16 var, const ArgumentsArray &args) { @@ -664,32 +665,32 @@ void Mechanical::o_elevatorWaitTimeout(uint16 var, const ArgumentsArray &args) { void Mechanical::o_crystalEnterYellow(uint16 var, const ArgumentsArray &args) { _crystalLit = 3; - _vm->redrawArea(20); + _vm->getCard()->redrawArea(20); } void Mechanical::o_crystalEnterGreen(uint16 var, const ArgumentsArray &args) { _crystalLit = 1; - _vm->redrawArea(21); + _vm->getCard()->redrawArea(21); } void Mechanical::o_crystalEnterRed(uint16 var, const ArgumentsArray &args) { _crystalLit = 2; - _vm->redrawArea(22); + _vm->getCard()->redrawArea(22); } void Mechanical::o_crystalLeaveYellow(uint16 var, const ArgumentsArray &args) { _crystalLit = 0; - _vm->redrawArea(20); + _vm->getCard()->redrawArea(20); } void Mechanical::o_crystalLeaveGreen(uint16 var, const ArgumentsArray &args) { _crystalLit = 0; - _vm->redrawArea(21); + _vm->getCard()->redrawArea(21); } void Mechanical::o_crystalLeaveRed(uint16 var, const ArgumentsArray &args) { _crystalLit = 0; - _vm->redrawArea(22); + _vm->getCard()->redrawArea(22); } void Mechanical::o_throne_init(uint16 var, const ArgumentsArray &args) { @@ -698,9 +699,9 @@ void Mechanical::o_throne_init(uint16 var, const ArgumentsArray &args) { } void Mechanical::o_fortressStaircase_init(uint16 var, const ArgumentsArray &args) { - _vm->_resources[args[0]]->setEnabled(!_state.staircaseState); - _vm->_resources[args[1]]->setEnabled(!_state.staircaseState); - _vm->_resources[args[2]]->setEnabled(_state.staircaseState); + _vm->getCard()->getResource<MystArea>(args[0])->setEnabled(!_state.staircaseState); + _vm->getCard()->getResource<MystArea>(args[1])->setEnabled(!_state.staircaseState); + _vm->getCard()->getResource<MystArea>(args[2])->setEnabled(_state.staircaseState); } void Mechanical::birdSing_run() { @@ -724,7 +725,7 @@ void Mechanical::o_snakeBox_init(uint16 var, const ArgumentsArray &args) { } void Mechanical::elevatorRotation_run() { - _vm->redrawArea(12); + _vm->getCard()->redrawArea(12); _elevatorRotationGearPosition += _elevatorRotationSpeed; @@ -735,7 +736,7 @@ void Mechanical::elevatorRotation_run() { _state.elevatorRotation = (_state.elevatorRotation + 1) % 10; _vm->_sound->playEffect(_elevatorRotationSoundId); - _vm->redrawArea(11); + _vm->getCard()->redrawArea(11); _vm->wait(100); } } diff --git a/engines/mohawk/myst_stacks/myst.cpp b/engines/mohawk/myst_stacks/myst.cpp index 4adee5fc20..a3e5685be1 100644 --- a/engines/mohawk/myst_stacks/myst.cpp +++ b/engines/mohawk/myst_stacks/myst.cpp @@ -23,6 +23,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" #include "mohawk/myst_sound.h" @@ -1077,7 +1078,7 @@ void Myst::o_imagerChangeSelection(uint16 var, const ArgumentsArray &args) { _state.imagerSelection = 10 * d1 + d2; _state.imagerActive = 0; - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } } @@ -1101,7 +1102,7 @@ void Myst::o_dockVaultOpen(uint16 var, const ArgumentsArray &args) { _dockVaultState = 1; _vm->_sound->playEffect(soundId); - _vm->redrawArea(41, false); + _vm->getCard()->redrawArea(41, false); animatedUpdate(ArgumentsArray(args.begin() + 3, directionalUpdateDataSize), delay); } } @@ -1124,7 +1125,7 @@ void Myst::o_dockVaultClose(uint16 var, const ArgumentsArray &args) { _dockVaultState = 0; _vm->_sound->playEffect(soundId); - _vm->redrawArea(41, false); + _vm->getCard()->redrawArea(41, false); animatedUpdate(ArgumentsArray(args.begin() + 3, directionalUpdateDataSize), delay); } } @@ -1238,7 +1239,7 @@ void Myst::o_clockWheelsExecute(uint16 var, const ArgumentsArray &args) { _vm->waitUntilMovieEnds(gears); _state.clockTowerBridgeOpen = 1; - _vm->redrawArea(12); + _vm->getCard()->redrawArea(12); } else if (_state.clockTowerBridgeOpen && !correctTime) { _vm->_sound->playEffect(soundId); _vm->wait(500); @@ -1251,7 +1252,7 @@ void Myst::o_clockWheelsExecute(uint16 var, const ArgumentsArray &args) { _vm->waitUntilMovieEnds(gears); _state.clockTowerBridgeOpen = 0; - _vm->redrawArea(12); + _vm->getCard()->redrawArea(12); } } @@ -1464,7 +1465,7 @@ void Myst::o_generatorButtonPressed(uint16 var, const ArgumentsArray &args) { } // Redraw button - _vm->redrawArea(button->getImageSwitchVar()); + _vm->getCard()->redrawArea(button->getImageSwitchVar()); // Blow breaker if (_state.generatorVoltage > 59) @@ -1472,9 +1473,9 @@ void Myst::o_generatorButtonPressed(uint16 var, const ArgumentsArray &args) { } void Myst::generatorRedrawRocket() { - _vm->redrawArea(64); - _vm->redrawArea(65); - _vm->redrawArea(97); + _vm->getCard()->redrawArea(64); + _vm->getCard()->redrawArea(65); + _vm->getCard()->redrawArea(97); } void Myst::generatorButtonValue(MystArea *button, uint16 &mask, uint16 &value) { @@ -1536,7 +1537,7 @@ void Myst::o_cabinSafeChangeDigit(uint16 var, const ArgumentsArray &args) { _state.cabinSafeCombination = 100 * d1 + 10 * d2 + d3; - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void Myst::o_cabinSafeHandleStartMove(uint16 var, const ArgumentsArray &args) { @@ -1579,7 +1580,7 @@ void Myst::o_cabinSafeHandleEndMove(uint16 var, const ArgumentsArray &args) { // Used on Card 4100 MystVideoInfo *handle = getInvokingResource<MystVideoInfo>(); handle->drawFrame(0); - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Myst::o_observatoryMonthChangeStartIncrease(uint16 var, const ArgumentsArray &args) { @@ -1630,7 +1631,7 @@ void Myst::observatoryIncrementMonth(int16 increment) { _state.observatoryMonthSetting = newMonth; // Redraw digits - _vm->redrawArea(73); + _vm->getCard()->redrawArea(73); // Update slider _observatoryMonthSlider->setPosition(94 + 94 * _state.observatoryMonthSetting / 11); @@ -1696,8 +1697,8 @@ void Myst::observatoryIncrementDay(int16 increment) { _state.observatoryDaySetting = newDay; // Redraw digits - _vm->redrawArea(75); - _vm->redrawArea(74); + _vm->getCard()->redrawArea(75); + _vm->getCard()->redrawArea(74); // Update slider _observatoryDaySlider->setPosition(91 + 3 * _state.observatoryDaySetting); @@ -1755,10 +1756,10 @@ void Myst::observatoryIncrementYear(int16 increment) { _state.observatoryYearSetting = newYear; // Redraw digits - _vm->redrawArea(79); - _vm->redrawArea(78); - _vm->redrawArea(77); - _vm->redrawArea(76); + _vm->getCard()->redrawArea(79); + _vm->getCard()->redrawArea(78); + _vm->getCard()->redrawArea(77); + _vm->getCard()->redrawArea(76); // Update slider _observatoryYearSlider->setPosition(94 + 94 * _state.observatoryYearSetting / 9999); @@ -1816,14 +1817,14 @@ void Myst::observatoryIncrementTime(int16 increment) { _state.observatoryTimeSetting = newTime; // Redraw digits - _vm->redrawArea(80); - _vm->redrawArea(81); - _vm->redrawArea(82); - _vm->redrawArea(83); + _vm->getCard()->redrawArea(80); + _vm->getCard()->redrawArea(81); + _vm->getCard()->redrawArea(82); + _vm->getCard()->redrawArea(83); // Draw AM/PM if (!observatoryIsDDMMYYYY2400()) { - _vm->redrawArea(88); + _vm->getCard()->redrawArea(88); } // Update slider @@ -1870,7 +1871,7 @@ void Myst::o_observatoryGoButton(uint16 var, const ArgumentsArray &args) { // Redraw button _tempVar = 0; - _vm->redrawArea(105); + _vm->getCard()->redrawArea(105); } } @@ -1948,8 +1949,8 @@ void Myst::o_circuitBreakerMove(uint16 var, const ArgumentsArray &args) { void Myst::o_circuitBreakerEndMove(uint16 var, const ArgumentsArray &args) { MystVideoInfo *breaker = getInvokingResource<MystVideoInfo>(); - _vm->redrawArea(breaker->getImageSwitchVar()); - _vm->checkCursorHints(); + _vm->getCard()->redrawArea(breaker->getImageSwitchVar()); + _vm->refreshCursor(); } void Myst::o_boilerIncreasePressureStart(uint16 var, const ArgumentsArray &args) { @@ -1964,7 +1965,7 @@ void Myst::o_boilerLightPilot(uint16 var, const ArgumentsArray &args) { // Match is lit if (_cabinMatchState == 1) { _state.cabinPilotLightLit = 1; - _vm->redrawArea(98); + _vm->getCard()->redrawArea(98); boilerFireUpdate(false); @@ -1995,7 +1996,7 @@ Common::Rational Myst::boilerComputeGaugeRate(uint16 pressure, uint32 delay) { void Myst::boilerResetGauge(const Common::Rational &rate) { if (!_cabinGaugeMovie || _cabinGaugeMovie->endOfVideo()) { - if (_vm->getCurCard() == 4098) { + if (_vm->getCard()->getId() == 4098) { _cabinGaugeMovie = _vm->playMovie("cabingau", kMystStack); _cabinGaugeMovie->moveTo(243, 96); } else { @@ -2042,7 +2043,7 @@ void Myst::boilerPressureIncrease_run() { boilerFireUpdate(false); // Draw fire - _vm->redrawArea(305); + _vm->getCard()->redrawArea(305); } else if (_state.cabinValvePosition == 25) { if (_state.cabinPilotLightLit == 1) _vm->_sound->playBackground(8098, 49152); @@ -2054,7 +2055,7 @@ void Myst::boilerPressureIncrease_run() { _vm->_sound->playEffect(5098); // Redraw wheel - _vm->redrawArea(99); + _vm->getCard()->redrawArea(99); } } @@ -2067,14 +2068,14 @@ void Myst::boilerPressureDecrease_run() { boilerFireUpdate(false); // Draw fire - _vm->redrawArea(305); + _vm->getCard()->redrawArea(305); } // Pressure increasing sound _vm->_sound->playEffect(5098); // Redraw wheel - _vm->redrawArea(99); + _vm->getCard()->redrawArea(99); } } @@ -2126,7 +2127,7 @@ void Myst::basementPressureIncrease_run() { _vm->_sound->playEffect(4642); // Redraw wheel - _vm->redrawArea(99); + _vm->getCard()->redrawArea(99); } } @@ -2139,7 +2140,7 @@ void Myst::basementPressureDecrease_run() { _vm->_sound->playEffect(4642); // Redraw wheel - _vm->redrawArea(99); + _vm->getCard()->redrawArea(99); } } @@ -2184,7 +2185,7 @@ void Myst::tree_run() { } // Stop background music if going up from book room - if (_vm->getCurCard() == 4630) { + if (_vm->getCard()->getId() == 4630) { if (_state.treePosition > 0) _vm->_sound->stopBackground(); else @@ -2192,7 +2193,7 @@ void Myst::tree_run() { } // Redraw tree - _vm->redrawArea(72); + _vm->getCard()->redrawArea(72); // Check if alcove is accessible treeSetAlcoveAccessible(); @@ -2235,7 +2236,7 @@ void Myst::o_rocketSoundSliderMove(uint16 var, const ArgumentsArray &args) { } void Myst::o_rocketSoundSliderEndMove(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); if (_state.generatorVoltage == 59 && !_state.generatorBreakers && _rocketSliderSound) _vm->_sound->stopEffect(); @@ -2382,7 +2383,7 @@ void Myst::o_rocketPianoMove(uint16 var, const ArgumentsArray &args) { _vm->_gfx->copyImageSectionToScreen(key->getSubImage(0).wdib, src, dest); if (piano.contains(mouse)) { - MystArea *resource = _vm->forceUpdateClickedResource(); + MystArea *resource = _vm->getCard()->forceUpdateClickedResource(mouse); if (resource && resource->hasType(kMystAreaDrag)) { // Press new key key = static_cast<MystAreaDrag *>(resource); @@ -2472,7 +2473,7 @@ void Myst::o_rocketLeverMove(uint16 var, const ArgumentsArray &args) { void Myst::o_rocketLeverEndMove(uint16 var, const ArgumentsArray &args) { MystVideoInfo *lever = getInvokingResource<MystVideoInfo>(); - _vm->checkCursorHints(); + _vm->refreshCursor(); _rocketLeverPosition = 0; lever->drawFrame(0); } @@ -2517,7 +2518,7 @@ void Myst::o_observatoryMonthSliderStartMove(uint16 var, const ArgumentsArray &a } void Myst::o_observatoryMonthSliderEndMove(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); _vm->_sound->resumeBackground(); observatoryUpdateMonth(); @@ -2533,7 +2534,7 @@ void Myst::observatoryUpdateMonth() { _vm->wait(20); // Redraw digits - _vm->redrawArea(73); + _vm->getCard()->redrawArea(73); } } @@ -2545,7 +2546,7 @@ void Myst::o_observatoryDaySliderStartMove(uint16 var, const ArgumentsArray &arg } void Myst::o_observatoryDaySliderEndMove(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); _vm->_sound->resumeBackground(); observatoryUpdateDay(); @@ -2561,8 +2562,8 @@ void Myst::observatoryUpdateDay() { _vm->wait(20); // Redraw digits - _vm->redrawArea(75); - _vm->redrawArea(74); + _vm->getCard()->redrawArea(75); + _vm->getCard()->redrawArea(74); } } @@ -2574,7 +2575,7 @@ void Myst::o_observatoryYearSliderStartMove(uint16 var, const ArgumentsArray &ar } void Myst::o_observatoryYearSliderEndMove(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); _vm->_sound->resumeBackground(); observatoryUpdateYear(); @@ -2590,10 +2591,10 @@ void Myst::observatoryUpdateYear() { _vm->wait(20); // Redraw digits - _vm->redrawArea(79); - _vm->redrawArea(78); - _vm->redrawArea(77); - _vm->redrawArea(76); + _vm->getCard()->redrawArea(79); + _vm->getCard()->redrawArea(78); + _vm->getCard()->redrawArea(77); + _vm->getCard()->redrawArea(76); } } @@ -2605,7 +2606,7 @@ void Myst::o_observatoryTimeSliderStartMove(uint16 var, const ArgumentsArray &ar } void Myst::o_observatoryTimeSliderEndMove(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); _vm->_sound->resumeBackground(); observatoryUpdateTime(); @@ -2621,14 +2622,14 @@ void Myst::observatoryUpdateTime() { _vm->wait(20); // Redraw digits - _vm->redrawArea(80); - _vm->redrawArea(81); - _vm->redrawArea(82); - _vm->redrawArea(83); + _vm->getCard()->redrawArea(80); + _vm->getCard()->redrawArea(81); + _vm->getCard()->redrawArea(82); + _vm->getCard()->redrawArea(83); // Draw AM/PM if (!observatoryIsDDMMYYYY2400()) - _vm->redrawArea(88); + _vm->getCard()->redrawArea(88); } } @@ -2706,12 +2707,12 @@ void Myst::matchBurn_run() { void Myst::o_courtyardBoxEnter(uint16 var, const ArgumentsArray &args) { _tempVar = 1; _vm->_sound->playEffect(_courtyardBoxSound); - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void Myst::o_courtyardBoxLeave(uint16 var, const ArgumentsArray &args) { _tempVar = 0; - _vm->redrawArea(var); + _vm->getCard()->redrawArea(var); } void Myst::o_clockMinuteWheelStartTurn(uint16 var, const ArgumentsArray &args) { @@ -2741,7 +2742,7 @@ void Myst::clockWheel_run() { else clockWheelTurn(38); - _vm->redrawArea(37); + _vm->getCard()->redrawArea(37); } } @@ -2758,7 +2759,7 @@ void Myst::clockWheelStartTurn(uint16 wheel) { else clockWheelTurn(38); - _vm->redrawArea(37); + _vm->getCard()->redrawArea(37); // Continue turning wheel until mouse button is released _clockTurningWheel = wheel; @@ -2877,12 +2878,12 @@ void Myst::o_dockVaultForceClose(uint16 var, const ArgumentsArray &args) { // Open switch _state.dockMarkerSwitch = 1; _vm->_sound->playEffect(4143); - _vm->redrawArea(4); + _vm->getCard()->redrawArea(4); // Close vault _dockVaultState = 0; _vm->_sound->playEffect(soundId); - _vm->redrawArea(41, false); + _vm->getCard()->redrawArea(41, false); animatedUpdate(ArgumentsArray(args.begin() + 3, directionalUpdateDataSize), delay); } } @@ -3027,7 +3028,7 @@ void Myst::clockGearsCheckSolution() { // Gear opening video _vm->playMovieBlocking("cl1wggat", kMystStack, 195, 225); _state.gearsOpen = 1; - _vm->redrawArea(40); + _vm->getCard()->redrawArea(40); _vm->_sound->playBackground(4113, 16384); } @@ -3085,7 +3086,7 @@ void Myst::clockReset() { // Redraw gear _state.gearsOpen = 0; - _vm->redrawArea(40); + _vm->getCard()->redrawArea(40); } _vm->_cursor->showCursor(); @@ -3131,7 +3132,7 @@ void Myst::o_clockResetLeverEndMove(uint16 var, const ArgumentsArray &args) { lever->releaseLeverV(); - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Myst::o_libraryBook_init(uint16 var, const ArgumentsArray &args) { @@ -3189,7 +3190,7 @@ void Myst::towerRotationMap_run() { void Myst::o_towerRotationMap_init(uint16 var, const ArgumentsArray &args) { _towerRotationMapRunning = true; _towerRotationMapTower = getInvokingResource<MystAreaImageSwitch>(); - _towerRotationMapLabel = _vm->getViewResource<MystAreaImageSwitch>(args[0]); + _towerRotationMapLabel = _vm->getCard()->getResource<MystAreaImageSwitch>(args[0]); _tempVar = 0; _startTime = 0; _towerRotationMapClicked = false; @@ -3197,11 +3198,11 @@ void Myst::o_towerRotationMap_init(uint16 var, const ArgumentsArray &args) { void Myst::towerRotationDrawBuildings() { // Draw library - _vm->redrawArea(304, false); + _vm->getCard()->redrawArea(304, false); // Draw other resources for (uint i = 1; i <= 10; i++) { - MystAreaImageSwitch *resource = _vm->getViewResource<MystAreaImageSwitch>(i); + MystAreaImageSwitch *resource = _vm->getCard()->getResource<MystAreaImageSwitch>(i); _vm->redrawResource(resource, false); } } @@ -3279,7 +3280,7 @@ void Myst::towerRotationMapDrawLine(const Common::Point &end, bool rotationLabel src.bottom = 332 - rect.top; // Redraw background - _vm->_gfx->copyImageSectionToBackBuffer(_vm->getCardBackgroundId(), src, rect); + _vm->_gfx->copyImageSectionToBackBuffer(_vm->getCard()->getBackgroundImageId(), src, rect); // Draw buildings towerRotationDrawBuildings(); @@ -3392,9 +3393,9 @@ void Myst::generatorControlRoom_run(void) { _generatorVoltage++; // Redraw generator gauge - _vm->redrawArea(62); - _vm->redrawArea(63); - _vm->redrawArea(96); + _vm->getCard()->redrawArea(62); + _vm->getCard()->redrawArea(63); + _vm->getCard()->redrawArea(96); } } @@ -3457,16 +3458,16 @@ void Myst::o_observatory_init(uint16 var, const ArgumentsArray &args) { _tempVar = 0; _observatoryNotInitialized = true; _observatoryVisualizer = getInvokingResource<MystAreaImageSwitch>(); - _observatoryGoButton = _vm->getViewResource<MystAreaImageSwitch>(args[0]); + _observatoryGoButton = _vm->getCard()->getResource<MystAreaImageSwitch>(args[0]); if (observatoryIsDDMMYYYY2400()) { - _observatoryDaySlider = _vm->getViewResource<MystAreaSlider>(args[1]); - _observatoryMonthSlider = _vm->getViewResource<MystAreaSlider>(args[2]); + _observatoryDaySlider = _vm->getCard()->getResource<MystAreaSlider>(args[1]); + _observatoryMonthSlider = _vm->getCard()->getResource<MystAreaSlider>(args[2]); } else { - _observatoryMonthSlider = _vm->getViewResource<MystAreaSlider>(args[1]); - _observatoryDaySlider = _vm->getViewResource<MystAreaSlider>(args[2]); + _observatoryMonthSlider = _vm->getCard()->getResource<MystAreaSlider>(args[1]); + _observatoryDaySlider = _vm->getCard()->getResource<MystAreaSlider>(args[2]); } - _observatoryYearSlider = _vm->getViewResource<MystAreaSlider>(args[3]); - _observatoryTimeSlider = _vm->getViewResource<MystAreaSlider>(args[4]); + _observatoryYearSlider = _vm->getCard()->getResource<MystAreaSlider>(args[3]); + _observatoryTimeSlider = _vm->getCard()->getResource<MystAreaSlider>(args[4]); // Set date selection sliders position _observatoryDaySlider->setPosition(_state.observatoryDaySlider); @@ -3610,13 +3611,13 @@ void Myst::o_boilerMovies_init(uint16 var, const ArgumentsArray &args) { } void Myst::boilerFireInit() { - if (_vm->getCurCard() == 4098) { + if (_vm->getCard()->getId() == 4098) { _cabinFireMovie = _vm->playMovie("cabfire", kMystStack); _cabinFireMovie->moveTo(240, 279); _cabinFireMovie->setLooping(true); _cabinFireMovie->pause(true); - _vm->redrawArea(305); + _vm->getCard()->redrawArea(305); boilerFireUpdate(true); } else { if (_state.cabinPilotLightLit == 1 && _state.cabinValvePosition >= 1) { @@ -3646,7 +3647,7 @@ void Myst::boilerFireUpdate(bool init) { } void Myst::boilerGaugeInit() { - if (_vm->getCurCard() == 4098) { + if (_vm->getCard()->getId() == 4098) { _cabinGaugeMovie = _vm->playMovie("cabingau", kMystStack); _cabinGaugeMovie->moveTo(243, 96); } else { @@ -3668,11 +3669,11 @@ void Myst::boilerGaugeInit() { void Myst::o_rocketSliders_init(uint16 var, const ArgumentsArray &args) { _rocketLinkBook.reset(); - _rocketSlider1 = _vm->getViewResource<MystAreaSlider>(args[0]); - _rocketSlider2 = _vm->getViewResource<MystAreaSlider>(args[1]); - _rocketSlider3 = _vm->getViewResource<MystAreaSlider>(args[2]); - _rocketSlider4 = _vm->getViewResource<MystAreaSlider>(args[3]); - _rocketSlider5 = _vm->getViewResource<MystAreaSlider>(args[4]); + _rocketSlider1 = _vm->getCard()->getResource<MystAreaSlider>(args[0]); + _rocketSlider2 = _vm->getCard()->getResource<MystAreaSlider>(args[1]); + _rocketSlider3 = _vm->getCard()->getResource<MystAreaSlider>(args[2]); + _rocketSlider4 = _vm->getCard()->getResource<MystAreaSlider>(args[3]); + _rocketSlider5 = _vm->getCard()->getResource<MystAreaSlider>(args[4]); // Initialize sliders position for (uint i = 0; i < 5; i++) diff --git a/engines/mohawk/myst_stacks/selenitic.cpp b/engines/mohawk/myst_stacks/selenitic.cpp index 239030645c..8d95cb5172 100644 --- a/engines/mohawk/myst_stacks/selenitic.cpp +++ b/engines/mohawk/myst_stacks/selenitic.cpp @@ -24,6 +24,7 @@ #include "mohawk/myst.h" #include "mohawk/graphics.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_state.h" #include "mohawk/myst_sound.h" #include "mohawk/video.h" @@ -1086,19 +1087,19 @@ void Selenitic::o_soundReceiver_init(uint16 var, const ArgumentsArray &args) { // Used for Card 1245 (Sound Receiver) _soundReceiverRunning = true; - _soundReceiverRightButton = _vm->getViewResource<MystAreaImageSwitch>(0); - _soundReceiverLeftButton = _vm->getViewResource<MystAreaImageSwitch>(1); - _soundReceiverSigmaButton = _vm->getViewResource<MystAreaImageSwitch>(2); - _soundReceiverSources[4] = _vm->getViewResource<MystAreaImageSwitch>(3); - _soundReceiverSources[3] = _vm->getViewResource<MystAreaImageSwitch>(4); - _soundReceiverSources[2] = _vm->getViewResource<MystAreaImageSwitch>(5); - _soundReceiverSources[1] = _vm->getViewResource<MystAreaImageSwitch>(6); - _soundReceiverSources[0] = _vm->getViewResource<MystAreaImageSwitch>(7); - _soundReceiverViewer = _vm->getViewResource<MystAreaImageSwitch>(8); - _soundReceiverAngle1 = _vm->getViewResource<MystAreaImageSwitch>(10); - _soundReceiverAngle2 = _vm->getViewResource<MystAreaImageSwitch>(11); - _soundReceiverAngle3 = _vm->getViewResource<MystAreaImageSwitch>(12); - _soundReceiverAngle4 = _vm->getViewResource<MystAreaImageSwitch>(13); + _soundReceiverRightButton = _vm->getCard()->getResource<MystAreaImageSwitch>(0); + _soundReceiverLeftButton = _vm->getCard()->getResource<MystAreaImageSwitch>(1); + _soundReceiverSigmaButton = _vm->getCard()->getResource<MystAreaImageSwitch>(2); + _soundReceiverSources[4] = _vm->getCard()->getResource<MystAreaImageSwitch>(3); + _soundReceiverSources[3] = _vm->getCard()->getResource<MystAreaImageSwitch>(4); + _soundReceiverSources[2] = _vm->getCard()->getResource<MystAreaImageSwitch>(5); + _soundReceiverSources[1] = _vm->getCard()->getResource<MystAreaImageSwitch>(6); + _soundReceiverSources[0] = _vm->getCard()->getResource<MystAreaImageSwitch>(7); + _soundReceiverViewer = _vm->getCard()->getResource<MystAreaImageSwitch>(8); + _soundReceiverAngle1 = _vm->getCard()->getResource<MystAreaImageSwitch>(10); + _soundReceiverAngle2 = _vm->getCard()->getResource<MystAreaImageSwitch>(11); + _soundReceiverAngle3 = _vm->getCard()->getResource<MystAreaImageSwitch>(12); + _soundReceiverAngle4 = _vm->getCard()->getResource<MystAreaImageSwitch>(13); uint16 currentSource = _state.soundReceiverCurrentSource; _soundReceiverPosition = &_state.soundReceiverPositions[currentSource]; @@ -1111,32 +1112,33 @@ void Selenitic::o_soundReceiver_init(uint16 var, const ArgumentsArray &args) { } void Selenitic::o_soundLock_init(uint16 var, const ArgumentsArray &args) { - for (uint i = 0; i < _vm->_resources.size(); i++) { - if (_vm->_resources[i]->hasType(kMystAreaSlider)) { - switch (_vm->_resources[i]->getImageSwitchVar()) { + for (uint i = 0; i < _vm->getCard()->_resources.size(); i++) { + if (_vm->getCard()->_resources[i]->hasType(kMystAreaSlider)) { + switch (_vm->getCard()->_resources[i]->getImageSwitchVar()) { case 20: - _soundLockSlider1 = _vm->getViewResource<MystAreaSlider>(i); + _soundLockSlider1 = _vm->getCard()->getResource<MystAreaSlider>(i); _soundLockSlider1->setStep(_state.soundLockSliderPositions[0]); break; case 21: - _soundLockSlider2 = _vm->getViewResource<MystAreaSlider>(i); + _soundLockSlider2 = _vm->getCard()->getResource<MystAreaSlider>(i); _soundLockSlider2->setStep(_state.soundLockSliderPositions[1]); break; case 22: - _soundLockSlider3 = _vm->getViewResource<MystAreaSlider>(i); + _soundLockSlider3 = _vm->getCard()->getResource<MystAreaSlider>(i); _soundLockSlider3->setStep(_state.soundLockSliderPositions[2]); break; case 23: - _soundLockSlider4 = _vm->getViewResource<MystAreaSlider>(i); + _soundLockSlider4 = _vm->getCard()->getResource<MystAreaSlider>(i); _soundLockSlider4->setStep(_state.soundLockSliderPositions[3]); break; case 24: - _soundLockSlider5 = _vm->getViewResource<MystAreaSlider>(i); + _soundLockSlider5 = _vm->getCard()->getResource<MystAreaSlider>(i); _soundLockSlider5->setStep(_state.soundLockSliderPositions[4]); break; } - } else if (_vm->_resources[i]->hasType(kMystAreaImageSwitch) && _vm->_resources[i]->getImageSwitchVar() == 28) { - _soundLockButton = _vm->getViewResource<MystAreaImageSwitch>(i); + } else if (_vm->getCard()->_resources[i]->hasType(kMystAreaImageSwitch) + && _vm->getCard()->_resources[i]->getImageSwitchVar() == 28) { + _soundLockButton = _vm->getCard()->getResource<MystAreaImageSwitch>(i); } } diff --git a/engines/mohawk/myst_stacks/stoneship.cpp b/engines/mohawk/myst_stacks/stoneship.cpp index cd1db68d44..0ae78c17d8 100644 --- a/engines/mohawk/myst_stacks/stoneship.cpp +++ b/engines/mohawk/myst_stacks/stoneship.cpp @@ -23,6 +23,7 @@ #include "mohawk/cursors.h" #include "mohawk/myst.h" #include "mohawk/myst_areas.h" +#include "mohawk/myst_card.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" #include "mohawk/myst_sound.h" @@ -426,8 +427,8 @@ void Stoneship::o_pumpTurnOff(uint16 var, const ArgumentsArray &args) { warning("Incorrect pump state"); } - for (uint i = 0; i < _vm->_resources.size(); i++) { - MystArea *resource = _vm->_resources[i]; + for (uint i = 0; i < _vm->getCard()->_resources.size(); i++) { + MystArea *resource = _vm->getCard()->_resources[i]; if (resource->hasType(kMystAreaImageSwitch) && resource->getImageSwitchVar() == buttonVar) { static_cast<MystAreaImageSwitch *>(resource)->drawConditionalDataToScreen(0, true); break; @@ -438,7 +439,7 @@ void Stoneship::o_pumpTurnOff(uint16 var, const ArgumentsArray &args) { void Stoneship::o_brotherDoorOpen(uint16 var, const ArgumentsArray &args) { _brotherDoorOpen = 1; - _vm->redrawArea(19, 0); + _vm->getCard()->redrawArea(19, 0); animatedUpdate(args, 5); } @@ -454,7 +455,7 @@ void Stoneship::o_cabinBookMovie(uint16 var, const ArgumentsArray &args) { } void Stoneship::o_drawerOpenSirius(uint16 var, const ArgumentsArray &args) { - MystAreaImageSwitch *drawer = _vm->getViewResource<MystAreaImageSwitch>(args[0]); + MystAreaImageSwitch *drawer = _vm->getCard()->getResource<MystAreaImageSwitch>(args[0]); if (drawer->getImageSwitchVar() == 35) { drawer->drawConditionalDataToScreen(getVar(102), 0); @@ -496,7 +497,7 @@ void Stoneship::o_telescopeMove(uint16 var, const ArgumentsArray &args) { } void Stoneship::o_telescopeStop(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Stoneship::o_generatorStart(uint16 var, const ArgumentsArray &args) { @@ -589,7 +590,7 @@ void Stoneship::batteryDeplete_run() { } void Stoneship::o_drawerOpenAchenar(uint16 var, const ArgumentsArray &args) { - MystAreaImageSwitch *drawer = _vm->getViewResource<MystAreaImageSwitch>(args[0]); + MystAreaImageSwitch *drawer = _vm->getCard()->getResource<MystAreaImageSwitch>(args[0]); drawer->drawConditionalDataToScreen(0, 0); _vm->_gfx->runTransition(kTransitionTopToBottom, drawer->getRect(), 25, 5); } @@ -644,7 +645,7 @@ void Stoneship::o_hologramSelectionMove(uint16 var, const ArgumentsArray &args) } void Stoneship::o_hologramSelectionStop(uint16 var, const ArgumentsArray &args) { - _vm->checkCursorHints(); + _vm->refreshCursor(); } void Stoneship::o_compassButton(uint16 var, const ArgumentsArray &args) { @@ -785,10 +786,10 @@ void Stoneship::o_drawerCloseOpened(uint16 var, const ArgumentsArray &args) { void Stoneship::drawerClose(uint16 drawer) { _chestDrawersOpen = 0; - _vm->drawCardBackground(); - _vm->drawResourceImages(); + _vm->getCard()->drawBackground(); + _vm->getCard()->drawResourceImages(); - MystArea *res = _vm->_resources[drawer]; + MystArea *res = _vm->getCard()->getResource<MystArea>(drawer); _vm->_gfx->runTransition(kTransitionBottomToTop, res->getRect(), 25, 5); } @@ -844,8 +845,8 @@ void Stoneship::batteryGauge_run() { _batteryLastCharge = batteryCharge; // Redraw card - _vm->drawCardBackground(); - _vm->drawResourceImages(); + _vm->getCard()->drawBackground(); + _vm->getCard()->drawResourceImages(); _vm->_gfx->copyBackBufferToScreen(Common::Rect(544, 333)); } } @@ -946,12 +947,12 @@ void Stoneship::o_achenarDrawers_init(uint16 var, const ArgumentsArray &args) { uint16 count1 = args[0]; for (uint16 i = 0; i < count1; i++) { debugC(kDebugScript, "Disable hotspot index %d", args[i + 1]); - _vm->setResourceEnabled(args[i + 1], false); + _vm->getCard()->setResourceEnabled(args[i + 1], false); } uint16 count2 = args[count1 + 1]; for (uint16 i = 0; i < count2; i++) { debugC(kDebugScript, "Enable hotspot index %d", args[i + count1 + 2]); - _vm->setResourceEnabled(args[i + count1 + 2], true); + _vm->getCard()->setResourceEnabled(args[i + count1 + 2], true); } } } |