Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoBallisticPath.c
Go to the documentation of this file.
1 class SCR_AIDecoBallisticPath : DecoratorScripted
2 {
3  // Inputs
4  protected static const string PORT_DISTANCE_COMPENSATION = "DistanceCompensation";
5  protected static const string PORT_TARGET_POSITION = "TargetPos";
6 
7  protected ref TraceParam m_TraceParam;
8 
9 #ifdef WORKBENCH
10  protected ref array<ref Shape> m_aDebugShapes = {};
11 #endif
12 
13  //--------------------------------------------------------------------------------
14  //override void OnInit(AIAgent owner) { }
15 
16  //--------------------------------------------------------------------------------
17  override bool TestFunction(AIAgent owner)
18  {
19  SCR_ChimeraCharacter myCharacter = SCR_ChimeraCharacter.Cast(owner.GetControlledEntity());
20  if (!myCharacter)
21  return false;
22 
23  vector targetPos;
24  GetVariableIn(PORT_TARGET_POSITION, targetPos);
25 
26  vector distanceCompensation;
27  GetVariableIn(PORT_DISTANCE_COMPENSATION, distanceCompensation);
28 
29  vector traceFrom = myCharacter.EyePosition(); // todo For now it only works for character, and not for turrets!
30  vector targetPosCompensated = targetPos + distanceCompensation;
31  vector traceTo = 0.5*(traceFrom + targetPosCompensated);
32 
33 
34  if (!m_TraceParam)
35  m_TraceParam = new TraceParam();
36 
37  m_TraceParam.Start = traceFrom;
38  m_TraceParam.End = traceTo;
39  m_TraceParam.Exclude = myCharacter;
40  m_TraceParam.LayerMask = EPhysicsLayerDefs.Projectile;
41  m_TraceParam.Flags = TraceFlags.ENTS | TraceFlags.OCEAN | TraceFlags.WORLD | TraceFlags.ANY_CONTACT;
42 
43  float traceResult = GetGame().GetWorld().TraceMove(m_TraceParam, null);
44  bool traceHit = traceResult != 1.0;
45 
46 #ifdef WORKBENCH
47  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_DEBUG_SHAPES))
48  {
49  m_aDebugShapes.Clear();
50 
51  int lineColor;
52  if (!traceHit)
53  lineColor = Color.GREEN;
54  else
55  lineColor = Color.RED;
56 
57  vector lineVerts[2];
58  lineVerts[0] = m_TraceParam.Start;
59  lineVerts[1] = m_TraceParam.End;
60  Shape lineShape = Shape.CreateLines(lineColor, ShapeFlags.DEFAULT, lineVerts, 2);
61  m_aDebugShapes.Insert(lineShape);
62 
63  if (traceHit)
64  {
65  vector hitPos = m_TraceParam.Start + traceResult * (m_TraceParam.End - m_TraceParam.Start);
66  Shape sphereShape = Shape.CreateSphere(Color.RED, ShapeFlags.DEFAULT, hitPos, 0.2);
67  m_aDebugShapes.Insert(sphereShape);
68  }
69  }
70 #endif
71 
72  return !traceHit;
73  }
74 
75  //--------------------------------------------------------------------------------
76  override string GetOnHoverDescription() { return "Estimates if projectile ballistic path can reach destination. It is performance heavy, use with some timer."; }
77  override bool VisibleInPalette() { return true; }
78 
79  protected static ref TStringArray s_aVarsIn = { PORT_DISTANCE_COMPENSATION, PORT_TARGET_POSITION };
80  override TStringArray GetVariablesIn() { return s_aVarsIn; }
81 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_AIDecoBallisticPath
Definition: SCR_AIDecoBallisticPath.c:1
m_aDebugShapes
protected ref array< ref Shape > m_aDebugShapes
Definition: SCR_PowerlineGeneratorEntity.c:64
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3