Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecoDistanceHysteresis.c
Go to the documentation of this file.
1 // if you want this node to abort subtree when conditions change, you must specify abort condition!
2 // normal mode: smaller than low distance -> Condition TRUE
3 // negate mode: bigger than high distance -> Condition TRUE
4 class SCR_AIDecoDistanceHysteresis : DecoratorScripted
5 {
6  static const string PORT_ENTITY_IN = "EntityIn";
7  static const string PORT_POSITION_IN = "PositionIn";
8 
9  [Attribute("", UIWidgets.EditBox, "Low boundary distance")]
10  private float m_lowBoundary;
11 
12  [Attribute("", UIWidgets.EditBox, "High boundary distance")]
13  private float m_highBoundary;
14 
15  private bool m_lastValueOfGate = false;
16 
17 /*
18  //------------------------------------------------------------------------------------------------
19  override void OnInit(AIAgent owner)
20  {
21  // make sure it works when uncomenting
22 
23  if (GetVariableType(true, PORT_POSITION_IN) == vector || GetVariableType(true, PORT_ENTITY_IN) == IEntity)
24  {
25  NodeError(this, owner, PORT_POSITION_IN + "(vector) or " + PORT_ENTITY_IN + "(IEntity) has to be provided");
26  }
27 
28  //TODO uncoment OnInit
29  }
30 */
31 
32  //------------------------------------------------------------------------------------------------
33  protected override bool TestFunction(AIAgent owner)
34  {
35  vector ownerPos,destinationPos;
36  IEntity entity;
37  bool openGate = false;
38 
39  AIGroup ownerIsGroup = AIGroup.Cast(owner);
40  if (ownerIsGroup)
41  ownerPos = ownerIsGroup.GetLeaderEntity().GetOrigin();
42  else
43  ownerPos = owner.GetControlledEntity().GetOrigin();
44 
45 
46  if (!GetVariableIn(PORT_ENTITY_IN, entity))
47  {
48  if (!GetVariableIn(PORT_POSITION_IN,destinationPos))
49  return false;
50  }
51  else if (!entity)
52  return false;
53  else
54  destinationPos = entity.GetOrigin();
55 
56  float dist = vector.Distance(destinationPos, ownerPos);
57  if ( dist < m_lowBoundary)
58  {
59  openGate = true;
60  m_lastValueOfGate = openGate;
61  }
62  else if ( dist > m_highBoundary)
63  {
64  openGate = false;
65  m_lastValueOfGate = openGate;
66  }
67  else
68  {
69  openGate = m_lastValueOfGate;
70  }
71 
72  return openGate;
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  protected override bool VisibleInPalette()
77  {
78  return true;
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  protected override string GetOnHoverDescription()
83  {
84  return "SCR_AIDecoDistanceHysteresis: Checks distance to entity within boundaries and in circumference it returns value according to history of moving";
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  protected static ref TStringArray s_aVarsIn = {
89  PORT_ENTITY_IN,
90  PORT_POSITION_IN
91  };
92  protected override TStringArray GetVariablesIn()
93  {
94  return s_aVarsIn;
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  protected override string GetNodeMiddleText()
99  {
100  string enumToString;
101 
102  return "Low boundary: " + m_lowBoundary.ToString() + "\n" + "High boundary: " + m_highBoundary.ToString();
103  }
104 };
SCR_AIDecoDistanceHysteresis
Definition: SCR_AIDecoDistanceHysteresis.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.