mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
A bunch of magic formulas to assure nice balance of blocked areas and obstacles on every template
This commit is contained in:
@@ -203,8 +203,34 @@ void Zone::fractalize()
|
||||
rmg::Area possibleTiles(dAreaPossible);
|
||||
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)
|
||||
{
|
||||
|
@@ -736,7 +736,7 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
|
||||
size_t size = 0;
|
||||
{
|
||||
Zone::Lock lock(zone.areaMutex);
|
||||
size = zone.areaPossible().getTiles().size();
|
||||
size = zone.getArea().getTiles().size();
|
||||
}
|
||||
|
||||
int totalDensity = 0;
|
||||
@@ -753,10 +753,12 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
|
||||
|
||||
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
|
||||
const float minDistance = std::max<float>((125.f / totalDensity), 1.0f);
|
||||
|
Reference in New Issue
Block a user