aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/parallaction/animation.cpp4
-rw-r--r--engines/parallaction/commands.cpp4
-rw-r--r--engines/parallaction/dialogue.cpp21
-rw-r--r--engines/parallaction/location.cpp11
-rw-r--r--engines/parallaction/parallaction.cpp4
-rw-r--r--engines/parallaction/parallaction.h8
-rw-r--r--engines/parallaction/parser.cpp110
-rw-r--r--engines/parallaction/parser.h22
-rw-r--r--engines/parallaction/zone.cpp8
9 files changed, 133 insertions, 59 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp
index 0dc76d38d4..613721cb80 100644
--- a/engines/parallaction/animation.cpp
+++ b/engines/parallaction/animation.cpp
@@ -85,7 +85,7 @@ Animation *Parallaction::parseAnimation(ArchivedFile *file, Node *list, char *na
addNode(list, &vD0->_zone._node);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endanimation")) {
// printf("token[0] = %s\n", _tokens[0]);
@@ -142,7 +142,7 @@ Animation *Parallaction::parseAnimation(ArchivedFile *file, Node *list, char *na
vD0->_zone._moveTo._y = atoi(_tokens[2]);
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
vD0->_zone.pos._oldposition._x = -1000;
diff --git a/engines/parallaction/commands.cpp b/engines/parallaction/commands.cpp
index 73341b6d2f..3662579427 100644
--- a/engines/parallaction/commands.cpp
+++ b/engines/parallaction/commands.cpp
@@ -51,7 +51,7 @@ Command *parseCommands(ArchivedFile *file) {
Node root;
memset(&root, 0, sizeof(root));
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDCOMMANDS") && scumm_stricmp(_tokens[0], "ENDZONE")) {
// printf("token[0] = %s", _tokens[0]);
@@ -185,7 +185,7 @@ Command *parseCommands(ArchivedFile *file) {
}
addNode(&root, &cmd->_node);
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
}
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index 1e374c8d0d..a7ceb7c697 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -57,9 +57,8 @@ int16 _answerBalloonW[10] = { 0 };
int16 _answerBalloonH[10] = { 0 };
-char *parseDialogueString();
-Dialogue *parseDialogue(ArchivedFile *file) {
+Dialogue *Parallaction::parseDialogue(ArchivedFile *file) {
// printf("parseDialogue()\n");
uint16 num_questions = 0;
uint16 v50[20];
@@ -70,7 +69,7 @@ Dialogue *parseDialogue(ArchivedFile *file) {
v50[_si] = 0;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "enddialogue")) {
if (scumm_stricmp(_tokens[0], "Question")) continue;
@@ -85,12 +84,12 @@ Dialogue *parseDialogue(ArchivedFile *file) {
vB4->_text = parseDialogueString();
// printf("Question: '%s'\n", vB4->_text);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
vB4->_mood = atoi(_tokens[0]);
uint16 _di = 0;
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endquestion")) { // parse answers
const char** v60 = const_cast<const char **>(_localFlagNames);
@@ -124,20 +123,20 @@ Dialogue *parseDialogue(ArchivedFile *file) {
// printf("answer[%i]: '%s'\n", _di, vB4->_answers[_di]);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
vB4->_answer_moods[_di] = atoi(_tokens[0]);
vB4->_following._names[_di] = parseDialogueString();
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
if (!scumm_stricmp(_tokens[0], "commands")) {
vB4->_commands[_di] = parseCommands(file);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
_di++;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
num_questions++;
}
@@ -173,13 +172,13 @@ Dialogue *parseDialogue(ArchivedFile *file) {
}
-char *parseDialogueString() {
+char *Parallaction::parseDialogueString() {
char vC8[200];
char *vD0 = NULL;
do {
- vD0 = parseNextLine(vC8, 200);
+ vD0 = _locationScript->readLine(vC8, 200);
if (vD0 == 0) return NULL;
vD0 = Common::ltrim(vD0);
diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp
index b99b5ce937..5896a45ec1 100644
--- a/engines/parallaction/location.cpp
+++ b/engines/parallaction/location.cpp
@@ -76,13 +76,14 @@ void Parallaction::parseLocation(const char *filename) {
uint32 count = file->_endOffset - file->_offset;
location_src = (char*)memAlloc(0x4000);
- parseInit(location_src);
+ _locationScript = new LocScript(location_src);
+// parseInit(location_src);
readArchivedFile(file, location_src, count);
closeArchivedFile(file);
closeArchive();
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDLOCATION")) {
// printf("token[0] = %s", _tokens[0]);
@@ -186,7 +187,7 @@ void Parallaction::parseLocation(const char *filename) {
if (!scumm_stricmp(_tokens[0], "SOUND")) {
strcpy(_soundFile, _tokens[1]);
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
resolveLocationForwards();
@@ -264,7 +265,7 @@ void freeLocation() {
void parseWalkNodes(ArchivedFile *file, Node *list) {
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
while (scumm_stricmp(_tokens[0], "ENDNODES")) {
if (!scumm_stricmp(_tokens[0], "COORD")) {
@@ -277,7 +278,7 @@ void parseWalkNodes(ArchivedFile *file, Node *list) {
}
- parseFillBuffers();
+ fillBuffers(*_vm->_locationScript, true);
}
return;
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 30c71c555b..958a001cfe 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -1017,7 +1017,7 @@ void Parallaction::initTable(const char *path, char** table) {
uint16 count = 0;
- tableFillBuffers(stream);
+ fillBuffers(stream);
while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
@@ -1025,7 +1025,7 @@ void Parallaction::initTable(const char *path, char** table) {
strcpy(table[count], _tokens[0]);
count++;
- tableFillBuffers(stream);
+ fillBuffers(stream);
}
table[count] = NULL;
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 015ea44029..3abf7b070c 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -26,6 +26,7 @@
#include "engines/engine.h"
#include "parallaction/defs.h"
#include "parallaction/inventory.h"
+#include "parallaction/parser.h"
#include "common/str.h"
#include "gui/dialog.h"
#include "gui/widget.h"
@@ -240,6 +241,11 @@ public:
void changeCursor(int32 index);
void changeCharacter(const char *name);
+ char *parseComment(ArchivedFile *file);
+ char *parseDialogueString();
+ Dialogue *parseDialogue(ArchivedFile *file);
+
+
public:
int getGameType() const;
uint32 getFeatures() const;
@@ -263,6 +269,8 @@ public:
InventoryItem _activeItem;
+ LocScript *_locationScript;
+
protected: // data
struct InputData {
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp
index 6ff753e68e..3237004450 100644
--- a/engines/parallaction/parser.cpp
+++ b/engines/parallaction/parser.cpp
@@ -22,11 +22,13 @@
#include "parallaction/defs.h"
#include "parallaction/parser.h"
+#include "parallaction/parallaction.h"
#include "parallaction/disk.h"
namespace Parallaction {
char _tokens[20][40];
+/*
static char *_src = NULL;
@@ -54,19 +56,84 @@ char *parseNextLine(char *s, uint16 count) {
return s;
}
+*/
+LocScript::LocScript(const char* s) : _src(s) {
+
+}
+
+char *LocScript::readLine(char *buf, size_t bufSize) {
+
+ uint16 _si;
+ char v2 = 0;
+ for ( _si = 0; _si<bufSize; _si++) {
+
+ v2 = *_src++;
+ if (v2 == 0xA || v2 == -1) break;
+ if (v2 != -1 && _si < bufSize) buf[_si] = v2;
+ }
+
+ if (_si == 0 && v2 == -1)
+ return 0;
+
+ buf[_si] = 0xA;
+ buf[_si+1] = '\0';
+
+ return buf;
+
+}
+
+uint32 LocScript::read(void *dataPtr, uint32 dataSize) {
+ error("binary read not supported on LocScript streams");
+}
+
+bool LocScript::eos() const {
+ error("EoS not supported on LocScript streams");
+}
+
+uint32 LocScript::pos() const {
+ error("position not supported on LocScript streams");
+}
+
+uint32 LocScript::size() const {
+ error("can't get size of LocScript streams");
+}
+
+void LocScript::seek(int32 offset, int whence) {
+ error("seek not supported on LocScript streams");
+}
+
+// looks for next token in a string
+//
+// scans 's' until one of the stop-chars in 'brk' is found
+// builds a token and return the part of the string which hasn't been parsed
+
+char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
+
+ while (*s != '\0') {
+
+ if (brk[0] == *s) break;
+ if (brk[1] == *s) break;
+ if (brk[2] == *s) break;
+
+ *tok++ = *s++;
+ }
+
+ *tok = '\0';
+ return s;
+}
//
// a comment can appear both at location and Zone levels
// comments are displayed into rectangles on the screen
//
-char *parseComment(ArchivedFile *file) {
+char *Parallaction::parseComment(ArchivedFile *file) {
char _tmp_comment[1000] = "\0";
char *v194;
do {
char v190[400];
- v194 = parseNextLine(v190, 400);
+ v194 = _locationScript->readLine(v190, 400);
v194[strlen(v194)-1] = '\0';
if (!scumm_stricmp(v194, "endtext"))
@@ -113,26 +180,29 @@ uint16 fillTokens(char* line) {
return i;
}
-uint16 parseFillBuffers() {
+uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF) {
clearTokens();
char buf[200];
char *line = NULL;
do {
- line = parseNextLine(buf, 200);
+ line = stream.readLine(buf, 200);
if (line == NULL) {
- error("unexpected end of file while parsing");
+ if (errorOnEOF)
+ error("unexpected end of file while parsing");
+ else
+ return 0;
}
line = Common::ltrim(line);
} while (strlen(line) == 0 || line[0] == '#');
return fillTokens(line);
}
-
+/*
//
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from a SeekableStream instead of a memory buffer
//
uint16 tableFillBuffers(Common::SeekableReadStream &stream) {
@@ -151,10 +221,10 @@ uint16 tableFillBuffers(Common::SeekableReadStream &stream) {
return fillTokens(line);
}
-
+*/
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from an ArchivedFile instead of a memory buffer
//
uint16 scriptFillBuffers(ArchivedFile *file) {
@@ -174,26 +244,4 @@ uint16 scriptFillBuffers(ArchivedFile *file) {
return fillTokens(line);
}
-
-// looks for next token in a string
-//
-// scans 's' until one of the stop-chars in 'brk' is found
-// builds a token and return the part of the string which hasn't been parsed
-
-char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
-
- while (*s != '\0') {
-
- if (brk[0] == *s) break;
- if (brk[1] == *s) break;
- if (brk[2] == *s) break;
-
- *tok++ = *s++;
- }
-
- *tok = '\0';
- return s;
-}
-
-
} // namespace Parallaction
diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h
index 5ae42b5956..622d3ec719 100644
--- a/engines/parallaction/parser.h
+++ b/engines/parallaction/parser.h
@@ -24,7 +24,7 @@
#define PARALLACTION_PARSER_H
#include "parallaction/defs.h"
-#include "common/file.h"
+#include "common/stream.h"
namespace Parallaction {
@@ -33,7 +33,7 @@ struct ArchivedFile;
void parseInit(char *s);
char *parseNextLine(char *s, uint16 count);
char *parseComment(ArchivedFile *file);
-uint16 parseFillBuffers();
+uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF = false);
char *parseNextToken(char *s, char *tok, uint16 count, const char *brk);
uint16 tableFillBuffers(Common::SeekableReadStream &stream);
@@ -42,6 +42,24 @@ uint16 scriptFillBuffers(ArchivedFile *file);
extern char _tokens[][40];
+class LocScript : public Common::SeekableReadStream {
+
+ const char* _src;
+
+public:
+ LocScript(const char* s);
+
+ uint32 read(void *dataPtr, uint32 dataSize);
+
+ char *readLine(char *buf, size_t bufSize);
+
+ bool eos() const;
+ uint32 pos() const;
+ uint32 size() const;
+
+ void seek(int32 offset, int whence = SEEK_SET);
+};
+
} // namespace Parallaction
#endif
diff --git a/engines/parallaction/zone.cpp b/engines/parallaction/zone.cpp
index 55ab4ce18e..fd132bc96a 100644
--- a/engines/parallaction/zone.cpp
+++ b/engines/parallaction/zone.cpp
@@ -59,7 +59,7 @@ void Parallaction::parseZone(ArchivedFile *file, Node *list, char *name) {
if (findZone(name)) {
while (scumm_stricmp(_tokens[0], "endzone")) {
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
return;
}
@@ -72,7 +72,7 @@ void Parallaction::parseZone(ArchivedFile *file, Node *list, char *name) {
addNode(list, &z->_node);
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
while (scumm_stricmp(_tokens[0], "endzone")) {
// printf("token[0] = %s", _tokens[0]);
@@ -114,7 +114,7 @@ void Parallaction::parseZone(ArchivedFile *file, Node *list, char *name) {
} while (!scumm_stricmp(_tokens[_si++], "|"));
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
}
return;
@@ -352,7 +352,7 @@ void Parallaction::parseZoneTypeBlock(ArchivedFile *file, Zone *z) {
break;
}
- parseFillBuffers();
+ fillBuffers(*_locationScript, true);
} while (scumm_stricmp(_tokens[0], "endzone"));
return;