Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIMoveFromDanger.c
Go to the documentation of this file.
1 
5 {
6  ref SCR_BTParam<vector> m_DangerPosition = new SCR_BTParam<vector>("DangerPosition");
7  ref SCR_BTParam<IEntity> m_DangerEntity = new SCR_BTParam<IEntity>("DangerEntity");
8  ref SCR_BTParam<ECharacterStance> m_Stance = new SCR_BTParam<ECharacterStance>("CharacterStance");
9  ref SCR_BTParam<EMovementType> m_MovementType = new SCR_BTParam<EMovementType>("MovementType");
10 
11  //-----------------------------------------------------------------------------------------------------
12  void InitParameters(IEntity dangerEntity, vector dangerPos)
13  {
14  m_DangerEntity.Init(this, dangerEntity);
15  m_DangerPosition.Init(this, dangerPos);
16  m_Stance.Init(this, ECharacterStance.STAND);
17  m_MovementType.Init(this, EMovementType.RUN); // Don't use sprint! Character can't reload during sprint, it makes it broken.
18  }
19 
20  //-----------------------------------------------------------------------------------------------------
21  void SCR_AIMoveFromDangerBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity)
22  {
23  SetPriority(PRIORITY_BEHAVIOR_MOVE_FROM_DANGER);
24  InitParameters(dangerEntity, dangerPos);
25 
26  if (dangerEntity)
27  {
28  m_DangerPosition.m_Value = dangerEntity.GetOrigin();
29  }
30 
31  m_sBehaviorTree = "{D12937CF422B639B}AI/BehaviorTrees/Chimera/Soldier/MoveFromDanger_Position.bt"
32  }
33 
34  //-----------------------------------------------------------------------------------------------------
36  static bool ExistsBehaviorForEntity(SCR_AIUtilityComponent utility, IEntity ent)
37  {
38  SCR_AIMoveFromDangerBehavior behavior = SCR_AIMoveFromDangerBehavior.Cast(utility.FindActionOfInheritedType(SCR_AIMoveFromDangerBehavior));
39  if (behavior && behavior.m_DangerEntity.m_Value == ent)
40  return true;
41  else
42  return false;
43  }
44 };
45 
47 {
48  //-----------------------------------------------------------------------------------------------------
49  void SCR_AIMoveFromUnknownFire(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity)
50  {
51  SetPriority(PRIORITY_BEHAVIOR_MOVE_FROM_UNKNOWN_FIRE);
52  m_Stance.m_Value = ECharacterStance.STAND;
53  m_MovementType.m_Value = EMovementType.SPRINT;
54  m_bIsInterruptable = false;
55 
56  m_bAllowLook = false;
57  }
58 
59  //-----------------------------------------------------------------------------------------------------
60  override float CustomEvaluate()
61  {
62  // This behavior is started by the fact that we don't have a current target,
63  // so it also ends when we have selected a target
64  if (m_Utility.m_CombatComponent.GetCurrentTarget())
65  {
66  Complete();
67  return 0;
68  }
69 
70  return GetPriority();
71  }
72 
73  //-----------------------------------------------------------------------------------------------------
74  override void OnActionSelected()
75  {
76  super.OnActionSelected();
77 
78  if (!m_Utility.m_CommsHandler.CanBypass())
79  {
80  SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_UNDER_FIRE, null, vector.Zero, 0, false, true, SCR_EAITalkRequestPreset.IRRELEVANT);
81  m_Utility.m_CommsHandler.AddRequest(rq);
82  }
83  }
84 }
85 
87 {
88  static const float MAX_GRENADE_LOOKAT_TIMEOUT_MS = 600;
89  static const float DISTANCE_MAX_SQ = 13*13;
90 
91  float m_fBehaviorTimeout = 0;
94 
95  //-----------------------------------------------------------------------------------------------------
96  void SCR_AIMoveFromGrenadeBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity, float behaviorDelay, vector observePosition)
97  {
98  m_bAllowLook = false;
99  m_fBehaviorTimeout = GetGame().GetWorld().GetWorldTime() + behaviorDelay;
100  m_sBehaviorTree = "{478811D2295EAF3E}AI/BehaviorTrees/Chimera/Soldier/MoveFromDanger_Grenade.bt";
101  m_MovementType.m_Value = EMovementType.SPRINT;
102  m_fDistanceToGrenade = vector.Distance(utility.m_OwnerEntity.GetOrigin(), dangerPos);
103  m_vObserveReactionPosition = observePosition;
104 
105  SetPriority(0);
106 
107  m_bUseCombatMove = true;
108  }
109 
111  {
112  if (m_vObserveReactionPosition == vector.Zero || m_Utility.m_CombatComponent.GetCurrentTarget() != null)
113  return;
114 
115  vector myOrigin = m_Utility.m_OwnerEntity.GetOrigin();
116 
117  // Stare at grenade origin
118  bool addObserveBehavior = false;
119  SCR_AIMoveAndInvestigateBehavior investigateBehavior = SCR_AIMoveAndInvestigateBehavior.Cast(m_Utility.FindActionOfType(SCR_AIMoveAndInvestigateBehavior));
120  SCR_AIObserveUnknownFireBehavior oldObserveBehavior = SCR_AIObserveUnknownFireBehavior.Cast(m_Utility.FindActionOfType(SCR_AIObserveUnknownFireBehavior));
121 
122  if (investigateBehavior && investigateBehavior.GetActionState() == EAIActionState.RUNNING)
123  {
124  if (SCR_AIObserveUnknownFireBehavior.IsNewPositionMoreRelevant(myOrigin, investigateBehavior.m_vPosition.m_Value, m_vObserveReactionPosition))
125  addObserveBehavior = true;
126  }
127  else if (oldObserveBehavior)
128  {
129  if (SCR_AIObserveUnknownFireBehavior.IsNewPositionMoreRelevant(myOrigin, oldObserveBehavior.m_vPosition.m_Value, m_vObserveReactionPosition))
130  addObserveBehavior = true;
131  }
132  else if (!oldObserveBehavior)
133  addObserveBehavior = true;
134 
135  if (addObserveBehavior)
136  {
137  SCR_AIObserveUnknownFireBehavior observeBehavior = new SCR_AIObserveUnknownFireBehavior(m_Utility, null, posWorld: m_vObserveReactionPosition, useMovement: false);
138  m_Utility.AddAction(observeBehavior);
139  }
140  }
141 
142  //-----------------------------------------------------------------------------------------------------
143  override void OnActionCompleted()
144  {
145  super.OnActionCompleted();
147  }
148 
149  //-----------------------------------------------------------------------------------------------------
150  override float CustomEvaluate()
151  {
153  {
154  Complete();
155  return 0;
156  }
157 
158  if (GetGame().GetWorld().GetWorldTime() > m_fBehaviorTimeout)
159  return PRIORITY_BEHAVIOR_MOVE_FROM_DANGER;
160 
161  return 0;
162  }
163 
165  {
166  if (!m_DangerEntity.m_Value)
167  return true;
168 
169  IEntity myEntity = m_Utility.m_OwnerEntity;
170  if (!myEntity)
171  return true;
172 
173  if (vector.DistanceSq(myEntity.GetOrigin(), m_DangerPosition.m_Value) > DISTANCE_MAX_SQ)
174  return true;
175 
176  return false;
177  }
178 }
179 
181 {
182  protected static const float MIN_COS_ANGLE_COVER_TO_VEHICLE = 0;
183 
184  //-----------------------------------------------------------------------------------------------------
185  void SCR_AIMoveFromIncomingVehicleBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity)
186  {
187  m_sBehaviorTree = "{2488649728730886}AI/BehaviorTrees/Chimera/Soldier/MoveFromDanger_Vehicle.bt";
188  SetPriority(PRIORITY_BEHAVIOR_MOVE_FROM_DANGER);
189  m_MovementType.m_Value = EMovementType.SPRINT;
190  m_bUseCombatMove = true;
191  }
192 
193  //-----------------------------------------------------------------------------------------------------
194  override float CustomEvaluate()
195  {
196  if (!ExecuteBehaviorCondition(m_Utility, m_DangerEntity.m_Value))
197  {
198  Complete();
199  return 0;
200  }
201 
202  return GetPriority();
203  }
204 
205  //-----------------------------------------------------------------------------------------------------
206  // Condition for the behavior to run
207  static bool ExecuteBehaviorCondition(notnull SCR_AIUtilityComponent utilityComp, IEntity vehicle)
208  {
209  if (!vehicle)
210  return false;
211 
212  // If vehicle is not moving towards us
213  IEntity myEntity = utilityComp.m_OwnerEntity;
214  if (!IsVehicleMovingTowardsMe(myEntity, vehicle))
215  return false;
216 
217  // If we are already in good cover
218  SCR_AICombatMoveState cmStace = utilityComp.m_CombatMoveState;
219  SCR_AICoverLock cover = utilityComp.m_CombatMoveState.GetAssignedCover();
220  if (cmStace.m_bInCover && cover && cover.IsValid() && IsCoverSafeAgainstVehicle(cover, vehicle))
221  return false;
222 
223  return true;
224  }
225 
226  //-----------------------------------------------------------------------------------------------------
227  static bool IsCoverSafeAgainstVehicle(notnull SCR_AICoverLock cover, notnull IEntity vehicle)
228  {
229  float cosAngleCoverToTgt = cover.CosAngleToThreat(vehicle.GetOrigin());
230  return cosAngleCoverToTgt > MIN_COS_ANGLE_COVER_TO_VEHICLE;
231  }
232 
233  //-----------------------------------------------------------------------------------------------------
234  protected static bool IsVehicleMovingTowardsMe(notnull IEntity myEntity, notnull IEntity vehicle)
235  {
236  Physics phy = vehicle.GetPhysics();
237 
238  if (!phy)
239  return false;
240 
241  // Bail if velocity is around zero
242  vector velocityWorld = phy.GetVelocity();
243  float velocityAbsSq = velocityWorld.LengthSq();
244  if (velocityAbsSq <= 0.001)
245  return false;
246 
247  vector velocityDir = velocityWorld.Normalized();
248 
249  vector vecToMe = vector.Direction(vehicle.GetOrigin(), myEntity.GetOrigin());
250  vecToMe.Normalize();
251 
252  float cosAngle = vector.Dot(vecToMe, velocityDir);
253 
254  return cosAngle > 0;
255  }
256 }
257 
259 {
260  //-----------------------------------------------------------------------------------------------------
261  void SCR_AIMoveFromVehicleHornBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity)
262  {
263  m_sBehaviorTree = "{10A3DFFBC3629A79}AI/BehaviorTrees/Chimera/Soldier/MoveFromDanger_VehicleHorn.bt";
264  SetPriority(PRIORITY_BEHAVIOR_MOVE_FROM_VEHICLE_HORN);
265  }
266 }
CreateObserveUnknownBehavior
void CreateObserveUnknownBehavior()
Definition: SCR_AIMoveFromDanger.c:110
EMovementType
EMovementType
Definition: EMovementType.c:12
ECharacterStance
ECharacterStance
Definition: ECharacterStance.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_AIObserveUnknownFireBehavior
Definition: SCR_AIObserveUnknownFireBehavior.c:8
CustomEvaluate
override float CustomEvaluate()
Definition: SCR_AIMoveFromDanger.c:150
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
SCR_AIMoveFromVehicleHornBehavior
SCR_AIMoveFromIncomingVehicleBehavior SCR_AIMoveFromDangerBehavior SCR_AIMoveFromVehicleHornBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity)
Definition: SCR_AIMoveFromDanger.c:261
GetPriority
int GetPriority()
Definition: SCR_BaseManualCameraComponent.c:107
SCR_AITalkRequest
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
Definition: SCR_AITalkRequest.c:37
SCR_AICoverLock
Definition: SCR_AICoverLock.c:19
CompleteActionCondition
bool CompleteActionCondition()
Definition: SCR_AIMoveFromDanger.c:164
ECommunicationType
ECommunicationType
Definition: SCR_AISoundHandling.c:1
MAX_GRENADE_LOOKAT_TIMEOUT_MS
SCR_AIMoveFromUnknownFire MAX_GRENADE_LOOKAT_TIMEOUT_MS
SCR_AIMoveFromGrenadeBehavior
void SCR_AIMoveFromGrenadeBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector dangerPos, IEntity dangerEntity, float behaviorDelay, vector observePosition)
Definition: SCR_AIMoveFromDanger.c:96
SCR_AIMoveFromDangerBehavior
Definition: SCR_AIMoveFromDanger.c:4
SCR_AIMoveFromUnknownFire
Definition: SCR_AIMoveFromDanger.c:46
m_fDistanceToGrenade
float m_fDistanceToGrenade
Definition: SCR_AIMoveFromDanger.c:92
m_fBehaviorTimeout
float m_fBehaviorTimeout
Definition: SCR_AIMoveFromDanger.c:91
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1
EAIActionState
EAIActionState
Definition: EAIActionState.c:12
m_vObserveReactionPosition
vector m_vObserveReactionPosition
Definition: SCR_AIMoveFromDanger.c:93
SCR_AIMoveAndInvestigateBehavior
Definition: SCR_AIMoveBehavior.c:53
OnActionCompleted
override void OnActionCompleted()
Definition: SCR_AIMoveFromDanger.c:143
SCR_AIMoveFromIncomingVehicleBehavior
Definition: SCR_AIMoveFromDanger.c:180