From b65870f31e5850bd8c6f9e11831bc6a26fafbb7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Sat, 10 Jun 2023 14:57:25 +0200 Subject: [PATCH] A bunch of magic formulas to assure nice balance of blocked areas and obstacles on every template --- lib/rmg/Zone.cpp | 30 +++++++++++++++++++++++-- lib/rmg/modificators/TreasurePlacer.cpp | 12 +++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/rmg/Zone.cpp b/lib/rmg/Zone.cpp index ca0e3e159..eb459d993 100644 --- a/lib/rmg/Zone.cpp +++ b/lib/rmg/Zone.cpp @@ -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) { diff --git a/lib/rmg/modificators/TreasurePlacer.cpp b/lib/rmg/modificators/TreasurePlacer.cpp index 0f575a401..6ffed6e4c 100644 --- a/lib/rmg/modificators/TreasurePlacer.cpp +++ b/lib/rmg/modificators/TreasurePlacer.cpp @@ -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((125.f / totalDensity), 1.0f);