aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction
diff options
context:
space:
mode:
authorNicola Mettifogo2007-04-07 15:18:26 +0000
committerNicola Mettifogo2007-04-07 15:18:26 +0000
commit162247ad3e765e8bc193f9d7b94d00cb844b5f2e (patch)
treec0189f961ed27f93f09e99cde11b20efe8d5d0f9 /engines/parallaction
parentcaf2b4d270ed2211c2810ac2e6c1db4f1dc78cc3 (diff)
downloadscummvm-rg350-162247ad3e765e8bc193f9d7b94d00cb844b5f2e.tar.gz
scummvm-rg350-162247ad3e765e8bc193f9d7b94d00cb844b5f2e.tar.bz2
scummvm-rg350-162247ad3e765e8bc193f9d7b94d00cb844b5f2e.zip
Changed Commands to use List<>
svn-id: r26407
Diffstat (limited to 'engines/parallaction')
-rw-r--r--engines/parallaction/animation.cpp2
-rw-r--r--engines/parallaction/commands.cpp24
-rw-r--r--engines/parallaction/commands.h1
-rw-r--r--engines/parallaction/dialogue.cpp12
-rw-r--r--engines/parallaction/location.cpp19
-rw-r--r--engines/parallaction/parallaction.cpp6
-rw-r--r--engines/parallaction/parallaction.h12
-rw-r--r--engines/parallaction/zone.cpp3
-rw-r--r--engines/parallaction/zone.h6
9 files changed, 41 insertions, 44 deletions
diff --git a/engines/parallaction/animation.cpp b/engines/parallaction/animation.cpp
index fc11383fc0..5ef51d170c 100644
--- a/engines/parallaction/animation.cpp
+++ b/engines/parallaction/animation.cpp
@@ -93,7 +93,7 @@ Animation *Parallaction::parseAnimation(Script& script, Node *list, char *name)
loadProgram(vD0, _tokens[1]);
}
if (!scumm_stricmp(_tokens[0], "commands")) {
- vD0->_commands = parseCommands(script);
+ parseCommands(script, vD0->_commands);
}
if (!scumm_stricmp(_tokens[0], "type")) {
if (_tokens[2][0] != '\0') {
diff --git a/engines/parallaction/commands.cpp b/engines/parallaction/commands.cpp
index 66e60c16e8..af42318d19 100644
--- a/engines/parallaction/commands.cpp
+++ b/engines/parallaction/commands.cpp
@@ -46,7 +46,7 @@ namespace Parallaction {
#define CMD_STOP 16
-Command *Parallaction::parseCommands(Script &script) {
+void Parallaction::parseCommands(Script &script, CommandList& list) {
// printf("parseCommands()");
Node root;
@@ -189,30 +189,32 @@ Command *Parallaction::parseCommands(Script &script) {
}
- return (Command*)root._next;
}
-void Parallaction::freeCommands(Command *list) {
+void Parallaction::freeCommands(CommandList &list) {
- Command *cmd = list;
+ CommandList::iterator it = list.begin();
- while (cmd) {
- Command *v4 = (Command*)cmd->_next;
- delete cmd;
- cmd = v4;
+ while ( it != list.end() ) {
+ delete *it;
+ it++;
}
+ list.clear();
+
return;
}
-void Parallaction::runCommands(Command *list, Zone *z) {
+void Parallaction::runCommands(CommandList& list, Zone *z) {
debugC(1, kDebugLocation, "runCommands");
- Command *cmd = list;
- for ( ; cmd; cmd = (Command*)cmd->_next) {
+ CommandList::iterator it = list.begin();
+ for ( ; it != list.end(); it++) {
+
+ Command *cmd = *it;
CommandData *u = &cmd->u;
uint32 v8 = _localFlags[_vm->_currentLocationIndex];
diff --git a/engines/parallaction/commands.h b/engines/parallaction/commands.h
index 1278cdcc9b..a1778b5d16 100644
--- a/engines/parallaction/commands.h
+++ b/engines/parallaction/commands.h
@@ -41,6 +41,7 @@ enum CommandFlags {
struct Zone;
struct Animation;
+
// TODO: turn this into a struct
union CommandData {
uint32 _flags;
diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp
index a56669ad27..b7d6d0cf35 100644
--- a/engines/parallaction/dialogue.cpp
+++ b/engines/parallaction/dialogue.cpp
@@ -133,7 +133,7 @@ Dialogue *Parallaction::parseDialogue(Script &script) {
fillBuffers(script, true);
if (!scumm_stricmp(_tokens[0], "commands")) {
- vB4->_answers[_di]->_commands = parseCommands(script);
+ parseCommands(script, vB4->_answers[_di]->_commands);
fillBuffers(script, true);
}
@@ -355,7 +355,7 @@ void Parallaction::runDialogue(SpeakData *data) {
_askPassword = false;
uint16 answer = 0;
- Command *cmdlist = NULL;
+ CommandList *cmdlist = NULL;
Dialogue *q = data->_dialogue;
while (q) {
@@ -369,7 +369,7 @@ void Parallaction::runDialogue(SpeakData *data) {
if (!displayAnswers(q)) break;
answer = getDialogueAnswer(q, _vm->_char._talk);
- cmdlist = q->_answers[answer]->_commands;
+ cmdlist = &q->_answers[answer]->_commands;
}
q = (Dialogue*)q->_answers[answer]->_following._question;
@@ -384,7 +384,7 @@ void Parallaction::runDialogue(SpeakData *data) {
}
exitDialogue();
- runCommands(cmdlist);
+ runCommands(*cmdlist);
return;
@@ -488,7 +488,6 @@ Answer::Answer() {
_text = NULL;
_mood = 0;
_following._question = NULL;
- _commands = NULL;
_noFlags = 0;
_yesFlags = 0;
}
@@ -497,8 +496,7 @@ Answer::~Answer() {
if (_mood & 0x10)
delete _following._question;
- if (_commands)
- _vm->freeCommands(_commands);
+ _vm->freeCommands(_commands);
if (_text)
free(_text);
diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp
index eaf2d5c2e3..445d084528 100644
--- a/engines/parallaction/location.cpp
+++ b/engines/parallaction/location.cpp
@@ -112,10 +112,10 @@ void Parallaction::parseLocation(const char *filename) {
}
}
if (!scumm_stricmp(_tokens[0], "COMMANDS")) {
- _location._commands = parseCommands(*_locationScript);
+ parseCommands(*_locationScript, _location._commands);
}
if (!scumm_stricmp(_tokens[0], "ACOMMANDS")) {
- _location._aCommands = parseCommands(*_locationScript);
+ parseCommands(*_locationScript, _location._aCommands);
}
if (!scumm_stricmp(_tokens[0], "FLAGS")) {
if ((_localFlags[_currentLocationIndex] & kFlagsVisited) == 0) {
@@ -221,16 +221,10 @@ void Parallaction::freeLocation() {
debugC(7, kDebugLocation, "freeLocation: comments freed");
// TODO (LIST): this should be _location._commands.clear();
- if (_vm->_location._commands) {
- freeNodeList(_vm->_location._commands);
- }
- _vm->_location._commands = NULL;
+ freeCommands(_vm->_location._commands);
debugC(7, kDebugLocation, "freeLocation: commands freed");
- if (_vm->_location._aCommands) {
- freeNodeList(_vm->_location._aCommands);
- }
- _vm->_location._aCommands = NULL;
+ freeCommands(_vm->_location._aCommands);
debugC(7, kDebugLocation, "freeLocation: acommands freed");
return;
@@ -412,7 +406,8 @@ void Parallaction::changeLocation(char *location) {
for (uint16 _si = 0; _si < PALETTE_SIZE; _si++) palette[_si] = 0;
_gfx->extendPalette(palette);
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
- if (_location._commands) {
+
+ if (_location._commands.size() > 0) {
runCommands(_location._commands);
runJobs();
_gfx->swapBuffers();
@@ -429,7 +424,7 @@ void Parallaction::changeLocation(char *location) {
_gfx->swapBuffers();
_gfx->extendPalette(_vm->_gfx->_palette);
- if (_location._aCommands) {
+ if (_location._aCommands.size() > 0) {
runCommands(_location._aCommands);
debugC(1, kDebugLocation, "changeLocation: location acommands run");
}
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 91228720a3..4feee8e47b 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -195,8 +195,6 @@ int Parallaction::init() {
else
strcpy(_location._name, "fogne");
- _location._aCommands = NULL;
- _location._commands = NULL;
_location._comment = NULL;
_location._endComment = NULL;
@@ -352,7 +350,7 @@ void Parallaction::runGame() {
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBit2);
- if (_location._commands)
+ if (_location._commands.size() > 0)
runCommands(_location._commands);
runJobs();
@@ -364,7 +362,7 @@ void Parallaction::runGame() {
changeCursor(kCursorArrow);
- if (_location._aCommands)
+ if (_location._aCommands.size() > 0)
runCommands(_location._aCommands);
while ((_engineFlags & kEngineQuit) == 0) {
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 1a405820f8..bc1205cc2f 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -226,6 +226,8 @@ class Gfx;
class Menu;
class MidiPlayer;
+
+
struct Location {
Common::Point _startPosition;
@@ -233,8 +235,8 @@ struct Location {
Node _walkNodes;
char _name[100];
- Command *_aCommands;
- Command *_commands;
+ CommandList _aCommands;
+ CommandList _commands;
char *_comment;
char *_endComment;
@@ -317,7 +319,7 @@ public:
// static void initTable(const char *path, char **table);
// static void freeTable(char** table);
// static int16 searchTable(const char *s, const char **table);
- void freeCommands(Command*);
+ void freeCommands(CommandList& list);
void parseLocation(const char *filename);
void changeCursor(int32 index);
@@ -352,7 +354,7 @@ public:
uint16 runZone(Zone*);
void runDialogue(SpeakData*);
- void runCommands(Command *list, Zone *z = NULL);
+ void runCommands(CommandList& list, Zone *z = NULL);
public:
int getGameType() const;
@@ -454,7 +456,7 @@ protected: // members
void pickMusic(const char *location);
void selectCharacterMusic(const char *name);
- Command *parseCommands(Script &script);
+ void parseCommands(Script &script, CommandList&);
void freeCharacter();
diff --git a/engines/parallaction/zone.cpp b/engines/parallaction/zone.cpp
index 80174f432b..378c7fde01 100644
--- a/engines/parallaction/zone.cpp
+++ b/engines/parallaction/zone.cpp
@@ -90,7 +90,7 @@ void Parallaction::parseZone(Script &script, Node *list, char *name) {
}
}
if (!scumm_stricmp(_tokens[0], "commands")) {
- z->_commands = parseCommands(script);
+ parseCommands(script, z->_commands);
}
if (!scumm_stricmp(_tokens[0], "label")) {
// printf("label: %s", _tokens[1]);
@@ -603,7 +603,6 @@ Zone::Zone() {
_type = 0;
_flags = 0;
- _commands = NULL;
}
Zone::~Zone() {
diff --git a/engines/parallaction/zone.h b/engines/parallaction/zone.h
index 7ee5bbf66d..6ad5c6c296 100644
--- a/engines/parallaction/zone.h
+++ b/engines/parallaction/zone.h
@@ -68,6 +68,8 @@ enum ZoneFlags {
struct Command;
struct Question;
+typedef Common::List<Command*> CommandList;
+
struct Answer {
char* _text;
uint16 _mood;
@@ -75,7 +77,7 @@ struct Answer {
Question* _question;
char* _name;
} _following;
- Command* _commands;
+ CommandList _commands;
uint32 _noFlags;
uint32 _yesFlags;
@@ -199,7 +201,7 @@ struct Zone : public Node {
uint16 field_2C; // unused
uint16 field_2E; // unused
TypeData u;
- Command *_commands;
+ CommandList _commands;
Common::Point _moveTo;
Zone();