Permalink
Browse files

MUTATIONOFJB: Add support for CAMEFROM command.

  • Loading branch information...
LubomirR authored and sev- committed Mar 21, 2018
1 parent 7a081f0 commit 3928c52c0ee2a930431a807d0b4262440ab75725
@@ -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);
}

}
@@ -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

@@ -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() {}
@@ -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);
}

@@ -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 {
@@ -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()) {
@@ -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;
@@ -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());
}
@@ -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);

@@ -171,6 +171,7 @@ Static *Scene::getStatic(uint8 staticId) {

GameData::GameData()
: _currentScene(0),
_lastScene(0),
_partB(false) {}

Scene *GameData::getScene(uint8 sceneId) {
@@ -152,6 +152,7 @@ struct GameData {
bool loadFromStream(Common::ReadStream &stream);

uint8 _currentScene;
uint8 _lastScene;
bool _partB;
Inventory _inventory;
Common::String _currentAPK;
@@ -2,6 +2,7 @@ MODULE := engines/mutationofjb

MODULE_OBJS := \
commands/additemcommand.o \
commands/camefromcommand.o \
commands/changecommand.o \
commands/command.o \
commands/conditionalcommand.o \
@@ -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);
}

@@ -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 @@ class ScriptParseContext {
struct ConditionalCommandInfo {
ConditionalCommand *_command;
char _tag;
bool _firstHash;
};
typedef Common::Array<ConditionalCommandInfo> ConditionalCommandInfos;
ConditionalCommandInfos _pendingCondCommands;

0 comments on commit 3928c52

Please sign in to comment.