Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AICombatMoveState.c
Go to the documentation of this file.
2 {
3  IDLE, // There was never a request
4  EXECUTING, // Executing a request
5  SUCCESS, // Last request succeeded
6  FAIL, // Last request failed, see fail reason
7  CANCELED // It was aborted while running
8 }
9 
10 enum SCR_EAICombatMoveRequestFailReason
11 {
12  NONE,
13  UNDEFINED,
16 }
17 
18 class SCR_AICombatMoveState
19 {
20  // Check VerifyCurrentCover
21  protected static const float DISTANCE_IN_COVER_MAX_SQ = 1.0;
22 
23  protected ref SCR_AICoverLock m_CoverLock; // Cover assigned to us. But it doesn't mean we are at the cover position (yet).
24 
26 
27  bool m_bInCover; // True if we are in cover
28  bool m_bExposedInCover; // If in cover, false means we are hidden behind cover completely, true means we are exposed and can shoot
29  bool m_bAimAtTarget = true; // True if we are allowed to aim at target due to combat movement constraints. Enabled at start!
30 
31  // Timers
32  float m_fTimerRequest_s; // Time since last request
33  float m_fTimerInCover_s; // Counts up when we are in cover
34  float m_fTimerStopped_s; // Counts up when we are not moving, no matter if in cover or not
35 
36 
37  //----------------------------------------------------------------
39  {
40  if (m_CoverLock)
41  m_CoverLock.Release();
42 
43  m_CoverLock = newCover;
44  }
45 
46  //----------------------------------------------------------------
47  void ReleaseCover()
48  {
49  // m_CoverLock might be still referenced by something else,
50  // Thus if we only unref it, it might still be not destroyed.
51  // That's why we also release it manually here.
52 
53  if (m_CoverLock)
54  m_CoverLock.Release();
55  m_CoverLock = null;
56  m_bInCover = false;
57  }
58 
59  //----------------------------------------------------------------
61  {
62  // mark old request as cancelled if it was running, in case something else needs to know its state
63  if (m_Request && m_Request.m_eState == SCR_EAICombatMoveRequestState.EXECUTING)
64  m_Request.m_eState = SCR_EAICombatMoveRequestState.CANCELED;
65 
66  m_Request = request; // Old request is unreferenced here
67  }
68 
69  //----------------------------------------------------------------
73  {
74  if (m_Request && m_Request.m_eState == SCR_EAICombatMoveRequestState.EXECUTING)
75  m_Request.m_eState = SCR_EAICombatMoveRequestState.CANCELED;
76 
77  m_Request = null;
78  }
79 
80  //----------------------------------------------------------------
81  void EnableAiming(bool enable)
82  {
83  m_bAimAtTarget = enable;
84  }
85 
86  //----------------------------------------------------------------
89  void VerifyCurrentCover(vector myPos)
90  {
91  if (m_CoverLock && m_bInCover)
92  {
93  if (vector.DistanceSq(myPos, m_CoverLock.GetPosition()) > DISTANCE_IN_COVER_MAX_SQ)
94  {
95  ReleaseCover();
96  }
97  }
98  }
99 
100 
101  //-------------------------------------------------------------------------------
102  // Getters
103 
104  bool IsMoving()
105  {
106  // Moving when executing a MOVE request
108  }
109 
110  bool IsMoving(SCR_EAICombatMoveReason eReason)
111  {
113  return rqMove && rqMove.m_eState == SCR_EAICombatMoveRequestState.EXECUTING && rqMove.m_eReason == eReason;
114  }
115 
117  {
119  return moveRequest && moveRequest.m_eState == SCR_EAICombatMoveRequestState.EXECUTING && m_CoverLock;
120  }
121 
123  {
124  return m_bInCover && m_CoverLock && m_CoverLock.IsValid();
125  }
126 
128  {
129  return m_bInCover && !m_bExposedInCover && m_CoverLock && m_CoverLock.IsValid();
130  }
131 
133  {
134  return m_Request && m_Request.m_eState == SCR_EAICombatMoveRequestState.EXECUTING;
135  }
136 
138  {
139  return m_Request;
140  }
141 
143  {
144  return m_CoverLock;
145  }
146 
148  {
149  return m_CoverLock && m_CoverLock.IsValid();
150  }
151 
152 
153 
154  //-------------------------------------------------------------------------------
155  // Helper methods for applying trivial requests
156 
157  //----------------------------------------------------------------
159  {
161 
162  rq.m_eStance = stance;
163  rq.m_bAimAtTarget = true;
164  rq.m_bAimAtTargetEnd = true;
165 
166  ApplyNewRequest(rq);
167  }
168 
169  //----------------------------------------------------------------
171  {
173 
174  rq.m_bExposedInCover = exposed;
175  rq.m_bAimAtTarget = true;
176  rq.m_bAimAtTargetEnd = true;
177 
178  ApplyNewRequest(rq);
179  }
180 }
m_Request
protected ref SCR_AICombatMoveRequestBase m_Request
Definition: SCR_AICombatMoveState.c:25
SUCCESS
@ SUCCESS
Definition: SCR_AICombatMoveState.c:5
IsInValidCover
bool IsInValidCover()
Definition: SCR_AICombatMoveState.c:122
CancelRequest
void CancelRequest()
Definition: SCR_AICombatMoveState.c:72
IsMoving
bool IsMoving()
Definition: SCR_AICombatMoveState.c:104
ApplyNewRequest
void ApplyNewRequest(notnull SCR_AICombatMoveRequestBase request)
Definition: SCR_AICombatMoveState.c:60
m_bExposedInCover
bool m_bExposedInCover
Definition: SCR_AICombatMoveState.c:28
UNDEFINED
enum SCR_EAICombatMoveRequestState UNDEFINED
m_bAimAtTarget
bool m_bAimAtTarget
Definition: SCR_AICombatMoveState.c:29
ECharacterStance
ECharacterStance
Definition: ECharacterStance.c:12
SCR_AICombatMoveRequestBase
Definition: SCR_AICombatMoveRequest.c:37
EXECUTING
@ EXECUTING
Definition: SCR_AICombatMoveState.c:4
COVER_NOT_FOUND
enum SCR_EAICombatMoveRequestState COVER_NOT_FOUND
GetRequest
SCR_AICombatMoveRequestBase GetRequest()
Definition: SCR_AICombatMoveState.c:137
MOVEMENT_FAILED
enum SCR_EAICombatMoveRequestState MOVEMENT_FAILED
ApplyRequestChangeStanceInCover
void ApplyRequestChangeStanceInCover(bool exposed)
Definition: SCR_AICombatMoveState.c:170
ApplyRequestChangeStanceOutsideCover
void ApplyRequestChangeStanceOutsideCover(ECharacterStance stance)
Definition: SCR_AICombatMoveState.c:158
IsAssignedCoverValid
bool IsAssignedCoverValid()
Definition: SCR_AICombatMoveState.c:147
SCR_AICombatMoveRequest_ChangeStanceInCover
Definition: SCR_AICombatMoveRequest.c:123
SCR_AICoverLock
Definition: SCR_AICoverLock.c:19
ReleaseCover
void ReleaseCover()
Definition: SCR_AICombatMoveState.c:47
NONE
enum SCR_EAICombatMoveRequestState NONE
VerifyCurrentCover
void VerifyCurrentCover(vector myPos)
Definition: SCR_AICombatMoveState.c:89
m_CoverLock
protected ref SCR_AICoverLock m_CoverLock
Definition: SCR_AICombatMoveState.c:23
IDLE
@ IDLE
Definition: SCR_AICombatMoveState.c:3
SCR_AICombatMoveRequest_ChangeStance
void SCR_AICombatMoveRequest_ChangeStance()
Definition: SCR_AICombatMoveRequest.c:138
SCR_AICombatMoveRequest_Move
Definition: SCR_AICombatMoveRequest.c:78
EnableAiming
void EnableAiming(bool enable)
Definition: SCR_AICombatMoveState.c:81
DISTANCE_IN_COVER_MAX_SQ
enum SCR_EAICombatMoveRequestState DISTANCE_IN_COVER_MAX_SQ
CANCELED
@ CANCELED
Definition: SCR_AICombatMoveState.c:7
m_fTimerInCover_s
float m_fTimerInCover_s
Definition: SCR_AICombatMoveState.c:33
FAIL
@ FAIL
Definition: SCR_AICombatMoveState.c:6
IsExecutingRequest
bool IsExecutingRequest()
Definition: SCR_AICombatMoveState.c:132
GetAssignedCover
SCR_AICoverLock GetAssignedCover()
Definition: SCR_AICombatMoveState.c:142
m_fTimerStopped_s
float m_fTimerStopped_s
Definition: SCR_AICombatMoveState.c:34
m_fTimerRequest_s
float m_fTimerRequest_s
Definition: SCR_AICombatMoveState.c:32
SCR_EAICombatMoveRequestState
SCR_EAICombatMoveRequestState
Definition: SCR_AICombatMoveState.c:1
IsMovingToCover
bool IsMovingToCover()
Definition: SCR_AICombatMoveState.c:116
AssignCover
void AssignCover(SCR_AICoverLock newCover)
Definition: SCR_AICombatMoveState.c:38
IsHidingInValidCover
bool IsHidingInValidCover()
Definition: SCR_AICombatMoveState.c:127
m_bInCover
bool m_bInCover
Definition: SCR_AICombatMoveState.c:27