2014-06-14 18:42:13 +03:00
|
|
|
/*
|
2021-05-16 19:53:11 +02:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CObjectClassesHandler.h"
|
|
|
|
#include "../CTownHandler.h" // for building ID-based filters
|
|
|
|
#include "MapObjects.h"
|
2014-06-14 18:42:13 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-07-06 23:14:37 +03:00
|
|
|
class CGObjectInstance;
|
2014-06-14 18:42:13 +03:00
|
|
|
class CGTownInstance;
|
|
|
|
class CGHeroInstance;
|
|
|
|
class CGDwelling;
|
|
|
|
class CHeroClass;
|
2014-06-22 13:39:40 +03:00
|
|
|
class CBank;
|
|
|
|
class CStackBasicDescriptor;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
/// Class that is used for objects that do not have dedicated handler
|
|
|
|
template<class ObjectType>
|
|
|
|
class CDefaultObjectTypeHandler : public AObjectTypeHandler
|
|
|
|
{
|
|
|
|
protected:
|
2022-09-11 15:12:35 +02:00
|
|
|
ObjectType * createTyped(std::shared_ptr<const ObjectTemplate> tmpl /* = nullptr */) const
|
2014-06-14 18:42:13 +03:00
|
|
|
{
|
|
|
|
auto obj = new ObjectType();
|
2015-11-14 15:50:29 +02:00
|
|
|
preInitObject(obj);
|
2022-09-11 15:12:35 +02:00
|
|
|
|
2022-09-29 19:07:56 +02:00
|
|
|
//Set custom template or leave null
|
2022-09-11 15:12:35 +02:00
|
|
|
if (tmpl)
|
|
|
|
{
|
|
|
|
obj->appearance = tmpl;
|
|
|
|
}
|
|
|
|
|
2014-06-14 18:42:13 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
public:
|
2021-05-16 19:53:11 +02:00
|
|
|
CDefaultObjectTypeHandler() {}
|
2014-06-14 18:42:13 +03:00
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override
|
2014-06-14 18:42:13 +03:00
|
|
|
{
|
|
|
|
return createTyped(tmpl);
|
|
|
|
}
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override
|
2014-06-14 18:42:13 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
virtual std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override
|
2014-06-14 18:42:13 +03:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CObstacleConstructor : public CDefaultObjectTypeHandler<CGObjectInstance>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CObstacleConstructor();
|
2015-10-12 15:47:10 +02:00
|
|
|
bool isStaticObject() override;
|
2014-06-14 18:42:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CTownInstanceConstructor : public CDefaultObjectTypeHandler<CGTownInstance>
|
|
|
|
{
|
|
|
|
JsonNode filtersJson;
|
|
|
|
protected:
|
2022-09-11 15:12:35 +02:00
|
|
|
bool objectFilter(const CGObjectInstance *, std::shared_ptr<const ObjectTemplate>) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void initTypeData(const JsonNode & input) override;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
CFaction * faction;
|
|
|
|
std::map<std::string, LogicalExpression<BuildingID>> filters;
|
|
|
|
|
|
|
|
CTownInstanceConstructor();
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
|
|
|
void afterLoadFinalization() override;
|
2014-06-16 19:27:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & filtersJson;
|
|
|
|
h & faction;
|
|
|
|
h & filters;
|
2014-06-16 19:27:26 +03:00
|
|
|
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:
|
2022-09-11 15:12:35 +02:00
|
|
|
bool objectFilter(const CGObjectInstance *, std::shared_ptr<const ObjectTemplate>) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void initTypeData(const JsonNode & input) override;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
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();
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
|
|
|
void afterLoadFinalization() override;
|
2014-06-16 19:27:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & filtersJson;
|
|
|
|
h & heroClass;
|
|
|
|
h & filters;
|
2014-06-16 19:27:26 +03:00
|
|
|
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:
|
2022-09-11 15:12:35 +02:00
|
|
|
bool objectFilter(const CGObjectInstance *, std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void initTypeData(const JsonNode & input) override;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
public:
|
2023-01-11 00:49:31 +02:00
|
|
|
bool hasNameTextID() const override;
|
2014-06-14 18:42:13 +03:00
|
|
|
|
|
|
|
CDwellingInstanceConstructor();
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
2014-06-15 19:43:01 +03:00
|
|
|
|
|
|
|
bool producesCreature(const CCreature * crea) const;
|
2014-07-06 23:14:37 +03:00
|
|
|
std::vector<const CCreature *> getProducedCreatures() const;
|
2014-06-16 19:27:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & availableCreatures;
|
|
|
|
h & guards;
|
2014-06-16 19:27:26 +03:00
|
|
|
h & static_cast<CDefaultObjectTypeHandler<CGDwelling>&>(*this);
|
|
|
|
}
|
2014-06-14 18:42:13 +03:00
|
|
|
};
|
2014-06-22 13:39:40 +03:00
|
|
|
|
|
|
|
struct BankConfig
|
|
|
|
{
|
|
|
|
BankConfig() { chance = upgradeChance = combatValue = value = 0; };
|
|
|
|
ui32 value; //overall value of given things
|
|
|
|
ui32 chance; //chance for this level being chosen
|
|
|
|
ui32 upgradeChance; //chance for creatures to be in upgraded versions
|
|
|
|
ui32 combatValue; //how hard are guards of this level
|
|
|
|
std::vector<CStackBasicDescriptor> guards; //creature ID, amount
|
|
|
|
Res::ResourceSet resources; //resources given in case of victory
|
|
|
|
std::vector<CStackBasicDescriptor> creatures; //creatures granted in case of victory (creature ID, amount)
|
|
|
|
std::vector<ArtifactID> artifacts; //artifacts given in case of victory
|
|
|
|
std::vector<SpellID> spells; // granted spell(s), for Pyramid
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & chance;
|
|
|
|
h & upgradeChance;
|
|
|
|
h & guards;
|
|
|
|
h & combatValue;
|
|
|
|
h & resources;
|
|
|
|
h & creatures;
|
|
|
|
h & artifacts;
|
|
|
|
h & value;
|
|
|
|
h & spells;
|
2014-06-22 13:39:40 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-10 13:29:51 +02:00
|
|
|
typedef std::vector<std::pair<ui8, IObjectInfo::CArmyStructure>> TPossibleGuards;
|
|
|
|
|
2021-05-16 19:53:11 +02:00
|
|
|
template <typename T>
|
|
|
|
struct DLL_LINKAGE PossibleReward
|
|
|
|
{
|
|
|
|
int chance;
|
|
|
|
T data;
|
|
|
|
|
|
|
|
PossibleReward(int chance, const T & data) : chance(chance), data(data) {}
|
|
|
|
};
|
|
|
|
|
2014-12-10 13:29:51 +02:00
|
|
|
class DLL_LINKAGE CBankInfo : public IObjectInfo
|
2014-06-22 13:39:40 +03:00
|
|
|
{
|
2015-12-14 10:26:14 +02:00
|
|
|
const JsonVector & config;
|
2014-06-22 13:39:40 +03:00
|
|
|
public:
|
2015-12-14 10:26:14 +02:00
|
|
|
CBankInfo(const JsonVector & Config);
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2014-12-10 13:29:51 +02:00
|
|
|
TPossibleGuards getPossibleGuards() const;
|
2021-05-16 19:53:11 +02:00
|
|
|
std::vector<PossibleReward<TResources>> getPossibleResourcesReward() const;
|
|
|
|
std::vector<PossibleReward<CStackBasicDescriptor>> getPossibleCreaturesReward() const;
|
2014-12-10 13:29:51 +02:00
|
|
|
|
2015-03-30 23:55:37 +02:00
|
|
|
// These functions should try to evaluate minimal possible/max possible guards to give provide information on possible thread to AI
|
2015-10-12 15:47:10 +02:00
|
|
|
CArmyStructure minGuards() const override;
|
|
|
|
CArmyStructure maxGuards() const override;
|
2014-12-10 13:29:51 +02:00
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
bool givesResources() const override;
|
|
|
|
bool givesArtifacts() const override;
|
|
|
|
bool givesCreatures() const override;
|
|
|
|
bool givesSpells() const override;
|
2014-06-22 13:39:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank>
|
|
|
|
{
|
|
|
|
BankConfig generateConfig(const JsonNode & conf, CRandomGenerator & rng) const;
|
|
|
|
|
|
|
|
JsonVector levels;
|
|
|
|
protected:
|
2015-10-12 15:47:10 +02:00
|
|
|
void initTypeData(const JsonNode & input) override;
|
2014-06-22 13:39:40 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
// all banks of this type will be reset N days after clearing,
|
|
|
|
si32 bankResetDuration;
|
|
|
|
|
|
|
|
CBankInstanceConstructor();
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
2015-10-12 15:47:10 +02:00
|
|
|
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
2014-06-22 13:39:40 +03:00
|
|
|
|
2023-01-11 00:49:31 +02:00
|
|
|
bool hasNameTextID() const override;
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
2014-08-09 12:31:43 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & levels;
|
|
|
|
h & bankResetDuration;
|
2014-08-09 12:31:43 +03:00
|
|
|
h & static_cast<CDefaultObjectTypeHandler<CBank>&>(*this);
|
|
|
|
}
|
2014-06-22 13:39:40 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|