aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Mettifogo2007-12-04 20:38:45 +0000
committerNicola Mettifogo2007-12-04 20:38:45 +0000
commitfdb20177b455f3ec65dc712a3ce421df239bacce (patch)
tree3745ba0d1b73c93f01db51ea4c97498da12a1055
parent60397448e98cb3cdaf74084516cf97faf47e6cbf (diff)
downloadscummvm-rg350-fdb20177b455f3ec65dc712a3ce421df239bacce.tar.gz
scummvm-rg350-fdb20177b455f3ec65dc712a3ce421df239bacce.tar.bz2
scummvm-rg350-fdb20177b455f3ec65dc712a3ce421df239bacce.zip
Broke up parseDialogue into more manageable and focused short routines.
svn-id: r29716
-rw-r--r--engines/parallaction/parallaction.h4
-rw-r--r--engines/parallaction/parser_ns.cpp131
2 files changed, 75 insertions, 60 deletions
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 521aa634b5..1d4631a389 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -835,6 +835,10 @@ protected:
char *parseComment(Script &script);
char *parseDialogueString(Script &script);
Dialogue *parseDialogue(Script &script);
+ void resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards);
+ Answer *parseAnswer(Script &script);
+ Question *parseQuestion(Script &script);
+
void parseZone(Script &script, ZoneList &list, char *name);
void parseZoneTypeBlock(Script &script, Zone *z);
void parseWalkNodes(Script& script, WalkNodeList &list);
diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp
index 9681d67a8b..038a75162b 100644
--- a/engines/parallaction/parser_ns.cpp
+++ b/engines/parallaction/parser_ns.cpp
@@ -680,6 +680,7 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
uint16 numQuestions = 0;
Dialogue *dialogue = new Dialogue;
+ assert(dialogue);
Table forwards(20);
@@ -688,84 +689,99 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
while (scumm_stricmp(_tokens[0], "enddialogue")) {
if (scumm_stricmp(_tokens[0], "Question")) continue;
- Question *question = new Question;
- dialogue->_questions[numQuestions] = question;
+ forwards.addData(_tokens[1]);
- forwards.addData(_tokens[1]);
-
- question->_text = parseDialogueString(script);
+ dialogue->_questions[numQuestions++] = parseQuestion(script);
script.readLineToken(true);
- question->_mood = atoi(_tokens[0]);
+ }
- uint16 numAnswers = 0;
+ resolveDialogueForwards(dialogue, numQuestions, forwards);
- script.readLineToken(true);
- while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers
+ debugC(7, kDebugParser, "parseDialogue() done");
- Answer *answer = new Answer;
- question->_answers[numAnswers] = answer;
+ return dialogue;
+}
- if (_tokens[1][0]) {
+Question *Parallaction_ns::parseQuestion(Script &script) {
- Table* flagNames;
- uint16 token;
+ Question *question = new Question;
+ assert(question);
- if (!scumm_stricmp(_tokens[1], "global")) {
- token = 2;
- flagNames = _globalTable;
- answer->_yesFlags |= kFlagsGlobal;
- } else {
- token = 1;
- flagNames = _localFlagNames;
- }
+ question->_text = parseDialogueString(script);
- do {
+ script.readLineToken(true);
+ question->_mood = atoi(_tokens[0]);
- if (!scumm_strnicmp(_tokens[token], "no", 2)) {
- byte _al = flagNames->lookup(_tokens[token]+2);
- answer->_noFlags |= 1 << (_al - 1);
- } else {
- byte _al = flagNames->lookup(_tokens[token]);
- answer->_yesFlags |= 1 << (_al - 1);
- }
+ uint16 numAnswers = 0;
- token++;
+ script.readLineToken(true);
+ while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers
+ question->_answers[numAnswers] = parseAnswer(script);
+ numAnswers++;
+ }
- } while (!scumm_stricmp(_tokens[token++], "|"));
+ return question;
+}
- }
+Answer *Parallaction_ns::parseAnswer(Script &script) {
- answer->_text = parseDialogueString(script);
+ Answer *answer = new Answer;
+ assert(answer);
- script.readLineToken(true);
- answer->_mood = atoi(_tokens[0]);
- answer->_following._name = parseDialogueString(script);
+ if (_tokens[1][0]) {
- script.readLineToken(true);
- if (!scumm_stricmp(_tokens[0], "commands")) {
+ Table* flagNames;
+ uint16 token;
- parseCommands(script, answer->_commands);
- _locParseCtxt.endcommands = false;
- do {
- script.readLineToken(true);
- parseStatement();
- } while (!_locParseCtxt.endcommands);
+ if (!scumm_stricmp(_tokens[1], "global")) {
+ token = 2;
+ flagNames = _globalTable;
+ answer->_yesFlags |= kFlagsGlobal;
+ } else {
+ token = 1;
+ flagNames = _localFlagNames;
+ }
- script.readLineToken(true);
- }
+ do {
- numAnswers++;
- }
+ if (!scumm_strnicmp(_tokens[token], "no", 2)) {
+ byte _al = flagNames->lookup(_tokens[token]+2);
+ answer->_noFlags |= 1 << (_al - 1);
+ } else {
+ byte _al = flagNames->lookup(_tokens[token]);
+ answer->_yesFlags |= 1 << (_al - 1);
+ }
- script.readLineToken(true);
- numQuestions++;
+ token++;
- }
+ } while (!scumm_stricmp(_tokens[token++], "|"));
+
+ }
- // link questions
- byte v50[20];
- memset(v50, 0, 20);
+ answer->_text = parseDialogueString(script);
+
+ script.readLineToken(true);
+ answer->_mood = atoi(_tokens[0]);
+ answer->_following._name = parseDialogueString(script);
+
+ script.readLineToken(true);
+ if (!scumm_stricmp(_tokens[0], "commands")) {
+
+ parseCommands(script, answer->_commands);
+ _locParseCtxt.endcommands = false;
+ do {
+ script.readLineToken(true);
+ parseStatement();
+ } while (!_locParseCtxt.endcommands);
+
+ script.readLineToken(true);
+ }
+
+ return answer;
+}
+
+void Parallaction_ns::resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards) {
for (uint16 i = 0; i < numQuestions; i++) {
Question *question = dialogue->_questions[i];
@@ -783,16 +799,11 @@ Dialogue *Parallaction_ns::parseDialogue(Script &script) {
else
answer->_following._question = dialogue->_questions[index - 1];
-
}
}
- debugC(7, kDebugParser, "parseDialogue() done");
-
- return dialogue;
}
-
char *Parallaction_ns::parseDialogueString(Script &script) {
char vC8[200];