diff --git a/lib/mapObjects/CommonConstructors.cpp b/lib/mapObjects/CommonConstructors.cpp index 7fb4ce5ff..e4432db8a 100644 --- a/lib/mapObjects/CommonConstructors.cpp +++ b/lib/mapObjects/CommonConstructors.cpp @@ -218,6 +218,17 @@ bool CDwellingInstanceConstructor::producesCreature(const CCreature * crea) cons return false; } +std::vector CDwellingInstanceConstructor::getProducedCreatures() const +{ + std::vector creatures; //no idea why it's 2D, to be honest + for (auto & entry : availableCreatures) + { + for (const CCreature * cre : entry) + creatures.push_back(cre); + } + return creatures; +} + CBankInstanceConstructor::CBankInstanceConstructor() { } diff --git a/lib/mapObjects/CommonConstructors.h b/lib/mapObjects/CommonConstructors.h index 241673d12..5853c2062 100644 --- a/lib/mapObjects/CommonConstructors.h +++ b/lib/mapObjects/CommonConstructors.h @@ -13,6 +13,7 @@ * */ +class CGObjectInstance; class CGTownInstance; class CGHeroInstance; class CGDwelling; @@ -123,6 +124,7 @@ public: void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const; bool producesCreature(const CCreature * crea) const; + std::vector getProducedCreatures() const; template void serialize(Handler &h, const int version) { diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index 9d9d53645..9bdcbfe82 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -19,12 +19,14 @@ #include "../CCreatureHandler.h" #include "../CSpellHandler.h" //for choosing random spells -#include "../mapObjects/CObjectClassesHandler.h" +#include "../mapObjects/CommonConstructors.h" +#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h #include "../mapObjects/CGPandoraBox.h" #include "../mapObjects/CRewardableObject.h" class CMap; class CMapEditManager; +//class CGObjectInstance; CRmgTemplateZone::CTownInfo::CTownInfo() : townCount(0), castleCount(0), townDensity(0), castleDensity(0) { @@ -1049,9 +1051,9 @@ void CRmgTemplateZone::createObstacles(CMapGenerator* gen) bool CRmgTemplateZone::fill(CMapGenerator* gen) { - addAllPossibleObjects (gen); initTownType(gen); initTerrainType(gen); + addAllPossibleObjects (gen); placeMines(gen); createRequiredObjects(gen); fractalize(gen); //after required objects are created and linked with their own paths @@ -1404,7 +1406,40 @@ void CRmgTemplateZone::addAllPossibleObjects (CMapGenerator* gen) } } } - } + } + + //dwellings + + for (auto secondaryID : VLC->objtypeh->knownSubObjects(Obj::CREATURE_GENERATOR1)) + { + auto dwellingHandler = dynamic_cast(VLC->objtypeh->getHandlerFor(Obj::CREATURE_GENERATOR1, secondaryID).get()); + auto creatures = dwellingHandler->getProducedCreatures(); + if (creatures.empty()) + continue; + + auto cre = creatures.front(); + if (cre->faction == townType) + { + oi.value = cre->AIValue * cre->growth * (1 + 0.5f); //TODO: include town count in formula + oi.probability = 40; + + for (auto temp : dwellingHandler->getTemplates()) + { + if (temp.canBePlacedAt(terrainType)) + { + oi.generateObject = [gen, temp, secondaryID, dwellingHandler]() -> CGObjectInstance * + { + auto obj = VLC->objtypeh->getHandlerFor(Obj::CREATURE_GENERATOR1, secondaryID)->create(temp); + //dwellingHandler->configureObject(obj, gen->rand); + obj->tempOwner = PlayerColor::NEUTRAL; + return obj; + }; + + possibleObjects.push_back (oi); + } + } + } + } static const int scrollValues[] = {500, 2000, 3000, 4000, 5000};