2014-06-14 18:42:13 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CObjectClassesHandler.h"
|
|
|
|
#include "../CTownHandler.h" // for building ID-based filters
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CommonConstructors.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CGTownInstance;
|
|
|
|
class CGHeroInstance;
|
|
|
|
class CGDwelling;
|
|
|
|
//class CGArtifact;
|
|
|
|
//class CGCreature;
|
|
|
|
class CHeroClass;
|
|
|
|
|
|
|
|
/// Class that is used for objects that do not have dedicated handler
|
|
|
|
template<class ObjectType>
|
|
|
|
class CDefaultObjectTypeHandler : public AObjectTypeHandler
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ObjectType * createTyped(ObjectTemplate tmpl) const
|
|
|
|
{
|
|
|
|
auto obj = new ObjectType();
|
|
|
|
obj->ID = tmpl.id;
|
|
|
|
obj->subID = tmpl.subid;
|
|
|
|
obj->appearance = tmpl;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
CDefaultObjectTypeHandler(){}
|
|
|
|
|
|
|
|
CGObjectInstance * create(ObjectTemplate tmpl) const
|
|
|
|
{
|
|
|
|
return createTyped(tmpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const IObjectInfo * getObjectInfo(ObjectTemplate tmpl) const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CObstacleConstructor : public CDefaultObjectTypeHandler<CGObjectInstance>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CObstacleConstructor();
|
|
|
|
bool isStaticObject();
|
|
|
|
};
|
|
|
|
|
|
|
|
class CTownInstanceConstructor : public CDefaultObjectTypeHandler<CGTownInstance>
|
|
|
|
{
|
|
|
|
JsonNode filtersJson;
|
|
|
|
protected:
|
|
|
|
bool objectFilter(const CGObjectInstance *, const ObjectTemplate &) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CFaction * faction;
|
|
|
|
std::map<std::string, LogicalExpression<BuildingID>> filters;
|
|
|
|
|
|
|
|
CTownInstanceConstructor();
|
|
|
|
CGObjectInstance * create(ObjectTemplate tmpl) const;
|
|
|
|
void initTypeData(const JsonNode & input);
|
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const;
|
|
|
|
void afterLoadFinalization();
|
2014-06-16 19:27:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & filtersJson & faction & filters;
|
|
|
|
h & static_cast<CDefaultObjectTypeHandler<CGTownInstance>&>(*this);
|
|
|
|
}
|
2014-06-14 18:42:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CHeroInstanceConstructor : public CDefaultObjectTypeHandler<CGHeroInstance>
|
|
|
|
{
|
2014-06-16 19:27:26 +03:00
|
|
|
JsonNode filtersJson;
|
2014-06-14 18:42:13 +03:00
|
|
|
protected:
|
|
|
|
bool objectFilter(const CGObjectInstance *, const ObjectTemplate &) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CHeroClass * heroClass;
|
2014-06-16 19:27:26 +03:00
|
|
|
std::map<std::string, LogicalExpression<HeroTypeID>> filters;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
CHeroInstanceConstructor();
|
|
|
|
CGObjectInstance * create(ObjectTemplate tmpl) const;
|
|
|
|
void initTypeData(const JsonNode & input);
|
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const;
|
2014-06-16 19:27:26 +03:00
|
|
|
void afterLoadFinalization();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & filtersJson & heroClass & filters;
|
|
|
|
h & static_cast<CDefaultObjectTypeHandler<CGHeroInstance>&>(*this);
|
|
|
|
}
|
2014-06-14 18:42:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CDwellingInstanceConstructor : public CDefaultObjectTypeHandler<CGDwelling>
|
|
|
|
{
|
2014-06-15 19:43:01 +03:00
|
|
|
std::vector<std::vector<const CCreature *>> availableCreatures;
|
|
|
|
|
|
|
|
JsonNode guards;
|
|
|
|
|
2014-06-14 18:42:13 +03:00
|
|
|
protected:
|
|
|
|
bool objectFilter(const CGObjectInstance *, const ObjectTemplate &) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CDwellingInstanceConstructor();
|
|
|
|
CGObjectInstance * create(ObjectTemplate tmpl) const;
|
|
|
|
void initTypeData(const JsonNode & input);
|
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const;
|
2014-06-15 19:43:01 +03:00
|
|
|
|
|
|
|
bool producesCreature(const CCreature * crea) const;
|
2014-06-16 19:27:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & availableCreatures & guards;
|
|
|
|
h & static_cast<CDefaultObjectTypeHandler<CGDwelling>&>(*this);
|
|
|
|
}
|
2014-06-14 18:42:13 +03:00
|
|
|
};
|