Skip to content

Commit

Permalink
WAGE: Handle NULL value Operands
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 27, 2015
1 parent 60ce5fa commit a2ac4ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
8 changes: 4 additions & 4 deletions engines/wage/script.cpp
Expand Up @@ -88,7 +88,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
{
Operand *op = readOperand();
// TODO check op type is string or number, or something good...
appendText(op->_str);
appendText(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
Expand All @@ -99,7 +99,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Operand *op = readOperand();
// TODO check op type is string.
_handled = true;
callbacks->playSound(op->_str);
callbacks->playSound(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
Expand All @@ -112,7 +112,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
{
Operand *op = readStringOperand(); // allows empty menu
// TODO check op type is string.
_callbacks->setMenu(op->_str);
_callbacks->setMenu(op->toString());
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
Expand Down Expand Up @@ -196,7 +196,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Script::Operand *Script::readOperand() {
byte operandType = _data->readByte();

debug(2, "readOperand: 0x%x", operandType);
debug(2, "%x: readOperand: 0x%x", _data->pos(), operandType);

Context *cont = &_world->_player->_context;
switch (operandType) {
Expand Down
34 changes: 27 additions & 7 deletions engines/wage/script.h
Expand Up @@ -87,43 +87,63 @@ class Script {
Designed *inputClick;
} _value;
OperandTypes _type;
String _str;
Common::String _str;

Operand(Obj *value, OperandTypes type) {
_value.obj = value;
_str = value->toString();
_type = type;
}

Operand(Chr *value, OperandTypes type) {
_value.chr = value;
_str = value->toString();
_type = type;
}

Operand(Scene *value, OperandTypes type) {
_value.scene = value;
_str = value->toString();
_type = type;
}

Operand(int value, OperandTypes type) {
_value.number = value;
_str = value;
_type = type;
}

Operand(String *value, OperandTypes type) {
_value.string = value;
_str = *value;
_type = type;
}

Operand(Designed *value, OperandTypes type) {
_value.inputClick = value;
_str = value->toString();
_type = type;
}

Common::String toString() {
char buf[128];

if (_value.obj == NULL)
_str = "";

switch(_type) {
case NUMBER:
_str = snprintf(buf, 128, "%d", _value.number);
return _str;
case STRING:
case TEXT_INPUT:
return *_value.string;
case OBJ:
return _value.obj->toString();
case CHR:
return _value.chr->toString();
case SCENE:
return _value.scene->toString();
case CLICK_INPUT:
return _value.inputClick->toString();
default:
error("Unhandled operand type: _type");
}
}
};

public:
Expand Down

0 comments on commit a2ac4ea

Please sign in to comment.