diff options
author | Bastien Bouclet | 2016-11-05 12:39:51 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-03 08:50:10 +0200 |
commit | efcf38f95f14272efd8ace91747a45bd53c74b57 (patch) | |
tree | 24dd9fd1c89ac06b84addd07da5efbee88f697e1 | |
parent | c04edb8f54f6e44079b389263428719c0b3c562c (diff) | |
download | scummvm-rg350-efcf38f95f14272efd8ace91747a45bd53c74b57.tar.gz scummvm-rg350-efcf38f95f14272efd8ace91747a45bd53c74b57.tar.bz2 scummvm-rg350-efcf38f95f14272efd8ace91747a45bd53c74b57.zip |
MOHAWK: Factor out stack name-id mapping
-rw-r--r-- | engines/mohawk/console.cpp | 29 | ||||
-rw-r--r-- | engines/mohawk/riven.cpp | 23 | ||||
-rw-r--r-- | engines/mohawk/riven.h | 1 | ||||
-rw-r--r-- | engines/mohawk/riven_scripts.cpp | 12 | ||||
-rw-r--r-- | engines/mohawk/riven_stack.cpp | 33 | ||||
-rw-r--r-- | engines/mohawk/riven_stack.h | 8 |
6 files changed, 53 insertions, 53 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp index 64d3a00ef8..37c5661078 100644 --- a/engines/mohawk/console.cpp +++ b/engines/mohawk/console.cpp @@ -474,7 +474,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->getStack()->getId()).c_str()); + debugPrintf("Current Stack: %s\n", RivenStacks::getName(_vm->getStack()->getId())); return true; } @@ -485,28 +485,20 @@ bool RivenConsole::Cmd_ChangeStack(int argc, const char **argv) { debugPrintf("Stacks:\n=======\n"); for (uint i = kStackFirst; i <= kStackLast; i++) - debugPrintf(" %s\n", _vm->getStackName(i).c_str()); + debugPrintf(" %s\n", RivenStacks::getName(i)); debugPrintf("\n"); return true; } - uint stack = kStackUnknown; - - for (uint i = kStackFirst; i <= kStackLast; i++) { - if (!scumm_stricmp(argv[1], _vm->getStackName(i).c_str())) { - stack = i; - break; - } - } - - if (stack == kStackUnknown) { + uint stackId = RivenStacks::getId(argv[1]); + if (stackId == kStackUnknown) { debugPrintf("\'%s\' is not a stack name!\n", argv[1]); return true; } - _vm->changeToStack(stack); + _vm->changeToStack(stackId); _vm->changeToCard((uint16)atoi(argv[2])); return false; @@ -577,15 +569,8 @@ bool RivenConsole::Cmd_DumpScript(int argc, const char **argv) { } uint16 oldStack = _vm->getStack()->getId(); - uint newStack = kStackUnknown; - - for (uint i = kStackFirst; i <= kStackLast; i++) { - if (!scumm_stricmp(argv[1], _vm->getStackName(i).c_str())) { - newStack = i; - break; - } - } + uint newStack = RivenStacks::getId(argv[1]); if (newStack == kStackUnknown) { debugPrintf("\'%s\' is not a stack name!\n", argv[1]); return true; @@ -659,7 +644,7 @@ bool RivenConsole::Cmd_ListZipCards(int argc, const char **argv) { bool RivenConsole::Cmd_GetRMAP(int argc, const char **argv) { uint32 rmapCode = _vm->getStack()->getCurrentCardGlobalId(); - debugPrintf("RMAP for %s %d = %08x\n", _vm->getStackName(_vm->getStack()->getId()).c_str(), _vm->getCard()->getId(), rmapCode); + debugPrintf("RMAP for %s %d = %08x\n", RivenStacks::getName(_vm->getStack()->getId()), _vm->getCard()->getId(), rmapCode); return true; } diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 7739dd5951..1b69e35d78 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -324,7 +324,7 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { _mhk.clear(); // Get the prefix character for the destination stack - char prefix = getStackName(n)[0]; + char prefix = RivenStacks::getName(n)[0]; // Load any file that fits the patterns for (int i = 0; i < ARRAYSIZE(endings); i++) { @@ -339,7 +339,7 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { // Make sure we have loaded files if (_mhk.empty()) - error("Could not load stack %s", getStackName(n).c_str()); + error("Could not load stack %s", RivenStacks::getName(n)); // Stop any currently playing sounds _sound->stopAllSLST(); @@ -554,25 +554,6 @@ Common::Error MohawkEngine_Riven::saveGameState(int slot, const Common::String & return _saveLoad->saveGame(slot, desc); } -Common::String MohawkEngine_Riven::getStackName(uint16 stack) const { - static const char *rivenStackNames[] = { - "<unknown>", - "ospit", - "pspit", - "rspit", - "tspit", - "bspit", - "gspit", - "jspit", - "aspit" - }; - - // Sanity check. - assert(stack < ARRAYSIZE(rivenStackNames)); - - return rivenStackNames[stack]; -} - void MohawkEngine_Riven::installTimer(TimerProc proc, uint32 time) { removeTimer(); _timerProc = proc; diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index b2e9188bf9..131d28548c 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -143,7 +143,6 @@ public: void changeToCard(uint16 dest); void changeToStack(uint16); void refreshCard(); - Common::String getStackName(uint16 stack) const; RivenCard *getCard() const { return _card; } RivenStack *getStack() const { return _stack; } diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index 6c744fca41..1445731199 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -766,20 +766,16 @@ RivenStackChangeCommand *RivenStackChangeCommand::createFromStream(MohawkEngine_ } void RivenStackChangeCommand::execute() { - int16 stackID = -1; + uint16 stackID; if (_byStackId) { stackID = _stackId; } else { Common::String stackName = _vm->getStack()->getName(kStackNames, _stackId); - for (byte i = kStackFirst; i < kStackLast; i++) - if (_vm->getStackName(i).equalsIgnoreCase(stackName)) { - stackID = i; - break; - } - - if (stackID == -1) + stackID = RivenStacks::getId(stackName.c_str()); + if (stackID == kStackUnknown) { error ("'%s' is not a stack name!", stackName.c_str()); + } } _vm->changeToStack(stackID); diff --git a/engines/mohawk/riven_stack.cpp b/engines/mohawk/riven_stack.cpp index 225e699591..ab79b788f4 100644 --- a/engines/mohawk/riven_stack.cpp +++ b/engines/mohawk/riven_stack.cpp @@ -136,7 +136,7 @@ uint32 RivenStack::getCardGlobalId(uint16 cardId) const { void RivenStack::dump() const { debug("= Stack ="); debug("id: %d", _id); - debug("name: %s", _vm->getStackName(_id).c_str()); + debug("name: %s", RivenStacks::getName(_id)); debugN("\n"); for (uint i = 0; i < _cardIdMap.size(); i++) { @@ -291,4 +291,35 @@ int16 RivenNameList::getNameId(const Common::String &name) const { return -1; } +namespace RivenStacks { +static const char *names[] = { + "<unknown>", + "ospit", + "pspit", + "rspit", + "tspit", + "bspit", + "gspit", + "jspit", + "aspit" +}; + +const char *getName(uint16 stackId) { + // Sanity check. + assert(stackId < ARRAYSIZE(names)); + + return names[stackId]; +} + +uint16 getId(const char *stackName) { + for (byte i = 0; i < ARRAYSIZE(names); i++) { + if (scumm_stricmp(stackName, names[i]) == 0) { + return i; + } + } + + return kStackUnknown; +} +} // End of namespace RivenStacks + } // End of namespace Mohawk diff --git a/engines/mohawk/riven_stack.h b/engines/mohawk/riven_stack.h index 0911fbbd86..d8098f7ab0 100644 --- a/engines/mohawk/riven_stack.h +++ b/engines/mohawk/riven_stack.h @@ -151,6 +151,14 @@ private: CommandsMap _commands; }; +namespace RivenStacks { + /** Get a stack name from an id */ + const char *getName(uint16 stackId); + + /** Get a stack id from a name */ + uint16 getId(const char *stackName); +} + } // End of namespace Mohawk #endif |