diff options
author | Ľubomír Remák | 2018-03-11 00:46:44 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | ae979a831091e04797f19d0c80210d745cd60f62 (patch) | |
tree | 988ab239c438bca49b1585ff2befc5a4aba64bb5 /engines/mutationofjb/commands | |
parent | fa9c8be1292e1f0174454193807f39b5c3ee52bf (diff) | |
download | scummvm-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.
Diffstat (limited to 'engines/mutationofjb/commands')
-rw-r--r-- | engines/mutationofjb/commands/conditionalcommand.cpp | 14 | ||||
-rw-r--r-- | engines/mutationofjb/commands/conditionalcommand.h | 7 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.cpp | 19 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.h | 8 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifitemcommand.cpp | 90 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifitemcommand.h | 53 |
6 files changed, 171 insertions, 20 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 |