diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 2fbf0a22b..c35139170 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -433,11 +433,11 @@ boost::optional 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 AObjectTypeHandler::getTemplates() const diff --git a/lib/mapObjects/CObjectClassesHandler.h b/lib/mapObjects/CObjectClassesHandler.h index c7aa25375..3f3d02254 100644 --- a/lib/mapObjects/CObjectClassesHandler.h +++ b/lib/mapObjects/CObjectClassesHandler.h @@ -128,7 +128,7 @@ public: /// Returns object-specific name, if set boost::optional 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 getObjectInfo(ObjectTemplate tmpl) const = 0; + virtual std::unique_ptr getObjectInfo(const ObjectTemplate & tmpl) const = 0; template void serialize(Handler &h, const int version) { diff --git a/lib/mapObjects/CRewardableConstructor.cpp b/lib/mapObjects/CRewardableConstructor.cpp index c71384a3f..1427b4711 100644 --- a/lib/mapObjects/CRewardableConstructor.cpp +++ b/lib/mapObjects/CRewardableConstructor.cpp @@ -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(object), rng); } -std::unique_ptr CRewardableConstructor::getObjectInfo(ObjectTemplate tmpl) const +std::unique_ptr CRewardableConstructor::getObjectInfo(const ObjectTemplate & tmpl) const { return std::unique_ptr(new CRandomRewardObjectInfo(objectInfo)); } diff --git a/lib/mapObjects/CRewardableConstructor.h b/lib/mapObjects/CRewardableConstructor.h index 25b9a5501..78f300a38 100644 --- a/lib/mapObjects/CRewardableConstructor.h +++ b/lib/mapObjects/CRewardableConstructor.h @@ -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 getObjectInfo(ObjectTemplate tmpl) const override; + std::unique_ptr getObjectInfo(const ObjectTemplate & tmpl) const override; }; diff --git a/lib/mapObjects/CommonConstructors.cpp b/lib/mapObjects/CommonConstructors.cpp index ec4083750..a0e029b46 100644 --- a/lib/mapObjects/CommonConstructors.cpp +++ b/lib/mapObjects/CommonConstructors.cpp @@ -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 CBankInstanceConstructor::getObjectInfo(ObjectTemplate tmpl) const +std::unique_ptr CBankInstanceConstructor::getObjectInfo(const ObjectTemplate & tmpl) const { return std::unique_ptr(new CBankInfo(levels)); } diff --git a/lib/mapObjects/CommonConstructors.h b/lib/mapObjects/CommonConstructors.h index 7c516fdd4..ed4263213 100644 --- a/lib/mapObjects/CommonConstructors.h +++ b/lib/mapObjects/CommonConstructors.h @@ -29,7 +29,7 @@ template 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 getObjectInfo(ObjectTemplate tmpl) const override + virtual std::unique_ptr getObjectInfo(const ObjectTemplate & tmpl) const override { return nullptr; } @@ -73,7 +73,7 @@ public: std::map> 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> 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 getObjectInfo(ObjectTemplate tmpl) const override; + std::unique_ptr getObjectInfo(const ObjectTemplate & tmpl) const override; template void serialize(Handler &h, const int version) { diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index b7e3b5003..f2009a463 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -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; }