Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AIDefendActivity.c
Go to the documentation of this file.
1
class
SCR_AIDefendActivity
:
SCR_AIActivityBase
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
//-------------------------------------------------------------------------------------------------
42
void
ClearRadialCoverAgents
()
43
{
44
m_aRadialCoverAgents
.Clear();
45
}
46
47
//-------------------------------------------------------------------------------------------------
48
int
GetRadialCoverAgentsCount
()
49
{
50
return
m_aRadialCoverAgents
.Count();
51
}
52
53
//-------------------------------------------------------------------------------------------------
54
void
AllocateAgentsToRadialCover
()
55
{
56
if
(!
m_RelatedWaypoint
)
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
();
88
SendCancelMessagesToAllAgents
();
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
();
98
SendCancelMessagesToAllAgents
();
99
}
100
101
//-------------------------------------------------------------------------------------------------
102
override
void
OnActionCompleted
()
103
{
104
super.OnActionCompleted();
105
SendCancelMessagesToAllAgents
();
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
};
m_fPriorityLevel
ref SCR_BTParam< float > m_fPriorityLevel
Definition
SCR_AIAction.c:87
PRIORITY_LEVEL_NORMAL
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
m_sBehaviorTree
ResourceName m_sBehaviorTree
Definition
SCR_AIAction.c:89
SendCancelMessagesToAllAgents
void SendCancelMessagesToAllAgents()
Definition
SCR_AIActivity.c:51
m_bIsWaypointRelated
ref SCR_BTParam< bool > m_bIsWaypointRelated
Definition
SCR_AIActivity.c:14
SCR_AIActivityBase
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
Definition
SCR_AIActivity.c:44
m_Utility
enum SCR_EAIActivityCause m_Utility
m_RelatedWaypoint
AIWaypoint m_RelatedWaypoint
Definition
SCR_AIActivity.c:15
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition
SCR_DestructionSynchronizationComponent.c:17
IEntity
Definition
IEntity.c:13
IEntity::GetAngles
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
IEntity::GetOrigin
proto external vector GetOrigin()
Math
Definition
Math.c:13
SCR_AIActionTask
Definition
SCR_AIBehaviorTask.c:2
SCR_AIDefendActivity::GetDefendDirection
static vector GetDefendDirection(IEntity centralEntity, float directionDistance)
calculates a direction vector from centralEntity towards frontal direction of the centralEntity
Definition
SCR_AIDefendActivity.c:118
SCR_AIDefendActivity::InitParameters
void InitParameters(vector defendDirection, float priorityLevel)
Definition
SCR_AIDefendActivity.c:7
SCR_AIDefendActivity::AllocateAgentsToRadialCover
void AllocateAgentsToRadialCover()
Definition
SCR_AIDefendActivity.c:54
SCR_AIDefendActivity::OnActionCompleted
override void OnActionCompleted()
Definition
SCR_AIDefendActivity.c:102
SCR_AIDefendActivity::SCR_AIDefendActivity
void SCR_AIDefendActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector defendDirection, float priority=PRIORITY_ACTIVITY_DEFEND, float priorityLevel=PRIORITY_LEVEL_NORMAL)
Definition
SCR_AIDefendActivity.c:14
SCR_AIDefendActivity::ClearRadialCoverAgents
void ClearRadialCoverAgents()
Definition
SCR_AIDefendActivity.c:42
SCR_AIDefendActivity::GetRadialCoverAgentsCount
int GetRadialCoverAgentsCount()
Definition
SCR_AIDefendActivity.c:48
SCR_AIDefendActivity::OnActionFailed
override void OnActionFailed()
Definition
SCR_AIDefendActivity.c:92
SCR_AIDefendActivity::GetActionDebugInfo
override string GetActionDebugInfo()
Definition
SCR_AIDefendActivity.c:76
SCR_AIDefendActivity::SendDefendSector
bool SendDefendSector(AIAgent who, vector directionAxis, float angleRange)
Definition
SCR_AIDefendActivity.c:109
SCR_AIDefendActivity::OnActionDeselected
override void OnActionDeselected()
Definition
SCR_AIDefendActivity.c:82
SCR_AIDefendActivity::m_aRadialCoverAgents
ref array< AIAgent > m_aRadialCoverAgents
Definition
SCR_AIDefendActivity.c:5
SCR_AIDefendActivity::AddAgentToRadialCover
void AddAgentToRadialCover(AIAgent agent)
Definition
SCR_AIDefendActivity.c:35
SCR_AIGroup
Definition
SCR_AIGroup.c:75
SCR_AIGroup::ReleaseCompartments
void ReleaseCompartments()
Definition
SCR_AIGroup.c:2024
SCR_AIGroupUtilityComponent
Definition
SCR_AIGroupUtilityComponent.c:18
SCR_AIMessage_Defend
Definition
SCR_AIMessage.c:511
vector
Definition
vector.c:13
ToString
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
scripts
Game
AI
Behavior
SCR_AIDefendActivity.c
Generated by
1.17.0