aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2016-08-07 09:22:40 +0200
committerEugene Sandulenko2017-07-03 08:50:10 +0200
commit3c8decec0a416d874ae6db93c7e4977ec36432fb (patch)
treef876bc49f1832aa5bc780698dea724f10f8a0f99
parentf752066a8e4ab50a436c053bf2690a81492c4b15 (diff)
downloadscummvm-rg350-3c8decec0a416d874ae6db93c7e4977ec36432fb.tar.gz
scummvm-rg350-3c8decec0a416d874ae6db93c7e4977ec36432fb.tar.bz2
scummvm-rg350-3c8decec0a416d874ae6db93c7e4977ec36432fb.zip
MOHAWK: Move the resource names to RivenStack
-rw-r--r--engines/mohawk/console.cpp1
-rw-r--r--engines/mohawk/riven.cpp50
-rw-r--r--engines/mohawk/riven.h20
-rw-r--r--engines/mohawk/riven_card.cpp5
-rw-r--r--engines/mohawk/riven_external.cpp3
-rw-r--r--engines/mohawk/riven_graphics.cpp1
-rw-r--r--engines/mohawk/riven_saveload.cpp1
-rw-r--r--engines/mohawk/riven_scripts.cpp11
-rw-r--r--engines/mohawk/riven_stack.cpp44
-rw-r--r--engines/mohawk/riven_stack.h69
-rw-r--r--engines/mohawk/riven_vars.cpp3
11 files changed, 113 insertions, 95 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp
index 975c4c28df..fbf4c23474 100644
--- a/engines/mohawk/console.cpp
+++ b/engines/mohawk/console.cpp
@@ -44,6 +44,7 @@
#include "mohawk/riven_card.h"
#include "mohawk/riven_external.h"
#include "mohawk/riven_sound.h"
+#include "mohawk/riven_stack.h"
#endif
namespace Mohawk {
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index f42c29d234..70f4ab5eb2 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -36,6 +36,7 @@
#include "mohawk/riven_graphics.h"
#include "mohawk/riven_saveload.h"
#include "mohawk/riven_sound.h"
+#include "mohawk/riven_stack.h"
#include "mohawk/dialogs.h"
#include "mohawk/video.h"
#include "mohawk/console.h"
@@ -305,9 +306,6 @@ void MohawkEngine_Riven::changeToStack(uint16 n) {
if (_stack && _stack->getId() == n && !_mhk.empty())
return;
- delete _stack;
- _stack = new RivenStack(this, n);
-
// Stop any videos playing
_video->stopVideos();
_video->clearMLST();
@@ -338,15 +336,11 @@ void MohawkEngine_Riven::changeToStack(uint16 n) {
if (_mhk.empty())
error("Could not load stack %s", getStackName(n).c_str());
- // Load stack specific names
- _varNames = RivenNameList(this, kVariableNames);
- _externalCommandNames = RivenNameList(this, kExternalCommandNames);
- _stackNames = RivenNameList(this, kStackNames);
- _cardNames = RivenNameList(this, kCardNames);
- _hotspotNames = RivenNameList(this, kHotspotNames);
-
// Stop any currently playing sounds
_sound->stopAllSLST();
+
+ delete _stack;
+ _stack = new RivenStack(this, n);
}
// Riven uses some hacks to change stacks for linking books
@@ -828,7 +822,7 @@ void MohawkEngine_Riven::checkSunnerAlertClick() {
}
void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
- Common::String cardName = getName(kCardNames, cardNameId);
+ Common::String cardName = getCurStack()->getName(kCardNames, cardNameId);
if (cardName.empty())
return;
ZipMode zip;
@@ -851,40 +845,6 @@ bool MohawkEngine_Riven::isZipVisitedCard(const Common::String &hotspotName) con
return foundMatch;
}
-Common::String MohawkEngine_Riven::getName(uint16 nameResource, uint16 nameID) {
- switch (nameResource) {
- case kVariableNames:
- return _varNames.getName(nameID);
- case kExternalCommandNames:
- return _externalCommandNames.getName(nameID);
- case kStackNames:
- return _stackNames.getName(nameID);
- case kCardNames:
- return _cardNames.getName(nameID);
- case kHotspotNames:
- return _hotspotNames.getName(nameID);
- default:
- error("Unknown name resource %d", nameResource);
- }
-}
-
-int16 MohawkEngine_Riven::getIdFromName(uint16 nameResource, const Common::String &name) {
- switch (nameResource) {
- case kVariableNames:
- return _varNames.getNameId(name);
- case kExternalCommandNames:
- return _externalCommandNames.getNameId(name);
- case kStackNames:
- return _stackNames.getNameId(name);
- case kCardNames:
- return _cardNames.getNameId(name);
- case kHotspotNames:
- return _hotspotNames.getNameId(name);
- default:
- error("Unknown name resource %d", nameResource);
- }
-}
-
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 b8203a57ef..3fd1905fd3 100644
--- a/engines/mohawk/riven.h
+++ b/engines/mohawk/riven.h
@@ -25,7 +25,6 @@
#include "mohawk/installer_archive.h"
#include "mohawk/mohawk.h"
-#include "mohawk/riven_stack.h"
#include "mohawk/riven_scripts.h"
#include "common/hashmap.h"
@@ -42,6 +41,7 @@ class RivenExternal;
class RivenConsole;
class RivenSaveLoad;
class RivenOptionsDialog;
+class RivenStack;
class RivenCard;
class RivenHotspot;
class RivenSoundManager;
@@ -62,15 +62,6 @@ enum {
kStackLast = kStackAspit
};
-// NAME Resource ID's
-enum {
- kCardNames = 1,
- kHotspotNames = 2,
- kExternalCommandNames = 3,
- kVariableNames = 4,
- kStackNames = 5
-};
-
enum RivenTransitionSpeed {
kRivenTransitionSpeedNone = 5000,
kRivenTransitionSpeedFastest = 5001,
@@ -134,13 +125,6 @@ private:
RivenStack *_stack;
void handleEvents();
- // Stack resource names
- RivenNameList _varNames;
- RivenNameList _externalCommandNames;
- RivenNameList _hotspotNames;
- RivenNameList _cardNames;
- RivenNameList _stackNames;
-
// Hotspot related functions and variables
void checkInventoryClick();
bool _showHotspots;
@@ -161,8 +145,6 @@ public:
void changeToCard(uint16 dest);
void changeToStack(uint16);
void refreshCard();
- Common::String getName(uint16 nameResource, uint16 nameID);
- int16 getIdFromName(uint16 nameResource, const Common::String &name);
Common::String getStackName(uint16 stack) const;
RivenCard *getCurCard() const { return _card; }
RivenStack *getCurStack() const { return _stack; }
diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp
index 402c10b7af..a5c64f262a 100644
--- a/engines/mohawk/riven_card.cpp
+++ b/engines/mohawk/riven_card.cpp
@@ -24,6 +24,7 @@
#include "mohawk/cursors.h"
#include "mohawk/riven_graphics.h"
+#include "mohawk/riven_stack.h"
#include "mohawk/resource.h"
#include "mohawk/riven.h"
@@ -261,7 +262,7 @@ Common::Array<RivenHotspot *> RivenCard::getHotspots() const {
}
RivenHotspot *RivenCard::getHotspotByName(const Common::String &name) const {
- int16 nameId = _vm->getIdFromName(kHotspotNames, name);
+ int16 nameId = _vm->getCurStack()->getIdFromName(kHotspotNames, name);
for (uint i = 0; i < _hotspots.size(); i++) {
if (_hotspots[i]->getNameId() == nameId) {
@@ -509,7 +510,7 @@ Common::String RivenHotspot::getName() const {
if (_nameResource < 0)
return Common::String();
- return _vm->getName(kHotspotNames, _nameResource);
+ return _vm->getCurStack()->getName(kHotspotNames, _nameResource);
}
uint16 RivenHotspot::getIndex() const {
diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp
index f021ca6ac8..11f0b9623c 100644
--- a/engines/mohawk/riven_external.cpp
+++ b/engines/mohawk/riven_external.cpp
@@ -26,6 +26,7 @@
#include "mohawk/riven_external.h"
#include "mohawk/riven_graphics.h"
#include "mohawk/riven_sound.h"
+#include "mohawk/riven_stack.h"
#include "mohawk/video.h"
#include "gui/message.h"
@@ -198,7 +199,7 @@ void RivenExternal::setupCommands() {
}
void RivenExternal::runCommand(uint16 argc, uint16 *argv) {
- Common::String externalCommandName = _vm->getName(kExternalCommandNames, argv[0]);
+ Common::String externalCommandName = _vm->getCurStack()->getName(kExternalCommandNames, argv[0]);
for (uint16 i = 0; i < _externalCommands.size(); i++)
if (externalCommandName == _externalCommands[i]->desc) {
diff --git a/engines/mohawk/riven_graphics.cpp b/engines/mohawk/riven_graphics.cpp
index 032b0595c4..9346ae92cc 100644
--- a/engines/mohawk/riven_graphics.cpp
+++ b/engines/mohawk/riven_graphics.cpp
@@ -25,6 +25,7 @@
#include "mohawk/riven_card.h"
#include "mohawk/riven_graphics.h"
#include "mohawk/riven_sound.h"
+#include "mohawk/riven_stack.h"
#include "common/system.h"
#include "engines/util.h"
diff --git a/engines/mohawk/riven_saveload.cpp b/engines/mohawk/riven_saveload.cpp
index 90ca25d46e..6be876de2a 100644
--- a/engines/mohawk/riven_saveload.cpp
+++ b/engines/mohawk/riven_saveload.cpp
@@ -24,6 +24,7 @@
#include "mohawk/riven.h"
#include "mohawk/riven_card.h"
#include "mohawk/riven_saveload.h"
+#include "mohawk/riven_stack.h"
#include "common/system.h"
#include "graphics/thumbnail.h"
diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp
index f6faff0a0f..cfc97bfe59 100644
--- a/engines/mohawk/riven_scripts.cpp
+++ b/engines/mohawk/riven_scripts.cpp
@@ -27,6 +27,7 @@
#include "mohawk/riven_graphics.h"
#include "mohawk/riven_scripts.h"
#include "mohawk/riven_sound.h"
+#include "mohawk/riven_stack.h"
#include "mohawk/video.h"
#include "common/memstream.h"
@@ -462,7 +463,7 @@ void RivenSimpleCommand::incrementVariable(uint16 op, uint16 argc, uint16 *argv)
// Command 27: go to stack (stack name, code high, code low)
void RivenSimpleCommand::changeStack(uint16 op, uint16 argc, uint16 *argv) {
- Common::String stackName = _vm->getName(kStackNames, argv[0]);
+ Common::String stackName = _vm->getCurStack()->getName(kStackNames, argv[0]);
int8 index = -1;
for (byte i = 0; i < 8; i++)
@@ -629,10 +630,10 @@ void RivenSimpleCommand::dump(byte tabs) {
printTabs(tabs);
if (_type == 7) { // Use the variable name
- Common::String varName = _vm->getName(kVariableNames, _arguments[0]);
+ Common::String varName = _vm->getCurStack()->getName(kVariableNames, _arguments[0]);
debugN("%s = %d;\n", varName.c_str(), _arguments[1]);
} else if (_type == 17) { // Use the external command name
- Common::String externalCommandName = _vm->getName(kVariableNames, _arguments[0]);
+ Common::String externalCommandName = _vm->getCurStack()->getName(kVariableNames, _arguments[0]);
debugN("%s(", externalCommandName.c_str());
uint16 varCount = _arguments[1];
for (uint16 j = 0; j < varCount; j++) {
@@ -642,7 +643,7 @@ void RivenSimpleCommand::dump(byte tabs) {
}
debugN(");\n");
} else if (_type == 24) { // Use the variable name
- Common::String varName = _vm->getName(kVariableNames, _arguments[0]);
+ Common::String varName = _vm->getCurStack()->getName(kVariableNames, _arguments[0]);
debugN("%s += %d;\n", varName.c_str(), _arguments[1]);
} else {
debugN("%s(", _opcodes[_type].desc);
@@ -704,7 +705,7 @@ RivenSwitchCommand *RivenSwitchCommand::createFromStream(MohawkEngine_Riven *vm,
}
void RivenSwitchCommand::dump(byte tabs) {
- Common::String varName = _vm->getName(kVariableNames, _variableId);
+ Common::String varName = _vm->getCurStack()->getName(kVariableNames, _variableId);
printTabs(tabs); debugN("switch (%s) {\n", varName.c_str());
for (uint16 j = 0; j < _branches.size(); j++) {
printTabs(tabs + 1);
diff --git a/engines/mohawk/riven_stack.cpp b/engines/mohawk/riven_stack.cpp
index 77f7a99ed9..b66ca834f4 100644
--- a/engines/mohawk/riven_stack.cpp
+++ b/engines/mohawk/riven_stack.cpp
@@ -30,7 +30,7 @@ namespace Mohawk {
RivenStack::RivenStack(MohawkEngine_Riven *vm, uint16 id) :
_vm(vm),
_id(id) {
-
+ loadResourceNames();
}
RivenStack::~RivenStack() {
@@ -41,6 +41,48 @@ uint16 RivenStack::getId() const {
return _id;
}
+void RivenStack::loadResourceNames() {
+ _varNames = RivenNameList(_vm, kVariableNames);
+ _externalCommandNames = RivenNameList(_vm, kExternalCommandNames);
+ _stackNames = RivenNameList(_vm, kStackNames);
+ _cardNames = RivenNameList(_vm, kCardNames);
+ _hotspotNames = RivenNameList(_vm, kHotspotNames);
+}
+
+Common::String RivenStack::getName(RivenNameResource nameResource, uint16 nameId) const {
+ switch (nameResource) {
+ case kVariableNames:
+ return _varNames.getName(nameId);
+ case kExternalCommandNames:
+ return _externalCommandNames.getName(nameId);
+ case kStackNames:
+ return _stackNames.getName(nameId);
+ case kCardNames:
+ return _cardNames.getName(nameId);
+ case kHotspotNames:
+ return _hotspotNames.getName(nameId);
+ default:
+ error("Unknown name resource %d", nameResource);
+ }
+}
+
+int16 RivenStack::getIdFromName(RivenNameResource nameResource, const Common::String &name) const {
+ switch (nameResource) {
+ case kVariableNames:
+ return _varNames.getNameId(name);
+ case kExternalCommandNames:
+ return _externalCommandNames.getNameId(name);
+ case kStackNames:
+ return _stackNames.getNameId(name);
+ case kCardNames:
+ return _cardNames.getNameId(name);
+ case kHotspotNames:
+ return _hotspotNames.getNameId(name);
+ default:
+ error("Unknown name resource %d", nameResource);
+ }
+}
+
RivenNameList::RivenNameList() {
}
diff --git a/engines/mohawk/riven_stack.h b/engines/mohawk/riven_stack.h
index 331a08237e..36d6fb0b06 100644
--- a/engines/mohawk/riven_stack.h
+++ b/engines/mohawk/riven_stack.h
@@ -28,27 +28,14 @@
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 Resource ID's
+enum RivenNameResource {
+ kCardNames = 1,
+ kHotspotNames = 2,
+ kExternalCommandNames = 3,
+ kVariableNames = 4,
+ kStackNames = 5
};
/**
@@ -71,10 +58,50 @@ public:
int16 getNameId(const Common::String &name) const;
private:
+ void loadResource(MohawkEngine_Riven *vm, uint16 id);
+
Common::StringArray _names;
Common::Array<uint16> _index;
+};
- void loadResource(MohawkEngine_Riven *vm, uint16 id);
+/**
+ * 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 and data 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;
+
+ /** Get the name of a resource using its id */
+ Common::String getName(RivenNameResource nameResource, uint16 nameId) const;
+
+ /**
+ * Get the id of a resource using its name
+ *
+ * The search is case insensitive.
+ */
+ int16 getIdFromName(RivenNameResource nameResource, const Common::String &name) const;
+private:
+ void loadResourceNames();
+
+ MohawkEngine_Riven *_vm;
+
+ uint16 _id;
+
+ // Stack resource names
+ RivenNameList _varNames;
+ RivenNameList _externalCommandNames;
+ RivenNameList _hotspotNames;
+ RivenNameList _cardNames;
+ RivenNameList _stackNames;
};
} // End of namespace Mohawk
diff --git a/engines/mohawk/riven_vars.cpp b/engines/mohawk/riven_vars.cpp
index c45b464b4d..2a19282c2b 100644
--- a/engines/mohawk/riven_vars.cpp
+++ b/engines/mohawk/riven_vars.cpp
@@ -23,6 +23,7 @@
#include "common/str.h"
#include "mohawk/riven.h"
+#include "mohawk/riven_stack.h"
namespace Mohawk {
@@ -268,7 +269,7 @@ static const char *variableNames[] = {
};
uint32 &MohawkEngine_Riven::getStackVar(uint32 index) {
- Common::String name = getName(kVariableNames, index);
+ Common::String name = getCurStack()->getName(kVariableNames, index);
if (!_vars.contains(name))
error("Could not find variable '%s' (stack variable %d)", name.c_str(), index);