From d19e92fbb0a1b410645a7badc9a229082f1763c5 Mon Sep 17 00:00:00 2001 From: sylvaintv Date: Sat, 28 Apr 2012 02:59:43 +0200 Subject: LILLIPUT: Several opcodes & renaming Rename character related variables --- engines/lilliput/lilliput.cpp | 80 ++++++++++++++++++++----------------------- engines/lilliput/lilliput.h | 4 +-- engines/lilliput/script.cpp | 33 ++++++++++-------- engines/lilliput/script.h | 2 +- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp index 87864407c8..3e8f4d9f20 100644 --- a/engines/lilliput/lilliput.cpp +++ b/engines/lilliput/lilliput.cpp @@ -145,10 +145,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) _byte16552 = 0; _byte12FE4 = 0xFF; _byte12FE3 = 0; - _byte16F08 = 0; + _byte16F08 = 0; _rulesBuffer2PrevIndx = 0; - _word16EFA = 0; + _currentScriptCharacterPosition = 0; _word10804 = 0; _word17081_nextIndex = 0; _word16EFE = 0xFFFF; @@ -575,7 +575,7 @@ void LilliputEngine::restoreMapPoints() { displayFunction5(); byte *buf = (byte *)_mainSurface->getPixels(); - for (int index = 0; index < _word10807_ERULES; index++) { + for (int index = 0; index < _numCharacters; index++) { buf[_word15E5D[index]] = _byte15E35[index]; } @@ -587,7 +587,7 @@ void LilliputEngine::displayCharactersOnMap() { displayFunction5(); byte *buf = (byte *)_mainSurface->getPixels(); - for (int index = _word10807_ERULES - 1; index >=0; index--) { + for (int index = _numCharacters - 1; index >=0; index--) { if (((_rulesBuffer2_11[index] & 2) == 0) && (_scriptHandler->_array1614B[index] != -1)) { int y = (3 * _scriptHandler->_array1614B[index]) + 1; int x = (_scriptHandler->_array16123[index] * 4) + 1; @@ -604,7 +604,7 @@ void LilliputEngine::sub16217() { debugC(2, kDebugEngine, "sub16217()"); _numCharactersToDisplay = 0; - int index = _word10807_ERULES - 1; + int index = _numCharacters - 1; _word16213 = _scriptHandler->_viewportX << 3; _word16215 = _scriptHandler->_viewportY << 3; @@ -806,14 +806,14 @@ int LilliputEngine::sub16DD5(int x1, int y1, int x2, int y2) void LilliputEngine::sub16CA0() { debugC(2, kDebugEngine, "sub16CA0()"); - for (int index = _word10807_ERULES - 1; index >= 0; index--) { + for (int index = _numCharacters - 1; index >= 0; index--) { if (_rulesBuffer2_11[index] & 1) continue; int c1 = _scriptHandler->_array16123[index]; int c2 = _scriptHandler->_array1614B[index]; - for (int index2 = _word10807_ERULES - 1; index2 >= 0; index2--) { + for (int index2 = _numCharacters - 1; index2 >= 0; index2--) { _byte16C9F = 0; if ((index != index2 ) && (_rulesBuffer2_5[index] != index2) && @@ -884,7 +884,7 @@ void LilliputEngine::sub16CA0() { int val = _scriptHandler->_array10B51[index2 + index * 40]; val = (val & 0xFF) + ((val & 0xFF) << 8); if( (val & 0xFF) != _byte16C9F ) { - _scriptHandler->_array10B29[index] = 1; + _scriptHandler->_characterScriptEnabled[index] = 1; val = (val & 0xFF00) | _byte16C9F; } _scriptHandler->_array10B51[index2 + index * 40] = val; @@ -1106,11 +1106,11 @@ void LilliputEngine::renderCharacters(byte *buf, int x, int y) { void LilliputEngine::sub1546F(byte displayX, byte displayY) { debugC(2, kDebugEngine, "sub1546F(%d, %d)", displayX, displayY); - + int orgX = displayX + 8; int orgY = displayY; int var2 = 0; - + int x = orgX; int y = orgY; do { @@ -1118,10 +1118,10 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) { --x; y >>= 1; } while (y != 0); - + x = orgX + 1; y = orgY >> 1; - + while (y != 0) { sub15498(x, y, var2); ++x; @@ -1131,7 +1131,7 @@ void LilliputEngine::sub1546F(byte displayX, byte displayY) { void LilliputEngine::sub15498(byte x, byte y, int var2) { debugC(2, kDebugEngine, "sub15498(%d, %d, %d)", x, y, var2); - + int index = x + ((var2 & 0xFF) << 8) + (var2 >> 8); for (int i = 1 + y - var2; i > 0; i--) { _buffer1_45k[index] = 17; @@ -1248,7 +1248,7 @@ void LilliputEngine::prepareGoldAmount(int param1) { void LilliputEngine::sub16626() { debugC(2, kDebugEngine, "sub16626()"); - int index = _word10807_ERULES - 1; + int index = _numCharacters - 1; int result; while (index >= 0) { result = 2; @@ -1263,9 +1263,6 @@ void LilliputEngine::sub16626() { var2 = ((var1 >> 8) >> 3); var2 &= 0xFE; - // temporary hack - result = 0; - switch (var2 / 2) { case 0: result = sub16675(index, var1); @@ -1309,7 +1306,7 @@ void LilliputEngine::sub16626() { if (result & 1) { ++_scriptHandler->_array12811[index]; if (_scriptHandler->_array12811[index] == 16) - _scriptHandler->_array10B29[index] = 1; + _scriptHandler->_characterScriptEnabled[index] = 1; } } --index; @@ -1328,7 +1325,7 @@ void LilliputEngine::sub16EBC() { int index2 = 3; - for (int index1 = _word10807_ERULES - 1; index1 >= 0; index1--) { + for (int index1 = _numCharacters - 1; index1 >= 0; index1--) { int var2 = (_scriptHandler->_array1614B[index1] << 8) + (_scriptHandler->_array16123[index1] << 2); int var1 = (_bufferIsoMap[index2 + var2] & 0x40); @@ -1337,7 +1334,7 @@ void LilliputEngine::sub16EBC() { _array16E94[index1] = var1; if (var1 != 0) - _scriptHandler->_array10B29[index1] = 1; + _scriptHandler->_characterScriptEnabled[index1] = 1; } } @@ -1347,15 +1344,15 @@ void LilliputEngine::sub12F37() { int index1 = _byte12A04 + 2; int index2 = 0; - for (int i = 0; i < _word10807_ERULES; i++) { + for (int i = 0; i < _numCharacters; i++) { if (_rulesBuffer2_15[index1] != 0 ) { if (_rulesBuffer2_15[index1] == 1) { _rulesBuffer2_15[index1] = 0; } else { --_rulesBuffer2_15[index1]; if (_rulesBuffer2_15[index1] == 1) - _scriptHandler->_array10B29[index2] = 1; - } + _scriptHandler->_characterScriptEnabled[index2] = 1; + } } index1 += 32; @@ -1429,7 +1426,7 @@ void LilliputEngine::sub131B2(int var2, int var4, bool &forceReturnFl) { forceReturnFl = false; - for (int i = 0; i < _word10807_ERULES; i++) { + for (int i = 0; i < _numCharacters; i++) { if ((var2 >= _characterDisplayX[i]) && (var2 <= _characterDisplayX[i] + 17) && (var4 >= _characterDisplayY[i]) && (var4 <= _characterDisplayY[i] + 17) && (i != _word10804)) { _byte129A0 = i; _byte16F07_menuId = 4; @@ -1564,11 +1561,11 @@ int LilliputEngine::sub16675(int idx, int var1) { void LilliputEngine::sub171CF() { debugC(2, kDebugEngine, "sub171CF()"); - for (int i = 0; i < _word10807_ERULES; i++) { + for (int i = 0; i < _numCharacters; i++) { if (_array1289F[i] != 0xFFFF) { _array11D49[i] = _array1289F[i]; _array1289F[i] = 0xFFFF; - _scriptHandler->_array10B29[i] = 1; + _scriptHandler->_characterScriptEnabled[i] = 1; } } @@ -1628,7 +1625,7 @@ void LilliputEngine::displayHeroismIndicator() { } _scriptHandler->_heroismLevel += var2; - + int index = _scriptHandler->_heroismBarX + _scriptHandler->_heroismBarBottomY * 320 ; var2 = _scriptHandler->_heroismLevel & 0xFF; @@ -1788,10 +1785,10 @@ void LilliputEngine::loadRules() { _rulesChunk1[i] = f.readByte(); // Chunk 2 - _word10807_ERULES = f.readSint16LE(); - assert(_word10807_ERULES <= 40); + _numCharacters = f.readSint16LE(); + assert(_numCharacters <= 40); - for (int i = _word10807_ERULES, j = 0; i != 0; i--, j++) { + for (int i = _numCharacters, j = 0; i != 0; i--, j++) { curWord = f.readUint16LE(); if (curWord != 0xFFFF) curWord = (curWord << 3) + 4; @@ -1975,7 +1972,7 @@ void LilliputEngine::sub170EE(int index) { int var2 = _characterPositionX[index]; int var4 = _characterPositionY[index]; - _word16EFA = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF); + _currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF); _ptr_rulesBuffer2_15 = &_rulesBuffer2_15[_rulesBuffer2PrevIndx * 32]; } @@ -2008,35 +2005,34 @@ void LilliputEngine::handleGameScripts() { int index = _word17081_nextIndex; int i; - for (i = 0; (_scriptHandler->_array10B29[index] == 0) && (i < _word10807_ERULES); i++) { + for (i = 0; (_scriptHandler->_characterScriptEnabled[index] == 0) && (i < _numCharacters); i++) { ++index; - if (index >= _word10807_ERULES) + if (index >= _numCharacters) index = 0; } - if (i > _word10807_ERULES) + if (i > _numCharacters) return; - _scriptHandler->_array10B29[index] = 0; - int tmpVal = index + 1; - if (tmpVal >= _word10807_ERULES) - tmpVal = 0; + _word17081_nextIndex = (index + 1) % _numCharacters; + - _word17081_nextIndex = tmpVal; + _scriptHandler->_characterScriptEnabled[index] = 0; sub170EE(index); _word16EFE = _array11D49[index]; _array11D49[index] = 0xFFFF; _word1817B = 0; - tmpVal = _rulesBuffer2_12[index]; + int tmpVal = _rulesBuffer2_12[index]; if (tmpVal == 0xFF) return; assert(tmpVal < _gameScriptIndexSize); - debugC(1, kDebugEngine, "========================== Game Script %d ==========================", tmpVal); - + debugC(1, kDebugEngine, "================= Game Script %d for character %d ==================", tmpVal, index); _scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal])); + debugC(1, kDebugEngine, "============= End Game Script %d for character %d ==================", tmpVal, index); + } Common::Error LilliputEngine::run() { diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h index ddcbfbe526..d49385d855 100644 --- a/engines/lilliput/lilliput.h +++ b/engines/lilliput/lilliput.h @@ -125,8 +125,8 @@ public: bool _int8installed; int _word10800_ERULES; - int _word10807_ERULES; - int _word16EFA; + int _numCharacters; + int _currentScriptCharacterPosition; int _word17081_nextIndex; int _word16EFE; int _word1817B; diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp index 1b75bd4a18..833fb14e03 100644 --- a/engines/lilliput/script.cpp +++ b/engines/lilliput/script.cpp @@ -58,7 +58,7 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) _array1813B[i] = 0; for (int i = 0; i < 40; i++) { - _array10B29[i] = 1; + _characterScriptEnabled[i] = 1; _array128EF[i] = 15; _array10AB1[i] = 0; _array12811[i] = 16; @@ -702,7 +702,7 @@ void LilliputScript::sub1823E(byte var1, byte var2, byte *curBufPtr) { debugC(1, kDebugScript, "sub1823E(%d, %d, curBufPtr)", var1, var2); assert ((var1 >= 0) && (var1 < 40)); - _array10B29[var1] = 1; + _characterScriptEnabled[var1] = 1; curBufPtr[0] = var2; curBufPtr[1] = 0; curBufPtr[2] = 0; @@ -844,7 +844,7 @@ int LilliputScript::getValue2() { return ((_vm->_rulesBuffer2_13[index] << 8) + _vm->_rulesBuffer2_14[index]); } case 0xFD: - return _vm->_word16EFA; + return _vm->_currentScriptCharacterPosition; case 0xFC: { int index = curWord & 0xFF; assert(index < 40); @@ -908,7 +908,10 @@ byte *LilliputScript::getBuffer215Ptr() { } byte LilliputScript::OC_sub173DF() { - warning("OC_sub173DF"); + debugC(2, kDebugScript, "OC_sub173F0()"); + if (_vm->_currentScriptCharacterPosition == getValue2()) { + return 1; + } return 0; } @@ -935,7 +938,7 @@ byte* LilliputScript::sub17399(int val) { byte LilliputScript::OC_sub1740A() { debugC(1, kDebugScript, "OC_sub1740A()"); - int var = _vm->_word16EFA; + int var = _vm->_currentScriptCharacterPosition; if (var == 0xFFFF) { _currScript->readUint16LE(); return 0; @@ -1028,7 +1031,7 @@ byte LilliputScript::OC_sub174D8() { if (curWord == 3000) { int index; - for (index = 0; index < _vm->_word10807_ERULES; index++) { + for (index = 0; index < _vm->_numCharacters; index++) { if (_vm->_rulesBuffer2_5[index] == tmpVal) { _word16F00 = index; return 1; @@ -1060,7 +1063,7 @@ byte LilliputScript::OC_compareCoords_1() { int var3 = _vm->_rulesBuffer12_1[index]; int var4 = _vm->_rulesBuffer12_2[index]; - int var1 = _vm->_word16EFA; + int var1 = _vm->_currentScriptCharacterPosition; if (((var1 >> 8) < (var3 >> 8)) || ((var1 >> 8) > (var3 & 0xFF)) || ((var1 & 0xFF) < (var4 >> 8)) || ((var1 & 0xFF) > (var4 & 0xFF))) return 0; @@ -1109,7 +1112,7 @@ byte LilliputScript::OC_sub175C8() { } if (tmpVal == 3000) { - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i]; if ((var1 & 0xFF) >= var4) { _word16F00 = i; @@ -1121,7 +1124,7 @@ byte LilliputScript::OC_sub175C8() { tmpVal -= 2000; byte var4b = tmpVal & 0xFF; - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i]; if ((var1 & 0xFF) >= var4) { if (_vm->_rulesBuffer2_12[i] == var4b) { @@ -1148,7 +1151,7 @@ byte LilliputScript::OC_sub17640() { if (var1 == 3000) { subIndex = 0; - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { tmpVal = _array10B51[index + i]; byte v1 = tmpVal & 0xFF; byte v2 = tmpVal >> 8; @@ -1161,7 +1164,7 @@ byte LilliputScript::OC_sub17640() { } else { var1 -= 2000; var4 &= ((var1 & 0xFF) << 8); - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { tmpVal = _array10B51[index + i]; byte v1 = tmpVal & 0xFF; byte v2 = tmpVal >> 8; @@ -1204,7 +1207,7 @@ byte LilliputScript::OC_sub176C4() { } if (tmpVal == 3000) { - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i]; if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) { _word16F00 = i; @@ -1216,7 +1219,7 @@ byte LilliputScript::OC_sub176C4() { tmpVal -= 2000; byte var4b = tmpVal & 0xFF; - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { int var1 = _array10B51[(_vm->_rulesBuffer2PrevIndx * 40) + i]; if (((var1 & 0xFF) < var4) && ((var1 >> 8) >= var4)) { if (_vm->_rulesBuffer2_12[i] == var4b) { @@ -1352,7 +1355,7 @@ byte LilliputScript::OC_sub1785C() { byte curByte = (_currScript->readUint16LE() & 0xFF); int count = 0; - for (int i = 0; i < _vm->_word10807_ERULES; i++) { + for (int i = 0; i < _vm->_numCharacters; i++) { if (curByte == _vm->_rulesBuffer2_15[(32 * i)]) ++count; } @@ -1451,7 +1454,7 @@ byte LilliputScript::OC_sub1792A() { byte LilliputScript::OC_sub1793E() { debugC(1, kDebugScript, "OC_sub1793E()"); - if (_vm->_word16EFA == 0xFFFF) + if (_vm->_currentScriptCharacterPosition == 0xFFFF) return 0; if (_vm->_array16E94[_vm->_rulesBuffer2PrevIndx] == 0) diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h index 4d7f5e9843..29ba6b2496 100644 --- a/engines/lilliput/script.h +++ b/engines/lilliput/script.h @@ -39,7 +39,7 @@ public: byte _byte12A04; byte _heroismLevel; - byte _array10B29[40]; + byte _characterScriptEnabled[40]; byte _array122E9[20]; byte _array16123[40]; byte _array1614B[40]; -- cgit v1.2.3