diff options
author | Walter van Niftrik | 2009-08-31 12:32:05 +0000 |
---|---|---|
committer | Walter van Niftrik | 2009-08-31 12:32:05 +0000 |
commit | 41e24b74954c416c386d1ea670e4395b8e29ce68 (patch) | |
tree | 2badc759caf9f43b9e2faf39a1a27796cd76586e | |
parent | 299b4d6195bae1db6a2481d6ee337cddc83ff5ba (diff) | |
download | scummvm-rg350-41e24b74954c416c386d1ea670e4395b8e29ce68.tar.gz scummvm-rg350-41e24b74954c416c386d1ea670e4395b8e29ce68.tar.bz2 scummvm-rg350-41e24b74954c416c386d1ea670e4395b8e29ce68.zip |
SCI: Fix messages in QFG remake.
svn-id: r43850
-rw-r--r-- | engines/sci/engine/message.cpp | 69 | ||||
-rw-r--r-- | engines/sci/engine/message.h | 7 |
2 files changed, 53 insertions, 23 deletions
diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index fe122e960f..67657aab25 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -31,14 +31,14 @@ namespace Sci { MessageTuple MessageState::getTuple() { MessageTuple t; - t.noun = *(_engineCursor.index_record + 0); - t.verb = *(_engineCursor.index_record + 1); - if (_version == 2) { + t.noun = _engineCursor.index_record[0]; + t.verb = _engineCursor.index_record[1]; + if (_offsetCondSeq == -1) { t.cond = 0; t.seq = 1; } else { - t.cond = *(_engineCursor.index_record + 2); - t.seq = *(_engineCursor.index_record + 3); + t.cond = _engineCursor.index_record[_offsetCondSeq]; + t.seq = _engineCursor.index_record[_offsetCondSeq + 1]; } return t; @@ -47,14 +47,14 @@ MessageTuple MessageState::getTuple() { MessageTuple MessageState::getRefTuple() { MessageTuple t; - if (_version == 2) { + if (_offsetRef == -1) { t.noun = 0; t.verb = 0; t.cond = 0; } else { - t.noun = *(_engineCursor.index_record + 7); - t.verb = *(_engineCursor.index_record + 8); - t.cond = *(_engineCursor.index_record + 9); + t.noun = _engineCursor.index_record[_offsetRef]; + t.verb = _engineCursor.index_record[_offsetRef + 1]; + t.cond = _engineCursor.index_record[_offsetRef + 2]; } t.seq = 1; @@ -68,7 +68,7 @@ void MessageState::initCursor() { } void MessageState::advanceCursor(bool increaseSeq) { - _engineCursor.index_record += ((_version == 2) ? 4 : 11); + _engineCursor.index_record += _recordSize; _engineCursor.index++; if (increaseSeq) @@ -118,6 +118,8 @@ int MessageState::getMessage() { // Recursion, advance the current cursor and load the reference advanceCursor(true); + _cursorStack.push(_engineCursor); + if (findTuple(ref)) return getMessage(); else { @@ -142,7 +144,7 @@ int MessageState::getMessage() { } int MessageState::getTalker() { - return (_version == 2) ? -1 : *(_engineCursor.index_record + 4); + return (_offsetTalker == -1) ? -1 : _engineCursor.index_record[_offsetTalker]; } MessageTuple &MessageState::getLastTuple() { @@ -154,7 +156,7 @@ int MessageState::getLastModule() { } Common::String MessageState::getText() { - char *str = (char *)_currentResource->data + READ_LE_UINT16(_engineCursor.index_record + ((_version == 2) ? 2 : 5)); + char *str = (char *)_currentResource->data + READ_LE_UINT16(_engineCursor.index_record + _offsetText); Common::String strippedStr; Common::String skippedSubstr; @@ -215,12 +217,14 @@ void MessageState::gotoNext() { } int MessageState::getLength() { - int offset = READ_LE_UINT16(_engineCursor.index_record + ((_version == 2) ? 2 : 5)); + int offset = READ_LE_UINT16(_engineCursor.index_record + _offsetText); char *stringptr = (char *)_currentResource->data + offset; return strlen(stringptr); } int MessageState::loadRes(ResourceManager *resourceManager, int module, bool lock) { + _cursorStack.clear(); + if (_locked) { // We already have a locked resource if (_module == module) { @@ -243,17 +247,38 @@ int MessageState::loadRes(ResourceManager *resourceManager, int module, bool loc _module = module; _locked = lock; - _version = READ_LE_UINT16(_currentResource->data); - debug(5, "Message: reading resource %d.msg, version %d.%03d", _module, _version / 1000, _version % 1000); - - // We assume for now that storing the major version is sufficient - _version /= 1000; + int version = READ_LE_UINT16(_currentResource->data); + debug(5, "Message: reading resource %d.msg, version %d.%03d", _module, version / 1000, version % 1000); + + int offsetCount; + + // FIXME: Correct/extend this data by examining more games + if (version < 3000) { + _offsetCondSeq = -1; + _offsetTalker = -1; + _offsetRef = -1; + _offsetText = 2; + _recordSize = 4; + offsetCount = 4; + } else if (version < 4000) { + _offsetCondSeq = 2; + _offsetTalker = 4; + _offsetRef = -1; + _offsetText = 5; + _recordSize = 10; + offsetCount = 6; + } else { + _offsetCondSeq = 2; + _offsetTalker = 4; + _offsetRef = 7; + _offsetText = 5; + _recordSize = 11; + offsetCount = 8; + } - int offs = (_version == 2) ? 0 : 4; - _recordCount = READ_LE_UINT16(_currentResource->data + 4 + offs); - _indexRecords = _currentResource->data + 6 + offs; + _recordCount = READ_LE_UINT16(_currentResource->data + offsetCount); + _indexRecords = _currentResource->data + offsetCount + 2; - _cursorStack.clear(); initCursor(); return 1; diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h index 5a9dab6684..7ab772aed5 100644 --- a/engines/sci/engine/message.h +++ b/engines/sci/engine/message.h @@ -46,6 +46,7 @@ struct IndexRecordCursor { typedef Common::Stack<IndexRecordCursor> CursorStack; +// FIXME: Documentation class MessageState { public: MessageState() : _module(-1), _locked(false) { } @@ -74,7 +75,11 @@ private: IndexRecordCursor _engineCursor; MessageTuple _lastReturned; int _lastReturnedModule; - int _version; + int _offsetCondSeq; + int _offsetRef; + int _offsetTalker; + int _offsetText; + int _recordSize; }; } // End of namespace Sci |