Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AICombatMoveLogic_MoveFromGrenade.c
Go to the documentation of this file.
2 {
3  // Inputs
4  protected static const string PORT_POSITION = "Position";
5 
6  // Outputs
7  protected static const string PORT_COMPLETE_ACTION = "CompleteAction";
8 
9  protected SCR_AICombatMoveState m_State;
10 
11  //--------------------------------------------------------------------------------------------
12  override void OnInit(AIAgent owner)
13  {
14  SCR_AIUtilityComponent utility = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
15  if (utility)
16  m_State = utility.m_CombatMoveState;
17  }
18 
19 
20  //--------------------------------------------------------------------------------------------
21  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
22  {
23  if (!m_State)
24  return ENodeResult.FAIL;
25 
26  vector threatPos;
27  GetVariableIn(PORT_POSITION, threatPos);
28  if (threatPos == vector.Zero)
29  return ENodeResult.FAIL;
30 
31  bool completeAction = false;
32  CombatMoveLogic(threatPos, completeAction);
33 
34  SetVariableOut(PORT_COMPLETE_ACTION, completeAction);
35 
36  return ENodeResult.SUCCESS;
37  }
38 
39  //--------------------------------------------------------------------------------------------
40  void CombatMoveLogic(vector threatPos, out bool outCompleteAction)
41  {
42  if (!m_State)
43  return;
44 
45  bool completeAction = false;
46 
47  if (ConditionPushMoveRequest(threatPos))
48  {
50 
51  rq.m_eReason = SCR_EAICombatMoveReason.MOVE_FROM_DANGER;
52 
53  rq.m_vTargetPos = threatPos;
54  rq.m_vMovePos = rq.m_vTargetPos;
55  rq.m_bTryFindCover = true;
56  rq.m_bUseCoverSearchDirectivity = true;
57  rq.m_bCheckCoverVisibility = false;
58  rq.m_bFailIfNoCover = false;
59  rq.m_eStanceMoving = ECharacterStance.STAND;
60  rq.m_eStanceEnd = ECharacterStance.CROUCH;
61  rq.m_eMovementType = EMovementType.SPRINT;
62  rq.m_fCoverSearchDistMax = 15;
63  rq.m_fCoverSearchDistMin = 4;
64  rq.m_fMoveDistance = rq.m_fCoverSearchDistMax;
65  rq.m_eDirection = SCR_EAICombatMoveDirection.BACKWARD;
66  rq.m_fCoverSearchSectorHalfAngleRad = Math.PI_HALF; // 90 deg
67 
68  rq.m_bAimAtTarget = false;
69  rq.m_bAimAtTargetEnd = true;
70 
71  m_State.ApplyNewRequest(rq);
72  }
73  else if (m_State.m_bInCover && m_State.IsAssignedCoverValid() && IsCoverSafeAgainstGrenade(m_State.GetAssignedCover(), threatPos))
74  {
75  // Found good enough cover, complete the action
76  completeAction = true;
77  return;
78  }
79 
80  outCompleteAction = completeAction;
81  }
82 
83  //--------------------------------------------------------------------------------------------
84  bool ConditionPushMoveRequest(vector tgtPos)
85  {
86  if (m_State.IsMoving())
87  {
88  if (m_State.IsMovingToCover())
89  {
90  // Already moving to cover, continue moving there even if it's not cover to hide from this grenade
91  return false;
92  }
93  else
94  {
96  if (rqMove && rqMove.m_eReason == SCR_EAICombatMoveReason.MOVE_FROM_DANGER)
97  return false;
98  else
99  {
100  // Moving not to cover, but this is not our request, make a new request
101  return true;
102  }
103  }
104  }
105  else if (m_State.m_bInCover && m_State.IsAssignedCoverValid())
106  {
107  // Not moving, but we are in cover
108  if (!IsCoverSafeAgainstGrenade(m_State.GetAssignedCover(), tgtPos))
109  return true;
110  else
111  return false;
112  }
113  else
114  {
115  // Not moving, not in cover, run somewhere
116  return true;
117  }
118 
119  return false;
120  }
121 
122  //--------------------------------------------------------------------------------------------
123  bool IsCoverSafeAgainstGrenade(notnull SCR_AICoverLock coverLock, vector threatPos)
124  {
125  float coverDistToThreatSq = vector.DistanceSq(threatPos, coverLock.m_vCoverPos);
126 
127  // So close is not safe
128  if (coverDistToThreatSq < 3*3) // TODO make it constant
129  return false;
130 
131  // Far enough, check angle
132  float cosAngleCoverToTgt = m_State.GetAssignedCover().CosAngleToThreat(threatPos);
133  return cosAngleCoverToTgt > 0.707; // This should match or be close to value in cover query properties
134  }
135 
136  //------------------------------------------------------------------------------------
137  protected static ref TStringArray s_aVarsIn = { PORT_POSITION };
138  override TStringArray GetVariablesIn() { return s_aVarsIn; }
139 
140  protected static ref TStringArray s_aVarsOut = { PORT_COMPLETE_ACTION };
141  override TStringArray GetVariablesOut() { return s_aVarsOut; }
142 
143  override bool VisibleInPalette() { return true; }
144 }
EMovementType
EMovementType
Definition: EMovementType.c:12
SCR_AICombatMoveLogic_MoveFromGrenade
Definition: SCR_AICombatMoveLogic_MoveFromGrenade.c:1
ECharacterStance
ECharacterStance
Definition: ECharacterStance.c:12
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_AICoverLock
Definition: SCR_AICoverLock.c:19
SCR_AICombatMoveRequest_Move
Definition: SCR_AICombatMoveRequest.c:78
SCR_AICombatMoveRequest_Move
void SCR_AICombatMoveRequest_Move()
Definition: SCR_AICombatMoveRequest.c:95
m_State
private EEditableEntityState m_State
Definition: SCR_BaseEntitiesEditorUIEffect.c:3