From 7b71462046155e2927bd1f76634ea9b5bf45d381 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 12 May 2016 20:16:08 -0400 Subject: TITANIC: Implementing virtual methods for TTword --- engines/titanic/true_talk/script_handler.h | 2 ++ engines/titanic/true_talk/tt_string.h | 12 ++++++++ engines/titanic/true_talk/tt_string_node.cpp | 6 ++-- engines/titanic/true_talk/tt_string_node.h | 3 +- engines/titanic/true_talk/tt_synonym.cpp | 6 ++-- engines/titanic/true_talk/tt_synonym.h | 5 +++- engines/titanic/true_talk/tt_vocab.cpp | 29 +++++++++++++++++++ engines/titanic/true_talk/tt_vocab.h | 2 ++ engines/titanic/true_talk/tt_word.cpp | 26 +++++++++++++++-- engines/titanic/true_talk/tt_word.h | 43 +++++++++++++++++++++++++++- 10 files changed, 123 insertions(+), 11 deletions(-) (limited to 'engines/titanic/true_talk') diff --git a/engines/titanic/true_talk/script_handler.h b/engines/titanic/true_talk/script_handler.h index 80532a7dda..73ddb7bee4 100644 --- a/engines/titanic/true_talk/script_handler.h +++ b/engines/titanic/true_talk/script_handler.h @@ -91,6 +91,8 @@ public: * Open a resource for access */ SimpleFile *openResource(const CString &name); + + }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h index 7d231b123a..9cb92cf330 100644 --- a/engines/titanic/true_talk/tt_string.h +++ b/engines/titanic/true_talk/tt_string.h @@ -63,8 +63,20 @@ public: */ TTStringStatus getStatus() const { return _status; } + /** + * Get a char * pointer to the string data + */ const char *c_str() const { return _data->_string.c_str(); } + + /** + * Automatic operator to convert to a const char * + */ operator const char *() const { return c_str(); } + + /** + * Get a character at a specified index + */ + char charAt(int index) const { return *(c_str() + index); } }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_string_node.cpp b/engines/titanic/true_talk/tt_string_node.cpp index cf01ac6063..d125d328e7 100644 --- a/engines/titanic/true_talk/tt_string_node.cpp +++ b/engines/titanic/true_talk/tt_string_node.cpp @@ -26,7 +26,7 @@ namespace Titanic { TTstringNode::TTstringNode() : _pPrior(nullptr), _pNext(nullptr), - _field14(0), _mode(0), _field1C(0) { + _file(HANDLE_STDIN), _mode(0), _field1C(0) { } TTstringNode::~TTstringNode() { @@ -35,7 +35,7 @@ TTstringNode::~TTstringNode() { void TTstringNode::initialize(int mode) { _mode = mode; - _field14 = 0; + _file = HANDLE_STDIN; if (_string.isValid()) { _field1C = 0; @@ -47,7 +47,7 @@ void TTstringNode::initialize(int mode) { void TTstringNode::initialize(TTstringNode *oldNode) { _mode = oldNode->_mode; - _field14 = oldNode->_field14; + _file = oldNode->_file; if (_string.isValid()) { _field1C = 0; diff --git a/engines/titanic/true_talk/tt_string_node.h b/engines/titanic/true_talk/tt_string_node.h index dddef8db0f..6994a0d1cd 100644 --- a/engines/titanic/true_talk/tt_string_node.h +++ b/engines/titanic/true_talk/tt_string_node.h @@ -24,6 +24,7 @@ #define TITANIC_TT_STRING_NODE_H #include "titanic/true_talk/tt_string.h" +#include "titanic/support/exe_resources.h" namespace Titanic { @@ -47,7 +48,7 @@ public: TTstringNode *_pPrior; TTstringNode *_pNext; TTString _string; - int _field14; + FileHandle _file; int _mode; int _field1C; public: diff --git a/engines/titanic/true_talk/tt_synonym.cpp b/engines/titanic/true_talk/tt_synonym.cpp index 5da124ab27..ea45f2e74a 100644 --- a/engines/titanic/true_talk/tt_synonym.cpp +++ b/engines/titanic/true_talk/tt_synonym.cpp @@ -30,14 +30,14 @@ TTsynonym::TTsynonym() : TTstringNode() { TTsynonym::TTsynonym(const TTstringNode *src) { _string = src->_string; initialize(src->_mode); - _field14 = src->_field14; + _file = src->_file; } -TTsynonym::TTsynonym(int mode, const char *str, int val2) : +TTsynonym::TTsynonym(int mode, const char *str, FileHandle file) : TTstringNode() { _string = str; initialize(mode); - _field14 = val2; + _file = file; } TTsynonym *TTsynonym::findByName(TTsynonym *start, const TTString &str, int mode) { diff --git a/engines/titanic/true_talk/tt_synonym.h b/engines/titanic/true_talk/tt_synonym.h index 6a20ef37a4..20f63ac0f6 100644 --- a/engines/titanic/true_talk/tt_synonym.h +++ b/engines/titanic/true_talk/tt_synonym.h @@ -31,8 +31,11 @@ class TTsynonym : public TTstringNode { public: TTsynonym(); TTsynonym(const TTstringNode *src); - TTsynonym(int mode, const char *str, int val2); + TTsynonym(int mode, const char *str, FileHandle file); + /** + * Copy the synonym + */ TTsynonym *copy(TTstringNode *src); /** diff --git a/engines/titanic/true_talk/tt_vocab.cpp b/engines/titanic/true_talk/tt_vocab.cpp index 1bfd3dfde3..1499573f2e 100644 --- a/engines/titanic/true_talk/tt_vocab.cpp +++ b/engines/titanic/true_talk/tt_vocab.cpp @@ -168,4 +168,33 @@ TTword *TTvocab::findWord(const TTString &str) { return word; } +TTword *TTvocab::getPrimeWord(TTString &str, TTword **words) { + TTsynonym *synonym = new TTsynonym(); + char c = str.charAt(0); + TTword *vocabList = _pHead; + TTword *returnWord = nullptr; + + if (!Common::isDigit(c)) { + returnWord = new TTword(str, 3, 300); + } else if (!vocabList) { + // No vocab present. Should never happen + } else { + TTword *foundWord = nullptr; + while (!foundWord && vocabList) { + if (_field18 == 3 && !strcmp(str.c_str(), vocabList->c_str())) { + + } + } + + // TODO + + } + + if (words) + *words = vocabList; + delete synonym; + + return returnWord; +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_vocab.h b/engines/titanic/true_talk/tt_vocab.h index d4dbda0029..b7e948680a 100644 --- a/engines/titanic/true_talk/tt_vocab.h +++ b/engines/titanic/true_talk/tt_vocab.h @@ -56,6 +56,8 @@ private: public: TTvocab(int val); ~TTvocab(); + + TTword *getPrimeWord(TTString &str, TTword **words); }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp index b7309b2c63..80fc611a38 100644 --- a/engines/titanic/true_talk/tt_word.cpp +++ b/engines/titanic/true_talk/tt_word.cpp @@ -32,6 +32,10 @@ TTword::TTword(TTString &str, int mode, int val2) : _string(str), _status = str.getStatus() == SS_VALID ? SS_VALID : SS_5; } +TTword::TTword(TTword *src) { + // TODO +} + void TTword::deleteSiblings() { while (_pNext) { TTword *next = _pNext; @@ -50,7 +54,7 @@ int TTword::readSyn(SimpleFile *file) { return 5; // Create new synanym node - TTsynonym *synNode = new TTsynonym(mode, str.c_str(), val1); + TTsynonym *synNode = new TTsynonym(mode, str.c_str(), (FileHandle)val1); if (_synP) { // A synonym already exists, so add new one as a tail @@ -99,7 +103,7 @@ uint TTword::readNumber(const char *str) { return numValue; } -bool TTword::testFileHandle(SimpleFile *file) const { +bool TTword::testFileHandle(FileHandle file) const { if (g_vm->_exeResources.is18Equals(3)) return true; @@ -120,6 +124,24 @@ TTword *TTword::scanCopy(const TTString &str, TTsynonym *node, int mode) { return nullptr; } +TTword *TTword::copy() { + return new TTword(this); +} + +FileHandle TTword::getSynFile() const { + return _synP ? _synP->_file : HANDLE_STDIN; +} + +bool TTword::checkSynFile(FileHandle file) const { + return _synP && _synP->_file == file; +} + +void TTword::setSynFile(FileHandle file) { + if (_synP && testFileHandle(file)) + _synP->_file = file; +} + + /*------------------------------------------------------------------------*/ TTword1::TTword1(TTString &str, int val1, int val2, int val3) : diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h index ad2ddeb987..d1de4118f9 100644 --- a/engines/titanic/true_talk/tt_word.h +++ b/engines/titanic/true_talk/tt_word.h @@ -43,13 +43,15 @@ protected: */ uint readNumber(const char *str); - bool testFileHandle(SimpleFile *file) const; + bool testFileHandle(SimpleFile *file) const { return true; } + bool testFileHandle(FileHandle resHandle) const; public: TTword *_pNext; TTsynonym *_synP; TTString _string; public: TTword(TTString &str, int mode, int val2); + TTword(TTword *src); /** * Delete any following words chained to the word @@ -75,6 +77,45 @@ public: const char *c_str() const { return _string.c_str(); } operator const char *() const { return c_str(); } + + virtual TTword *copy(); + virtual int proc2() const { return 0; } + virtual int proc3() const { return -1; } + virtual void proc4() {} + virtual void proc5() {} + virtual int proc6() const { return 0; } + virtual int proc7() const { return 0; } + virtual int proc8() const { return 0; } + virtual int proc9() const { return 0; } + virtual int proc10() const { return 0; } + virtual void proc11() {} + virtual int proc12() const { return 0; } + virtual int proc13() const { return 0; } + virtual int proc14() const { return 0; } + virtual int proc15() const { return -1; } + virtual int proc16() const { return 0; } + virtual int proc17() const { return 0; } + virtual int proc18() const { return 0; } + virtual int proc19() const { return 0; } + virtual int proc20() const { return 0; } + + /** + * Returns the file associated with the word's first synonym + */ + virtual FileHandle getSynFile() const; + + /** + * Checks whether the file associated with the word's first + * synonym matches the specified file + */ + virtual bool checkSynFile(FileHandle file) const; + + /** + * Sets the file associated with a synonym + */ + virtual void setSynFile(FileHandle file); + + virtual int proc24() const { return 0; } }; class TTword1 : public TTword { -- cgit v1.2.3