diff options
author | Paul Gilbert | 2015-01-05 21:17:44 -0500 |
---|---|---|
committer | Paul Gilbert | 2015-01-05 21:17:44 -0500 |
commit | eb0c292aafc9b1b819ab1f43d4ec3a059842e96a (patch) | |
tree | 94d1624d04f06eadf5846c2322ebf138069c7553 | |
parent | 42165d21bb626e325d79d755bbf65b8b5044020f (diff) | |
download | scummvm-rg350-eb0c292aafc9b1b819ab1f43d4ec3a059842e96a.tar.gz scummvm-rg350-eb0c292aafc9b1b819ab1f43d4ec3a059842e96a.tar.bz2 scummvm-rg350-eb0c292aafc9b1b819ab1f43d4ec3a059842e96a.zip |
XEEN: Start of in-game display implementation
-rw-r--r-- | engines/xeen/files.cpp | 123 | ||||
-rw-r--r-- | engines/xeen/files.h | 55 | ||||
-rw-r--r-- | engines/xeen/interface.cpp | 16 | ||||
-rw-r--r-- | engines/xeen/interface.h | 4 | ||||
-rw-r--r-- | engines/xeen/map.cpp | 9 | ||||
-rw-r--r-- | engines/xeen/saves.cpp | 50 | ||||
-rw-r--r-- | engines/xeen/saves.h | 12 | ||||
-rw-r--r-- | engines/xeen/xeen.cpp | 2 |
8 files changed, 167 insertions, 104 deletions
diff --git a/engines/xeen/files.cpp b/engines/xeen/files.cpp index a0ca2435a1..b1358d4cdc 100644 --- a/engines/xeen/files.cpp +++ b/engines/xeen/files.cpp @@ -29,64 +29,10 @@ namespace Xeen { -CCArchive::CCArchive(const Common::String &filename, bool encoded): - _filename(filename), _encoded(encoded) { - File f(filename); - loadIndex(&f); -} - -CCArchive::~CCArchive() { -} - -// Archive implementation -bool CCArchive::hasFile(const Common::String &name) const { - CCEntry ccEntry; - return getHeaderEntry(name, ccEntry); -} - -int CCArchive::listMembers(Common::ArchiveMemberList &list) const { - // CC files don't maintain the original filenames, so we can't list it - return 0; -} - -const Common::ArchiveMemberPtr CCArchive::getMember(const Common::String &name) const { - if (!hasFile(name)) - return Common::ArchiveMemberPtr(); - - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); -} - -Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::String &name) const { - CCEntry ccEntry; - - if (getHeaderEntry(name, ccEntry)) { - // Open the correct CC file - Common::File f; - if (!f.open(_filename)) - error("Could not open CC file"); - - // Read in the data for the specific resource - f.seek(ccEntry._offset); - byte *data = new byte[ccEntry._size]; - f.read(data, ccEntry._size); - - if (_encoded) { - // Decrypt the data - for (int i = 0; i < ccEntry._size; ++i) - data[i] ^= 0x35; - } - - // Return the data as a stream - return new Common::MemoryReadStream(data, ccEntry._size, DisposeAfterUse::YES); - } - - return nullptr; -} - /** - * Hash a given filename to produce the Id that represents it - */ -uint16 CCArchive::convertNameToId(const Common::String &resourceName) const { +* Hash a given filename to produce the Id that represents it +*/ +uint16 BaseCCArchive::convertNameToId(const Common::String &resourceName) const { if (resourceName.empty()) return 0xffff; @@ -104,9 +50,9 @@ uint16 CCArchive::convertNameToId(const Common::String &resourceName) const { } /** - * Load the index of a given CC file - */ -void CCArchive::loadIndex(Common::SeekableReadStream *stream) { +* Load the index of a given CC file +*/ +void BaseCCArchive::loadIndex(Common::SeekableReadStream *stream) { int count = stream->readUint16LE(); // Read in the data for the archive's index @@ -136,11 +82,16 @@ void CCArchive::loadIndex(Common::SeekableReadStream *stream) { delete[] rawIndex; } +bool BaseCCArchive::hasFile(const Common::String &name) const { + CCEntry ccEntry; + return getHeaderEntry(name, ccEntry); +} + /** * Given a resource name, returns whether an entry exists, and returns * the header index data for that entry */ -bool CCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const { +bool BaseCCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const { uint16 id = convertNameToId(resourceName); // Loop through the index @@ -155,6 +106,56 @@ bool CCArchive::getHeaderEntry(const Common::String &resourceName, CCEntry &ccEn return false; } +const Common::ArchiveMemberPtr BaseCCArchive::getMember(const Common::String &name) const { + if (!hasFile(name)) + return Common::ArchiveMemberPtr(); + + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +int BaseCCArchive::listMembers(Common::ArchiveMemberList &list) const { + // CC files don't maintain the original filenames, so we can't list it + return 0; +} + +/*------------------------------------------------------------------------*/ + +CCArchive::CCArchive(const Common::String &filename, bool encoded): + _filename(filename), _encoded(encoded) { + File f(filename); + loadIndex(&f); +} + +CCArchive::~CCArchive() { +} + +Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::String &name) const { + CCEntry ccEntry; + + if (getHeaderEntry(name, ccEntry)) { + // Open the correct CC file + Common::File f; + if (!f.open(_filename)) + error("Could not open CC file"); + + // Read in the data for the specific resource + f.seek(ccEntry._offset); + byte *data = new byte[ccEntry._size]; + f.read(data, ccEntry._size); + + if (_encoded) { + // Decrypt the data + for (int i = 0; i < ccEntry._size; ++i) + data[i] ^= 0x35; + } + + // Return the data as a stream + return new Common::MemoryReadStream(data, ccEntry._size, DisposeAfterUse::YES); + } + + return nullptr; +} + /*------------------------------------------------------------------------*/ /** diff --git a/engines/xeen/files.h b/engines/xeen/files.h index 3e38ad842c..6e560ca334 100644 --- a/engines/xeen/files.h +++ b/engines/xeen/files.h @@ -58,41 +58,52 @@ public: }; /** -* Xeen CC file implementation +* Details of a single entry in a CC file index */ -class CCArchive : public Common::Archive { -private: - /** - * Details of a single entry in a CC file index - */ - struct CCEntry { - uint16 _id; - uint32 _offset; - uint16 _size; - - CCEntry() : _id(0), _offset(0), _size(0) {} - CCEntry(uint16 id, uint32 offset, uint32 size) - : _id(id), _offset(offset), _size(size) { - } - }; - - Common::Array<CCEntry> _index; - Common::String _filename; - bool _encoded; +struct CCEntry { + uint16 _id; + uint32 _offset; + uint16 _size; + + CCEntry() : _id(0), _offset(0), _size(0) {} + CCEntry(uint16 id, uint32 offset, uint32 size) + : _id(id), _offset(offset), _size(size) { + } +}; +/** +* Base Xeen CC file implementation +*/ +class BaseCCArchive : public Common::Archive { +private: uint16 convertNameToId(const Common::String &resourceName) const; +protected: + Common::Array<CCEntry> _index; void loadIndex(Common::SeekableReadStream *stream); bool getHeaderEntry(const Common::String &resourceName, CCEntry &ccEntry) const; public: - CCArchive(const Common::String &filename, bool encoded = true); - virtual ~CCArchive(); + BaseCCArchive() {} // Archive implementation virtual bool hasFile(const Common::String &name) const; virtual int listMembers(Common::ArchiveMemberList &list) const; virtual const Common::ArchiveMemberPtr getMember(const Common::String &name) const; +}; + +/** +* Xeen CC file implementation +*/ +class CCArchive : public BaseCCArchive { +private: + Common::String _filename; + bool _encoded; +public: + CCArchive(const Common::String &filename, bool encoded = true); + virtual ~CCArchive(); + + // Archive implementation virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; }; diff --git a/engines/xeen/interface.cpp b/engines/xeen/interface.cpp index 4f40c4730d..daeb4402e5 100644 --- a/engines/xeen/interface.cpp +++ b/engines/xeen/interface.cpp @@ -71,10 +71,7 @@ void Interface::initDrawStructs() { _mainList[15] = DrawStruct(30, 286, 169); } -void Interface::manageCharacters(bool soundPlayed) { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - bool flag = false; +void Interface::setup() { _globalSprites.load("global.icn"); _borderSprites.load("border.icn"); _spellFxSprites.load("spellfx.icn"); @@ -84,7 +81,6 @@ void Interface::manageCharacters(bool soundPlayed) { _hpSprites.load("hpbars.icn"); _uiSprites.load("inn.icn"); -start: // Get mappings to the active characters in the party _vm->_party._activeParty.resize(_vm->_party._partyCount); for (int i = 0; i < _vm->_party._partyCount; ++i) { @@ -92,7 +88,14 @@ start: } _isEarlyGame = _vm->_party._minutes >= 300; +} +void Interface::manageCharacters(bool soundPlayed) { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + bool flag = false; + +start: if (_vm->_party._mazeId != 0) { _vm->_mode = MODE_0; _buttonsLoaded = true; @@ -279,7 +282,7 @@ start: void Interface::loadCharIcons() { for (int i = 0; i < XEEN_TOTAL_CHARACTERS; ++i) { // Load new character resource - Common::String name = Common::String::format("char%02d.fac", i); + Common::String name = Common::String::format("char%02d.fac", i + 1); _charFaces[i].load(name); } @@ -556,6 +559,7 @@ void Interface::setOutdoorsObjects() { void Interface::startup() { Screen &screen = *_vm->_screen; + loadCharIcons(); _iconSprites.load("main.icn"); animate3d(); diff --git a/engines/xeen/interface.h b/engines/xeen/interface.h index f455957699..b19f031ac4 100644 --- a/engines/xeen/interface.h +++ b/engines/xeen/interface.h @@ -66,6 +66,8 @@ private: int _hiliteChar; int _intrIndex1; + void loadSprites(); + void initDrawStructs(); void assembleBorder(); @@ -92,6 +94,8 @@ private: public: Interface(XeenEngine *vm); + void setup(); + void manageCharacters(bool soundPlayed); void loadCharIcons(); diff --git a/engines/xeen/map.cpp b/engines/xeen/map.cpp index 5179b929f2..5e98c519f4 100644 --- a/engines/xeen/map.cpp +++ b/engines/xeen/map.cpp @@ -669,6 +669,7 @@ void MonsterObjectData::synchronize(Common::SeekableReadStream &s, } // merge up monsters + _monsters.resize(monData.size()); for (uint i = 0; i < monData.size(); ++i) { MazeMonster &dest = _monsters[i]; dest._position = monData[i]._pos; @@ -808,7 +809,7 @@ void Map::load(int mapId) { if (!textLoaded) { textLoaded = true; Common::String txtName = Common::String::format("%s%c%03u.txt", - isDarkCc ? "dark" : "xeen", mapId >= 100 ? 'x' : '0'); + isDarkCc ? "dark" : "xeen", mapId >= 100 ? 'x' : '0', mapId); File fText(txtName); char mazeName[33]; fText.read(mazeName, 33); @@ -819,13 +820,13 @@ void Map::load(int mapId) { // Load the monster data Common::String mobName = Common::String::format("maze%c%03u.mob", - (_vm->_party._mazeId >= 100) ? 'x' : '0', _vm->_party._mazeId); + (mapId >= 100) ? 'x' : '0', mapId); File mobFile(mobName); _mobData.synchronize(mobFile, _isOutdoors, _monsterData); mobFile.close(); Common::String headName = Common::String::format("aaze%c%03u.hed", - (_vm->_party._mazeId >= 100) ? 'x' : '0', _vm->_party._mazeId); + (mapId >= 100) ? 'x' : '0', mapId); File headFile(headName); _headData.synchronize(headFile); headFile.close(); @@ -846,7 +847,7 @@ void Map::load(int mapId) { // Move to next surrounding maze MazeData *baseMaze = &_mazeData[MAP_GRID_PRIOR_INDEX[idx]]; mapId = baseMaze->_surroundingMazes[MAP_GRID_PRIOR_DIRECTION[idx]]; - if (mapId) { + if (!mapId) { baseMaze = &_mazeData[MAP_GRID_PRIOR_INDEX2[idx]]; mapId = baseMaze->_surroundingMazes[MAP_GRID_PRIOR_DIRECTION2[idx]]; } diff --git a/engines/xeen/saves.cpp b/engines/xeen/saves.cpp index 95957c4daa..ae29dd1149 100644 --- a/engines/xeen/saves.cpp +++ b/engines/xeen/saves.cpp @@ -22,6 +22,7 @@ #include "common/scummsys.h" #include "common/algorithm.h" +#include "common/memstream.h" #include "xeen/saves.h" #include "xeen/files.h" #include "xeen/xeen.h" @@ -29,7 +30,13 @@ namespace Xeen { SavesManager::SavesManager(XeenEngine *vm, Party &party, Roster &roster) : - _vm(vm), _party(party), _roster(roster) { + BaseCCArchive(), _vm(vm), _party(party), _roster(roster) { + SearchMan.add("saves", this, 0, false); + _data = nullptr; +} + +SavesManager::~SavesManager() { + delete[] _data; } /** @@ -57,24 +64,47 @@ void SavesManager::syncBitFlags(Common::Serializer &s, bool *startP, bool *endP) } } -/** - * Sets up the dynamic data for the game for a new game - */ -void SavesManager::reset() { - Common::String name(_vm->getGameID() == GType_Clouds ? "xeen.cur" : "dark.cur"); - CCArchive cur(name, false); - - Common::SeekableReadStream *chr = cur.createReadStreamForMember("maze.chr"); +Common::SeekableReadStream *SavesManager::createReadStreamForMember(const Common::String &name) const { + CCEntry ccEntry; + + if (getHeaderEntry(name, ccEntry)) { + // Open the correct CC entry + return new Common::MemoryReadStream(_data + ccEntry._offset, ccEntry._size); + } + + return nullptr; +} + +void SavesManager::load(Common::SeekableReadStream *stream) { + loadIndex(stream); + + delete[] _data; + _data = new byte[stream->size()]; + stream->seek(0); + stream->read(_data, stream->size()); + + // Load in the character stats and active party + Common::SeekableReadStream *chr = createReadStreamForMember("maze.chr"); Common::Serializer sChr(chr, nullptr); _roster.synchronize(sChr); delete chr; - Common::SeekableReadStream *pty = cur.createReadStreamForMember("maze.pty"); + Common::SeekableReadStream *pty = createReadStreamForMember("maze.pty"); Common::Serializer sPty(pty, nullptr); _party.synchronize(sPty); delete pty; } +/** + * Sets up the dynamic data for the game for a new game + */ +void SavesManager::reset() { + Common::String name(_vm->getGameID() == GType_Clouds ? "xeen.cur" : "dark.cur"); + File f(name); + + load(&f); +} + void SavesManager::readCharFile() { warning("TODO: readCharFile"); } diff --git a/engines/xeen/saves.h b/engines/xeen/saves.h index 1e67638fe4..ed4b80b29d 100644 --- a/engines/xeen/saves.h +++ b/engines/xeen/saves.h @@ -27,6 +27,7 @@ #include "common/savefile.h" #include "graphics/surface.h" #include "xeen/party.h" +#include "xeen/files.h" namespace Xeen { @@ -39,20 +40,29 @@ struct XeenSavegameHeader { int _totalFrames; }; -class SavesManager { +class SavesManager: public BaseCCArchive { private: XeenEngine *_vm; Party &_party; Roster &_roster; + byte *_data; + + void load(Common::SeekableReadStream *stream); public: static void syncBitFlags(Common::Serializer &s, bool *startP, bool *endP); public: SavesManager(XeenEngine *vm, Party &party, Roster &roster); + + ~SavesManager(); + void reset(); void readCharFile(); void writeCharFile(); + + // Archive implementation + virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; }; } // End of namespace Xeen diff --git a/engines/xeen/xeen.cpp b/engines/xeen/xeen.cpp index 7321befb08..948b4154fe 100644 --- a/engines/xeen/xeen.cpp +++ b/engines/xeen/xeen.cpp @@ -54,6 +54,7 @@ XeenEngine::XeenEngine(OSystem *syst, const XeenGameDescription *gameDesc) _falling = false; _tillMove = false; _moveMonsters = false; + _mode = MODE_0; } XeenEngine::~XeenEngine() { @@ -271,6 +272,7 @@ void XeenEngine::playGame() { void XeenEngine::play() { // TODO: Init variables + _interface->setup(); _screen->loadBackground("back.raw"); _screen->loadPalette("mm4.pal"); _interface->loadPartyIcons(); |