From f752066a8e4ab50a436c053bf2690a81492c4b15 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 7 Aug 2016 08:45:25 +0200 Subject: MOHAWK: Introduce a new RivenStack class --- engines/mohawk/console.cpp | 8 ++++---- engines/mohawk/riven.cpp | 28 +++++++++++++++------------- engines/mohawk/riven.h | 7 +++---- engines/mohawk/riven_external.cpp | 30 +++++++++++++++--------------- engines/mohawk/riven_graphics.cpp | 2 +- engines/mohawk/riven_saveload.cpp | 2 +- engines/mohawk/riven_scripts.cpp | 4 ++-- engines/mohawk/riven_stack.cpp | 14 ++++++++++++++ engines/mohawk/riven_stack.h | 22 ++++++++++++++++++++++ 9 files changed, 77 insertions(+), 40 deletions(-) (limited to 'engines') diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp index b95b999123..975c4c28df 100644 --- a/engines/mohawk/console.cpp +++ b/engines/mohawk/console.cpp @@ -471,7 +471,7 @@ bool RivenConsole::Cmd_StopSound(int argc, const char **argv) { } bool RivenConsole::Cmd_CurStack(int argc, const char **argv) { - debugPrintf("Current Stack: %s\n", _vm->getStackName(_vm->getCurStack()).c_str()); + debugPrintf("Current Stack: %s\n", _vm->getStackName(_vm->getCurStack()->getId()).c_str()); return true; } @@ -510,7 +510,7 @@ bool RivenConsole::Cmd_ChangeStack(int argc, const char **argv) { } bool RivenConsole::Cmd_Hotspots(int argc, const char **argv) { - Common::Array hotspots = _vm->_card->getHotspots(); + Common::Array hotspots = _vm->getCurCard()->getHotspots(); debugPrintf("Current card (%d) has %d hotspots:\n", _vm->getCurCard()->getId(), hotspots.size()); @@ -547,7 +547,7 @@ bool RivenConsole::Cmd_DumpScript(int argc, const char **argv) { return true; } - uint16 oldStack = _vm->getCurStack(); + uint16 oldStack = _vm->getCurStack()->getId(); uint newStack = kStackUnknown; for (uint i = kStackFirst; i <= kStackLast; i++) { @@ -630,7 +630,7 @@ bool RivenConsole::Cmd_ListZipCards(int argc, const char **argv) { bool RivenConsole::Cmd_GetRMAP(int argc, const char **argv) { uint32 rmapCode = _vm->getCurCardRMAP(); - debugPrintf("RMAP for %s %d = %08x\n", _vm->getStackName(_vm->getCurStack()).c_str(), _vm->getCurCard()->getId(), rmapCode); + debugPrintf("RMAP for %s %d = %08x\n", _vm->getStackName(_vm->getCurStack()->getId()).c_str(), _vm->getCurCard()->getId(), rmapCode); return true; } diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 2e035005a1..f42c29d234 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -57,7 +57,7 @@ MohawkEngine_Riven::MohawkEngine_Riven(OSystem *syst, const MohawkGameDescriptio _activatedPLST = false; _activatedSLST = false; _extrasFile = nullptr; - _curStack = kStackUnknown; + _stack = nullptr; _gfx = nullptr; _sound = nullptr; _externalScriptHandler = nullptr; @@ -93,6 +93,7 @@ MohawkEngine_Riven::MohawkEngine_Riven(OSystem *syst, const MohawkGameDescriptio MohawkEngine_Riven::~MohawkEngine_Riven() { delete _card; + delete _stack; delete _sound; delete _gfx; delete _console; @@ -260,7 +261,7 @@ void MohawkEngine_Riven::handleEvents() { case Common::KEYCODE_r: // Return to the main menu in the demo on ctrl+r if (event.kbd.flags & Common::KBD_CTRL && getFeatures() & GF_DEMO) { - if (_curStack != kStackAspit) + if (_stack->getId() != kStackAspit) changeToStack(kStackAspit); changeToCard(1); } @@ -268,7 +269,7 @@ void MohawkEngine_Riven::handleEvents() { case Common::KEYCODE_p: // Play the intro videos in the demo on ctrl+p if (event.kbd.flags & Common::KBD_CTRL && getFeatures() & GF_DEMO) { - if (_curStack != kStackAspit) + if (_stack->getId() != kStackAspit) changeToStack(kStackAspit); changeToCard(6); } @@ -301,10 +302,11 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { static const char *endings[] = { "_Data3.mhk", "_Data2.mhk", "_Data1.mhk", "_Data.mhk", "_Sounds.mhk" }; // Don't change stack to the current stack (if the files are loaded) - if (_curStack == n && !_mhk.empty()) + if (_stack && _stack->getId() == n && !_mhk.empty()) return; - _curStack = n; + delete _stack; + _stack = new RivenStack(this, n); // Stop any videos playing _video->stopVideos(); @@ -319,7 +321,7 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { _mhk.clear(); // Get the prefix character for the destination stack - char prefix = getStackName(_curStack)[0]; + char prefix = getStackName(n)[0]; // Load any file that fits the patterns for (int i = 0; i < ARRAYSIZE(endings); i++) { @@ -334,7 +336,7 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { // Make sure we have loaded files if (_mhk.empty()) - error("Could not load stack %s", getStackName(_curStack).c_str()); + error("Could not load stack %s", getStackName(n).c_str()); // Load stack specific names _varNames = RivenNameList(this, kVariableNames); @@ -381,7 +383,7 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) { if (!(getFeatures() & GF_DEMO)) { for (byte i = 0; i < 13; i++) - if (_curStack == rivenSpecialChange[i].startStack && dest == matchRMAPToCard(rivenSpecialChange[i].startCardRMAP)) { + if (_stack->getId() == rivenSpecialChange[i].startStack && dest == matchRMAPToCard(rivenSpecialChange[i].startCardRMAP)) { changeToStack(rivenSpecialChange[i].targetStack); dest = matchRMAPToCard(rivenSpecialChange[i].targetCardRMAP); } @@ -423,15 +425,15 @@ void MohawkEngine_Riven::checkInventoryClick() { // In the demo, check if we've clicked the exit button if (getFeatures() & GF_DEMO) { if (g_demoExitRect->contains(mousePos)) { - if (_curStack == kStackAspit && _card->getId() == 1) { + if (_stack->getId() == kStackAspit && _card->getId() == 1) { // From the main menu, go to the "quit" screen changeToCard(12); - } else if (_curStack == kStackAspit && _card->getId() == 12) { + } else if (_stack->getId() == kStackAspit && _card->getId() == 12) { // From the "quit" screen, just quit _gameOver = true; } else { // Otherwise, return to the main menu - if (_curStack != kStackAspit) + if (_stack->getId() != kStackAspit) changeToStack(kStackAspit); changeToCard(1); } @@ -440,11 +442,11 @@ void MohawkEngine_Riven::checkInventoryClick() { } // No inventory shown on aspit - if (_curStack == kStackAspit) + if (_stack->getId() == kStackAspit) return; // Set the return stack/card id's. - _vars["returnstackid"] = _curStack; + _vars["returnstackid"] = _stack->getId(); _vars["returncardid"] = _card->getId(); // See RivenGraphics::showInventory() for an explanation diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index 0e951b6076..b8203a57ef 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -110,8 +110,6 @@ public: Common::RandomSource *_rnd; RivenScriptManager *_scriptMan; - RivenCard *_card; - GUI::Debugger *getDebugger(); bool canLoadGameStateCurrently() { return !(getFeatures() & GF_DEMO); } @@ -132,7 +130,8 @@ private: InstallerArchive _installerArchive; // Stack/Card-related functions and variables - uint16 _curStack; + RivenCard *_card; + RivenStack *_stack; void handleEvents(); // Stack resource names @@ -166,7 +165,7 @@ public: int16 getIdFromName(uint16 nameResource, const Common::String &name); Common::String getStackName(uint16 stack) const; RivenCard *getCurCard() const { return _card; } - uint16 getCurStack() const { return _curStack; } + RivenStack *getCurStack() const { return _stack; } uint16 matchRMAPToCard(uint32); uint32 getCurCardRMAP(); diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp index 6740f13007..f021ca6ac8 100644 --- a/engines/mohawk/riven_external.cpp +++ b/engines/mohawk/riven_external.cpp @@ -418,7 +418,7 @@ void RivenExternal::drawDomeSliders(uint16 startHotspot) { // On pspit, the rect is different by two pixels // (alternatively, we could just use hotspot 3 here, but only on pspit is there a hotspot for this) - if (_vm->getCurStack() == kStackPspit) + if (_vm->getCurStack()->getId() == kStackPspit) dstAreaRect.translate(-2, 0); // Find out bitmap id @@ -462,9 +462,9 @@ void RivenExternal::xaatrusopenbook(uint16 argc, uint16 *argv) { uint32 &page = _vm->_vars["aatruspage"]; // Set hotspots depending on the page - RivenHotspot *openBook = _vm->_card->getHotspotByName("openBook"); - RivenHotspot *nextPage = _vm->_card->getHotspotByName("nextpage"); - RivenHotspot *prevPage = _vm->_card->getHotspotByName("prevpage"); + RivenHotspot *openBook = _vm->getCurCard()->getHotspotByName("openBook"); + RivenHotspot *nextPage = _vm->getCurCard()->getHotspotByName("nextpage"); + RivenHotspot *prevPage = _vm->getCurCard()->getHotspotByName("prevpage"); if (page == 1) { prevPage->enable(false); nextPage->enable(false); @@ -502,7 +502,7 @@ void RivenExternal::xaatrusbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xaatrusbooknextpage(uint16 argc, uint16 *argv) { @@ -522,7 +522,7 @@ void RivenExternal::xaatrusbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xacathopenbook(uint16 argc, uint16 *argv) { @@ -530,9 +530,9 @@ void RivenExternal::xacathopenbook(uint16 argc, uint16 *argv) { uint32 page = _vm->_vars["acathpage"]; // Set hotspots depending on the page - RivenHotspot *openBook = _vm->_card->getHotspotByName("openBook"); - RivenHotspot *nextPage = _vm->_card->getHotspotByName("nextpage"); - RivenHotspot *prevPage = _vm->_card->getHotspotByName("prevpage"); + RivenHotspot *openBook = _vm->getCurCard()->getHotspotByName("openBook"); + RivenHotspot *nextPage = _vm->getCurCard()->getHotspotByName("nextpage"); + RivenHotspot *prevPage = _vm->getCurCard()->getHotspotByName("prevpage"); if (page == 1) { prevPage->enable(false); nextPage->enable(false); @@ -591,7 +591,7 @@ void RivenExternal::xacathbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(3); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xacathbooknextpage(uint16 argc, uint16 *argv) { @@ -608,7 +608,7 @@ void RivenExternal::xacathbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(2); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xtrapbookback(uint16 argc, uint16 *argv) { @@ -768,7 +768,7 @@ void RivenExternal::xblabbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xblabbooknextpage(uint16 argc, uint16 *argv) { @@ -785,7 +785,7 @@ void RivenExternal::xblabbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xsoundplug(uint16 argc, uint16 *argv) { @@ -2228,7 +2228,7 @@ void RivenExternal::xogehnbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } void RivenExternal::xogehnbooknextpage(uint16 argc, uint16 *argv) { @@ -2245,7 +2245,7 @@ void RivenExternal::xogehnbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_card->drawPicture(page); + _vm->getCurCard()->drawPicture(page); } uint16 RivenExternal::getComboDigit(uint32 correctCombo, uint32 digit) { diff --git a/engines/mohawk/riven_graphics.cpp b/engines/mohawk/riven_graphics.cpp index e0cfa365c1..032b0595c4 100644 --- a/engines/mohawk/riven_graphics.cpp +++ b/engines/mohawk/riven_graphics.cpp @@ -263,7 +263,7 @@ void RivenGraphics::showInventory() { drawInventoryImage(101, g_demoExitRect); } else { // We don't want to show the inventory on setup screens or in other journals. - if (_vm->getCurStack() == kStackAspit) + if (_vm->getCurStack()->getId() == kStackAspit) return; // There are three books and three vars. We have three different diff --git a/engines/mohawk/riven_saveload.cpp b/engines/mohawk/riven_saveload.cpp index 766ad30c51..90ca25d46e 100644 --- a/engines/mohawk/riven_saveload.cpp +++ b/engines/mohawk/riven_saveload.cpp @@ -403,7 +403,7 @@ Common::Error RivenSaveLoad::saveGame(const int slot, const Common::String &desc Common::String filename = buildSaveFilename(slot); // Convert class variables to variable numbers - _vm->_vars["currentstackid"] = _vm->getCurStack(); + _vm->_vars["currentstackid"] = _vm->getCurStack()->getId(); _vm->_vars["currentcardid"] = _vm->getCurCard()->getId(); Common::OutSaveFile *saveFile = _saveFileMan->openForSaving(filename); diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index 18c666dbbb..f6faff0a0f 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -393,7 +393,7 @@ void RivenSimpleCommand::stopSound(uint16 op, uint16 argc, uint16 *argv) { // would cause all ambient sounds not to play. An alternative // fix would be to stop all scripts on a stack change, but this // does fine for now. - if (_vm->getCurStack() == kStackTspit && (_vm->getCurCardRMAP() == 0x6e9a || _vm->getCurCardRMAP() == 0xfeeb)) + if (_vm->getCurStack()->getId() == kStackTspit && (_vm->getCurCardRMAP() == 0x6e9a || _vm->getCurCardRMAP() == 0xfeeb)) return; // The argument is a bitflag for the setting. @@ -579,7 +579,7 @@ void RivenSimpleCommand::activatePLST(uint16 op, uint16 argc, uint16 *argv) { void RivenSimpleCommand::activateSLST(uint16 op, uint16 argc, uint16 *argv) { // WORKAROUND: Disable the SLST that is played during Riven's intro. // Riven X does this too (spoke this over with Jeff) - if (_vm->getCurStack() == kStackTspit && _vm->getCurCardRMAP() == 0x6e9a && argv[0] == 2) + if (_vm->getCurStack()->getId() == kStackTspit && _vm->getCurCardRMAP() == 0x6e9a && argv[0] == 2) return; _vm->_activatedSLST = true; diff --git a/engines/mohawk/riven_stack.cpp b/engines/mohawk/riven_stack.cpp index 3ff34e7478..77f7a99ed9 100644 --- a/engines/mohawk/riven_stack.cpp +++ b/engines/mohawk/riven_stack.cpp @@ -27,6 +27,20 @@ namespace Mohawk { +RivenStack::RivenStack(MohawkEngine_Riven *vm, uint16 id) : + _vm(vm), + _id(id) { + +} + +RivenStack::~RivenStack() { + +} + +uint16 RivenStack::getId() const { + return _id; +} + RivenNameList::RivenNameList() { } diff --git a/engines/mohawk/riven_stack.h b/engines/mohawk/riven_stack.h index ca513a15cc..331a08237e 100644 --- a/engines/mohawk/riven_stack.h +++ b/engines/mohawk/riven_stack.h @@ -28,6 +28,28 @@ namespace Mohawk { class MohawkEngine_Riven; +class RivenNameList; + +/** + * A game level + * + * The names Card and Stack are legacy from the HyperCard engine used in + * the original mac version of Myst. + * + * Stacks contain behaviors that are specific to a game level. + */ +class RivenStack { +public: + RivenStack(MohawkEngine_Riven *vm, uint16 id); + virtual ~RivenStack(); + + /** Get the id of the stack */ + uint16 getId() const; +private: + MohawkEngine_Riven *_vm; + + uint16 _id; +}; /** * Name lists provide bidirectional association between an object's name and its id -- cgit v1.2.3