Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetSidePosition.c
Go to the documentation of this file.
1 class SCR_AIGetSidePosition: AITaskScripted
2 {
3  static const string PORT_ENEMY = "Enemy";
4  static const string PORT_ENEMY_POSITION = "EnemyPosition";
5  static const string PORT_KEEP_SIDE = "KeepSide";
6  static const string PORT_POSITION = "PositionOut";
7 
8 
9  [Attribute("4", UIWidgets.EditBox, "Distance from origin")]
10  private float m_fDistance;
11 
12  private int m_iSide = 0;
13  private IEntity m_OwnerEntity;
14 
15  //------------------------------------------------------------------------------------------------
16  override void OnEnter(AIAgent owner)
17  {
18  if (GetVariableType(false, PORT_POSITION) != vector)
19  {
20  NodeError(this, owner, PORT_POSITION + " has to be vector");
21  }
22  m_OwnerEntity = owner.GetControlledEntity();
23  if (!m_OwnerEntity)
24  {
25  NodeError(this, owner, "Owner must be a character!");
26  }
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
31  {
32  vector direction, enemyPos, origin = m_OwnerEntity.GetOrigin();
33  IEntity enemy;
34  bool keepSide;
35  if (!GetVariableIn(PORT_KEEP_SIDE, keepSide) || !keepSide) // if parameter keepSide == true, it will not change side from previous run
36  m_iSide = Math.RandomInt(0,2);
37  // get direction of enemy
38  if (GetVariableIn(PORT_ENEMY, enemy))
39  {
40  direction = vector.Direction(enemy.GetOrigin(), origin);
41  direction.Normalize();
42  }
43  else if (GetVariableIn(PORT_ENEMY_POSITION, enemyPos))
44  {
45  direction = vector.Direction(enemyPos, origin);
46  direction.Normalize();
47 
48  }
49  else
50  direction = m_OwnerEntity.GetYawPitchRoll().AnglesToVector(); // gets normalized forward vector of m_OwnerEntity
51 
52  // make perpendicular vector
53  if (m_iSide == 0)
54  {
55  float x = direction[0];
56  direction[0] = direction[2];
57  direction[2] = -x;
58  }
59  else
60  {
61  float x = direction[0];
62  direction[0] = -direction[2];
63  direction[2] = x;
64  }
65 
66  origin += direction * m_fDistance;
67 
68  SetVariableOut(PORT_POSITION, origin);
69 
70  return ENodeResult.SUCCESS;
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  override bool VisibleInPalette()
75  {
76  return true;
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override protected string GetOnHoverDescription()
81  {
82  return "Returns position from owner entity that is either on random side of the direction towards enemy pos or the keeps the same side as previously if KeepSide is true";
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  protected static ref TStringArray s_aVarsIn = {
87  PORT_ENEMY,
88  PORT_ENEMY_POSITION,
89  PORT_KEEP_SIDE
90  };
91  override TStringArray GetVariablesIn()
92  {
93  return s_aVarsIn;
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  protected static ref TStringArray s_aVarsOut = {
98  PORT_POSITION
99  };
100  override TStringArray GetVariablesOut()
101  {
102  return s_aVarsOut;
103  }
104 };
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
m_fDistance
float m_fDistance
Definition: SCR_AIGroupTargetCluster.c:38
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
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.
SCR_AIGetSidePosition
Definition: SCR_AIGetSidePosition.c:1
m_OwnerEntity
SCR_AIUtilityComponentClass m_OwnerEntity