From 58eefc0833a540213298f75e87222b12831dd1f7 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 27 Feb 2013 00:15:54 +0100 Subject: HOPKINS: Get rid of magic values in FilesManager --- engines/hopkins/files.cpp | 22 +++++++++++----------- engines/hopkins/files.h | 7 ++++++- engines/hopkins/graphics.cpp | 10 +++++----- engines/hopkins/objects.cpp | 6 +++--- engines/hopkins/sound.cpp | 6 +++--- engines/hopkins/talk.cpp | 10 +++++----- 6 files changed, 33 insertions(+), 28 deletions(-) (limited to 'engines') diff --git a/engines/hopkins/files.cpp b/engines/hopkins/files.cpp index e0cd1a3995..5a15c1d68d 100644 --- a/engines/hopkins/files.cpp +++ b/engines/hopkins/files.cpp @@ -96,7 +96,7 @@ bool FileManager::fileExists(const Common::String &file) { /** * Search file in Cat file */ -byte *FileManager::searchCat(const Common::String &file, int a2) { +byte *FileManager::searchCat(const Common::String &file, CatMode mode) { byte *ptr = NULL; Common::File f; @@ -104,8 +104,8 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { Common::String secondaryFilename = ""; filename.toUppercase(); - switch (a2) { - case 1: + switch (mode) { + case RES_INI: if (!f.exists("RES_INI.CAT")) return g_PTRNUL; @@ -113,7 +113,7 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { secondaryFilename = "RES_INI.RES"; break; - case 2: + case RES_REP: if (!f.exists("RES_REP.CAT")) return g_PTRNUL; @@ -121,7 +121,7 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { secondaryFilename = "RES_REP.RES"; break; - case 3: + case RES_LIN: if (!f.exists("RES_LIN.CAT")) return g_PTRNUL; @@ -129,7 +129,7 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { secondaryFilename = "RES_LIN.RES"; break; - case 4: + case RES_ANI: if (!f.exists("RES_ANI.CAT")) return g_PTRNUL; @@ -137,7 +137,7 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { secondaryFilename = "RES_ANI.RES"; break; - case 5: + case RES_PER: if (!f.exists("RES_PER.CAT")) return g_PTRNUL; @@ -145,28 +145,28 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { secondaryFilename = "RES_PER.RES"; break; - case 6: + case RES_PIC: if (!f.exists("PIC.CAT")) return g_PTRNUL; ptr = loadFile("PIC.CAT"); break; - case 7: + case RES_SAN: if (!f.exists("RES_SAN.CAT")) return g_PTRNUL; ptr = loadFile("RES_SAN.CAT"); break; - case 8: + case RES_SLI: if (!f.exists("RES_SLI.CAT")) return g_PTRNUL; ptr = loadFile("RES_SLI.CAT"); break; - case 9: { + case RES_VOI: { Common::String tmpFilename; if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) tmpFilename = "ENG_VOI.CAT"; diff --git a/engines/hopkins/files.h b/engines/hopkins/files.h index 55a57955b2..461bd22bf2 100644 --- a/engines/hopkins/files.h +++ b/engines/hopkins/files.h @@ -32,6 +32,11 @@ namespace Hopkins { class HopkinsEngine; +// CHECKME: RES_ANI looks unused +enum CatMode { RES_INI = 1, RES_REP = 2, RES_LIN = 3, RES_ANI = 4, + RES_PER = 5, RES_PIC = 6, RES_SAN = 7, RES_SLI = 8, + RES_VOI = 9 }; + class FileManager { public: HopkinsEngine *_vm; @@ -43,7 +48,7 @@ public: byte *loadFile(const Common::String &file); int readStream(Common::ReadStream &stream, void *buf, size_t nbytes); void initCensorship(); - byte *searchCat(const Common::String &file, int a2); + byte *searchCat(const Common::String &file, CatMode mode); uint32 fileSize(const Common::String &filename); }; diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp index ef2e07de31..51c6e2a733 100644 --- a/engines/hopkins/graphics.cpp +++ b/engines/hopkins/graphics.cpp @@ -193,7 +193,7 @@ void GraphicsManager::loadScreen(const Common::String &file) { Common::File f; bool flag = true; - if (_vm->_fileManager.searchCat(file, 6) == g_PTRNUL) { + if (_vm->_fileManager.searchCat(file, RES_PIC) == g_PTRNUL) { if (!f.open(file)) error("loadScreen - %s", file.c_str()); @@ -1678,7 +1678,7 @@ void GraphicsManager::displayFont(byte *surface, const byte *spriteData, int xp, void GraphicsManager::initScreen(const Common::String &file, int mode, bool initializeScreen) { Common::String filename = file + ".ini"; - byte *ptr = _vm->_fileManager.searchCat(filename, 1); + byte *ptr = _vm->_fileManager.searchCat(filename, RES_INI); if (ptr == g_PTRNUL) { ptr = _vm->_fileManager.loadFile(filename); @@ -1687,7 +1687,7 @@ void GraphicsManager::initScreen(const Common::String &file, int mode, bool init filename = file + ".spr"; _vm->_globals.SPRITE_ECRAN = _vm->_globals.freeMemory(_vm->_globals.SPRITE_ECRAN); if (initializeScreen) { - _vm->_globals.SPRITE_ECRAN = _vm->_fileManager.searchCat(filename, 8); + _vm->_globals.SPRITE_ECRAN = _vm->_fileManager.searchCat(filename, RES_SLI); if (_vm->_globals.SPRITE_ECRAN) { _vm->_globals.SPRITE_ECRAN = _vm->_fileManager.loadFile(filename); } else { @@ -1696,7 +1696,7 @@ void GraphicsManager::initScreen(const Common::String &file, int mode, bool init } } if (READ_BE_UINT24(ptr) != MKTAG24('I', 'N', 'I')) { - error("Error, file not ini"); + error("Invalid INI File %s", file); } else { bool doneFlag = false; int dataOffset = 1; @@ -1722,7 +1722,7 @@ void GraphicsManager::initScreen(const Common::String &file, int mode, bool init _vm->_globals._answerBuffer = _vm->_globals.freeMemory(_vm->_globals._answerBuffer); filename = file + ".rep"; - byte *dataP = _vm->_fileManager.searchCat(filename, 2); + byte *dataP = _vm->_fileManager.searchCat(filename, RES_REP); if (dataP == g_PTRNUL) dataP = _vm->_fileManager.loadFile(filename); diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp index f6c057b7d3..836fc0df0f 100644 --- a/engines/hopkins/objects.cpp +++ b/engines/hopkins/objects.cpp @@ -2535,7 +2535,7 @@ void ObjectsManager::OPTI_OBJET() { int lastOpcodeResult = 1; file = "OBJET1.ini"; - data = _vm->_fileManager.searchCat(file, 1); + data = _vm->_fileManager.searchCat(file, RES_INI); if (data == g_PTRNUL) { data = _vm->_fileManager.loadFile(file); if (data == g_PTRNUL) @@ -3047,7 +3047,7 @@ int ObjectsManager::getBobFrameIndex(int idx) { void ObjectsManager::loadLinkFile(const Common::String &file) { Common::File f; Common::String filename = file + ".LNK"; - byte *ptr = _vm->_fileManager.searchCat(filename, 3); + byte *ptr = _vm->_fileManager.searchCat(filename, RES_LIN); size_t nbytes = _vm->_globals._catalogSize; if (ptr == g_PTRNUL) { if (!f.open(filename)) @@ -3068,7 +3068,7 @@ void ObjectsManager::loadLinkFile(const Common::String &file) { Common::String filename2 = Common::String((const char *)ptr + 1000); if (!filename2.empty()) { - _vm->_globals._hidingItemData[1] = _vm->_fileManager.searchCat(filename2, 8); + _vm->_globals._hidingItemData[1] = _vm->_fileManager.searchCat(filename2, RES_SLI); if (_vm->_globals._hidingItemData[1] || _vm->_globals._hidingItemData[1] == g_PTRNUL) { _vm->_globals._hidingItemData[1] = _vm->_fileManager.loadFile(filename2); diff --git a/engines/hopkins/sound.cpp b/engines/hopkins/sound.cpp index de8b1115db..55c1155008 100644 --- a/engines/hopkins/sound.cpp +++ b/engines/hopkins/sound.cpp @@ -520,7 +520,7 @@ bool SoundManager::mixVoice(int voiceId, int voiceMode, bool dispTxtFl) { filename = Common::String::format("%s%d", prefix.c_str(), mappedFileNumber); - if (!_vm->_fileManager.searchCat(filename + ".WAV", 9)) { + if (!_vm->_fileManager.searchCat(filename + ".WAV", RES_VOI)) { if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) filename = "ENG_VOI.RES"; // Win95 and Linux versions uses another set of names @@ -533,7 +533,7 @@ bool SoundManager::mixVoice(int voiceId, int voiceMode, bool dispTxtFl) { catPos = _vm->_globals._catalogPos; catLen = _vm->_globals._catalogSize; - } else if (!_vm->_fileManager.searchCat(filename + ".APC", 9)) { + } else if (!_vm->_fileManager.searchCat(filename + ".APC", RES_VOI)) { if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) filename = "ENG_VOI.RES"; // Win95 and Linux versions uses another set of names @@ -546,7 +546,7 @@ bool SoundManager::mixVoice(int voiceId, int voiceMode, bool dispTxtFl) { catPos = _vm->_globals._catalogPos; catLen = _vm->_globals._catalogSize; - } else if (!_vm->_fileManager.searchCat(filename + ".RAW", 9)) { + } else if (!_vm->_fileManager.searchCat(filename + ".RAW", RES_VOI)) { if (_vm->getPlatform() == Common::kPlatformOS2 || _vm->getPlatform() == Common::kPlatformBeOS) filename = "ENG_VOI.RES"; // Win95 and Linux versions uses another set of names diff --git a/engines/hopkins/talk.cpp b/engines/hopkins/talk.cpp index 72ad774f9f..98a750d065 100644 --- a/engines/hopkins/talk.cpp +++ b/engines/hopkins/talk.cpp @@ -58,7 +58,7 @@ void TalkManager::startAnimatedCharacterDialogue(const Common::String &filename) _vm->_graphicsManager._scrollStatus = 1; bool oldDisableInventFl = _vm->_globals._disableInventFl; _vm->_globals._disableInventFl = true; - _characterBuffer = _vm->_fileManager.searchCat(filename, 5); + _characterBuffer = _vm->_fileManager.searchCat(filename, RES_PER); _characterSize = _vm->_globals._catalogSize; if (_characterBuffer == g_PTRNUL) { _characterBuffer = _vm->_fileManager.loadFile(filename); @@ -79,7 +79,7 @@ void TalkManager::startAnimatedCharacterDialogue(const Common::String &filename) } _dialogueMesgId1 = READ_LE_INT16((uint16 *)_characterBuffer + 40); _paletteBufferIdx = 20 * READ_LE_INT16((uint16 *)_characterBuffer + 42) + 110; - _characterSprite = _vm->_fileManager.searchCat(spriteFilename, 7); + _characterSprite = _vm->_fileManager.searchCat(spriteFilename, RES_SAN); if (_characterSprite) { _characterSprite = _vm->_objectsManager.loadSprite(spriteFilename); } else { @@ -158,7 +158,7 @@ void TalkManager::startStaticCharacterDialogue(const Common::String &filename) { // TODO: The original disables the mouse cursor here bool oldDisableInventFl = _vm->_globals._disableInventFl; _vm->_globals._disableInventFl = true; - _characterBuffer = _vm->_fileManager.searchCat(filename, 5); + _characterBuffer = _vm->_fileManager.searchCat(filename, RES_PER); _characterSize = _vm->_globals._catalogSize; if (_characterBuffer == g_PTRNUL) { _characterBuffer = _vm->_fileManager.loadFile(filename); @@ -980,7 +980,7 @@ void TalkManager::animateObject(const Common::String &a2) { _vm->_objectsManager._zoneNum = -1; _vm->_eventsManager._mouseCursorId = 4; _vm->_eventsManager.changeMouseCursor(0); - _characterBuffer = _vm->_fileManager.searchCat(a2, 5); + _characterBuffer = _vm->_fileManager.searchCat(a2, RES_PER); _characterSize = _vm->_globals._catalogSize; if (_characterBuffer == g_PTRNUL) { _characterBuffer = _vm->_fileManager.loadFile(a2); @@ -996,7 +996,7 @@ void TalkManager::animateObject(const Common::String &a2) { if (curScreenFilename == "NULL") curScreenFilename = Common::String::format("IM%d", _vm->_globals._screenId); - _characterSprite = _vm->_fileManager.searchCat(spriteFilename, 7); + _characterSprite = _vm->_fileManager.searchCat(spriteFilename, RES_SAN); if (_characterSprite) _characterSprite = _vm->_objectsManager.loadSprite(spriteFilename); else -- cgit v1.2.3