diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/wage/script.cpp | 45 | ||||
-rw-r--r-- | engines/wage/script.h | 2 |
2 files changed, 45 insertions, 2 deletions
diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index 778c0c8269..13b2617509 100644 --- a/engines/wage/script.cpp +++ b/engines/wage/script.cpp @@ -749,10 +749,51 @@ Script::Operand *Script::convertOperand(Operand *operand, int type) { return NULL; } +bool Script::evalClickEquality(Operand *lhs, Operand *rhs, bool partialMatch) { + bool result = false; + if (lhs->_value.obj == NULL || rhs->_value.obj == NULL) { + result = false; + } else if (lhs->_value.obj == rhs->_value.obj) { + result = true; + } else if (rhs->_type == STRING) { + Common::String str = rhs->toString(); + str.toLowercase(); + + if (lhs->_type == CHR || lhs->_type == OBJ) { + Common::String name = lhs->_value.designed->_name; + name.toLowercase(); + + if (partialMatch) + result = name.contains(str); + else + result = name.equals(str); + } + } + return result; +} + bool Script::evalClickCondition(Operand *lhs, const char *op, Operand *rhs) { - warning("STUB: evalClickCondition"); + // TODO: check if >> can be used for click inputs + if (strcmp(op, "==") && strcmp(op, "=") && strcmp(op, "<") && strcmp(op, ">")) { + error("Unknown operation '%s' for Script::evalClickCondition", op); + } - return false; + bool partialMatch = strcmp(op, "=="); + bool result; + if (lhs->_type == CLICK_INPUT) { + result = evalClickEquality(lhs, rhs, partialMatch); + } else { + result = evalClickEquality(rhs, lhs, partialMatch); + } + if (!strcmp(op, "<") || !strcmp(op, ">")) { + // CLICK$<FOO only matches if there was a click + if (_inputClick == NULL) { + result = false; + } else { + result = !result; + } + } + return result; } void Script::takeObj(Obj *obj) { diff --git a/engines/wage/script.h b/engines/wage/script.h index 0cf6785fc6..876ec0764e 100644 --- a/engines/wage/script.h +++ b/engines/wage/script.h @@ -70,6 +70,7 @@ private: union { Obj *obj; Chr *chr; + Designed *designed; Scene *scene; int16 number; String *string; @@ -156,6 +157,7 @@ private: bool eval(Operand *lhs, const char *op, Operand *rhs); Operand *convertOperand(Operand *operand, int type); bool evalClickCondition(Operand *lhs, const char *op, Operand *rhs); + bool evalClickEquality(Operand *lhs, Operand *rhs, bool partialMatch); void takeObj(Obj *obj); void processMove(); void processLet(); |