Browse Source

Correct underground terrains. More improvements for connection placement.

DjWarmonger 11 years ago
parent
commit
5fb07ded38
2 changed files with 41 additions and 14 deletions
  1. 30 13
      lib/rmg/CMapGenerator.cpp
  2. 11 1
      lib/rmg/CRmgTemplateZone.cpp

+ 30 - 13
lib/rmg/CMapGenerator.cpp

@@ -251,7 +251,8 @@ void CMapGenerator::createConnections()
 					continue;
 				foreach_neighbour (tile, [&guardPos, tile, &otherZoneTiles, this](int3 &pos)
 				{
-					if (vstd::contains(otherZoneTiles, pos) && !this->isBlocked(pos))
+					//if (vstd::contains(otherZoneTiles, pos) && !this->isBlocked(pos))
+					if (vstd::contains(otherZoneTiles, pos))
 						guardPos = tile;
 				});
 				if (guardPos.valid())
@@ -285,26 +286,42 @@ void CMapGenerator::createConnections()
 				float distanceFromA = posA.dist2d(tile);
 				float distanceFromB = posB.dist2d(tile);
 
-				if (distanceFromA + distanceFromB > std::max(zoneA->getSize() + zoneB->getSize(), distance))
+				if (distanceFromA + distanceFromB > std::max<int>(zoneA->getSize() + zoneB->getSize(), distance))
 					break; //we are too far away to ever connect
 
-				//if zone is underground, gate must lay withing its (reduced) radius
-				if (distanceFromA > 3 && (!posA.z || distanceFromA < zoneA->getSize() - 3) &&
-					distanceFromB > 3 && (!posB.z || distanceFromB < zoneB->getSize() - 3))
+				//if zone is underground, gate must fit within its (reduced) radius
+				if (distanceFromA > 5 && (!posA.z || distanceFromA < zoneA->getSize() - 3) &&
+					distanceFromB > 5 && (!posB.z || distanceFromB < zoneB->getSize() - 3))
 				{
 					otherTile = tile;
 					otherTile.z = posB.z;
 
 					if (vstd::contains(tiles, tile) && vstd::contains(otherZoneTiles, otherTile))
 					{
-						auto gate1 = new CGTeleport;
-						gate1->ID = Obj::SUBTERRANEAN_GATE;
-						gate1->subID = 0;
-						zoneA->placeAndGuardObject(this, gate1, tile, connection.getGuardStrength());
-						auto gate2 = new CGTeleport(*gate1);
-						zoneB->placeAndGuardObject(this, gate2, otherTile, connection.getGuardStrength());
-
-						stop = true; //we are done, go to next connection
+						bool withinZone = true;
+
+						foreach_neighbour (tile, [&withinZone, &tiles](int3 &pos)
+						{
+							if (!vstd::contains(tiles, pos))
+								withinZone = false;
+						});
+						foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles](int3 &pos)
+						{
+							if (!vstd::contains(otherZoneTiles, pos))
+								withinZone = false;
+						});
+
+						if (withinZone)
+						{
+							auto gate1 = new CGTeleport;
+							gate1->ID = Obj::SUBTERRANEAN_GATE;
+							gate1->subID = 0;
+							zoneA->placeAndGuardObject(this, gate1, tile, connection.getGuardStrength());
+							auto gate2 = new CGTeleport(*gate1);
+							zoneB->placeAndGuardObject(this, gate2, otherTile, connection.getGuardStrength());
+
+							stop = true; //we are done, go to next connection
+						}
 					}
 				}
 			}

+ 11 - 1
lib/rmg/CRmgTemplateZone.cpp

@@ -839,7 +839,17 @@ void CRmgTemplateZone::initTerrainType (CMapGenerator* gen)
 	else
 		terrainType = *RandomGeneratorUtil::nextItem(terrainTypes, gen->rand);
 
-	//paint zone with matching terrain
+	//TODO: allow new types of terrain?
+	if (pos.z)
+	{
+		if (terrainType != ETerrainType::LAVA)
+			terrainType = ETerrainType::SUBTERRANEAN;
+	}
+	else
+	{
+		if (terrainType == ETerrainType::SUBTERRANEAN)
+			terrainType = ETerrainType::DIRT;
+	}
 
 	paintZoneTerrain (gen, terrainType);
 }