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}.");