STARK: Allow retrieving the current chapter

This commit is contained in:
Bastien Bouclet
2015-01-11 15:57:04 +01:00
parent a75de69533
commit 7de123d6a1
7 changed files with 154 additions and 9 deletions
+2
View File
@@ -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 \
+39
View File
@@ -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
+55
View File
@@ -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
+3 -1
View File
@@ -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
}
+46
View File
@@ -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>(KnowledgeSet::kState);
Knowledge *chapter = globalState->findChildWithIndex<Knowledge>(0);
return chapter->getIntegerValue();
}
} // End of namespace Stark
+5 -8
View File
@@ -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;
+4
View File
@@ -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;