diff options
author | Filippos Karapetis | 2015-12-12 03:28:06 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-23 21:34:00 +0100 |
commit | 8f5c91ee07b65f977ec556e22a5ddf8a916f776d (patch) | |
tree | 8a92424fa3581e94f8ca3413496fa5d5c72766ba /engines | |
parent | b77f726469fd6ff3ccad633b75fe432392c3201d (diff) | |
download | scummvm-rg350-8f5c91ee07b65f977ec556e22a5ddf8a916f776d.tar.gz scummvm-rg350-8f5c91ee07b65f977ec556e22a5ddf8a916f776d.tar.bz2 scummvm-rg350-8f5c91ee07b65f977ec556e22a5ddf8a916f776d.zip |
LAB: Move all the tile puzzle related functionality into its own class
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/engine.cpp | 15 | ||||
-rw-r--r-- | engines/lab/lab.cpp | 13 | ||||
-rw-r--r-- | engines/lab/lab.h | 18 | ||||
-rw-r--r-- | engines/lab/savegame.cpp | 24 | ||||
-rw-r--r-- | engines/lab/tilepuzzle.cpp | 185 | ||||
-rw-r--r-- | engines/lab/tilepuzzle.h | 70 |
6 files changed, 200 insertions, 125 deletions
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 4cfdd454f9..b80910e091 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -40,6 +40,7 @@ #include "lab/music.h" #include "lab/processroom.h" #include "lab/resource.h" +#include "lab/tilepuzzle.h" #include "lab/utils.h" namespace Lab { @@ -122,8 +123,7 @@ void LabEngine::freeScreens() { for (uint16 imgIdx = 0; imgIdx < 10; imgIdx++) { delete _invImages[imgIdx]; - delete _numberImages[imgIdx]; - _invImages[imgIdx] = _numberImages[imgIdx] = nullptr; + _invImages[imgIdx] = nullptr; } } @@ -459,13 +459,11 @@ void LabEngine::mainGameLoop() { if (_closeDataPtr) { if ((_closeDataPtr->_closeUpType == SPECIALLOCK) && _mainDisplay) - // LAB: Labyrinth specific code - showCombination(_curFileName); + _tilePuzzle->showCombination(_curFileName); else if (((_closeDataPtr->_closeUpType == SPECIALBRICK) || (_closeDataPtr->_closeUpType == SPECIALBRICKNOMOUSE)) && _mainDisplay) - // LAB: Labyrinth specific code - showTile(_curFileName, (bool)(_closeDataPtr->_closeUpType == SPECIALBRICKNOMOUSE)); + _tilePuzzle->showTile(_curFileName, (bool)(_closeDataPtr->_closeUpType == SPECIALBRICKNOMOUSE)); else _graphics->readPict(_curFileName, false); } else @@ -943,10 +941,9 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo if (_closeDataPtr) { if ((_closeDataPtr->_closeUpType == SPECIALLOCK) && _mainDisplay) - // LAB: Labyrinth specific code - mouseCombination(curPos); + _tilePuzzle->mouseCombination(curPos); else if ((_closeDataPtr->_closeUpType == SPECIALBRICK) && _mainDisplay) - mouseTile(curPos); + _tilePuzzle->mouseTile(curPos); else doit = true; } else diff --git a/engines/lab/lab.cpp b/engines/lab/lab.cpp index 7a80f64f9c..be5b9556e1 100644 --- a/engines/lab/lab.cpp +++ b/engines/lab/lab.cpp @@ -43,6 +43,7 @@ #include "lab/music.h" #include "lab/processroom.h" #include "lab/resource.h" +#include "lab/tilepuzzle.h" #include "lab/utils.h" namespace Lab { @@ -86,6 +87,7 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc) _anim = nullptr; _graphics = nullptr; _rooms = nullptr; + _tilePuzzle = nullptr; _utils = nullptr; _lastTooLong = false; @@ -97,12 +99,8 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc) for (int i = 0; i < 10; i++) { _invImages[i] = nullptr; - _numberImages[i] = nullptr; } - for (int i = 0; i < 16; i++) - _tiles[i] = nullptr; - _curFileName = nullptr; _nextFileName = nullptr; _newFileName = nullptr; @@ -128,8 +126,6 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc) _imgXMark = nullptr; _maps = nullptr; - initTilePuzzle(); - //const Common::FSNode gameDataDir(ConfMan.get("path")); //SearchMan.addSubDirectoryMatching(gameDataDir, "game"); //SearchMan.addSubDirectoryMatching(gameDataDir, "game/pict"); @@ -147,6 +143,7 @@ LabEngine::~LabEngine() { delete _anim; delete _graphics; delete[] _rooms; + delete _tilePuzzle; delete _utils; delete _imgMap; delete _imgRoom; @@ -164,9 +161,6 @@ LabEngine::~LabEngine() { delete _imgMapWest; delete _imgXMark; delete _maps; - - for (int i = 0; i < 16; i++) - delete _tiles[i]; } Common::Error LabEngine::run() { @@ -180,6 +174,7 @@ Common::Error LabEngine::run() { _music = new Music(this); _graphics = new DisplayMan(this); _anim = new Anim(this); + _tilePuzzle = new TilePuzzle(this); _utils = new Utils(this); if (getPlatform() == Common::kPlatformWindows) { diff --git a/engines/lab/lab.h b/engines/lab/lab.h index b407f319bf..7160df51f9 100644 --- a/engines/lab/lab.h +++ b/engines/lab/lab.h @@ -58,6 +58,7 @@ class Image; class LargeSet; class Music; class Resource; +class TilePuzzle; class Utils; enum GameFeatures { @@ -133,6 +134,7 @@ public: Anim *_anim; DisplayMan *_graphics; RoomData *_rooms; + TilePuzzle *_tilePuzzle; Utils *_utils; int _roomNum; @@ -160,16 +162,12 @@ public: GadgetList _invGadgetList; Image *_moveImages[20]; Image *_invImages[10]; - Image *_numberImages[10]; - uint16 _curTile[4][4]; - byte _combination[6]; private: int _lastWaitTOFTicks; bool _lastTooLong; CloseDataPtr _closeDataPtr; InventoryData *_inventory; - Image *_tiles[16]; GadgetList _journalGadgetList; GadgetList _mapGadgetList; Image *_imgMap, *_imgRoom, *_imgUpArrowRoom, *_imgDownArrowRoom, *_imgBridge; @@ -213,7 +211,6 @@ public: char *getPictName(CloseDataPtr *closePtrList); private: - // engine.cpp void freeScreens(); void perFlipGadget(uint16 gadID); bool doCloseUp(CloseDataPtr closePtr); @@ -222,17 +219,6 @@ private: void mayShowCrumbIndicator(); void mayShowCrumbIndicatorOff(); const char *getInvName(uint16 curInv); - void mouseTile(Common::Point pos); - void changeTile(uint16 col, uint16 row); - void mouseCombination(Common::Point pos); - void doTile(bool showsolution); - void showTile(const char *filename, bool showsolution); - void doTileScroll(uint16 col, uint16 row, uint16 scrolltype); - void changeCombination(uint16 number); - void scrollRaster(int16 dx, int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer); - void doCombination(); - void showCombination(const char *filename); - void initTilePuzzle(); bool saveRestoreGame(); Common::Rect roomCoords(uint16 curRoom); void drawRoomMap(uint16 curRoom, bool drawMarkFl); diff --git a/engines/lab/savegame.cpp b/engines/lab/savegame.cpp index 686b537182..622c1a5cdb 100644 --- a/engines/lab/savegame.cpp +++ b/engines/lab/savegame.cpp @@ -28,6 +28,7 @@ * */ +#include "common/savefile.h" #include "common/translation.h" #include "gui/message.h" @@ -43,6 +44,7 @@ #include "lab/music.h" #include "lab/processroom.h" #include "lab/savegame.h" +#include "lab/tilepuzzle.h" namespace Lab { @@ -122,7 +124,7 @@ bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { * Writes the game out to disk. */ bool saveGame(uint16 Direction, uint16 Quarters, int slot, Common::String desc) { - uint16 i, j; + uint16 i; Common::String fileName = g_lab->generateSaveFileName(slot); Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); Common::OutSaveFile *file = saveFileManager->openForSaving(fileName); @@ -147,14 +149,7 @@ bool saveGame(uint16 Direction, uint16 Quarters, int slot, Common::String desc) for (i = 0; i < g_lab->_roomsFound->_lastElement / (8 * 2); i++) file->writeUint16LE(g_lab->_roomsFound->_array[i]); - // Combination lock and tile stuff - for (i = 0; i < 6; i++) - file->writeByte(g_lab->_combination[i]); - - // Tiles - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - file->writeUint16LE(g_lab->_curTile[i][j]); + g_lab->_tilePuzzle->save(file); // Breadcrumbs for (i = 0; i < sizeof(g_lab->_breadCrumbs); i++) { @@ -173,7 +168,7 @@ bool saveGame(uint16 Direction, uint16 Quarters, int slot, Common::String desc) * Reads the game from disk. */ bool loadGame(uint16 *Direction, uint16 *Quarters, int slot) { - uint16 i, j; + uint16 i; Common::String fileName = g_lab->generateSaveFileName(slot); Common::SaveFileManager *saveFileManager = g_system->getSavefileManager(); Common::InSaveFile *file = saveFileManager->openForLoading(fileName); @@ -195,14 +190,7 @@ bool loadGame(uint16 *Direction, uint16 *Quarters, int slot) { for (i = 0; i < g_lab->_roomsFound->_lastElement / (8 * 2); i++) g_lab->_roomsFound->_array[i] = file->readUint16LE(); - // Combination lock and tile stuff - for (i = 0; i < 6; i++) - g_lab->_combination[i] = file->readByte(); - - // Tiles - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - g_lab->_curTile[i][j] = file->readUint16LE(); + g_lab->_tilePuzzle->load(file); // Breadcrumbs for (i = 0; i < 128; i++) { diff --git a/engines/lab/tilepuzzle.cpp b/engines/lab/tilepuzzle.cpp index 652c633c61..782bcda483 100644 --- a/engines/lab/tilepuzzle.cpp +++ b/engines/lab/tilepuzzle.cpp @@ -33,12 +33,12 @@ #include "gui/message.h" #include "lab/lab.h" - #include "lab/anim.h" #include "lab/dispman.h" #include "lab/image.h" #include "lab/labsets.h" #include "lab/resource.h" +#include "lab/tilepuzzle.h" #include "lab/utils.h" namespace Lab { @@ -59,7 +59,7 @@ const uint16 SOLUTION[4][4] = { const int COMBINATION_X[6] = { 45, 83, 129, 166, 211, 248 }; -void LabEngine::initTilePuzzle() { +TilePuzzle::TilePuzzle(LabEngine *vm) : _vm(vm) { for (int i = 0; i < 16; i++) _tiles[i] = nullptr; @@ -70,13 +70,26 @@ void LabEngine::initTilePuzzle() { for (int i = 0; i < 6; i++) _combination[i] = 0; + + for (int i = 0; i < 10; i++) + _numberImages[i] = nullptr; +} + +TilePuzzle::~TilePuzzle() { + for (int i = 0; i < 16; i++) + delete _tiles[i]; + + for (uint16 imgIdx = 0; imgIdx < 10; imgIdx++) { + delete _numberImages[imgIdx]; + _numberImages[imgIdx] = nullptr; + } } /** * Processes mouse clicks and changes the combination. */ -void LabEngine::mouseTile(Common::Point pos) { - Common::Point realPos = _utils->vgaUnscale(pos); +void TilePuzzle::mouseTile(Common::Point pos) { + Common::Point realPos = _vm->_utils->vgaUnscale(pos); if ((realPos.x < 101) || (realPos.y < 26)) return; @@ -91,7 +104,7 @@ void LabEngine::mouseTile(Common::Point pos) { /** * Changes the combination number of one of the slots */ -void LabEngine::changeTile(uint16 col, uint16 row) { +void TilePuzzle::changeTile(uint16 col, uint16 row) { int16 scrolltype = -1; if (row > 0) { @@ -129,7 +142,7 @@ void LabEngine::changeTile(uint16 col, uint16 row) { if (scrolltype != -1) { doTileScroll(col, row, scrolltype); - if (getFeatures() & GF_WINDOWS_TRIAL) { + if (_vm->getFeatures() & GF_WINDOWS_TRIAL) { GUI::MessageDialog trialMessage("This puzzle is not available in the trial version of the game"); trialMessage.runModal(); return; @@ -151,9 +164,9 @@ void LabEngine::changeTile(uint16 col, uint16 row) { if (check) { // unlocked combination - _conditions->inclElement(BRICKOPEN); - _anim->_doBlack = true; - _graphics->readPict("p:Up/BDOpen", true); + _vm->_conditions->inclElement(BRICKOPEN); + _vm->_anim->_doBlack = true; + _vm->_graphics->readPict("p:Up/BDOpen", true); } } } @@ -161,8 +174,8 @@ void LabEngine::changeTile(uint16 col, uint16 row) { /** * Processes mouse clicks and changes the combination. */ -void LabEngine::mouseCombination(Common::Point pos) { - Common::Point realPos = _utils->vgaUnscale(pos); +void TilePuzzle::mouseCombination(Common::Point pos) { + Common::Point realPos = _vm->_utils->vgaUnscale(pos); if (!Common::Rect(44, 63, 285, 99).contains(realPos)) return; @@ -187,25 +200,25 @@ void LabEngine::mouseCombination(Common::Point pos) { /** * Draws the images of the combination lock to the display bitmap. */ -void LabEngine::doTile(bool showsolution) { +void TilePuzzle::doTile(bool showsolution) { uint16 row = 0, col = 0, rowm, colm, num; int16 rows, cols; if (showsolution) { - rowm = _utils->vgaScaleY(23); - colm = _utils->vgaScaleX(27); + rowm = _vm->_utils->vgaScaleY(23); + colm = _vm->_utils->vgaScaleX(27); - rows = _utils->vgaScaleY(31); - cols = _utils->vgaScaleX(105); + rows = _vm->_utils->vgaScaleY(31); + cols = _vm->_utils->vgaScaleX(105); } else { - _graphics->setAPen(0); - _graphics->rectFillScaled(97, 22, 220, 126); + _vm->_graphics->setAPen(0); + _vm->_graphics->rectFillScaled(97, 22, 220, 126); - rowm = _utils->vgaScaleY(25); - colm = _utils->vgaScaleX(30); + rowm = _vm->_utils->vgaScaleY(25); + colm = _vm->_utils->vgaScaleX(30); - rows = _utils->vgaScaleY(25); - cols = _utils->vgaScaleX(100); + rows = _vm->_utils->vgaScaleY(25); + cols = _vm->_utils->vgaScaleX(100); } while (row < 4) { @@ -229,63 +242,63 @@ void LabEngine::doTile(bool showsolution) { /** * Reads in a backdrop picture. */ -void LabEngine::showTile(const char *filename, bool showsolution) { - uint16 start = showsolution ? 0 : 1; +void TilePuzzle::showTile(const char *filename, bool showSolution) { + uint16 start = showSolution ? 0 : 1; - _anim->_doBlack = true; - _anim->_noPalChange = true; - _graphics->readPict(filename, true); - _anim->_noPalChange = false; - _graphics->blackScreen(); + _vm->_anim->_doBlack = true; + _vm->_anim->_noPalChange = true; + _vm->_graphics->readPict(filename, true); + _vm->_anim->_noPalChange = false; + _vm->_graphics->blackScreen(); - Common::File *tileFile = tileFile = _resource->openDataFile(showsolution ? "P:TileSolution" : "P:Tile"); + Common::File *tileFile = _vm->_resource->openDataFile(showSolution ? "P:TileSolution" : "P:Tile"); for (uint16 curBit = start; curBit < 16; curBit++) _tiles[curBit] = new Image(tileFile); delete tileFile; - doTile(showsolution); - _graphics->setPalette(_anim->_diffPalette, 256); + doTile(showSolution); + _vm->_graphics->setPalette(_vm->_anim->_diffPalette, 256); } /** * Does the scrolling for the tiles on the tile puzzle. */ -void LabEngine::doTileScroll(uint16 col, uint16 row, uint16 scrolltype) { +void TilePuzzle::doTileScroll(uint16 col, uint16 row, uint16 scrolltype) { int16 dX = 0, dY = 0, dx = 0, dy = 0, sx = 0, sy = 0; uint16 last = 0; if (scrolltype == LEFTSCROLL) { - dX = _utils->vgaScaleX(5); - sx = _utils->vgaScaleX(5); + dX = _vm->_utils->vgaScaleX(5); + sx = _vm->_utils->vgaScaleX(5); last = 6; } else if (scrolltype == RIGHTSCROLL) { - dX = _utils->vgaScaleX(-5); - dx = _utils->vgaScaleX(-5); - sx = _utils->vgaScaleX(5); + dX = _vm->_utils->vgaScaleX(-5); + dx = _vm->_utils->vgaScaleX(-5); + sx = _vm->_utils->vgaScaleX(5); last = 6; } else if (scrolltype == UPSCROLL) { - dY = _utils->vgaScaleY(5); - sy = _utils->vgaScaleY(5); + dY = _vm->_utils->vgaScaleY(5); + sy = _vm->_utils->vgaScaleY(5); last = 5; } else if (scrolltype == DOWNSCROLL) { - dY = _utils->vgaScaleY(-5); - dy = _utils->vgaScaleY(-5); - sy = _utils->vgaScaleY(5); + dY = _vm->_utils->vgaScaleY(-5); + dy = _vm->_utils->vgaScaleY(-5); + sy = _vm->_utils->vgaScaleY(5); last = 5; } - sx += _utils->svgaCord(2); + sx += _vm->_utils->svgaCord(2); - uint16 x1 = _utils->vgaScaleX(100) + (col * _utils->vgaScaleX(30)) + dx; - uint16 y1 = _utils->vgaScaleY(25) + (row * _utils->vgaScaleY(25)) + dy; + uint16 x1 = _vm->_utils->vgaScaleX(100) + (col * _vm->_utils->vgaScaleX(30)) + dx; + uint16 y1 = _vm->_utils->vgaScaleY(25) + (row * _vm->_utils->vgaScaleY(25)) + dy; byte *buffer = new byte[_tiles[1]->_width * _tiles[1]->_height * 2L]; for (uint16 i = 0; i < last; i++) { - waitTOF(); - scrollRaster(dX, dY, x1, y1, x1 + _utils->vgaScaleX(28) + sx, y1 + _utils->vgaScaleY(23) + sy, buffer); + _vm->waitTOF(); + scrollRaster(dX, dY, x1, y1, x1 + _vm->_utils->vgaScaleX(28) + sx, y1 + _vm->_utils->vgaScaleY(23) + sy, buffer); x1 += dX; y1 += dY; } @@ -296,7 +309,7 @@ void LabEngine::doTileScroll(uint16 col, uint16 row, uint16 scrolltype) { /** * Changes the combination number of one of the slots */ -void LabEngine::changeCombination(uint16 number) { +void TilePuzzle::changeCombination(uint16 number) { const int solution[6] = { 0, 4, 0, 8, 7, 2 }; Image display; @@ -310,22 +323,22 @@ void LabEngine::changeCombination(uint16 number) { combnum = _combination[number]; - display._imageData = _graphics->getCurrentDrawingBuffer(); - display._width = _graphics->_screenWidth; - display._height = _graphics->_screenHeight; + display._imageData = _vm->_graphics->getCurrentDrawingBuffer(); + display._width = _vm->_graphics->_screenWidth; + display._height = _vm->_graphics->_screenHeight; byte *buffer = new byte[_tiles[1]->_width * _tiles[1]->_height * 2L]; for (uint16 i = 1; i <= (_numberImages[combnum]->_height / 2); i++) { - if (_isHiRes) { + if (_vm->_isHiRes) { if (i & 1) - waitTOF(); + _vm->waitTOF(); } else - waitTOF(); + _vm->waitTOF(); - display._imageData = _graphics->getCurrentDrawingBuffer(); - _graphics->scrollDisplayY(2, _utils->vgaScaleX(COMBINATION_X[number]), _utils->vgaScaleY(65), _utils->vgaScaleX(COMBINATION_X[number]) + (_numberImages[combnum])->_width - 1, _utils->vgaScaleY(65) + (_numberImages[combnum])->_height, buffer); - _numberImages[combnum]->blitBitmap(0, (_numberImages[combnum])->_height - (2 * i), &(display), _utils->vgaScaleX(COMBINATION_X[number]), _utils->vgaScaleY(65), (_numberImages[combnum])->_width, 2, false); + display._imageData = _vm->_graphics->getCurrentDrawingBuffer(); + _vm->_graphics->scrollDisplayY(2, _vm->_utils->vgaScaleX(COMBINATION_X[number]), _vm->_utils->vgaScaleY(65), _vm->_utils->vgaScaleX(COMBINATION_X[number]) + (_numberImages[combnum])->_width - 1, _vm->_utils->vgaScaleY(65) + (_numberImages[combnum])->_height, buffer); + _numberImages[combnum]->blitBitmap(0, (_numberImages[combnum])->_height - (2 * i), &(display), _vm->_utils->vgaScaleX(COMBINATION_X[number]), _vm->_utils->vgaScaleY(65), (_numberImages[combnum])->_width, 2, false); } delete[] buffer; @@ -334,39 +347,39 @@ void LabEngine::changeCombination(uint16 number) { unlocked &= (_combination[i] == solution[i]); if (unlocked) - _conditions->inclElement(COMBINATIONUNLOCKED); + _vm->_conditions->inclElement(COMBINATIONUNLOCKED); else - _conditions->exclElement(COMBINATIONUNLOCKED); + _vm->_conditions->exclElement(COMBINATIONUNLOCKED); } -void LabEngine::scrollRaster(int16 dx, int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer) { +void TilePuzzle::scrollRaster(int16 dx, int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer) { if (dx) - _graphics->scrollDisplayX(dx, x1, y1, x2, y2, buffer); + _vm->_graphics->scrollDisplayX(dx, x1, y1, x2, y2, buffer); if (dy) - _graphics->scrollDisplayY(dy, x1, y1, x2, y2, buffer); + _vm->_graphics->scrollDisplayY(dy, x1, y1, x2, y2, buffer); } /** * Draws the images of the combination lock to the display bitmap. */ -void LabEngine::doCombination() { +void TilePuzzle::doCombination() { for (uint16 i = 0; i <= 5; i++) - _numberImages[_combination[i]]->drawImage(_utils->vgaScaleX(COMBINATION_X[i]), _utils->vgaScaleY(65)); + _numberImages[_combination[i]]->drawImage(_vm->_utils->vgaScaleX(COMBINATION_X[i]), _vm->_utils->vgaScaleY(65)); } /** * Reads in a backdrop picture. */ -void LabEngine::showCombination(const char *filename) { - _anim->_doBlack = true; - _anim->_noPalChange = true; - _graphics->readPict(filename, true); - _anim->_noPalChange = false; +void TilePuzzle::showCombination(const char *filename) { + _vm->_anim->_doBlack = true; + _vm->_anim->_noPalChange = true; + _vm->_graphics->readPict(filename, true); + _vm->_anim->_noPalChange = false; - _graphics->blackScreen(); + _vm->_graphics->blackScreen(); - Common::File *numFile = _resource->openDataFile("P:Numbers"); + Common::File *numFile = _vm->_resource->openDataFile("P:Numbers"); for (uint16 CurBit = 0; CurBit < 10; CurBit++) _numberImages[CurBit] = new Image(numFile); @@ -375,7 +388,33 @@ void LabEngine::showCombination(const char *filename) { doCombination(); - _graphics->setPalette(_anim->_diffPalette, 256); + _vm->_graphics->setPalette(_vm->_anim->_diffPalette, 256); +} + +void TilePuzzle::save(Common::OutSaveFile *file) { + uint16 i, j; + + // Combination lock and tile stuff + for (i = 0; i < 6; i++) + file->writeByte(_combination[i]); + + // Tiles + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + file->writeUint16LE(_curTile[i][j]); +} + +void TilePuzzle::load(Common::InSaveFile *file) { + uint16 i, j; + + // Combination lock and tile stuff + for (i = 0; i < 6; i++) + _combination[i] = file->readByte(); + + // Tiles + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + _curTile[i][j] = file->readUint16LE(); } } // End of namespace Lab diff --git a/engines/lab/tilepuzzle.h b/engines/lab/tilepuzzle.h new file mode 100644 index 0000000000..a20f4ce04a --- /dev/null +++ b/engines/lab/tilepuzzle.h @@ -0,0 +1,70 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This code is based on Labyrinth of Time code with assistance of + * + * Copyright (c) 1993 Terra Nova Development + * Copyright (c) 2004 The Wyrmkeep Entertainment Co. + * + */ + +#ifndef LAB_TILEPUZZLE_H +#define LAB_TILEPUZZLE_H + +#include "common/savefile.h" + +namespace Lab { + +class LabEngine; + +class TilePuzzle { +private: + LabEngine *_vm; + Image *_tiles[16]; + Image *_numberImages[10]; + uint16 _curTile[4][4]; + byte _combination[6]; + +public: + TilePuzzle(LabEngine *vm); + virtual ~TilePuzzle(); + + void mouseTile(Common::Point pos); + void showTile(const char *filename, bool showSolution); + void mouseCombination(Common::Point pos); + void showCombination(const char *filename); + void save(Common::OutSaveFile *file); + void load(Common::InSaveFile *file); + +private: + void doTile(bool showsolution); + void doTileScroll(uint16 col, uint16 row, uint16 scrolltype); + void changeCombination(uint16 number); + void scrollRaster(int16 dx, int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer); + void doCombination(); + void changeTile(uint16 col, uint16 row); +}; + +} // End of namespace Lab + +#endif // LAB_TILEPUZZLE_H |