mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Use const for ObjectTemplate
This commit is contained in:
parent
114dac7e81
commit
a109580b91
@ -433,11 +433,11 @@ boost::optional<std::string> AObjectTypeHandler::getCustomName() const
|
||||
return objectName;
|
||||
}
|
||||
|
||||
void AObjectTypeHandler::addTemplate(ObjectTemplate templ)
|
||||
void AObjectTypeHandler::addTemplate(const ObjectTemplate & templ)
|
||||
{
|
||||
templ.id = Obj(type);
|
||||
templ.subid = subtype;
|
||||
templates.push_back(templ);
|
||||
templates.back().id = Obj(type);
|
||||
templates.back().subid = subtype;
|
||||
}
|
||||
|
||||
void AObjectTypeHandler::addTemplate(JsonNode config)
|
||||
@ -449,7 +449,7 @@ void AObjectTypeHandler::addTemplate(JsonNode config)
|
||||
tmpl.subid = subtype;
|
||||
tmpl.stringID = ""; // TODO?
|
||||
tmpl.readJson(config);
|
||||
addTemplate(tmpl);
|
||||
templates.push_back(tmpl);
|
||||
}
|
||||
|
||||
std::vector<ObjectTemplate> AObjectTypeHandler::getTemplates() const
|
||||
|
@ -128,7 +128,7 @@ public:
|
||||
/// Returns object-specific name, if set
|
||||
boost::optional<std::string> getCustomName() const;
|
||||
|
||||
void addTemplate(ObjectTemplate templ);
|
||||
void addTemplate(const ObjectTemplate & templ);
|
||||
void addTemplate(JsonNode config);
|
||||
|
||||
/// returns all templates matching parameters
|
||||
@ -147,14 +147,14 @@ public:
|
||||
|
||||
/// Creates object and set up core properties (like ID/subID). Object is NOT initialized
|
||||
/// to allow creating objects before game start (e.g. map loading)
|
||||
virtual CGObjectInstance * create(ObjectTemplate tmpl) const = 0;
|
||||
virtual CGObjectInstance * create(const ObjectTemplate & tmpl) const = 0;
|
||||
|
||||
/// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
|
||||
/// This should set remaining properties, including randomized or depending on map
|
||||
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0;
|
||||
|
||||
/// Returns object configuration, if available. Otherwise returns NULL
|
||||
virtual std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const = 0;
|
||||
virtual std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const = 0;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ void CRewardableConstructor::initTypeData(const JsonNode & config)
|
||||
objectInfo.init(config);
|
||||
}
|
||||
|
||||
CGObjectInstance * CRewardableConstructor::create(ObjectTemplate tmpl) const
|
||||
CGObjectInstance * CRewardableConstructor::create(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
auto ret = new CRewardableObject();
|
||||
preInitObject(ret);
|
||||
@ -198,7 +198,7 @@ void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomG
|
||||
objectInfo.configureObject(dynamic_cast<CRewardableObject*>(object), rng);
|
||||
}
|
||||
|
||||
std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(ObjectTemplate tmpl) const
|
||||
std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
return std::unique_ptr<IObjectInfo>(new CRandomRewardObjectInfo(objectInfo));
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ class DLL_LINKAGE CRewardableConstructor : public AObjectTypeHandler
|
||||
public:
|
||||
CRewardableConstructor();
|
||||
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const override;
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
|
||||
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override;
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override;
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ bool CTownInstanceConstructor::objectFilter(const CGObjectInstance * object, con
|
||||
return false;
|
||||
}
|
||||
|
||||
CGObjectInstance * CTownInstanceConstructor::create(ObjectTemplate tmpl) const
|
||||
CGObjectInstance * CTownInstanceConstructor::create(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
CGTownInstance * obj = createTyped(tmpl);
|
||||
obj->town = faction->town;
|
||||
@ -126,7 +126,7 @@ bool CHeroInstanceConstructor::objectFilter(const CGObjectInstance * object, con
|
||||
return false;
|
||||
}
|
||||
|
||||
CGObjectInstance * CHeroInstanceConstructor::create(ObjectTemplate tmpl) const
|
||||
CGObjectInstance * CHeroInstanceConstructor::create(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
CGHeroInstance * obj = createTyped(tmpl);
|
||||
obj->type = nullptr; //FIXME: set to valid value. somehow.
|
||||
@ -169,7 +169,7 @@ bool CDwellingInstanceConstructor::objectFilter(const CGObjectInstance *, const
|
||||
return false;
|
||||
}
|
||||
|
||||
CGObjectInstance * CDwellingInstanceConstructor::create(ObjectTemplate tmpl) const
|
||||
CGObjectInstance * CDwellingInstanceConstructor::create(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
CGDwelling * obj = createTyped(tmpl);
|
||||
|
||||
@ -267,7 +267,7 @@ void CBankInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
bankResetDuration = input["resetDuration"].Float();
|
||||
}
|
||||
|
||||
CGObjectInstance *CBankInstanceConstructor::create(ObjectTemplate tmpl) const
|
||||
CGObjectInstance *CBankInstanceConstructor::create(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
return createTyped(tmpl);
|
||||
}
|
||||
@ -448,7 +448,7 @@ bool CBankInfo::givesSpells() const
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<IObjectInfo> CBankInstanceConstructor::getObjectInfo(ObjectTemplate tmpl) const
|
||||
std::unique_ptr<IObjectInfo> CBankInstanceConstructor::getObjectInfo(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
return std::unique_ptr<IObjectInfo>(new CBankInfo(levels));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ template<class ObjectType>
|
||||
class CDefaultObjectTypeHandler : public AObjectTypeHandler
|
||||
{
|
||||
protected:
|
||||
ObjectType * createTyped(ObjectTemplate tmpl) const
|
||||
ObjectType * createTyped(const ObjectTemplate & tmpl) const
|
||||
{
|
||||
auto obj = new ObjectType();
|
||||
preInitObject(obj);
|
||||
@ -39,7 +39,7 @@ protected:
|
||||
public:
|
||||
CDefaultObjectTypeHandler(){}
|
||||
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const override
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override
|
||||
{
|
||||
return createTyped(tmpl);
|
||||
}
|
||||
@ -48,7 +48,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override
|
||||
virtual std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public:
|
||||
std::map<std::string, LogicalExpression<BuildingID>> filters;
|
||||
|
||||
CTownInstanceConstructor();
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const override;
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
void afterLoadFinalization() override;
|
||||
|
||||
@ -96,7 +96,7 @@ public:
|
||||
std::map<std::string, LogicalExpression<HeroTypeID>> filters;
|
||||
|
||||
CHeroInstanceConstructor();
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const override;
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
void afterLoadFinalization() override;
|
||||
|
||||
@ -120,7 +120,7 @@ protected:
|
||||
public:
|
||||
|
||||
CDwellingInstanceConstructor();
|
||||
CGObjectInstance * create(ObjectTemplate tmpl) const override;
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
|
||||
bool producesCreature(const CCreature * crea) const;
|
||||
@ -186,10 +186,10 @@ public:
|
||||
|
||||
CBankInstanceConstructor();
|
||||
|
||||
CGObjectInstance *create(ObjectTemplate tmpl) const override;
|
||||
CGObjectInstance * create(const ObjectTemplate & tmpl) const override;
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(ObjectTemplate tmpl) const override;
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(const ObjectTemplate & tmpl) const override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -61,15 +61,15 @@ ObjectTemplate::ObjectTemplate():
|
||||
ObjectTemplate::ObjectTemplate(const ObjectTemplate& other):
|
||||
visitDir(other.visitDir),
|
||||
allowedTerrains(other.allowedTerrains),
|
||||
id(other.id),
|
||||
subid(other.subid),
|
||||
id(other.id),
|
||||
subid(other.subid),
|
||||
printPriority(other.printPriority),
|
||||
animationFile(other.animationFile)
|
||||
{
|
||||
//default copy constructor is failing with usedTiles this for unknown reason
|
||||
|
||||
usedTiles.resize(other.usedTiles.size());
|
||||
for(size_t i = 0; i < usedTiles.size(); i++)
|
||||
usedTiles.resize(other.usedTiles.size());
|
||||
for(size_t i = 0; i < usedTiles.size(); i++)
|
||||
std::copy(other.usedTiles[i].begin(), other.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
|
||||
}
|
||||
|
||||
@ -77,14 +77,14 @@ ObjectTemplate & ObjectTemplate::operator=(const ObjectTemplate & rhs)
|
||||
{
|
||||
visitDir = rhs.visitDir;
|
||||
allowedTerrains = rhs.allowedTerrains;
|
||||
id = rhs.id;
|
||||
subid = rhs.subid;
|
||||
id = rhs.id;
|
||||
subid = rhs.subid;
|
||||
printPriority = rhs.printPriority;
|
||||
animationFile = rhs.animationFile;
|
||||
|
||||
usedTiles.clear();
|
||||
usedTiles.resize(rhs.usedTiles.size());
|
||||
for(size_t i = 0; i < usedTiles.size(); i++)
|
||||
usedTiles.resize(rhs.usedTiles.size());
|
||||
for(size_t i = 0; i < usedTiles.size(); i++)
|
||||
std::copy(rhs.usedTiles[i].begin(), rhs.usedTiles[i].end(), std::back_inserter(usedTiles[i]));
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user