diff options
author | Paul Gilbert | 2016-06-05 18:44:56 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:20:08 -0400 |
commit | 289856dce3868de36c985f1df94ce3d1f3bff99b (patch) | |
tree | 6646202e32e67c5772e3691814376430da1eac47 /engines/titanic | |
parent | bfe075d314f8e9d7010d0f5e60d44bb314e53846 (diff) | |
download | scummvm-rg350-289856dce3868de36c985f1df94ce3d1f3bff99b.tar.gz scummvm-rg350-289856dce3868de36c985f1df94ce3d1f3bff99b.tar.bz2 scummvm-rg350-289856dce3868de36c985f1df94ce3d1f3bff99b.zip |
TITANIC: Finished TTquotesTree search methods
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/true_talk/tt_quotes.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_quotes.h | 4 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_quotes_tree.cpp | 94 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_quotes_tree.h | 39 |
4 files changed, 120 insertions, 28 deletions
diff --git a/engines/titanic/true_talk/tt_quotes.cpp b/engines/titanic/true_talk/tt_quotes.cpp index 1df3c0c01e..825210ae06 100644 --- a/engines/titanic/true_talk/tt_quotes.cpp +++ b/engines/titanic/true_talk/tt_quotes.cpp @@ -68,7 +68,7 @@ void TTquotes::load() { delete r; } -int TTquotes::read(const char *str) { +int TTquotes::find(const char *str) { if (!str || !*str) return 0; @@ -78,9 +78,9 @@ int TTquotes::read(const char *str) { ++endP; do { - int result = read(startP, endP); - if (result) - return result; + int tagId = find(startP, endP); + if (tagId) + return tagId; // Move to next following space or end of string while (*startP && *startP != ' ') @@ -91,10 +91,11 @@ int TTquotes::read(const char *str) { } while (*startP); + // No match return 0; } -int TTquotes::read(const char *startP, const char *endP) { +int TTquotes::find(const char *startP, const char *endP) { int size = endP - startP; if (size < 3) return 0; diff --git a/engines/titanic/true_talk/tt_quotes.h b/engines/titanic/true_talk/tt_quotes.h index 1387a1d873..c6627dcc34 100644 --- a/engines/titanic/true_talk/tt_quotes.h +++ b/engines/titanic/true_talk/tt_quotes.h @@ -53,7 +53,7 @@ private: * Test whether a substring contains one of the quotes, * and if so, returns the 4-character tag Id associated with it */ - int read(const char *startP, const char *endP); + int find(const char *startP, const char *endP); public: TTquotes(); ~TTquotes(); @@ -67,7 +67,7 @@ public: * Test whether a passed string contains one of the quotes, * and if so, returns the 4-character tag Id associated with it */ - int read(const char *str); + int find(const char *str); }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_quotes_tree.cpp b/engines/titanic/true_talk/tt_quotes_tree.cpp index 6eee91227a..8641ab9a1d 100644 --- a/engines/titanic/true_talk/tt_quotes_tree.cpp +++ b/engines/titanic/true_talk/tt_quotes_tree.cpp @@ -35,7 +35,7 @@ void TTquotesTree::load() { Common::SeekableReadStream *r = g_vm->_filesManager->getResource("TEXT/TREE"); for (int idx = 0; idx < QUOTES_TREE_COUNT; ++idx) { - TTquotesTree::TTquotesTreeEntry &rec = _entries[idx]; + TTquotesTreeEntry &rec = _entries[idx]; assert(r->pos() < r->size()); rec._id = r->readUint32LE(); @@ -59,12 +59,30 @@ void TTquotesTree::load() { delete r; } -void TTquotesTree::search(const char **str, TTquotesTreeEntry *bTree, - TTtreeBuffer *buffer, int quoteId) { - buffer->_strP = nullptr; - (buffer + 1)->_strP = nullptr; +int TTquotesTree::search(const char *str, QuoteTreeNum treeNum, + TTtreeResult *buffer, uint tagId, int *remainder) { + const TTquotesTreeEntry *bTree = &_entries[TABLE_INDEXES[treeNum]]; + if (!search1(&str, bTree, buffer, tagId) || !buffer->_treeItemP) + return -1; + + if (remainder) { + while (*str) { + if (*str >= 'a' && *str != 's') + *remainder += *str; + } + } + + return buffer->_treeItemP->_id & 0xffffff; +} + +bool TTquotesTree::search1(const char **str, const TTquotesTreeEntry *bTree, + TTtreeResult *buffer, uint tagId) { + buffer->_treeItemP = nullptr; + (buffer + 1)->_treeItemP = nullptr; + const char *strP = *str; bool flag = false; + for (uint mode = bTree->_id >> 24; mode != 0; ++bTree, mode = bTree->_id >> 24) { @@ -79,21 +97,83 @@ void TTquotesTree::search(const char **str, TTquotesTreeEntry *bTree, break; case 5: - warning("TODO: TTquotesTree::search"); + if (READ_LE_UINT32(bTree->_string.c_str()) == tagId) + flag = true; break; case 7: + if (search1(str, bTree->_subTable, buffer + 1, tagId)) + flag = true; + break; + + case 8: + if (search2(str, bTree->_subTable, buffer + 1, tagId)) + flag = true; + break; default: break; } if (flag) { - // TODO + buffer->_treeItemP = bTree; + return true; + } + } + + *str = strP; + return false; +} + +bool TTquotesTree::search2(const char **str, const TTquotesTreeEntry *bTree, + TTtreeResult *buffer, uint tagId) { + buffer->_treeItemP = bTree; + (buffer + 1)->_treeItemP = nullptr; + + const char *strP = *str; + bool flag = false; + for (uint mode = bTree->_id >> 24; mode != 0; + ++bTree, mode = bTree->_id >> 24) { + switch (mode) { + case 0: + return true; + + case 1: + if (compareWord(str, bTree->_string.c_str())) + flag = true; + break; + + case 2: + compareWord(str, bTree->_string.c_str()); + break; + + case 5: + if (READ_LE_UINT32(bTree->_string.c_str()) == tagId) + flag = true; + break; + + case 7: + if (search1(str, bTree->_subTable, buffer + 1, tagId)) + flag = true; break; + + case 8: + if (search2(str, bTree->_subTable, buffer + 1, tagId)) + flag = true; + break; + + default: + break; + } + + if (flag) { + buffer->_treeItemP = nullptr; + *str = strP; + return false; } } + return true; } bool TTquotesTree::compareWord(const char **str, const char *refStr) { diff --git a/engines/titanic/true_talk/tt_quotes_tree.h b/engines/titanic/true_talk/tt_quotes_tree.h index fb7d262879..fa0e9edf2a 100644 --- a/engines/titanic/true_talk/tt_quotes_tree.h +++ b/engines/titanic/true_talk/tt_quotes_tree.h @@ -31,30 +31,39 @@ namespace Titanic { #define QUOTES_TREE_COUNT 1022 -class TTtreeBuffer { +enum QuoteTreeNum { TREE_1 = 0, TREE_2 = 1, TREE_3 = 2 }; + +struct TTquotesTreeEntry { + uint _id; + TTquotesTreeEntry *_subTable; + CString _string; + + TTquotesTreeEntry() : _id(0), _subTable(nullptr) {} +}; + +class TTtreeResult { public: - int _field0; - const char *_strP; + int _id; + const TTquotesTreeEntry *_treeItemP; public: - TTtreeBuffer() : _field0(0), _strP(nullptr) {} + TTtreeResult() : _id(0), _treeItemP(nullptr) {} }; class TTquotesTree { - struct TTquotesTreeEntry { - uint _id; - TTquotesTreeEntry *_subTable; - CString _string; - - TTquotesTreeEntry() : _id(0), _subTable(nullptr) {} - }; private: TTquotesTreeEntry _entries[QUOTES_TREE_COUNT]; private: /** - * Inner search method + * First inner search method + */ + bool search1(const char **str, const TTquotesTreeEntry *bTree, + TTtreeResult *buffer, uint tagId); + + /** + * Second inner search method */ - void search(const char **str, TTquotesTreeEntry *bTree, TTtreeBuffer *buffer, - int quoteId); + bool search2(const char **str, const TTquotesTreeEntry *bTree, + TTtreeResult *buffer, uint tagId); /** * Compare the current word in the string against a specified word @@ -66,6 +75,8 @@ public: */ void load(); + int search(const char *str, QuoteTreeNum treeNum, + TTtreeResult *buffer, uint tagId, int *remainder); }; } // End of namespace Titanic |