diff options
author | richiesams | 2013-08-18 15:38:56 -0500 |
---|---|---|
committer | richiesams | 2013-08-18 19:53:04 -0500 |
commit | 46ab3557660221b2896c0d5cd4a7d3fb0464d1d1 (patch) | |
tree | 4b71f9744f11ea295b79ef6ae06df4117fec09c0 /engines/zvision | |
parent | 5a86355e7dae3b00924ce95275f1fea9346a6211 (diff) | |
download | scummvm-rg350-46ab3557660221b2896c0d5cd4a7d3fb0464d1d1.tar.gz scummvm-rg350-46ab3557660221b2896c0d5cd4a7d3fb0464d1d1.tar.bz2 scummvm-rg350-46ab3557660221b2896c0d5cd4a7d3fb0464d1d1.zip |
ZVISION: Allow Puzzles to have mutiple 'sets' of CriteriaEntries
Diffstat (limited to 'engines/zvision')
-rw-r--r-- | engines/zvision/puzzle.h | 4 | ||||
-rw-r--r-- | engines/zvision/scr_file_handling.cpp | 32 | ||||
-rw-r--r-- | engines/zvision/script_manager.cpp | 89 | ||||
-rw-r--r-- | engines/zvision/script_manager.h | 2 |
4 files changed, 74 insertions, 53 deletions
diff --git a/engines/zvision/puzzle.h b/engines/zvision/puzzle.h index e7846f5296..36787e7ba1 100644 --- a/engines/zvision/puzzle.h +++ b/engines/zvision/puzzle.h @@ -41,7 +41,7 @@ struct Puzzle { }; /** Criteria for a Puzzle result to be fired */ - struct Criteria { + struct CriteriaEntry { /** The key of a global state */ uint32 key; /** @@ -62,7 +62,7 @@ struct Puzzle { }; uint32 key; - Common::List<Criteria> criteriaList; + Common::List<Common::List <CriteriaEntry> > criteriaList; // This has to be list of pointers because ResultAction is abstract Common::List<Common::SharedPtr<ResultAction> > resultActions; uint flags; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 3fee767135..dd2754c12f 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -73,10 +73,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { - Puzzle::Criteria criteria; - if (parseCriteria(&criteria, stream)) { - puzzle.criteriaList.push_back(criteria); - } + parseCriteria(stream, puzzle.criteriaList); } else if (line.matchString("results {", true)) { parseResults(stream, puzzle.resultActions); } else if (line.matchString("flags {", true)) { @@ -88,7 +85,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre } } -bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const { +bool ScriptManager::parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); @@ -98,37 +95,44 @@ bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableRe return false; } + // Create a new List to hold the CriteriaEntries + criteriaList.push_back(Common::List<Puzzle::CriteriaEntry>()); + while (!stream.eos() && !line.contains('}')) { + Puzzle::CriteriaEntry entry; + // Split the string into tokens using ' ' as a delimiter Common::StringTokenizer tokenizer(line); Common::String token; // Parse the id out of the first token token = tokenizer.nextToken(); - sscanf(token.c_str(), "[%u]", &(criteria->key)); + sscanf(token.c_str(), "[%u]", &(entry.key)); // Parse the operator out of the second token token = tokenizer.nextToken(); if (token.c_str()[0] == '=') - criteria->criteriaOperator = Puzzle::EQUAL_TO; + entry.criteriaOperator = Puzzle::EQUAL_TO; else if (token.c_str()[0] == '!') - criteria->criteriaOperator = Puzzle::NOT_EQUAL_TO; + entry.criteriaOperator = Puzzle::NOT_EQUAL_TO; else if (token.c_str()[0] == '>') - criteria->criteriaOperator = Puzzle::GREATER_THAN; + entry.criteriaOperator = Puzzle::GREATER_THAN; else if (token.c_str()[0] == '<') - criteria->criteriaOperator = Puzzle::LESS_THAN; + entry.criteriaOperator = Puzzle::LESS_THAN; // First determine if the last token is an id or a value // Then parse it into 'argument' token = tokenizer.nextToken(); if (token.contains('[')) { - sscanf(token.c_str(), "[%u]", &(criteria->argument)); - criteria->argumentIsAKey = true; + sscanf(token.c_str(), "[%u]", &(entry.argument)); + entry.argumentIsAKey = true; } else { - sscanf(token.c_str(), "%u", &(criteria->argument)); - criteria->argumentIsAKey = false; + sscanf(token.c_str(), "%u", &(entry.argument)); + entry.argumentIsAKey = false; } + criteriaList.back().push_back(entry); + line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } diff --git a/engines/zvision/script_manager.cpp b/engines/zvision/script_manager.cpp index 13f30ca0d2..9796a95353 100644 --- a/engines/zvision/script_manager.cpp +++ b/engines/zvision/script_manager.cpp @@ -61,13 +61,16 @@ void ScriptManager::createReferenceTable() { for (Common::List<Puzzle>::iterator activePuzzleIter = _activePuzzles.begin(); activePuzzleIter != _activePuzzles.end(); activePuzzleIter++) { Puzzle *puzzlePtr = &(*activePuzzleIter); - // Iterate through each Criteria and add a reference from the criteria key to the Puzzle - for (Common::List<Puzzle::Criteria>::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).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); + // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle + for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + _referenceTable[entryIter->key].push_back(puzzlePtr); + + // If the argument is a key, add a reference to it as well + if (entryIter->argumentIsAKey) { + _referenceTable[entryIter->argument].push_back(puzzlePtr); + } + } } } @@ -75,13 +78,16 @@ void ScriptManager::createReferenceTable() { for (Common::List<Puzzle>::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<Puzzle::Criteria>::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { - _referenceTable[criteriaIter->key].push_back(puzzlePtr); + // Iterate through each CriteriaEntry and add a reference from the criteria key to the Puzzle + for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = globalPuzzleIter->criteriaList.begin(); criteriaIter != (*globalPuzzleIter).criteriaList.end(); criteriaIter++) { + for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + _referenceTable[entryIter->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); + // If the argument is a key, add a reference to it as well + if (entryIter->argumentIsAKey) { + _referenceTable[entryIter->argument].push_back(puzzlePtr); + } + } } } @@ -115,32 +121,43 @@ void ScriptManager::checkPuzzleCriteria() { } // Check each Criteria + bool criteriaMet = false; - for (Common::List<Puzzle::Criteria>::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) { - // Get the value to compare against - uint argumentValue; - if ((*iter).argumentIsAKey) - argumentValue = getStateValue(iter->argument); - else - argumentValue = iter->argument; - - // Do the comparison - switch ((*iter).criteriaOperator) { - case Puzzle::EQUAL_TO: - criteriaMet = getStateValue(iter->key) == argumentValue; - break; - case Puzzle::NOT_EQUAL_TO: - criteriaMet = getStateValue(iter->key) != argumentValue; - break; - case Puzzle::GREATER_THAN: - criteriaMet = getStateValue(iter->key) > argumentValue; - break; - case Puzzle::LESS_THAN: - criteriaMet = getStateValue(iter->key) < argumentValue; - break; + for (Common::List<Common::List<Puzzle::CriteriaEntry> >::iterator criteriaIter = puzzle->criteriaList.begin(); criteriaIter != puzzle->criteriaList.end(); criteriaIter++) { + criteriaMet = false; + + for (Common::List<Puzzle::CriteriaEntry>::iterator entryIter = (*criteriaIter).begin(); entryIter != (*criteriaIter).end(); entryIter++) { + // Get the value to compare against + uint argumentValue; + if ((*entryIter).argumentIsAKey) + argumentValue = getStateValue(entryIter->argument); + else + argumentValue = entryIter->argument; + + // Do the comparison + switch ((*entryIter).criteriaOperator) { + case Puzzle::EQUAL_TO: + criteriaMet = getStateValue(entryIter->key) == argumentValue; + break; + case Puzzle::NOT_EQUAL_TO: + criteriaMet = getStateValue(entryIter->key) != argumentValue; + break; + case Puzzle::GREATER_THAN: + criteriaMet = getStateValue(entryIter->key) > argumentValue; + break; + case Puzzle::LESS_THAN: + criteriaMet = getStateValue(entryIter->key) < argumentValue; + break; + } + + // If one check returns false, don't keep checking + if (!criteriaMet) { + break; + } } - if (!criteriaMet) { + // If any of the Criteria are *fully* met, then execute the results + if (criteriaMet) { break; } } diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h index 7012ee0c5e..d484531470 100644 --- a/engines/zvision/script_manager.h +++ b/engines/zvision/script_manager.h @@ -122,7 +122,7 @@ private: * @param stream Scr file stream * @return Whether any criteria were read */ - bool parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const; + bool parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList) const; /** * Parses the stream into a ResultAction objects |