From bfe075d314f8e9d7010d0f5e60d44bb314e53846 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 5 Jun 2016 14:27:31 -0400 Subject: TITANIC: Further fleshing out of TTquotes and TTquotesTree --- engines/titanic/true_talk/tt_quotes.cpp | 8 +-- engines/titanic/true_talk/tt_quotes.h | 8 +-- engines/titanic/true_talk/tt_quotes_tree.cpp | 74 +++++++++++++++++++++++++++- engines/titanic/true_talk/tt_quotes_tree.h | 23 +++++++-- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/engines/titanic/true_talk/tt_quotes.cpp b/engines/titanic/true_talk/tt_quotes.cpp index a2afa1a949..1df3c0c01e 100644 --- a/engines/titanic/true_talk/tt_quotes.cpp +++ b/engines/titanic/true_talk/tt_quotes.cpp @@ -54,8 +54,8 @@ void TTquotes::load() { // Load the list of entries for the given letter letter._entries.resize(count); for (int idx = 0; idx < count; ++idx) { - letter._entries[idx]._val1 = r->readByte(); - letter._entries[idx]._val2 = r->readByte(); + letter._entries[idx]._tagIndex = r->readByte(); + letter._entries[idx]._maxSize = r->readByte(); letter._entries[idx]._strP = _dataP + r->readUint32LE(); } } @@ -109,7 +109,7 @@ int TTquotes::read(const char *startP, const char *endP) { for (uint idx = 0; idx < letter._entries.size(); ++idx) { const TTquotesEntry &entry = letter._entries[idx]; - if (entry._val2 > maxSize) + if (entry._maxSize > maxSize) continue; const char *srcP = startP; @@ -135,7 +135,7 @@ int TTquotes::read(const char *startP, const char *endP) { if (!destP[destIndex] && (srcP[srcIndex] <= '*' || (srcP[srcIndex] == 's' && srcP[srcIndex + 1] <= '*'))) - return entry._val1; + return _tags[entry._tagIndex]; } } diff --git a/engines/titanic/true_talk/tt_quotes.h b/engines/titanic/true_talk/tt_quotes.h index a90c70e9cc..1387a1d873 100644 --- a/engines/titanic/true_talk/tt_quotes.h +++ b/engines/titanic/true_talk/tt_quotes.h @@ -31,9 +31,9 @@ namespace Titanic { class TTquotes { struct TTquotesEntry { - byte _val1, _val2; + byte _tagIndex, _maxSize; const char *_strP; - TTquotesEntry() : _val1(0), _val2(0), _strP(nullptr) {} + TTquotesEntry() : _tagIndex(0), _maxSize(0), _strP(nullptr) {} }; struct TTquotesLetter { Common::Array _entries; @@ -51,7 +51,7 @@ private: private: /** * Test whether a substring contains one of the quotes, - * and if so, returns the Id associated with it + * and if so, returns the 4-character tag Id associated with it */ int read(const char *startP, const char *endP); public: @@ -65,7 +65,7 @@ public: /** * Test whether a passed string contains one of the quotes, - * and if so, returns the Id associated with it + * and if so, returns the 4-character tag Id associated with it */ int read(const char *str); }; diff --git a/engines/titanic/true_talk/tt_quotes_tree.cpp b/engines/titanic/true_talk/tt_quotes_tree.cpp index 0f10a10aa6..6eee91227a 100644 --- a/engines/titanic/true_talk/tt_quotes_tree.cpp +++ b/engines/titanic/true_talk/tt_quotes_tree.cpp @@ -40,7 +40,7 @@ void TTquotesTree::load() { rec._id = r->readUint32LE(); if (rec._id == 0) { - rec._type = ET_END; + // Nothing needed } else { byte type = r->readByte(); if (type == 0) { @@ -59,4 +59,76 @@ void TTquotesTree::load() { delete r; } +void TTquotesTree::search(const char **str, TTquotesTreeEntry *bTree, + TTtreeBuffer *buffer, int quoteId) { + buffer->_strP = nullptr; + (buffer + 1)->_strP = nullptr; + + bool flag = false; + for (uint mode = bTree->_id >> 24; mode != 0; + ++bTree, mode = bTree->_id >> 24) { + + switch (mode) { + case 1: + if (compareWord(str, bTree->_string.c_str())) + flag = true; + break; + + case 2: + compareWord(str, bTree->_string.c_str()); + break; + + case 5: + warning("TODO: TTquotesTree::search"); + break; + + case 7: + + default: + break; + } + + if (flag) { + // TODO + break; + } + } + +} + +bool TTquotesTree::compareWord(const char **str, const char *refStr) { + // Skip over any spaces + const char *strP = *str; + while (*strP && *strP == ' ') + ++strP; + *str = strP; + + // Compare against the reference string + while (*strP && *refStr && *refStr != '*') { + if (*refStr == '-') { + if (*strP == ' ') + ++strP; + } else if (*strP == *refStr) { + ++strP; + } else { + return false; + } + } + + if (*refStr && *refStr != '*') + return false; + if (!*refStr && *strP && *strP != ' ') + return false; + + if (*refStr == '*') { + // Skip over to the end of the word + while (*strP && *strP != ' ') + ++strP; + } + + // Pass out the new updated string position + *str = strP; + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_quotes_tree.h b/engines/titanic/true_talk/tt_quotes_tree.h index 9496fa8887..fb7d262879 100644 --- a/engines/titanic/true_talk/tt_quotes_tree.h +++ b/engines/titanic/true_talk/tt_quotes_tree.h @@ -31,24 +31,41 @@ namespace Titanic { #define QUOTES_TREE_COUNT 1022 -enum TreeEntryType { ET_END = 0, ET_TABLE = 1, ET_STRING = 2 }; +class TTtreeBuffer { +public: + int _field0; + const char *_strP; +public: + TTtreeBuffer() : _field0(0), _strP(nullptr) {} +}; class TTquotesTree { struct TTquotesTreeEntry { uint _id; - TreeEntryType _type; TTquotesTreeEntry *_subTable; CString _string; - TTquotesTreeEntry() : _id(0), _type(ET_END), _subTable(nullptr) {} + TTquotesTreeEntry() : _id(0), _subTable(nullptr) {} }; private: TTquotesTreeEntry _entries[QUOTES_TREE_COUNT]; +private: + /** + * Inner search method + */ + void search(const char **str, TTquotesTreeEntry *bTree, TTtreeBuffer *buffer, + int quoteId); + + /** + * Compare the current word in the string against a specified word + */ + bool compareWord(const char **str, const char *refStr); public: /** * Load data for the quotes tree */ void load(); + }; } // End of namespace Titanic -- cgit v1.2.3