diff options
author | Ľubomír Remák | 2018-03-22 20:56:42 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 938f222d4857b45e0f1f7e4726040ab0bf1d9b67 (patch) | |
tree | 5c15540224645ca541ad6e22b9ce786dbddc7be9 | |
parent | e1d173ed7541f9da79f60a65d974da3ebbb29e7a (diff) | |
download | scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.tar.gz scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.tar.bz2 scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.zip |
MUTATIONOFJB: Add support for calling macros.
-rw-r--r-- | engines/mutationofjb/commands/additemcommand.h | 2 | ||||
-rw-r--r-- | engines/mutationofjb/commands/callmacrocommand.cpp | 85 | ||||
-rw-r--r-- | engines/mutationofjb/commands/callmacrocommand.h | 58 | ||||
-rw-r--r-- | engines/mutationofjb/debug.cpp | 3 | ||||
-rw-r--r-- | engines/mutationofjb/game.cpp | 17 | ||||
-rw-r--r-- | engines/mutationofjb/game.h | 9 | ||||
-rw-r--r-- | engines/mutationofjb/module.mk | 1 | ||||
-rw-r--r-- | engines/mutationofjb/script.cpp | 15 | ||||
-rw-r--r-- | engines/mutationofjb/script.h | 2 |
9 files changed, 189 insertions, 3 deletions
diff --git a/engines/mutationofjb/commands/additemcommand.h b/engines/mutationofjb/commands/additemcommand.h index 4e2ea2b692..d740d35c05 100644 --- a/engines/mutationofjb/commands/additemcommand.h +++ b/engines/mutationofjb/commands/additemcommand.h @@ -32,7 +32,7 @@ class AddItemCommandParser : public SeqCommandParser { public: AddItemCommandParser() {} - virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command); + virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override; }; class AddItemCommand : public SeqCommand { diff --git a/engines/mutationofjb/commands/callmacrocommand.cpp b/engines/mutationofjb/commands/callmacrocommand.cpp new file mode 100644 index 0000000000..b1c59eba21 --- /dev/null +++ b/engines/mutationofjb/commands/callmacrocommand.cpp @@ -0,0 +1,85 @@ +/* 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/callmacrocommand.h" +#include "mutationofjb/script.h" +#include "mutationofjb/game.h" +#include "common/translation.h" + +/* + "_" <name> + + Calls macro with the specified name. +*/ + +namespace MutationOfJB { + +bool CallMacroCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) { + if (line.size() < 2 || line.firstChar() != '_') { + return false; + } + + const Common::String macroName = line.c_str() + 1; + command = new CallMacroCommand(macroName); + return true; +} + +void CallMacroCommandParser::transition(ScriptParseContext &, Command *oldCommand, Command *newCommand, CommandParser *) { + if (!oldCommand || !newCommand) { + warning(_("Unexpected empty command in transition")); + return; + } + + static_cast<CallMacroCommand *>(oldCommand)->setReturnCommand(newCommand); +} + + +void CallMacroCommand::setReturnCommand(Command *cmd) { + _returnCommand = cmd; +} + +Command *CallMacroCommand::getReturnCommand() const { + return _returnCommand; +} + +Command::ExecuteResult CallMacroCommand::execute(ScriptExecutionContext &scriptExecCtx) { + Game &game = scriptExecCtx.getGame(); + _callCommand = game.getMacro(_macroName); + if (_callCommand) { + scriptExecCtx.pushReturnCommand(_returnCommand); + } else { + warning("Macro '%s' not found.", _macroName.c_str()); + } + + return Finished; +} + +Command *CallMacroCommand::next() const { + return _callCommand; +} + +Common::String CallMacroCommand::debugString() const { + return Common::String::format("CALL '%s'", _macroName.c_str()); +} + +} + diff --git a/engines/mutationofjb/commands/callmacrocommand.h b/engines/mutationofjb/commands/callmacrocommand.h new file mode 100644 index 0000000000..0486bcd4d5 --- /dev/null +++ b/engines/mutationofjb/commands/callmacrocommand.h @@ -0,0 +1,58 @@ +/* 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_CALLMACROCOMMAND_H +#define MUTATIONOFJB_CALLMACROCOMMAND_H + +#include "mutationofjb/commands/command.h" +#include "common/scummsys.h" +#include "common/str.h" + +namespace MutationOfJB { + +class CallMacroCommandParser : public CommandParser { +public: + CallMacroCommandParser() {} + + virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override; + virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser) override; +}; + +class CallMacroCommand : public Command { +public: + CallMacroCommand(const Common::String ¯oName) : _macroName(macroName), _returnCommand(nullptr), _callCommand(nullptr) {} + void setReturnCommand(Command *); + + Command *getReturnCommand() const; + + virtual ExecuteResult execute(ScriptExecutionContext &scriptExecCtx) override; + Command *next() const override; + virtual Common::String debugString() const override; +private: + Common::String _macroName; + Command *_returnCommand; + Command *_callCommand; +}; + +} + +#endif diff --git a/engines/mutationofjb/debug.cpp b/engines/mutationofjb/debug.cpp index 867a0210a6..b4c2e773a8 100644 --- a/engines/mutationofjb/debug.cpp +++ b/engines/mutationofjb/debug.cpp @@ -27,6 +27,7 @@ #include "mutationofjb/commands/command.h" #include "mutationofjb/commands/seqcommand.h" #include "mutationofjb/commands/conditionalcommand.h" +#include "mutationofjb/commands/callmacrocommand.h" #include "common/debug-channels.h" #include "common/translation.h" #include "common/scummsys.h" @@ -129,6 +130,8 @@ void Console::showCommands(Command *command, int indentLevel) { debugPrintf("ELSE\n"); showCommands(condCmd->getFalseCommand(), indentLevel + 1); command = nullptr; + } else if (CallMacroCommand* const callMacroCmd = dynamic_cast<CallMacroCommand *>(command)) { + command = callMacroCmd->getReturnCommand(); } else { command = nullptr; } diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp index 397b86c237..047971b83d 100644 --- a/engines/mutationofjb/game.cpp +++ b/engines/mutationofjb/game.cpp @@ -28,10 +28,11 @@ #include "mutationofjb/script.h" #include "mutationofjb/util.h" #include "common/util.h" +#include "common/str.h" namespace MutationOfJB { -Game::Game(MutationOfJBEngine* vm) : _vm(vm) { +Game::Game(MutationOfJBEngine *vm) : _vm(vm) { _gameData = new GameData; loadGameData(false); @@ -104,4 +105,18 @@ void Game::changeScene(uint8 sceneId, bool partB) { scriptFile.close(); } +Command *Game::getMacro(const Common::String &name) const { + Command *cmd = nullptr; + + if (_localScript) { + cmd = _localScript->getMacro(name); + } + + if (!cmd && _globalScript) { + cmd = _globalScript->getMacro(name); + } + + return cmd; +} + } diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h index 4b4ab43343..5ed65f1b51 100644 --- a/engines/mutationofjb/game.h +++ b/engines/mutationofjb/game.h @@ -25,8 +25,13 @@ #include "common/scummsys.h" +namespace Common { +class String; +} + namespace MutationOfJB { +class Command; class MutationOfJBEngine; class GameData; class Script; @@ -34,7 +39,7 @@ class Room; class Game { public: - Game(MutationOfJBEngine* vm); + Game(MutationOfJBEngine *vm); GameData &getGameData(); Script *getGlobalScript() const; @@ -42,6 +47,8 @@ public: void changeScene(uint8 sceneId, bool partB); + Command *getMacro(const Common::String &name) const; + private: bool loadGameData(bool partB); diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk index a81e2a3b62..447f9a920c 100644 --- a/engines/mutationofjb/module.mk +++ b/engines/mutationofjb/module.mk @@ -2,6 +2,7 @@ MODULE := engines/mutationofjb MODULE_OBJS := \ commands/additemcommand.o \ + commands/callmacrocommand.o \ commands/camefromcommand.o \ commands/changecommand.o \ commands/command.o \ diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp index 699daeb6c3..1291bd8d97 100644 --- a/engines/mutationofjb/script.cpp +++ b/engines/mutationofjb/script.cpp @@ -39,6 +39,7 @@ #include "mutationofjb/commands/labelcommand.h" #include "mutationofjb/commands/gotocommand.h" #include "mutationofjb/commands/camefromcommand.h" +#include "mutationofjb/commands/callmacrocommand.h" #include "mutationofjb/game.h" namespace MutationOfJB { @@ -49,6 +50,7 @@ static CommandParser **getParsers() { new IfItemCommandParser, new IfCommandParser, new CameFromCommandParser, + new CallMacroCommandParser, new EndBlockCommandParser, new ChangeDoorCommandParser, new ChangeObjectCommandParser, @@ -109,6 +111,10 @@ Command *ScriptExecutionContext::popReturnCommand() { return _stack.pop(); } +Game &ScriptExecutionContext::getGame() { + return _game; +} + GameData &ScriptExecutionContext::getGameData() { return _game.getGameData(); } @@ -206,4 +212,13 @@ const Macros &Script::getMacros() const { return _macros; } +Command *Script::getMacro(const Common::String &name) const { + Macros::const_iterator it = _macros.find(name); + if (it == _macros.end()) { + return nullptr; + } + + return it->_value; +} + } diff --git a/engines/mutationofjb/script.h b/engines/mutationofjb/script.h index 477181b445..940a274c29 100644 --- a/engines/mutationofjb/script.h +++ b/engines/mutationofjb/script.h @@ -99,6 +99,7 @@ public: ScriptExecutionContext(Game &game) : _game(game) {} void pushReturnCommand(Command *); Command *popReturnCommand(); + Game &getGame(); GameData &getGameData(); private: @@ -116,6 +117,7 @@ public: const ActionInfos &getTalkActionInfos() const; const ActionInfos &getUseActionInfos() const; const Macros &getMacros() const; + Command *getMacro(const Common::String &name) const; private: void destroy(); |