From 693557487d66daaecabb81b15ee68f31283c8d77 Mon Sep 17 00:00:00 2001 From: antoniou79 Date: Wed, 26 Apr 2023 23:02:01 +0300 Subject: [PATCH] PINK: Clear global game variables on New Game This addresses the cause for #13869 PINK: Can't pickup the poker in sir Manley's house However, this will not retroactively fix the broken saved games that carry stale global game variables from other playthroughs It will also will not set the "appropriate" global game variables if the player uses the debug console to jump to different modules and pages back and forth. --- engines/pink/constants.h | 5 ----- engines/pink/cursor_mgr.cpp | 1 + engines/pink/gui.cpp | 3 +-- engines/pink/objects/module.cpp | 2 +- engines/pink/objects/pages/game_page.cpp | 2 +- engines/pink/pink.cpp | 8 +++++++- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/engines/pink/constants.h b/engines/pink/constants.h index 91a81ef05a5..f5629671291 100644 --- a/engines/pink/constants.h +++ b/engines/pink/constants.h @@ -131,11 +131,6 @@ enum { kPerilPDAClickableSecondFrameCursorID = 143 }; -enum { - kLoadingSave = 1, - kLoadingNewGame = 0 -}; - enum { kOrbMajorVersion = 2, kOrbMinorVersion = 0, diff --git a/engines/pink/cursor_mgr.cpp b/engines/pink/cursor_mgr.cpp index c06452d5d74..77fa9544c5d 100644 --- a/engines/pink/cursor_mgr.cpp +++ b/engines/pink/cursor_mgr.cpp @@ -34,6 +34,7 @@ CursorMgr::CursorMgr(PinkEngine *game, Page *page) void CursorMgr::setCursor(byte index, Common::Point point, const Common::String &itemName) { switch (index) { case kClickableFirstFrameCursor: + // fall through case kPDAClickableFirstFrameCursor: startAnimation(index); hideItem(); diff --git a/engines/pink/gui.cpp b/engines/pink/gui.cpp index d898f567393..3a35d23e4bf 100644 --- a/engines/pink/gui.cpp +++ b/engines/pink/gui.cpp @@ -210,8 +210,7 @@ void PinkEngine::executeMenuCommand(uint id) { switch (id) { case kNewGameAction: { - const Common::String moduleName = _modules[0]->getName(); - initModule(moduleName, "", nullptr); + initModule(_modules[0]->getName(), "", nullptr); break; } case kLoadSave: diff --git a/engines/pink/objects/module.cpp b/engines/pink/objects/module.cpp index 45f89bf7c54..a8485fbe4db 100644 --- a/engines/pink/objects/module.cpp +++ b/engines/pink/objects/module.cpp @@ -65,7 +65,7 @@ void Module::init(bool isLoadingSave, const Common::String &pageName) { void Module::changePage(const Common::String &pageName) { _page->unload(); _page = findPage(pageName); - _page->init(kLoadingNewGame); + _page->init(false); } GamePage *Module::findPage(const Common::String &pageName) const { diff --git a/engines/pink/objects/pages/game_page.cpp b/engines/pink/objects/pages/game_page.cpp index 2fedaa0f121..da8f2bc0051 100644 --- a/engines/pink/objects/pages/game_page.cpp +++ b/engines/pink/objects/pages/game_page.cpp @@ -185,7 +185,7 @@ void GamePage::unload() { void GamePage::clear() { Page::clear(); - _variables.clear(1); + _variables.clear(true); for (uint i = 0; i < _handlers.size(); ++i) { delete _handlers[i]; diff --git a/engines/pink/pink.cpp b/engines/pink/pink.cpp index fd55e15c6fd..6d75b4eb61c 100644 --- a/engines/pink/pink.cpp +++ b/engines/pink/pink.cpp @@ -187,13 +187,19 @@ void PinkEngine::initModule(const Common::String &moduleName, const Common::Stri if (_module) removeModule(); + if (moduleName == _modules[0]->getName()) { + // new game + _variables.clear(); + debugC(6, kPinkDebugGeneral, "Global Game Variables cleared"); + } + addModule(moduleName); if (saveFile) _module->loadState(*saveFile); debugC(6, kPinkDebugGeneral, "Module added"); - _module->init(saveFile ? kLoadingSave : kLoadingNewGame, pageName); + _module->init(saveFile != nullptr, pageName); } void PinkEngine::changeScene() {