From 1e75efd31148ef807430a47e1e8a8585553aa9d9 Mon Sep 17 00:00:00 2001 From: kanym Date: Mon, 24 Aug 2026 14:03:40 +0200 Subject: [PATCH] Limit troll cave placement-refusal log to near a cave ReportWhyIfRefused fired on every refused placement by any Trol/Skadi player, anywhere in the world - not just cave-related ones - since it only rate-limits on the reason changing, not on location. Gate it on distance to the nearest TrollCave02 mouth (100m) so it still catches a refusal that survives near a cave, without logging every ordinary "can't build here" the rest of the world produces. --- JotunnModStub/RaceCaveBuilding.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/JotunnModStub/RaceCaveBuilding.cs b/JotunnModStub/RaceCaveBuilding.cs index c34cb9d..4e026d7 100644 --- a/JotunnModStub/RaceCaveBuilding.cs +++ b/JotunnModStub/RaceCaveBuilding.cs @@ -33,6 +33,13 @@ namespace RacesOfValheim /// Slack on the location's own radius, since the inside of a cave is not a neat sphere. private const float RadiusSlack = 12f; + /// + /// How far from a troll cave mouth a refusal is still worth logging. Wide enough to catch + /// "standing at the mouth but not detected", far too narrow to catch the ordinary "can't + /// build here" that happens anywhere else in the world and has nothing to do with caves. + /// + private const float ReportRadius = 100f; + private const float CheckInterval = 0.25f; private float nextCheck; @@ -188,22 +195,28 @@ namespace RacesOfValheim string statusName = status.ToString(); if (statusName == "Valid") { lastReport = null; return; } - string report = statusName + "|" + lastHow; - if (report == lastReport) return; - lastReport = report; - // The player's own position and the distance to the nearest troll cave MOUTH are here for // one reason: if a refusal ever survives with "in troll cave=False", these two numbers say // whether the interior sits near its mouth or has been relocated somewhere else entirely - // which is the difference between a tolerance to widen and a wrong idea about the world. Vector3 position = player.transform.position; string nearest = ""; + float distance = float.PositiveInfinity; if (ZoneSystem.instance != null && ZoneSystem.instance.FindClosestLocation("TrollCave02", position, out ZoneSystem.LocationInstance closest)) { - nearest = $"{Vector3.Distance(position, closest.m_position):0} m away at {closest.m_position}"; + distance = Vector3.Distance(position, closest.m_position); + nearest = $"{distance:0} m away at {closest.m_position}"; } + // Not worth logging anywhere but near a cave - otherwise this fires on every ordinary + // "can't build here" a Trol/Skadi player runs into across the rest of the world. + if (!allowing && distance > ReportRadius) { lastReport = null; return; } + + string report = statusName + "|" + lastHow; + if (report == lastReport) return; + lastReport = report; + Jotunn.Logger.LogInfo($"[Races] Placement refused: {statusName} " + $"(in troll cave={allowing}, pieces flipped={flipped.Count}). " + $"Detection said: {lastHow}. Player at {position}; nearest TrollCave02 mouth {nearest}.");