aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorĽubomír Remák2018-03-11 00:46:44 +0100
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commitae979a831091e04797f19d0c80210d745cd60f62 (patch)
tree988ab239c438bca49b1585ff2befc5a4aba64bb5
parentfa9c8be1292e1f0174454193807f39b5c3ee52bf (diff)
downloadscummvm-rg350-ae979a831091e04797f19d0c80210d745cd60f62.tar.gz
scummvm-rg350-ae979a831091e04797f19d0c80210d745cd60f62.tar.bz2
scummvm-rg350-ae979a831091e04797f19d0c80210d745cd60f62.zip
MUTATIONOFJB: Add support for IFITEM command and fix parsing conditional commands that are right after #ELSE.
-rw-r--r--engines/mutationofjb/commands/conditionalcommand.cpp14
-rw-r--r--engines/mutationofjb/commands/conditionalcommand.h7
-rw-r--r--engines/mutationofjb/commands/ifcommand.cpp19
-rw-r--r--engines/mutationofjb/commands/ifcommand.h8
-rw-r--r--engines/mutationofjb/commands/ifitemcommand.cpp90
-rw-r--r--engines/mutationofjb/commands/ifitemcommand.h53
-rw-r--r--engines/mutationofjb/debug.cpp2
-rw-r--r--engines/mutationofjb/inventory.cpp5
-rw-r--r--engines/mutationofjb/inventory.h1
-rw-r--r--engines/mutationofjb/module.mk1
-rw-r--r--engines/mutationofjb/script.cpp2
11 files changed, 181 insertions, 21 deletions
diff --git a/engines/mutationofjb/commands/conditionalcommand.cpp b/engines/mutationofjb/commands/conditionalcommand.cpp
index 13ea6741d1..1e0b7555c2 100644
--- a/engines/mutationofjb/commands/conditionalcommand.cpp
+++ b/engines/mutationofjb/commands/conditionalcommand.cpp
@@ -21,10 +21,24 @@
*/
#include "mutationofjb/commands/conditionalcommand.h"
+#include "mutationofjb/script.h"
#include "common/scummsys.h"
+#include "common/translation.h"
namespace MutationOfJB {
+void ConditionalCommandParser::transition(ScriptParseContext &parseContext, Command *oldCommand, Command *newCommand, CommandParser *) {
+ if (!oldCommand || !newCommand) {
+ warning(_("Unexpected empty command in transition"));
+ return;
+ }
+
+ ConditionalCommand *const condCommand = static_cast<ConditionalCommand *>(oldCommand);
+ parseContext.addConditionalCommand(condCommand, _lastTag);
+ condCommand->setTrueCommand(newCommand);
+}
+
+
ConditionalCommand::ConditionalCommand() :
_trueCommand(nullptr),
_falseCommand(nullptr),
diff --git a/engines/mutationofjb/commands/conditionalcommand.h b/engines/mutationofjb/commands/conditionalcommand.h
index 6f647204c6..4a4e7e1064 100644
--- a/engines/mutationofjb/commands/conditionalcommand.h
+++ b/engines/mutationofjb/commands/conditionalcommand.h
@@ -28,6 +28,13 @@
namespace MutationOfJB {
+class ConditionalCommandParser : public CommandParser {
+public:
+ virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);
+protected:
+ char _lastTag;
+};
+
class ConditionalCommand : public Command {
public:
ConditionalCommand();
diff --git a/engines/mutationofjb/commands/ifcommand.cpp b/engines/mutationofjb/commands/ifcommand.cpp
index da8efc1846..44c6b18735 100644
--- a/engines/mutationofjb/commands/ifcommand.cpp
+++ b/engines/mutationofjb/commands/ifcommand.cpp
@@ -31,12 +31,12 @@
IF command compares the value of the WX pseudo-register of the object in the specified scene.
If the values match, execution continues to the next line.
- Otherwise execution continues after first "#ELSE" with the same <tag>.
+ Otherwise execution continues after first "#ELSE" or "=ELSE" with the same <tag>.
The logic can be reversed with exclamation mark at the end.
<tag> is always 1 character long, <sceneId> and <objectId> 2 characters long.
- Please note that this does not work line you are used to from saner languages.
+ Please note that this does not work like you are used to from saner languages.
IF does not have any blocks. It only searches for first #ELSE, so you can have stuff like:
IF something
IF something else
@@ -70,20 +70,11 @@ bool IfCommandParser::parse(const Common::String &line, ScriptParseContext &pars
const uint8 value = atoi(cstr + 9);
const bool negative = (line.lastChar() == '!');
- IfCommand *ifCommand = new IfCommand(sceneId, objectId, value, negative);
+ _lastTag = tag;
- command = ifCommand;
- parseContext.addConditionalCommand(ifCommand, tag);
- return true;
-}
+ command = new IfCommand(sceneId, objectId, value, negative);
-void IfCommandParser::transition(ScriptParseContext &, Command *oldCommand, Command *newCommand, CommandParser *) {
- if (!oldCommand || !newCommand) {
- warning(_("Unexpected empty command in transition"));
- return;
- }
-
- static_cast<IfCommand *>(oldCommand)->setTrueCommand(newCommand);
+ return true;
}
IfCommand::IfCommand(uint8 sceneId, uint8 objectId, uint16 value, bool negative) :
diff --git a/engines/mutationofjb/commands/ifcommand.h b/engines/mutationofjb/commands/ifcommand.h
index 9462278483..51350cecd5 100644
--- a/engines/mutationofjb/commands/ifcommand.h
+++ b/engines/mutationofjb/commands/ifcommand.h
@@ -30,16 +30,14 @@ namespace MutationOfJB {
class ScriptParseContext;
-class IfCommandParser : public CommandParser {
+class IfCommandParser : public ConditionalCommandParser {
public:
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
- virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser);
+private:
};
class IfCommand : public ConditionalCommand {
public:
- static bool ParseFunc(const Common::String &line, ScriptParseContext &parseContext, Command *&command);
-
IfCommand(uint8 sceneId, uint8 objectId, uint16 value, bool negative);
virtual ExecuteResult execute(GameData &gameData) override;
@@ -50,8 +48,6 @@ private:
uint8 _objectId;
uint16 _value;
bool _negative;
-
- bool _cachedResult;
};
}
diff --git a/engines/mutationofjb/commands/ifitemcommand.cpp b/engines/mutationofjb/commands/ifitemcommand.cpp
new file mode 100644
index 0000000000..6f467da0bd
--- /dev/null
+++ b/engines/mutationofjb/commands/ifitemcommand.cpp
@@ -0,0 +1,90 @@
+/* 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/ifitemcommand.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/script.h"
+#include "mutationofjb/util.h"
+#include "common/str.h"
+#include "common/translation.h"
+
+/*
+ "IFITEM" <item> ["!"]
+
+ IFITEM command tests whether an item is in the inventory.
+ If it is, execution continues to the next line.
+ Otherwise execution continues after first "#ELSE" or "=ELSE".
+ The logic can be reversed with exclamation mark at the end.
+
+ Please note that this does not work like you are used to from saner languages.
+ IFITEM does not have any blocks. It only searches for first #ELSE, so you can have stuff like:
+ IFITEM item1
+ IFITEM item2
+ #ELSE
+ ...
+ This is effectively logical AND.
+*/
+
+namespace MutationOfJB {
+
+bool IfItemCommandParser::parse(const Common::String &line, ScriptParseContext &parseContext, Command *&command) {
+ if (line.size() < 8) {
+ return false;
+ }
+
+ if (!line.hasPrefix("IFITEM")) {
+ return false;
+ }
+
+ const bool negative = (line.lastChar() == '!');
+ Common::String item(line.c_str() + 7);
+ if (negative) {
+ item.deleteLastChar(); // Remove '!'.
+ }
+
+ _lastTag = 0;
+ command = new IfItemCommand(item, negative);
+
+ return true;
+}
+
+
+IfItemCommand::IfItemCommand(const Common::String &item, bool negative) :
+ _item(item),
+ _negative(negative)
+{}
+
+Command::ExecuteResult IfItemCommand::execute(GameData &gameData) {
+ _cachedResult = gameData._inventory.hasItem(_item);
+ if (_negative) {
+ _cachedResult = !_cachedResult;
+ }
+
+ return Finished;
+}
+
+Common::String IfItemCommand::debugString() const {
+ return Common::String::format("IFITEM %s%s", _negative ? "NOT " : "", _item.c_str());
+}
+
+}
+
diff --git a/engines/mutationofjb/commands/ifitemcommand.h b/engines/mutationofjb/commands/ifitemcommand.h
new file mode 100644
index 0000000000..0451786789
--- /dev/null
+++ b/engines/mutationofjb/commands/ifitemcommand.h
@@ -0,0 +1,53 @@
+/* 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_IFITEMCOMMAND_H
+#define MUTATIONOFJB_IFITEMCOMMAND_H
+
+#include "mutationofjb/commands/conditionalcommand.h"
+#include "common/scummsys.h"
+#include "common/str.h"
+
+namespace MutationOfJB {
+
+class ScriptParseContext;
+
+class IfItemCommandParser : public ConditionalCommandParser {
+public:
+ virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
+};
+
+class IfItemCommand : public ConditionalCommand {
+public:
+ IfItemCommand(const Common::String &item, bool negative);
+
+ virtual ExecuteResult execute(GameData &gameData) override;
+ virtual Common::String debugString() const;
+
+private:
+ Common::String _item;
+ bool _negative;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/debug.cpp b/engines/mutationofjb/debug.cpp
index c4eb0a3296..87f0091a29 100644
--- a/engines/mutationofjb/debug.cpp
+++ b/engines/mutationofjb/debug.cpp
@@ -115,7 +115,7 @@ void Console::showIndent(int indentLevel) {
void Console::showCommands(Command *command, int indentLevel) {
while (command) {
showIndent(indentLevel);
- debugPrintf("%s\n", command->debugString().c_str());
+ debugPrintf("%s\n", convertToASCII(command->debugString()).c_str());
if (SeqCommand *const seqCmd = dynamic_cast<SeqCommand *>(command)) {
command = seqCmd->next();
diff --git a/engines/mutationofjb/inventory.cpp b/engines/mutationofjb/inventory.cpp
index 8dcec8d9b5..4a46548ad2 100644
--- a/engines/mutationofjb/inventory.cpp
+++ b/engines/mutationofjb/inventory.cpp
@@ -32,6 +32,11 @@ const Inventory::Items &Inventory::getItems() const {
return _items;
}
+bool Inventory::hasItem(const Common::String &item) const {
+ Items::const_iterator it = find(_items.begin(), _items.end(), item);
+ return (it != _items.end());
+}
+
void Inventory::addItem(const Common::String &item) {
_items.push_back(item);
diff --git a/engines/mutationofjb/inventory.h b/engines/mutationofjb/inventory.h
index 02cccc0a51..fe7ca67afa 100644
--- a/engines/mutationofjb/inventory.h
+++ b/engines/mutationofjb/inventory.h
@@ -34,6 +34,7 @@ public:
typedef Common::Array<Common::String> Items;
const Items &getItems() const;
+ bool hasItem(const Common::String &item) const;
void addItem(const Common::String &item);
void removeItem(const Common::String &item);
void removeAllItems();
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index 27c4f4b084..0dfe130c28 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -7,6 +7,7 @@ MODULE_OBJS := \
commands/conditionalcommand.o \
commands/endblockcommand.o \
commands/ifcommand.o \
+ commands/ifitemcommand.o \
commands/removeallitemscommand.o \
commands/removeitemcommand.o \
commands/saycommand.o \
diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp
index 1df6c919cd..c959f0f8cf 100644
--- a/engines/mutationofjb/script.cpp
+++ b/engines/mutationofjb/script.cpp
@@ -28,6 +28,7 @@
#include "common/debug.h"
#include "mutationofjb/commands/command.h"
#include "mutationofjb/commands/ifcommand.h"
+#include "mutationofjb/commands/ifitemcommand.h"
#include "mutationofjb/commands/endblockcommand.h"
#include "mutationofjb/commands/changecommand.h"
#include "mutationofjb/commands/saycommand.h"
@@ -39,6 +40,7 @@ namespace MutationOfJB {
static CommandParser **getParsers() {
static CommandParser *parsers[] = {
+ new IfItemCommandParser,
new IfCommandParser,
new EndBlockCommandParser,
new ChangeDoorCommandParser,