Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIDecideBehavior.c
Go to the documentation of this file.
1 class SCR_AIDecideBehavior: AITaskScripted
2 {
3  // Update intervals for different LOD values
4  static const int LOD_MAX = 10;
5  static const int LOD_COUNT = LOD_MAX + 1;
6  static float s_aUpdateIntervals[LOD_COUNT] = {
7  0.55, // LOD 0
8  1.3, // 1
9  2.0,
10  2.0, // 3
11  2.0,
12  2.0, // 5
13  2.0,
14  2.0, // 7
15  2.0,
16  2.0, // 9
17  2.0
18  };
19 
20  // Inputs
21  protected static string PORT_UNKNOWN_TARGET = "UnknownTarget";
22 
23  // Outputs
24  protected static string PORT_BEHAVIOR_TREE = "BehaviorTree";
25  protected static string PORT_UPDATE_BEHAVIOR = "UpdateBehavior";
26  protected static string PORT_USE_COMBAT_MOVE = "UseCombatMove";
27  protected static string PORT_UPDATE_INTERVAL = "UpdateInterval";
28 
29  protected SCR_AIBehaviorBase m_PreviousBehavior;
30  protected SCR_AIBehaviorBase m_CurrentBehavior;
31  protected SCR_AIUtilityComponent m_UtilityComponent;
32 
33  protected float m_fRandomDelay_s; // Random delay added to update interval to distribute updated over time more evenly
34 
35  //------------------------------------------------------------------------------------------------
36  override void OnInit(AIAgent owner)
37  {
38  m_UtilityComponent = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
39  if (!m_UtilityComponent)
40  {
41  NodeError(this, owner, "Can't find utility component.");
42  }
43 
44  m_fRandomDelay_s = Math.RandomFloat(0.0, s_aUpdateIntervals[0]);
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
49  {
50  if (!m_UtilityComponent)
51  return ENodeResult.FAIL;
52 
53  BaseTarget unknownTarget;
54  GetVariableIn(PORT_UNKNOWN_TARGET, unknownTarget);
55 
56  m_CurrentBehavior = m_UtilityComponent.EvaluateBehavior(unknownTarget);
57  if (!m_CurrentBehavior || m_CurrentBehavior.m_sBehaviorTree == ResourceName.Empty)
58  {
59  Print("AI: Missing behavior tree in " + m_CurrentBehavior.ToString(), LogLevel.WARNING);
60  return ENodeResult.FAIL;
61  }
62 
63  if (m_PreviousBehavior != m_CurrentBehavior)
64  {
65  SetVariableOut(PORT_BEHAVIOR_TREE, m_CurrentBehavior.m_sBehaviorTree);
66  SetVariableOut(PORT_UPDATE_BEHAVIOR, true);
67  }
68 
69  // m_bUseCombatMove can change at behavior run time
70  SetVariableOut(PORT_USE_COMBAT_MOVE, m_CurrentBehavior.m_bUseCombatMove);
71 
72  // Resolve desired update interval
73  int lod = Math.ClampInt(owner.GetLOD(), 0, LOD_MAX);
74  float updateInterval = s_aUpdateIntervals[lod] + m_fRandomDelay_s;
75  SetVariableOut(PORT_UPDATE_INTERVAL, updateInterval);
76  m_fRandomDelay_s = 0;
77 
78  m_PreviousBehavior = m_CurrentBehavior;
79  return ENodeResult.SUCCESS;
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  protected static ref TStringArray s_aVarsOut = {
84  PORT_BEHAVIOR_TREE,
85  PORT_UPDATE_BEHAVIOR,
86  PORT_USE_COMBAT_MOVE,
87  PORT_UPDATE_INTERVAL
88  };
89  override TStringArray GetVariablesOut()
90  {
91  return s_aVarsOut;
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  protected static ref TStringArray s_aVarsIn = {
96  PORT_UNKNOWN_TARGET
97  };
98  override TStringArray GetVariablesIn()
99  {
100  return s_aVarsIn;
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  override bool VisibleInPalette() {return true;}
105 };
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
BaseTarget
Definition: BaseTarget.c:12
SCR_AIDecideBehavior
Definition: SCR_AIDecideBehavior.c:1
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
m_CurrentBehavior
ref SCR_AIBehaviorBase m_CurrentBehavior
Used for avoiding constant casting, outside of this class use GetCurrentBehavior()
Definition: SCR_AIUtilityComponent.c:19
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1