aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/commands/endblockcommand.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mutationofjb/commands/endblockcommand.cpp')
-rw-r--r--engines/mutationofjb/commands/endblockcommand.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp
index 218be1a31f..be610c7c9a 100644
--- a/engines/mutationofjb/commands/endblockcommand.cpp
+++ b/engines/mutationofjb/commands/endblockcommand.cpp
@@ -41,15 +41,17 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
// This is the start or end of section/block.
if (line.size() >= 4 && (line.hasPrefix("#L ") || line.hasPrefix("-L "))) {
- ScriptParseContext::ActionInfo ai = {ScriptParseContext::Look, line.c_str() + 3, "", firstChar == '#'};
- parseCtx._actionInfos.push_back(ai);
- debug("# Look: %s", line.c_str() + 3);
+ ActionInfo ai = {ActionInfo::Look, line.c_str() + 3, "", firstChar == '#', nullptr};
+ parseCtx._lookActionInfos.push_back(ai);
+ _pendingActionInfos.push_back(&parseCtx._lookActionInfos.back());
} else if (line.size() >= 4 && (line.hasPrefix("#W ") || line.hasPrefix("-W "))) {
- ScriptParseContext::ActionInfo ai = {ScriptParseContext::Walk, line.c_str() + 3, "", firstChar == '#'};
- parseCtx._actionInfos.push_back(ai);
+ ActionInfo ai = {ActionInfo::Walk, line.c_str() + 3, "", firstChar == '#', nullptr};
+ parseCtx._walkActionInfos.push_back(ai);
+ _pendingActionInfos.push_back(&parseCtx._walkActionInfos.back());
} else if (line.size() >= 4 && (line.hasPrefix("#T ") || line.hasPrefix("-T "))) {
- ScriptParseContext::ActionInfo ai = {ScriptParseContext::Talk, line.c_str() + 3, "", firstChar == '#'};
- parseCtx._actionInfos.push_back(ai);
+ ActionInfo ai = {ActionInfo::Talk, line.c_str() + 3, "", firstChar == '#', nullptr};
+ parseCtx._talkActionInfos.push_back(ai);
+ _pendingActionInfos.push_back(&parseCtx._talkActionInfos.back());
} else if (line.size() >= 4 && (line.hasPrefix("#U ") || line.hasPrefix("-U "))) {
int secondObjPos = -1;
for (int i = 3; i < (int) line.size(); ++i) {
@@ -58,13 +60,15 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
break;
}
}
- ScriptParseContext::ActionInfo ai = {
- ScriptParseContext::Talk,
+ ActionInfo ai = {
+ ActionInfo::Use,
line.c_str() + 3,
(secondObjPos != -1) ? line.c_str() + secondObjPos : "",
- firstChar == '#'
+ firstChar == '#',
+ nullptr
};
- parseCtx._actionInfos.push_back(ai);
+ parseCtx._useActionInfos.push_back(ai);
+ _pendingActionInfos.push_back(&parseCtx._useActionInfos.back());
} else if ((line.hasPrefix("#ELSE") || line.hasPrefix("=ELSE"))) {
_elseFound = true;
_ifTag = 0;
@@ -78,7 +82,7 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
return true;
}
-void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand) {
+void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand, CommandParser *newCommandParser) {
if (_elseFound) {
if (newCommand) {
ScriptParseContext::ConditionalCommandInfos::iterator it = parseCtx._pendingCondCommands.begin();
@@ -96,6 +100,14 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *,
_elseFound = false;
_ifTag = 0;
}
+
+ if (!_pendingActionInfos.empty() && newCommandParser != this) {
+ debug("Fixing pending action info.\n");
+ for (Common::Array<ActionInfo *>::iterator it = _pendingActionInfos.begin(); it != _pendingActionInfos.end(); ++it) {
+ (*it)->_command = newCommand;
+ }
+ _pendingActionInfos.clear();
+ }
}
Command::ExecuteResult EndBlockCommand::execute(GameData &) {
@@ -105,4 +117,9 @@ Command::ExecuteResult EndBlockCommand::execute(GameData &) {
Command *EndBlockCommand::next() const {
return nullptr;
}
+
+Common::String EndBlockCommand::debugString() const {
+ return "ENDBLOCK";
+}
+
}