Jelajahi Sumber

- Added faction-specific dwellings
- Fixed generation of terrain-specific objects

DjWarmonger 11 tahun lalu
induk
melakukan
f65239b51f

+ 11 - 0
lib/mapObjects/CommonConstructors.cpp

@@ -218,6 +218,17 @@ bool CDwellingInstanceConstructor::producesCreature(const CCreature * crea) cons
 	return false;
 }
 
+std::vector<const CCreature *> CDwellingInstanceConstructor::getProducedCreatures() const
+{
+	std::vector<const CCreature *> 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()
 {
 }

+ 2 - 0
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<const CCreature *> getProducedCreatures() const;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 38 - 3
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<const CDwellingInstanceConstructor*>(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};