aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-23 22:40:20 -0400
committerPaul Gilbert2016-07-15 19:15:14 -0400
commitae9a04bd414b45bbd8d3c00357432457a92230f9 (patch)
treeb0a8ca974f55528b3164667cd0d7f5445e367613
parent2b6a6cffc0b1854734540170d8b91430b5cc2f97 (diff)
downloadscummvm-rg350-ae9a04bd414b45bbd8d3c00357432457a92230f9.tar.gz
scummvm-rg350-ae9a04bd414b45bbd8d3c00357432457a92230f9.tar.bz2
scummvm-rg350-ae9a04bd414b45bbd8d3c00357432457a92230f9.zip
TITANIC: Refactored TTsentenceSubBase to TTconceptNode
-rw-r--r--engines/titanic/module.mk1
-rw-r--r--engines/titanic/true_talk/tt_concept_node.cpp126
-rw-r--r--engines/titanic/true_talk/tt_concept_node.h65
-rw-r--r--engines/titanic/true_talk/tt_parser.cpp28
-rw-r--r--engines/titanic/true_talk/tt_parser.h2
-rw-r--r--engines/titanic/true_talk/tt_sentence.cpp97
-rw-r--r--engines/titanic/true_talk/tt_sentence.h39
7 files changed, 218 insertions, 140 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index b3d1444317..19e4aff31b 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -463,6 +463,7 @@ MODULE_OBJS := \
true_talk/tt_action.o \
true_talk/tt_adj.o \
true_talk/tt_concept.o \
+ true_talk/tt_concept_node.o \
true_talk/tt_hist.o \
true_talk/tt_major_word.o \
true_talk/tt_node.o \
diff --git a/engines/titanic/true_talk/tt_concept_node.cpp b/engines/titanic/true_talk/tt_concept_node.cpp
new file mode 100644
index 0000000000..9ad985746f
--- /dev/null
+++ b/engines/titanic/true_talk/tt_concept_node.cpp
@@ -0,0 +1,126 @@
+/* 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 "titanic/true_talk/tt_concept_node.h"
+#include "titanic/true_talk/script_handler.h"
+#include "titanic/titanic.h"
+
+namespace Titanic {
+
+TTconceptNode::TTconceptNode() : _concept0P(nullptr),
+ _concept1P(nullptr), _concept2P(nullptr), _concept3P(nullptr),
+ _concept4P(nullptr), _concept5P(nullptr), _field18(0),
+ _field1C(0), _nextP(nullptr), _status(0) {
+}
+
+TTconceptNode::TTconceptNode(const TTconceptNode &src) : _concept0P(nullptr),
+ _concept1P(nullptr), _concept2P(nullptr), _concept3P(nullptr),
+ _concept4P(nullptr), _concept5P(nullptr), _field18(0),
+ _field1C(0), _nextP(nullptr), _status(0) {
+ if (src._status) {
+ _status = SS_5;
+ } else {
+ // TODO
+ }
+}
+
+
+void TTconceptNode::deleteSiblings() {
+ // Iterate through the linked chain of nodes, deleting each in turn
+ for (TTconceptNode *curP = _nextP, *nextP = nullptr; nextP; curP = nextP) {
+ nextP = curP->_nextP;
+ delete curP;
+ }
+
+ _nextP = nullptr;
+}
+
+TTconcept **TTconceptNode::setConcept(int conceptIndex, TTconcept *src) {
+ TTconcept **conceptPP = nullptr;
+ switch (conceptIndex) {
+ case 1:
+ conceptPP = &_concept1P;
+ break;
+ case 2:
+ conceptPP = &_concept2P;
+ break;
+ case 3:
+ conceptPP = &_concept3P;
+ break;
+ case 4:
+ conceptPP = &_concept4P;
+ break;
+ case 5:
+ conceptPP = &_concept5P;
+ break;
+ default:
+ break;
+ }
+
+ bool isPronoun = false;
+ StringArray &pronouns = g_vm->_scriptHandler->_parser._pronouns;
+ for (uint idx = 0; idx < pronouns.size() && !isPronoun; ++idx) {
+ isPronoun = pronouns[idx] == src->getText();
+ }
+
+ CScriptHandler &scrHandler = *g_vm->_exeResources._owner;
+ if (!isPronoun) {
+ switch (conceptIndex) {
+ case 0:
+ delete scrHandler._concept2P;
+ scrHandler._concept2P = new TTconcept(*src);
+ break;
+
+ case 1:
+ delete scrHandler._concept4P;
+ scrHandler._concept4P = new TTconcept(*src);
+ break;
+
+ case 2:
+ delete scrHandler._concept1P;
+ scrHandler._concept1P = new TTconcept(*src);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return conceptPP;
+}
+
+int TTconceptNode::changeConcept(int mode, TTconcept **conceptPP, int conceptIndex) {
+ TTconcept **newConceptPP = setConcept(conceptIndex, *conceptPP);
+
+ if (mode == 0 || (mode == 1 && !*newConceptPP)) {
+ if (!*conceptPP)
+ return SS_5;
+
+ delete *newConceptPP;
+ *newConceptPP = new TTconcept(**conceptPP);
+ return SS_VALID;
+ } else {
+ return SS_1;
+ }
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/tt_concept_node.h b/engines/titanic/true_talk/tt_concept_node.h
new file mode 100644
index 0000000000..8fc1371f7b
--- /dev/null
+++ b/engines/titanic/true_talk/tt_concept_node.h
@@ -0,0 +1,65 @@
+/* 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_CONCEPT_NODE_H
+#define TITANIC_TT_CONCEPT_NODE_H
+
+#include "titanic/true_talk/tt_concept.h"
+
+namespace Titanic {
+
+class TTconceptNode {
+public:
+ TTconcept *_concept0P;
+ TTconcept *_concept1P;
+ TTconcept *_concept2P;
+ TTconcept *_concept3P;
+ TTconcept *_concept4P;
+ TTconcept *_concept5P;
+ int _field18;
+ int _field1C;
+ TTconceptNode *_nextP;
+ int _status;
+public:
+ TTconceptNode();
+ TTconceptNode(const TTconceptNode &src);
+
+ /**
+ * Delete any sibling chain attached to this node
+ */
+ void deleteSiblings();
+
+ void set18(int val) { _field18 = val; }
+ int get18() const { return _field18; }
+
+ /**
+ * Returns true if the node is valid
+ */
+ bool isValid() const { return _status == SS_VALID; }
+
+ TTconcept **setConcept(int conceptIndex, TTconcept *src);
+ int changeConcept(int mode, TTconcept **conceptPP, int conceptIndex);
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_TT_CONCEPT_NODE_H */
diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp
index 02ecf0aedd..d02aec931a 100644
--- a/engines/titanic/true_talk/tt_parser.cpp
+++ b/engines/titanic/true_talk/tt_parser.cpp
@@ -30,7 +30,7 @@
namespace Titanic {
-TTparser::TTparser(CScriptHandler *owner) : _owner(owner), _sentenceSub(nullptr),
+TTparser::TTparser(CScriptHandler *owner) : _owner(owner), _sentenceConcept(nullptr),
_sentence(nullptr), _fieldC(0), _field10(0), _field14(0),
_currentWordP(nullptr), _nodesP(nullptr), _conceptP(nullptr) {
loadArrays();
@@ -476,7 +476,7 @@ const NumberEntry *TTparser::replaceNumbers2(TTstring &line, int *startIndex) {
int TTparser::findFrames(TTsentence *sentence) {
static bool flag;
- _sentenceSub = &sentence->_sub;
+ _sentenceConcept = &sentence->_sentenceConcept;
_sentence = sentence;
TTstring *line = sentence->_normalizedLine.copy();
@@ -573,10 +573,10 @@ int TTparser::loadRequests(TTword *word) {
break;
}
- if (_sentenceSub) {
- if (_sentenceSub->get18() == 0 || _sentenceSub->get18() == 2) {
+ if (_sentenceConcept) {
+ if (_sentenceConcept->get18() == 0 || _sentenceConcept->get18() == 2) {
TTaction *action = static_cast<TTaction *>(word);
- _sentenceSub->set18(action->getVal());
+ _sentenceConcept->set18(action->getVal());
}
}
break;
@@ -621,8 +621,8 @@ int TTparser::loadRequests(TTword *word) {
case WC_CONJUNCTION:
if (_sentence->check2C()) {
- _sentenceSub->_field1C = 1;
- _sentenceSub = _sentenceSub->addSibling();
+ _sentenceConcept->_field1C = 1;
+ _sentenceConcept = _sentenceConcept->addSibling();
delete this;
} else {
addNode(23);
@@ -675,8 +675,8 @@ int TTparser::loadRequests(TTword *word) {
case 902:
case 904:
if (_sentence->_field2C == 9) {
- _sentenceSub->_field1C = 1;
- _sentenceSub = _sentenceSub->addSibling();
+ _sentenceConcept->_field1C = 1;
+ _sentenceConcept = _sentenceConcept->addSibling();
addNode(1);
}
else {
@@ -765,11 +765,11 @@ int TTparser::considerRequests(TTword *word) {
} else {
switch (nodeP->_tag) {
case CHECK_COMMAND_FORM:
- if (_sentenceSub->_concept1P && _sentence->_field2C == 1 &&
- !_sentenceSub->_concept0P) {
+ if (_sentenceConcept->_concept1P && _sentence->_field2C == 1 &&
+ !_sentenceConcept->_concept0P) {
concept = new TTconcept(_sentence->_npcScript, ST_NPC_SCRIPT);
- _sentenceSub->_concept0P = concept;
- _sentenceSub->_field18 = 3;
+ _sentenceConcept->_concept0P = concept;
+ _sentenceConcept->_field18 = 3;
}
flag = true;
@@ -786,7 +786,7 @@ int TTparser::considerRequests(TTword *word) {
break;
case OBJECT_IS_TO:
- flag = fn3(&_sentenceSub->_concept2P, 3);
+ flag = fn3(&_sentenceConcept->_concept2P, 3);
break;
case SEEK_ACTOR:
diff --git a/engines/titanic/true_talk/tt_parser.h b/engines/titanic/true_talk/tt_parser.h
index a8bb906559..3e8c91c917 100644
--- a/engines/titanic/true_talk/tt_parser.h
+++ b/engines/titanic/true_talk/tt_parser.h
@@ -164,7 +164,7 @@ private:
bool fn3(TTconcept **v, int v2);
public:
CScriptHandler *_owner;
- TTsentenceSub *_sentenceSub;
+ TTsentenceConcept *_sentenceConcept;
TTsentence *_sentence;
int _fieldC;
int _field10;
diff --git a/engines/titanic/true_talk/tt_sentence.cpp b/engines/titanic/true_talk/tt_sentence.cpp
index 7b49df2560..a78a4efa0e 100644
--- a/engines/titanic/true_talk/tt_sentence.cpp
+++ b/engines/titanic/true_talk/tt_sentence.cpp
@@ -27,99 +27,12 @@
namespace Titanic {
-TTsentenceSubBase::TTsentenceSubBase() : _concept0P(nullptr),
- _concept1P(nullptr), _concept2P(nullptr), _concept3P(nullptr),
- _concept4P(nullptr), _concept5P(nullptr), _field18(0),
- _field1C(0), _nextP(nullptr), _field24(0) {
-}
-
-void TTsentenceSubBase::deleteSiblings() {
- // Iterate through the linked chain of nodes, deleting each in turn
- for (TTsentenceSubBase *curP = _nextP, *nextP = nullptr; nextP; curP = nextP) {
- nextP = curP->_nextP;
- delete curP;
- }
-
- _nextP = nullptr;
-}
-
-TTconcept **TTsentenceSubBase::setConcept(int conceptIndex, TTconcept *src) {
- TTconcept **conceptPP = nullptr;
- switch (conceptIndex) {
- case 1:
- conceptPP = &_concept1P;
- break;
- case 2:
- conceptPP = &_concept2P;
- break;
- case 3:
- conceptPP = &_concept3P;
- break;
- case 4:
- conceptPP = &_concept4P;
- break;
- case 5:
- conceptPP = &_concept5P;
- break;
- default:
- break;
- }
-
- bool isPronoun = false;
- StringArray &pronouns = g_vm->_scriptHandler->_parser._pronouns;
- for (uint idx = 0; idx < pronouns.size() && !isPronoun; ++idx) {
- isPronoun = pronouns[idx] == src->getText();
- }
-
- CScriptHandler &scrHandler = *g_vm->_exeResources._owner;
- if (!isPronoun) {
- switch (conceptIndex) {
- case 0:
- delete scrHandler._concept2P;
- scrHandler._concept2P = new TTconcept(*src);
- break;
-
- case 1:
- delete scrHandler._concept4P;
- scrHandler._concept4P = new TTconcept(*src);
- break;
-
- case 2:
- delete scrHandler._concept1P;
- scrHandler._concept1P = new TTconcept(*src);
- break;
-
- default:
- break;
- }
- }
-
- return conceptPP;
-}
-
-int TTsentenceSubBase::changeConcept(int mode, TTconcept **conceptPP, int conceptIndex) {
- TTconcept **newConceptPP = setConcept(conceptIndex, *conceptPP);
-
- if (mode == 0 || (mode == 1 && !*newConceptPP)) {
- if (!*conceptPP)
- return SS_5;
-
- delete *newConceptPP;
- *newConceptPP = new TTconcept(**conceptPP);
- return SS_VALID;
- } else {
- return SS_1;
- }
-}
-
-/*------------------------------------------------------------------------*/
-
-TTsentenceSub *TTsentenceSub::addSibling() {
+TTsentenceConcept *TTsentenceConcept::addSibling() {
if (this == nullptr || _nextP != nullptr)
// This should never happen
return nullptr;
- TTsentenceSub *nextP = new TTsentenceSub();
+ TTsentenceConcept *nextP = new TTsentenceConcept();
_nextP = nextP;
return nextP;
}
@@ -134,13 +47,13 @@ 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) {
+TTsentence::TTsentence(const TTsentence *src) : _sentenceConcept(src->_sentenceConcept),
+ _initialLine(src->_initialLine), _normalizedLine(src->_normalizedLine) {
copyFrom(*src);
}
TTsentence::~TTsentence() {
- _sub.deleteSiblings();
+ _sentenceConcept.deleteSiblings();
if (_nodesP) {
_nodesP->deleteSiblings();
diff --git a/engines/titanic/true_talk/tt_sentence.h b/engines/titanic/true_talk/tt_sentence.h
index e995884ec0..6cee9705c4 100644
--- a/engines/titanic/true_talk/tt_sentence.h
+++ b/engines/titanic/true_talk/tt_sentence.h
@@ -23,6 +23,7 @@
#ifndef TITANIC_TT_SENTENCE_H
#define TITANIC_TT_SENTENCE_H
+#include "titanic/true_talk/tt_concept_node.h"
#include "titanic/true_talk/tt_npc_script.h"
#include "titanic/true_talk/tt_room_script.h"
#include "titanic/true_talk/tt_sentence_node.h"
@@ -31,45 +32,17 @@
namespace Titanic {
class CScriptHandler;
-class TTconcept;
class TTword;
-class TTsentenceSubBase {
+class TTsentenceConcept : public TTconceptNode {
public:
- TTconcept *_concept0P;
- TTconcept *_concept1P;
- TTconcept *_concept2P;
- TTconcept *_concept3P;
- TTconcept *_concept4P;
- TTconcept *_concept5P;
- int _field18;
- int _field1C;
- TTsentenceSubBase *_nextP;
- int _field24;
-public:
- TTsentenceSubBase();
-
- /**
- * Delete any sibling chain attached to this node
- */
- void deleteSiblings();
-
- void set18(int val) { _field18 = val; }
- int get18() const { return _field18; }
- bool is24() const { return _field24 == 0; }
-
- TTconcept **setConcept(int conceptIndex, TTconcept *src);
- int changeConcept(int mode, TTconcept **conceptPP, int conceptIndex);
-};
-
-class TTsentenceSub : public TTsentenceSubBase {
-public:
- TTsentenceSub() : TTsentenceSubBase() {}
+ TTsentenceConcept() : TTconceptNode() {}
+ TTsentenceConcept(const TTsentenceConcept &src) : TTconceptNode(src) {}
/**
* Adds a new sibling instance
*/
- TTsentenceSub *addSibling();
+ TTsentenceConcept *addSibling();
};
class TTsentence {
@@ -87,7 +60,7 @@ private:
*/
void copyFrom(const TTsentence &src);
public:
- TTsentenceSub _sub;
+ TTsentenceConcept _sentenceConcept;
TTstring _initialLine;
TTstring _normalizedLine;
int _field58;