Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetPosForwardToTarget.c
Go to the documentation of this file.
1 class SCR_AIGetPosForwardToTarget: AITaskScripted
2 {
3  static const string PORT_DISTANCE = "Distance";
4  static const string PORT_RESULT_VECTOR = "ResultVector";
5  static const string PORT_TARGET = "Target";
6 
7  [Attribute("10", UIWidgets.EditBox, PORT_DISTANCE)]
8  float m_Distance;
9 
10  protected vector m_ResultVector;
11  protected IEntity m_Target;
12  protected vector m_vPosition;
13 
14  //------------------------------------------------------------------------------------------------
15  override void OnInit(AIAgent owner)
16  {
17  if (GetVariableType(false, PORT_RESULT_VECTOR) != vector)
18  {
19  NodeError(this, owner, PORT_RESULT_VECTOR + " should be vector");
20  }
21 
22  if (GetVariableIn(PORT_DISTANCE, m_Distance) && (GetVariableType(true, PORT_DISTANCE) != int && GetVariableType(true, PORT_DISTANCE) != float) )
23  {
24  NodeError(this, owner, PORT_DISTANCE + " type should be number");
25  }
26 
27  if (GetVariableType(true, PORT_TARGET) != vector && GetVariableType(true, PORT_TARGET) != IEntity)
28  {
29  NodeError(this, owner, PORT_TARGET + " should be IEntity or vector");
30  }
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
35  {
36  IEntity controlledEntity = owner.GetControlledEntity();
37  if (GetVariableType(true, PORT_TARGET) == vector)
38  {
39  GetVariableIn(PORT_TARGET,m_vPosition);
40  }
41  else if (GetVariableType(true, PORT_TARGET) == IEntity)
42  {
43  GetVariableIn(PORT_TARGET,m_Target);
44  if (!m_Target)
45  return ENodeResult.FAIL;
46 
47  if (m_Target == owner || m_Target == controlledEntity)
48  return NodeError(this, owner, PORT_TARGET + " can't be the same as owner entity");
49  }
50 
51  if (GetVariableType(true, PORT_DISTANCE) == int)
52  {
53  int distance;
54  GetVariableIn(PORT_DISTANCE, distance);
55  m_Distance = distance;
56  }
57  else if (GetVariableType(true, PORT_DISTANCE) == float)
58  {
59  GetVariableIn(PORT_DISTANCE, m_Distance);
60  }
61 
62 
63  vector ownerPos = controlledEntity.GetOrigin();
64 
65  vector pos = m_vPosition;
66  if (m_Target)
67  pos = m_Target.GetOrigin();
68 
69  vector direction = vector.Direction(ownerPos, pos).Normalized();
70  vector forwardVector = ownerPos + ( direction * m_Distance );
71  // snap the vector on ground, for valid location to run to
72  forwardVector[1] = controlledEntity.GetWorld().GetSurfaceY(forwardVector[0], forwardVector[2]);
73 
74  m_ResultVector = forwardVector;
75 
76  SetVariableOut(PORT_RESULT_VECTOR, m_ResultVector);
77 
78  //DrawDebug();
79 
80  return ENodeResult.SUCCESS;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  protected override string GetOnHoverDescription()
85  {
86  return "It will return world position in direction to target away from owner position. Doesn't take navmesh in account. Target can be entity or vector.";
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  void DrawDebug()
91  {
92  int color = ARGB(255, 255, 64, 64);
93 
94  Shape dbgShape = Shape.CreateSphere(color, ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE, vector.Zero, 1.0);
95 
96  vector mat[4];
97  Math3D.MatrixIdentity4(mat);
98  mat[3] = m_ResultVector;
99  dbgShape.SetMatrix(mat);
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override bool VisibleInPalette()
104  {
105  return true;
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  protected static ref TStringArray s_aVarsIn = {
110  PORT_TARGET,
111  PORT_DISTANCE
112  };
113  override TStringArray GetVariablesIn()
114  {
115  return s_aVarsIn;
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected static ref TStringArray s_aVarsOut = {
120  PORT_RESULT_VECTOR
121  };
122  override TStringArray GetVariablesOut()
123  {
124  return s_aVarsOut;
125  }
126 };
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
m_Target
class SCR_AIPolar m_Target
SCR_AIGetPosForwardToTarget
Definition: SCR_AIGetPosForwardToTarget.c:1
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
m_vPosition
vector m_vPosition
Definition: SCR_AITalkRequest.c:23