Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIAvoidCharacterBehavior.c
Go to the documentation of this file.
2{
5
6 protected const float MOVE_DURATION_S = 0.5;
7
8 //--------------------------------------------------------------------------------------------------------------
9 void SCR_AIAvoidCharacterBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector targetPos, vector targetVelocity)
10 {
11 m_bAllowLook = false;
12 m_bUseCombatMove = true;
13 m_vTargetPos = targetPos;
14 m_vTargetVelocity = targetVelocity;
15 SetPriority(PRIORITY_BEHAVIOR_AVOID_CHARACTER);
16 m_sBehaviorTree = "{A75A34B4B237851F}AI/BehaviorTrees/Chimera/Soldier/AvoidCharacter.bt";
17 }
18
19 //--------------------------------------------------------------------------------------------------------------
20 override void OnActionSelected()
21 {
23
24 SCR_CharacterControllerComponent characterController = m_Utility.GetCharacterController();
25
26 if (!characterController)
27 {
28 Fail();
29 return;
30 }
31
32 // Just move a bit backwards from the position of offender. Don't use covers.
33
34 rq.m_bAimAtTarget = true;
35 rq.m_bAimAtTargetEnd = true;
36 rq.m_eReason = SCR_EAICombatMoveReason.CHARACTER_AVOIDANCE;
37 rq.m_vTargetPos = m_vTargetPos; // Position of target (enemy) - must be useable for cover search, should be muzzle position or head position.
38 rq.m_vMovePos = m_vTargetPos; // Move position relative to which m_eDirection works
39 rq.m_bTryFindCover = false; // Try to find cover or not?
40 rq.m_bFailIfNoCover = false; // If m_bTryFindCover is true, but cover was not found, fail or move anyway?
41 //rq.m_bCheckCoverVisibility = false; // (only m_bTryFindCover) Do we need to check target pos. visibility from that cover or not?
42 rq.m_eStanceMoving = characterController.GetStance(); // Stance used for movement
43 rq.m_eStanceEnd = rq.m_eStanceMoving; // Stance used at the end (might be overridden by found cover)
44 rq.m_eMovementType = EMovementType.RUN; //
45 //float m_fCoverSearchDistMin; // (only m_bTryFindCover)
46 //float m_fCoverSearchDistMax; // (only m_bTryFindCover)
47 //float m_fCoverSearchSectorHalfAngleRad = Math.PI; // (only m_bTryFindCover) Half-angle (in radians) of cover query sector. Pi is full circle, Pi/2 is -90deg...+90deg sector.
48 rq.m_fMoveDuration_s = MOVE_DURATION_S; // Movement duration for movement to non-cover position
49 //bool m_bUseCoverSearchDirectivity; // If trying to find cover, prefer covers in given direction or not. Affects cover scoring.
50 rq.m_eDirection = ResolveMoveDirection(); // Direction - Where we want to move !!! relative to m_vMovePos
51 //vector m_vAvoidStraightPathDir; // When not 0,0,0, changes pathfinding to try to flank and avoid the path aligned same direction. Makes sense mostly for m_eDirection = CUSTOM_POS.
52
53 rq.GetOnCompleted().Insert(OnMovementCompleted);
54 rq.GetOnFailed().Insert(OnMovementFailed);
55
56 m_Utility.m_CombatMoveState.ApplyNewRequest(rq);
57
58 // For safety, in case that move request gets stuck, make a timer with duration larger than duration of move request, and complete the action.
59 m_Utility.GetCallqueue().CallLater(OnTimeout, 1500*MOVE_DURATION_S);
60 }
61
62 //--------------------------------------------------------------------------------------------------------------
63 SCR_EAICombatMoveDirection ResolveMoveDirection()
64 {
65 if (m_vTargetVelocity == vector.Zero)
66 return SCR_EAICombatMoveDirection.BACKWARD;
67
68 vector dirToMeXZ = (m_Utility.m_OwnerEntity.GetOrigin() - m_vTargetPos);
69 dirToMeXZ[1] = 0;
70 dirToMeXZ.Normalize();
71
72 vector dirVelocityXZ = m_vTargetVelocity;
73 dirVelocityXZ[1] = 0;
74 dirVelocityXZ.Normalize();
75
76 vector cross = dirToMeXZ * dirVelocityXZ;
77 float sinAngle = cross[1];
78
79 if (Math.AbsFloat(sinAngle) < 0.5) // Sin 30
80 return SCR_EAICombatMoveDirection.BACKWARD;
81
82 if (sinAngle > 0)
83 return SCR_EAICombatMoveDirection.RIGHT;
84 else
85 return SCR_EAICombatMoveDirection.LEFT;
86 }
87
88 //--------------------------------------------------------------------------------------------------------------
89 void OnMovementCompleted(SCR_AIUtilityComponent utility, SCR_AICombatMoveRequestBase request)
90 {
91 Complete();
92 }
93
94 //--------------------------------------------------------------------------------------------------------------
95 void OnMovementFailed(SCR_AIUtilityComponent utility, SCR_AICombatMoveRequestBase request, SCR_EAICombatMoveRequestFailReason failReason)
96 {
97 Complete();
98 }
99
100 //--------------------------------------------------------------------------------------------------------------
102 {
103 if (GetActionState() != EAIActionState.FAILED || GetActionState() != EAIActionState.COMPLETED)
104 Complete();
105 }
106
107 //--------------------------------------------------------------------------------------------------------------
109 {
110 return SCR_EAIBehaviorCause.SAFE;
111 }
112}
ResourceName m_sBehaviorTree
void Fail(bool doNotCompleteWaypoint)
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
bool m_bUseCombatMove
SCR_EAIBehaviorCause
bool m_bAllowLook
void SCR_AICombatMoveRequest_Move()
Definition Math.c:13
void OnMovementFailed(SCR_AIUtilityComponent utility, SCR_AICombatMoveRequestBase request, SCR_EAICombatMoveRequestFailReason failReason)
void SCR_AIAvoidCharacterBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector targetPos, vector targetVelocity)
override SCR_EAIBehaviorCause GetCause()
void OnMovementCompleted(SCR_AIUtilityComponent utility, SCR_AICombatMoveRequestBase request)
SCR_EAICombatMoveDirection ResolveMoveDirection()
EAIActionState
EMovementType