Permalink
Browse files

MUTATIONOFJB: Start implementation of ATN scripts (IF command).

  • Loading branch information...
LubomirR authored and sev- committed Feb 22, 2018
1 parent 356a680 commit f7d5a825a053199ddbf4d7c564e84e9f9709d958
@@ -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;
}

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

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

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

}
Oops, something went wrong.

0 comments on commit f7d5a82

Please sign in to comment.