ZVISION: Move CriteriaOperator, Criteria, and StateFlag inside the Puzzle class

This commit is contained in:
richiesams
2013-08-04 13:32:54 -05:00
parent f975fbe521
commit f39e1fdc43
4 changed files with 47 additions and 45 deletions
+31 -29
View File
@@ -29,41 +29,43 @@ namespace ZVision {
class ResultAction;
/** How criteria should be decided */
enum CriteriaOperator {
EQUAL_TO,
NOT_EQUAL_TO,
GREATER_THAN,
LESS_THAN
};
/** Criteria for a Puzzle result to be fired */
struct Criteria {
/** The key of a global state */
uint32 key;
/**
* What we're comparing the value of the global state against
* This can either be a pure value or it can be the key of another global state
*/
uint32 argument;
/** How to do the comparison */
CriteriaOperator criteriaOperator;
/** Whether 'argument' is the key of a global state (true) or a pure value (false) */
bool argumentIsAKey;
};
enum StateFlags {
ONCE_PER_INST = 0x01,
DO_ME_NOW = 0x02,
DISABLED = 0x04
};
class Puzzle {
public:
Puzzle() {}
~Puzzle();
Puzzle(const Puzzle &other);
public:
/** How criteria should be decided */
enum CriteriaOperator {
EQUAL_TO,
NOT_EQUAL_TO,
GREATER_THAN,
LESS_THAN
};
/** Criteria for a Puzzle result to be fired */
struct Criteria {
/** The key of a global state */
uint32 key;
/**
* What we're comparing the value of the global state against
* This can either be a pure value or it can be the key of another global state
*/
uint32 argument;
/** How to do the comparison */
CriteriaOperator criteriaOperator;
/** Whether 'argument' is the key of a global state (true) or a pure value (false) */
bool argumentIsAKey;
};
enum StateFlags {
ONCE_PER_INST = 0x01,
DO_ME_NOW = 0x02,
DISABLED = 0x04
};
public:
uint32 key;
Common::List<Criteria> criteriaList;
// This has to be list of pointers because ResultAction is abstract
+9 -9
View File
@@ -71,7 +71,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre
while (!line.contains('}')) {
if (line.matchString("criteria {", true)) {
Criteria criteria;
Puzzle::Criteria criteria;
if (parseCriteria(&criteria, stream)) {
puzzle.criteriaList.push_back(criteria);
}
@@ -86,7 +86,7 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre
}
}
bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const {
bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const {
// Loop until we find the closing brace
Common::String line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
@@ -108,13 +108,13 @@ bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream
// Parse the operator out of the second token
token = tokenizer.nextToken();
if (token.c_str()[0] == '=')
criteria->criteriaOperator = EQUAL_TO;
criteria->criteriaOperator = Puzzle::EQUAL_TO;
else if (token.c_str()[0] == '!')
criteria->criteriaOperator = NOT_EQUAL_TO;
criteria->criteriaOperator = Puzzle::NOT_EQUAL_TO;
else if (token.c_str()[0] == '>')
criteria->criteriaOperator = GREATER_THAN;
criteria->criteriaOperator = Puzzle::GREATER_THAN;
else if (token.c_str()[0] == '<')
criteria->criteriaOperator = LESS_THAN;
criteria->criteriaOperator = Puzzle::LESS_THAN;
// First determine if the last token is an id or a value
// Then parse it into 'argument'
@@ -276,11 +276,11 @@ byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const {
while (!line.contains('}')) {
if (line.matchString("ONCE_PER_INST", true)) {
flags |= ONCE_PER_INST;
flags |= Puzzle::ONCE_PER_INST;
} else if (line.matchString("DO_ME_NOW", true)) {
flags |= DO_ME_NOW;
flags |= Puzzle::DO_ME_NOW;
} else if (line.matchString("DISABLED", true)) {
flags |= DISABLED;
flags |= Puzzle::DISABLED;
}
line = stream.readLine();
+6 -6
View File
@@ -45,7 +45,7 @@ void ScriptManager::createReferenceTable() {
Puzzle *puzzlePtr = &(*activePuzzleIter);
// Iterate through each Criteria and add a reference from the criteria key to the Puzzle
for (Common::List<Criteria>::iterator criteriaIter = activePuzzleIter->criteriaList.begin(); criteriaIter != (*activePuzzleIter).criteriaList.end(); criteriaIter++) {
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
@@ -80,7 +80,7 @@ void ScriptManager::checkPuzzleCriteria() {
// Check each Criteria
bool criteriaMet = false;
for (Common::List<Criteria>::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) {
for (Common::List<Puzzle::Criteria>::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) {
// Get the value to compare against
byte argumentValue;
if ((*iter).argument)
@@ -90,16 +90,16 @@ void ScriptManager::checkPuzzleCriteria() {
// Do the comparison
switch ((*iter).criteriaOperator) {
case EQUAL_TO:
case Puzzle::EQUAL_TO:
criteriaMet = getStateValue(iter->key) == argumentValue;
break;
case NOT_EQUAL_TO:
case Puzzle::NOT_EQUAL_TO:
criteriaMet = getStateValue(iter->key) != argumentValue;
break;
case GREATER_THAN:
case Puzzle::GREATER_THAN:
criteriaMet = getStateValue(iter->key) > argumentValue;
break;
case LESS_THAN:
case Puzzle::LESS_THAN:
criteriaMet = getStateValue(iter->key) < argumentValue;
break;
}
+1 -1
View File
@@ -103,7 +103,7 @@ private:
* @param stream Scr file stream
* @return Whether any criteria were read
*/
bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const;
bool ScriptManager::parseCriteria(Puzzle::Criteria *criteria, Common::SeekableReadStream &stream) const;
/**
* Parses the stream into a Results object