Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AILookAction.c
Go to the documentation of this file.
1 class SCR_AILookAction : Managed
2 {
3  SCR_AIUtilityComponent m_Utility;
4 
5  vector m_vPosition; // {0,0,0} is an invalid position
6  bool m_bCancelLook; // There was a request to cancel character looking
7  bool m_bRestartLook; // Restart might happen if we have a new request while previous one is still not Complete()
8  float m_fDuration; // How long to look at something
9 
10  static const float PRIO_ENEMY_TARGET = 80;
11  static const float PRIO_UNKNOWN_TARGET = 50;
12  static const float PRIO_DANGER_EVENT = 20;
13 
14  protected float m_fPriority;
15 
16  void SCR_AILookAction(SCR_AIUtilityComponent utility, bool prioritize)
17  {
18  m_Utility = utility;
19  }
20 
21  void LookAt(vector pos, float priority, float duration = 0.8)
22  {
23  #ifdef AI_DEBUG
24  AddDebugMessage(string.Format("LookAt: pos: %1, priority: %2/%3", pos, priority, m_fPriority));
25  #endif
26 
27  if (priority < m_fPriority)
28  return;
29 
30  // Restart if a previous look action is in process
31  if (m_vPosition != vector.Zero)
32  m_bRestartLook = true;
33 
34  m_vPosition = pos;
35  m_fPriority = priority;
36  m_fDuration = duration;
37  }
38 
39  void LookAt(IEntity ent, float priority, float duration = 0.8)
40  {
41  #ifdef AI_DEBUG
42  AddDebugMessage(string.Format("LookAt: ent: %1, priority: %2/%3", ent, priority, m_fPriority));
43  #endif
44 
45  if (priority < m_fPriority && ent)
46  return;
47 
48  // Restart if a previous look action is in process
49  if (m_vPosition != vector.Zero)
50  m_bRestartLook = true;
51 
52  vector min, max;
53  ent.GetBounds(min, max);
54  m_vPosition = ent.GetOrigin() + (min + max) * 0.5;
55  m_fPriority = priority;
56  m_fDuration = duration;
57  }
58 
59  void Cancel()
60  {
61  #ifdef AI_DEBUG
62  AddDebugMessage(string.Format("Cancel"));
63  #endif
64 
65  Complete();
66  m_bCancelLook = true;
67  }
68 
69  void Complete()
70  {
71  #ifdef AI_DEBUG
72  AddDebugMessage(string.Format("Complete"));
73  #endif
74 
75  m_vPosition = vector.Zero;
76  m_fPriority = 0;
77  }
78 
79  #ifdef AI_DEBUG
80  protected void AddDebugMessage(string str, LogLevel logLevel = LogLevel.NORMAL)
81  {
82  SCR_AIInfoBaseComponent infoComp = m_Utility.m_AIInfo;
83  infoComp.AddDebugMessage(str, msgType: EAIDebugMsgType.LOOK, logLevel);
84  }
85  #endif
86 
87  ENodeResult GetLookParametersToNode(SCR_AIGetLookParameters node)
88  {
89  bool canLook = m_vPosition != vector.Zero && (!m_Utility.m_CurrentBehavior || m_Utility.m_CurrentBehavior.m_bAllowLook);
90 
91  node.SetVariableOut(node.PORT_LOOK, canLook);
92 
93  node.SetVariableOut(node.PORT_CANCEL, m_bCancelLook);
94  m_bCancelLook = false; // Reset the flag if it was set
95 
96  node.SetVariableOut(node.PORT_RESTART, m_bRestartLook);
97  m_bRestartLook = false; // Reset the flag if it was set
98 
99  if (canLook)
100  {
101  // Otherwise don't bother clearing variables, time waste
102  node.SetVariableOut(node.PORT_POSITION, m_vPosition);
103  node.SetVariableOut(node.PORT_DURATION, m_fDuration);
104  }
105 
106  return ENodeResult.SUCCESS;
107  }
108 };
SCR_AILookAction
Definition: SCR_AILookAction.c:1
m_fDuration
float m_fDuration
Definition: SendGoalMessage.c:437
EAIDebugMsgType
EAIDebugMsgType
Definition: SCR_AIDebugMessage.c:1
m_fPriority
int m_fPriority
Definition: SCR_DestructionBaseComponent.c:713
m_vPosition
vector m_vPosition
Definition: SCR_AITalkRequest.c:23
SCR_AIGetLookParameters
Definition: SCR_AIGetLookParameters.c:1