aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--engines/mutationofjb/game.cpp1
-rw-r--r--engines/mutationofjb/gamedata.cpp1
-rw-r--r--engines/mutationofjb/gamedata.h1
-rw-r--r--engines/mutationofjb/module.mk1
-rw-r--r--engines/mutationofjb/script.cpp6
-rw-r--r--engines/mutationofjb/script.h3
14 files changed, 133 insertions, 11 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());
}
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp
index cc7dab753f..397b86c237 100644
--- a/engines/mutationofjb/game.cpp
+++ b/engines/mutationofjb/game.cpp
@@ -77,6 +77,7 @@ bool Game::loadGameData(bool partB) {
void Game::changeScene(uint8 sceneId, bool partB) {
+ _gameData->_lastScene = _gameData->_currentScene;
_gameData->_currentScene = sceneId;
_room->load(_gameData->_currentScene, partB);
diff --git a/engines/mutationofjb/gamedata.cpp b/engines/mutationofjb/gamedata.cpp
index cc85da3a6f..a181510371 100644
--- a/engines/mutationofjb/gamedata.cpp
+++ b/engines/mutationofjb/gamedata.cpp
@@ -171,6 +171,7 @@ Static *Scene::getStatic(uint8 staticId) {
GameData::GameData()
: _currentScene(0),
+ _lastScene(0),
_partB(false) {}
Scene *GameData::getScene(uint8 sceneId) {
diff --git a/engines/mutationofjb/gamedata.h b/engines/mutationofjb/gamedata.h
index 23e238a826..ca70cd7588 100644
--- a/engines/mutationofjb/gamedata.h
+++ b/engines/mutationofjb/gamedata.h
@@ -152,6 +152,7 @@ public:
bool loadFromStream(Common::ReadStream &stream);
uint8 _currentScene;
+ uint8 _lastScene;
bool _partB;
Inventory _inventory;
Common::String _currentAPK;
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index 4137581b72..a81e2a3b62 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -2,6 +2,7 @@ MODULE := engines/mutationofjb
MODULE_OBJS := \
commands/additemcommand.o \
+ commands/camefromcommand.o \
commands/changecommand.o \
commands/command.o \
commands/conditionalcommand.o \
diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp
index 3c34660402..dfb6886af7 100644
--- a/engines/mutationofjb/script.cpp
+++ b/engines/mutationofjb/script.cpp
@@ -38,6 +38,7 @@
#include "mutationofjb/commands/removeallitemscommand.h"
#include "mutationofjb/commands/labelcommand.h"
#include "mutationofjb/commands/gotocommand.h"
+#include "mutationofjb/commands/camefromcommand.h"
namespace MutationOfJB {
@@ -46,6 +47,7 @@ static CommandParser **getParsers() {
new IfPiggyCommandParser,
new IfItemCommandParser,
new IfCommandParser,
+ new CameFromCommandParser,
new EndBlockCommandParser,
new ChangeDoorCommandParser,
new ChangeObjectCommandParser,
@@ -88,8 +90,8 @@ bool ScriptParseContext::readLine(Common::String &line) {
return false;
}
-void ScriptParseContext::addConditionalCommand(ConditionalCommand *command, char tag) {
- ConditionalCommandInfo cmi = {command, tag};
+void ScriptParseContext::addConditionalCommand(ConditionalCommand *command, char tag, bool firstHash) {
+ ConditionalCommandInfo cmi = {command, tag, firstHash};
_pendingCondCommands.push_back(cmi);
}
diff --git a/engines/mutationofjb/script.h b/engines/mutationofjb/script.h
index 66d137c8db..9589968d9a 100644
--- a/engines/mutationofjb/script.h
+++ b/engines/mutationofjb/script.h
@@ -63,7 +63,7 @@ class ScriptParseContext {
public:
ScriptParseContext(Common::SeekableReadStream &stream);
bool readLine(Common::String &line);
- void addConditionalCommand(ConditionalCommand *command, char tag);
+ void addConditionalCommand(ConditionalCommand *command, char tag, bool firstHash);
void addLookSection(const Common::String &item, bool walkTo);
Common::SeekableReadStream &_stream;
@@ -73,6 +73,7 @@ public:
struct ConditionalCommandInfo {
ConditionalCommand *_command;
char _tag;
+ bool _firstHash;
};
typedef Common::Array<ConditionalCommandInfo> ConditionalCommandInfos;
ConditionalCommandInfos _pendingCondCommands;