diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/module.mk | 1 | ||||
-rw-r--r-- | engines/mohawk/riven.cpp | 66 | ||||
-rw-r--r-- | engines/mohawk/riven.h | 15 | ||||
-rw-r--r-- | engines/mohawk/riven_card.cpp | 69 | ||||
-rw-r--r-- | engines/mohawk/riven_card.h | 54 | ||||
-rw-r--r-- | engines/mohawk/riven_scripts.h | 4 |
6 files changed, 158 insertions, 51 deletions
diff --git a/engines/mohawk/module.mk b/engines/mohawk/module.mk index 3fc118d2b6..8a186b1526 100644 --- a/engines/mohawk/module.mk +++ b/engines/mohawk/module.mk @@ -53,6 +53,7 @@ endif ifdef ENABLE_RIVEN MODULE_OBJS += \ riven.o \ + riven_card.o \ riven_external.o \ riven_graphics.o \ riven_saveload.o \ diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 03a489884b..9403627212 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -31,6 +31,7 @@ #include "mohawk/installer_archive.h" #include "mohawk/resource.h" #include "mohawk/riven.h" +#include "mohawk/riven_card.h" #include "mohawk/riven_external.h" #include "mohawk/riven_graphics.h" #include "mohawk/riven_saveload.h" @@ -51,7 +52,6 @@ Common::Rect *g_demoExitRect; MohawkEngine_Riven::MohawkEngine_Riven(OSystem *syst, const MohawkGameDescription *gamedesc) : MohawkEngine(syst, gamedesc) { _showHotspots = false; - _cardData.hasData = false; _gameOver = false; _activatedSLST = false; _ignoreNextMouseUp = false; @@ -67,6 +67,7 @@ MohawkEngine_Riven::MohawkEngine_Riven(OSystem *syst, const MohawkGameDescriptio _saveLoad = nullptr; _optionsDialog = nullptr; _curCard = 0; + _card = nullptr; _hotspotCount = 0; _curHotspot = -1; removeTimer(); @@ -94,6 +95,7 @@ MohawkEngine_Riven::MohawkEngine_Riven(OSystem *syst, const MohawkGameDescriptio } MohawkEngine_Riven::~MohawkEngine_Riven() { + delete _card; delete _sound; delete _gfx; delete _console; @@ -392,10 +394,12 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) { } } - if (_cardData.hasData) - runCardScript(kCardLeaveScript); + if (_card) + _card->runScript(kCardLeaveScript); + + delete _card; + _card = new RivenCard(this, dest); - loadCard(_curCard); refreshCard(); // Handles hotspots and scripts } @@ -412,9 +416,10 @@ void MohawkEngine_Riven::refreshCard() { _gfx->drawPLST(1); _activatedSLST = false; - runCardScript(kCardLoadScript); + _card->runScript(kCardLoadScript); _gfx->updateScreen(); - runCardScript(kCardOpenScript); + _card->runScript(kCardOpenScript); + _card->open(); // Activate the first sound list if none have been activated if (!_activatedSLST) @@ -431,30 +436,6 @@ void MohawkEngine_Riven::refreshCard() { installCardTimer(); } -void MohawkEngine_Riven::loadCard(uint16 id) { - // NOTE: The card scripts are cleared by the RivenScriptManager automatically. - - Common::SeekableReadStream* inStream = getResource(ID_CARD, id); - - _cardData.name = inStream->readSint16BE(); - _cardData.zipModePlace = inStream->readUint16BE(); - _cardData.scripts = _scriptMan->readScripts(inStream); - _cardData.hasData = true; - - delete inStream; - - if (_cardData.zipModePlace) { - Common::String cardName = getName(CardNames, _cardData.name); - if (cardName.empty()) - return; - ZipMode zip; - zip.name = cardName; - zip.id = id; - if (!(Common::find(_zipModeData.begin(), _zipModeData.end(), zip) != _zipModeData.end())) - _zipModeData.push_back(zip); - } -} - void MohawkEngine_Riven::loadHotspots(uint16 id) { // Clear old hotspots delete[] _hotspots; @@ -693,16 +674,6 @@ uint32 MohawkEngine_Riven::getCurCardRMAP() { return rmapCode; } -void MohawkEngine_Riven::runCardScript(uint16 scriptType) { - assert(_cardData.hasData); - for (uint16 i = 0; i < _cardData.scripts.size(); i++) - if (_cardData.scripts[i].type == scriptType) { - RivenScriptPtr script = _cardData.scripts[i].script; - _scriptMan->runScript(script, false); - break; - } -} - void MohawkEngine_Riven::runHotspotScript(uint16 hotspot, uint16 scriptType) { assert(hotspot < _hotspotCount); for (uint16 i = 0; i < _hotspots[hotspot].scripts.size(); i++) @@ -1022,6 +993,21 @@ void MohawkEngine_Riven::checkSunnerAlertClick() { sunners = 1; } +void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) { + Common::String cardName = getName(CardNames, cardNameId); + if (cardName.empty()) + return; + ZipMode zip; + zip.name = cardName; + zip.id = cardId; + if (!(Common::find(_zipModeData.begin(), _zipModeData.end(), zip) != _zipModeData.end())) + _zipModeData.push_back(zip); +} + +void MohawkEngine_Riven::runUpdateScreenScript() { + _card->runScript(kCardUpdateScript); +} + bool ZipMode::operator== (const ZipMode &z) const { return z.name == name && z.id == id; } diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index ce819ac970..11a6d071ee 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -41,6 +41,7 @@ class RivenExternal; class RivenConsole; class RivenSaveLoad; class RivenOptionsDialog; +class RivenCard; class RivenSoundManager; // Riven Stack Types @@ -99,13 +100,6 @@ struct RivenHotspot { bool enabled; }; -struct Card { - int16 name; - uint16 zipModePlace; - bool hasData; - RivenScriptList scripts; -}; - struct ZipMode { Common::String name; uint16 id; @@ -128,7 +122,7 @@ public: Common::RandomSource *_rnd; RivenScriptManager *_scriptMan; - Card _cardData; + RivenCard *_card; GUI::Debugger *getDebugger(); @@ -152,7 +146,6 @@ private: // Stack/Card-related functions and variables uint16 _curCard; uint16 _curStack; - void loadCard(uint16); void handleEvents(); // Hotspot related functions and variables @@ -182,8 +175,7 @@ public: void refreshCard(); Common::String getName(uint16 nameResource, uint16 nameID); Common::String getStackName(uint16 stack) const; - void runCardScript(uint16 scriptType); - void runUpdateScreenScript() { runCardScript(kCardUpdateScript); } + void runUpdateScreenScript(); uint16 getCurCard() const { return _curCard; } uint16 getCurStack() const { return _curStack; } uint16 matchRMAPToCard(uint32); @@ -198,6 +190,7 @@ public: int32 getCurHotspot() const { return _curHotspot; } Common::String getHotspotName(uint16 hotspot); void updateCurrentHotspot(); + void addZipVisitedCard(uint16 cardId, uint16 cardNameId); // Variables RivenVariableMap _vars; diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp new file mode 100644 index 0000000000..f45fde1d1e --- /dev/null +++ b/engines/mohawk/riven_card.cpp @@ -0,0 +1,69 @@ +/* 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/riven_card.h" + +#include "mohawk/resource.h" +#include "mohawk/riven.h" + +namespace Mohawk { + +RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) : + _vm(vm), + _id(id) { + loadCardResource(id); +} + +RivenCard::~RivenCard() { + +} + +void RivenCard::loadCardResource(uint16 id) { + Common::SeekableReadStream *inStream = _vm->getResource(ID_CARD, id); + + _name = inStream->readSint16BE(); + _zipModePlace = inStream->readUint16BE(); + _scripts = _vm->_scriptMan->readScripts(inStream); + + delete inStream; +} + +void RivenCard::open() { + initializeZipMode(); +} + +void RivenCard::initializeZipMode() { + if (_zipModePlace) { + _vm->addZipVisitedCard(_id, _name); + } +} + +void RivenCard::runScript(uint16 scriptType) { + for (uint16 i = 0; i < _scripts.size(); i++) + if (_scripts[i].type == scriptType) { + RivenScriptPtr script = _scripts[i].script; + _vm->_scriptMan->runScript(script, false); + break; + } +} + +} // End of namespace Mohawk diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h new file mode 100644 index 0000000000..94bbfe6968 --- /dev/null +++ b/engines/mohawk/riven_card.h @@ -0,0 +1,54 @@ +/* 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 RIVEN_CARD_H +#define RIVEN_CARD_H + +#include "mohawk/riven_scripts.h" + +#include "common/system.h" + +namespace Mohawk { + +class RivenCard { +public: + RivenCard(MohawkEngine_Riven *vm, uint16 id); + ~RivenCard(); + + void open(); + void initializeZipMode(); + void runScript(uint16 scriptType); + +private: + void loadCardResource(uint16 id); + + MohawkEngine_Riven *_vm; + + uint16 _id; + int16 _name; + uint16 _zipModePlace; + RivenScriptList _scripts; +}; + +} // End of namespace Mohawk + +#endif diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h index 394c046cae..f562619dbf 100644 --- a/engines/mohawk/riven_scripts.h +++ b/engines/mohawk/riven_scripts.h @@ -29,6 +29,10 @@ #define DECLARE_OPCODE(x) void x(uint16 op, uint16 argc, uint16 *argv) +namespace Common { +class ReadStream; +} + namespace Mohawk { // Script Types |