diff options
Diffstat (limited to 'engines/zvision')
-rw-r--r-- | engines/zvision/actions.cpp | 12 | ||||
-rw-r--r-- | engines/zvision/puzzle.h | 9 | ||||
-rw-r--r-- | engines/zvision/scr_file_handling.cpp | 8 | ||||
-rw-r--r-- | engines/zvision/script_manager.cpp | 42 | ||||
-rw-r--r-- | engines/zvision/script_manager.h | 18 |
5 files changed, 48 insertions, 41 deletions
diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 1fa9fcf334..0bb553a559 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -124,7 +124,8 @@ ActionDisableControl::ActionDisableControl(const Common::String &line) { bool ActionDisableControl::execute(ZVision *engine) { debug("Disabling control %u", _key); - engine->getScriptManager()->disableControl(_key); + ScriptManager *scriptManager = engine->getScriptManager(); + scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) | StateFlags::DISABLED); return true; } @@ -141,7 +142,8 @@ ActionEnableControl::ActionEnableControl(const Common::String &line) { bool ActionEnableControl::execute(ZVision *engine) { debug("Enabling control %u", _key); - engine->getScriptManager()->enableControl(_key); + ScriptManager *scriptManager = engine->getScriptManager(); + scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) & ~StateFlags::DISABLED); return true; } @@ -223,8 +225,10 @@ bool ActionPreloadAnimation::execute(ZVision *engine) { // TODO: Check if the Control already exists // Create the control, but disable it until PlayPreload is called - engine->getScriptManager()->addControl(new AnimationControl(engine, _key, _fileName)); - engine->getScriptManager()->disableControl(_key); + ScriptManager *scriptManager = engine->getScriptManager(); + scriptManager->addControl(new AnimationControl(engine, _key, _fileName)); + scriptManager->setStateFlags(_key, scriptManager->getStateFlags(_key) | StateFlags::DISABLED); + return true; } diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index 1e730365dc..d468da1886 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -32,7 +32,7 @@ namespace ZVision { struct Puzzle { - Puzzle() : key(0), flags(0) {} + Puzzle() : key(0) {} ~Puzzle() { for (Common::List<ResultAction *>::iterator iter = resultActions.begin(); iter != resultActions.end(); ++iter) { @@ -63,17 +63,10 @@ struct Puzzle { bool argumentIsAKey; }; - enum StateFlags { - ONCE_PER_INST = 0x01, - DO_ME_NOW = 0x02, // Somewhat useless flag since anything that needs to be done immediately has no criteria - DISABLED = 0x04 - }; - uint32 key; Common::List<Common::List <CriteriaEntry> > criteriaList; // This has to be list of pointers because ResultAction is abstract Common::List<ResultAction *> resultActions; - uint flags; }; } // End of namespace ZVision diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index e90408cf0d..0c952ae0ce 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -81,7 +81,7 @@ void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stre } else if (line.matchString("results {", true)) { parseResults(stream, puzzle->resultActions); } else if (line.matchString("flags {", true)) { - puzzle->flags = parseFlags(stream); + setStateFlags(puzzle->key, parseFlags(stream)); } line = stream.readLine(); @@ -259,11 +259,11 @@ uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const { while (!stream.eos() && !line.contains('}')) { if (line.matchString("ONCE_PER_INST", true)) { - flags |= Puzzle::ONCE_PER_INST; + flags |= ONCE_PER_INST; } else if (line.matchString("DO_ME_NOW", true)) { - flags |= Puzzle::DO_ME_NOW; + flags |= DO_ME_NOW; } else if (line.matchString("DISABLED", true)) { - flags |= Puzzle::DISABLED; + flags |= DISABLED; } line = stream.readLine(); diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 66a54088fd..0e08345f07 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -126,8 +126,7 @@ void ScriptManager::checkPuzzleCriteria() { // Check if the puzzle is already finished // Also check that the puzzle isn't disabled - if (getStateValue(puzzle->key) == 1 && - (puzzle->flags & Puzzle::DISABLED) == 0) { + if (getStateValue(puzzle->key) == 1 && (getStateFlags(puzzle->key) & DISABLED) == 0) { continue; } @@ -223,6 +222,23 @@ void ScriptManager::setStateValue(uint32 key, uint value) { } } +uint ScriptManager::getStateFlags(uint32 key) { + if (_globalStateFlags.contains(key)) + return _globalStateFlags[key]; + else + return 0; +} + +void ScriptManager::setStateFlags(uint32 key, uint flags) { + _globalStateFlags[key] = flags; + + if (_referenceTable.contains(key)) { + for (Common::Array<Puzzle *>::iterator iter = _referenceTable[key].begin(); iter != _referenceTable[key].end(); ++iter) { + _puzzlesToCheck.push((*iter)); + } + } +} + void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) { _globalState[key] += valueToAdd; } @@ -241,24 +257,6 @@ Control *ScriptManager::getControl(uint32 key) { return nullptr; } -void ScriptManager::enableControl(uint32 key) { - for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { - if ((*iter)->getKey() == key) { - (*iter)->enable(); - break; - } - } -} - -void ScriptManager::disableControl(uint32 key) { - for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { - if ((*iter)->getKey() == key) { - (*iter)->disable(); - break; - } - } -} - void ScriptManager::focusControl(uint32 key) { for (ControlList::iterator iter = _activeControls.begin(); iter != _activeControls.end(); ++iter) { uint32 controlKey = (*iter)->getKey(); @@ -352,7 +350,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Add all the local puzzles to the queue to be checked for (PuzzleList::iterator iter = _activePuzzles.begin(); iter != _activePuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + if ((getStateFlags((*iter)->key) & ONCE_PER_INST) == ONCE_PER_INST) { setStateValue((*iter)->key, 0); } @@ -362,7 +360,7 @@ void ScriptManager::changeLocation(char world, char room, char node, char view, // Add all the global puzzles to the queue to be checked for (PuzzleList::iterator iter = _globalPuzzles.begin(); iter != _globalPuzzles.end(); ++iter) { // Reset any Puzzles that have the flag ONCE_PER_INST - if (((*iter)->flags & Puzzle::ONCE_PER_INST) == Puzzle::ONCE_PER_INST) { + if ((getStateFlags((*iter)->key) & ONCE_PER_INST) == ONCE_PER_INST) { setStateValue((*iter)->key, 0); } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 388d0805e0..a5079e3332 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -49,11 +49,18 @@ struct Location { uint32 offset; }; +enum StateFlags { + ONCE_PER_INST = 0x01, + DO_ME_NOW = 0x02, // Somewhat useless flag since anything that needs to be done immediately has no criteria + DISABLED = 0x04 +}; + typedef Common::HashMap<uint32, Common::Array<Puzzle *> > PuzzleMap; typedef Common::List<Puzzle *> PuzzleList; typedef Common::Queue<Puzzle *> PuzzleQueue; typedef Common::List<Control *> ControlList; typedef Common::HashMap<uint32, uint32> StateMap; +typedef Common::HashMap<uint32, uint> StateFlagMap; class ScriptManager { public: @@ -68,6 +75,11 @@ private: * particular state key are checked after the key is modified. */ StateMap _globalState; + /** + * Holds the flags for the global states. This is used to enable/disable puzzles and/or + * controls as well as which puzzles should are allowed to be re-executed + */ + StateFlagMap _globalStateFlags; /** References _globalState keys to Puzzles */ PuzzleMap _referenceTable; /** Holds the Puzzles that should be checked this frame */ @@ -91,12 +103,12 @@ public: void setStateValue(uint32 key, uint value); void addToStateValue(uint32 key, uint valueToAdd); + uint getStateFlags(uint32 key); + void setStateFlags(uint32 key, uint flags); + void addControl(Control *control); Control *getControl(uint32 key); - void enableControl(uint32 key); - void disableControl(uint32 key); - void focusControl(uint32 key); /** |