diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp index a595c2c0e48..ee7ff42fe46 100644 --- a/engines/stark/console.cpp +++ b/engines/stark/console.cpp @@ -29,6 +29,8 @@ #include "engines/stark/resources/knowledge.h" #include "engines/stark/resources/root.h" #include "engines/stark/resources/script.h" +#include "engines/stark/resources/knowledgeset.h" +#include "engines/stark/resources/item.h" #include "engines/stark/services/archiveloader.h" #include "engines/stark/services/dialogplayer.h" #include "engines/stark/services/global.h" @@ -468,17 +470,29 @@ bool Console::Cmd_DumpLocation(int argc, const char **argv) { } bool Console::Cmd_ListInventory(int argc, const char **argv) { - if (StarkGlobal->getInventory()) { - StarkGlobal->printInventory(argc != 2); - } else { + Resources::KnowledgeSet *inventory = StarkGlobal->getInventory(); + + if (!inventory) { debugPrintf("The inventory has not been loaded\n"); + return true; + } + + bool printAll = argc != 2; + Common::Array inventoryItems = inventory->listChildren(Resources::Item::kItemInventory); + Common::Array::iterator it = inventoryItems.begin(); + for (int i = 0; it != inventoryItems.end(); ++it, i++) { + if (printAll || (*it)->isEnabled()) { + debugPrintf("Item %d: %s\n", i, (*it)->getName().c_str()); + } } return true; } bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) { - if (!StarkGlobal->getInventory()) { + Resources::KnowledgeSet *inventory = StarkGlobal->getInventory(); + + if (!inventory) { debugPrintf("The inventory has not been loaded\n"); return true; } @@ -490,7 +504,13 @@ bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) { return true; } - StarkGlobal->enableInventoryItem(atoi(argv[1])); + uint num = atoi(argv[1]); + Common::Array inventoryItems = inventory->listChildren(Resources::Item::kItemInventory); + if (num < inventoryItems.size()) { + inventoryItems[num]->setEnabled(true); + } else { + debugPrintf("Invalid index %d, only %d indices available\n", num, inventoryItems.size()); + } return true; } diff --git a/engines/stark/services/global.cpp b/engines/stark/services/global.cpp index c39bcd728f6..27c85cced49 100644 --- a/engines/stark/services/global.cpp +++ b/engines/stark/services/global.cpp @@ -54,27 +54,6 @@ void Global::setCurrentChapter(int32 value) { chapter->setIntegerValue(value); } -void Global::printInventory(bool printAll) { - // Assume that this function is only called by the debug console - Common::Array inventoryItems = _inventory->listChildren(Resources::Item::kItemInventory); - Common::Array::iterator it = inventoryItems.begin(); - for (int i = 0; it != inventoryItems.end(); ++it, i++) { - if (printAll || (*it)->isEnabled()) { - g_engine->getDebugger()->debugPrintf("Item %d: %s\n", i, (*it)->getName().c_str()); - } - } -} - -void Global::enableInventoryItem(int32 num) { - Common::Array inventoryItems = _inventory->listChildren(Resources::Item::kItemInventory); - if (num >= 0 && num <= inventoryItems.size()) { - inventoryItems[num]->setEnabled(true); - } else { - // Assume that only being called by the debug console will cause the checking failed - g_engine->getDebugger()->debugPrintf("Invalid index %d, only %d indices available\n", num, inventoryItems.size()); - } -} - Common::String Global::getCharacterName(int32 id) { Resources::KnowledgeSet *characters = _level->findChildWithSubtype(Resources::KnowledgeSet::kPersons); Resources::Knowledge *character = characters->findChildWithIndex(id); diff --git a/engines/stark/services/global.h b/engines/stark/services/global.h index d9222b8aa83..ac8537f03a3 100644 --- a/engines/stark/services/global.h +++ b/engines/stark/services/global.h @@ -100,8 +100,6 @@ public: int32 getCurrentChapter(); /** Temporary HACK to allow us to query the inventory */ - void printInventory(bool printAll); - void enableInventoryItem(int32 num); bool hasInventoryItem(const Common::String &itemName) const; /** Change the current chapter */ diff --git a/engines/stark/stark.h b/engines/stark/stark.h index 20317679f35..0113b8a1df9 100644 --- a/engines/stark/stark.h +++ b/engines/stark/stark.h @@ -61,12 +61,10 @@ public: /** Build a save file name for the specified target and slot */ static Common::String formatSaveName(const char *target, int slot); - // Engine API - GUI::Debugger *getDebugger() override { return (GUI::Debugger *)_console; } - protected: // Engine APIs Common::Error run() override; + GUI::Debugger *getDebugger() override { return (GUI::Debugger *)_console; } bool hasFeature(EngineFeature f) const override; bool canLoadGameStateCurrently() override; bool canSaveGameStateCurrently() override;