Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGetPosForwardToTarget.c
Go to the documentation of this file.
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
11 protected IEntity m_Target;
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 static 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 static override bool VisibleInPalette()
104 {
105 return true;
106 }
107
108 //------------------------------------------------------------------------------------------------
109 protected static ref TStringArray s_aVarsIn = {
110 PORT_TARGET,
111 PORT_DISTANCE
112 };
114 {
115 return s_aVarsIn;
116 }
117
118 //------------------------------------------------------------------------------------------------
119 protected static ref TStringArray s_aVarsOut = {
120 PORT_RESULT_VECTOR
121 };
123 {
124 return s_aVarsOut;
125 }
126};
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition NodeError.c:3
float distance
vector direction
proto external vector GetOrigin()
proto external BaseWorld GetWorld()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
proto external GetVariableType(bool inputPort, string name)
static override string GetOnHoverDescription()
override void OnInit(AIAgent owner)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Instance of created debug visualizer.
Definition Shape.c:14
ENodeResult
Definition ENodeResult.c:13
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385
proto int ARGB(int a, int r, int g, int b)