From 7de123d6a1ea76752c92d692e292fa2e5cd5aba5 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 11 Jan 2015 15:57:04 +0100 Subject: [PATCH] STARK: Allow retrieving the current chapter --- engines/stark/module.mk | 2 + engines/stark/resources/knowledgeset.cpp | 39 +++++++++++++++++ engines/stark/resources/knowledgeset.h | 55 ++++++++++++++++++++++++ engines/stark/resources/script.cpp | 4 +- engines/stark/services/global.cpp | 46 ++++++++++++++++++++ engines/stark/services/global.h | 13 +++--- engines/stark/xrcreader.cpp | 4 ++ 7 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 engines/stark/resources/knowledgeset.cpp create mode 100644 engines/stark/resources/knowledgeset.h create mode 100644 engines/stark/services/global.cpp diff --git a/engines/stark/module.mk b/engines/stark/module.mk index 50aa4f64de4..7310628fe06 100644 --- a/engines/stark/module.mk +++ b/engines/stark/module.mk @@ -25,6 +25,7 @@ MODULE_OBJS := \ resources/image.o \ resources/item.o \ resources/knowledge.o \ + resources/knowledgeset.o \ resources/layer.o \ resources/level.o \ resources/location.o \ @@ -37,6 +38,7 @@ MODULE_OBJS := \ scene.o \ services/archiveloader.o \ services/dialogplayer.o \ + services/global.o \ services/resourceprovider.o \ services/services.o \ services/stateprovider.o \ diff --git a/engines/stark/resources/knowledgeset.cpp b/engines/stark/resources/knowledgeset.cpp new file mode 100644 index 00000000000..428a4284a91 --- /dev/null +++ b/engines/stark/resources/knowledgeset.cpp @@ -0,0 +1,39 @@ +/* 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/resources/knowledgeset.h" +#include "engines/stark/xrcreader.h" + +namespace Stark { + +KnowledgeSet::~KnowledgeSet() { +} + +KnowledgeSet::KnowledgeSet(Resource *parent, byte subType, uint16 index, const Common::String &name) : + Resource(parent, subType, index, name) { + _type = TYPE; +} + +void KnowledgeSet::printData() { +} + +} // End of namespace Stark diff --git a/engines/stark/resources/knowledgeset.h b/engines/stark/resources/knowledgeset.h new file mode 100644 index 00000000000..4337086059d --- /dev/null +++ b/engines/stark/resources/knowledgeset.h @@ -0,0 +1,55 @@ +/* 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. + * + */ + +#ifndef STARK_RESOURCES_KNOWLEDGE_SET_H +#define STARK_RESOURCES_KNOWLEDGE_SET_H + +#include "common/str.h" + +#include "engines/stark/resources/resource.h" + +namespace Stark { + +class XRCReadStream; + +class KnowledgeSet : public Resource { +public: + static const ResourceType::Type TYPE = ResourceType::kKnowledgeSet; + + enum SubType { + kInventory = 1, + kState = 2, + kPersons = 3, + kLocations = 4, + kDiary = 5 + }; + + KnowledgeSet(Resource *parent, byte subType, uint16 index, const Common::String &name); + virtual ~KnowledgeSet(); + +protected: + void printData() override; +}; + +} // End of namespace Stark + +#endif // STARK_RESOURCES_KNOWLEDGE_SET_H diff --git a/engines/stark/resources/script.cpp b/engines/stark/resources/script.cpp index 9ad8a775d4b..bb59ce6eecb 100644 --- a/engines/stark/resources/script.cpp +++ b/engines/stark/resources/script.cpp @@ -110,6 +110,8 @@ bool Script::isEnabled() { } bool Script::shouldExecute(uint32 callMode) { + Global *global = StarkServices::instance().global; + if ((!isEnabled() && isOnBegin()) || !_nextCommand) { return false; // Don't execute disabled scripts } @@ -145,7 +147,7 @@ bool Script::shouldExecute(uint32 callMode) { return false; // Wrong script type } - uint32 currentChapter = 0; // TODO: Implement + uint32 currentChapter = global->getCurrentChapter(); if (currentChapter < _minChapter || currentChapter > _maxChapter) { return false; // Wrong chapter } diff --git a/engines/stark/services/global.cpp b/engines/stark/services/global.cpp new file mode 100644 index 00000000000..91c006905c3 --- /dev/null +++ b/engines/stark/services/global.cpp @@ -0,0 +1,46 @@ +/* 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/global.h" + +#include "engines/stark/resources/level.h" +#include "engines/stark/resources/knowledge.h" +#include "engines/stark/resources/knowledgeset.h" + +namespace Stark { + +Global::Global() : + _millisecondsPerGameloop(0), + _root(nullptr), + _level(nullptr), + _current(nullptr), + _debug(false), + _fastForward(false) { +} + +int32 Global::getCurrentChapter() { + KnowledgeSet *globalState = _level->findChildWithSubtype(KnowledgeSet::kState); + Knowledge *chapter = globalState->findChildWithIndex(0); + return chapter->getIntegerValue(); +} + +} // End of namespace Stark diff --git a/engines/stark/services/global.h b/engines/stark/services/global.h index 4650644df3b..03b00bbb3f8 100644 --- a/engines/stark/services/global.h +++ b/engines/stark/services/global.h @@ -23,6 +23,8 @@ #ifndef STARK_SERVICES_GLOBAL_H #define STARK_SERVICES_GLOBAL_H +#include "common/scummsys.h" + namespace Stark { class Camera; @@ -66,14 +68,7 @@ private: */ class Global { public: - Global() : - _millisecondsPerGameloop(0), - _root(nullptr), - _level(nullptr), - _current(nullptr), - _debug(false), - _fastForward(false) { - } + Global(); Root *getRoot() const { return _root; } Level *getLevel() const { return _level; } @@ -89,6 +84,8 @@ public: void setFastForward(bool fastForward) { _fastForward = fastForward; } void setMillisecondsPerGameloop(uint millisecondsPerGameloop) { _millisecondsPerGameloop = millisecondsPerGameloop; } + /** Retrieve the current chapter number from the global resource tree */ + int32 getCurrentChapter(); private: uint _millisecondsPerGameloop; Root *_root; diff --git a/engines/stark/xrcreader.cpp b/engines/stark/xrcreader.cpp index d76da017af9..112d49b0cce 100644 --- a/engines/stark/xrcreader.cpp +++ b/engines/stark/xrcreader.cpp @@ -37,6 +37,7 @@ #include "engines/stark/resources/floor.h" #include "engines/stark/resources/floorface.h" #include "engines/stark/resources/knowledge.h" +#include "engines/stark/resources/knowledgeset.h" #include "engines/stark/resources/layer.h" #include "engines/stark/resources/level.h" #include "engines/stark/resources/location.h" @@ -226,6 +227,9 @@ Resource *XRCReader::createResource(XRCReadStream *stream, Resource *parent) { case ResourceType::kBookmark: resource = new Bookmark(parent, subType, index, name); break; + case ResourceType::kKnowledgeSet: + resource = new KnowledgeSet(parent, subType, index, name); + break; case ResourceType::kKnowledge: resource = new Knowledge(parent, subType, index, name); break;