[Scummvm-cvs-logs] SF.net SVN: scummvm: [29716] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Tue Dec 4 21:38:45 CET 2007


Revision: 29716
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29716&view=rev
Author:   peres001
Date:     2007-12-04 12:38:45 -0800 (Tue, 04 Dec 2007)

Log Message:
-----------
Broke up parseDialogue into more manageable and focused short routines.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parser_ns.cpp

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-12-04 13:07:22 UTC (rev 29715)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-12-04 20:38:45 UTC (rev 29716)
@@ -835,6 +835,10 @@
 	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);

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2007-12-04 13:07:22 UTC (rev 29715)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2007-12-04 20:38:45 UTC (rev 29716)
@@ -680,6 +680,7 @@
 	uint16 numQuestions = 0;
 
 	Dialogue *dialogue = new Dialogue;
+	assert(dialogue);
 
 	Table forwards(20);
 
@@ -688,85 +689,100 @@
 	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]);
+        dialogue->_questions[numQuestions++] = parseQuestion(script);
 
-		question->_text = parseDialogueString(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 @@
 			else
 				answer->_following._question = dialogue->_questions[index - 1];
 
-
 		}
 	}
 
-	debugC(7, kDebugParser, "parseDialogue() done");
-
-	return dialogue;
 }
 
-
 char *Parallaction_ns::parseDialogueString(Script &script) {
 
 	char vC8[200];


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list