diff options
author | Paul Gilbert | 2016-05-09 08:34:06 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-10 16:38:56 -0400 |
commit | 88dcfebebc183a11729e8dca8768e3a9251533eb (patch) | |
tree | 568d12da0ca90ecae193a13c58cea4a48c2822db /engines | |
parent | bb8f95ba9d08d9e660b22240a59486166011bd0b (diff) | |
download | scummvm-rg350-88dcfebebc183a11729e8dca8768e3a9251533eb.tar.gz scummvm-rg350-88dcfebebc183a11729e8dca8768e3a9251533eb.tar.bz2 scummvm-rg350-88dcfebebc183a11729e8dca8768e3a9251533eb.zip |
TITANIC: Implementing vocab word loading
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/true_talk/st_vocab.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_string.h | 8 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.cpp | 67 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.h | 11 |
4 files changed, 70 insertions, 20 deletions
diff --git a/engines/titanic/true_talk/st_vocab.cpp b/engines/titanic/true_talk/st_vocab.cpp index 3850c64de2..578ffe569a 100644 --- a/engines/titanic/true_talk/st_vocab.cpp +++ b/engines/titanic/true_talk/st_vocab.cpp @@ -68,7 +68,7 @@ int STVocab::load(const CString &name) { case 3: case 9: { TTWord1 *word = new TTWord1(space, 0, 0, 0); - result = word->load(file, &mode); + result = word->load(file, mode); _word = word; break; } @@ -77,7 +77,7 @@ int STVocab::load(const CString &name) { case 5: case 7: { TTWord *word = new TTWord(space, 0, 0); - result = word->load(file, &mode); + result = word->load(file, mode); _word = word; break; } diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h index 947007f1ff..bc7278cce7 100644 --- a/engines/titanic/true_talk/tt_string.h +++ b/engines/titanic/true_talk/tt_string.h @@ -27,12 +27,10 @@ namespace Titanic { -class TTStringData { -private: +struct TTStringData { CString _string; -public: int _referenceCount; -public: + TTStringData() : _referenceCount(1) {} TTStringData(const char *str) : _string(str), _referenceCount(1) {} TTStringData(const CString &str) : _string(str), _referenceCount(1) {} @@ -60,6 +58,8 @@ public: * Get the status of the string */ TTStringStatus getStatus() const { return _status; } + + operator const char *() const { return _data->_string.c_str(); } }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp index a37b049d6e..0bc3611589 100644 --- a/engines/titanic/true_talk/tt_word.cpp +++ b/engines/titanic/true_talk/tt_word.cpp @@ -24,8 +24,8 @@ namespace Titanic { -TTWord::TTWord(TTString &str, int val1, int val2) : _string(str), - _field18(val1), _field1C(val2), _fieldC(0), _field10(0), +TTWord::TTWord(TTString &str, int mode, int val2) : _string(str), + _wordMode(mode), _field1C(val2), _fieldC(0), _field10(0), _field20(0), _field24(0), _field28(0) { _status = str.getStatus() == SS_VALID ? SS_VALID : SS_5; } @@ -34,9 +34,32 @@ int TTWord::readSyn(SimpleFile *file) { return 0; } -int TTWord::load(SimpleFile *file, int *mode) { - // TODO - return 0; +int TTWord::load(SimpleFile *file, int mode) { + CString str1, str2; + int val; + + if (file->scanf("%d %s %s", &val, &str1, &str2)) { + _string = TTString(str1); + _field1C = val; + _field20 = readNumber(str2.c_str()); + _wordMode = mode; + return 0; + } else { + return 3; + } +} + +uint TTWord::readNumber(const char *str) { + uint numValue = *str; + if (*str == '0') { + numValue = MKTAG('Z', 'Z', 'Z', '['); + } else { + ++str; + for (int idx = 0; idx < 3; ++idx, ++str) + numValue = (numValue << 8) + *str; + } + + return numValue; } /*------------------------------------------------------------------------*/ @@ -52,8 +75,14 @@ TTWord2::TTWord2(TTString &str, int val1, int val2, int val3, int val4) : } int TTWord2::load(SimpleFile *file) { - // TODO - return 0; + int val; + + if (TTWord::load(file, 1) && file->scanf("%d", &val)) { + _field30 = val; + return 0; + } else { + return 8; + } } /*------------------------------------------------------------------------*/ @@ -81,8 +110,14 @@ TTWord4::TTWord4(TTString &str, int val1, int val2, int val3, int val4) : } int TTWord4::load(SimpleFile *file) { - // TODO - return 0; + int val; + + if (TTWord::load(file, 1) && file->scanf("%d", &val)) { + _field30 = val; + return 0; + } else { + return 8; + } } /*------------------------------------------------------------------------*/ @@ -92,8 +127,18 @@ TTWord5::TTWord5(TTString &str, int val1, int val2, int val3, int val4) : } int TTWord5::load(SimpleFile *file) { - // TODO - return 0; + int val; + + if (TTWord::load(file, 1) && file->scanf("%d", &val)) { + if (val >= 0 && val <= 12) { + _field30 = val; + return 0; + } else { + return 5; + } + } else { + return 8; + } } } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h index 1a8b7368f5..7018d6e7e6 100644 --- a/engines/titanic/true_talk/tt_word.h +++ b/engines/titanic/true_talk/tt_word.h @@ -34,20 +34,25 @@ protected: int _fieldC; int _field10; TTStringStatus _status; - int _field18; + int _wordMode; int _field1C; int _field20; int _field24; int _field28; +protected: + /** + * Read in a number + */ + uint readNumber(const char *str); public: - TTWord(TTString &str, int val1, int val2); + TTWord(TTString &str, int mode, int val2); int readSyn(SimpleFile *file); /** * Load the word */ - int load(SimpleFile *file, int *mode); + int load(SimpleFile *file, int mode); }; class TTWord1 : public TTWord { |