diff options
author | Ľubomír Remák | 2018-02-22 23:47:16 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | f7d5a825a053199ddbf4d7c564e84e9f9709d958 (patch) | |
tree | ceb20f74e8a40ae8553f5d06a24139aa21813714 /engines/mutationofjb/commands | |
parent | 356a6809c31224f4ed2bfcc5e6bacd131f144026 (diff) | |
download | scummvm-rg350-f7d5a825a053199ddbf4d7c564e84e9f9709d958.tar.gz scummvm-rg350-f7d5a825a053199ddbf4d7c564e84e9f9709d958.tar.bz2 scummvm-rg350-f7d5a825a053199ddbf4d7c564e84e9f9709d958.zip |
MUTATIONOFJB: Start implementation of ATN scripts (IF command).
Diffstat (limited to 'engines/mutationofjb/commands')
-rw-r--r-- | engines/mutationofjb/commands/command.cpp | 33 | ||||
-rw-r--r-- | engines/mutationofjb/commands/command.h | 58 | ||||
-rw-r--r-- | engines/mutationofjb/commands/conditionalcommand.cpp | 41 | ||||
-rw-r--r-- | engines/mutationofjb/commands/conditionalcommand.h | 41 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.cpp | 88 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.h | 52 | ||||
-rw-r--r-- | engines/mutationofjb/commands/seqcommand.cpp | 40 | ||||
-rw-r--r-- | engines/mutationofjb/commands/seqcommand.h | 44 |
8 files changed, 397 insertions, 0 deletions
diff --git a/engines/mutationofjb/commands/command.cpp b/engines/mutationofjb/commands/command.cpp new file mode 100644 index 0000000000..d0b3f826e3 --- /dev/null +++ b/engines/mutationofjb/commands/command.cpp @@ -0,0 +1,33 @@ +/* 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/command.h" +#include "common/scummsys.h" + +namespace MutationOfJB { +Command::~Command() {} + +SeqCommand *Command::asSeqCommand() { + return nullptr; +} + +} diff --git a/engines/mutationofjb/commands/command.h b/engines/mutationofjb/commands/command.h new file mode 100644 index 0000000000..beae9d2833 --- /dev/null +++ b/engines/mutationofjb/commands/command.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_COMMAND_H +#define MUTATIONOFJB_COMMAND_H + +namespace Common { + class String; +} + +namespace MutationOfJB { + +class GameData; +class SeqCommand; +class IfCommand; +class CallMacroCommand; +class ScriptParseContext; +class Command; + +typedef bool (*CommandParseFunc)(const Common::String &line, ScriptParseContext &parseContext, Command *&command); + +class Command { +public: + enum ExecuteResult { + None, + Finished, + InProgress + }; + + virtual ~Command(); + + virtual ExecuteResult execute(GameData &gameData) = 0; + virtual Command *next() const = 0; + + virtual SeqCommand *asSeqCommand(); +}; +} + +#endif diff --git a/engines/mutationofjb/commands/conditionalcommand.cpp b/engines/mutationofjb/commands/conditionalcommand.cpp new file mode 100644 index 0000000000..3118e6d8cb --- /dev/null +++ b/engines/mutationofjb/commands/conditionalcommand.cpp @@ -0,0 +1,41 @@ +/* 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/conditionalcommand.h" +#include "common/scummsys.h" + +namespace MutationOfJB { + +ConditionalCommand::ConditionalCommand() : + _trueCommand(nullptr), + _falseCommand(nullptr), + _cachedResult(false) +{} + +Command *ConditionalCommand::next() const { + if (_cachedResult) { + return _trueCommand; + } else { + return _falseCommand; + } +} +}; diff --git a/engines/mutationofjb/commands/conditionalcommand.h b/engines/mutationofjb/commands/conditionalcommand.h new file mode 100644 index 0000000000..e355662454 --- /dev/null +++ b/engines/mutationofjb/commands/conditionalcommand.h @@ -0,0 +1,41 @@ +/* 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/command.h" +#include "common/scummsys.h" + +namespace MutationOfJB { + +class ConditionalCommand : public Command { +public: + ConditionalCommand(); + void setTrueCommand(Command *command); + void setFalseCommand(Command *command); + + virtual Command *next() const override; +protected: + Command *_trueCommand; + Command *_falseCommand; + bool _cachedResult; +}; + +} diff --git a/engines/mutationofjb/commands/ifcommand.cpp b/engines/mutationofjb/commands/ifcommand.cpp new file mode 100644 index 0000000000..18b8081842 --- /dev/null +++ b/engines/mutationofjb/commands/ifcommand.cpp @@ -0,0 +1,88 @@ +/* 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/ifcommand.h" +#include "mutationofjb/game.h" +#include "mutationofjb/script.h" +#include "common/str.h" +#include "common/translation.h" + +namespace MutationOfJB { + +bool IfCommand::ParseFunc(const Common::String &line, ScriptParseContext &parseContext, Command *&command) +{ + // IFtss oo val! + // <t> 1B Tag. + // <ss> 2B Scene. + // <oo> 2B Object ID. + // <val> VL Value. + // ! 1B Negation (optional). + + if (line.size() < 10) { + return false; + } + + if (strncmp(line.c_str(), "IF", 2) != 0) { + return false; + } + + const char *const cstr = line.c_str(); + const char tag = cstr[2]; + const uint8 sceneId = atoi(cstr + 3); + const uint8 objectId = atoi(cstr + 6); + const uint8 value = atoi(cstr + 9); + const bool negative = (line.lastChar() == '!'); + + IfCommand *ifCommand = new IfCommand(sceneId, objectId, value, negative); + + command = ifCommand; + parseContext.addConditionalCommand(ifCommand, tag); + return true; +} + +IfCommand::IfCommand(uint8 sceneId, uint8 objectId, uint16 value, bool negative) : + _sceneId(sceneId), + _objectId(objectId), + _value(value), + _negative(negative) +{} + +Command::ExecuteResult IfCommand::execute(GameData &gameData) { + Scene* const scene = gameData.getScene(_sceneId); + if (!scene) { + return Finished; + } + + Object* const object = scene->getObject(_objectId); + if (!object) { + return Finished; + } + + _cachedResult = (object->_WX == _value); + if (_negative) { + _cachedResult = !_cachedResult; + } + + return Finished; +} +} + diff --git a/engines/mutationofjb/commands/ifcommand.h b/engines/mutationofjb/commands/ifcommand.h new file mode 100644 index 0000000000..d33f34ffb0 --- /dev/null +++ b/engines/mutationofjb/commands/ifcommand.h @@ -0,0 +1,52 @@ +/* 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_IFCOMMAND_H +#define MUTATIONOFJB_IFCOMMAND_H + +#include "mutationofjb/commands/conditionalcommand.h" +#include "common/scummsys.h" + +namespace MutationOfJB { + +class ScriptParseContext; + +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; + +private: + uint8 _sceneId; + uint8 _objectId; + uint16 _value; + bool _negative; + + bool _cachedResult; +}; + +} + +#endif diff --git a/engines/mutationofjb/commands/seqcommand.cpp b/engines/mutationofjb/commands/seqcommand.cpp new file mode 100644 index 0000000000..ab98497f21 --- /dev/null +++ b/engines/mutationofjb/commands/seqcommand.cpp @@ -0,0 +1,40 @@ +/* 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 "seqcommand.h" + +namespace MutationOfJB { + +void SeqCommand::setNextCommand(Command *nextCommand) +{ + _nextCommand = nextCommand; +} + +Command *SeqCommand::next() const { + return _nextCommand; +} + +SeqCommand *SeqCommand::asSeqCommand() { + return this; +} + +} diff --git a/engines/mutationofjb/commands/seqcommand.h b/engines/mutationofjb/commands/seqcommand.h new file mode 100644 index 0000000000..b247fb22e1 --- /dev/null +++ b/engines/mutationofjb/commands/seqcommand.h @@ -0,0 +1,44 @@ +/* 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_SEQCOMMAND_H +#define MUTATIONOFJB_SEQCOMMAND_H + +#include "mutationofjb/commands/command.h" +#include "common/scummsys.h" + +namespace MutationOfJB { + +class SeqCommand : public Command { +public: + void setNextCommand(Command *nextCommand); + virtual Command *next() const override; + virtual SeqCommand *asSeqCommand(); + +private: + Command *_nextCommand; +}; + +} + +#endif + |