aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorĽubomír Remák2018-04-15 02:26:42 +0200
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commit2fb867b2f56b5c337fe3c547a5f53a627e52b74e (patch)
tree246c6667d8fe596a96981c9ba4918269ef0f4f8f /engines
parent61c106b3307ee2f8aaa579dbc5d7c8f8e62ae41a (diff)
downloadscummvm-rg350-2fb867b2f56b5c337fe3c547a5f53a627e52b74e.tar.gz
scummvm-rg350-2fb867b2f56b5c337fe3c547a5f53a627e52b74e.tar.bz2
scummvm-rg350-2fb867b2f56b5c337fe3c547a5f53a627e52b74e.zip
MUTATIONOFJB: Fix issue with parsing #MACRO and #STARTUP right after end block command.
Diffstat (limited to 'engines')
-rw-r--r--engines/mutationofjb/commands/endblockcommand.cpp59
-rw-r--r--engines/mutationofjb/commands/endblockcommand.h14
2 files changed, 53 insertions, 20 deletions
diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp
index cc6a4559b4..3b4c25bf51 100644
--- a/engines/mutationofjb/commands/endblockcommand.cpp
+++ b/engines/mutationofjb/commands/endblockcommand.cpp
@@ -61,6 +61,7 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
}
// This is the start or end of section/block.
+ command = new EndBlockCommand();
if (line.size() >= 4 && (line.hasPrefix("#L ") || line.hasPrefix("-L "))) {
ActionInfo ai = {ActionInfo::Look, line.c_str() + 3, "", firstChar == '#', nullptr};
@@ -112,21 +113,23 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
_ifTag = line[5];
}
} else if (line.size() >= 8 && line.hasPrefix("#MACRO")) {
- _foundMacro = line.c_str() + 7;
+ NameAndCommand nc = {line.c_str() + 7, command};
+ _foundMacros.push_back(nc);
} else if (line.size() >= 10 && line.hasPrefix("#STARTUP")) {
- _foundStartup = line.c_str() + 9;
+ const uint8 startupId = atoi(line.c_str() + 9);
+ IdAndCommand ic = {startupId, command};
+ _foundStartups.push_back(ic);
}
if (firstChar == '#') {
_hashFound = true;
}
- command = new EndBlockCommand();
return true;
}
-void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand, CommandParser *newCommandParser) {
+void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser) {
if (_elseFound || _hashFound) {
if (newCommand) {
ScriptParseContext::ConditionalCommandInfos::iterator it = parseCtx._pendingCondCommands.begin();
@@ -146,26 +149,39 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *,
_ifTag = 0;
}
- if (!_foundMacro.empty()) {
+ if (!_foundMacros.empty()) {
if (newCommand) {
- if (!parseCtx._macros.contains(_foundMacro)) {
- parseCtx._macros[_foundMacro] = newCommand;
- } else {
- warning(_("Macro '%s' already exists."), _foundMacro.c_str());
+ for (NameAndCommandArray::iterator it = _foundMacros.begin(); it != _foundMacros.end();) {
+ if (it->_command != oldCommand) {
+ it++;
+ continue;
+ }
+
+ if (!parseCtx._macros.contains(it->_name)) {
+ parseCtx._macros[it->_name] = newCommand;
+ } else {
+ warning(_("Macro '%s' already exists"), it->_name.c_str());
+ }
+ it = _foundMacros.erase(it);
}
}
- _foundMacro.clear();
}
- if (!_foundStartup.empty()) {
+ if (!_foundStartups.empty()) {
if (newCommand) {
- const uint8 startupId = atoi(_foundStartup.c_str());
- if (!parseCtx._startups.contains(startupId)) {
- parseCtx._startups[startupId] = newCommand;
- } else {
- warning(_("Startup %u already exists."), (unsigned int) startupId);
+ for (IdAndCommandArray::iterator it = _foundStartups.begin(); it != _foundStartups.end();) {
+ if (it->_command != oldCommand) {
+ it++;
+ continue;
+ }
+
+ if (!parseCtx._startups.contains(it->_id)) {
+ parseCtx._startups[it->_id] = newCommand;
+ } else {
+ warning(_("Startup %u already exists"), (unsigned int) it->_id);
+ }
+ it = _foundStartups.erase(it);
}
}
- _foundStartup.clear();
}
if (newCommandParser != this) {
@@ -186,8 +202,15 @@ void EndBlockCommandParser::finish(ScriptParseContext &) {
if (!_pendingActionInfos.empty()) {
debug("Problem: Pending action infos from end block parser is not empty!");
}
+ if (!_foundMacros.empty()) {
+ debug("Problem: Found macros from end block parser is not empty!");
+ }
+ if (!_foundStartups.empty()) {
+ debug("Problem: Found startups from end block parser is not empty!");
+ }
_pendingActionInfos.clear();
- _foundMacro = "";
+ _foundMacros.clear();
+ _foundStartups.clear();
}
Command::ExecuteResult EndBlockCommand::execute(ScriptExecutionContext &scriptExecCtx) {
diff --git a/engines/mutationofjb/commands/endblockcommand.h b/engines/mutationofjb/commands/endblockcommand.h
index eb77f435d4..4ca46dd97d 100644
--- a/engines/mutationofjb/commands/endblockcommand.h
+++ b/engines/mutationofjb/commands/endblockcommand.h
@@ -44,8 +44,18 @@ private:
char _ifTag;
Common::Array<uint> _pendingActionInfos;
- Common::String _foundMacro;
- Common::String _foundStartup;
+ struct NameAndCommand {
+ Common::String _name;
+ Command *_command;
+ };
+ struct IdAndCommand {
+ uint8 _id;
+ Command *_command;
+ };
+ typedef Common::Array<NameAndCommand> NameAndCommandArray;
+ typedef Common::Array<IdAndCommand> IdAndCommandArray;
+ NameAndCommandArray _foundMacros;
+ IdAndCommandArray _foundStartups;
};
class EndBlockCommand : public Command {