1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/* ResidualVM - A 3D game interpreter
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* 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 "engines/stark/services/diary.h"
#include "engines/stark/services/global.h"
#include "engines/stark/services/services.h"
#include "engines/stark/services/stateprovider.h"
namespace Stark {
Diary::Diary() {
clear();
}
Diary::~Diary() {}
void Diary::clear() {
_diaryEntries.clear();
_fmvEntries.clear();
_hasUnreadEntries = false;
_pageIndex = 0;
}
void Diary::addDiaryEntry(const Common::String &name) {
_diaryEntries.push_back(name);
_hasUnreadEntries = true;
}
void Diary::addFMVEntry(const Common::String &filename, const Common::String &title, int gameDisc) {
if (!hasFMVEntry(filename)) {
FMVEntry entry;
entry.filename = filename;
entry.title = title;
entry.gameDisc = gameDisc;
_fmvEntries.push_back(entry);
}
}
bool Diary::hasFMVEntry(const Common::String &filename) const {
for (uint i = 0; i < _fmvEntries.size(); i++) {
if (_fmvEntries[i].filename == filename) {
return true;
}
}
return false;
}
void Diary::readStateFromStream(Common::SeekableReadStream *stream, uint32 version) {
clear();
if (version <= 6) {
return; //Early save versions did not persist the diary
}
ResourceSerializer serializer(stream, nullptr, version);
saveLoad(&serializer);
}
void Diary::writeStateToStream(Common::WriteStream *stream) {
ResourceSerializer serializer(nullptr, stream, StateProvider::kSaveVersion);
saveLoad(&serializer);
}
void Diary::saveLoad(ResourceSerializer *serializer) {
// Diary entries
serializer->syncArraySize(_diaryEntries);
for (uint i = 0; i < _diaryEntries.size(); i++) {
serializer->syncAsString32(_diaryEntries[i]);
}
// FMV entries
serializer->syncArraySize(_fmvEntries);
for (uint i = 0; i < _fmvEntries.size(); i++) {
serializer->syncAsString32(_fmvEntries[i].filename);
serializer->syncAsString32(_fmvEntries[i].title);
serializer->syncAsUint32LE(_fmvEntries[i].gameDisc);
}
// Conversations
serializer->syncArraySize(_conversationEntries, 8);
for (uint i = 0; i < _conversationEntries.size(); i++) {
ConversationLog &entry = _conversationEntries[i];
serializer->syncAsSint32LE(entry.chapter);
serializer->syncAsSint32LE(entry.characterId);
serializer->syncAsString32(entry.characterName);
serializer->syncAsString32(entry.title);
serializer->syncArraySize(entry.lines);
for (uint j = 0; j < entry.lines.size(); j++) {
ConversationLogLine &logLine = entry.lines[j];
serializer->syncAsString32(logLine.line);
serializer->syncAsSint32LE(logLine.characterId);
}
}
// Misc
serializer->syncAsByte(_hasUnreadEntries);
serializer->syncAsUint32LE(_pageIndex);
}
void Diary::openDialog(const Common::String &title, const Common::String &characterName, int32 characterId) {
// Reuse the previous dialog if it has the same title
if (_conversationEntries.empty() || _conversationEntries.back().title != title) {
ConversationLog conversation;
conversation.title = title;
conversation.characterName = characterName;
conversation.characterId = characterId;
conversation.chapter = StarkGlobal->getCurrentChapter();
_conversationEntries.push_back(conversation);
}
_conversationEntries.back().dialogActive = true;
}
void Diary::closeDialog() {
if (!_conversationEntries.empty()) {
_conversationEntries.back().dialogActive = false;
}
}
void Diary::logSpeech(const Common::String &line, int32 characterId) {
ConversationLog &conversationLog = _conversationEntries.back();
if (conversationLog.dialogActive) {
ConversationLogLine logLine;
logLine.line = line;
logLine.characterId = characterId;
conversationLog.lines.push_back(logLine);
}
}
Diary::ConversationLog::ConversationLog() :
dialogActive(false),
chapter(0),
characterId(0) {
}
Diary::ConversationLogLine::ConversationLogLine() :
characterId(0) {
}
} // End of namespace Stark
|