diff options
author | Florian Kagerer | 2009-03-28 11:58:22 +0000 |
---|---|---|
committer | Florian Kagerer | 2009-03-28 11:58:22 +0000 |
commit | 8875fdcdedc08710517295f770acaf6931912041 (patch) | |
tree | d69bf788a25363be80aa7557b054bba63abe9e09 | |
parent | 97abfc9181e0689aada9ee97cde5899e6b28c366 (diff) | |
download | scummvm-rg350-8875fdcdedc08710517295f770acaf6931912041.tar.gz scummvm-rg350-8875fdcdedc08710517295f770acaf6931912041.tar.bz2 scummvm-rg350-8875fdcdedc08710517295f770acaf6931912041.zip |
LOL: - Level temp data now get stored in memory so you can now return to a level without everything being broken. Temp data isn't saved to disk. Since total memory requirement for storing this data won't exceed ~100kb I'd rather save memory in other places (like removing some screen page buffers)
- Implemented some more opcodes and fixed some bugs (You can now safely pick up coin pouches. The lamp seems to work fine, too).
svn-id: r39719
-rw-r--r-- | engines/kyra/gui_lol.cpp | 41 | ||||
-rw-r--r-- | engines/kyra/lol.cpp | 84 | ||||
-rw-r--r-- | engines/kyra/lol.h | 38 | ||||
-rw-r--r-- | engines/kyra/scene_lol.cpp | 133 | ||||
-rw-r--r-- | engines/kyra/script_lol.cpp | 48 | ||||
-rw-r--r-- | engines/kyra/text_lol.cpp | 8 | ||||
-rw-r--r-- | engines/kyra/timer_lol.cpp | 4 |
7 files changed, 239 insertions, 117 deletions
diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp index e7c3d6f138..51880b1199 100644 --- a/engines/kyra/gui_lol.cpp +++ b/engines/kyra/gui_lol.cpp @@ -56,6 +56,7 @@ void LoLEngine::gui_drawPlayField() { if (_gameFlags[15] & 0x800) resetLampStatus(); + updateDrawPage2(); gui_drawScene(2); gui_drawAllCharPortraitsWithStats(); @@ -63,9 +64,8 @@ void LoLEngine::gui_drawPlayField() { gui_drawMoneyBox(_screen->_curPage); _screen->setCurPage(cp); - _screen->hideMouse(); _screen->copyPage(2, 0); - _screen->showMouse(); + updateDrawPage2(); } void LoLEngine::gui_drawScene(int pageNum) { @@ -74,7 +74,7 @@ void LoLEngine::gui_drawScene(int pageNum) { } void LoLEngine::gui_drawInventory() { - if (!_currentControlMode || !_hideInventory) { + if (!_currentControlMode || !_needSceneRestore) { for (int i = 0; i < 9; i++) gui_drawInventoryItem(i); } @@ -603,7 +603,7 @@ void LoLEngine::gui_toggleButtonDisplayMode(int shapeIndex, int mode) { if (shapeIndex == 78 && !(_gameFlags[15] & 0x1000)) return; - if (_currentControlMode && _hideInventory) + if (_currentControlMode && _needSceneRestore) return; if (mode == 0) @@ -1198,7 +1198,7 @@ int LoLEngine::clickedExitCharInventory(Button *button) { _screen->copyBlockToPage(2, 0, 0, 320, 200, _pageBuffer2); _lastCharInventory = -1; - updateSceneWindow(); + updateDrawPage2(); enableSysTimer(2); return 1; @@ -1356,11 +1356,11 @@ int LoLEngine::clickedWall(Button *button) { break; case 2: - res = clickedLever(block, dir); + res = clickedLeverOn(block, dir); break; case 3: - res = clicked3(block, dir); + res = clickedLeverOff(block, dir); break; case 4: @@ -1454,11 +1454,36 @@ int LoLEngine::clickedAutomap(Button *button) { // displayAutopmap(); gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); return 1; } int LoLEngine::clickedLamp(Button *button) { + if (!(_gameFlags[15] & 0x800)) + return 0; + + if (_itemsInPlay[_itemInHand].itemPropertyIndex == 248) { + if (_lampOilStatus >= 100) { + _txt->printMessage(0, getLangString(0x4061)); + return 1; + } + + _txt->printMessage(0, getLangString(0x4062)); + + deleteItem(_itemInHand); + snd_playSoundEffect(181, -1); + setHandItem(0); + + _lampOilStatus += 100; + + } else { + uint16 s = (_lampOilStatus >= 100) ? 0x4060 : ((!_lampOilStatus) ? 0x405c : (_lampOilStatus / 33) + 0x405d); + _txt->printMessage(0, getLangString(0x405b), getLangString(s)); + } + + if (_brightness) + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); + return 1; } diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index 34ee0891ac..e4521f5d1d 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -105,7 +105,7 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy _spellProperties = 0; _updateFlags = 0; _selectedSpell = 0; - _updateCharNum = _updatePortraitSpeechAnimDuration = _portraitSpeechAnimMode = _updateCharV3 = _textColourFlag = _hideInventory = 0; + _updateCharNum = _updatePortraitSpeechAnimDuration = _portraitSpeechAnimMode = _updateCharV3 = _textColourFlag = _needSceneRestore = 0; _fadeText = false; _palUpdateTimer = _updatePortraitNext = 0; _lampStatusTimer = 0xffffffff; @@ -122,7 +122,6 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy _currentBlock = 0; memset(_visibleBlockIndex, 0, sizeof(_visibleBlockIndex)); - _scrollSceneBuffer = 0; _smoothScrollModeNormal = 1; _wllVmpMap = _wllBuffer3 = _wllBuffer4 = _wllWallFlags = 0; _wllShapeMap = 0; @@ -145,7 +144,7 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy _sceneWindowBuffer = 0; memset(_doorShapes, 0, sizeof(_doorShapes)); - _lampOilStatus = _brightness = _lampStatusUnk = 0; + _lampEffect = _brightness = _lampOilStatus = 0; _lampStatusSuspended = false; _tempBuffer5120 = 0; _flyingObjects = 0; @@ -212,6 +211,7 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy _smoothScrollingEnabled = true; _floatingCursorsEnabled = false; + memset (_lvlTempData, 0, sizeof(LevelTempData) * 28); _unkIceSHpFlag = 0; } @@ -307,7 +307,6 @@ LoLEngine::~LoLEngine() { delete[] _monsters; delete[] _levelBlockProperties; delete[] _monsterProperties; - delete[] _scrollSceneBuffer; delete[] _scriptAssignedLevelShape; delete[] _levelFileData; @@ -337,6 +336,16 @@ LoLEngine::~LoLEngine() { delete[] _ingameSoundList[i]; delete[] _ingameSoundList; } + + for (int i = 0; i < 28; i++) { + if (_lvlTempData[i]) { + delete[] _lvlTempData[i]->wallsXorData; + delete[] _lvlTempData[i]->flags; + delete[] _lvlTempData[i]->monsters; + delete[] _lvlTempData[i]->flyingObjects; + delete _lvlTempData[i]; + } + } } Screen *LoLEngine::screen() { @@ -413,8 +422,6 @@ Common::Error LoLEngine::init() { _monsterProperties = new MonsterProperty[5]; memset(_monsterProperties, 0, 5 * sizeof(MonsterProperty)); - _scrollSceneBuffer = new uint8[21120]; - _vcnExpTable = new uint8[128]; for (int i = 0; i < 128; i++) _vcnExpTable[i] = i & 0x0f; @@ -443,7 +450,7 @@ Common::Error LoLEngine::init() { memset(_monsterShapesEx, 0, 576 * sizeof(uint8*)); memset(&_scriptData, 0, sizeof(EMCData)); - _levelFlagUnk = 0; + _hasTempDataFlags = 0; _unkCharNum = -1; return Common::kNoError; @@ -1020,7 +1027,7 @@ void LoLEngine::initTextFading(int textType, int clearField) { return; updatePortraits(); - if (_hideInventory) + if (_needSceneRestore) _screen->setScreenDim(_txt->clearDim(3)); _fadeText = false; @@ -1242,11 +1249,11 @@ void LoLEngine::restoreAfterSceneWindowDialogue(int redraw) { if (_screen->_fadeFlag != 2) _screen->fadeClearSceneWindow(10); gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); _screen->_fadeFlag = 0; } - _hideInventory = 0; + _needSceneRestore = 0; enableSysTimer(2); } @@ -1314,7 +1321,7 @@ void LoLEngine::restoreAfterDialogueSequence(int controlMode) { } void LoLEngine::resetPortraitsAndDisableSysTimer() { - _hideInventory = 1; + _needSceneRestore = 1; if (!textEnabled() || (!(_currentControlMode & 2))) timerUpdatePortraitAnimations(1); @@ -1328,7 +1335,7 @@ void LoLEngine::fadeText() { if (_screen->fadeColour(192, 252, _system->getMillis() - _palUpdateTimer, 60 * _tickLength)) return; - if (_hideInventory) + if (_needSceneRestore) return; _screen->setScreenDim(_txt->clearDim(3)); @@ -1533,7 +1540,8 @@ void LoLEngine::snd_playSoundEffect(int track, int volume) { volume = 254 - volume; int16 vocIndex = (int16)READ_LE_UINT16(&_ingameSoundIndex[track * 2]); - if (vocIndex != -1) { + if (vocIndex != -1 +) { _sound->voicePlay(_ingameSoundList[vocIndex], volume & 0xff, true); } else if (_flags.platform == Common::kPlatformPC) { if (_sound->getSfxType() == Sound::kMidiMT32) @@ -1635,7 +1643,7 @@ int LoLEngine::snd_stopMusic() { return snd_playTrack(-1); } -bool LoLEngine::characterSays(int track, int charId, bool redraw) { +int LoLEngine::characterSays(int track, int charId, bool redraw) { if (charId == 1) { charId = _selectedCharacter; } else { @@ -1648,7 +1656,7 @@ bool LoLEngine::characterSays(int track, int charId, bool redraw) { } if (i == 4) - return false; + return 0; } bool r = snd_playCharacterSpeech(track, charId, 0); @@ -1662,7 +1670,7 @@ bool LoLEngine::characterSays(int track, int charId, bool redraw) { updatePortraitSpeechAnim(); } - return r ? textEnabled() : 1; + return r ? (textEnabled() ? 1 : 0) : 1; } int LoLEngine::playCharacterScriptChat(int charId, int mode, int unk1, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex) { @@ -1907,6 +1915,50 @@ uint16 LoLEngine::getClosestPartyMember(int x, int y) { return id; } +void LoLEngine::generateTempData() { + int l = _currentLevel - 1; + if (_lvlTempData[l]) { + delete[] _lvlTempData[l]->wallsXorData; + delete[] _lvlTempData[l]->flags; + delete[] _lvlTempData[l]->monsters; + delete[] _lvlTempData[l]->flyingObjects; + delete _lvlTempData[l]; + } + + _lvlTempData[l] = new LevelTempData; + + _lvlTempData[l]->wallsXorData = new uint8[4096]; + _lvlTempData[l]->flags = new uint8[1024]; + _lvlTempData[l]->monsters = new MonsterInPlay[30]; + _lvlTempData[l]->flyingObjects = new FlyingObject[8]; + + char filename[13]; + snprintf(filename, sizeof(filename), "LEVEL%d.CMZ", _currentLevel); + + _screen->loadBitmap(filename, 3, 3, 0); + const uint8 *p = _screen->getCPagePtr(2); + uint16 len = READ_LE_UINT16(p + 4); + p += 6; + + memset(_lvlTempData[l]->wallsXorData, 0, 4096); + memset(_lvlTempData[l]->flags, 0, 1024); + uint8 *d = _lvlTempData[l]->wallsXorData; + uint8 *df = _lvlTempData[l]->flags; + + for (int i = 0; i < 1024; i++) { + for (int ii = 0; ii < 4; ii++) + *d++ = p[i * len + ii] ^ _levelBlockProperties[i].walls[ii]; + *df++ = _levelBlockProperties[i].flags; + } + + memcpy(_lvlTempData[l]->monsters, _monsters, sizeof(MonsterInPlay) * 30); + memcpy(_lvlTempData[l]->flyingObjects, _flyingObjects, sizeof(FlyingObject) * 8); + + _lvlTempData[l]->monsterDifficulty =_monsterDifficulty; + + _hasTempDataFlags |= (1 << l); +} + } // end of namespace Kyra #endif // ENABLE_LOL diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index e117239ef0..a914f7fdeb 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -235,6 +235,14 @@ struct FlyingObjectShape { uint8 flipFlags; }; +struct LevelTempData { + uint8 *wallsXorData; + uint8 *flags; + MonsterInPlay *monsters; + FlyingObject *flyingObjects; + uint8 monsterDifficulty; +}; + class LoLEngine : public KyraEngine_v1 { friend class GUI_LoL; friend class TextDisplayer_LoL; @@ -509,7 +517,7 @@ private: int _buttonList8Size; // text - bool characterSays(int track, int charId, bool redraw); + int characterSays(int track, int charId, bool redraw); int playCharacterScriptChat(int charId, int mode, int unk1, char *str, EMCState *script, const uint16 *paramList, int16 paramIndex); TextDisplayer_LoL *_txt; @@ -612,6 +620,7 @@ private: int olol_stopCharacterSpeech(EMCState *script); int olol_setPaletteBrightness(EMCState *script); int olol_printMessage(EMCState *script); + int olol_deleteLevelItem(EMCState *script); int olol_playDialogueTalkText(EMCState *script); int olol_checkMonsterTypeHostility(EMCState *script); int olol_setNextFunc(EMCState *script); @@ -630,7 +639,8 @@ private: int olol_resetPortraitsAndDisableSysTimer(EMCState *script); int olol_enableSysTimer(EMCState *script); int olol_disableControls(EMCState *script); - int olol_enableControls(EMCState *script); + int olol_enableControls(EMCState *script); + int olol_characterSays(EMCState *script); int olol_queueSpeech(EMCState *script); int olol_getItemPrice(EMCState *script); int olol_getLanguage(EMCState *script); @@ -745,12 +755,12 @@ private: int _updateCharV3; int _textColourFlag; bool _fadeText; - int _hideInventory; + int _needSceneRestore; uint32 _palUpdateTimer; uint32 _updatePortraitNext; int _loadLevelFlag; - int _levelFlagUnk; + int _hasTempDataFlags; int _unkCharNum; int _charStatsTemp[5]; @@ -773,9 +783,9 @@ private: void setLampMode(bool lampOn); void updateLampStatus(); - int _lampOilStatus; + int _lampEffect; int _brightness; - int _lampStatusUnk; + int _lampOilStatus; uint32 _lampStatusTimer; bool _lampStatusSuspended; @@ -786,8 +796,8 @@ private: void assignBlockObject(uint16 *cmzItemIndex, uint16 item); int assignLevelShapes(int index); uint8 *getLevelShapes(int index); - void loadLevelCmzFile(int index); - void loadCMZ_Sub(int index1, int index2); + void restoreBlockTempData(int index); + void restoreTempDataAdjustMonsterStrength(int index); void loadCmzFile(const char *file); void loadLevelShpDat(const char *shpFile, const char *datFile, bool flag); void loadLevelGraphics(const char *file, int specialColor, int weight, int vcnLen, int vmpLen, const char *palFile); @@ -815,7 +825,7 @@ private: void drawBlockEffects(int index, int type); void drawScriptShapes(int pageNum); void setWallType(int block, int wall, int val); - void updateSceneWindow(); + void updateDrawPage2(); void prepareSpecialScene(int fieldType, int hasDialogue, int suspendGui, int allowSceneUpdate, int controlMode, int fadeFlag); int restoreAfterSpecialScene(int fadeFlag, int redrawPlayField, int releaseTimScripts, int sceneUpdateMode); @@ -837,8 +847,8 @@ private: void calcCoordinatesAddDirectionOffset(int16 &x, int16 &y, int direction); int clickedWallShape(uint16 block, uint16 direction); - int clickedLever(uint16 block, uint16 direction); - int clicked3(uint16 block, uint16 direction); + int clickedLeverOn(uint16 block, uint16 direction); + int clickedLeverOff(uint16 block, uint16 direction); int clickedWallOnlyScript(uint16 block); int clickedDoorSwitch(uint16 block, uint16 direction); int clicked6(uint16 block, uint16 direction); @@ -846,7 +856,7 @@ private: bool clickedShape(int shapeIndex); void processDoorSwitch(uint16 block, int unk); void openCloseDoor(uint16 block, int openClose); - void resetDoors(); + void completeDoorOperations(); void movePartySmoothScrollBlocked(int speed); void movePartySmoothScrollUp(int speed); @@ -862,7 +872,6 @@ private: OpenDoorState _openDoorState[3]; int _emcDoorState; - uint8 *_scrollSceneBuffer; uint32 _smoothScrollTimer; int _smoothScrollModeNormal; @@ -1158,6 +1167,9 @@ private: // save Common::Error loadGameState(int slot) { return Common::kNoError; } Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail) { return Common::kNoError; } + + void generateTempData(); + LevelTempData *_lvlTempData[28]; }; } // end of namespace Kyra diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp index ae868ea8ea..c95740e2c2 100644 --- a/engines/kyra/scene_lol.cpp +++ b/engines/kyra/scene_lol.cpp @@ -73,12 +73,12 @@ void LoLEngine::loadLevel(int index) { char filename[13]; snprintf(filename, sizeof(filename), "LEVEL%d.INI", index); - int f = _levelFlagUnk & (1 << (index - 1)); + int f = _hasTempDataFlags & (1 << (index - 1)); runInitScript(filename, f ? 0 : 1); if (f) - loadLevelCmzFile(index); + restoreBlockTempData(index); snprintf(filename, sizeof(filename), "LEVEL%d.INF", index); runInfScript(filename); @@ -94,7 +94,7 @@ void LoLEngine::loadLevel(int index) { gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); setMouseCursorToItemInHand(); snd_playTrack(_curMusicTheme); @@ -232,13 +232,12 @@ uint8 *LoLEngine::getLevelShapes(int shapeIndex) { return res; } -void LoLEngine::loadLevelCmzFile(int index) { - //char filename[13]; - //snprintf(filename, sizeof(filename), "_LEVEL%d.TMP", index); - // TODO ??? +void LoLEngine::restoreBlockTempData(int index) { memset(_tempBuffer5120, 0, 5120); - uint16 tmpLvlVal = 0; + int l = index - 1; + memcpy(_monsters, _lvlTempData[l]->monsters, sizeof(MonsterInPlay) * 30); + memcpy(_flyingObjects, _lvlTempData[l]->flyingObjects, sizeof(FlyingObject) * 8); char filename[13]; snprintf(filename, sizeof(filename), "LEVEL%d.CMZ", index); @@ -246,25 +245,19 @@ void LoLEngine::loadLevelCmzFile(int index) { _screen->loadBitmap(filename, 3, 3, 0); const uint8 *p = _screen->getCPagePtr(2); uint16 len = READ_LE_UINT16(p + 4); - - uint8 *cmzdata = new uint8[0x1000]; - - for (int i = 0; i < 1024; i++) - memcpy(&cmzdata[i << 2], &p[i * len + 6], 4); + p += 6; memset(_levelBlockProperties, 0, 1024 * sizeof(LevelBlockProperty)); - uint8 *c = cmzdata; - uint8 *t = _tempBuffer5120; + uint8 *t = _lvlTempData[l]->wallsXorData; + uint8 *t2 = _lvlTempData[l]->flags; for (int i = 0; i < 1024; i++) { for (int ii = 0; ii < 4; ii++) - _levelBlockProperties[i].walls[ii] = *c++ ^ *t++; + _levelBlockProperties[i].walls[ii] = p[i * len + ii] ^ *t++; + _levelBlockProperties[i].flags = *t2++; } - for (int i = 0; i < 1024; i++) - _levelBlockProperties[i].flags = *t++; - for (int i = 0; i < 30; i++) { if (_monsters[i].blockPropertyIndex) { _monsters[i].blockPropertyIndex = 0; @@ -273,24 +266,21 @@ void LoLEngine::loadLevelCmzFile(int index) { } } - loadCMZ_Sub(tmpLvlVal, _monsterDifficulty); - - delete[] cmzdata; + restoreTempDataAdjustMonsterStrength(l); } -void LoLEngine::loadCMZ_Sub(int index1, int index2) { - static const int table[] = { 0x66, 0x100, 0x180, 0x100, 0x100, 0xC0, 0x140, 0x100, 0x80, 0x80, 0x100, 0x100 }; - int val = (table[index2] << 8) / table[index1]; +void LoLEngine::restoreTempDataAdjustMonsterStrength(int index) { + if (_lvlTempData[index]->monsterDifficulty == _monsterDifficulty) + return; - //int r = 0; + uint16 d = (_monsterModifiers[_lvlTempData[index]->monsterDifficulty] << 8) / _monsterModifiers[_monsterDifficulty]; for (int i = 0; i < 30; i++) { if (_monsters[i].mode >= 14 || _monsters[i].blockPropertyIndex == 0 || _monsters[i].might <= 0) continue; - int t = (val * _monsters[i].might) >> 8; - _monsters[i].might = t; - if (index2 < index1) + _monsters[i].might = (d * _monsters[i].might) >> 8; + if (_monsterDifficulty < _lvlTempData[index]->monsterDifficulty) _monsters[i].might++; if (_monsters[i].might == 0) _monsters[i].might = 1; @@ -452,7 +442,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight _screen->getLevelOverlay(7)[i] = i & 0xff; _loadSuppFilesFlag = 0; - generateBrightnessPalette(_screen->_currentPalette, _screen->getPalette(1), _brightness, _lampOilStatus); + generateBrightnessPalette(_screen->_currentPalette, _screen->getPalette(1), _brightness, _lampEffect); char tname[13]; snprintf(tname, sizeof(tname), "LEVEL%.02d.TLC", _currentLevel); @@ -535,7 +525,7 @@ bool LoLEngine::testWallInvisibility(int block, int direction) { void LoLEngine::resetLampStatus() { _gameFlags[15] |= 0x400; - _lampOilStatus = 255; + _lampEffect = 255; updateLampStatus(); } @@ -545,7 +535,7 @@ void LoLEngine::setLampMode(bool lampOn) { return; _screen->drawShape(0, _gameShapes[43], 291, 56, 0, 0); - _lampOilStatus = 8; + _lampEffect = 8; } void LoLEngine::updateLampStatus() { @@ -555,34 +545,34 @@ void LoLEngine::updateLampStatus() { if ((_updateFlags & 4) || !(_gameFlags[15] & 0x800)) return; - if (!_brightness || !_lampStatusUnk) { + if (!_brightness || !_lampOilStatus) { newLampOilStatus = 8; - if (newLampOilStatus != _lampOilStatus && _screen->_fadeFlag == 0) - setPaletteBrightness(_screen->_currentPalette, _lampOilStatus, newLampOilStatus); + if (newLampOilStatus != _lampEffect && _screen->_fadeFlag == 0) + setPaletteBrightness(_screen->_currentPalette, _lampEffect, newLampOilStatus); } else { - tmp2 = (_lampStatusUnk < 100) ? _lampStatusUnk : 100; + tmp2 = (_lampOilStatus < 100) ? _lampOilStatus : 100; newLampOilStatus = (3 - (tmp2 - 1) / 25) << 1; - if (_lampOilStatus == 255) { + if (_lampEffect == 255) { if (_screen->_fadeFlag == 0) setPaletteBrightness(_screen->_currentPalette, _brightness, newLampOilStatus); _lampStatusTimer = _system->getMillis() + (10 + _rnd.getRandomNumberRng(1, 30)) * _tickLength; } else { - if ((_lampOilStatus & 0xfe) == (newLampOilStatus & 0xfe)) { + if ((_lampEffect & 0xfe) == (newLampOilStatus & 0xfe)) { if (_system->getMillis() <= _lampStatusTimer) { - newLampOilStatus = _lampOilStatus; + newLampOilStatus = _lampEffect; } else { - newLampOilStatus = _lampOilStatus ^ 1; + newLampOilStatus = _lampEffect ^ 1; _lampStatusTimer = _system->getMillis() + (10 + _rnd.getRandomNumberRng(1, 30)) * _tickLength; } } else { if (_screen->_fadeFlag == 0) - setPaletteBrightness(_screen->_currentPalette, _lampOilStatus, newLampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _lampEffect, newLampOilStatus); } } } - if (newLampOilStatus == _lampOilStatus) + if (newLampOilStatus == _lampEffect) return; _screen->hideMouse(); @@ -590,7 +580,7 @@ void LoLEngine::updateLampStatus() { _screen->drawShape(_screen->_curPage, _gameShapes[35 + newLampOilStatus], 291, 56, 0, 0); _screen->showMouse(); - _lampOilStatus = newLampOilStatus; + _lampEffect = newLampOilStatus; } void LoLEngine::updateCompass() { @@ -739,11 +729,32 @@ int LoLEngine::clickedWallShape(uint16 block, uint16 direction) { return 1; } -int LoLEngine::clickedLever(uint16 block, uint16 direction) { +int LoLEngine::clickedLeverOn(uint16 block, uint16 direction) { + uint8 v = _wllShapeMap[_levelBlockProperties[block].walls[direction]]; + if (!clickedShape(v)) + return 0; + + _levelBlockProperties[block].walls[direction]++; + _sceneUpdateRequired = true; + + snd_playSoundEffect(30, -1); + + runLevelScript(block, 0x40); + return 1; } -int LoLEngine::clicked3(uint16 block, uint16 direction) { +int LoLEngine::clickedLeverOff(uint16 block, uint16 direction) { + uint8 v = _wllShapeMap[_levelBlockProperties[block].walls[direction]]; + if (!clickedShape(v)) + return 0; + + _levelBlockProperties[block].walls[direction]--; + _sceneUpdateRequired = true; + + snd_playSoundEffect(29, -1); + + runLevelScript(block, 0x40); return 1; } @@ -869,7 +880,7 @@ void LoLEngine::openCloseDoor(uint16 block, int openClose) { } } -void LoLEngine::resetDoors() { +void LoLEngine::completeDoorOperations() { for (int i = 0; i < 3; i++) { if (!_openDoorState[i].block) continue; @@ -886,7 +897,7 @@ void LoLEngine::resetDoors() { } void LoLEngine::movePartySmoothScrollBlocked(int speed) { - if (!_smoothScrollingEnabled || (_smoothScrollingEnabled && _hideInventory)) + if (!_smoothScrollingEnabled || (_smoothScrollingEnabled && _needSceneRestore)) return; _screen->backupSceneWindow(_sceneDrawPage2 == 2 ? 2 : 6, 6); @@ -920,11 +931,11 @@ void LoLEngine::movePartySmoothScrollBlocked(int speed) { _screen->updateScreen(); } - updateSceneWindow(); + updateDrawPage2(); } void LoLEngine::movePartySmoothScrollUp(int speed) { - if (!_smoothScrollingEnabled || (_smoothScrollingEnabled && _hideInventory)) + if (!_smoothScrollingEnabled || (_smoothScrollingEnabled && _needSceneRestore)) return; int d = 0; @@ -932,12 +943,12 @@ void LoLEngine::movePartySmoothScrollUp(int speed) { if (_sceneDrawPage2 == 2) { d = smoothScrollDrawSpecialShape(6); gui_drawScene(6); - _screen->copyRegionToBuffer(6, 112, 0, 176, 120, _scrollSceneBuffer); + _screen->backupSceneWindow(6, 12); _screen->backupSceneWindow(2, 6); } else { d = smoothScrollDrawSpecialShape(2); gui_drawScene(2); - _screen->copyRegionToBuffer(2, 112, 0, 176, 120, _scrollSceneBuffer); + _screen->backupSceneWindow(2, 12); _screen->backupSceneWindow(6, 6); } @@ -961,11 +972,11 @@ void LoLEngine::movePartySmoothScrollUp(int speed) { // unk(_tempBuffer5120, _scrollSceneBuffer); if (_sceneDefaultUpdate != 2) { - _screen->copyBlockToPage(0, 112, 0, 176, 120, _scrollSceneBuffer); + _screen->restoreSceneWindow(12, 0); _screen->updateScreen(); } - updateSceneWindow(); + updateDrawPage2(); } void LoLEngine::movePartySmoothScrollDown(int speed) { @@ -1000,7 +1011,7 @@ void LoLEngine::movePartySmoothScrollDown(int speed) { _screen->updateScreen(); } - updateSceneWindow(); + updateDrawPage2(); } void LoLEngine::movePartySmoothScrollLeft(int speed) { @@ -1173,12 +1184,12 @@ void LoLEngine::updateAutoMap(int block) { void LoLEngine::drawScene(int pageNum) { if (pageNum && pageNum != _sceneDrawPage1) { SWAP(_sceneDrawPage1, _sceneDrawPage2); - updateSceneWindow(); + updateDrawPage2(); } if (pageNum && pageNum != _sceneDrawPage1) { SWAP(_sceneDrawPage1, _sceneDrawPage2); - updateSceneWindow(); + updateDrawPage2(); } generateBlockDrawingBuffer(); @@ -1215,10 +1226,8 @@ void LoLEngine::setWallType(int block, int wall, int val) { checkSceneUpdateNeed(block); } -void LoLEngine::updateSceneWindow() { - _screen->hideMouse(); +void LoLEngine::updateDrawPage2() { _screen->copyRegion(112, 0, 112, 0, 176, 120, 0, _sceneDrawPage2, Screen::CR_NO_P_CHECK); - _screen->showMouse(); } void LoLEngine::prepareSpecialScene(int fieldType, int hasDialogue, int suspendGui, int allowSceneUpdate, int controlMode, int fadeFlag) { @@ -1264,10 +1273,10 @@ void LoLEngine::prepareSpecialScene(int fieldType, int hasDialogue, int suspendG } int LoLEngine::restoreAfterSpecialScene(int fadeFlag, int redrawPlayField, int releaseTimScripts, int sceneUpdateMode) { - if (!_hideInventory) + if (!_needSceneRestore) return 0; - _hideInventory = 0; + _needSceneRestore = 0; enableSysTimer(2); if (_dialogueField) @@ -1308,7 +1317,7 @@ int LoLEngine::restoreAfterSpecialScene(int fadeFlag, int redrawPlayField, int r if (redrawPlayField) gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); } else { _currentControlMode = 0; diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index c706ce4741..8b7cd732f9 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -571,7 +571,7 @@ int LoLEngine::olol_getGlobalVar(EMCState *script) { case 8: return _updateFlags; case 9: - return _lampStatusUnk; + return _lampOilStatus; case 10: return _sceneDefaultUpdate; case 11: @@ -638,7 +638,7 @@ int LoLEngine::olol_setGlobalVar(EMCState *script) { break; case 9: - _lampStatusUnk = b & 0xff; + _lampOilStatus = b & 0xff; break; case 10: @@ -767,7 +767,7 @@ int LoLEngine::olol_redrawPlayfield(EMCState *script) { if (_screen->_fadeFlag != 2) _screen->fadeClearSceneWindow(10); gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); _screen->_fadeFlag = 0; return 1; } @@ -784,10 +784,9 @@ int LoLEngine::olol_loadNewLevel(EMCState *script) { endObjectFlight(&_flyingObjects[i], _flyingObjects[i].x, _flyingObjects[i].y, 1); } - resetDoors(); + completeDoorOperations(); - /////////////////////// - // TODO: generate temp files + generateTempData(); _currentBlock = stackPos(1); _currentDirection = stackPos(2); @@ -1147,7 +1146,7 @@ int LoLEngine::olol_setPaletteBrightness(EMCState *script) { uint16 old = _brightness; _brightness = stackPos(0); if (stackPos(1) == 1) - setPaletteBrightness(_screen->_currentPalette, stackPos(0), _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, stackPos(0), _lampEffect); return old; } @@ -1156,8 +1155,18 @@ int LoLEngine::olol_printMessage(EMCState *script) { int snd = stackPos(2); _txt->printMessage(stackPos(0), getLangString(stackPos(1)), stackPos(3), stackPos(4), stackPos(5), stackPos(6), stackPos(7), stackPos(8), stackPos(9)); - if (snd) - snd_playSoundEffect(snd, 255); + if (snd >= 0) + snd_playSoundEffect(snd, -1); + + return 1; +} + +int LoLEngine::olol_deleteLevelItem(EMCState *script) { + debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_deleteLevelItem(%p) (%d)", (const void *)script, stackPos(0)); + if (_itemsInPlay[stackPos(0)].blockPropertyIndex) + removeLevelItem(stackPos(0), _itemsInPlay[stackPos(0)].blockPropertyIndex); + + deleteItem(stackPos(0)); return 1; } @@ -1281,7 +1290,7 @@ int LoLEngine::olol_resetPortraitsAndDisableSysTimer(EMCState *script) { int LoLEngine::olol_enableSysTimer(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_enableSysTimer(%p)", (const void *)script); - _hideInventory = 0; + _needSceneRestore = 0; enableSysTimer(2); return 1; } @@ -1296,6 +1305,19 @@ int LoLEngine::olol_enableControls(EMCState *script) { return gui_enableControls(); } +int LoLEngine::olol_characterSays(EMCState *script) { + debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_characterSays(%p) (%d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2)); + if (stackPos(0) == -1) { + snd_stopSpeech(true); + return 1; + } + + if (stackPos(0) != -1) + return characterSays(stackPos(0), stackPos(1), stackPos(2)); + else + return snd_characterSpeaking(); +} + int LoLEngine::olol_queueSpeech(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_queueSpeech(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); if (stackPos(0) && stackPos(1)) { @@ -1455,7 +1477,7 @@ int LoLEngine::tlol_fadeClearWindow(const TIM *tim, const uint16 *param) { if (_screen->_fadeFlag != 2) _screen->fadeClearSceneWindow(10); gui_drawPlayField(); - setPaletteBrightness(_screen->_currentPalette, _brightness, _lampOilStatus); + setPaletteBrightness(_screen->_currentPalette, _brightness, _lampEffect); _screen->_fadeFlag = 0; break; @@ -1721,7 +1743,7 @@ void LoLEngine::setupOpcodeTable() { Opcode(olol_printMessage); // 0x70 - OpcodeUnImpl(); + Opcode(olol_deleteLevelItem); OpcodeUnImpl(); OpcodeUnImpl(); OpcodeUnImpl(); @@ -1832,7 +1854,7 @@ void LoLEngine::setupOpcodeTable() { OpcodeUnImpl(); OpcodeUnImpl(); OpcodeUnImpl(); - OpcodeUnImpl(); + Opcode(olol_characterSays); // 0xBC Opcode(olol_queueSpeech); diff --git a/engines/kyra/text_lol.cpp b/engines/kyra/text_lol.cpp index f7087cd846..9616596710 100644 --- a/engines/kyra/text_lol.cpp +++ b/engines/kyra/text_lol.cpp @@ -223,8 +223,10 @@ void TextDisplayer_LoL::printMessage(uint16 type, char *str, ...) { _screen->setScreenDim(od); - if (!(type & 0x8000) && soundEffect[type]) - _vm->sound()->playSoundEffect(soundEffect[type]); + if (!(type & 0x8000)) { + if (soundEffect[type]) + _vm->sound()->playSoundEffect(soundEffect[type]); + } _vm->_textColourFlag = type & 0x7fff; _vm->_fadeText = false; @@ -606,7 +608,7 @@ void TextDisplayer_LoL::textPageBreak() { int x = ((dim->sx + dim->w) << 3) - 77; int y = 0; - if (_vm->_hideInventory && (_vm->_updateFlags & 2)) { + if (_vm->_needSceneRestore && (_vm->_updateFlags & 2)) { if (_vm->_currentControlMode || !(_vm->_updateFlags & 2)) { y = dim->sy + dim->h - 5; } else { diff --git a/engines/kyra/timer_lol.cpp b/engines/kyra/timer_lol.cpp index c6ed885a29..f82687b2d5 100644 --- a/engines/kyra/timer_lol.cpp +++ b/engines/kyra/timer_lol.cpp @@ -154,8 +154,8 @@ void LoLEngine::timerUpdatePortraitAnimations(int skipUpdate) { } void LoLEngine::timerUpdateLampState(int timerNum) { - if ((_gameFlags[15] & 0x800) && (_gameFlags[15] & 0x400) && _lampStatusUnk) - _lampStatusUnk--; + if ((_gameFlags[15] & 0x800) && (_gameFlags[15] & 0x400) && _lampOilStatus) + _lampOilStatus--; } void LoLEngine::timerFadeMessageText(int timerNum) { |