From a52dff53f24c712f35eef26265e31f177697e0a9 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 13 Feb 2015 09:19:47 +0100 Subject: [PATCH] STARK: Add a console command allowing to change the current chapter --- engines/stark/console.cpp | 51 +++++++++++++++++++++++++++++++ engines/stark/console.h | 3 ++ engines/stark/services/global.cpp | 6 ++++ engines/stark/services/global.h | 3 ++ engines/stark/stark.cpp | 1 + 5 files changed, 64 insertions(+) diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp index bc420c8261a..68fadc4caf7 100644 --- a/engines/stark/console.cpp +++ b/engines/stark/console.cpp @@ -42,7 +42,10 @@ Console::Console() : GUI::Debugger() { registerCmd("dumpLevel", WRAP_METHOD(Console, Cmd_DumpLevel)); registerCmd("dumpLocation", WRAP_METHOD(Console, Cmd_DumpLocation)); registerCmd("listLocations", WRAP_METHOD(Console, Cmd_ListLocations)); + registerCmd("location", WRAP_METHOD(Console, Cmd_Location)); + registerCmd("chapter", WRAP_METHOD(Console, Cmd_Chapter)); registerCmd("changeLocation", WRAP_METHOD(Console, Cmd_ChangeLocation)); + registerCmd("changeChapter", WRAP_METHOD(Console, Cmd_ChangeChapter)); } Console::~Console() { @@ -173,4 +176,52 @@ bool Console::Cmd_ChangeLocation(int argc, const char **argv) { return false; } +bool Console::Cmd_ChangeChapter(int argc, const char **argv) { + if (argc != 2) { + debugPrintf("Change the current chapter.\n"); + debugPrintf("Usage :\n"); + debugPrintf("changeChapter [value]\n"); + return true; + } + + uint32 value = atoi(argv[1]); + + Global *global = StarkServices::instance().global; + global->setCurrentChapter(value); + + return true; +} + +bool Console::Cmd_Location(int argc, const char **argv) { + if (argc != 1) { + debugPrintf("Display the current location.\n"); + debugPrintf("Usage :\n"); + debugPrintf("location\n"); + return true; + } + + Global *global = StarkServices::instance().global; + Current *current = global->getCurrent(); + + debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); + + return true; +} + +bool Console::Cmd_Chapter(int argc, const char **argv) { + if (argc != 1) { + debugPrintf("Display the current chapter.\n"); + debugPrintf("Usage :\n"); + debugPrintf("chapter\n"); + return true; + } + + Global *global = StarkServices::instance().global; + int32 value = global->getCurrentChapter(); + + debugPrintf("chapter: %d\n", value); + + return true; +} + } // End of namespace Stark diff --git a/engines/stark/console.h b/engines/stark/console.h index a65b75ac386..d9f94de402f 100644 --- a/engines/stark/console.h +++ b/engines/stark/console.h @@ -42,7 +42,10 @@ private: bool Cmd_DumpLevel(int argc, const char **argv); bool Cmd_DumpLocation(int argc, const char **argv); bool Cmd_ListLocations(int argc, const char** argv); + bool Cmd_Location(int argc, const char **argv); + bool Cmd_Chapter(int argc, const char **argv); bool Cmd_ChangeLocation(int argc, const char **argv); + bool Cmd_ChangeChapter(int argc, const char **argv); }; } // End of namespace Stark diff --git a/engines/stark/services/global.cpp b/engines/stark/services/global.cpp index 586ded81336..0cd86c93363 100644 --- a/engines/stark/services/global.cpp +++ b/engines/stark/services/global.cpp @@ -44,4 +44,10 @@ int32 Global::getCurrentChapter() { return chapter->getIntegerValue(); } +void Global::setCurrentChapter(int32 value) { + KnowledgeSet *globalState = _level->findChildWithSubtype(KnowledgeSet::kState); + Knowledge *chapter = globalState->findChildWithIndex(0); + chapter->setIntegerValue(value); +} + } // End of namespace Stark diff --git a/engines/stark/services/global.h b/engines/stark/services/global.h index 98812560456..76bf14cb48e 100644 --- a/engines/stark/services/global.h +++ b/engines/stark/services/global.h @@ -93,6 +93,9 @@ public: /** Retrieve the current chapter number from the global resource tree */ int32 getCurrentChapter(); + + /** Change the current chapter */ + void setCurrentChapter(int32 value); private: uint _millisecondsPerGameloop; Root *_root; diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index d029fb623b9..61a83cb879c 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -115,6 +115,7 @@ Common::Error StarkEngine::run() { _resourceProvider->initGlobal(); // Start us up at the house of all worlds + _global->setCurrentChapter(0); _resourceProvider->requestLocationChange(0x45, 0x00); // Start running