2011-12-13 21:23:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
2012-11-13 11:52:23 +00:00
|
|
|
#include "GameConstants.h"
|
2010-12-19 14:39:56 +00:00
|
|
|
#include "../lib/ConstTransitivePtr.h"
|
2009-04-16 11:14:13 +00:00
|
|
|
|
2009-04-15 14:03:31 +00:00
|
|
|
/*
|
|
|
|
* CDefObjInfoHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 11:14:13 +00:00
|
|
|
*/
|
|
|
|
|
2014-01-02 23:48:38 +00:00
|
|
|
class CBinaryReader;
|
|
|
|
class CLegacyConfigParser;
|
|
|
|
class JsonNode;
|
|
|
|
|
|
|
|
class DLL_LINKAGE ObjectTemplate
|
2009-04-16 11:14:13 +00:00
|
|
|
{
|
2014-01-02 23:48:38 +00:00
|
|
|
enum EBlockMapBits
|
|
|
|
{
|
|
|
|
VISIBLE = 1,
|
|
|
|
VISITABLE = 2,
|
|
|
|
BLOCKED = 4
|
|
|
|
};
|
2009-04-16 11:14:13 +00:00
|
|
|
|
2014-01-02 23:48:38 +00:00
|
|
|
/// tiles that are covered by this object, uses EBlockMapBits enum as flags
|
|
|
|
std::vector<std::vector<ui8>> usedTiles;
|
|
|
|
/// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
|
|
|
|
ui8 visitDir;
|
|
|
|
/// list of terrains on which this object can be placed
|
|
|
|
std::set<ETerrainType> allowedTerrains;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// H3 ID/subID of this object
|
2013-02-10 23:24:57 +00:00
|
|
|
Obj id;
|
2014-01-02 23:48:38 +00:00
|
|
|
si32 subid;
|
|
|
|
/// print priority, objects with higher priority will be print first, below everything else
|
2009-04-16 11:14:13 +00:00
|
|
|
si32 printPriority;
|
2014-01-02 23:48:38 +00:00
|
|
|
/// animation file that should be used to display object
|
|
|
|
std::string animationFile;
|
|
|
|
|
2014-03-23 20:26:18 +00:00
|
|
|
/// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
|
|
|
|
std::string stringID;
|
|
|
|
|
2014-01-02 23:48:38 +00:00
|
|
|
ui32 getWidth() const;
|
|
|
|
ui32 getHeight() const;
|
|
|
|
void setSize(ui32 width, ui32 height);
|
|
|
|
|
2009-07-25 16:35:47 +00:00
|
|
|
bool isVisitable() const;
|
2014-01-02 23:48:38 +00:00
|
|
|
|
|
|
|
// Checks object used tiles
|
|
|
|
// Position is relative to bottom-right corner of the object, can not be negative
|
|
|
|
bool isWithin(si32 X, si32 Y) const;
|
|
|
|
bool isVisitableAt(si32 X, si32 Y) const;
|
|
|
|
bool isVisibleAt(si32 X, si32 Y) const;
|
|
|
|
bool isBlockedAt(si32 X, si32 Y) const;
|
|
|
|
|
|
|
|
// Checks if object is visitable from certain direction. X and Y must be between -1..+1
|
|
|
|
bool isVisitableFrom(si8 X, si8 Y) const;
|
|
|
|
|
|
|
|
// Checks if object can be placed on specific terrain
|
|
|
|
bool canBePlacedAt(ETerrainType terrain) const;
|
|
|
|
|
|
|
|
ObjectTemplate();
|
|
|
|
|
|
|
|
void readTxt(CLegacyConfigParser & parser);
|
|
|
|
void readMsk();
|
|
|
|
void readMap(CBinaryReader & reader);
|
|
|
|
void readJson(const JsonNode & node);
|
|
|
|
|
2009-04-16 11:14:13 +00:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-03-23 20:26:18 +00:00
|
|
|
h & usedTiles & allowedTerrains & animationFile & stringID;
|
2014-01-02 23:48:38 +00:00
|
|
|
h & id & subid & printPriority & visitDir;
|
2009-04-16 11:14:13 +00:00
|
|
|
}
|
|
|
|
};
|
2014-01-02 23:48:38 +00:00
|
|
|
|
|
|
|
class DLL_LINKAGE CDefObjInfoHandler
|
|
|
|
{
|
|
|
|
/// list of all object templates loaded from text files
|
|
|
|
/// actual object have ObjectTemplate as member "appearance"
|
|
|
|
std::vector<ObjectTemplate> objects;
|
|
|
|
|
|
|
|
/// reads one of H3 text files that contain object templates description
|
|
|
|
void readTextFile(std::string path);
|
|
|
|
public:
|
|
|
|
|
|
|
|
CDefObjInfoHandler();
|
|
|
|
|
|
|
|
/// Erases all templates with given type/subtype
|
|
|
|
void eraseAll(Obj type, si32 subtype);
|
|
|
|
|
|
|
|
/// Add new template into the list
|
|
|
|
void registerTemplate(ObjectTemplate obj);
|
|
|
|
|
|
|
|
/// picks all possible candidates for specific pair <type, subtype>
|
|
|
|
std::vector<ObjectTemplate> pickCandidates(Obj type, si32 subtype) const;
|
|
|
|
/// picks all candidates for <type, subtype> and of possible - also filters them by terrain
|
|
|
|
std::vector<ObjectTemplate> pickCandidates(Obj type, si32 subtype, ETerrainType terrain) const;
|
2014-03-23 20:26:18 +00:00
|
|
|
/// as above, but also filters out templates that are not applicable according to accepted test
|
|
|
|
std::vector<ObjectTemplate> pickCandidates(Obj type, si32 subtype, ETerrainType terrain, std::function<bool(ObjectTemplate &)> filter) const;
|
2009-04-16 11:14:13 +00:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-01-02 23:48:38 +00:00
|
|
|
h & objects;
|
2009-04-16 11:14:13 +00:00
|
|
|
}
|
|
|
|
};
|
2014-04-25 17:59:05 +03:00
|
|
|
|
|
|
|
class IObjectInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool givesResources() const = 0;
|
|
|
|
|
|
|
|
virtual bool givesExperience() const = 0;
|
|
|
|
virtual bool givesMana() const = 0;
|
|
|
|
virtual bool givesMovement() const = 0;
|
|
|
|
|
|
|
|
virtual bool givesPrimarySkills() const = 0;
|
|
|
|
virtual bool givesSecondarySkills() const = 0;
|
|
|
|
|
|
|
|
virtual bool givesArtifacts() const = 0;
|
|
|
|
virtual bool givesCreatures() const = 0;
|
|
|
|
virtual bool givesSpells() const = 0;
|
|
|
|
|
|
|
|
virtual bool givesBonuses() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CGObjectInstance;
|
|
|
|
|
2014-04-27 20:37:53 +03:00
|
|
|
class IObjectTypesHandler
|
2014-04-25 17:59:05 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-04-27 20:37:53 +03:00
|
|
|
virtual std::vector<ObjectTemplate> getTemplates(si32 type, si32 subType) const = 0;
|
2014-04-25 17:59:05 +03:00
|
|
|
|
2014-04-27 20:37:53 +03:00
|
|
|
virtual CGObjectInstance * create(ObjectTemplate tmpl) const = 0;
|
|
|
|
|
|
|
|
virtual bool handlesID(ObjectTemplate tmpl) const = 0;
|
2014-04-25 17:59:05 +03:00
|
|
|
|
|
|
|
virtual void configureObject(CGObjectInstance * object) const = 0;
|
|
|
|
|
2014-04-27 20:37:53 +03:00
|
|
|
virtual const IObjectInfo * getObjectInfo(ObjectTemplate tmpl) const = 0;
|
2014-04-25 17:59:05 +03:00
|
|
|
};
|
|
|
|
|
2014-04-27 20:37:53 +03:00
|
|
|
typedef std::shared_ptr<IObjectTypesHandler> TObjectTypeHandler;
|
2014-04-25 17:59:05 +03:00
|
|
|
|
2014-04-27 20:37:53 +03:00
|
|
|
class CObjectGroupsHandler
|
2014-04-25 17:59:05 +03:00
|
|
|
{
|
|
|
|
/// list of object handlers, each of them handles 1 or more object type
|
|
|
|
std::vector<TObjectTypeHandler> objectTypes;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// returns handler for specified object (ID-based). ObjectHandler keeps ownership
|
2014-04-27 20:37:53 +03:00
|
|
|
IObjectTypesHandler * getHandlerFor(ObjectTemplate tmpl) const;
|
2014-04-25 17:59:05 +03:00
|
|
|
|
|
|
|
/// creates object based on specified template
|
2014-04-27 20:37:53 +03:00
|
|
|
CGObjectInstance * createObject(ObjectTemplate tmpl);
|
2014-04-25 17:59:05 +03:00
|
|
|
|
|
|
|
template<typename CObjectClass>
|
2014-04-27 20:37:53 +03:00
|
|
|
CObjectClass * createObjectTyped(ObjectTemplate tmpl)
|
2014-04-25 17:59:05 +03:00
|
|
|
{
|
|
|
|
auto objInst = createObject(tmpl);
|
|
|
|
auto objClass = dynamic_cast<CObjectClass*>(objInst);
|
|
|
|
assert(objClass);
|
|
|
|
return objClass;
|
|
|
|
}
|
2014-04-27 20:37:53 +03:00
|
|
|
};
|