Permalink
Browse files

MUTATIONOFJB: Basic conversation support.

  • Loading branch information...
LubomirR authored and sev- committed Jul 8, 2018
1 parent f102667 commit 20d6d71ec97c1f7bc4b95ed6c98375b47dff6646
@@ -0,0 +1,45 @@
/* 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/assets.h"

namespace MutationOfJB {

Assets::Assets(Game &game) : _game(game), _toSayList("tosay.ger"), _responseList("response.ger") {}

Font& Assets::getSystemFont() {
return _systemFont;
}

Font& Assets::getSpeechFont() {
return _speechFont;
}

ConversationLineList &Assets::getToSayList() {
return _toSayList;
}

ConversationLineList &Assets::getResponseList() {
return _responseList;
}

}
@@ -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_ASSETS_H
#define MUTATIONOFJB_ASSETS_H

#include "mutationofjb/font.h"
#include "mutationofjb/conversationlinelist.h"

namespace MutationOfJB {

class Game;

class Assets {
public:
Assets(Game &game);

Font& getSystemFont();
Font& getSpeechFont();

ConversationLineList& getToSayList();
ConversationLineList& getResponseList();

private:
Game &_game;
SystemFont _systemFont;
SpeechFont _speechFont;
ConversationLineList _toSayList;
ConversationLineList _responseList;
};

}

#endif
@@ -33,7 +33,7 @@ class ScriptParseContext;

class IfItemCommandParser : public ConditionalCommandParser {
public:
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override;
};

class IfItemCommand : public ConditionalCommand {
@@ -0,0 +1,76 @@
/* 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/talkcommand.h"
#include "mutationofjb/tasks/conversationtask.h"
#include "mutationofjb/script.h"
#include "mutationofjb/game.h"
#include "common/str.h"

namespace MutationOfJB {

bool TalkCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) {
if (line.size() < 11 || !line.hasPrefix("TALK TO HIM")) {
return false;
}

int modeInt = 0;

if (line.size() >= 13) {
modeInt = atoi(line.c_str() + 12);
}

TalkCommand::Mode mode = TalkCommand::NORMAL_MODE;

if (modeInt == 1) {
mode = TalkCommand::RAY_AND_BUTTLEG_MODE;
} else if (modeInt == 3) {
mode = TalkCommand::CARNIVAL_TICKET_SELLER_MODE;
}

command = new TalkCommand(mode);
return true;
}

Command::ExecuteResult TalkCommand::execute(ScriptExecutionContext &scriptExeCtx) {
if (!_task) {
_task = new ConversationTask(scriptExeCtx.getGame().getGameData()._conversationInfo);
scriptExeCtx.getGame().getTaskManager().addTask(_task);
}

if (_task->getState() == Task::FINISHED) {
scriptExeCtx.getGame().getTaskManager().removeTask(_task);
delete _task;
_task = nullptr;

return Command::Finished;
}

return Command::InProgress;
}

Common::String TalkCommand::debugString() const {
const char * modes[] = {"NORMAL", "RAY_AND_BUTTLEG", "CARNIVAL_TICKET_SELLER"};
return Common::String::format("TALK %s", modes[(int) _mode]);
}

}
@@ -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.
*
*/

#ifndef MUTATIONOFJB_TALKCOMMAND_H
#define MUTATIONOFJB_TALKCOMMAND_H

#include "mutationofjb/commands/seqcommand.h"
#include "common/scummsys.h"

namespace MutationOfJB {

class ConversationTask;

class TalkCommandParser : public SeqCommandParser {
public:
virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override;
};

class TalkCommand : public SeqCommand {
public:
enum Mode {
NORMAL_MODE,
RAY_AND_BUTTLEG_MODE,
CARNIVAL_TICKET_SELLER_MODE
};

TalkCommand(Mode mode) : _mode(mode), _task(nullptr) {}
virtual ExecuteResult execute(ScriptExecutionContext &scriptExecCtx) override;
virtual Common::String debugString() const;

private:
Mode _mode;
ConversationTask *_task;
};

}

#endif
@@ -0,0 +1,91 @@
/* 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/conversationlinelist.h"
#include "mutationofjb/encryptedfile.h"
#include "mutationofjb/util.h"

namespace MutationOfJB {

ConversationLineList::ConversationLineList(const Common::String &fileName) {
parseFile(fileName);
}

const ConversationLineList::Line *ConversationLineList::getLine(uint index) const {
if (index > _lines.size()) {
return nullptr;
}

return &_lines[index - 1];
}

bool ConversationLineList::parseFile(const Common::String &fileName) {
EncryptedFile file;
file.open(fileName);
if (!file.isOpen()) {
reportFileMissingError(fileName.c_str());
return false;
}

while (!file.eos()) {
Common::String lineStr = file.readLine();
if (lineStr.empty()) {
continue;
}

Line line;

Common::String::iterator endIt = Common::find(lineStr.begin(), lineStr.end(), '|');
if (endIt != lineStr.end()) {
Common::String extra = lineStr + endIt;
if (*endIt == 'X') {
line._extra = Common::String(endIt + 1, lineStr.end()); // Skip 'X' char.
}
}

Common::String::iterator startSpeechIt = lineStr.begin();
Common::String::iterator endSpeechIt = startSpeechIt;

while (startSpeechIt < endIt) {
endSpeechIt = Common::find(startSpeechIt, endIt, '\\');
Common::String::iterator voiceFileIt = Common::find(startSpeechIt, endSpeechIt, '<');
Speech speech;

if (voiceFileIt != endSpeechIt) {
if (*voiceFileIt == 'S') {
speech._voiceFile = Common::String(voiceFileIt + 1, endSpeechIt);
}
}

speech._text = Common::String(startSpeechIt, voiceFileIt);
line._speeches.push_back(speech);

startSpeechIt = endSpeechIt + 1;
}

_lines.push_back(line);
}

return true;
}

}
@@ -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_CONVERSATIONLINELIST_H
#define MUTATIONOFJB_CONVERSATIONLINELIST_H

#include "common/str.h"
#include "common/array.h"

namespace MutationOfJB {

class ConversationLineList {
public:
struct Speech {
Common::String _text;
Common::String _voiceFile;

bool isRepeating() const { return _text.firstChar() == '*'; }
bool isFirstSpeaker() const { return _text.firstChar() == '~'; }
bool isSecondSpeaker() const { return _text.firstChar() == '`'; }
};

struct Line {
Common::Array<Speech> _speeches;
Common::String _extra;
};

ConversationLineList(const Common::String &fileName);
const Line *getLine(uint index) const;

private:
bool parseFile(const Common::String &fileName);

Common::Array<Line> _lines;
};

}

#endif
Oops, something went wrong.

0 comments on commit 20d6d71

Please sign in to comment.