From 5af8ed228d729dd9ef71f5f6cea7adb254dff7a4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 18 Sep 2017 18:16:03 -0400 Subject: TITANIC: Add VocabMode enum, fix German vocab loading --- engines/titanic/support/exe_resources.cpp | 6 +++--- engines/titanic/support/exe_resources.h | 17 +++++++++++++---- engines/titanic/true_talk/script_handler.cpp | 6 +++--- engines/titanic/true_talk/script_handler.h | 2 +- engines/titanic/true_talk/title_engine.cpp | 9 +++++---- engines/titanic/true_talk/title_engine.h | 4 ++-- engines/titanic/true_talk/true_talk_manager.cpp | 2 +- engines/titanic/true_talk/tt_sentence.cpp | 6 +++--- engines/titanic/true_talk/tt_string_node.cpp | 4 ++-- engines/titanic/true_talk/tt_string_node.h | 2 +- engines/titanic/true_talk/tt_vocab.cpp | 12 +++++++----- engines/titanic/true_talk/tt_vocab.h | 5 +++-- engines/titanic/true_talk/tt_word.cpp | 4 ++-- engines/titanic/true_talk/tt_word.h | 4 +++- 14 files changed, 49 insertions(+), 34 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/support/exe_resources.cpp b/engines/titanic/support/exe_resources.cpp index 2b2c9c7635..b216ea5c26 100644 --- a/engines/titanic/support/exe_resources.cpp +++ b/engines/titanic/support/exe_resources.cpp @@ -27,12 +27,12 @@ namespace Titanic { CExeResources::CExeResources() : _owner(nullptr), _field4(0), _field8(0), - _fieldC(0), _field10(0), _field14(0), _field18(0) { + _fieldC(0), _field10(0), _field14(0), _vocabMode(VOCAB_MODE_NONE) { } -void CExeResources::reset(CScriptHandler *owner, int val1, int val2) { +void CExeResources::reset(CScriptHandler *owner, int val1, VocabMode vocabMode) { _owner = owner; - _field18 = val2; + _vocabMode = vocabMode; } } // End of namespace Titanic diff --git a/engines/titanic/support/exe_resources.h b/engines/titanic/support/exe_resources.h index 993c34db97..382df39984 100644 --- a/engines/titanic/support/exe_resources.h +++ b/engines/titanic/support/exe_resources.h @@ -29,6 +29,8 @@ class CScriptHandler; enum FileHandle { HANDLE_STDIN = 0, HANDLE_STDOUT = 1, HANDLE_STDERR = 2 }; +enum VocabMode { VOCAB_MODE_NONE = 0, VOCAB_MODE_EN = 3, VOCAB_MODE_DE = 5 }; + class CExeResources { public: CScriptHandler *_owner; @@ -37,14 +39,21 @@ public: int _fieldC; int _field10; int _field14; - int _field18; + VocabMode _vocabMode; public: CExeResources(); - void reset(CScriptHandler *owner, int val1, int val2); + void reset(CScriptHandler *owner, int val1, VocabMode vocabMode); + + /** + * Tests whether the vocab mode equals the passed mode + */ + bool isVocabMode(int mode) const { return _vocabMode == mode; } - bool is18Equals(int val) const { return _field18 == val; } - int get18() const { return _field18; } + /** + * Returns the vocab mode + */ + VocabMode getVocabMode() const { return _vocabMode; } }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/script_handler.cpp b/engines/titanic/true_talk/script_handler.cpp index f716a96130..0572cd4190 100644 --- a/engines/titanic/true_talk/script_handler.cpp +++ b/engines/titanic/true_talk/script_handler.cpp @@ -32,13 +32,13 @@ namespace Titanic { /*------------------------------------------------------------------------*/ -CScriptHandler::CScriptHandler(CTitleEngine *owner, int val1, int val2) : +CScriptHandler::CScriptHandler(CTitleEngine *owner, int val1, VocabMode vocabMode) : _owner(owner), _script(owner->_script), _parser(this), _inputCtr(0), _concept1P(nullptr), _concept2P(nullptr), _concept3P(nullptr), _concept4P(nullptr) { g_vm->_scriptHandler = this; g_vm->_script = _script; - g_vm->_exeResources.reset(this, val1, val2); - _vocab = new TTvocab(val2); + g_vm->_exeResources.reset(this, val1, vocabMode); + _vocab = new TTvocab(vocabMode); } CScriptHandler::~CScriptHandler() { diff --git a/engines/titanic/true_talk/script_handler.h b/engines/titanic/true_talk/script_handler.h index b8e62a586c..149532bd1b 100644 --- a/engines/titanic/true_talk/script_handler.h +++ b/engines/titanic/true_talk/script_handler.h @@ -50,7 +50,7 @@ public: TTconcept *_concept3P; TTconcept *_concept4P; public: - CScriptHandler(CTitleEngine *owner, int val1, int val2); + CScriptHandler(CTitleEngine *owner, int val1, VocabMode vocabMode); ~CScriptHandler(); /** diff --git a/engines/titanic/true_talk/title_engine.cpp b/engines/titanic/true_talk/title_engine.cpp index 23327014d6..f11bf1df29 100644 --- a/engines/titanic/true_talk/title_engine.cpp +++ b/engines/titanic/true_talk/title_engine.cpp @@ -23,6 +23,7 @@ #include "titanic/true_talk/title_engine.h" #include "titanic/support/files_manager.h" #include "titanic/titanic.h" +#include "titanic/translation.h" namespace Titanic { @@ -34,9 +35,9 @@ CTitleEngine::~CTitleEngine() { delete _scriptHandler; } -void CTitleEngine::setup(int val1, int val2) { +void CTitleEngine::setup(int val1, VocabMode vocabMode) { _script = new TTTitleScript(); - _scriptHandler = new CScriptHandler(this, val1, val2); + _scriptHandler = new CScriptHandler(this, val1, vocabMode); } /*------------------------------------------------------------------------*/ @@ -53,8 +54,8 @@ void STtitleEngine::reset() { _indexes.clear(); } -void STtitleEngine::setup(int val1, int val2) { - CTitleEngine::setup(val1, 3); +void STtitleEngine::setup(int val1, VocabMode vocabMode) { + CTitleEngine::setup(val1, TRANSLATE(VOCAB_MODE_EN, VOCAB_MODE_DE)); } int STtitleEngine::setResponse(TTscriptBase *script, TTresponse *response) { diff --git a/engines/titanic/true_talk/title_engine.h b/engines/titanic/true_talk/title_engine.h index ca7a5dcd14..d9b21af423 100644 --- a/engines/titanic/true_talk/title_engine.h +++ b/engines/titanic/true_talk/title_engine.h @@ -51,7 +51,7 @@ public: /** * Setup the engine */ - virtual void setup(int val1, int val2 = 0); + virtual void setup(int val1, VocabMode vocabMode = VOCAB_MODE_NONE); /** * Sets a conversation reponse @@ -80,7 +80,7 @@ public: /** * Setup the engine */ - virtual void setup(int val1, int val2 = 0); + virtual void setup(int val1, VocabMode vocabMode = VOCAB_MODE_NONE); /** * Sets a conversation reponse diff --git a/engines/titanic/true_talk/true_talk_manager.cpp b/engines/titanic/true_talk/true_talk_manager.cpp index d0cead3206..a7766e8d18 100644 --- a/engines/titanic/true_talk/true_talk_manager.cpp +++ b/engines/titanic/true_talk/true_talk_manager.cpp @@ -48,7 +48,7 @@ CTrueTalkNPC *CTrueTalkManager::_currentNPC; CTrueTalkManager::CTrueTalkManager(CGameManager *owner) : _gameManager(owner), _scripts(), _currentCharId(0), _dialogueFile(nullptr), _dialogueId(0) { - _titleEngine.setup(3, 3); + _titleEngine.setup(3, VOCAB_MODE_EN); _quotes.load(); _quotesTree.load(); diff --git a/engines/titanic/true_talk/tt_sentence.cpp b/engines/titanic/true_talk/tt_sentence.cpp index 5a5bff7af8..b20f760f48 100644 --- a/engines/titanic/true_talk/tt_sentence.cpp +++ b/engines/titanic/true_talk/tt_sentence.cpp @@ -317,7 +317,7 @@ bool TTsentence::localWord(const char *str) const { foundMatch = true; } - int val = g_vm->_exeResources.get18(); + VocabMode mode = g_vm->_exeResources.getVocabMode(); bool result = false; for (TTsentenceNode *nodeP = _nodesP; nodeP && !result; @@ -327,9 +327,9 @@ bool TTsentence::localWord(const char *str) const { continue; const TTstring wordStr = nodeP->_wordP->_text; - if (val == 3 && wordStr == str) { + if (mode == VOCAB_MODE_EN && wordStr == str) { result = true; - } else if (nodeP->_wordP->findSynByName(str, &syn, val)) { + } else if (nodeP->_wordP->findSynByName(str, &syn, mode)) { result = true; } else if (foundMatch) { result = wordStr == "it" || wordStr == "that" || wordStr == "he" diff --git a/engines/titanic/true_talk/tt_string_node.cpp b/engines/titanic/true_talk/tt_string_node.cpp index 60c506e8cd..16860cc93f 100644 --- a/engines/titanic/true_talk/tt_string_node.cpp +++ b/engines/titanic/true_talk/tt_string_node.cpp @@ -55,9 +55,9 @@ void TTstringNode::initialize(TTstringNode *oldNode) { delete oldNode; } -TTstringNode *TTstringNode::findByName(const TTstring &str, int mode) { +TTstringNode *TTstringNode::findByName(const TTstring &str, VocabMode mode) { for (TTstringNode *nodeP = this; nodeP; nodeP = dynamic_cast(nodeP->_nextP)) { - if (nodeP->_mode == mode || (mode == 3 && nodeP->_mode < 3)) { + if (nodeP->_mode == mode || (mode == VOCAB_MODE_EN && nodeP->_mode < 3)) { if (nodeP->_string == str) return nodeP; } diff --git a/engines/titanic/true_talk/tt_string_node.h b/engines/titanic/true_talk/tt_string_node.h index ced162b439..ee17cf1d38 100644 --- a/engines/titanic/true_talk/tt_string_node.h +++ b/engines/titanic/true_talk/tt_string_node.h @@ -51,7 +51,7 @@ public: /** * Find a string node in the linked chain by name */ - TTstringNode *findByName(const TTstring &str, int mode); + TTstringNode *findByName(const TTstring &str, VocabMode mode); }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_vocab.cpp b/engines/titanic/true_talk/tt_vocab.cpp index 20df6bd4bb..861d8f89a0 100644 --- a/engines/titanic/true_talk/tt_vocab.cpp +++ b/engines/titanic/true_talk/tt_vocab.cpp @@ -28,12 +28,13 @@ #include "titanic/true_talk/tt_picture.h" #include "titanic/true_talk/tt_pronoun.h" #include "titanic/titanic.h" +#include "titanic/translation.h" #include "common/file.h" namespace Titanic { -TTvocab::TTvocab(int val): _headP(nullptr), _tailP(nullptr), - _word(nullptr), _vocabMode(val) { +TTvocab::TTvocab(VocabMode vocabMode): _headP(nullptr), _tailP(nullptr), + _word(nullptr), _vocabMode(vocabMode) { load("STVOCAB"); } @@ -131,7 +132,8 @@ int TTvocab::load(const CString &name) { } void TTvocab::addWord(TTword *word) { - TTword *existingWord = findWord(word->_text); + TTword *existingWord = g_language == Common::DE_DEU ? nullptr : + findWord(word->_text); if (existingWord) { if (word->_synP) { @@ -160,7 +162,7 @@ TTword *TTvocab::findWord(const TTstring &str) { TTword *word = _headP; while (word && !flag) { - if (_vocabMode != 3 || strcmp(word->c_str(), str)) { + if (_vocabMode != VOCAB_MODE_EN || strcmp(word->c_str(), str)) { if (word->findSynByName(str, tempNode, _vocabMode)) flag = true; else @@ -203,7 +205,7 @@ TTword *TTvocab::getPrimeWord(TTstring &str, TTword **srcWord) const { } else { // Standard word for (vocabP = _headP; vocabP; vocabP = vocabP->_nextP) { - if (_vocabMode == 3 && !strcmp(str.c_str(), vocabP->c_str())) { + if (_vocabMode == VOCAB_MODE_EN && !strcmp(str.c_str(), vocabP->c_str())) { newWord = vocabP->copy(); newWord->_nextP = nullptr; newWord->setSyn(nullptr); diff --git a/engines/titanic/true_talk/tt_vocab.h b/engines/titanic/true_talk/tt_vocab.h index 614d1bbf02..7e5cc29bc5 100644 --- a/engines/titanic/true_talk/tt_vocab.h +++ b/engines/titanic/true_talk/tt_vocab.h @@ -23,6 +23,7 @@ #ifndef TITANIC_ST_VOCAB_H #define TITANIC_ST_VOCAB_H +#include "titanic/support/exe_resources.h" #include "titanic/support/string.h" #include "titanic/true_talk/tt_string.h" #include "titanic/true_talk/tt_word.h" @@ -34,7 +35,7 @@ private: TTword *_headP; TTword *_tailP; TTword *_word; - int _vocabMode; + VocabMode _vocabMode; private: /** * Load the vocab data @@ -77,7 +78,7 @@ private: */ TTword *getPrefixedWord(TTstring &str) const; public: - TTvocab(int val); + TTvocab(VocabMode vocabMode); ~TTvocab(); /** diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp index 5ed3e5755f..c05b61e48c 100644 --- a/engines/titanic/true_talk/tt_word.cpp +++ b/engines/titanic/true_talk/tt_word.cpp @@ -163,14 +163,14 @@ uint TTword::readNumber(const char *str) { } bool TTword::testFileHandle(FileHandle file) const { - if (g_vm->_exeResources.is18Equals(3)) + if (g_vm->_exeResources.isVocabMode(VOCAB_MODE_EN)) return true; // TODO: Figure out why original compares passed file handle against specific values return true; } -bool TTword::findSynByName(const TTstring &str, TTsynonym *dest, int mode) const { +bool TTword::findSynByName(const TTstring &str, TTsynonym *dest, VocabMode mode) const { if (!_synP) return false; diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h index 7a42614f43..207c1c155b 100644 --- a/engines/titanic/true_talk/tt_word.h +++ b/engines/titanic/true_talk/tt_word.h @@ -23,6 +23,7 @@ #ifndef TITANIC_TT_WORD_H #define TITANIC_TT_WORD_H +#include "titanic/support/exe_resources.h" #include "titanic/support/simple_file.h" #include "titanic/true_talk/tt_string.h" #include "titanic/true_talk/tt_synonym.h" @@ -102,9 +103,10 @@ public: * Finds a synonym in the word by name, if one exists * @param str Name to search for * @param dest Destination synonym instance to copy match into + * @param mode Specifies English or German vocab mode * @returns Returns true if a match was found */ - bool findSynByName(const TTstring &str, TTsynonym *dest, int mode) const; + bool findSynByName(const TTstring &str, TTsynonym *dest, VocabMode mode) const; const char *c_str() const { return _text.c_str(); } operator const char *() const { return c_str(); } -- cgit v1.2.3