Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDefendActivity.c
Go to the documentation of this file.
2{
3 ref SCR_BTParam<vector> m_vDefendDirection = new SCR_BTParam<vector>(SCR_AIActionTask.DEFEND_DIRECTION_PORT);
4
5 protected ref array<AIAgent> m_aRadialCoverAgents = {};
6 //-------------------------------------------------------------------------------------------------
7 void InitParameters(vector defendDirection, float priorityLevel)
8 {
9 m_vDefendDirection.Init(this, defendDirection);
10 m_fPriorityLevel.Init(this, priorityLevel);
11 }
12
13 //-------------------------------------------------------------------------------------------------
14 void SCR_AIDefendActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector defendDirection, float priority = PRIORITY_ACTIVITY_DEFEND, float priorityLevel = PRIORITY_LEVEL_NORMAL)
15 {
16 InitParameters(defendDirection, priorityLevel);
17 m_sBehaviorTree = "AI/BehaviorTrees/Chimera/Group/ActivityDefend.bt";
18 SetPriority(priority);
19 if (!relatedWaypoint)
20 return;
21
22 float waypointRadius = relatedWaypoint.GetCompletionRadius();
23 vector waypointPositionWorld = relatedWaypoint.GetOrigin();
24 if (defendDirection == vector.Zero) // use orientation of the waypoint
25 {
26 m_vDefendDirection.m_Value = GetDefendDirection(relatedWaypoint, waypointRadius);
27 }
28 else
29 {
30 m_vDefendDirection.m_Value = (defendDirection - waypointPositionWorld).Normalized() * waypointRadius + waypointPositionWorld;
31 }
32 }
33
34 //-------------------------------------------------------------------------------------------------
35 void AddAgentToRadialCover (AIAgent agent)
36 {
37 if (m_aRadialCoverAgents.Find(agent) == -1)
38 m_aRadialCoverAgents.Insert(agent);
39 }
40
41 //-------------------------------------------------------------------------------------------------
43 {
45 }
46
47 //-------------------------------------------------------------------------------------------------
49 {
50 return m_aRadialCoverAgents.Count();
51 }
52
53 //-------------------------------------------------------------------------------------------------
55 {
57 return;
58 vector originOfLocalSpace = m_RelatedWaypoint.GetOrigin();
59 vector directionToDefend = m_vDefendDirection.m_Value - originOfLocalSpace;
60 float angleToDefend = directionToDefend.ToYaw();
61 float sector = 360 / m_aRadialCoverAgents.Count();
62 float length = directionToDefend.Length();
63 vector directionAxis;
64 float angleRange = sector/2;
65 foreach(int index, AIAgent agent: m_aRadialCoverAgents)
66 {
67 int directionAngle = Math.Round(angleToDefend + sector * index);
68 directionAngle = directionAngle % 360;
69 directionAxis[0] = Math.Sin(directionAngle * Math.DEG2RAD) * length;
70 directionAxis[2] = Math.Cos(directionAngle * Math.DEG2RAD) * length;
71 SendDefendSector(agent, directionAxis + originOfLocalSpace, angleRange);
72 }
73 }
74
75 //-------------------------------------------------------------------------------------------------
76 override string GetActionDebugInfo()
77 {
78 return this.ToString() + " defending area of " + m_RelatedWaypoint.ToString();
79 }
80
81 //-------------------------------------------------------------------------------------------------
82 override void OnActionDeselected()
83 {
84 super.OnActionDeselected();
85 SCR_AIGroup group = SCR_AIGroup.Cast(m_Utility.GetAIAgent());
86 if (group)
87 group.ReleaseCompartments();
89 }
90
91 //-------------------------------------------------------------------------------------------------
92 override void OnActionFailed()
93 {
94 super.OnActionFailed();
95 SCR_AIGroup group = SCR_AIGroup.Cast(m_Utility.GetAIAgent());
96 if (group)
97 group.ReleaseCompartments();
99 }
100
101 //-------------------------------------------------------------------------------------------------
102 override void OnActionCompleted()
103 {
104 super.OnActionCompleted();
106 }
107
108 //-------------------------------------------------------------------------------------------------
109 bool SendDefendSector (AIAgent who, vector directionAxis, float angleRange)
110 {
111 SCR_AIMessage_Defend defendMessage = SCR_AIMessage_Defend.Create(directionAxis, angleRange, m_bIsWaypointRelated.m_Value, m_fPriorityLevel.m_Value, m_RelatedWaypoint, this);
112 m_Utility.m_Mailbox.RequestBroadcast(defendMessage, who);
113 return true;
114 }
115
116 //-------------------------------------------------------------------------------------------------
118 static vector GetDefendDirection(IEntity centralEntity, float directionDistance)
119 {
120 vector startPositionWorld = centralEntity.GetOrigin();
121 float rotationAngle = centralEntity.GetAngles()[1] * Math.DEG2RAD;
122 vector endPositionWorld;
123 endPositionWorld[0] = startPositionWorld[0] + Math.Sin(rotationAngle) * directionDistance;
124 endPositionWorld[1] = startPositionWorld[1];
125 endPositionWorld[2] = startPositionWorld[2] + Math.Cos(rotationAngle) * directionDistance;
126 return endPositionWorld;
127 }
128};
ref SCR_BTParam< float > m_fPriorityLevel
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
ResourceName m_sBehaviorTree
void SendCancelMessagesToAllAgents()
ref SCR_BTParam< bool > m_bIsWaypointRelated
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
AIWaypoint m_RelatedWaypoint
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external vector GetOrigin()
Definition Math.c:13
static vector GetDefendDirection(IEntity centralEntity, float directionDistance)
calculates a direction vector from centralEntity towards frontal direction of the centralEntity
void InitParameters(vector defendDirection, float priorityLevel)
override void OnActionCompleted()
void SCR_AIDefendActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector defendDirection, float priority=PRIORITY_ACTIVITY_DEFEND, float priorityLevel=PRIORITY_LEVEL_NORMAL)
override void OnActionFailed()
override string GetActionDebugInfo()
bool SendDefendSector(AIAgent who, vector directionAxis, float angleRange)
override void OnActionDeselected()
ref array< AIAgent > m_aRadialCoverAgents
void AddAgentToRadialCover(AIAgent agent)
void ReleaseCompartments()
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.