diff options
author | Strangerke | 2012-05-04 23:13:43 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-03-28 17:36:57 +0200 |
commit | 8d25611dcb8417dc874a444f077eed3459a76db1 (patch) | |
tree | a5f782eb0f840fdc4a6d84a1f2e7ed3f3abbe528 /engines | |
parent | 9fc6e8f370ded2e777dca5d1150ced02c82ae9b8 (diff) | |
download | scummvm-rg350-8d25611dcb8417dc874a444f077eed3459a76db1.tar.gz scummvm-rg350-8d25611dcb8417dc874a444f077eed3459a76db1.tar.bz2 scummvm-rg350-8d25611dcb8417dc874a444f077eed3459a76db1.zip |
LILLIPUT: Remove duplicated variable, introduce getCharacterVariablesPtr() to handle negative indexes used by menus
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lilliput/lilliput.cpp | 30 | ||||
-rw-r--r-- | engines/lilliput/lilliput.h | 5 | ||||
-rw-r--r-- | engines/lilliput/script.cpp | 28 | ||||
-rw-r--r-- | engines/lilliput/script.h | 3 |
4 files changed, 41 insertions, 25 deletions
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp index 3ccf2dd72e..95407cda7a 100644 --- a/engines/lilliput/lilliput.cpp +++ b/engines/lilliput/lilliput.cpp @@ -222,6 +222,10 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) for (int i = 0; i < 160; i++) _displayStringBuf[i] = 0; + for (int i = 0; i < 1400 + 3120; i++) { + _characterVariables_[i] = 0; + } + _currentCharacterVariables = NULL; _bufferIdeogram = NULL; _bufferMen = NULL; @@ -1825,12 +1829,13 @@ void LilliputEngine::sub12F37() { int index2 = 0; for (int i = 0; i < _numCharacters; i++) { - if (_characterVariables[index1] != 0 ) { - if (_characterVariables[index1] == 1) { - _characterVariables[index1] = 0; + byte *varPtr = getCharacterVariablesPtr(index1); + if (varPtr[0] != 0 ) { + if (varPtr[0] == 1) { + varPtr[0] = 0; } else { - --_characterVariables[index1]; - if (_characterVariables[index1] == 1) + --varPtr[0]; + if (varPtr[0] == 1) _scriptHandler->_characterScriptEnabled[index2] = 1; } } @@ -2443,7 +2448,7 @@ void LilliputEngine::loadRules() { _rulesBuffer2_14[j] = f.readByte(); for (int k = 0; k < 32; k++) - _characterVariables[(j * 32) + k] = f.readByte(); + _characterVariables_[(j * 32) + k] = f.readByte(); for (int k = 0; k < 32; k++) _rulesBuffer2_16[(j * 32) + k] = f.readByte(); @@ -2603,7 +2608,7 @@ void LilliputEngine::sub170EE(int index) { int var4 = _characterPositionY[index]; _currentScriptCharacterPosition = (((var2 >> 3) & 0xFF) << 8) + ((var4 >> 3) & 0xFF); - _currentCharacterVariables = &_characterVariables[_currentScriptCharacter * 32]; + _currentCharacterVariables = getCharacterVariablesPtr(_currentScriptCharacter * 32); } void LilliputEngine::sub130DD() { @@ -2677,7 +2682,7 @@ while(1);*/ //warning("dump char stat"); i = index; - debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], _characterVariables[i*32+0], _scriptHandler->_characterScriptEnabled[i]); + debugC(3, kDebugEngine, "char %d, pos %d %d, state %d, script enabled %d", i, _characterPositionX[i], _characterPositionY[i], *getCharacterVariablesPtr(i * 32 + 0), _scriptHandler->_characterScriptEnabled[i]); } Common::Error LilliputEngine::run() { @@ -2738,6 +2743,15 @@ void LilliputEngine::initialize() { } } +byte *LilliputEngine::getCharacterVariablesPtr(int16 index) { + debugC(1, kDebugEngine, "getCharacterVariablesPtr(%d)", index); + + if (index >= 0) + return &_characterVariables_[index]; + else + return &_characterVariables_[1400 - index]; +} + void LilliputEngine::syncSoundSettings() { Engine::syncSoundSettings(); diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h index 0bf211aee0..5f320d14fd 100644 --- a/engines/lilliput/lilliput.h +++ b/engines/lilliput/lilliput.h @@ -165,7 +165,7 @@ public: byte _rulesBuffer2_12[40]; byte _rulesBuffer2_13[40]; byte _rulesBuffer2_14[40]; - byte _characterVariables[40 * 32]; + byte _characterVariables_[1400 + 3120]; byte *_currentCharacterVariables; byte _rulesBuffer2_16[40 * 32]; int *_rulesChunk3; @@ -352,6 +352,9 @@ public: void setNextDisplayCharacter(int var1); void handleGameScripts(); + // Added by Strangerke + byte *getCharacterVariablesPtr(int16 index); + // Temporary stubs byte _keyboard_getch(); diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp index 9942f24d5e..75e1fd7da9 100644 --- a/engines/lilliput/script.cpp +++ b/engines/lilliput/script.cpp @@ -43,7 +43,6 @@ LilliputScript::LilliputScript(LilliputEngine *vm) : _vm(vm), _currScript(NULL) _word1855E = 0; _word16F00 = -1; _viewportCharacterTarget = -1; - _word10804 = 0; _heroismBarX = 0; _heroismBarBottomY = 0; _viewportX = 0; @@ -1275,10 +1274,10 @@ void LilliputScript::sub18B3C(int var) { sub18A56(&_vm->_rulesChunk4[index + count + i]); } -int LilliputScript::getValue1() { +int16 LilliputScript::getValue1() { debugC(2, kDebugScript, "getValue1()"); - int curWord = _currScript->readUint16LE(); + int16 curWord = _currScript->readUint16LE(); if (curWord < 1000) return curWord; @@ -1292,7 +1291,7 @@ int LilliputScript::getValue1() { case 1003: return (int)_vm->_currentCharacterVariables[6]; case 1004: - return _word10804; + return _vm->_word10804; default: warning("getValue1: Unexpected large value %d", curWord); return curWord; @@ -1369,12 +1368,13 @@ void LilliputScript::sub130B6() { byte *LilliputScript::getCharacterVariablePtr() { debugC(2, kDebugScript, "getCharacterVariablePtr()"); - int tmpVal = getValue1(); - tmpVal *= 32; - tmpVal += _currScript->readUint16LE(); + int8 tmpVal = (int8) (getValue1() & 0xFF); + int index = tmpVal * 32; + index += _currScript->readUint16LE(); + + assert(index < 1400); - assert(tmpVal < 40 * 32); - return &_vm->_characterVariables[tmpVal]; + return _vm->getCharacterVariablesPtr(index); } byte LilliputScript::OC_sub173DF() { @@ -1729,7 +1729,7 @@ byte LilliputScript::OC_compWord10804() { debugC(1, kDebugScript, "OC_compWord10804()"); byte tmpVal = getValue1(); - if (tmpVal == _word10804) + if (tmpVal == _vm->_word10804) return 1; return 0; @@ -1860,7 +1860,7 @@ byte LilliputScript::OC_sub1785C() { int count = 0; for (int i = 0; i < _vm->_numCharacters; i++) { - if (curByte == _vm->_characterVariables[(32 * i)]) + if (curByte == *_vm->getCharacterVariablesPtr(32 * i)) ++count; } @@ -2270,7 +2270,7 @@ void LilliputScript::OC_sub17A8D() { int tmpVal = getValue1(); assert(tmpVal < 40); - if (tmpVal == _word10804) + if (tmpVal == _vm->_word10804) _viewportCharacterTarget = 0xFFFF; _vm->_characterPositionX[tmpVal] = 0xFFFF; @@ -2389,7 +2389,7 @@ void LilliputScript::OC_sub17AEE() { void LilliputScript::OC_setWord10804() { debugC(1, kDebugScript, "OC_setWord10804()"); - _word10804 = getValue1(); + _vm->_word10804 = getValue1(); } void LilliputScript::OC_sub17C0E() { @@ -2982,7 +2982,7 @@ void LilliputScript::OC_sub17D04() { byte var1 = getValue1(); byte var2 = _currScript->readUint16LE() & 0xFF; - sub1823E(var1, var2, &_vm->_characterVariables[var1]); + sub1823E(var1, var2, _vm->getCharacterVariablesPtr(var1)); } void LilliputScript::OC_sub18387() { diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h index d39519e8b5..0c3c86ba8c 100644 --- a/engines/lilliput/script.h +++ b/engines/lilliput/script.h @@ -113,7 +113,6 @@ private: byte _byte1881D; int _word16F00; - int _word10804; int _word18776; int _word18821; @@ -140,7 +139,7 @@ private: int sub17285(int index); int sub18BB7(int index); - int getValue1(); + int16 getValue1(); int getValue2(); byte *getCharacterVariablePtr(); |