瀏覽代碼

A bunch of magic formulas to assure nice balance of blocked areas and obstacles on every template

Tomasz Zieliński 2 年之前
父節點
當前提交
b65870f31e
共有 2 個文件被更改,包括 35 次插入7 次删除
  1. 28 2
      lib/rmg/Zone.cpp
  2. 7 5
      lib/rmg/modificators/TreasurePlacer.cpp

+ 28 - 2
lib/rmg/Zone.cpp

@@ -203,8 +203,34 @@ void Zone::fractalize()
 	rmg::Area possibleTiles(dAreaPossible);
 	rmg::Area possibleTiles(dAreaPossible);
 	rmg::Area tilesToIgnore; //will be erased in this iteration
 	rmg::Area tilesToIgnore; //will be erased in this iteration
 
 
-	const float minDistance = 10 * 10; //squared
-	float blockDistance = minDistance * 0.25f;
+	//Squared
+	float minDistance = 10 * 10;
+	float spanFactor = (pos.z ? 0.25 : 0.5f); //Narrower passages in the Underground
+
+	int treasureValue = 0;
+	int treasureDensity = 0;
+	for (auto t : treasureInfo)
+	{
+		treasureValue += ((t.min + t.max) / 2) * t.density / 1000.f; //Thousands
+		treasureDensity += t.density;
+	}
+
+	if (treasureValue > 100)
+	{
+		//Less obstacles - max span is 1 (no obstacles)
+		spanFactor = 1.0f - ((std::max(0, (1000 - treasureValue)) / 1000.f) * (1 - spanFactor));
+	}
+	else if (treasureValue < 100)
+	{
+		//Dense obstacles
+		spanFactor *= (treasureValue / 100.f);
+		vstd::amax(spanFactor, 0.2f);
+	}
+	if (treasureDensity <= 10)
+	{
+		vstd::amin(spanFactor, 0.25f); //Add extra obstacles to fill up space
+	}
+	float blockDistance = minDistance * spanFactor; //More obstacles in the Underground
 	
 	
 	if(type != ETemplateZoneType::JUNCTION)
 	if(type != ETemplateZoneType::JUNCTION)
 	{
 	{

+ 7 - 5
lib/rmg/modificators/TreasurePlacer.cpp

@@ -736,7 +736,7 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
 	size_t size = 0;
 	size_t size = 0;
 	{
 	{
 		Zone::Lock lock(zone.areaMutex);
 		Zone::Lock lock(zone.areaMutex);
-		size = zone.areaPossible().getTiles().size();
+		size = zone.getArea().getTiles().size();
 	}
 	}
 
 
 	int totalDensity = 0;
 	int totalDensity = 0;
@@ -753,10 +753,12 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
 
 
 		totalDensity += t.density;
 		totalDensity += t.density;
 
 
-		const size_t count = size * t.density / 300;
-
-		//treasure density is inversely proportional to zone size but must be scaled back to map size
-		//also, normalize it to zone count - higher count means relatively smaller zones
+		size_t count = size * t.density / 500;
+		const int averageValue = (t.min + t.max) / 2;
+		if (averageValue > 10000) //Will surely be guarded => larger
+		{
+			vstd::amin(count, size * (10.f/500) / (std::sqrt((float)averageValue / 10000)));
+		}
 		
 		
 		//this is squared distance for optimization purposes
 		//this is squared distance for optimization purposes
 		const float minDistance = std::max<float>((125.f / totalDensity), 1.0f);
 		const float minDistance = std::max<float>((125.f / totalDensity), 1.0f);