From 8b618e46df21d90a1a5ad62633a2b9d3c1da0317 Mon Sep 17 00:00:00 2001 From: athrxx Date: Sun, 11 Dec 2011 12:29:09 +0100 Subject: KYRA: (EOB/LOL) - cleanup common code (rename some stuff and move EOB/LOL common code to separate files) --- engines/kyra/scene_eob.cpp | 598 +-------------------------------------------- 1 file changed, 7 insertions(+), 591 deletions(-) (limited to 'engines/kyra/scene_eob.cpp') diff --git a/engines/kyra/scene_eob.cpp b/engines/kyra/scene_eob.cpp index e2a2e794ff..1927df79c1 100644 --- a/engines/kyra/scene_eob.cpp +++ b/engines/kyra/scene_eob.cpp @@ -20,7 +20,7 @@ * */ -#if defined(ENABLE_EOB) || defined(ENABLE_LOL) +#ifdef ENABLE_EOB #include "kyra/eobcommon.h" #include "kyra/resource.h" @@ -30,590 +30,6 @@ #include "common/system.h" -namespace Kyra { - -void LolEobBaseEngine::setLevelShapesDim(int index, int16 &x1, int16 &x2, int dim) { - if (_lvlShapeLeftRight[index << 1] == -1) { - x1 = 0; - x2 = 22; - - int16 y1 = 0; - int16 y2 = 120; - - int m = index * 18; - - for (int i = 0; i < 18; i++) { - uint8 d = _visibleBlocks[i]->walls[_sceneDrawVarDown]; - uint8 a = _wllWallFlags[d]; - - if (a & 8) { - int t = _dscDim2[(m + i) << 1]; - - if (t > x1) { - x1 = t; - if (!(a & 0x10)) - scaleLevelShapesDim(index, y1, y2, -1); - } - - t = _dscDim2[((m + i) << 1) + 1]; - - if (t < x2) { - x2 = t; - if (!(a & 0x10)) - scaleLevelShapesDim(index, y1, y2, -1); - } - } else { - int t = _dscDim1[m + i]; - - if (!_wllVmpMap[d] || t == -40) - continue; - - if (t == -41) { - x1 = 22; - x2 = 0; - break; - } - - if (t > 0 && x2 > t) - x2 = t; - - if (t < 0 && x1 < -t) - x1 = -t; - } - - if (x2 < x1) - break; - } - - x1 += (_sceneXoffset >> 3); - x2 += (_sceneXoffset >> 3); - - - _lvlShapeTop[index] = y1; - _lvlShapeBottom[index] = y2; - _lvlShapeLeftRight[index << 1] = x1; - _lvlShapeLeftRight[(index << 1) + 1] = x2; - } else { - x1 = _lvlShapeLeftRight[index << 1]; - x2 = _lvlShapeLeftRight[(index << 1) + 1]; - } - - drawLevelModifyScreenDim(dim, x1, 0, x2, 15); -} - -void LolEobBaseEngine::scaleLevelShapesDim(int index, int16 &y1, int16 &y2, int dim) { - static const int8 dscY1[] = { 0x1E, 0x18, 0x10, 0x00 }; - static const int8 dscY2[] = { 0x3B, 0x47, 0x56, 0x78 }; - - uint8 a = _dscDimMap[index]; - - if (dim == -1 && a != 3) - a++; - - y1 = dscY1[a]; - y2 = dscY2[a]; - - if (dim == -1) - return; - - const ScreenDim *cDim = screen()->getScreenDim(dim); - - screen()->modifyScreenDim(dim, cDim->sx, y1, cDim->w, y2 - y1); -} - -void LolEobBaseEngine::drawLevelModifyScreenDim(int dim, int16 x1, int16 y1, int16 x2, int16 y2) { - screen()->modifyScreenDim(dim, x1, y1 << 3, x2 - x1, (y2 - y1) << 3); -} - -void LolEobBaseEngine::generateBlockDrawingBuffer() { - _sceneDrawVarDown = _dscBlockMap[_currentDirection]; - _sceneDrawVarRight = _dscBlockMap[_currentDirection + 4]; - _sceneDrawVarLeft = _dscBlockMap[_currentDirection + 8]; - - /******************************************* - * _visibleBlocks map * - * * - * | | | | | | * - * 00 | 01 | 02 | 03 | 04 | 05 | 06 * - * ____|_____|_____|_____|_____|_____|_____ * - * | | | | | | * - * | 07 | 08 | 09 | 10 | 11 | * - * |_____|_____|_____|_____|_____| * - * | | | | * - * | 12 | 13 | 14 | * - * |_____|_____|_____| * - * | | * - * 15 | 16 | 17 * - * | (P) | * - ********************************************/ - - memset(_blockDrawingBuffer, 0, 660 * sizeof(uint16)); - - _wllProcessFlag = ((_currentBlock >> 5) + (_currentBlock & 0x1f) + _currentDirection) & 1; - - if (_wllProcessFlag) // floor and ceiling - generateVmpTileDataFlipped(0, 15, 1, -330, 22, 15); - else - generateVmpTileData(0, 15, 1, -330, 22, 15); - - assignVisibleBlocks(_currentBlock, _currentDirection); - - uint8 t = _visibleBlocks[0]->walls[_sceneDrawVarRight]; - if (t) - generateVmpTileData(-2, 3, t, 102, 3, 5); - - t = _visibleBlocks[6]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileDataFlipped(21, 3, t, 102, 3, 5); - - t = _visibleBlocks[1]->walls[_sceneDrawVarRight]; - uint8 t2 = _visibleBlocks[2]->walls[_sceneDrawVarDown]; - - if (hasWall(t) && !(_wllWallFlags[t2] & 8)) - generateVmpTileData(2, 3, t, 102, 3, 5); - else if (t && (_wllWallFlags[t2] & 8)) - generateVmpTileData(2, 3, t2, 102, 3, 5); - - t = _visibleBlocks[5]->walls[_sceneDrawVarLeft]; - t2 = _visibleBlocks[4]->walls[_sceneDrawVarDown]; - - if (hasWall(t) && !(_wllWallFlags[t2] & 8)) - generateVmpTileDataFlipped(17, 3, t, 102, 3, 5); - else if (t && (_wllWallFlags[t2] & 8)) - generateVmpTileDataFlipped(17, 3, t2, 102, 3, 5); - - t = _visibleBlocks[2]->walls[_sceneDrawVarRight]; - if (t) - generateVmpTileData(8, 3, t, 97, 1, 5); - - t = _visibleBlocks[4]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileDataFlipped(13, 3, t, 97, 1, 5); - - t = _visibleBlocks[1]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(-4, 3, t, 129, 6, 5); - - t = _visibleBlocks[5]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(20, 3, t, 129, 6, 5); - - t = _visibleBlocks[2]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(2, 3, t, 129, 6, 5); - - t = _visibleBlocks[4]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(14, 3, t, 129, 6, 5); - - t = _visibleBlocks[3]->walls[_sceneDrawVarDown]; - if (t) - generateVmpTileData(8, 3, t, 129, 6, 5); - - t = _visibleBlocks[7]->walls[_sceneDrawVarRight]; - if (t) - generateVmpTileData(0, 3, t, 117, 2, 6); - - t = _visibleBlocks[11]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileDataFlipped(20, 3, t, 117, 2, 6); - - t = _visibleBlocks[8]->walls[_sceneDrawVarRight]; - if (t) - generateVmpTileData(6, 2, t, 81, 2, 8); - - t = _visibleBlocks[10]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileDataFlipped(14, 2, t, 81, 2, 8); - - t = _visibleBlocks[8]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(-4, 2, t, 159, 10, 8); - - t = _visibleBlocks[10]->walls[_sceneDrawVarDown]; - if (hasWall(t)) - generateVmpTileData(16, 2, t, 159, 10, 8); - - t = _visibleBlocks[9]->walls[_sceneDrawVarDown]; - if (t) - generateVmpTileData(6, 2, t, 159, 10, 8); - - t = _visibleBlocks[12]->walls[_sceneDrawVarRight]; - if (t) - generateVmpTileData(3, 1, t, 45, 3, 12); - - t = _visibleBlocks[14]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileDataFlipped(16, 1, t, 45, 3, 12); - - t = _visibleBlocks[12]->walls[_sceneDrawVarDown]; - if (!(_wllWallFlags[t] & 8)) - generateVmpTileData(-13, 1, t, 239, 16, 12); - - t = _visibleBlocks[14]->walls[_sceneDrawVarDown]; - if (!(_wllWallFlags[t] & 8)) - generateVmpTileData(19, 1, t, 239, 16, 12); - - t = _visibleBlocks[13]->walls[_sceneDrawVarDown]; - if (t) - generateVmpTileData(3, 1, t, 239, 16, 12); - - t = _visibleBlocks[15]->walls[_sceneDrawVarRight]; - t2 = _visibleBlocks[17]->walls[_sceneDrawVarLeft]; - if (t) - generateVmpTileData(0, 0, t, 0, 3, 15); - if (t2) - generateVmpTileDataFlipped(19, 0, t2, 0, 3, 15); -} - -void LolEobBaseEngine::generateVmpTileData(int16 startBlockX, uint8 startBlockY, uint8 vmpMapIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY) { - if (!_wllVmpMap[vmpMapIndex]) - return; - - uint16 *vmp = &_vmpPtr[(_wllVmpMap[vmpMapIndex] - 1) * 431 + vmpOffset + 330]; - - for (int i = 0; i < numBlocksY; i++) { - uint16 *bl = &_blockDrawingBuffer[(startBlockY + i) * 22 + startBlockX]; - for (int ii = 0; ii < numBlocksX; ii++) { - if ((startBlockX + ii >= 0) && (startBlockX + ii < 22) && *vmp) - *bl = *vmp; - bl++; - vmp++; - } - } -} - -void LolEobBaseEngine::generateVmpTileDataFlipped(int16 startBlockX, uint8 startBlockY, uint8 vmpMapIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY) { - if (!_wllVmpMap[vmpMapIndex]) - return; - - uint16 *vmp = &_vmpPtr[(_wllVmpMap[vmpMapIndex] - 1) * 431 + vmpOffset + 330]; - - for (int i = 0; i < numBlocksY; i++) { - for (int ii = 0; ii < numBlocksX; ii++) { - if ((startBlockX + ii) < 0 || (startBlockX + ii) > 21) - continue; - - uint16 v = vmp[i * numBlocksX + (numBlocksX - 1 - ii)]; - if (!v) - continue; - - if (v & 0x4000) - v -= 0x4000; - else - v |= 0x4000; - - _blockDrawingBuffer[(startBlockY + i) * 22 + startBlockX + ii] = v; - } - } -} - -bool LolEobBaseEngine::hasWall(int index) { - if (!index || (_wllWallFlags[index] & 8)) - return false; - return true; -} - -void LolEobBaseEngine::assignVisibleBlocks(int block, int direction) { - for (int i = 0; i < 18; i++) { - uint16 t = (block + _dscBlockIndex[direction * 18 + i]) & 0x3ff; - _visibleBlockIndex[i] = t; - - _visibleBlocks[i] = &_levelBlockProperties[t]; - _lvlShapeLeftRight[i] = _lvlShapeLeftRight[18 + i] = -1; - } -} - -bool LolEobBaseEngine::checkSceneUpdateNeed(int block) { - if (_sceneUpdateRequired) - return true; - - for (int i = 0; i < 15; i++) { - if (_visibleBlockIndex[i] == block) { - _sceneUpdateRequired = true; - return true; - } - } - - if (_currentBlock == block){ - _sceneUpdateRequired = true; - return true; - } - - return false; -} - -void LolEobBaseEngine::drawVcnBlocks() { - uint8 *d = _sceneWindowBuffer; - uint16 *bdb = _blockDrawingBuffer; - - for (int y = 0; y < 15; y++) { - for (int x = 0; x < 22; x++) { - bool horizontalFlip = false; - int remainder = 0; - - uint16 vcnOffset = *bdb++; - int wllVcnOffset = 0; - int wllVcnRmdOffset = 0; - - if (vcnOffset & 0x8000) { - // this renders a wall block over the transparent pixels of a floor/ceiling block - remainder = vcnOffset - 0x8000; - vcnOffset = 0; - wllVcnRmdOffset = _wllVcnOffset; - } - - if (vcnOffset & 0x4000) { - horizontalFlip = true; - vcnOffset &= 0x3fff; - } - - uint8 *src = 0; - if (vcnOffset) { - src = &_vcnBlocks[vcnOffset << 5]; - wllVcnOffset = _wllVcnOffset; - } else { - // floor/ceiling blocks - vcnOffset = bdb[329]; - if (vcnOffset & 0x4000) { - horizontalFlip = true; - vcnOffset &= 0x3fff; - } - - src = (_vcfBlocks ? _vcfBlocks : _vcnBlocks) + (vcnOffset << 5); - } - - uint8 shift = _vcnShift ? _vcnShift[vcnOffset] : _blockBrightness; - - if (horizontalFlip) { - for (int blockY = 0; blockY < 8; blockY++) { - src += 3; - for (int blockX = 0; blockX < 4; blockX++) { - uint8 t = *src--; - *d++ = _vcnExpTable[((t & 0x0f) + wllVcnOffset) | shift]; - *d++ = _vcnExpTable[((t >> 4) + wllVcnOffset) | shift]; - } - src += 5; - d += 168; - } - } else { - for (int blockY = 0; blockY < 8; blockY++) { - for (int blockX = 0; blockX < 4; blockX++) { - uint8 t = *src++; - *d++ = _vcnExpTable[((t >> 4) + wllVcnOffset) | shift]; - *d++ = _vcnExpTable[((t & 0x0f) + wllVcnOffset) | shift]; - } - d += 168; - } - } - d -= 1400; - - if (remainder) { - d -= 8; - horizontalFlip = false; - - if (remainder & 0x4000) { - remainder &= 0x3fff; - horizontalFlip = true; - } - - shift = _vcnShift ? _vcnShift[remainder] : _blockBrightness; - src = &_vcnBlocks[remainder << 5]; - - if (horizontalFlip) { - for (int blockY = 0; blockY < 8; blockY++) { - src += 3; - for (int blockX = 0; blockX < 4; blockX++) { - uint8 t = *src--; - uint8 h = _vcnExpTable[((t & 0x0f) + wllVcnRmdOffset) | shift]; - uint8 l = _vcnExpTable[((t >> 4) + wllVcnRmdOffset) | shift]; - if (h) - *d = h; - d++; - if (l) - *d = l; - d++; - } - src += 5; - d += 168; - } - } else { - for (int blockY = 0; blockY < 8; blockY++) { - for (int blockX = 0; blockX < 4; blockX++) { - uint8 t = *src++; - uint8 h = _vcnExpTable[((t >> 4) + wllVcnRmdOffset) | shift]; - uint8 l = _vcnExpTable[((t & 0x0f) + wllVcnRmdOffset) | shift]; - if (h) - *d = h; - d++; - if (l) - *d = l; - d++; - } - d += 168; - } - } - d -= 1400; - } - } - d += 1232; - } - - screen()->copyBlockToPage(_sceneDrawPage1, _sceneXoffset, 0, 176, 120, _sceneWindowBuffer); -} - -uint16 LolEobBaseEngine::calcNewBlockPosition(uint16 curBlock, uint16 direction) { - static const int16 blockPosTable[] = { -32, 1, 32, -1 }; - return (curBlock + blockPosTable[direction]) & 0x3ff; -} - -int LolEobBaseEngine::clickedWallShape(uint16 block, uint16 direction) { - uint8 v = _wllShapeMap[_levelBlockProperties[block].walls[direction]]; - if (!clickedShape(v)) - return 0; - - snd_stopSpeech(true); - runLevelScript(block, 0x40); - - return 1; -} - -int LolEobBaseEngine::clickedLeverOn(uint16 block, uint16 direction) { - uint8 v = _wllShapeMap[_levelBlockProperties[block].walls[direction]]; - if (!clickedShape(v)) - return 0; - - _levelBlockProperties[block].walls[direction]++; - _sceneUpdateRequired = true; - - if (_flags.gameID == GI_LOL) - snd_playSoundEffect(30, -1); - - runLevelScript(block, _clickedSpecialFlag); - - return 1; -} - -int LolEobBaseEngine::clickedLeverOff(uint16 block, uint16 direction) { - uint8 v = _wllShapeMap[_levelBlockProperties[block].walls[direction]]; - if (!clickedShape(v)) - return 0; - - _levelBlockProperties[block].walls[direction]--; - _sceneUpdateRequired = true; - - if (_flags.gameID == GI_LOL) - snd_playSoundEffect(29, -1); - - runLevelScript(block, _clickedSpecialFlag); - return 1; -} - -int LolEobBaseEngine::clickedWallOnlyScript(uint16 block) { - runLevelScript(block, _clickedSpecialFlag); - return 1; -} - -void LolEobBaseEngine::processDoorSwitch(uint16 block, int openClose) { - if (block == _currentBlock) - return; - - if ((_flags.gameID == GI_LOL && (_levelBlockProperties[block].assignedObjects & 0x8000)) || (_flags.gameID != GI_LOL && (_levelBlockProperties[block].flags & 7))) - return; - - if (openClose == 0) { - for (int i = 0; i < 3; i++) { - if (_openDoorState[i].block != block) - continue; - openClose = -_openDoorState[i].state; - break; - } - } - - if (openClose == 0) { - openClose = (_wllWallFlags[_levelBlockProperties[block].walls[_wllWallFlags[_levelBlockProperties[block].walls[0]] & 8 ? 0 : 1]] & 1) ? 1 : -1; - if (_flags.gameID != GI_LOL) - openClose *= -1; - } - - openCloseDoor(block, openClose); -} - -void LolEobBaseEngine::openCloseDoor(int block, int openClose) { - int s1 = -1; - int s2 = -1; - - int c = (_wllWallFlags[_levelBlockProperties[block].walls[0]] & 8) ? 0 : 1; - int v = _levelBlockProperties[block].walls[c]; - int flg = (openClose == 1) ? 0x10 : (openClose == -1 ? 0x20 : 0); - - if (_wllWallFlags[v] & flg) - return; - - for (int i = 0; i < 3; i++) { - if (_openDoorState[i].block == block) { - s1 = i; - break; - } else if (_openDoorState[i].block == 0 && s2 == -1) { - s2 = i; - } - } - - if (s1 != -1 || s2 != -1) { - if (s1 == -1) - s1 = s2; - - _openDoorState[s1].block = block; - _openDoorState[s1].state = openClose; - _openDoorState[s1].wall = c; - - flg = (-openClose == 1) ? 0x10 : (-openClose == -1 ? 0x20 : 0); - - if (_wllWallFlags[v] & flg) { - _levelBlockProperties[block].walls[c] += openClose; - _levelBlockProperties[block].walls[c ^ 2] += openClose; - - int snd = (openClose == -1) ? 4 : 3; - if (_flags.gameID == GI_LOL) { - snd_processEnvironmentalSoundEffect(snd + 28, _currentBlock); - if (!checkSceneUpdateNeed(block)) - updateEnvironmentalSfx(0); - } else { - updateEnvironmentalSfx(snd); - } - } - - enableTimer(_flags.gameID == GI_LOL ? 0 : 4); - - } else { - while (!(flg & _wllWallFlags[v])) - v += openClose; - - _levelBlockProperties[block].walls[c] = _levelBlockProperties[block].walls[c ^ 2] = v; - checkSceneUpdateNeed(block); - } -} - -void LolEobBaseEngine::completeDoorOperations() { - for (int i = 0; i < 3; i++) { - if (!_openDoorState[i].block) - continue; - - uint16 b = _openDoorState[i].block; - - do { - _levelBlockProperties[b].walls[_openDoorState[i].wall] += _openDoorState[i].state; - _levelBlockProperties[b].walls[_openDoorState[i].wall ^ 2] += _openDoorState[i].state; - } while (!(_wllWallFlags[_levelBlockProperties[b].walls[_openDoorState[i].wall]] & 0x30)); - - _openDoorState[i].block = 0; - } -} - -} // End of namespace Kyra - -#endif // ENABLE_EOB || ENABLE_LOL -#ifdef ENABLE_EOB namespace Kyra { @@ -625,7 +41,7 @@ void EobCoreEngine::loadLevel(int level, int sub) { Common::String file; Common::SeekableReadStream *s = 0; static const char *suffix[] = { "INF", "DRO", "ELO", 0 }; - + for (const char *const *sf = suffix; *sf && !s; sf++) { file = Common::String::format("LEVEL%d.%s", level, *sf); s = _res->createReadStream(file); @@ -649,11 +65,11 @@ void EobCoreEngine::loadLevel(int level, int sub) { } Common::String gfxFile; - // Work around for issue with corrupt (incomplete) monster property data + // Work around for issue with corrupt (incomplete) monster property data // when loading a savegame saved in a sub level for (int i = 0; i <= sub; i++) gfxFile = initLevelData(i); - + const uint8 *data = _screen->getCPagePtr(5); const uint8 *pos = data + READ_LE_UINT16(data); uint16 len = READ_LE_UINT16(pos); @@ -744,7 +160,7 @@ Common::String EobCoreEngine::initLevelData(int sub){ _screen->setShapeFadeMode(0, false); _screen->setShapeFadeMode(1, false); } - + _screen->loadPalette(tmpStr.c_str(), _screen->getPalette(0)); Palette backupPal(256); @@ -850,7 +266,7 @@ void EobCoreEngine::addLevelItems() { void EobCoreEngine::loadVcnData(const char *file, const char*/*nextFile*/) { if (file) strcpy(_lastBlockDataFile, file); - + _screen->loadBitmap(Common::String::format("%s.VCN", _lastBlockDataFile).c_str(), 3, 3, 0); const uint8 *v = _screen->getCPagePtr(2); uint32 tlen = READ_LE_UINT16(v) << 5; @@ -1212,7 +628,7 @@ int EobCoreEngine::clickedDoorSwitch(uint16 block, uint16 direction) { else x1 += ((v - _dscDoorXE[v]) * 9); } - + if (!posWithinRect(_mouseX, _mouseY, x1, y1, x1 + (d->shp[2] << 3) + 8, y1 + d->shp[1] + 8) && (_clickedSpecialFlag == 0x40)) return clickedDoorNoPry(block, direction); -- cgit v1.2.3