ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

diary.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/services/diary.h"
00024 
00025 #include "engines/stark/services/global.h"
00026 #include "engines/stark/services/services.h"
00027 #include "engines/stark/services/stateprovider.h"
00028 #include "engines/stark/services/userinterface.h"
00029 
00030 namespace Stark {
00031 
00032 Diary::Diary() {
00033     clear();
00034 }
00035 
00036 Diary::~Diary() {}
00037 
00038 void Diary::clear() {
00039     _diaryEntries.clear();
00040     _fmvEntries.clear();
00041     _conversationEntries.clear();
00042     _hasUnreadEntries = false;
00043     _pageIndex = 0;
00044 }
00045 
00046 void Diary::addDiaryEntry(const Common::String &name) {
00047     _diaryEntries.push_back(name);
00048     _hasUnreadEntries = true;
00049     StarkUserInterface->notifyDiaryEntryEnabled();
00050 }
00051 
00052 void Diary::addFMVEntry(const Common::String &filename, const Common::String &title, int gameDisc) {
00053     if (!hasFMVEntry(filename)) {
00054         FMVEntry entry;
00055         entry.filename = filename;
00056         entry.title = title;
00057         entry.gameDisc = gameDisc;
00058         _fmvEntries.push_back(entry);
00059     }
00060 }
00061 
00062 bool Diary::hasFMVEntry(const Common::String &filename) const {
00063     for (uint i = 0; i < _fmvEntries.size(); i++) {
00064         if (_fmvEntries[i].filename == filename) {
00065             return true;
00066         }
00067     }
00068 
00069     return false;
00070 }
00071 
00072 void Diary::readStateFromStream(Common::SeekableReadStream *stream, uint32 version) {
00073     clear();
00074 
00075     if (version <= 6) {
00076         return; //Early save versions did not persist the diary
00077     }
00078 
00079     ResourceSerializer serializer(stream, nullptr, version);
00080     saveLoad(&serializer);
00081 }
00082 
00083 void Diary::writeStateToStream(Common::WriteStream *stream) {
00084     ResourceSerializer serializer(nullptr, stream, StateProvider::kSaveVersion);
00085     saveLoad(&serializer);
00086 }
00087 
00088 void Diary::saveLoad(ResourceSerializer *serializer) {
00089     // Diary entries
00090     serializer->syncArraySize(_diaryEntries);
00091     for (uint i = 0; i < _diaryEntries.size(); i++) {
00092         serializer->syncAsString32(_diaryEntries[i]);
00093     }
00094 
00095     // FMV entries
00096     serializer->syncArraySize(_fmvEntries);
00097     for (uint i = 0; i < _fmvEntries.size(); i++) {
00098         serializer->syncAsString32(_fmvEntries[i].filename);
00099         serializer->syncAsString32(_fmvEntries[i].title);
00100         serializer->syncAsUint32LE(_fmvEntries[i].gameDisc);
00101     }
00102 
00103     // Conversations
00104     serializer->syncArraySize(_conversationEntries, 8);
00105     for (uint i = 0; i < _conversationEntries.size(); i++) {
00106         ConversationLog &entry = _conversationEntries[i];
00107         serializer->syncAsSint32LE(entry.chapter);
00108         serializer->syncAsSint32LE(entry.characterId);
00109         serializer->syncAsString32(entry.characterName);
00110         serializer->syncAsString32(entry.title);
00111 
00112         serializer->syncArraySize(entry.lines);
00113         for (uint j = 0; j < entry.lines.size(); j++) {
00114             ConversationLogLine &logLine = entry.lines[j];
00115             serializer->syncAsString32(logLine.line);
00116             serializer->syncAsSint32LE(logLine.characterId);
00117         }
00118     }
00119 
00120     // Misc
00121     serializer->syncAsByte(_hasUnreadEntries);
00122     serializer->syncAsUint32LE(_pageIndex);
00123 }
00124 
00125 void Diary::openDialog(const Common::String &title, const Common::String &characterName, int32 characterId) {
00126     // Reuse the previous dialog if it has the same title
00127     if (_conversationEntries.empty() || _conversationEntries.back().title != title) {
00128         ConversationLog conversation;
00129         conversation.title = title;
00130         conversation.characterName = characterName;
00131         conversation.characterId = characterId;
00132         conversation.chapter = StarkGlobal->getCurrentChapter();
00133         _conversationEntries.push_back(conversation);
00134     }
00135 
00136     _conversationEntries.back().dialogActive = true;
00137 }
00138 
00139 void Diary::closeDialog() {
00140     if (!_conversationEntries.empty()) {
00141         _conversationEntries.back().dialogActive = false;
00142     }
00143 }
00144 
00145 void Diary::logSpeech(const Common::String &line, int32 characterId) {
00146     ConversationLog &conversationLog = _conversationEntries.back();
00147     if (conversationLog.dialogActive) {
00148         ConversationLogLine logLine;
00149         logLine.line = line;
00150         logLine.characterId = characterId;
00151 
00152         conversationLog.lines.push_back(logLine);
00153     }
00154 }
00155 
00156 bool Diary::isEnabled() const {
00157     return StarkGlobal->getInventory() && StarkGlobal->hasInventoryItem("Diary");
00158 }
00159 
00160 bool Diary::hasUnreadEntries() const {
00161     return _hasUnreadEntries;
00162 }
00163 
00164 Diary::ConversationLog::ConversationLog() :
00165         dialogActive(false),
00166         chapter(0),
00167         characterId(0) {
00168 }
00169 
00170 Diary::ConversationLogLine::ConversationLogLine() :
00171         characterId(0) {
00172 }
00173 
00174 } // End of namespace Stark


Generated on Sat Dec 7 2019 05:00:39 for ResidualVM by doxygen 1.7.1
curved edge   curved edge