aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-11 07:23:08 -0400
committerPaul Gilbert2016-07-10 16:39:11 -0400
commitb8c41050211c6b5c25a9e02a767a54b8e1ef55d7 (patch)
treeab171016649c8a56ad365c7234b4b6bf73703df2 /engines
parente86ce94441a032de3707eb7576060d9281a3fec0 (diff)
downloadscummvm-rg350-b8c41050211c6b5c25a9e02a767a54b8e1ef55d7.tar.gz
scummvm-rg350-b8c41050211c6b5c25a9e02a767a54b8e1ef55d7.tar.bz2
scummvm-rg350-b8c41050211c6b5c25a9e02a767a54b8e1ef55d7.zip
TITANIC: Implemented STVocab addWord
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/true_talk/st_vocab.cpp26
-rw-r--r--engines/titanic/true_talk/st_vocab.h4
-rw-r--r--engines/titanic/true_talk/tt_word.cpp7
-rw-r--r--engines/titanic/true_talk/tt_word.h9
4 files changed, 39 insertions, 7 deletions
diff --git a/engines/titanic/true_talk/st_vocab.cpp b/engines/titanic/true_talk/st_vocab.cpp
index bf4d366d60..5135f6466e 100644
--- a/engines/titanic/true_talk/st_vocab.cpp
+++ b/engines/titanic/true_talk/st_vocab.cpp
@@ -26,7 +26,7 @@
namespace Titanic {
-STVocab::STVocab(int val): _vocab(nullptr), _field4(0), _word(nullptr),
+STVocab::STVocab(int val): _pHead(nullptr), _pTail(nullptr), _word(nullptr),
_fieldC(0), _field10(0), _field18(val) {
_field14 = load("STVOCAB.TXT");
}
@@ -117,13 +117,33 @@ int STVocab::load(const CString &name) {
}
void STVocab::addWord(TTword *word) {
- // TODO
+ TTword *existingWord = findWord(word->_string);
+
+ if (existingWord) {
+ if (word->_synP) {
+ // Move over the synonym
+ existingWord->appendNode(word->_synP);
+ word->_synP = nullptr;
+ }
+
+ _word = nullptr;
+ if (word)
+ delete word;
+ } else if (_pTail) {
+ _pTail->_pNext = word;
+ _pTail = word;
+ } else {
+ if (!_pHead)
+ _pHead = word;
+
+ _pTail = word;
+ }
}
TTword *STVocab::findWord(const TTString &str) {
TTsynonymNode *tempNode = new TTsynonymNode();
bool flag = false;
- TTword *word = _vocab;
+ TTword *word = _pHead;
while (!flag) {
if (_field18 != 3 || strcmp(word->c_str(), str)) {
diff --git a/engines/titanic/true_talk/st_vocab.h b/engines/titanic/true_talk/st_vocab.h
index 19fe0b24a6..68ce86b7cf 100644
--- a/engines/titanic/true_talk/st_vocab.h
+++ b/engines/titanic/true_talk/st_vocab.h
@@ -31,8 +31,8 @@ namespace Titanic {
class STVocab {
private:
- TTword *_vocab;
- int _field4;
+ TTword *_pHead;
+ TTword *_pTail;
TTword *_word;
int _fieldC;
int _field10;
diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp
index 7f4b5a8dde..7fc5263c88 100644
--- a/engines/titanic/true_talk/tt_word.cpp
+++ b/engines/titanic/true_talk/tt_word.cpp
@@ -56,6 +56,13 @@ int TTword::readSyn(SimpleFile *file) {
return 0;
}
+void TTword::appendNode(TTsynonymNode *node) {
+ if (_synP)
+ _synP->addNode(node);
+ else
+ _synP = node;
+}
+
int TTword::load(SimpleFile *file, int mode) {
CString str1, str2;
int val;
diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h
index 277f180d6c..a535cac834 100644
--- a/engines/titanic/true_talk/tt_word.h
+++ b/engines/titanic/true_talk/tt_word.h
@@ -31,8 +31,6 @@ namespace Titanic {
class TTword {
protected:
- TTString _string;
- TTsynonymNode *_synP;
TTStringStatus _status;
int _wordMode;
int _field1C;
@@ -48,6 +46,8 @@ protected:
bool testFileHandle(SimpleFile *file) const;
public:
TTword *_pNext;
+ TTsynonymNode *_synP;
+ TTString _string;
public:
TTword(TTString &str, int mode, int val2);
@@ -57,6 +57,11 @@ public:
int readSyn(SimpleFile *file);
/**
+ * Either sets the first synonym for a word, or adds it to an existing one
+ */
+ void appendNode(TTsynonymNode *node);
+
+ /**
* Load the word
*/
int load(SimpleFile *file, int mode);