diff options
-rw-r--r-- | engines/xeen/debugger.cpp | 2 | ||||
-rw-r--r-- | engines/xeen/dialogs_quests.cpp | 2 | ||||
-rw-r--r-- | engines/xeen/files.cpp | 137 | ||||
-rw-r--r-- | engines/xeen/files.h | 54 | ||||
-rw-r--r-- | engines/xeen/map.cpp | 37 | ||||
-rw-r--r-- | engines/xeen/map.h | 1 | ||||
-rw-r--r-- | engines/xeen/music.cpp | 8 | ||||
-rw-r--r-- | engines/xeen/music.h | 1 | ||||
-rw-r--r-- | engines/xeen/resources.cpp | 2 | ||||
-rw-r--r-- | engines/xeen/saves.cpp | 20 | ||||
-rw-r--r-- | engines/xeen/sprites.cpp | 4 | ||||
-rw-r--r-- | engines/xeen/sprites.h | 2 | ||||
-rw-r--r-- | engines/xeen/worldofxeen/clouds_cutscenes.cpp | 4 | ||||
-rw-r--r-- | engines/xeen/xeen.cpp | 2 |
14 files changed, 175 insertions, 101 deletions
diff --git a/engines/xeen/debugger.cpp b/engines/xeen/debugger.cpp index 25eab2b7b3..ee96d5c4a4 100644 --- a/engines/xeen/debugger.cpp +++ b/engines/xeen/debugger.cpp @@ -93,8 +93,6 @@ bool Debugger::cmdDump(int argc, const char **argv) { } else { if (argc == 2) f.open(argv[1]); - else - f.open(argv[1], (ArchiveType)strToInt(argv[2])); if (f.isOpen()) { Common::DumpFile df; diff --git a/engines/xeen/dialogs_quests.cpp b/engines/xeen/dialogs_quests.cpp index 6667bf5262..6e337aab95 100644 --- a/engines/xeen/dialogs_quests.cpp +++ b/engines/xeen/dialogs_quests.cpp @@ -245,7 +245,7 @@ void Quests::addButtons() { } void Quests::loadQuestNotes() { - File f("qnotes.bin", _vm->getGameID() == GType_Clouds ? GAME_ARCHIVE : ALTSIDE_ARCHIVE); + File f("qnotes.bin"); while (f.pos() < f.size()) _questNotes.push_back(f.readString()); f.close(); diff --git a/engines/xeen/files.cpp b/engines/xeen/files.cpp index 06dd3d12a7..b62a0d8cd5 100644 --- a/engines/xeen/files.cpp +++ b/engines/xeen/files.cpp @@ -26,6 +26,7 @@ #include "common/textconsole.h" #include "xeen/xeen.h" #include "xeen/files.h" +#include "xeen/saves.h" namespace Xeen { @@ -120,7 +121,7 @@ int BaseCCArchive::listMembers(Common::ArchiveMemberList &list) const { CCArchive::CCArchive(const Common::String &filename, bool encoded): BaseCCArchive(), _filename(filename), _encoded(encoded) { - File f(filename); + File f(filename, SearchMan); loadIndex(&f); } @@ -128,7 +129,7 @@ CCArchive::CCArchive(const Common::String &filename, const Common::String &prefi bool encoded): BaseCCArchive(), _filename(filename), _prefix(prefix), _encoded(encoded) { _prefix.toLowercase(); - File f(filename); + File f(filename, SearchMan); loadIndex(&f); } @@ -183,71 +184,67 @@ Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::S /*------------------------------------------------------------------------*/ -CCArchive *FileManager::_archives[3]; - FileManager::FileManager(XeenEngine *vm) { Common::File f; int sideNum = 0; - File::_currentArchive = ANY_ARCHIVE; _isDarkCc = vm->getGameID() == GType_DarkSide; - _archives[0] = _archives[1] = _archives[2] = nullptr; - - if (vm->getGameID() != GType_DarkSide) { - _archives[0] = new CCArchive("xeen.cc", "xeen", true); - SearchMan.add("xeen", _archives[0]); - sideNum = 1; + + File::_xeenCc = (vm->getGameID() == GType_DarkSide) ? nullptr : + new CCArchive("xeen.cc", "xeen", true); + File::_darkCc = (vm->getGameID() == GType_Clouds) ? nullptr : + new CCArchive("dark.cc", "dark", true); + if (Common::File::exists("intro.cc")) { + CCArchive *introCc = new CCArchive("intro.cc", "intro", true); + SearchMan.add("intro", introCc); } - if (vm->getGameID() == GType_DarkSide || vm->getGameID() == GType_WorldOfXeen) { - _archives[sideNum] = new CCArchive("dark.cc", "dark", true); - SearchMan.add("dark", _archives[sideNum]); - } + File::_currentArchive = vm->getGameID() == GType_DarkSide ? + File::_darkCc : File::_xeenCc; + assert(File::_currentArchive); +} - if (f.exists("intro.cc")) { - _archives[2] = new CCArchive("intro.cc", "intro", true); - SearchMan.add("intro", _archives[2]); - } +FileManager::~FileManager() { + SearchMan.remove("intro"); + delete File::_xeenCc; + delete File::_darkCc; } -void FileManager::setGameCc(bool isDarkCc) { - _isDarkCc = isDarkCc; - File::_currentArchive = isDarkCc ? ALTSIDE_ARCHIVE : GAME_ARCHIVE; +void FileManager::setGameCc(int ccMode) { + if (g_vm->getGameID() != GType_WorldOfXeen) + ccMode = 1; + + File::setCurrentArchive(ccMode); + _isDarkCc = ccMode != 0; } /*------------------------------------------------------------------------*/ -ArchiveType File::_currentArchive; +CCArchive *File::_currentArchive; +CCArchive *File::_xeenCc; +CCArchive *File::_darkCc; File::File(const Common::String &filename) { File::open(filename); } -File::File(const Common::String &filename, ArchiveType archiveType) { - File::open(filename, archiveType); -} - File::File(const Common::String &filename, Common::Archive &archive) { File::open(filename, archive); } -bool File::open(const Common::String &filename) { - return File::open(filename, _currentArchive); +File::File(const Common::String &filename, int ccMode) { + File::open(filename, ccMode); } -bool File::open(const Common::String &filename, ArchiveType archiveType) { - if (archiveType == ANY_ARCHIVE) { - Common::File::open(filename); - } else { - CCArchive &archive = *FileManager::_archives[archiveType]; - if (!Common::File::open(filename, archive)) - // If not in the designated archive, try opening from any archive, - // or as a standalone file in the filesystem - Common::File::open(filename); +bool File::open(const Common::String &filename) { + if (!g_vm->_saves || !Common::File::open(filename, *g_vm->_saves)) { + if (!Common::File::open(filename, *_currentArchive)) { + // Could not find in current archive, so try intro.cc or in folder + if (!Common::File::open(filename)) + error("Could not open file - %s", filename.c_str()); + } } - if (!isOpen()) - error("Could not open file - %s", filename.c_str()); return true; } @@ -257,6 +254,34 @@ bool File::open(const Common::String &filename, Common::Archive &archive) { return true; } +bool File::open(const Common::String &filename, int ccMode) { + FileManager &files = *g_vm->_files; + int oldMode = files._isDarkCc ? 1 : 0; + + files.setGameCc(ccMode); + File::open(filename); + files.setGameCc(oldMode); + + return true; +} + +void File::setCurrentArchive(int ccMode) { + switch (ccMode) { + case 0: + _currentArchive = _xeenCc; + break; + + case 1: + _currentArchive = _darkCc; + break; + + default: + break; + } + + assert(_currentArchive); +} + Common::String File::readString() { Common::String result; char c; @@ -267,18 +292,42 @@ Common::String File::readString() { return result; } +bool File::exists(const Common::String &filename) { + if (!g_vm->_saves || !g_vm->_saves->hasFile(filename)) { + if (!_currentArchive->hasFile(filename)) { + // Could not find in current archive, so try intro.cc or in folder + return Common::File::exists(filename); + } + } + + return true; +} + +bool File::exists(const Common::String &filename, int ccMode) { + FileManager &files = *g_vm->_files; + int oldMode = files._isDarkCc ? 1 : 0; + + files.setGameCc(ccMode); + bool result = exists(filename); + files.setGameCc(oldMode); + + return result; +} + /*------------------------------------------------------------------------*/ void StringArray::load(const Common::String &name) { - load(name, ANY_ARCHIVE); + File f(name); + clear(); + while (f.pos() < f.size()) + push_back(f.readString()); } -void StringArray::load(const Common::String &name, ArchiveType archiveType) { - File f(name, archiveType); +void StringArray::load(const Common::String &name, int ccMode) { + File f(name, ccMode); clear(); while (f.pos() < f.size()) push_back(f.readString()); } - } // End of namespace Xeen diff --git a/engines/xeen/files.h b/engines/xeen/files.h index ffb703374b..1fcfa6a7b8 100644 --- a/engines/xeen/files.h +++ b/engines/xeen/files.h @@ -32,11 +32,6 @@ namespace Xeen { -enum ArchiveType { - ANY_ARCHIVE = -1, GAME_ARCHIVE = 0, ALTSIDE_ARCHIVE = 1, - INTRO_ARCHIVE = 2 -}; - class XeenEngine; class CCArchive; class File; @@ -59,38 +54,44 @@ class File; * Main resource manager */ class FileManager { - friend class File; -private: - static CCArchive *_archives[3]; public: bool _isDarkCc; public: /** - * Instantiates the resource manager + * Constructor */ FileManager(XeenEngine *vm); + + /** + * Destructor + */ + ~FileManager(); /** * Set which game side files to use + * @param ccMode 0=Clouds, 1=Dark Side */ - void setGameCc(bool isDarkCc); + void setGameCc(int ccMode); }; /** * Derived file class */ class File : public Common::File { + friend class FileManager; +private: + static CCArchive *_currentArchive; + static CCArchive *_xeenCc; + static CCArchive *_darkCc; public: - static ArchiveType _currentArchive; - /** * Sets which archive is used by default */ - static void setCurrentArchive(ArchiveType arcType) { _currentArchive = arcType; } + static void setCurrentArchive(int ccMode); public: File() : Common::File() {} File(const Common::String &filename); - File(const Common::String &filename, ArchiveType archiveType); + File(const Common::String &filename, int ccMode); File(const Common::String &filename, Common::Archive &archive); virtual ~File() {} @@ -102,12 +103,12 @@ public: /** * Opens the given file, throwing an error if it can't be opened */ - virtual bool open(const Common::String &filename, ArchiveType archiveType); + virtual bool open(const Common::String &filename, Common::Archive &archive); /** * Opens the given file, throwing an error if it can't be opened */ - virtual bool open(const Common::String &filename, Common::Archive &archive); + virtual bool open(const Common::String &filename, int ccMode); /** * Opens the given file @@ -123,7 +124,26 @@ public: return Common::File::open(stream, name); } + /** + * Reads in a null terminated string + */ Common::String readString(); + + /** + * Checks if a given file exists + * + * @param filename the file to check for + * @return true if the file exists, false otherwise + */ + static bool exists(const Common::String &filename); + + /** + * Checks if a given file exists + * + * @param filename the file to check for + * @return true if the file exists, false otherwise + */ + static bool exists(const Common::String &filename, int ccMode); }; class StringArray : public Common::StringArray { @@ -139,7 +159,7 @@ public: /** * Loads a string array from the specified file */ - void load(const Common::String &name, ArchiveType archiveType); + void load(const Common::String &name, int ccMode); }; class XeenSerializer : public Common::Serializer { diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp index f0c9b57802..6777178d31 100644 --- a/engines/xeen/map.cpp +++ b/engines/xeen/map.cpp @@ -928,6 +928,7 @@ Map::Map(XeenEngine *vm) : _vm(vm), _mobData(vm) { _sideObjects = 0; _sideMonsters = 0; _sidePictures = 0; + _sideMusic = 0; _isOutdoors = false; _mazeDataIndex = 0; _currentSteppedOn = false; @@ -944,6 +945,7 @@ Map::Map(XeenEngine *vm) : _vm(vm), _mobData(vm) { void Map::load(int mapId) { EventsManager &events = *g_vm->_events; + FileManager &files = *g_vm->_files; Interface &intf = *g_vm->_interface; Party &party = *g_vm->_party; Sound &sound = *g_vm->_sound; @@ -974,6 +976,8 @@ void Map::load(int mapId) { } if (_vm->getGameID() == GType_WorldOfXeen) { + files.setGameCc(1); + if (!_loadDarkSide) { _animationInfo.load("clouds.dat"); _monsterData.load("xeen.mon"); @@ -1020,6 +1024,8 @@ void Map::load(int mapId) { break; } } + + files.setGameCc(_loadDarkSide); } // Load any events for the new map @@ -1056,9 +1062,10 @@ void Map::load(int mapId) { // Handle loading text data if (!textLoaded) { textLoaded = true; + Common::String txtName = Common::String::format("%s%c%03d.txt", isDarkCc ? "dark" : "xeen", mapId >= 100 ? 'x' : '0', mapId); - File fText(txtName); + File fText(txtName, 1); char mazeName[33]; fText.read(mazeName, 33); mazeName[32] = '\0'; @@ -1115,6 +1122,8 @@ void Map::load(int mapId) { // Load sprites for the objects for (uint i = 0; i < _mobData._objectSprites.size(); ++i) { + files.setGameCc(_sideObjects); + if (party._cloudsEnd && _mobData._objectSprites[i]._spriteId == 85 && mapId == 27 && isDarkCc) { _mobData._objects[29]._spriteId = 0; @@ -1131,31 +1140,31 @@ void Map::load(int mapId) { } // Read in the object sprites - _mobData._objectSprites[i]._sprites.load(filename, - _sideObjects ? ALTSIDE_ARCHIVE : GAME_ARCHIVE); + _mobData._objectSprites[i]._sprites.load(filename); } // Load sprites for the monsters for (uint i = 0; i < _mobData._monsterSprites.size(); ++i) { MonsterObjectData::SpriteResourceEntry &spr = _mobData._monsterSprites[i]; - ArchiveType archiveType = spr._spriteId == 91 && _vm->getGameID() == GType_WorldOfXeen ? - ALTSIDE_ARCHIVE : GAME_ARCHIVE; uint imgNumber = _monsterData[spr._spriteId]._imageNumber; + files.setGameCc((spr._spriteId == 91 && _vm->getGameID() == GType_WorldOfXeen) ? + 0 : _sideMonsters); filename = Common::String::format("%03u.mon", imgNumber); - _mobData._monsterSprites[i]._sprites.load(filename, archiveType); + _mobData._monsterSprites[i]._sprites.load(filename); filename = Common::String::format("%03u.att", imgNumber); - _mobData._monsterSprites[i]._attackSprites.load(filename, archiveType); + _mobData._monsterSprites[i]._attackSprites.load(filename); } // Load wall picture sprite resources for (uint i = 0; i < _mobData._wallItemSprites.size(); ++i) { filename = Common::String::format("%03d.pic", _mobData._wallItemSprites[i]._spriteId); - _mobData._wallItemSprites[i]._sprites.load(filename, - _sidePictures ? ALTSIDE_ARCHIVE : GAME_ARCHIVE); + _mobData._wallItemSprites[i]._sprites.load(filename, _sidePictures); } + files.setGameCc(isDarkCc); + // Handle loading miscellaneous sprites for the map if (_isOutdoors) { // Start playing relevant music @@ -1190,11 +1199,15 @@ void Map::load(int mapId) { _surfaceSprites[i].load(Res.SURFACE_NAMES[_mazeData[0]._surfaceTypes[i]]); } } else { + if (isDarkCc || mapId == 125 || mapId == 126 || mapId == 127) + files.setGameCc(0); + // Start playing relevant music const int MUS_INDEXES[] = { 1, 2, 3, 4, 3, 5 }; Common::String musName; - if (_vm->_files->_isDarkCc) { + _sideMusic = isDarkCc; + if (isDarkCc) { int randIndex = _vm->getRandomNumber(6); musName = MUSIC_FILES2[MUS_INDEXES[_mazeData->_wallKind]][randIndex]; } else { @@ -1298,6 +1311,10 @@ void Map::load(int mapId) { } loadSky(); + + files.setGameCc(isDarkCc); + if (windows[9]._enabled) + windows[9].close(); } int Map::mazeLookup(const Common::Point &pt, int layerShift, int wallMask) { diff --git a/engines/xeen/map.h b/engines/xeen/map.h index 3defc589bf..c74f084392 100644 --- a/engines/xeen/map.h +++ b/engines/xeen/map.h @@ -388,6 +388,7 @@ private: int _sidePictures; int _sideObjects; int _sideMonsters; + int _sideMusic; int _mazeDataIndex; /** diff --git a/engines/xeen/music.cpp b/engines/xeen/music.cpp index fbbaadb374..0ebb8ac02f 100644 --- a/engines/xeen/music.cpp +++ b/engines/xeen/music.cpp @@ -655,7 +655,7 @@ const uint AdlibMusicDriver::WAVEFORMS[24] = { /*------------------------------------------------------------------------*/ Music::Music() : _musicDriver(nullptr), _songData(nullptr), - _archiveType(ANY_ARCHIVE), _effectsData(nullptr), _musicOn(true) { + _effectsData(nullptr), _musicOn(true) { _musicDriver = new AdlibMusicDriver(); } @@ -668,13 +668,13 @@ Music::~Music() { void Music::loadEffectsData() { // Check whether it's the first load, or switching from intro to game data - if (_effectsData && !(_archiveType == INTRO_ARCHIVE && File::_currentArchive != INTRO_ARCHIVE)) - return; +// if (_effectsData && !(_archiveType == INTRO_ARCHIVE && File::_currentArchive != INTRO_ARCHIVE)) +// return; // Stop any prior FX stopFX(); delete[] _effectsData; - _archiveType = File::_currentArchive; +// _archiveType = File::_currentArchive; // Load in an entire driver so we have quick access to the effects data // that's hardcoded within it diff --git a/engines/xeen/music.h b/engines/xeen/music.h index a3d0121665..085c85ac7f 100644 --- a/engines/xeen/music.h +++ b/engines/xeen/music.h @@ -305,7 +305,6 @@ private: const byte *_effectsData; Common::Array<uint16> _effectsOffsets; const byte *_songData; - ArchiveType _archiveType; private: /** * Loads effects data that was embedded in the music driver diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp index c60897cb81..cff4127c19 100644 --- a/engines/xeen/resources.cpp +++ b/engines/xeen/resources.cpp @@ -42,6 +42,8 @@ Resources *Resources::init(XeenEngine *vm) { Resources::Resources() { g_resources = this; + g_vm->_files->setGameCc(1); + _globalSprites.load("global.icn"); File f("mae.xen"); diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index 1c0604249d..5126642df1 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -57,7 +57,6 @@ void OutFile::finalize() { SavesManager::SavesManager(XeenEngine *vm, Party &party) : BaseCCArchive(), _vm(vm), _party(party) { - SearchMan.add("saves", this, 0, false); _data = nullptr; _wonWorld = false; _wonDarkSide = false; @@ -133,13 +132,13 @@ void SavesManager::load(Common::SeekableReadStream *stream) { } void SavesManager::reset() { - Common::String prefix = _vm->getGameID() != GType_DarkSide ? "xeen|" : "dark|"; Common::MemoryWriteStreamDynamic saveFile(DisposeAfterUse::YES); - Common::File fIn; + File fIn; + g_vm->_files->setGameCc(g_vm->getGameID() == GType_DarkSide ? 1 : 0); const int RESOURCES[6] = { 0x2A0C, 0x2A1C, 0x2A2C, 0x2A3C, 0x284C, 0x2A5C }; for (int i = 0; i < 6; ++i) { - Common::String filename = prefix + Common::String::format("%.4x", RESOURCES[i]); + Common::String filename = Common::String::format("%.4x", RESOURCES[i]); if (fIn.exists(filename)) { // Read in the next resource fIn.open(filename); @@ -153,21 +152,10 @@ void SavesManager::reset() { } } + assert(saveFile.size() > 0); Common::MemoryReadStream f(saveFile.getData(), saveFile.size()); load(&f); - // Set up the party and characters from dark.cur - CCArchive gameCur("xeen.cur", false); - File fParty("maze.pty", gameCur); - Common::Serializer sParty(&fParty, nullptr); - _party.synchronize(sParty); - fParty.close(); - - File fChar("maze.chr", gameCur); - Common::Serializer sChar(&fChar, nullptr); - _party._roster.synchronize(sChar); - fChar.close(); - // Set any final initial values _party.resetBlacksmithWares(); _party._year = _vm->getGameID() == GType_WorldOfXeen ? 610 : 850; diff --git a/engines/xeen/sprites.cpp b/engines/xeen/sprites.cpp index dac7949164..8ea18f0e10 100644 --- a/engines/xeen/sprites.cpp +++ b/engines/xeen/sprites.cpp @@ -69,8 +69,8 @@ void SpriteResource::load(const Common::String &filename) { load(f); } -void SpriteResource::load(const Common::String &filename, ArchiveType archiveType) { - File f(filename, archiveType); +void SpriteResource::load(const Common::String &filename, int ccMode) { + File f(filename, ccMode); load(f); } diff --git a/engines/xeen/sprites.h b/engines/xeen/sprites.h index a370ceea83..342fa3f39a 100644 --- a/engines/xeen/sprites.h +++ b/engines/xeen/sprites.h @@ -101,7 +101,7 @@ public: /** * Load a sprite resource from a given file and archive */ - void load(const Common::String &filename, ArchiveType archiveType); + void load(const Common::String &filename, int ccMode); /** * Clears the sprite resource diff --git a/engines/xeen/worldofxeen/clouds_cutscenes.cpp b/engines/xeen/worldofxeen/clouds_cutscenes.cpp index 3d85a6ce22..26ce12eb69 100644 --- a/engines/xeen/worldofxeen/clouds_cutscenes.cpp +++ b/engines/xeen/worldofxeen/clouds_cutscenes.cpp @@ -94,7 +94,7 @@ bool CloudsCutscenes::showCloudsIntro() { lake("lake.vga"), xeen("xeen.vga"), wizTower("wiztower.vga"), wizTower2("wiztwer2.vga"), lake2("lake2.vga"), lake3("lake3.vga"), xeen1("xeen1.vga"); - _subtitles.load("special.bin", GAME_ARCHIVE); + _subtitles.load("special.bin", 0); _vm->_files->_isDarkCc = false; // Show the production splash screen @@ -343,7 +343,7 @@ bool CloudsCutscenes::showCloudsEnding() { Sound &sound = *_vm->_sound; files._isDarkCc = false; - File::setCurrentArchive(GAME_ARCHIVE); + files.setGameCc(0); // Show the castle with swirling clouds and lightning SpriteResource prec; diff --git a/engines/xeen/xeen.cpp b/engines/xeen/xeen.cpp index 67fb977572..39e5f4b7b5 100644 --- a/engines/xeen/xeen.cpp +++ b/engines/xeen/xeen.cpp @@ -267,7 +267,7 @@ void XeenEngine::writeSavegameHeader(Common::OutSaveFile *out, XeenSavegameHeade void XeenEngine::playGame() { _saves->reset(); - File::setCurrentArchive(GAME_ARCHIVE); + _files->setGameCc(0); _sound->stopAllAudio(); play(); |