From 5c233c447ba9656608b41fd0bd46edcc830e8b13 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 7 Jun 2009 20:43:43 +0000 Subject: Remove LoLEngine::_gameFlags and convert all Lands of Lore code to use _flagsTable instead. svn-id: r41351 --- engines/kyra/debugger.cpp | 47 ------------------------------------------- engines/kyra/debugger.h | 10 +++------ engines/kyra/gui_lol.cpp | 20 +++++++++--------- engines/kyra/items_lol.cpp | 2 +- engines/kyra/kyra_v1.cpp | 3 +++ engines/kyra/lol.cpp | 21 +++++++++---------- engines/kyra/lol.h | 1 - engines/kyra/saveload.cpp | 2 +- engines/kyra/saveload_lol.cpp | 38 +++++++++++++++++++++++++--------- engines/kyra/scene_lol.cpp | 18 ++++++++--------- engines/kyra/script_lol.cpp | 13 +++--------- engines/kyra/timer_lol.cpp | 2 +- 12 files changed, 69 insertions(+), 108 deletions(-) diff --git a/engines/kyra/debugger.cpp b/engines/kyra/debugger.cpp index a77ffee299..e0c2c0aa77 100644 --- a/engines/kyra/debugger.cpp +++ b/engines/kyra/debugger.cpp @@ -465,53 +465,6 @@ bool Debugger_HoF::cmd_passcodes(int argc, const char **argv) { #ifdef ENABLE_LOL Debugger_LoL::Debugger_LoL(LoLEngine *vm) : Debugger(vm), _vm(vm) { } - -bool Debugger_LoL::cmd_listFlags(int argc, const char **argv) { - for (int i = 0, p = 0; i < (int)sizeof(_vm->_gameFlags)*8; ++i, ++p) { - const uint8 index = (i >> 4); - const uint8 offset = i & 0xF; - - DebugPrintf("(%-3i): %-2i", i, (_vm->_gameFlags[index] >> offset) & 1); - if (p == 5) { - DebugPrintf("\n"); - p -= 6; - } - } - DebugPrintf("\n"); - return true; -} - -bool Debugger_LoL::cmd_toggleFlag(int argc, const char **argv) { - if (argc > 1) { - uint flag = atoi(argv[1]); - - const uint8 index = (flag >> 4); - const uint8 offset = flag & 0xF; - - _vm->_gameFlags[index] ^= _vm->_gameFlags[index] & (1 << offset); - - DebugPrintf("Flag %i is now %i\n", flag, (_vm->_gameFlags[index] >> offset) & 1); - } else { - DebugPrintf("Syntax: toggleflag \n"); - } - - return true; -} - -bool Debugger_LoL::cmd_queryFlag(int argc, const char **argv) { - if (argc > 1) { - uint flag = atoi(argv[1]); - - const uint8 index = (flag >> 4); - const uint8 offset = flag & 0xF; - - DebugPrintf("Flag %i is %i\n", flag, (_vm->_gameFlags[index] >> offset) & 1); - } else { - DebugPrintf("Syntax: queryflag \n"); - } - - return true; -} #endif // ENABLE_LOL } // End of namespace Kyra diff --git a/engines/kyra/debugger.h b/engines/kyra/debugger.h index b01402f7d5..c9cf6dba2a 100644 --- a/engines/kyra/debugger.h +++ b/engines/kyra/debugger.h @@ -47,9 +47,9 @@ protected: bool cmd_loadPalette(int argc, const char **argv); bool cmd_showFacings(int argc, const char **argv); bool cmd_gameSpeed(int argc, const char **argv); - virtual bool cmd_listFlags(int argc, const char **argv); - virtual bool cmd_toggleFlag(int argc, const char **argv); - virtual bool cmd_queryFlag(int argc, const char **argv); + bool cmd_listFlags(int argc, const char **argv); + bool cmd_toggleFlag(int argc, const char **argv); + bool cmd_queryFlag(int argc, const char **argv); bool cmd_listTimers(int argc, const char **argv); bool cmd_setTimerCountdown(int argc, const char **argv); }; @@ -106,10 +106,6 @@ public: protected: LoLEngine *_vm; - - bool cmd_listFlags(int argc, const char **argv); - bool cmd_toggleFlag(int argc, const char **argv); - bool cmd_queryFlag(int argc, const char **argv); }; #endif // ENABLE_LOL diff --git a/engines/kyra/gui_lol.cpp b/engines/kyra/gui_lol.cpp index 7a7de65e43..af8bc6aa97 100644 --- a/engines/kyra/gui_lol.cpp +++ b/engines/kyra/gui_lol.cpp @@ -34,26 +34,26 @@ namespace Kyra { void LoLEngine::gui_drawPlayField() { _screen->loadBitmap("PLAYFLD.CPS", 3, 3, 0); - if (_gameFlags[15] & 0x4000) { + if (_flagsTable[31] & 0x40) { // copy compass shape static const int cx[] = { 112, 152, 224 }; _screen->copyRegion(cx[_lang], 32, 288, 0, 32, 32, 2, 2, Screen::CR_NO_P_CHECK); _compassDirection = -1; } - if (_gameFlags[15] & 0x1000) + if (_flagsTable[31] & 0x10) // draw automap book _screen->drawShape(2, _gameShapes[78], 290, 32, 0, 0); int cp = _screen->setCurPage(2); - if (_gameFlags[15] & 0x2000) { + if (_flagsTable[31] & 0x20) { gui_drawScroll(); } else { _selectedSpell = 0; } - if (_gameFlags[15] & 0x800) + if (_flagsTable[31] & 0x08) resetLampStatus(); updateDrawPage2(); @@ -548,7 +548,7 @@ void LoLEngine::gui_drawMoneyBox(int pageNum) { } void LoLEngine::gui_drawCompass() { - if (!(_gameFlags[15] & 0x4000)) + if (!(_flagsTable[31] & 0x40)) return; if (_compassDirection == -1) { @@ -606,7 +606,7 @@ void LoLEngine::gui_toggleButtonDisplayMode(int shapeIndex, int mode) { static const int16 buttonX[] = { 0x0056, 0x0128, 0x000C, 0x0021, 0x0122, 0x000C, 0x0021, 0x0036, 0x000C, 0x0021, 0x0036 }; static const int16 buttonY[] = { 0x00B4, 0x00B4, 0x00B4, 0x00B4, 0x0020, 0x0084, 0x0084, 0x0084, 0x0096, 0x0096, 0x0096 }; - if (shapeIndex == 78 && !(_gameFlags[15] & 0x1000)) + if (shapeIndex == 78 && !(_flagsTable[31] & 0x10)) return; if (_currentControlMode && _needSceneRestore) @@ -836,7 +836,7 @@ void LoLEngine::gui_enableDefaultPlayfieldButtons() { gui_setFaceFramesControlButtons(29, 0); gui_setFaceFramesControlButtons(25, 33); - if (_gameFlags[15] & 0x2000) + if (_flagsTable[31] & 0x20) gui_initMagicScrollButtons(); } @@ -1752,7 +1752,7 @@ int LoLEngine::clickedMoneyBox(Button *button) { } int LoLEngine::clickedCompass(Button *button) { - if (!(_gameFlags[15] & 0x4000)) + if (!(_flagsTable[31] & 0x40)) return 0; if (_compassBroken) { @@ -1766,7 +1766,7 @@ int LoLEngine::clickedCompass(Button *button) { } int LoLEngine::clickedAutomap(Button *button) { - if (!(_gameFlags[15] & 0x1000)) + if (!(_flagsTable[31] & 0x10)) return 0; removeInputTop(); @@ -1778,7 +1778,7 @@ int LoLEngine::clickedAutomap(Button *button) { } int LoLEngine::clickedLamp(Button *button) { - if (!(_gameFlags[15] & 0x800)) + if (!(_flagsTable[31] & 0x08)) return 0; if (_itemsInPlay[_itemInHand].itemPropertyIndex == 248) { diff --git a/engines/kyra/items_lol.cpp b/engines/kyra/items_lol.cpp index 98894154f0..e75a13c870 100644 --- a/engines/kyra/items_lol.cpp +++ b/engines/kyra/items_lol.cpp @@ -279,7 +279,7 @@ void LoLEngine::setHandItem(uint16 itemIndex) { int mouseOffs = 0; - if (itemIndex && !(_gameFlags[15] & 0x200)) { + if (itemIndex && !(_flagsTable[31] & 0x02)) { mouseOffs = 10; if (!_currentControlMode || textEnabled()) _txt->printMessage(0, getLangString(0x403E), getLangString(_itemProperties[_itemsInPlay[itemIndex].itemPropertyIndex].nameStringId)); diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp index 71045e116d..d9fc8f9d66 100644 --- a/engines/kyra/kyra_v1.cpp +++ b/engines/kyra/kyra_v1.cpp @@ -470,15 +470,18 @@ void KyraEngine_v1::resetSkipFlag(bool removeEvent) { int KyraEngine_v1::setGameFlag(int flag) { + assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable)); _flagsTable[flag >> 3] |= (1 << (flag & 7)); return 1; } int KyraEngine_v1::queryGameFlag(int flag) const { + assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable)); return ((_flagsTable[flag >> 3] >> (flag & 7)) & 1); } int KyraEngine_v1::resetGameFlag(int flag) { + assert((flag >> 3) >= 0 && (flag >> 3) <= ARRAYSIZE(_flagsTable)); _flagsTable[flag >> 3] &= ~(1 << (flag & 7)); return 0; } diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index 0f251bc57d..3461fa5da9 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -500,7 +500,6 @@ Common::Error LoLEngine::init() { _flyingObjects = new FlyingObject[8]; memset(_flyingObjects, 0, 8 * sizeof(FlyingObject)); - memset(_gameFlags, 0, sizeof(_gameFlags)); memset(_globalScriptVars, 0, sizeof(_globalScriptVars)); _levelFileData = 0; @@ -643,7 +642,7 @@ void LoLEngine::loadItemIconShapes() { } void LoLEngine::setMouseCursorToIcon(int icon) { - _gameFlags[15] |= 0x200; + _flagsTable[31] |= 0x02; int i = _itemProperties[_itemsInPlay[_itemInHand].itemPropertyIndex].shpIndex; if (i == icon) return; @@ -651,7 +650,7 @@ void LoLEngine::setMouseCursorToIcon(int icon) { } void LoLEngine::setMouseCursorToItemInHand() { - _gameFlags[15] &= 0xFDFF; + _flagsTable[31] &= 0xFD; int o = (_itemInHand == 0) ? 0 : 10; _screen->setMouseCursor(o, o, getItemIconShapePtr(_itemInHand)); } @@ -856,7 +855,7 @@ void LoLEngine::runLoop() { enableSysTimer(2); bool _runFlag = true; - _gameFlags[36] |= 0x800; + _flagsTable[73] |= 0x08; while (!shouldQuit() && _runFlag) { if (_nextScriptFunc) { @@ -891,10 +890,10 @@ void LoLEngine::update() { if (_updateCharNum != -1 && _system->getMillis() > _updatePortraitNext) updatePortraitSpeechAnim(); - if (_gameFlags[15] & 0x800 || !(_updateFlags & 4)) + if (_flagsTable[31] & 0x08 || !(_updateFlags & 4)) updateLampStatus(); - if (_gameFlags[15] & 0x4000 && !(_updateFlags & 4) && (_compassDirection == -1 || (_currentDirection << 6) != _compassDirection || _compassStep)) + if (_flagsTable[31] & 0x40 && !(_updateFlags & 4) && (_compassDirection == -1 || (_currentDirection << 6) != _compassDirection || _compassStep)) updateCompass(); snd_updateCharacterSpeech(); @@ -1595,7 +1594,7 @@ void LoLEngine::generateBrightnessPalette(uint8 *src, uint8 *dst, int brightness memcpy(dst, src, 0x300); _screen->loadSpecialColors(dst); brightness = (8 - brightness) << 5; - if (modifier >= 0 && modifier < 8 && _gameFlags[15] & 0x800) { + if (modifier >= 0 && modifier < 8 && (_flagsTable[31] & 0x08)) { brightness = 256 - ((((modifier & 0xfffe) << 5) * (256 - brightness)) >> 8); if (brightness < 0) brightness = 0; @@ -2124,12 +2123,12 @@ int LoLEngine::processMagicIce(int charNum, int spellLevel) { uint8 *tpal = new uint8[768]; uint8 *swampCol = new uint8[768]; - if (_currentLevel == 11 && !(_gameFlags[26] & 4)) { + if (_currentLevel == 11 && !(_flagsTable[52] & 0x04)) { uint8 *sc = _screen->_currentPalette; uint8 *dc = _screen->getPalette(2); for (int i = 1; i < 768; i++) SWAP(sc[i], dc[i]); - _gameFlags[26] |= 4; + _flagsTable[52] |= 0x04; static const uint8 freezeTimes[] = { 20, 28, 40, 60 }; setCharacterUpdateEvent(charNum, 8, freezeTimes[spellLevel], 1); } @@ -3496,7 +3495,7 @@ void LoLEngine::stunCharacter(int charNum) { } void LoLEngine::restoreSwampPalette() { - _gameFlags[26] &= 0xfffb; + _flagsTable[52] &= 0xFB; if (_currentLevel != 11) return; @@ -3761,7 +3760,7 @@ void LoLEngine::displayAutomap() { } void LoLEngine::updateAutoMap(uint16 block) { - if (!(_gameFlags[15] & 0x1000)) + if (!(_flagsTable[31] & 0x10)) return; _levelBlockProperties[block].flags |= 7; diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index 4544faf499..45795a7cab 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -627,7 +627,6 @@ private: uint16 _currentBlock; bool _sceneUpdateRequired; int16 _visibleBlockIndex[18]; - uint16 _gameFlags[40]; int16 _globalScriptVars[24]; // emc opcode diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp index 7349cab9b5..79665068f6 100644 --- a/engines/kyra/saveload.cpp +++ b/engines/kyra/saveload.cpp @@ -30,7 +30,7 @@ #include "kyra/kyra_v1.h" -#define CURRENT_SAVE_VERSION 15 +#define CURRENT_SAVE_VERSION 16 #define GF_FLOPPY (1 << 0) #define GF_TALKIE (1 << 1) diff --git a/engines/kyra/saveload_lol.cpp b/engines/kyra/saveload_lol.cpp index cdfaca3b6d..2090deddfa 100644 --- a/engines/kyra/saveload_lol.cpp +++ b/engines/kyra/saveload_lol.cpp @@ -119,15 +119,33 @@ Common::Error LoLEngine::loadGameState(int slot) { _inventoryCurItem = in.readSint16BE(); _itemInHand = in.readSint16BE(); _lastMouseRegion = in.readSint16BE(); - if (header.version == 14) { - for (int i = 0; i < 16; i++) - _gameFlags[i] = in.readUint16BE(); - _gameFlags[26] = in.readUint16BE(); - _gameFlags[36] = in.readUint16BE(); + + if (header.version <= 15) { + uint16 flags[40]; + memset(flags, 0, sizeof(flags)); + + if (header.version == 14) { + for (int i = 0; i < 16; i++) + flags[i] = in.readUint16BE(); + flags[26] = in.readUint16BE(); + flags[36] = in.readUint16BE(); + } else if (header.version == 15) { + for (int i = 0; i < 40; i++) + flags[i] = in.readUint16BE(); + } + + for (uint i = 0; i < ARRAYSIZE(flags); ++i) { + for (uint k = 0; k < 16; ++k) { + if (flags[i] & (1 << k)) + setGameFlag(((i << 4) & 0xFFF0) | (k & 0x000F)); + } + } } else { - for (int i = 0; i < 40; i++) - _gameFlags[i] = in.readUint16BE(); + uint32 flagsSize = in.readUint32BE(); + assert(flagsSize <= sizeof(_flagsTable)); + in.read(_flagsTable, flagsSize); } + for (int i = 0; i < 24; i++) _globalScriptVars[i] = in.readUint16BE(); _brightness = in.readByte(); @@ -245,7 +263,7 @@ Common::Error LoLEngine::loadGameState(int slot) { loadLevel(_currentLevel); gui_drawPlayField(); timerSpecialCharacterUpdate(0); - _gameFlags[36] |= 0x800; + _flagsTable[73] |= 0x08; while (!_screen->isMouseVisible()) _screen->showMouse(); @@ -323,8 +341,8 @@ Common::Error LoLEngine::saveGameState(int slot, const char *saveName, const Gra out->writeSint16BE(_inventoryCurItem); out->writeSint16BE(_itemInHand); out->writeSint16BE(_lastMouseRegion); - for (int i = 0; i < 40; i++) - out->writeUint16BE(_gameFlags[i]); + out->writeUint32BE(ARRAYSIZE(_flagsTable)); + out->write(_flagsTable, ARRAYSIZE(_flagsTable)); for (int i = 0; i < 24; i++) out->writeUint16BE(_globalScriptVars[i]); out->writeByte(_brightness); diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp index df4be0fa1a..0236e4fa7d 100644 --- a/engines/kyra/scene_lol.cpp +++ b/engines/kyra/scene_lol.cpp @@ -36,7 +36,7 @@ namespace Kyra { void LoLEngine::loadLevel(int index) { - _gameFlags[36] |= 0x800; + _flagsTable[73] |= 0x08; setMouseCursorToIcon(0x85); _nextScriptFunc = 0; @@ -398,7 +398,7 @@ void LoLEngine::loadLevelGraphics(const char *file, int specialColor, int weight memcpy(_screen->getPalette(2) + 384, _screen->_currentPalette + 384, 384); delete[] swampPal; - if (_gameFlags[26] & 4) { + if (_flagsTable[52] & 0x04) { uint8 *pal0 = _screen->_currentPalette; uint8 *pal2 = _screen->getPalette(2); for (int i = 1; i < 768; i++) @@ -524,14 +524,14 @@ bool LoLEngine::testWallInvisibility(int block, int direction) { } void LoLEngine::resetLampStatus() { - _gameFlags[15] |= 0x400; + _flagsTable[31] |= 0x04; _lampEffect = -1; updateLampStatus(); } void LoLEngine::setLampMode(bool lampOn) { - _gameFlags[15] &= 0xFBFF; - if (!(_gameFlags[15] & 0x800) || !lampOn) + _flagsTable[31] &= 0xFB; + if (!(_flagsTable[30] & 0x08) || !lampOn) return; _screen->drawShape(0, _gameShapes[43], 291, 56, 0, 0); @@ -542,7 +542,7 @@ void LoLEngine::updateLampStatus() { uint8 newLampEffect = 0; uint8 tmpOilStatus = 0; - if ((_updateFlags & 4) || !(_gameFlags[15] & 0x800)) + if ((_updateFlags & 4) || !(_flagsTable[31] & 0x08)) return; if (!_brightness || !_lampOilStatus) { @@ -584,7 +584,7 @@ void LoLEngine::updateLampStatus() { } void LoLEngine::updateCompass() { - if (!(_gameFlags[15] & 0x4000) || (_updateFlags & 4)) + if (!(_flagsTable[31] & 0x40) || (_updateFlags & 4)) return; if (_compassDirection == -1) { @@ -651,12 +651,12 @@ void LoLEngine::moveParty(uint16 direction, int unk1, int unk2, int buttonShape) _sceneDefaultUpdate = 1; calcCoordinates(_partyPosX, _partyPosY, _currentBlock, 0x80, 0x80); - _gameFlags[36] &= 0xfdff; + _flagsTable[73] &= 0xFD; runLevelScript(opos, 4); runLevelScript(npos, 1); - if (!(_gameFlags[36] & 0x200)) { + if (!(_flagsTable[73] & 0x02)) { initTextFading(2, 0); if (_sceneDefaultUpdate) { diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index 6eb6ca96b6..3d57b23181 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -206,12 +206,10 @@ int LoLEngine::olol_delay(EMCState *script) { int LoLEngine::olol_setGameFlag(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_setGameFlag(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); - assert((stackPos(0) >> 4) < 40); - if (stackPos(1)) - _gameFlags[stackPos(0) >> 4] |= (1 << (stackPos(0) & 0x0f)); + setGameFlag(stackPos(0)); else - _gameFlags[stackPos(0) >> 4] &= (~(1 << (stackPos(0) & 0x0f))); + resetGameFlag(stackPos(0)); return 1; } @@ -221,12 +219,7 @@ int LoLEngine::olol_testGameFlag(EMCState *script) { if (stackPos(0) < 0) return 0; - assert((stackPos(0) >> 4) < 40); - - if (_gameFlags[stackPos(0) >> 4] & (1 << (stackPos(0) & 0x0f))) - return 1; - - return 0; + return queryGameFlag(stackPos(0)); } int LoLEngine::olol_loadLevelGraphics(EMCState *script) { diff --git a/engines/kyra/timer_lol.cpp b/engines/kyra/timer_lol.cpp index 4a66557465..84c4f8b19d 100644 --- a/engines/kyra/timer_lol.cpp +++ b/engines/kyra/timer_lol.cpp @@ -247,7 +247,7 @@ void LoLEngine::timerUpdatePortraitAnimations(int skipUpdate) { } void LoLEngine::timerUpdateLampState(int timerNum) { - if ((_gameFlags[15] & 0x800) && (_gameFlags[15] & 0x400) && _lampOilStatus > 0) + if ((_flagsTable[31] & 0x08) && (_flagsTable[31] & 0x04) && _lampOilStatus > 0) _lampOilStatus--; } -- cgit v1.2.3