diff options
author | Strangerke | 2018-04-11 07:27:03 +0200 |
---|---|---|
committer | Strangerke | 2018-04-11 07:27:45 +0200 |
commit | 1a29932672553b5e7b7a01ddbb828098b05e808e (patch) | |
tree | 587889831e735cde442052eb10cf4ce7f26cff34 /engines/lilliput | |
parent | 701df47cae2885c5c68bd03c41d0dda70072668d (diff) | |
download | scummvm-rg350-1a29932672553b5e7b7a01ddbb828098b05e808e.tar.gz scummvm-rg350-1a29932672553b5e7b7a01ddbb828098b05e808e.tar.bz2 scummvm-rg350-1a29932672553b5e7b7a01ddbb828098b05e808e.zip |
LILLIPUT: some more rework related to the positions
Diffstat (limited to 'engines/lilliput')
-rw-r--r-- | engines/lilliput/lilliput.cpp | 118 | ||||
-rw-r--r-- | engines/lilliput/lilliput.h | 9 | ||||
-rw-r--r-- | engines/lilliput/script.cpp | 53 |
3 files changed, 74 insertions, 106 deletions
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp index 59bce8e2cf..c61c4c777c 100644 --- a/engines/lilliput/lilliput.cpp +++ b/engines/lilliput/lilliput.cpp @@ -184,8 +184,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) _specialCubes[i] = 0; _characterSignals[i] = -1; - _characterPositionX[i] = -1; - _characterPositionY[i] = -1; + _characterPos[i] = Common::Point(-1, -1); _characterPosAltitude[i] = 0; _characterFrameArray[i] = 0; _characterCarried[i] = -1; @@ -196,8 +195,7 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) _characterMobility[i] = 0; _characterTypes[i] = 0; _characterBehaviour[i] = 0; - _characterHomePosX[i] = 0; - _characterHomePosY[i] = 0; + _characterHomePos[i] = Common::Point(0, 0); _signalArr[i] = -1; } @@ -411,7 +409,7 @@ void LilliputEngine::displayInterfaceHotspots() { for (int index = 0; index < _interfaceHotspotNumb; index++) { int tmpVal = _scriptHandler->_interfaceHotspotStatus[index] * 20; - display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index])); + display16x16IndexedBuf(_bufferIdeogram, tmpVal + index, _interfaceHotspots[index]); } } @@ -604,43 +602,41 @@ void LilliputEngine::moveCharacters() { if (_characterCarried[i] != -1) { int index2 = _characterCarried[i]; _characterPosAltitude[i] = _characterPosAltitude[index2] + _characterAboveDist[i]; - int8 tmpVal = _characterBehindDist[i]; + int8 behindDist = _characterBehindDist[i]; _characterDirectionArray[i] = _characterDirectionArray[index2]; - int var3 = _characterPositionX[index2]; - int var4 = _characterPositionY[index2]; + int nextPosX = _characterPos[index2].x; + int nextPosY = _characterPos[index2].y; switch (_characterDirectionArray[i]) { case 0: - var3 -= tmpVal; + nextPosX -= behindDist; break; case 1: - var4 += tmpVal; + nextPosY += behindDist; break; case 2: - var4 -= tmpVal; + nextPosY -= behindDist; break; default: - var3 += tmpVal; + nextPosX += behindDist; break; } - _characterPositionX[i] = var3; - _characterPositionY[i] = var4; + _characterPos[i] = Common::Point(nextPosX, nextPosY); } - _scriptHandler->_characterTilePos[i] = Common::Point(_characterPositionX[i] >> 3, _characterPositionY[i] >> 3); + _scriptHandler->_characterTilePos[i] = Common::Point(_characterPos[i].x >> 3, _characterPos[i].y >> 3); _characterRelativePos[i] = Common::Point(-1, -1); _characterDisplay[i] = Common::Point(-1, -1); - int tmpVal2 = (_characterPositionX[i] >> 3) - _scriptHandler->_viewportPos.x; - int tmpVal3 = (_characterPositionY[i] >> 3) - _scriptHandler->_viewportPos.y; - if ((tmpVal2 >= 0) && (tmpVal2 <= 7) && (tmpVal3 >= 0) && (tmpVal3 <= 7)) { - _characterRelativePos[i] = Common::Point(tmpVal2, tmpVal3); - tmpVal2 = _characterPositionX[i] - pos16213.x; - tmpVal3 = _characterPositionY[i] - pos16213.y; - int tmpVal4 = _characterPosAltitude[i]; - _characterDisplay[i].x = ((60 + tmpVal2 - tmpVal3) * 2) & 0xFF; - _characterDisplay[i].y = (20 + tmpVal2 + tmpVal3 - tmpVal4) & 0xFF; + int tileX = (_characterPos[i].x >> 3) - _scriptHandler->_viewportPos.x; + int tileY = (_characterPos[i].y >> 3) - _scriptHandler->_viewportPos.y; + if ((tileX >= 0) && (tileX <= 7) && (tileY >= 0) && (tileY <= 7)) { + _characterRelativePos[i] = Common::Point(tileX, tileY); + int tempX = _characterPos[i].x - pos16213.x; + int tempY = _characterPos[i].y - pos16213.y; + _characterDisplay[i].x = ((60 + tempX - tempY) * 2) & 0xFF; + _characterDisplay[i].y = (20 + tempX + tempY - _characterPosAltitude[i]) & 0xFF; _charactersToDisplay[_numCharactersToDisplay] = i; ++_numCharactersToDisplay; } @@ -1127,34 +1123,23 @@ void LilliputEngine::scrollToViewportCharacterTarget() { if (_scriptHandler->_viewportCharacterTarget == -1) return; - int var2 = (_characterPositionX[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.x; - int var4 = (_characterPositionY[_scriptHandler->_viewportCharacterTarget] >> 3) - _scriptHandler->_viewportPos.y; + int tileX = (_characterPos[_scriptHandler->_viewportCharacterTarget].x >> 3) - _scriptHandler->_viewportPos.x; + int tileY = (_characterPos[_scriptHandler->_viewportCharacterTarget].y >> 3) - _scriptHandler->_viewportPos.y; Common::Point newPos = _scriptHandler->_viewportPos; - if (var2 >= 1) { - if (var2 > 6) { - newPos.x += 4; - if (newPos.x > 56) - newPos.x = 56; - } - } else { - newPos.x -= 4; - if (newPos.x < 0) - newPos.x = 0; - } + if (tileX >= 1) { + if (tileX > 6) + newPos.x = CLIP(newPos.x + 4, 0, 56); + } else + newPos.x = CLIP(newPos.x - 4, 0, 56); - if ((var4 < 1) && (newPos.y < 4)) + if ((tileY < 1) && (newPos.y < 4)) newPos.y = 0; - else { - if (var4 < 1) - newPos.y -= 4; - - if (var4 > 6) { - newPos.y += 4; - if (newPos.y >= 56) - newPos.y = 56; - } - } + else if (tileY >= 1) + newPos.y = CLIP(newPos.y + 4, 0, 56); + else + // CHECKME: not clipped? + newPos.y -= 4; viewportScrollTo(newPos); } @@ -1935,7 +1920,7 @@ void LilliputEngine::checkInterfaceHotspots(bool &forceReturnFl) { forceReturnFl = false; for (int index = _interfaceHotspotNumb - 1; index >= 0; index--) { - if (isMouseOverHotspot(_mousePos, Common::Point(_interfaceHotspotsX[index], _interfaceHotspotsY[index]))) { + if (isMouseOverHotspot(_mousePos, _interfaceHotspots[index])) { handleInterfaceHotspot(index, 1); forceReturnFl = true; return; @@ -2108,8 +2093,8 @@ void LilliputEngine::moveCharacterSpeed3(int index) { void LilliputEngine::moveCharacterForward(int index, int16 speed) { debugC(2, kDebugEngine, "moveCharacterForward(%d, %d)", index, speed); - int16 newX = _characterPositionX[index]; - int16 newY = _characterPositionY[index]; + int16 newX = _characterPos[index].x; + int16 newY = _characterPos[index].y; switch (_characterDirectionArray[index]) { case 0: newX += speed; @@ -2132,8 +2117,7 @@ void LilliputEngine::checkCollision(int index, Common::Point pos, int direction) int16 diffX = pos.x >> 3; if (((diffX & 0xFF) == _scriptHandler->_characterTilePos[index].x) && ((pos.y >> 3) == _scriptHandler->_characterTilePos[index].y)) { - _characterPositionX[index] = pos.x; - _characterPositionY[index] = pos.y; + _characterPos[index] = pos; return; } @@ -2159,8 +2143,7 @@ void LilliputEngine::checkCollision(int index, Common::Point pos, int direction) if ((var1 & _rulesChunk9[_bufferIsoMap[mapIndex]]) != 0) return; - _characterPositionX[index] = pos.x; - _characterPositionY[index] = pos.y; + _characterPos[index] = pos; } void LilliputEngine::signalDispatcher(byte type, byte index, int var4) { @@ -2472,12 +2455,12 @@ void LilliputEngine::loadRules() { curWord = f.readUint16LE(); if (curWord != 0xFFFF) curWord = (curWord << 3) + 4; - _characterPositionX[j] = curWord; + _characterPos[j].x = curWord; curWord = f.readUint16LE(); if (curWord != 0xFFFF) curWord = (curWord << 3) + 4; - _characterPositionY[j] = curWord; + _characterPos[j].y = curWord; _characterPosAltitude[j] = (f.readUint16LE() & 0xFF); _characterFrameArray[j] = f.readUint16LE(); @@ -2489,8 +2472,8 @@ void LilliputEngine::loadRules() { _characterMobility[j] = f.readByte(); _characterTypes[j] = f.readByte(); _characterBehaviour[j] = f.readByte(); - _characterHomePosX[j] = f.readByte(); - _characterHomePosY[j] = f.readByte(); + _characterHomePos[j].x = f.readByte(); + _characterHomePos[j].y = f.readByte(); for (int k = 0; k < 32; k++) _characterVariables[(j * 32) + k] = f.readByte(); @@ -2570,12 +2553,13 @@ void LilliputEngine::loadRules() { _rectXMinMax[i].min = (int16)f.readByte(); _rectYMinMax[i].max = (int16)f.readByte(); _rectYMinMax[i].min = (int16)f.readByte(); + int16 tmpValY = (int16)f.readByte(); int16 tmpValX = (int16)f.readByte(); _rulesBuffer12Pos3[i] = Common::Point(tmpValX, tmpValY); + tmpValY = (int16)f.readByte(); tmpValX = (int16)f.readByte(); - // _rulesBuffer12Pos4 is used by the into _portalPos[i] = Common::Point(tmpValX, tmpValY); } @@ -2585,10 +2569,10 @@ void LilliputEngine::loadRules() { _interfaceTwoStepAction[i] = f.readByte(); for (int i = 0 ; i < 20; i++) - _interfaceHotspotsX[i] = f.readSint16LE(); + _interfaceHotspots[i].x = f.readSint16LE(); for (int i = 0 ; i < 20; i++) - _interfaceHotspotsY[i] = f.readSint16LE(); + _interfaceHotspots[i].y = f.readSint16LE(); for (int i = 0; i < 20; i++) { byte curByte = f.readByte(); @@ -2609,8 +2593,6 @@ void LilliputEngine::loadRules() { } } f.close(); - - // Skipped: Load Savegame } void LilliputEngine::displayVGAFile(Common::String fileName) { @@ -2649,13 +2631,9 @@ void LilliputEngine::initPalette() { void LilliputEngine::setCurrentCharacter(int index) { debugC(1, kDebugEngine, "setCurrentCharacter(%d)", index); - _currentScriptCharacter = index; - assert(index < 40); - int posX = _characterPositionX[index]; - int posY = _characterPositionY[index]; - - _currentScriptCharacterPos = Common::Point(posX >> 3, posY >> 3); + _currentScriptCharacter = index; + _currentScriptCharacterPos = Common::Point(_characterPos[index].x >> 3, _characterPos[index].y >> 3); _currentCharacterAttributes = getCharacterAttributesPtr(_currentScriptCharacter * 32); } diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h index 58f6d6f504..069b9a0f00 100644 --- a/engines/lilliput/lilliput.h +++ b/engines/lilliput/lilliput.h @@ -166,8 +166,7 @@ public: byte *_rulesChunk1; int16 _currentScriptCharacter; - int16 _characterPositionX[40]; - int16 _characterPositionY[40]; + Common::Point _characterPos[40]; int8 _characterPosAltitude[40]; int16 _characterFrameArray[40]; int8 _characterCarried[40]; @@ -178,8 +177,7 @@ public: byte _characterMobility[40]; byte _characterTypes[40]; byte _characterBehaviour[40]; - byte _characterHomePosX[40]; - byte _characterHomePosY[40]; + Common::Point _characterHomePos[40]; byte _characterVariables[1400 + 3120]; byte *_currentCharacterAttributes; byte _poseArray[40 * 32]; @@ -204,8 +202,7 @@ public: Common::Point _portalPos[40]; int _interfaceHotspotNumb; byte _interfaceTwoStepAction[20]; - int16 _interfaceHotspotsX[20]; - int16 _interfaceHotspotsY[20]; + Common::Point _interfaceHotspots[20]; Common::KeyCode _keyboardMapping[20]; Common::Point _characterTargetPos[40]; byte _savedSurfaceUnderMouse[16 * 16]; diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp index 39b346ac12..d1426c3bcb 100644 --- a/engines/lilliput/script.cpp +++ b/engines/lilliput/script.cpp @@ -1297,27 +1297,27 @@ Common::Point LilliputScript::getPosFromScript() { switch(tmpVal) { case 0xFF: assert((_vm->_currentScriptCharacter >= 0) && (_vm->_currentScriptCharacter < 40)); - return Common::Point(_vm->_characterHomePosX[_vm->_currentScriptCharacter], _vm->_characterHomePosY[_vm->_currentScriptCharacter]); + return _vm->_characterHomePos[_vm->_currentScriptCharacter]; case 0xFE: { int8 index = curWord & 0xFF; assert((index >= 0) && (index < 40)); - return Common::Point(_vm->_characterHomePosX[index], _vm->_characterHomePosY[index]); + return _vm->_characterHomePos[index]; } case 0xFD: return _vm->_currentScriptCharacterPos; case 0xFC: { int8 index = curWord & 0xFF; assert((index >= 0) && (index < 40)); - int16 x = _vm->_characterPositionX[index] >> 3; - int16 y = _vm->_characterPositionY[index] >> 3; + int16 x = _vm->_characterPos[index].x >> 3; + int16 y = _vm->_characterPos[index].y >> 3; return Common::Point(x, y); } case 0xFB: { int index = _word16F00_characterId; assert((index >= 0) && (index < 40)); - int16 x = _vm->_characterPositionX[index] >> 3; - int16 y = _vm->_characterPositionY[index] >> 3; + int16 x = _vm->_characterPos[index].x >> 3; + int16 y = _vm->_characterPos[index].y >> 3; return Common::Point(x, y); } @@ -1333,10 +1333,7 @@ Common::Point LilliputScript::getPosFromScript() { case 0xF7: { int8 index = _vm->_currentCharacterAttributes[6]; assert((index >= 0) && (index < 40)); - int16 x = _vm->_characterPositionX[index] >> 3; - int16 y = _vm->_characterPositionY[index] >> 3; - - return Common::Point(x, y); + return Common::Point(_vm->_characterPos[index].x >> 3, _vm->_characterPos[index].y >> 3); } case 0xF6: return _vm->_savedMousePosDivided; @@ -1780,7 +1777,7 @@ byte LilliputScript::OC_IsCharacterValid() { debugC(1, kDebugScript, "OC_IsCharacterValid()"); int index = getValue1(); - if (_vm->_characterPositionX[index] == -1) + if (_vm->_characterPos[index].x == -1) return 0; return 1; @@ -2266,14 +2263,13 @@ void LilliputScript::OC_setCharacterPosition() { debugC(1, kDebugScript, "OC_setCharacterPosition()"); int index = getValue1(); + assert((index >= 0) && (index < 40)); Common::Point tmpVal = getPosFromScript(); - int var2 = (tmpVal.x << 3) + 4; - int var4 = (tmpVal.y << 3) + 4; + int charPosX = (tmpVal.x << 3) + 4; + int charPosY = (tmpVal.y << 3) + 4; - assert((index >= 0) && (index < 40)); - _vm->_characterPositionX[index] = var2; - _vm->_characterPositionY[index] = var4; + _vm->_characterPos[index] = Common::Point(charPosX, charPosY); } void LilliputScript::OC_DisableCharacter() { @@ -2285,8 +2281,7 @@ void LilliputScript::OC_DisableCharacter() { if (characterIndex == _vm->_host) _viewportCharacterTarget = -1; - _vm->_characterPositionX[characterIndex] = -1; - _vm->_characterPositionY[characterIndex] = -1; + _vm->_characterPos[characterIndex] = Common::Point(-1, -1); } void LilliputScript::OC_saveAndQuit() { @@ -2609,7 +2604,7 @@ void LilliputScript::OC_sub17EC5() { Common::Point LilliputScript::getCharacterTilePos(int index) { debugC(2, kDebugScript, "getCharacterTilePos(%d)", index); - return Common::Point(_vm->_characterPositionX[index] / 8, _vm->_characterPositionY[index] / 8); + return Common::Point(_vm->_characterPos[index].x >> 3, _vm->_characterPos[index].y >> 3); } void LilliputScript::OC_setCharacterDirectionTowardsPos() { @@ -2628,8 +2623,8 @@ void LilliputScript::OC_turnCharacterTowardsAnother() { static const byte _directionsArray[] = { 0, 2, 0, 1, 3, 2, 3, 1 }; - int dx = _vm->_characterPositionX[index] - _vm->_characterPositionX[_vm->_currentScriptCharacter]; - int dy = _vm->_characterPositionY[index] - _vm->_characterPositionY[_vm->_currentScriptCharacter]; + int dx = _vm->_characterPos[index].x - _vm->_characterPos[_vm->_currentScriptCharacter].x; + int dy = _vm->_characterPos[index].y - _vm->_characterPos[_vm->_currentScriptCharacter].y; int flag = 0; if (dx < 0) { @@ -2732,13 +2727,13 @@ void LilliputScript::OC_setCharacterProperties() { int16 index = getValue1(); - int16 x = _vm->_characterPositionX[index] & 0xFFF8; + int16 x = _vm->_characterPos[index].x & 0xFFF8; x += _currScript->readSint16LE(); - _vm->_characterPositionX[index] = x; + _vm->_characterPos[index].x = x; - int16 y = _vm->_characterPositionY[index] & 0xFFF8; + int16 y = _vm->_characterPos[index].y & 0xFFF8; y += _currScript->readSint16LE(); - _vm->_characterPositionY[index] = y; + _vm->_characterPos[index].y = y; _vm->_characterPosAltitude[index] = (int8)(_currScript->readUint16LE() & 0xFF); _vm->_characterDirectionArray[index] = _currScript->readUint16LE() & 0xFF; @@ -2943,8 +2938,8 @@ void LilliputScript::OC_spawnCharacterAtPos() { var4 = _word1825E; } - _vm->_characterPositionX[index] = (var4.x + _viewportPos.x) * 8; - _vm->_characterPositionY[index] = (var4.y + _viewportPos.y) * 8; + _vm->_characterPos[index].x = (var4.x + _viewportPos.x) * 8; + _vm->_characterPos[index].y = (var4.y + _viewportPos.y) * 8; } void LilliputScript::OC_CharacterVariableAddOrRemoveFlag() { @@ -3258,9 +3253,7 @@ void LilliputScript::OC_setCharacterHome() { debugC(1, kDebugScript, "OC_setCharacterHome()"); int index = getValue1(); - Common::Point pos = getPosFromScript(); - _vm->_characterHomePosX[index] = pos.x; - _vm->_characterHomePosY[index] = pos.y; + _vm->_characterHomePos[index] = getPosFromScript(); } void LilliputScript::OC_setViewPortCharacterTarget() { |