Merge branch 'limit-cave-build-debug-log' into main

This commit is contained in:
kanym 2026-08-24 14:10:24 +02:00
commit 3352e84438

View file

@ -33,6 +33,13 @@ namespace RacesOfValheim
/// <summary>Slack on the location's own radius, since the inside of a cave is not a neat sphere.</summary>
private const float RadiusSlack = 12f;
/// <summary>
/// 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.
/// </summary>
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 = "<none in this world>";
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}.");