aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/commands
diff options
context:
space:
mode:
authorĽubomír Remák2018-03-21 22:49:36 +0100
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commit3928c52c0ee2a930431a807d0b4262440ab75725 (patch)
tree874e279633838112983f3468fc3fc93880f41365 /engines/mutationofjb/commands
parent7a081f0605f2282fdce907bedfc9cae55dc67ab7 (diff)
downloadscummvm-rg350-3928c52c0ee2a930431a807d0b4262440ab75725.tar.gz
scummvm-rg350-3928c52c0ee2a930431a807d0b4262440ab75725.tar.bz2
scummvm-rg350-3928c52c0ee2a930431a807d0b4262440ab75725.zip
MUTATIONOFJB: Add support for CAMEFROM command.
Diffstat (limited to 'engines/mutationofjb/commands')
-rw-r--r--engines/mutationofjb/commands/camefromcommand.cpp57
-rw-r--r--engines/mutationofjb/commands/camefromcommand.h49
-rw-r--r--engines/mutationofjb/commands/command.cpp2
-rw-r--r--engines/mutationofjb/commands/conditionalcommand.cpp2
-rw-r--r--engines/mutationofjb/commands/conditionalcommand.h4
-rw-r--r--engines/mutationofjb/commands/endblockcommand.cpp10
-rw-r--r--engines/mutationofjb/commands/endblockcommand.h3
-rw-r--r--engines/mutationofjb/commands/labelcommand.cpp4
8 files changed, 123 insertions, 8 deletions
diff --git a/engines/mutationofjb/commands/camefromcommand.cpp b/engines/mutationofjb/commands/camefromcommand.cpp
new file mode 100644
index 0000000000..2c232c1ce5
--- /dev/null
+++ b/engines/mutationofjb/commands/camefromcommand.cpp
@@ -0,0 +1,57 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "mutationofjb/commands/camefromcommand.h"
+#include "mutationofjb/gamedata.h"
+#include "common/str.h"
+
+/*
+ "CAMEFROM" <sceneId>
+
+ This command tests whether last scene (the scene player came from) is sceneId.
+ If true, the execution continues after this command.
+ Otherwise the execution continues after first '#' found.
+*/
+
+namespace MutationOfJB {
+
+bool CameFromCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) {
+ if (line.size() < 10 || !line.hasPrefix("CAMEFROM")) {
+ return false;
+ }
+
+ const uint8 sceneId = atoi(line.c_str() + 9);
+ command = new CameFromCommand(sceneId);
+ return true;
+}
+
+Command::ExecuteResult CameFromCommand::execute(GameData &gameData) {
+ _cachedResult = (gameData._lastScene == _sceneId);
+
+ return Finished;
+}
+
+Common::String CameFromCommand::debugString() const {
+ return Common::String::format("CAMEFROM %d", _sceneId);
+}
+
+}
diff --git a/engines/mutationofjb/commands/camefromcommand.h b/engines/mutationofjb/commands/camefromcommand.h
new file mode 100644
index 0000000000..c097ca1fa6
--- /dev/null
+++ b/engines/mutationofjb/commands/camefromcommand.h
@@ -0,0 +1,49 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MUTATIONOFJB_CAMEFROMCOMMAND_H
+#define MUTATIONOFJB_CAMEFROMCOMMAND_H
+
+#include "mutationofjb/commands/conditionalcommand.h"
+#include "common/scummsys.h"
+
+namespace MutationOfJB {
+
+class CameFromCommandParser : public ConditionalCommandParser {
+public:
+ CameFromCommandParser() : ConditionalCommandParser(true) {}
+ virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
+};
+
+class CameFromCommand : public ConditionalCommand {
+public:
+ CameFromCommand(uint8 sceneId) : _sceneId(sceneId) {}
+ virtual ExecuteResult execute(GameData &gameData) override;
+ virtual Common::String debugString() const;
+private:
+ uint8 _sceneId;
+};
+
+}
+
+#endif
+
diff --git a/engines/mutationofjb/commands/command.cpp b/engines/mutationofjb/commands/command.cpp
index 6c4dc47cbb..d1e92f8f74 100644
--- a/engines/mutationofjb/commands/command.cpp
+++ b/engines/mutationofjb/commands/command.cpp
@@ -26,7 +26,7 @@
namespace MutationOfJB {
void CommandParser::transition(ScriptParseContext &, Command *, Command *, CommandParser *) {}
-void CommandParser::finish(ScriptParseContext &parseCtx) {}
+void CommandParser::finish(ScriptParseContext &) {}
CommandParser::~CommandParser() {}
Command::~Command() {}
diff --git a/engines/mutationofjb/commands/conditionalcommand.cpp b/engines/mutationofjb/commands/conditionalcommand.cpp
index aa42d1c4db..27b271409a 100644
--- a/engines/mutationofjb/commands/conditionalcommand.cpp
+++ b/engines/mutationofjb/commands/conditionalcommand.cpp
@@ -34,7 +34,7 @@ void ConditionalCommandParser::transition(ScriptParseContext &parseContext, Comm
}
ConditionalCommand *const condCommand = static_cast<ConditionalCommand *>(oldCommand);
- parseContext.addConditionalCommand(condCommand, _lastTag);
+ parseContext.addConditionalCommand(condCommand, _lastTag, _firstHash);
condCommand->setTrueCommand(newCommand);
}
diff --git a/engines/mutationofjb/commands/conditionalcommand.h b/engines/mutationofjb/commands/conditionalcommand.h
index d64efbf180..ea1a66afb0 100644
--- a/engines/mutationofjb/commands/conditionalcommand.h
+++ b/engines/mutationofjb/commands/conditionalcommand.h
@@ -30,11 +30,13 @@ namespace MutationOfJB {
class ConditionalCommandParser : public CommandParser {
public:
- ConditionalCommandParser() : _lastTag(0) {}
+ ConditionalCommandParser(bool firstHash = false) : _lastTag(0), _firstHash(firstHash) {}
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);
virtual void finish(ScriptParseContext &parseCtx) override;
protected:
char _lastTag;
+private:
+ bool _firstHash;
};
class ConditionalCommand : public Command {
diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp
index 2d2ebe3478..c8adaaa998 100644
--- a/engines/mutationofjb/commands/endblockcommand.cpp
+++ b/engines/mutationofjb/commands/endblockcommand.cpp
@@ -87,18 +87,22 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext
}
}
+ if (firstChar == '#') {
+ _hashFound = true;
+ }
+
command = new EndBlockCommand();
return true;
}
void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand, CommandParser *newCommandParser) {
- if (_elseFound) {
+ if (_elseFound || _hashFound) {
if (newCommand) {
ScriptParseContext::ConditionalCommandInfos::iterator it = parseCtx._pendingCondCommands.begin();
while (it != parseCtx._pendingCondCommands.end()) {
- if (it->_tag == _ifTag) {
+ if ((it->_firstHash && _hashFound) || (!it->_firstHash && it->_tag == _ifTag)) {
it->_command->setFalseCommand(newCommand);
it = parseCtx._pendingCondCommands.erase(it);
} else {
@@ -108,6 +112,7 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *,
}
_elseFound = false;
+ _hashFound = false;
_ifTag = 0;
}
@@ -123,6 +128,7 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *,
void EndBlockCommandParser::finish(ScriptParseContext &) {
_elseFound = false;
+ _hashFound = false;
_ifTag = 0;
if (!_pendingActionInfos.empty()) {
diff --git a/engines/mutationofjb/commands/endblockcommand.h b/engines/mutationofjb/commands/endblockcommand.h
index 3af86a3d82..140fb21917 100644
--- a/engines/mutationofjb/commands/endblockcommand.h
+++ b/engines/mutationofjb/commands/endblockcommand.h
@@ -33,13 +33,14 @@ class ActionInfo;
class EndBlockCommandParser : public CommandParser {
public:
- EndBlockCommandParser() : _elseFound(false), _ifTag(0) {}
+ EndBlockCommandParser() : _elseFound(false), _hashFound(false), _ifTag(0) {}
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override;
virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser) override;
virtual void finish(ScriptParseContext &parseCtx) override;
private:
bool _elseFound;
+ bool _hashFound;
char _ifTag;
Common::Array<uint> _pendingActionInfos;
diff --git a/engines/mutationofjb/commands/labelcommand.cpp b/engines/mutationofjb/commands/labelcommand.cpp
index 15a10cafd4..87c78f953d 100644
--- a/engines/mutationofjb/commands/labelcommand.cpp
+++ b/engines/mutationofjb/commands/labelcommand.cpp
@@ -41,8 +41,8 @@ bool LabelCommandParser::parse(const Common::String &line, ScriptParseContext &p
label.deleteLastChar();
LabelCommand *labelCmd = new LabelCommand(label);
- if (!parseCtx._labels.contains(line)) {
- parseCtx._labels[line] = labelCmd;
+ if (!parseCtx._labels.contains(label)) {
+ parseCtx._labels[label] = labelCmd;
} else {
warning("Label '%s' already exists", label.c_str());
}