From 5bba509db8a84a5d6c2ab4863990683977203e60 Mon Sep 17 00:00:00 2001 From: richiesams Date: Sat, 10 Aug 2013 17:23:47 -0500 Subject: ZVISION: Create a global puzzle list and parse universe.scr into it during ScriptManager::initialize() --- engines/zvision/scr_file_handling.cpp | 8 ++++++-- engines/zvision/script_manager.cpp | 21 +++++++++++++++++---- engines/zvision/script_manager.h | 7 +++++-- 3 files changed, 28 insertions(+), 8 deletions(-) (limited to 'engines/zvision') diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 061079cd85..efd122994d 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -33,7 +33,7 @@ namespace ZVision { -void ScriptManager::parseScrFile(const Common::String &fileName) { +void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) { Common::File file; if (!file.open(fileName)) return; // File.open already throws a warning if the file doesn't exist, so there is no need to throw another @@ -54,7 +54,11 @@ void ScriptManager::parseScrFile(const Common::String &fileName) { sscanf(line.c_str(),"puzzle:%u",&(puzzle.key)); parsePuzzle(puzzle, file); - _activePuzzles.push_back(puzzle); + if (isGlobal) { + _globalPuzzles.push_back(puzzle); + } else { + _activePuzzles.push_back(puzzle); + } } else if (line.matchString("control:*", true)) { Common::SharedPtr control; diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index fe6548cd80..027fec43a1 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -35,13 +35,12 @@ namespace ZVision { ScriptManager::ScriptManager(ZVision *engine) : _engine(engine) {} -// TODO: Actually do something in the initialize or remove it void ScriptManager::initialize() { - + parseScrFile("universe.scr", true); } void ScriptManager::createReferenceTable() { - // Iterate through each Puzzle + // Iterate through each local Puzzle for (Common::List::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { Puzzle *puzzlePtr = &(*activePuzzleIter); @@ -50,7 +49,21 @@ void ScriptManager::createReferenceTable() { _referenceTable[criteriaIter->key].push_back(puzzlePtr); // If the argument is a key, add a reference to it as well - if (criteriaIter->argument) + if (criteriaIter->argumentIsAKey) + _referenceTable[criteriaIter->argument].push_back(puzzlePtr); + } + } + + // Iterate through each global Puzzle + for (Common::List::iterator globalPuzzleIter = _globalPuzzles.begin(); globalPuzzleIter != _globalPuzzles.end(); globalPuzzleIter++) { + Puzzle *puzzlePtr = &(*globalPuzzleIter); + + // Iterate through each Criteria and add a reference from the criteria key to the Puzzle + for (Common::List::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + _referenceTable[criteriaIter->key].push_back(puzzlePtr); + + // If the argument is a key, add a reference to it as well + if (criteriaIter->argumentIsAKey) _referenceTable[criteriaIter->argument].push_back(puzzlePtr); } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 484069b335..63dc4f8804 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -59,6 +59,8 @@ private: Common::Stack _puzzlesToCheck; /** Holds the currently active puzzles */ Common::List _activePuzzles; + /** Holds the global puzzles */ + Common::List_globalPuzzles; /** Holds the currently active controls */ Common::List > _activeControls; @@ -82,9 +84,10 @@ private: /** * Parses a script file into triggers and events * - * @param fileName Name of the .scr file + * @param fileName Name of the .scr file + * @param isGlobal Are the puzzles included in the file global (true). AKA, the won't be purged during location changes */ - void parseScrFile(const Common::String &fileName); + void parseScrFile(const Common::String &fileName, bool isGlobal = false); /** * Parses the stream into a Puzzle object -- cgit v1.2.3