aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEugene Sandulenko2015-12-22 00:32:57 +0100
committerEugene Sandulenko2015-12-27 15:40:59 +0100
commit423d3642960e2187d90eae17b5ce0115b2219c48 (patch)
treea73c8d3e08f8e77f937c07b17d2987a1ab1f4d23 /engines
parentc40b5a30c035729b953979e709e5b35a8d1b5b63 (diff)
downloadscummvm-rg350-423d3642960e2187d90eae17b5ce0115b2219c48.tar.gz
scummvm-rg350-423d3642960e2187d90eae17b5ce0115b2219c48.tar.bz2
scummvm-rg350-423d3642960e2187d90eae17b5ce0115b2219c48.zip
WAGE: Implemented processLet()
Diffstat (limited to 'engines')
-rw-r--r--engines/wage/script.cpp192
-rw-r--r--engines/wage/script.h3
2 files changed, 173 insertions, 22 deletions
diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp
index 19de26e9a2..0c550da426 100644
--- a/engines/wage/script.cpp
+++ b/engines/wage/script.cpp
@@ -190,6 +190,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Script::Operand *Script::readOperand() {
byte operandType = _data->readByte();
+ Context *cont = &_world->_player->_context;
switch (operandType) {
case 0xA0: // TEXT$
return new Operand(_inputText, Operand::TEXT_INPUT);
@@ -210,7 +211,7 @@ Script::Operand *Script::readOperand() {
case 0xC6: // RANDOMOBJ@
return new Operand(_world->_orderedObjs[_callbacks->_rnd->getRandomNumber(_world->_orderedObjs.size())], Operand::OBJ);
case 0xB0: // VISITS#
- return new Operand(_world->_player->_context._visits, Operand::NUMBER);
+ return new Operand(cont->_visits, Operand::NUMBER);
case 0xB1: // RANDOM# for Star Trek, but VISITS# for some other games?
return new Operand(1 + _callbacks->_rnd->getRandomNumber(100), Operand::NUMBER);
case 0xB5: // RANDOM# // A random number between 1 and 100.
@@ -218,55 +219,55 @@ Script::Operand *Script::readOperand() {
case 0xB2: // LOOP#
return new Operand(_loopCount, Operand::NUMBER);
case 0xB3: // VICTORY#
- return new Operand(_world->_player->_context._kills, Operand::NUMBER);
+ return new Operand(cont->_kills, Operand::NUMBER);
case 0xB4: // BADCOPY#
return new Operand(0, Operand::NUMBER); // ????
case 0xFF:
{
// user variable
- int value = _data->readByte();
+ int value = _data->readSByte();
if (value < 0)
value += 256;
// TODO: Verify that we're using the right index.
- return new Operand(_world->_player->_context._userVariables[value], Operand::NUMBER);
+ return new Operand(cont->_userVariables[value - 1], Operand::NUMBER);
}
case 0xD0:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_STR_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_STR_BAS], Operand::NUMBER);
case 0xD1:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_HIT_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_HIT_BAS], Operand::NUMBER);
case 0xD2:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_ARM_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_ARM_BAS], Operand::NUMBER);
case 0xD3:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_ACC_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_ACC_BAS], Operand::NUMBER);
case 0xD4:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_STR_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_STR_BAS], Operand::NUMBER);
case 0xD5:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_HIT_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_HIT_BAS], Operand::NUMBER);
case 0xD6:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_ARM_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_ARM_BAS], Operand::NUMBER);
case 0xD7:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_ACC_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_ACC_BAS], Operand::NUMBER);
case 0xD8:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_SPE_BAS], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_SPE_BAS], Operand::NUMBER);
case 0xE0:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_STR_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_STR_CUR], Operand::NUMBER);
case 0xE1:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_HIT_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_HIT_CUR], Operand::NUMBER);
case 0xE2:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_ARM_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_ARM_CUR], Operand::NUMBER);
case 0xE3:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_ACC_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_ACC_CUR], Operand::NUMBER);
case 0xE4:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_STR_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_STR_CUR], Operand::NUMBER);
case 0xE5:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_HIT_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_HIT_CUR], Operand::NUMBER);
case 0xE6:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_ARM_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_ARM_CUR], Operand::NUMBER);
case 0xE7:
- return new Operand(_world->_player->_context._statVariables[Context::SPIR_ACC_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::SPIR_ACC_CUR], Operand::NUMBER);
case 0xE8:
- return new Operand(_world->_player->_context._statVariables[Context::PHYS_SPE_CUR], Operand::NUMBER);
+ return new Operand(cont->_statVariables[Context::PHYS_SPE_CUR], Operand::NUMBER);
default:
if (operandType >= 0x20 && operandType < 0x80) {
return readStringOperand();
@@ -277,6 +278,77 @@ Script::Operand *Script::readOperand() {
}
}
+void Script::assign(byte operandType, int uservar, uint16 value) {
+ Context *cont = &_world->_player->_context;
+
+ switch (operandType) {
+ case 0xFF:
+ {
+ // user variable
+ if (uservar < 0)
+ uservar += 256;
+
+ cont->_userVariables[uservar - 1] = value;
+ }
+ case 0xD0:
+ cont->_statVariables[Context::PHYS_STR_BAS] = value;
+ break;
+ case 0xD1:
+ cont->_statVariables[Context::PHYS_HIT_BAS] = value;
+ break;
+ case 0xD2:
+ cont->_statVariables[Context::PHYS_ARM_BAS] = value;
+ break;
+ case 0xD3:
+ cont->_statVariables[Context::PHYS_ACC_BAS] = value;
+ break;
+ case 0xD4:
+ cont->_statVariables[Context::SPIR_STR_BAS] = value;
+ break;
+ case 0xD5:
+ cont->_statVariables[Context::SPIR_HIT_BAS] = value;
+ break;
+ case 0xD6:
+ cont->_statVariables[Context::SPIR_ARM_BAS] = value;
+ break;
+ case 0xD7:
+ cont->_statVariables[Context::SPIR_ACC_BAS] = value;
+ break;
+ case 0xD8:
+ cont->_statVariables[Context::PHYS_SPE_BAS] = value;
+ break;
+ case 0xE0:
+ cont->_statVariables[Context::PHYS_STR_CUR] = value;
+ break;
+ case 0xE1:
+ cont->_statVariables[Context::PHYS_HIT_CUR] = value;
+ break;
+ case 0xE2:
+ cont->_statVariables[Context::PHYS_ARM_CUR] = value;
+ break;
+ case 0xE3:
+ cont->_statVariables[Context::PHYS_ACC_CUR] = value;
+ break;
+ case 0xE4:
+ cont->_statVariables[Context::SPIR_STR_CUR] = value;
+ break;
+ case 0xE5:
+ cont->_statVariables[Context::SPIR_HIT_CUR] = value;
+ break;
+ case 0xE6:
+ cont->_statVariables[Context::SPIR_ARM_CUR] = value;
+ break;
+ case 0xE7:
+ cont->_statVariables[Context::SPIR_ACC_CUR] = value;
+ break;
+ case 0xE8:
+ cont->_statVariables[Context::PHYS_SPE_CUR] = value;
+ break;
+ default:
+ debug("No idea what I'm supposed to assign! (%x at %d)!\n", operandType, _data->pos()-1);
+ }
+}
+
Script::Operand *Script::readStringOperand() {
String *sb;
bool allDigits = true;
@@ -304,13 +376,78 @@ Script::Operand *Script::readStringOperand() {
}
}
+const char *Script::readOperator() {
+ byte cmd = _data->readByte();
+
+ switch (cmd) {
+ case 0x81:
+ return "=";
+ case 0x82:
+ return "<";
+ case 0x83:
+ return ">";
+ case 0x8f:
+ return "+";
+ case 0x90:
+ return "-";
+ case 0x91:
+ return "*";
+ case 0x92:
+ return "/";
+ case 0x93:
+ return "==";
+ case 0x94:
+ return ">>";
+ case 0xfd:
+ return ";";
+ default:
+ warning("UNKNOWN OP %x", cmd);
+ }
+ return NULL;
+}
+
void Script::processIf() {
+ warning("STUB: processIf");
}
void Script::processMove() {
+ warning("STUB: processMove");
}
void Script::processLet() {
+ const char *lastOp = NULL;
+ int16 result = 0;
+ int operandType = _data->readByte();
+ int uservar = 0;
+
+ if (operandType == 0xff)
+ uservar = _data->readSByte();
+
+ _data->readByte(); // skip "=" operator
+ do {
+ Operand *operand = readOperand();
+ // TODO assert that value is NUMBER
+ int16 value = operand->_value.number;
+ if (lastOp != NULL) {
+ if (lastOp[0] == '+')
+ result += value;
+ else if (lastOp[0] == '-')
+ result -= value;
+ else if (lastOp[0] == '/')
+ result = (int16)(value == 0 ? 0 : result / value);
+ else if (lastOp[0] == '*')
+ result *= value;
+ } else {
+ result = value;
+ }
+ lastOp = readOperator();
+
+ if (lastOp[0] == ';')
+ break;
+ } while (true);
+ //System.out.println("processLet " + buildStringFromOffset(oldIndex - 1, index - oldIndex + 1) + "}");
+
+ assign(operandType, uservar, result);
}
void Script::appendText(String str) {
@@ -319,36 +456,47 @@ void Script::appendText(String str) {
}
void Script::handleMoveCommand(Scene::Directions dir, const char *dirName) {
+ warning("STUB: handleMoveCommand");
}
void Script::handleLookCommand() {
+ warning("STUB: handleLookCommand");
}
void Script::handleInventoryCommand() {
+ warning("STUB: handleInventoryCommand");
}
void Script::handleStatusCommand() {
+ warning("STUB: handleStatusCommand");
}
void Script::handleRestCommand() {
+ warning("STUB: handleRestCommand");
}
void Script::handleAcceptCommand() {
+ warning("STUB: handleAcceptCommand");
}
void Script::handleTakeCommand(const char *target) {
+ warning("STUB: handleTakeCommand");
}
void Script::handleDropCommand(const char *target) {
+ warning("STUB: handleDropCommand");
}
void Script::handleAimCommand(const char *target) {
+ warning("STUB: handleAimCommand");
}
void Script::handleWearCommand(const char *target) {
+ warning("STUB: handleWearCommand");
}
void Script::handleOfferCommand(const char *target) {
+ warning("STUB: handleOfferCommand");
}
} // End of namespace Wage
diff --git a/engines/wage/script.h b/engines/wage/script.h
index 5d5f9ef7e2..f99e6d91f0 100644
--- a/engines/wage/script.h
+++ b/engines/wage/script.h
@@ -130,10 +130,13 @@ private:
bool execute(World *world, int loopCount, String *inputText, Designed *inputClick, WageEngine *callbacks);
Operand *readOperand();
Operand *readStringOperand();
+ const char *readOperator();
void processIf();
void processMove();
void processLet();
+ void assign(byte operandType, int uservar, uint16 value);
+
void appendText(String str);
void handleMoveCommand(Scene::Directions dir, const char *dirName);
void handleLookCommand();