aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-17 22:25:59 -0400
committerPaul Gilbert2016-07-15 19:12:50 -0400
commit5b42ae357ebdf5fd2665351a41127fc76167beb5 (patch)
tree85c10634713b603baa8311530655fa08f6eb2d52
parent5da19b674d3b9d24517a266e369728f3b5c2957a (diff)
downloadscummvm-rg350-5b42ae357ebdf5fd2665351a41127fc76167beb5.tar.gz
scummvm-rg350-5b42ae357ebdf5fd2665351a41127fc76167beb5.tar.bz2
scummvm-rg350-5b42ae357ebdf5fd2665351a41127fc76167beb5.zip
TITANIC: Refactor TTstringNode to have a base TTnode class
-rw-r--r--engines/titanic/module.mk2
-rw-r--r--engines/titanic/true_talk/tt_hist.cpp8
-rw-r--r--engines/titanic/true_talk/tt_hist.h4
-rw-r--r--engines/titanic/true_talk/tt_node.cpp60
-rw-r--r--engines/titanic/true_talk/tt_node.h54
-rw-r--r--engines/titanic/true_talk/tt_sentence.cpp9
-rw-r--r--engines/titanic/true_talk/tt_sentence.h6
-rw-r--r--engines/titanic/true_talk/tt_sentence_node.cpp31
-rw-r--r--engines/titanic/true_talk/tt_sentence_node.h37
-rw-r--r--engines/titanic/true_talk/tt_string_node.cpp32
-rw-r--r--engines/titanic/true_talk/tt_string_node.h21
-rw-r--r--engines/titanic/true_talk/tt_synonym.cpp12
-rw-r--r--engines/titanic/true_talk/tt_synonym.h5
-rw-r--r--engines/titanic/true_talk/tt_vocab.cpp28
-rw-r--r--engines/titanic/true_talk/tt_vocab.h4
-rw-r--r--engines/titanic/true_talk/tt_word.cpp22
-rw-r--r--engines/titanic/true_talk/tt_word.h2
17 files changed, 251 insertions, 86 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index 9e10577758..1568eb5a8c 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -464,6 +464,7 @@ MODULE_OBJS := \
true_talk/tt_adj.o \
true_talk/tt_hist.o \
true_talk/tt_major_word.o \
+ true_talk/tt_node.o \
true_talk/tt_npc_script.o \
true_talk/tt_parser.o \
true_talk/tt_picture.o \
@@ -472,6 +473,7 @@ MODULE_OBJS := \
true_talk/tt_script_base.o \
true_talk/tt_scripts.o \
true_talk/tt_sentence.o \
+ true_talk/tt_sentence_node.o \
true_talk/tt_string.o \
true_talk/tt_string_node.o \
true_talk/tt_synonym.o \
diff --git a/engines/titanic/true_talk/tt_hist.cpp b/engines/titanic/true_talk/tt_hist.cpp
index e0f6cb88b6..fae9ae6286 100644
--- a/engines/titanic/true_talk/tt_hist.cpp
+++ b/engines/titanic/true_talk/tt_hist.cpp
@@ -25,8 +25,12 @@
namespace Titanic {
-TThist::TThist(TTsentence *sentence) {
- // TODO
+TThist::TThist(TTsentence *sentence) : _status(0) {
+ _sentence = new TTsentence(sentence);
+}
+
+TThist::~TThist() {
+ delete _sentence;
}
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_hist.h b/engines/titanic/true_talk/tt_hist.h
index 7ba0032a4d..f67a0387c5 100644
--- a/engines/titanic/true_talk/tt_hist.h
+++ b/engines/titanic/true_talk/tt_hist.h
@@ -30,9 +30,11 @@ class TTsentence;
class TThist {
protected:
int _field0;
- TTsentence *_input;
+ TTsentence *_sentence;
+ int _status;
public:
TThist(TTsentence *sentence);
+ virtual ~TThist();
};
class TTscriptHist : public TThist {
diff --git a/engines/titanic/true_talk/tt_node.cpp b/engines/titanic/true_talk/tt_node.cpp
new file mode 100644
index 0000000000..8b175a0906
--- /dev/null
+++ b/engines/titanic/true_talk/tt_node.cpp
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/textconsole.h"
+#include "titanic/true_talk/tt_node.h"
+
+namespace Titanic {
+
+TTnode::TTnode() : _priorP(nullptr), _nextP(nullptr) {
+}
+
+TTnode::~TTnode() {
+ detach();
+}
+
+void TTnode::addNode(TTnode *newNode) {
+ TTnode *tail = getTail();
+ tail->_nextP = newNode;
+ newNode->_priorP = this;
+}
+
+void TTnode::detach() {
+ if (_priorP)
+ _priorP->_nextP = _nextP;
+
+ if (_nextP)
+ _nextP->_priorP = _priorP;
+}
+
+TTnode *TTnode::getTail() {
+ if (_nextP == nullptr)
+ return this;
+
+ TTnode *node = _nextP;
+ while (node->_nextP)
+ node = node->_nextP;
+
+ return node;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_node.h b/engines/titanic/true_talk/tt_node.h
new file mode 100644
index 0000000000..668b909bd5
--- /dev/null
+++ b/engines/titanic/true_talk/tt_node.h
@@ -0,0 +1,54 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_TT_NODE_H
+#define TITANIC_TT_NODE_H
+
+namespace Titanic {
+
+class TTnode {
+public:
+ TTnode *_priorP;
+ TTnode *_nextP;
+public:
+ TTnode();
+ virtual ~TTnode();
+
+ /**
+ * Links the passed node to this node as a linked list
+ */
+ void addNode(TTnode *newNode);
+
+ /**
+ * Detaches a node from any predecessor and/or successor
+ */
+ void detach();
+
+ /**
+ * Returns the final node at the end of the linked list of nodes
+ */
+ TTnode *getTail();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_TT_NODE_H */
diff --git a/engines/titanic/true_talk/tt_sentence.cpp b/engines/titanic/true_talk/tt_sentence.cpp
index e5968bd35a..e39a627694 100644
--- a/engines/titanic/true_talk/tt_sentence.cpp
+++ b/engines/titanic/true_talk/tt_sentence.cpp
@@ -40,6 +40,15 @@ TTsentence::TTsentence(int inputCtr, const TTstring &line, CScriptHandler *owner
_status = _initialLine.isValid() && _normalizedLine.isValid() ? SS_11: SS_VALID;
}
+TTsentence::TTsentence(const TTsentence *src) : _initialLine(src->_initialLine),
+ _normalizedLine(src->_normalizedLine) {
+ copyFrom(*src);
+}
+
+void TTsentence::copyFrom(const TTsentence &src) {
+
+}
+
void TTsentence::set38(int val) {
_field38 = val;
}
diff --git a/engines/titanic/true_talk/tt_sentence.h b/engines/titanic/true_talk/tt_sentence.h
index 94d7bfc8d9..784177dd3a 100644
--- a/engines/titanic/true_talk/tt_sentence.h
+++ b/engines/titanic/true_talk/tt_sentence.h
@@ -65,12 +65,18 @@ private:
int _field58;
int _field5C;
int _status;
+private:
+ /**
+ * Copy sentence data from a given source
+ */
+ void copyFrom(const TTsentence &src);
public:
TTstring _initialLine;
TTstring _normalizedLine;
public:
TTsentence(int inputCtr, const TTstring &line, CScriptHandler *owner,
TTroomScript *roomScript, TTnpcScript *npcScript);
+ TTsentence(const TTsentence *src);
void set38(int v);
};
diff --git a/engines/titanic/true_talk/tt_sentence_node.cpp b/engines/titanic/true_talk/tt_sentence_node.cpp
new file mode 100644
index 0000000000..46a1412a2a
--- /dev/null
+++ b/engines/titanic/true_talk/tt_sentence_node.cpp
@@ -0,0 +1,31 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/textconsole.h"
+#include "titanic/true_talk/tt_sentence_node.h"
+
+namespace Titanic {
+
+TTsentenceNode::TTsentenceNode() : TTnode() {
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_sentence_node.h b/engines/titanic/true_talk/tt_sentence_node.h
new file mode 100644
index 0000000000..5d22454d82
--- /dev/null
+++ b/engines/titanic/true_talk/tt_sentence_node.h
@@ -0,0 +1,37 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_TT_SENTENCE_NODE_H
+#define TITANIC_TT_SENTENCE_NODE_H
+
+#include "titanic/true_talk/tt_node.h"
+
+namespace Titanic {
+
+class TTsentenceNode : public TTnode {
+public:
+ TTsentenceNode();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_TT_SENTENCE_NODE_H */
diff --git a/engines/titanic/true_talk/tt_string_node.cpp b/engines/titanic/true_talk/tt_string_node.cpp
index d125d328e7..1c0b5b9a90 100644
--- a/engines/titanic/true_talk/tt_string_node.cpp
+++ b/engines/titanic/true_talk/tt_string_node.cpp
@@ -25,12 +25,7 @@
namespace Titanic {
-TTstringNode::TTstringNode() : _pPrior(nullptr), _pNext(nullptr),
- _file(HANDLE_STDIN), _mode(0), _field1C(0) {
-}
-
-TTstringNode::~TTstringNode() {
- detach();
+TTstringNode::TTstringNode() : TTnode() {
}
void TTstringNode::initialize(int mode) {
@@ -59,29 +54,4 @@ void TTstringNode::initialize(TTstringNode *oldNode) {
delete oldNode;
}
-void TTstringNode::addNode(TTstringNode *newNode) {
- TTstringNode *tail = getTail();
- tail->_pNext = newNode;
- newNode->_pPrior = this;
-}
-
-void TTstringNode::detach() {
- if (_pPrior)
- _pPrior->_pNext = _pNext;
-
- if (_pNext)
- _pNext->_pPrior = _pPrior;
-}
-
-TTstringNode *TTstringNode::getTail() {
- if (_pNext == nullptr)
- return this;
-
- TTstringNode *node = _pNext;
- while (node->_pNext)
- node = node->_pNext;
-
- return node;
-}
-
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_string_node.h b/engines/titanic/true_talk/tt_string_node.h
index f9f73ce545..31013a950e 100644
--- a/engines/titanic/true_talk/tt_string_node.h
+++ b/engines/titanic/true_talk/tt_string_node.h
@@ -23,17 +23,13 @@
#ifndef TITANIC_TT_STRING_NODE_H
#define TITANIC_TT_STRING_NODE_H
+#include "titanic/true_talk/tt_node.h"
#include "titanic/true_talk/tt_string.h"
#include "titanic/support/exe_resources.h"
namespace Titanic {
-class TTstringNode {
-private:
- /**
- * Returns the final node at the end of the linked list of nodes
- */
- TTstringNode *getTail();
+class TTstringNode : public TTnode {
protected:
/**
* Initializes state for the node
@@ -45,25 +41,12 @@ protected:
*/
void initialize(TTstringNode *oldNode);
public:
- TTstringNode *_pPrior;
- TTstringNode *_pNext;
TTstring _string;
FileHandle _file;
int _mode;
int _field1C;
public:
TTstringNode();
- virtual ~TTstringNode();
-
- /**
- * Links the passed node to this node as a linked list
- */
- void addNode(TTstringNode *newNode);
-
- /**
- * Detaches a node from any predecessor and/or successor
- */
- void detach();
};
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_synonym.cpp b/engines/titanic/true_talk/tt_synonym.cpp
index cac9f647cc..0e5ae39e82 100644
--- a/engines/titanic/true_talk/tt_synonym.cpp
+++ b/engines/titanic/true_talk/tt_synonym.cpp
@@ -24,24 +24,26 @@
namespace Titanic {
-TTsynonym::TTsynonym() : TTstringNode() {
+TTsynonym::TTsynonym() : TTstringNode(), _file(HANDLE_STDIN),
+ _mode(0), _field1C(0) {
}
-TTsynonym::TTsynonym(const TTsynonym *src) {
+TTsynonym::TTsynonym(const TTsynonym *src) : TTstringNode(),
+ _mode(0), _field1C(0) {
_string = src->_string;
initialize(src->_mode);
_file = src->_file;
}
TTsynonym::TTsynonym(int mode, const char *str, FileHandle file) :
- TTstringNode() {
+ TTstringNode(), _mode(0), _field1C(0) {
_string = str;
initialize(mode);
_file = file;
}
TTsynonym *TTsynonym::findByName(TTsynonym *start, const TTstring &str, int mode) {
- for (; start; start = static_cast<TTsynonym *>(start->_pNext)) {
+ for (; start; start = static_cast<TTsynonym *>(start->_nextP)) {
if (start->_mode == mode || (mode == 3 && start->_mode < 3)) {
if (!strcmp(start->_string.c_str(), str.c_str()))
start;
@@ -69,7 +71,7 @@ TTsynonym *TTsynonym::copy(TTsynonym *src) {
}
int TTsynonym::save(SimpleFile *file) {
- for (TTstringNode *synP = this; synP; synP = synP->_pNext) {
+ for (TTstringNode *synP = this; synP; synP = static_cast<TTstringNode *>(synP->_nextP)) {
file->writeFormat("%s", " 0 ");
synP->_string.save(file);
file->writeFormat("%c", ' ');
diff --git a/engines/titanic/true_talk/tt_synonym.h b/engines/titanic/true_talk/tt_synonym.h
index 40f7ad3449..288e9809ff 100644
--- a/engines/titanic/true_talk/tt_synonym.h
+++ b/engines/titanic/true_talk/tt_synonym.h
@@ -30,6 +30,11 @@ namespace Titanic {
class TTsynonym : public TTstringNode {
public:
+ TTstring _string;
+ FileHandle _file;
+ int _mode;
+ int _field1C;
+public:
TTsynonym();
TTsynonym(const TTsynonym *src);
TTsynonym(int mode, const char *str, FileHandle file);
diff --git a/engines/titanic/true_talk/tt_vocab.cpp b/engines/titanic/true_talk/tt_vocab.cpp
index 3d2a9d98c8..707cbafff4 100644
--- a/engines/titanic/true_talk/tt_vocab.cpp
+++ b/engines/titanic/true_talk/tt_vocab.cpp
@@ -32,16 +32,16 @@
namespace Titanic {
-TTvocab::TTvocab(int val): _pHead(nullptr), _pTail(nullptr), _word(nullptr),
+TTvocab::TTvocab(int val): _headP(nullptr), _tailP(nullptr), _word(nullptr),
_fieldC(0), _field10(0), _field18(val) {
_field14 = load("STVOCAB.TXT");
}
TTvocab::~TTvocab() {
- if (_pHead) {
- _pHead->deleteSiblings();
- delete _pHead;
- _pHead = _pTail = nullptr;
+ if (_headP) {
+ _headP->deleteSiblings();
+ delete _headP;
+ _headP = _tailP = nullptr;
}
}
@@ -143,28 +143,28 @@ void TTvocab::addWord(TTword *word) {
_word = nullptr;
if (word)
delete word;
- } else if (_pTail) {
- _pTail->_pNext = word;
- _pTail = word;
+ } else if (_tailP) {
+ _tailP->_nextP = word;
+ _tailP = word;
} else {
- if (!_pHead)
- _pHead = word;
+ if (!_headP)
+ _headP = word;
- _pTail = word;
+ _tailP = word;
}
}
TTword *TTvocab::findWord(const TTstring &str) {
TTsynonym *tempNode = new TTsynonym();
bool flag = false;
- TTword *word = _pHead;
+ TTword *word = _headP;
while (word && !flag) {
if (_field18 != 3 || strcmp(word->c_str(), str)) {
if (word->scanCopy(str, tempNode, _field18))
flag = true;
else
- word = word->_pNext;
+ word = word->_nextP;
} else {
flag = true;
}
@@ -177,7 +177,7 @@ TTword *TTvocab::findWord(const TTstring &str) {
TTword *TTvocab::getPrimeWord(TTstring &str, TTword **words) {
TTsynonym *synonym = new TTsynonym();
char c = str.charAt(0);
- TTword *vocabList = _pHead;
+ TTword *vocabList = _headP;
TTword *returnWord = nullptr;
if (!Common::isDigit(c)) {
diff --git a/engines/titanic/true_talk/tt_vocab.h b/engines/titanic/true_talk/tt_vocab.h
index 804d8cbae3..40e9458cb7 100644
--- a/engines/titanic/true_talk/tt_vocab.h
+++ b/engines/titanic/true_talk/tt_vocab.h
@@ -31,8 +31,8 @@ namespace Titanic {
class TTvocab {
private:
- TTword *_pHead;
- TTword *_pTail;
+ TTword *_headP;
+ TTword *_tailP;
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 aa602d869c..90c7cf1a9d 100644
--- a/engines/titanic/true_talk/tt_word.cpp
+++ b/engines/titanic/true_talk/tt_word.cpp
@@ -27,8 +27,8 @@
namespace Titanic {
TTword::TTword(TTstring &str, int mode, int val2) : _string(str),
- _wordMode(mode), _field1C(val2), _pNext(nullptr), _synP(nullptr),
- _field20(0), _field24(0), _field28(0) {
+ _wordMode(mode), _field1C(val2), _field20(0), _field24(0),
+ _field28(0), _synP(nullptr), _nextP(nullptr) {
_status = str.getStatus() == SS_VALID ? SS_VALID : SS_5;
}
@@ -50,11 +50,11 @@ TTword::TTword(TTword *src) {
if (!newSyn) {
_status = SS_7;
} else {
- newSyn->_pPrior = priorSyn;
- newSyn->_pNext = nullptr;
+ newSyn->_priorP = priorSyn;
+ newSyn->_nextP = nullptr;
if (priorSyn) {
- priorSyn->_pNext = newSyn;
+ priorSyn->_nextP = newSyn;
} else {
_synP = newSyn;
}
@@ -63,15 +63,15 @@ TTword::TTword(TTword *src) {
}
}
- _pNext = src->_pNext;
+ _nextP = src->_nextP;
_field24 = src->_field24;
_field28 = src->_field28;
}
void TTword::deleteSiblings() {
- while (_pNext) {
- TTword *next = _pNext;
- _pNext = next->_pNext;
+ while (_nextP) {
+ TTword *next = _nextP;
+ _nextP = next->_nextP;
delete next;
}
}
@@ -148,8 +148,8 @@ TTword *TTword::scanCopy(const TTstring &str, TTsynonym *node, int mode) {
TTsynonym *strNode = TTsynonym::findByName(_synP, str, mode);
if (strNode) {
node->copy(strNode);
- node->_pPrior = nullptr;
- node->_pNext = nullptr;
+ node->_priorP = nullptr;
+ node->_nextP = nullptr;
}
}
diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h
index f77f11ce75..7e692ffeea 100644
--- a/engines/titanic/true_talk/tt_word.h
+++ b/engines/titanic/true_talk/tt_word.h
@@ -46,7 +46,7 @@ protected:
bool testFileHandle(SimpleFile *file) const { return true; }
bool testFileHandle(FileHandle resHandle) const;
public:
- TTword *_pNext;
+ TTword *_nextP;
TTsynonym *_synP;
TTstring _string;
public: