소스 검색

- Added monoliths between remote zones
- Fixed land connections between zones, now they're generated correctly.

DjWarmonger 11 년 전
부모
커밋
aee748d8d6
8개의 변경된 파일45개의 추가작업 그리고 22개의 파일을 삭제
  1. 3 3
      AI/VCAI/VCAI.cpp
  2. 4 4
      lib/CObjectHandler.cpp
  3. 3 3
      lib/GameConstants.h
  4. 3 3
      lib/mapping/MapFormatH3M.cpp
  5. 6 1
      lib/rmg/CMapGenerator.cpp
  6. 5 1
      lib/rmg/CMapGenerator.h
  7. 19 7
      lib/rmg/CRmgTemplateZone.cpp
  8. 2 0
      lib/rmg/CRmgTemplateZone.h

+ 3 - 3
AI/VCAI/VCAI.cpp

@@ -2845,9 +2845,9 @@ bool shouldVisit(HeroPtr h, const CGObjectInstance * obj)
 			}
 			return false;
 		}
-		case Obj::MONOLITH1:
-		case Obj::MONOLITH2:
-		case Obj::MONOLITH3:
+		case Obj::MONOLITH_ONE_WAY_ENTRANCE:
+		case Obj::MONOLITH_ONE_WAY_EXIT:
+		case Obj::MONOLITH_TWO_WAY:
 		case Obj::WHIRLPOOL:
 			//TODO: mechanism for handling monoliths
 			return false;

+ 4 - 4
lib/CObjectHandler.cpp

@@ -4071,11 +4071,11 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
 	ObjectInstanceID destinationid;
 	switch(ID)
 	{
-	case Obj::MONOLITH1: //one way - find corresponding exit monolith
+	case Obj::MONOLITH_ONE_WAY_ENTRANCE: //one way - find corresponding exit monolith
 	{
-		if(vstd::contains(objs,Obj::MONOLITH2) && vstd::contains(objs[Obj::MONOLITH2],subID) && objs[Obj::MONOLITH2][subID].size())
+		if(vstd::contains(objs,Obj::MONOLITH_ONE_WAY_EXIT) && vstd::contains(objs[Obj::MONOLITH_ONE_WAY_EXIT],subID) && objs[Obj::MONOLITH_ONE_WAY_EXIT][subID].size())
 		{
-			destinationid = *RandomGeneratorUtil::nextItem(objs[Obj::MONOLITH2][subID], cb->gameState()->getRandomGenerator());
+			destinationid = *RandomGeneratorUtil::nextItem(objs[Obj::MONOLITH_ONE_WAY_EXIT][subID], cb->gameState()->getRandomGenerator());
 		}
 		else
 		{
@@ -4083,7 +4083,7 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
 		}
 		break;
 	}
-	case Obj::MONOLITH3://two way monolith - pick any other one
+	case Obj::MONOLITH_TWO_WAY://two way monolith - pick any other one
 	case Obj::WHIRLPOOL: //Whirlpool
 		if(vstd::contains(objs,ID) && vstd::contains(objs[ID],subID) && objs[ID][subID].size()>1)
 		{

+ 3 - 3
lib/GameConstants.h

@@ -507,9 +507,9 @@ public:
 		LEAN_TO = 39,
 		LIBRARY_OF_ENLIGHTENMENT = 41,
 		LIGHTHOUSE = 42,
-		MONOLITH1 = 43,
-		MONOLITH2 = 44,
-		MONOLITH3 = 45,
+		MONOLITH_ONE_WAY_ENTRANCE = 43,
+		MONOLITH_ONE_WAY_EXIT = 44,
+		MONOLITH_TWO_WAY = 45,
 		MAGIC_PLAINS1 = 46,
 		SCHOOL_OF_MAGIC = 47,
 		MAGIC_SPRING = 48,

+ 3 - 3
lib/mapping/MapFormatH3M.cpp

@@ -1084,9 +1084,9 @@ void CMapLoaderH3M::readObjects()
 				nobj = new CGVisitableOPW();
 				break;
 			}
-		case Obj::MONOLITH1:
-		case Obj::MONOLITH2:
-		case Obj::MONOLITH3:
+		case Obj::MONOLITH_ONE_WAY_ENTRANCE:
+		case Obj::MONOLITH_ONE_WAY_EXIT:
+		case Obj::MONOLITH_TWO_WAY:
 		case Obj::SUBTERRANEAN_GATE:
 		case Obj::WHIRLPOOL:
 			{

+ 6 - 1
lib/rmg/CMapGenerator.cpp

@@ -26,7 +26,7 @@ void CMapGenerator::foreach_neighbour(const int3 &pos, std::function<void(int3&
 
 
 CMapGenerator::CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int randomSeed /*= std::time(nullptr)*/) :
-	mapGenOptions(mapGenOptions), randomSeed(randomSeed)
+	mapGenOptions(mapGenOptions), randomSeed(randomSeed), monolithIndex(0)
 {
 	rand.setSeed(randomSeed);
 }
@@ -306,4 +306,9 @@ int CMapGenerator::getNearestObjectDistance(const int3 &tile) const
 		throw  rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
 
 	return tiles[tile.x][tile.y][tile.z].getNearestObjectDistance();
+}
+
+int CMapGenerator::getNextMonlithIndex()
+{
+	return monolithIndex++;
 }

+ 5 - 1
lib/rmg/CMapGenerator.h

@@ -74,13 +74,17 @@ public:
 	CTileInfo getTile(int3 tile) const;
 
 	int getNearestObjectDistance(const int3 &tile) const; 
-	void setNearestObjectDistance(int3 &tile, int value); 
+	void setNearestObjectDistance(int3 &tile, int value);
+
+	int getNextMonlithIndex();
 
 private:
 	std::map<TRmgTemplateZoneId, CRmgTemplateZone*> zones;
 
 	CTileInfo*** tiles;
 
+	int monolithIndex;
+
 	/// Generation methods
 	std::string getMapDescription() const;
 	void addPlayerInfo();

+ 19 - 7
lib/rmg/CRmgTemplateZone.cpp

@@ -349,7 +349,7 @@ void CRmgTemplateZone::createConnections(CMapGenerator* gen)
 			});
 			if (guardPos.valid())
 			{
-				gen->setOccupied (pos, ETileType::FREE); //TODO: place monster here
+				gen->setOccupied (guardPos, ETileType::FREE); //TODO: place monster here
 				//zones can make paths only in their own area
 				this->crunchPath (gen, guardPos, this->getPos(), this->getId()); //make connection towards our zone center
 				gen->getZones()[connection]->crunchPath (gen, guardPos, otherZoneCenter, connection); //make connection towards other zone center
@@ -357,7 +357,16 @@ void CRmgTemplateZone::createConnections(CMapGenerator* gen)
 			}
 		}
 		if (!guardPos.valid())
