Skip to content

Commit

Permalink
WAGE: Implement evalClickCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 2, 2016
1 parent 8d6e811 commit 0870ac8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
45 changes: 43 additions & 2 deletions engines/wage/script.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions engines/wage/script.h
Expand Up @@ -70,6 +70,7 @@ class Script {
union {
Obj *obj;
Chr *chr;
Designed *designed;
Scene *scene;
int16 number;
String *string;
Expand Down Expand Up @@ -156,6 +157,7 @@ class Script {
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();
Expand Down

0 comments on commit 0870ac8

Please sign in to comment.