Files
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

112 lines
4.6 KiB
Diff

--- /dev/null
+++ b/addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeRandomRadiusTrace.c
@@ -0,0 +1,108 @@
+// Explicit Workbench diagnostic only. Preserve every native superclass result,
+// output and random draw; this observes zero-radius callers without correcting them.
+#ifdef WORKBENCH
+class ERR_NativeRandomRadiusTrace
+{
+ protected static bool s_Checked;
+ protected static bool s_Enabled;
+ protected static int s_Count;
+ static bool CanTrace()
+ {
+ if (!s_Checked)
+ {
+ s_Checked = true;
+ string value;
+ s_Enabled = System.GetCLIParam("errTraceRandomRadius", value) && value == "1";
+ }
+ return s_Enabled && s_Count < 16;
+ }
+ static void Log(string context, AIAgent owner, float inner, float outer, string details, Node node = null)
+ {
+ if (!CanTrace()) return;
+ s_Count++;
+ string nodeStack;
+ if (node) node.GetCallstackStr(nodeStack);
+ PrintFormat("ERR ZERO RADIUS TRACE: sample=%1/16 class=%2 owner=%3 inner=%4 outer=%5 %6 nodeStack=%7", s_Count, context, owner, inner, outer, details, nodeStack);
+ Debug.DumpStack();
+ }
+}
+
+modded class SCR_AIGetRandomPoint
+{
+ override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
+ {
+ ENodeResult result = super.EOnTaskSimulate(owner, dt);
+ // The superclass updates these fields from the actual waypoint/input ports.
+ if (ERR_NativeRandomRadiusTrace.CanTrace() && result == ENodeResult.SUCCESS && m_ExclusionRadius == 0 && m_Radius == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_AIGetRandomPoint", owner, m_ExclusionRadius, m_Radius, string.Format("phase=after-success node=%1", this), this);
+ return result;
+ }
+}
+
+modded class SCR_AIGetRandomLookPosition
+{
+ override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
+ {
+ if (ERR_NativeRandomRadiusTrace.CanTrace() && owner)
+ {
+ IEntity controlledEntity = owner.GetControlledEntity();
+ vector inPos;
+ if (controlledEntity && GetVariableIn(PORT_IN_POS, inPos))
+ {
+ float distance = vector.Distance(controlledEntity.GetOrigin(), inPos);
+ float radius = distance * m_fTangent;
+ if (radius == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_AIGetRandomLookPosition", owner, 0, radius, string.Format("phase=before-super node=%1 entity=%2 inPos=%3 distance=%4 tangent=%5", this, controlledEntity, inPos, distance, m_fTangent), this);
+ }
+ }
+ return super.EOnTaskSimulate(owner, dt);
+ }
+}
+
+modded class SCR_AICalculateNextCombatMovePos
+{
+ override protected vector RandomizeDestinationPos(float distance, vector centerPos)
+ {
+ if (ERR_NativeRandomRadiusTrace.CanTrace())
+ {
+ float radius = 0.1 * distance;
+ if (radius == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_AICalculateNextCombatMovePos", null, 0, radius, string.Format("phase=before-super node=%1 center=%2 distance=%3 scale=0.1", this, centerPos, distance), this);
+ }
+ return super.RandomizeDestinationPos(distance, centerPos);
+ }
+}
+
+modded class SCR_AIGetRandomPointWithExclude
+{
+ override protected bool FindPosition2D(out vector randomPos, vector randomSphereOrigin, float randomSphereRadius, vector excludeSphereOrigin = vector.Zero, float excludeRadius = 0, int iterationCount = 50)
+ {
+ if (ERR_NativeRandomRadiusTrace.CanTrace())
+ {
+ if (randomSphereOrigin == excludeSphereOrigin || excludeRadius < 1.0e-8)
+ {
+ if (excludeRadius == 0 && randomSphereRadius == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_AIGetRandomPointWithExclude", null, excludeRadius, randomSphereRadius, string.Format("phase=before-super branch=direct node=%1 origin=%2 excludedOrigin=%3 excludeRadius=%4 iterations=%5", this, randomSphereOrigin, excludeSphereOrigin, excludeRadius, iterationCount), this);
+ }
+ else if (iterationCount > 0 && randomSphereRadius == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_AIGetRandomPointWithExclude", null, 0, randomSphereRadius, string.Format("phase=before-super branch=iterative node=%1 origin=%2 excludedOrigin=%3 excludeRadius=%4 iterations=%5", this, randomSphereOrigin, excludeSphereOrigin, excludeRadius, iterationCount), this);
+ }
+ return super.FindPosition2D(randomPos, randomSphereOrigin, randomSphereRadius, excludeSphereOrigin, excludeRadius, iterationCount);
+ }
+}
+
+modded class SCR_RecoilCameraShakeParams
+{
+ override protected vector RandomVectorSphere(vector min, vector max, bool uniform = true)
+ {
+ if (ERR_NativeRandomRadiusTrace.CanTrace())
+ {
+ float inner = min.Length();
+ float outer = max.Length();
+ if (inner == 0 && outer == 0)
+ ERR_NativeRandomRadiusTrace.Log("SCR_RecoilCameraShakeParams", null, inner, outer, string.Format("phase=before-super params=%1 min=%2 max=%3 uniform=%4", this, min, max, uniform));
+ }
+ return super.RandomVectorSphere(min, max, uniform);
+ }
+}
+#endif