-			logGlobal->warnStream() << boost::format ("Did not find connection between zones %d and %d") %getId() %connection;
+		{
+			auto teleport1 = new CGTeleport;
+			teleport1->ID = Obj::MONOLITH_TWO_WAY;
+			teleport1->subID = gen->getNextMonlithIndex();
+
+			auto teleport2 = new CGTeleport(*teleport1);
+
+			addRequiredObject (teleport1);
+			gen->getZones()[connection]->addRequiredObject(teleport2);
+		}		
 	}
 }
 
@@ -440,10 +449,13 @@ do not leave zone border
 	return result;
 }
 
-bool CRmgTemplateZone::fill(CMapGenerator* gen)
+void CRmgTemplateZone::addRequiredObject(CGObjectInstance * obj)
 {
-	std::vector<CGObjectInstance*> required_objects;
+	requiredObjects.push_back(obj);
+}
 
+bool CRmgTemplateZone::fill(CMapGenerator* gen)
+{
 	int townId = 0;
 
 	if ((type == ETemplateZoneType::CPU_START) || (type == ETemplateZoneType::PLAYER_START))
@@ -478,7 +490,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
 			playerInfo.posOfMainTown = town->pos - int3(2, 0, 0);
 			playerInfo.generateHeroAtMainTown = true;
 
-			//required_objects.push_back(town);
+			//requiredObjects.push_back(town);
 
 			std::vector<Res::ERes> required_mines;
 			required_mines.push_back(Res::ERes::WOOD);
@@ -491,7 +503,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
 				mine->subID = static_cast<si32>(res);
 				mine->producedResource = res;
 				mine->producedQuantity = mine->defaultResProduction();
-				required_objects.push_back(mine);
+				requiredObjects.push_back(mine);
 			}
 		}
 		else
@@ -515,7 +527,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
 	gen->editManager->drawTerrain(VLC->townh->factions[townId]->nativeTerrain, &gen->rand);
 
 	logGlobal->infoStream() << "Creating required objects";
-	for(const auto &obj : required_objects)
+	for(const auto &obj : requiredObjects)
 	{
 		int3 pos;
 		logGlobal->traceStream() << "Looking for place";

+ 2 - 0
lib/rmg/CRmgTemplateZone.h

@@ -112,6 +112,7 @@ public:
 	void addTile (const int3 &pos);
 	std::set<int3> getTileInfo () const;
 
+	void addRequiredObject(CGObjectInstance * obj);
 	bool fill(CMapGenerator* gen);
 	void createConnections(CMapGenerator* gen);
 	void createBorder(CMapGenerator* gen);
@@ -135,6 +136,7 @@ private:
 
 	//content info
 	std::vector<int3> shape; //TODO: remove
+	std::vector<CGObjectInstance*> requiredObjects;
 	std::vector<CGObjectInstance*> objects;
 
 	//placement info