diff options
author | Paul Gilbert | 2016-05-26 20:37:11 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:15:40 -0400 |
commit | f98ad3313499c8c6375f3216f5ae6ddb8faa3271 (patch) | |
tree | cb70c7473715604910cc554f9bf88c76cec8b8a5 | |
parent | 1992afe4aa5ff8b02d38a0038fc390b6280ab358 (diff) | |
download | scummvm-rg350-f98ad3313499c8c6375f3216f5ae6ddb8faa3271.tar.gz scummvm-rg350-f98ad3313499c8c6375f3216f5ae6ddb8faa3271.tar.bz2 scummvm-rg350-f98ad3313499c8c6375f3216f5ae6ddb8faa3271.zip |
TITANIC: In-progress TTparser checkForAction
-rw-r--r-- | engines/titanic/true_talk/tt_parser.cpp | 82 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_string.h | 2 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_vocab.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.cpp | 8 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_word.h | 11 |
5 files changed, 96 insertions, 11 deletions
diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp index 3741ab7e5f..a0eb6a5e9a 100644 --- a/engines/titanic/true_talk/tt_parser.cpp +++ b/engines/titanic/true_talk/tt_parser.cpp @@ -915,8 +915,88 @@ void TTparser::removeConcept(TTconcept *concept) { } int TTparser::checkForAction() { + int status = SS_VALID; + bool flag = false; + bool actionFlag = false; + + if (_conceptP && _currentWordP) { + // Firstly we need to get the next word to process, and remove it from + // the list pointed to by _currentWordP + TTword *word = _currentWordP; + if (word->_nextP) { + // Chain of words, so we need to find the last word of the chain, + // and set the last-but-one's _nextP to nullptr to detach the last one + TTword *prior = nullptr; + for (word = word->_nextP; word->_nextP; word = word->_nextP) { + prior = word; + } + + if (prior) + prior->_nextP = nullptr; + } else { + // No chain, so singular word can simply be removed + _currentWordP = nullptr; + if (word->_id == 906 && _sentence->_field2C == 1) + _sentence->_field2C = 12; + } + + if (word->_text == "do" || word->_text == "doing" || word->_text == "does" || + word->_text == "done") { + TTstring doStr("do"); + TTaction *action = new TTaction(doStr, WC_ACTION, 112, 0, _sentenceConcept->get18()); + + if (!action->isValid()) { + status = SS_4; + } else { + // Have the new action replace the old word instance + delete word; + word = action; + actionFlag = true; + } + } + + addToConceptList(word); + delete word; + flag = true; + } + + // Handle any remaining words + TTword *reqWord = nullptr; + while (_currentWordP) { + if (considerRequests(_currentWordP) > 1) { + reqWord = _currentWordP; + } else { + // Delete the top of the word chain + TTword *wordP = _currentWordP; + _currentWordP = _currentWordP->_nextP; + delete wordP; + } + } + + if (flag && _conceptP) { + if (actionFlag && (!_sentenceConcept->_concept1P || _sentenceConcept->_concept1P->isWordId(113))) { + _sentenceConcept->replaceConcept(0, 1, _conceptP); + } else if (!_sentenceConcept->_concept5P) { + _sentenceConcept->replaceConcept(1, 5, _conceptP); + } else if (_sentenceConcept->_concept5P->isWordId(904)) { + _sentenceConcept->replaceConcept(0, 5, _conceptP); + } + + removeConcept(_conceptP); + } + + if (_sentence->fn2(3, TTstring("thePlayer"), _sentenceConcept) && !flag) { + if (_sentenceConcept->concept1WordId() == 101) { + _sentence->_field2C = 16; + } else if (_sentence->_field2C != 18 && _sentenceConcept->concept1WordId() == 102) { + if (_sentence->fn2(0, TTstring("targetNpc"), _sentenceConcept)) + _sentence->_field2C = 15; + } + } + + // TODO - return 0; + return status; } int TTparser::fn2(TTword *word) { diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h index b6ec859794..3e8718df2a 100644 --- a/engines/titanic/true_talk/tt_string.h +++ b/engines/titanic/true_talk/tt_string.h @@ -38,7 +38,7 @@ struct TTstringData { TTstringData(const CString &str) : _string(str), _referenceCount(1) {} }; -enum TTstringStatus { SS_VALID = 0, SS_1 = 1, SS_5 = 5, SS_7 = 7, SS_8 = 8, SS_11 = 11, SS_13 = 13 }; +enum TTstringStatus { SS_VALID = 0, SS_1 = 1, SS_4 = 4, SS_5 = 5, SS_7 = 7, SS_8 = 8, SS_11 = 11, SS_13 = 13 }; class TTstring { private: diff --git a/engines/titanic/true_talk/tt_vocab.cpp b/engines/titanic/true_talk/tt_vocab.cpp index 062b598609..350fc71d35 100644 --- a/engines/titanic/true_talk/tt_vocab.cpp +++ b/engines/titanic/true_talk/tt_vocab.cpp @@ -131,7 +131,7 @@ int TTvocab::load(const CString &name) { }
void TTvocab::addWord(TTword *word) {
- TTword *existingWord = findWord(word->_string);
+ TTword *existingWord = findWord(word->_text);
if (existingWord) {
if (word->_synP) {
@@ -540,7 +540,7 @@ TTword *TTvocab::getPrefixedWord(TTstring &str) const { if (word->hasSynonyms())
word->setSynStr(str);
else
- word->_string = str;
+ word->_text = str;
}
delete tempStr;
diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp index e799507d22..1bf4783459 100644 --- a/engines/titanic/true_talk/tt_word.cpp +++ b/engines/titanic/true_talk/tt_word.cpp @@ -26,7 +26,7 @@ namespace Titanic { -TTword::TTword(TTstring &str, WordClass wordClass, int id) : _string(str), +TTword::TTword(TTstring &str, WordClass wordClass, int id) : _text(str), _wordClass(wordClass), _id(id), _tag(0), _field24(0), _field28(0), _synP(nullptr), _nextP(nullptr) { _status = str.getStatus() == SS_VALID ? SS_VALID : SS_5; @@ -38,7 +38,7 @@ TTword::TTword(const TTword *src) { return; } - _string = src->_string; + _text = src->_text; _wordClass = src->_wordClass; _id = src->_id; _tag = src->_tag; @@ -138,7 +138,7 @@ int TTword::load(SimpleFile *file, WordClass wordClass) { int id; if (file->scanf("%d %s %s", &id, &str1, &str2)) { - _string = str1; + _text = str1; _id = id; _tag = readNumber(str2.c_str()); _wordClass = wordClass; @@ -186,7 +186,7 @@ bool TTword::findSynByName(const TTstring &str, TTsynonym *dest, int mode) const } bool TTword::compareTo(const char *str) const { - return _string == str; + return _text == str; } TTword *TTword::copy() const { diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h index 94edee329e..ef907964c9 100644 --- a/engines/titanic/true_talk/tt_word.h +++ b/engines/titanic/true_talk/tt_word.h @@ -59,7 +59,7 @@ protected: public: TTword *_nextP; TTsynonym *_synP; - TTstring _string; + TTstring _text; WordClass _wordClass; int _id; uint _tag; @@ -111,13 +111,13 @@ public: */ bool findSynByName(const TTstring &str, TTsynonym *dest, int mode) const; - const char *c_str() const { return _string.c_str(); } + const char *c_str() const { return _text.c_str(); } operator const char *() const { return c_str(); } /** * Return the text of the word */ - const TTstring getText() { return _string; } + const TTstring getText() { return _text; } /** * Compares the word's text to a passed string @@ -137,6 +137,11 @@ public: TTstringStatus getStatus() const { return _status; } /** + * Returns true if the word is in a valid state + */ + bool isValid() const { return _status == SS_VALID; } + + /** * Return the status of the entire word chain */ TTstringStatus getChainStatus() const; |