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 /engines/mutationofjb/commands | |
parent | e1d173ed7541f9da79f60a65d974da3ebbb29e7a (diff) | |
download | scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.tar.gz scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.tar.bz2 scummvm-rg350-938f222d4857b45e0f1f7e4726040ab0bf1d9b67.zip |
MUTATIONOFJB: Add support for calling macros.
Diffstat (limited to 'engines/mutationofjb/commands')
-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 |
3 files changed, 144 insertions, 1 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 |