diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp index 3aeae6ce84f..d8f8e61f03b 100644 --- a/engines/stark/console.cpp +++ b/engines/stark/console.cpp @@ -116,55 +116,32 @@ bool Console::Cmd_DumpArchive(int argc, const char **argv) { } bool Console::Cmd_DumpRoot(int argc, const char **argv) { - Resources::Root *root = StarkGlobal->getRoot(); - if (root) { - root->print(); - } else { - debugPrintf("The global root has not been loaded\n"); - } + StarkGlobal->getRoot()->print(); return true; } bool Console::Cmd_DumpGlobal(int argc, const char **argv) { - Resources::Level *level = StarkGlobal->getLevel(); - if (level) { - level->print(); - } else { - debugPrintf("The global level has not been loaded\n"); - } + StarkGlobal->getLevel()->print(); return true; } bool Console::Cmd_DumpStatic(int argc, const char **argv) { - // Static resources are initialized in the beginning of the running StarkStaticProvider->getLevel()->print(); return true; } bool Console::Cmd_DumpLevel(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - if (current) { - current->getLevel()->print(); - } else { - debugPrintf("Game levels have not been loaded\n"); - } + StarkGlobal->getCurrent()->getLevel()->print(); return true; } bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - - Resources::Level *level = current->getLevel(); - Resources::Location *location = current->getLocation(); + Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); + Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); Common::Array knowledge = level->listChildrenRecursive(); knowledge.insert_at(knowledge.size(), location->listChildrenRecursive()); Common::Array::iterator it; @@ -175,13 +152,6 @@ bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { } bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - uint index = 0; char type = 0; @@ -189,8 +159,8 @@ bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) { index = atoi(argv[1]); type = argv[2][0]; if (type == 'b' || type == 'i') { - Resources::Level *level = current->getLevel(); - Resources::Location *location = current->getLocation(); + Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); + Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); Common::Array knowledgeArr = level->listChildrenRecursive(); knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive()); if (index < knowledgeArr.size() ) { @@ -230,12 +200,6 @@ Common::Array Console::listAllLocationScripts() const { } bool Console::Cmd_ListScripts(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - Common::Array scripts = listAllLocationScripts(); for (uint i = 0; i < scripts.size(); i++) { @@ -260,12 +224,6 @@ bool Console::Cmd_ListScripts(int argc, const char **argv) { } bool Console::Cmd_EnableScript(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - uint index = 0; if (argc >= 2) { @@ -295,12 +253,6 @@ bool Console::Cmd_EnableScript(int argc, const char **argv) { } bool Console::Cmd_ForceScript(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - uint index = 0; if (argc >= 2) { @@ -327,12 +279,6 @@ bool Console::Cmd_ForceScript(int argc, const char **argv) { } bool Console::Cmd_DecompileScript(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - if (argc >= 2) { uint index = atoi(argv[1]); @@ -454,44 +400,27 @@ void Console::decompileScriptChildren(Resources::Object *level) { bool Console::Cmd_DumpLocation(int argc, const char **argv) { if (StarkStaticProvider->isStaticLocation()) { StarkStaticProvider->getLocation()->print(); - return true; - } - - Current *current = StarkGlobal->getCurrent(); - if (current) { - current->getLocation()->print(); } else { - debugPrintf("Locations have not been loaded\n"); + StarkGlobal->getCurrent()->getLocation()->print(); } return true; } bool Console::Cmd_ListInventory(int argc, const char **argv) { - if (StarkGlobal->getInventory()) { - StarkGlobal->printInventory(argc != 2); - } else { - debugPrintf("The inventory has not been loaded\n"); - } + StarkGlobal->printInventory(argc != 2); return true; } bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) { - if (!StarkGlobal->getInventory()) { - debugPrintf("The inventory has not been loaded\n"); - return true; - } - if (argc != 2) { debugPrintf("Enable a specific inventory item. Use listInventory to get an id\n"); debugPrintf("Usage :\n"); debugPrintf("enableInventoryItem [id]\n"); return true; } - StarkGlobal->enableInventoryItem(atoi(argv[1])); - return true; } @@ -542,11 +471,6 @@ bool Console::Cmd_ListLocations(int argc, const char **argv) { } bool Console::Cmd_ChangeLocation(int argc, const char **argv) { - if (!StarkGlobal->getRoot()) { - debugPrintf("The global root has not been loaded\n"); - return true; - } - if (argc != 3) { debugPrintf("Change the current location. Use listLocations to get ids\n"); debugPrintf("Usage :\n"); @@ -557,57 +481,12 @@ bool Console::Cmd_ChangeLocation(int argc, const char **argv) { uint levelIndex = strtol(argv[1] , nullptr, 16); uint locationIndex = strtol(argv[2] , nullptr, 16); - bool isIndicesValid = true; + StarkResourceProvider->requestLocationChange(levelIndex, locationIndex); - // Temporarily replace the global archive loader - ArchiveLoader *archiveLoader = new ArchiveLoader(); - ArchiveLoader *gameArchiveLoader = StarkArchiveLoader; - StarkArchiveLoader = archiveLoader; - - archiveLoader->load("x.xarc"); - Resources::Root *root = archiveLoader->useRoot("x.xarc"); - - // Assert the level index - Resources::Level *level = root->findChildWithIndex(levelIndex); - if (!level) { - debugPrintf("Invalid level index %d, only %d indices available\n", levelIndex, - root->listChildren().size()); - isIndicesValid = false; - } - - // Load locations archives - Common::String levelArchive = archiveLoader->buildArchiveName(level); - archiveLoader->load(levelArchive); - level = archiveLoader->useRoot(levelArchive); - - // Assert the location index - Resources::Location *location = level->findChildWithIndex(locationIndex); - if (!location) { - debugPrintf("Invalid location index %d, only %d indices available\n", locationIndex, - level->listChildren().size()); - isIndicesValid = false; - } - - // Restore the global archive loader - archiveLoader->returnRoot(levelArchive); - archiveLoader->unloadUnused(); - StarkArchiveLoader = gameArchiveLoader; - delete archiveLoader; - - if (isIndicesValid) { - StarkResourceProvider->requestLocationChange(levelIndex, locationIndex); - return false; - } - - return true; + return false; } bool Console::Cmd_ChangeChapter(int argc, const char **argv) { - if (!StarkGlobal->getLevel()) { - debugPrintf("The global level has not been loaded\n"); - return true; - } - if (argc != 2) { debugPrintf("Change the current chapter\n"); debugPrintf("Usage :\n"); @@ -623,13 +502,6 @@ bool Console::Cmd_ChangeChapter(int argc, const char **argv) { } bool Console::Cmd_Location(int argc, const char **argv) { - Current *current = StarkGlobal->getCurrent(); - - if (!current) { - debugPrintf("Game levels have not been loaded\n"); - return true; - } - if (argc != 1) { debugPrintf("Display the current location\n"); debugPrintf("Usage :\n"); @@ -637,17 +509,14 @@ bool Console::Cmd_Location(int argc, const char **argv) { return true; } + Current *current = StarkGlobal->getCurrent(); + debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); return true; } bool Console::Cmd_Chapter(int argc, const char **argv) { - if (!StarkGlobal->getLevel()) { - debugPrintf("The global level has not been loaded\n"); - return true; - } - if (argc != 1) { debugPrintf("Display the current chapter\n"); debugPrintf("Usage :\n"); diff --git a/engines/stark/services/global.cpp b/engines/stark/services/global.cpp index b33fd60ab7b..cc540c7fb56 100644 --- a/engines/stark/services/global.cpp +++ b/engines/stark/services/global.cpp @@ -27,9 +27,6 @@ #include "engines/stark/resources/knowledge.h" #include "engines/stark/resources/knowledgeset.h" -#include "gui/debugger.h" -#include "engines/engine.h" - namespace Stark { Global::Global() : @@ -55,24 +52,18 @@ void Global::setCurrentChapter(int32 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()); + warning("Item %d: %s", 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 cheking failed - g_engine->getDebugger()->debugPrintf("Invalid index %d, only %d indices available\n", num, inventoryItems.size()); - } + inventoryItems[num]->setEnabled(true); } Common::String Global::getCharacterName(int32 id) { 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;