aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/script.cpp
diff options
context:
space:
mode:
authorDenis Kasak2009-08-08 15:55:19 +0000
committerDenis Kasak2009-08-08 15:55:19 +0000
commit18b5d7ce33ffc3631f38b041cb3a48bcb64a3bc7 (patch)
tree5c846317e08846e1cebb09889829318e84f38211 /engines/draci/script.cpp
parentd2f7268171b1ef3756a5de10aafc5f93761484f1 (diff)
downloadscummvm-rg350-18b5d7ce33ffc3631f38b041cb3a48bcb64a3bc7.tar.gz
scummvm-rg350-18b5d7ce33ffc3631f38b041cb3a48bcb64a3bc7.tar.bz2
scummvm-rg350-18b5d7ce33ffc3631f38b041cb3a48bcb64a3bc7.zip
Implemented Script::testExpression().
svn-id: r43129
Diffstat (limited to 'engines/draci/script.cpp')
-rw-r--r--engines/draci/script.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp
index 9d72c4ab34..a997fa4e55 100644
--- a/engines/draci/script.cpp
+++ b/engines/draci/script.cpp
@@ -598,6 +598,8 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) {
GPL2Operator oper;
GPL2Function func;
+ debugC(3, kDraciBytecodeDebugLevel, "\t<MATHEXPR>");
+
// Read in initial math object
obj = (mathExpressionObject)reader.readSint16LE();
@@ -688,6 +690,36 @@ int Script::handleMathExpression(Common::MemoryReadStream &reader) {
}
/**
+ * @brief Evaluates a GPL mathematical expression on a given offset and returns
+ * the result (which is normally a boolean-like value)
+ *
+ * @param program A GPL2Program instance of the program containing the expression
+ * @param offset Offset of the expression inside the program (in multiples of 2 bytes)
+ *
+ * @return The result of the expression converted to a bool.
+ *
+ * Reference: the function equivalent to this one is called "Can()" in the original engine.
+ */
+bool Script::testExpression(GPL2Program program, uint16 offset) {
+
+ // Initialize program reader
+ Common::MemoryReadStream reader(program._bytecode, program._length);
+
+ // Offset is given as number of 16-bit integers so we need to convert
+ // it to a number of bytes
+ offset -= 1;
+ offset *= 2;
+
+ // Seek to the expression
+ reader.seek(offset);
+
+ debugC(2, kDraciBytecodeDebugLevel,
+ "Evaluating (standalone) GPL expression at offset %d:", offset);
+
+ return (bool)handleMathExpression(reader);
+}
+
+/**
* @brief Find the current command in the internal table
*
* @param num Command number
@@ -812,7 +844,8 @@ int Script::run(GPL2Program program, uint16 offset) {
for (int i = 0; i < cmd->_numParams; ++i) {
if (cmd->_paramTypes[i] == 4) {
- debugC(2, kDraciBytecodeDebugLevel, "\t<MATHEXPR>");
+ debugC(2, kDraciBytecodeDebugLevel,
+ "Evaluating (in-script) GPL expression at offset %d: ", offset);
params.push(handleMathExpression(reader));
}
else {