diff options
author | Paul Gilbert | 2016-05-29 20:56:31 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-15 19:17:05 -0400 |
commit | 4ee0ced047ddef1994879e23cb6a2bb160933c1c (patch) | |
tree | 189d9bf7e8151e1c5e9e47792824cdf9faf3ca9e /engines/titanic | |
parent | 2f4cf6a26aab58f932c06806a952cbd047c02ed0 (diff) | |
download | scummvm-rg350-4ee0ced047ddef1994879e23cb6a2bb160933c1c.tar.gz scummvm-rg350-4ee0ced047ddef1994879e23cb6a2bb160933c1c.tar.bz2 scummvm-rg350-4ee0ced047ddef1994879e23cb6a2bb160933c1c.zip |
TITANIC: Fleshing out TTscriptBase class
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/true_talk/title_engine.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/true_talk/title_engine.h | 12 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_response.cpp | 8 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_response.h | 21 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_script_base.cpp | 70 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_script_base.h | 48 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_string.h | 5 |
7 files changed, 132 insertions, 43 deletions
diff --git a/engines/titanic/true_talk/title_engine.cpp b/engines/titanic/true_talk/title_engine.cpp index d5f465139e..4dd45ba335 100644 --- a/engines/titanic/true_talk/title_engine.cpp +++ b/engines/titanic/true_talk/title_engine.cpp @@ -40,7 +40,8 @@ void CTitleEngine::setup(int val1, int val2) { /*------------------------------------------------------------------------*/ -STtitleEngine::STtitleEngine(): CTitleEngine(), _field58(0) { +STtitleEngine::STtitleEngine(): CTitleEngine(), + _responseP(nullptr), _field58(0) { } STtitleEngine::~STtitleEngine() { @@ -56,8 +57,12 @@ void STtitleEngine::setup(int val1, int val2) { CTitleEngine::setup(val1, 3); } -int STtitleEngine::proc2(int val1, int val2) { - // TODO +int STtitleEngine::setResponse(TTscriptBase *script, TTresponse *response) { + _indexes.clear(); + for (TTresponse *respP = response; respP; respP = respP->getNext()) { + _indexes.push_back(respP->getDialogueId()); + } + return 0; } diff --git a/engines/titanic/true_talk/title_engine.h b/engines/titanic/true_talk/title_engine.h index 10c32a7634..afd2d3b92f 100644 --- a/engines/titanic/true_talk/title_engine.h +++ b/engines/titanic/true_talk/title_engine.h @@ -27,6 +27,7 @@ #include "common/winexe_pe.h" #include "titanic/support/string.h" #include "titanic/true_talk/script_handler.h" +#include "titanic/true_talk/tt_response.h" #include "titanic/true_talk/tt_script_base.h" #include "titanic/true_talk/tt_title_script.h" @@ -52,7 +53,10 @@ public: */ virtual void setup(int val1, int val2 = 0); - virtual int proc2(int val1, int val2) { return 2; } + /** + * Sets a conversation reponse + */ + virtual int setResponse(TTscriptBase *script, TTresponse *response) { return SS_4; } virtual int proc4(int unused) const = 0; virtual int proc5(int64 unused) const = 0; @@ -69,6 +73,7 @@ public: class STtitleEngine : public CTitleEngine { private: Common::SeekableReadStream *_stream; + TTresponse *_responseP; int _field58; public: Common::Array<uint> _indexes; @@ -84,7 +89,10 @@ public: */ virtual void setup(int val1, int val2 = 0); - virtual int proc2(int val1, int val2); + /** + * Sets a conversation reponse + */ + virtual int setResponse(TTscriptBase *script, TTresponse *response); virtual void dump(int val1, int val2); diff --git a/engines/titanic/true_talk/tt_response.cpp b/engines/titanic/true_talk/tt_response.cpp index 8d580ec198..f007f98f97 100644 --- a/engines/titanic/true_talk/tt_response.cpp +++ b/engines/titanic/true_talk/tt_response.cpp @@ -25,15 +25,15 @@ namespace Titanic { TTresponse::TTresponse(const TTstring &src) : _field0(0), _text(src), - _fieldC(0), _nextP(nullptr), _linkP(nullptr) { + _dialogueId(0), _nextP(nullptr), _linkP(nullptr) { } -TTresponse::TTresponse(int val1, int val2) : _field0(val2), _text(" "), - _fieldC(val1), _nextP(nullptr), _linkP(nullptr) { +TTresponse::TTresponse(int dialogueId, int val2) : _field0(val2), _text(" "), + _dialogueId(dialogueId), _nextP(nullptr), _linkP(nullptr) { } TTresponse::TTresponse(const TTresponse *src) : _field0(src->_field0), - _text(src->_text), _fieldC(src->_fieldC), _nextP(src->_nextP), + _text(src->_text), _dialogueId(src->_dialogueId), _nextP(src->_nextP), _linkP(src->_linkP) { } diff --git a/engines/titanic/true_talk/tt_response.h b/engines/titanic/true_talk/tt_response.h index c4119763ea..38f7ec70a8 100644 --- a/engines/titanic/true_talk/tt_response.h +++ b/engines/titanic/true_talk/tt_response.h @@ -32,21 +32,30 @@ class TTresponse { private: int _field0; TTstring _text; - int _fieldC; + int _dialogueId; TTresponse *_nextP; TTresponse *_linkP; TTresponse *copyChain() const; -private: - /** - * - */ - void addLink(TTresponse *item); public: TTresponse(const TTstring &src); TTresponse(int val1, int val2); TTresponse(const TTresponse *src); virtual ~TTresponse(); + + TTresponse *getLink() const { return _linkP; } + + void addLink(TTresponse *item); + + /** + * Get the dialogue Id for the response + */ + int getDialogueId() const { return _dialogueId; } + + /** + * Return the next response item, if present + */ + TTresponse *getNext() const { return _nextP; } }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_script_base.cpp b/engines/titanic/true_talk/tt_script_base.cpp index 85c329c330..25c0b781bd 100644 --- a/engines/titanic/true_talk/tt_script_base.cpp +++ b/engines/titanic/true_talk/tt_script_base.cpp @@ -27,12 +27,12 @@ namespace Titanic { TTscriptBase::TTscriptBase(int scriptId, const char *charClass, int v2, const char *charName, int v3, int v4, int v5, int v6, int v7) : - _charName(charName), _charClass(charClass), - _nodesP(nullptr), _id(0), _hist(nullptr), + _charName(charName), _charClass(charClass), _status(0), + _nodesP(nullptr), _id(0), _hist1P(nullptr), _field20(0), _field24(0), _field28(0), _field2C(0), - _field30(0), _field34(0), _field38(0), _field3C(0), - _field40(0), _field44(0), _field48(0), _status(0) { - if (!areNamesValid()) { + _field30(0), _field34(0), _hist2P(nullptr), _field3C(0), + _respHeadP(nullptr), _respTailP(nullptr), _responseP(nullptr) { + if (!isValid()) { if (!v7 || !getStatus()) { _id = scriptId; _field20 = v3; @@ -51,13 +51,19 @@ TTscriptBase::TTscriptBase(int scriptId, const char *charClass, int v2, } TTscriptBase::~TTscriptBase() { + deleteResponses(); + delete _responseP; + + delete _hist1P; + delete _hist2P; + if (_nodesP) { _nodesP->deleteSiblings(); delete _nodesP; } } -bool TTscriptBase::areNamesValid() { +bool TTscriptBase::isValid() { bool result = !_charName.isValid() && !_charClass.isValid(); _status = result ? 0 : 11; return result; @@ -66,25 +72,25 @@ bool TTscriptBase::areNamesValid() { void TTscriptBase::reset() { _nodesP = nullptr; _id = 4; - _hist = nullptr; + _hist1P = nullptr; _field20 = 0; _field24 = -1; _field28 = -1; _field2C = -1; _field30 = 0; _field34 = 0; - _field38 = 0; + _hist2P = nullptr; _field3C = 0; - _field40 = 0; - _field44 = 0; - _field48 = 0; + _respHeadP = nullptr; + _respTailP = nullptr; + _responseP = nullptr; } int TTscriptBase::preprocess(TTsentence *sentence) { - delete _hist; - _hist = new TTscriptHist(sentence); + delete _hist1P; + _hist1P = new TTscriptHist(sentence); - return _hist ? SS_VALID : SS_7; + return _hist1P ? SS_VALID : SS_7; } void TTscriptBase::proc2(int v) { @@ -103,4 +109,40 @@ void TTscriptBase::proc5() { warning("TODO"); } +void TTscriptBase::deleteResponses() { + while (_respTailP) { + _respHeadP = _respTailP; + _respTailP = _respHeadP->getLink(); + delete _respHeadP; + } +} + +void TTscriptBase::appendResponse(int val1, int *val2, int val3) { + if (!val2 || val1 <= *val2) { + if (_respHeadP) { + _respHeadP = new TTresponse(_respHeadP); + } else { + _respHeadP = new TTresponse(val3, 3); + if (_respTailP) + _respTailP->addLink(_respHeadP); + else + _respTailP = _respHeadP; + } + } +} + +void TTscriptBase::appendResponse(int val1, int *val2, const TTstring &str) { + if (!val2 || val1 <= *val2) { + if (_respHeadP) { + _respHeadP = new TTresponse(str); + } else { + _respHeadP = new TTresponse(str); + if (_respTailP) + _respTailP->addLink(_respHeadP); + else + _respTailP = _respHeadP; + } + } +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_script_base.h b/engines/titanic/true_talk/tt_script_base.h index 2ffbf60760..1baff891bb 100644 --- a/engines/titanic/true_talk/tt_script_base.h +++ b/engines/titanic/true_talk/tt_script_base.h @@ -26,6 +26,7 @@ #include "titanic/true_talk/tt_string.h" #include "titanic/true_talk/tt_hist.h" #include "titanic/true_talk/tt_node.h" +#include "titanic/true_talk/tt_response.h" namespace Titanic { @@ -40,7 +41,7 @@ private: void reset(); protected: TTnode *_nodesP; - TThist *_hist; + TThist *_hist1P; TTstring _charName, _charClass; int _field20; int _field24; @@ -48,12 +49,28 @@ protected: int _field2C; int _field30; int _field34; - int _field38; + TThist *_hist2P; int _field3C; - int _field40; - int _field44; - int _field48; + TTresponse *_respHeadP; + TTresponse *_respTailP; + TTresponse *_responseP; int _status; +protected: + /** + * Delete any responses set up for the script + */ + void deleteResponses(); + + /** + * Creates and appends a new response to the script + */ + void appendResponse(int val1, int *val2, int val3); + + void appendResponse(int val1, int *val2, const TTstring &str); + + void appendResponse2(int val1, int *val2, const TTstring &str) { + appendResponse(val1, val2, str); + } public: int _id; public: @@ -61,7 +78,19 @@ public: int v3, int v4, int v5, int v6, int v7); virtual ~TTscriptBase(); - bool areNamesValid(); + virtual void proc2(int v); + + virtual void proc3(int v); + + virtual void proc4(int v); + + virtual void proc5(); + + + /** + * Returns true if the script is in a valid state + */ + bool isValid(); /** * Return the Id of the script @@ -83,13 +112,6 @@ public: */ int preprocess(TTsentence *sentence); - virtual void proc2(int v); - - virtual void proc3(int v); - - virtual void proc4(int v); - - virtual void proc5(); }; diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h index 3e8718df2a..12daa07a9d 100644 --- a/engines/titanic/true_talk/tt_string.h +++ b/engines/titanic/true_talk/tt_string.h @@ -38,7 +38,10 @@ struct TTstringData { TTstringData(const CString &str) : _string(str), _referenceCount(1) {} }; -enum TTstringStatus { SS_VALID = 0, SS_1 = 1, SS_4 = 4, SS_5 = 5, SS_7 = 7, SS_8 = 8, SS_11 = 11, SS_13 = 13 }; +enum TTstringStatus { + SS_VALID = 0, SS_1 = 1, SS_2 = 2, SS_3 = 3, SS_4 = 4, + SS_5 = 5, SS_7 = 7, SS_8 = 8, SS_11 = 11, SS_13 = 13 +}; class TTstring { private: |