diff options
-rw-r--r-- | engines/parallaction/dialogue.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/objects.cpp | 26 | ||||
-rw-r--r-- | engines/parallaction/objects.h | 16 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 3 | ||||
-rw-r--r-- | engines/parallaction/parser_ns.cpp | 53 |
5 files changed, 41 insertions, 59 deletions
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index e3c505f7d4..26aecbda00 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -388,7 +388,7 @@ void DialogueManager::runAnswer() { void DialogueManager::nextQuestion() { debugC(9, kDebugDialogue, "nextQuestion\n"); - _q = _q->_answers[_answerId]->_followingQuestion; + _q = _dialogue->findQuestion(_q->_answers[_answerId]->_followingName); if (_q == 0) { _state = DIALOGUE_OVER; } else { diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp index c852d58881..8358a20ad2 100644 --- a/engines/parallaction/objects.cpp +++ b/engines/parallaction/objects.cpp @@ -212,6 +212,7 @@ bool Zone::hitRect(int x, int y) const { Dialogue::Dialogue() { memset(_questions, 0, sizeof(_questions)); + _numQuestions = 0; } Dialogue::~Dialogue() { @@ -220,20 +221,31 @@ Dialogue::~Dialogue() { } } +Question *Dialogue::findQuestion(const Common::String &name) const { + for (uint i = 0; _questions[i]; ++i) { + if (_questions[i]->_name == name) { + return _questions[i]; + } + } + return 0; +} + +void Dialogue::addQuestion(Question *q) { + assert(_numQuestions < NUM_QUESTIONS); + assert(q); + _questions[_numQuestions] = q; + _numQuestions++; +} + Answer::Answer() { _mood = 0; - _followingQuestion = NULL; _noFlags = 0; _yesFlags = 0; _hasCounterCondition = false; } -Question::Question() { - _mood = 0; - - for (uint32 i = 0; i < NUM_ANSWERS; i++) - _answers[i] = NULL; - +Question::Question(const Common::String &name) : _name(name), _mood(0) { + memset(_answers, 0, sizeof(_answers)); } Question::~Question() { diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h index bf8daa173e..4eabf08720 100644 --- a/engines/parallaction/objects.h +++ b/engines/parallaction/objects.h @@ -160,9 +160,8 @@ typedef Common::List<CommandPtr> CommandList; struct Answer { Common::String _text; - uint16 _mood; - Question* _followingQuestion; - Common::String _followingName; + uint16 _mood; + Common::String _followingName; CommandList _commands; uint32 _noFlags; @@ -178,16 +177,21 @@ struct Answer { }; struct Question { + Common::String _name; Common::String _text; - uint16 _mood; - Answer* _answers[NUM_ANSWERS]; + uint16 _mood; + Answer* _answers[NUM_ANSWERS]; - Question(); + Question(const Common::String &name); ~Question(); }; struct Dialogue { Question *_questions[NUM_QUESTIONS]; + uint _numQuestions; + + Question *findQuestion(const Common::String &name) const; + void addQuestion(Question *q); Dialogue(); ~Dialogue(); diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index ed28dfc1d1..68f6b02caa 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -190,11 +190,10 @@ protected: Common::String parseComment(); Common::String parseDialogueString(); Dialogue *parseDialogue(); - void resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards); virtual Answer *parseAnswer(); void parseAnswerFlags(Answer *answer); void parseAnswerBody(Answer *answer); - Question *parseQuestion(); + void parseQuestion(Question *q); uint32 buildZoneType(const char *t0, const char* t1); diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index ce7770b2d3..c75caca9ee 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -810,51 +810,39 @@ void LocationParser_ns::parseCommands(CommandList& list) { Dialogue *LocationParser_ns::parseDialogue() { debugC(7, kDebugParser, "parseDialogue()"); - uint16 numQuestions = 0; - Dialogue *dialogue = new Dialogue; assert(dialogue); - Table forwards(NUM_QUESTIONS); - _script->readLineToken(true); while (scumm_stricmp(_tokens[0], "enddialogue")) { - if (scumm_stricmp(_tokens[0], "Question")) continue; - - forwards.addData(_tokens[1]); - - dialogue->_questions[numQuestions++] = parseQuestion(); - + if (!scumm_stricmp(_tokens[0], "question")) { + Question *q = new Question(_tokens[1]); + assert(q); + parseQuestion(q); + dialogue->addQuestion(q); + } _script->readLineToken(true); } - resolveDialogueForwards(dialogue, numQuestions, forwards); - debugC(7, kDebugParser, "parseDialogue() done"); return dialogue; } -Question *LocationParser_ns::parseQuestion() { - - Question *question = new Question; - assert(question); - - question->_text = parseDialogueString(); +void LocationParser_ns::parseQuestion(Question *q) { + q->_text = parseDialogueString(); _script->readLineToken(true); - question->_mood = atoi(_tokens[0]); + q->_mood = atoi(_tokens[0]); uint16 numAnswers = 0; _script->readLineToken(true); while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers - question->_answers[numAnswers] = parseAnswer(); + q->_answers[numAnswers] = parseAnswer(); numAnswers++; } - - return question; } void LocationParser_ns::parseAnswerBody(Answer *answer) { @@ -918,27 +906,6 @@ Answer *LocationParser_ns::parseAnswer() { return answer; } -void LocationParser_ns::resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards) { - - for (uint16 i = 0; i < numQuestions; i++) { - Question *question = dialogue->_questions[i]; - - for (uint16 j = 0; j < NUM_ANSWERS; j++) { - Answer *answer = question->_answers[j]; - if (answer == 0) continue; - - int16 index = forwards.lookup(answer->_followingName.c_str()); - answer->_followingName.clear(); - - if (index == Table::notFound) - answer->_followingQuestion = 0; - else - answer->_followingQuestion = dialogue->_questions[index - 1]; - - } - } - -} Common::String LocationParser_ns::parseDialogueString() { char buf[400]; |