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_AIAllocateActionsForDefendActivity.c
Go to the documentation of this file.
1
class
SCR_AIAllocateActionsForDefendActivity
:
AITaskScripted
2
{
3
static
const
string
PORT_WAYPOINT =
"WaypointIn"
;
4
static
const
string
PORT_WAYPOINT_RELATED =
"WaypointRelated"
;
5
static
const
string
PORT_PRIORITY_LEVEL =
"PriorityLevel"
;
6
7
protected
SCR_AIGroup
m_groupOwner
;
8
protected
bool
m_bWaypointRelated
;
9
protected
float
m_fPriorityLevel
;
10
protected
SCR_DefendWaypoint
m_RelatedWaypoint
;
11
protected
SCR_AIGroupUtilityComponent
m_Utility
;
12
protected
SCR_MailboxComponent
m_Mailbox
;
13
protected
SCR_AIDefendActivity
m_RelatedActivity
;
14
15
//------------------------------------------------------------------------------------------------
16
static
override
bool
VisibleInPalette
() {
return
true
;}
17
18
//------------------------------------------------------------------------------------------------
19
override
void
OnInit
(AIAgent owner)
20
{
21
m_groupOwner
=
SCR_AIGroup
.Cast(owner);
22
if
(!
m_groupOwner
)
23
{
24
m_groupOwner
=
SCR_AIGroup
.Cast(owner.GetParentGroup());
25
if
(!
m_groupOwner
)
26
{
27
SCR_AgentMustBeAIGroup
(
this
, owner);
28
return
;
29
}
30
}
31
m_Utility
=
SCR_AIGroupUtilityComponent
.Cast(
m_groupOwner
.FindComponent(
SCR_AIGroupUtilityComponent
));
32
m_Mailbox
=
m_Utility
.m_Mailbox;
33
m_RelatedActivity
=
SCR_AIDefendActivity
.Cast(
m_Utility
.GetCurrentAction());
34
}
35
36
//------------------------------------------------------------------------------------------------
37
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
38
{
39
if
(!
m_groupOwner
)
40
return
ENodeResult
.FAIL;
41
IEntity
waypointEnt;
42
43
if
(!
m_Mailbox
|| !
m_Utility
|| !
m_RelatedActivity
)
44
return
ENodeResult
.FAIL;
45
46
GetVariableIn
(PORT_WAYPOINT,waypointEnt);
47
GetVariableIn
(PORT_WAYPOINT_RELATED,
m_bWaypointRelated
);
48
GetVariableIn
(PORT_PRIORITY_LEVEL,
m_fPriorityLevel
);
49
50
array<AIAgent> groupMembers = {};
51
m_groupOwner
.GetAgents(groupMembers);
52
if
(groupMembers.IsEmpty())
53
return
ENodeResult
.FAIL;
54
55
int
numSAToOccupy;
56
57
// Preparation of turrets and actions array
58
m_RelatedWaypoint
=
SCR_DefendWaypoint
.Cast(waypointEnt);
59
if
(!
m_RelatedWaypoint
)
60
return
NodeError
(
this
, owner,
"Defend Waypoint not provided to the node!"
);
61
62
SCR_DefendWaypointPreset
defendPreset =
m_RelatedWaypoint
.GetCurrentDefendPreset();
63
if
(!defendPreset)
64
return
SCR_AIErrorMessages
.NodeErrorDefendPreset(
this
, owner);
65
66
bool
useTurrets = defendPreset.
GetUseTurrets
();
67
bool
teleport =
m_RelatedWaypoint
.GetFastInit();
68
69
ref array<BaseCompartmentSlot> compartments = {};
70
ref array<AISmartActionComponent> smartActions = {};
71
72
if
(useTurrets)
73
{
74
m_groupOwner
.GetAllocatedCompartments(compartments);
75
for
(
int
i = compartments.Count() - 1; i >= 0; i--)
76
{
77
if
(!
TurretCompartmentSlot
.Cast(compartments[i]))
78
compartments.Remove(i);
79
}
80
}
81
82
float
fraction = defendPreset.
GetFractionOfSA
();
83
if
(fraction > 0)
84
{
85
m_groupOwner
.GetAllocatedSmartActions(smartActions);
86
numSAToOccupy =
Math
.Round(fraction * smartActions.Count());
87
}
88
89
// Distribution of turrets, actions and sector defends (randomized)
90
for
(
int
i = 0, max = groupMembers.Count(); i < max; i++)
91
{
92
int
j = groupMembers.GetRandomIndex();
93
if
(useTurrets && compartments.Count() > 0)
94
{
95
OccupyTurret
(groupMembers[j], compartments[0], teleport);
96
compartments.Remove(0);
97
groupMembers.Remove(j);
98
continue
;
99
}
100
if
(numSAToOccupy > 0)
101
{
102
OccupySA
(groupMembers[j], smartActions[0], teleport);
103
smartActions.Remove(0);
104
groupMembers.Remove(j);
105
numSAToOccupy--;
106
continue
;
107
}
108
m_RelatedActivity
.AddAgentToRadialCover(groupMembers[j]);
109
groupMembers.Remove(j);
110
}
111
112
// Remaining agents to defend sectors of Waypoint
113
if
(
m_RelatedActivity
.GetRadialCoverAgentsCount() > 0)
114
{
115
m_RelatedActivity
.AllocateAgentsToRadialCover();
116
m_RelatedActivity
.ClearRadialCoverAgents();
117
};
118
119
return
ENodeResult
.SUCCESS;
120
}
121
122
//Sends order to agent, reserves compartment
123
protected
bool
OccupyTurret
(AIAgent who,
BaseCompartmentSlot
slot,
bool
teleport)
124
{
125
IEntity
vehicle = slot.
GetVehicle
();
126
if
(!vehicle)
127
return
false
;
128
129
SCR_AIVehicleUsageComponent
vehicleUsageComp =
SCR_AIVehicleUsageComponent
.
FindOnNearestParent
(vehicle, vehicle);
130
if
(!vehicleUsageComp)
131
return
false
;
132
133
if
(teleport)
134
{
135
IEntity
entityToTeleport = who.GetControlledEntity();
136
if
(!entityToTeleport)
137
return
false
;
138
CompartmentAccessComponent CAComponent = CompartmentAccessComponent.Cast(entityToTeleport.
FindComponent
(CompartmentAccessComponent));
139
if
(!CAComponent.GetInVehicle(vehicle, slot,
true
, -1,
ECloseDoorAfterActions
.INVALID,
false
))
140
Print
(
"Unable to teleport to Turret"
,
LogLevel
.WARNING);
// might be still in the process of teleporting...
141
}
142
SCR_AIMessage_GetIn
getInMessage =
SCR_AIMessage_GetIn
.Create(vehicle, null,
EAICompartmentType
.Turret,
m_bWaypointRelated
,
m_fPriorityLevel
,
m_RelatedWaypoint
,
m_RelatedActivity
, slot);
143
m_Mailbox
.RequestBroadcast(getInMessage, who);
144
m_groupOwner
.GetGroupUtilityComponent().AddUsableVehicle(vehicleUsageComp);
145
146
return
true
;
147
}
148
149
//Sends order to agent, reserves smart action
150
protected
bool
OccupySA
(AIAgent who,
AISmartActionComponent
smartAction,
bool
teleport)
151
{
152
if
(teleport)
153
{
154
vector
originOfObject, positionToTeleport;
155
vector
mat[4];
156
157
originOfObject = smartAction.
GetOwner
().
GetOrigin
();
158
positionToTeleport = originOfObject + smartAction.GetActionOffset();
159
BaseGameEntity entityToTeleport = BaseGameEntity.Cast(who.GetControlledEntity());
160
if
(!entityToTeleport)
161
return
false
;
162
Math3D
.MatrixIdentity4(mat);
163
mat[3] = positionToTeleport;
164
165
entityToTeleport.Teleport(mat);
// teleporting entity
166
}
167
168
SCR_AISmartActionComponent
smartActionComponent =
SCR_AISmartActionComponent
.Cast(smartAction);
169
if
(!smartActionComponent)
170
return
false
;
171
smartActionComponent.
ReserveAction
(who);
172
SCR_AIMessage_PerformAction
actionMessage =
SCR_AIMessage_PerformAction
.Create(null,
""
, smartActionComponent,
m_bWaypointRelated
,
m_fPriorityLevel
,
m_RelatedWaypoint
,
m_RelatedActivity
);
173
m_Mailbox
.RequestBroadcast(actionMessage, who);
174
return
true
;
175
}
176
177
//------------------------------------------------------------------------------------------------
178
protected
static
ref
TStringArray
s_aVarsIn
= {
179
PORT_WAYPOINT,
180
PORT_WAYPOINT_RELATED,
181
PORT_PRIORITY_LEVEL
182
};
183
override
TStringArray
GetVariablesIn
()
184
{
185
return
s_aVarsIn
;
186
}
187
188
//------------------------------------------------------------------------------------------------
189
static
override
string
GetOnHoverDescription
()
190
{
191
return
"AllocateActionsForDefendActivity: Goes over all group members and alocates them either turret, smart action or sector defend.\n Works only inside defend activity under defend waypoint."
;
192
}
193
}
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition
NodeError.c:3
SCR_AgentMustBeAIGroup
void SCR_AgentMustBeAIGroup(Node node, AIAgent owner)
Definition
NodeError.c:14
EAICompartmentType
EAICompartmentType
Definition
SCR_AIVehicleBehavior.c:2
AISmartActionComponent
Definition
AISmartActionComponent.c:13
AITaskScripted
Definition
AITaskScripted.c:13
BaseCompartmentSlot
Definition
BaseCompartmentSlot.c:2
BaseCompartmentSlot::GetVehicle
IEntity GetVehicle()
Definition
BaseCompartmentSlot.c:83
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetOrigin
proto external vector GetOrigin()
Math3D
Definition
Math3D.c:13
Math
Definition
Math.c:13
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
SCR_AIAllocateActionsForDefendActivity
Definition
SCR_AIAllocateActionsForDefendActivity.c:2
SCR_AIAllocateActionsForDefendActivity::OccupySA
bool OccupySA(AIAgent who, AISmartActionComponent smartAction, bool teleport)
Definition
SCR_AIAllocateActionsForDefendActivity.c:150
SCR_AIAllocateActionsForDefendActivity::m_RelatedWaypoint
SCR_DefendWaypoint m_RelatedWaypoint
Definition
SCR_AIAllocateActionsForDefendActivity.c:10
SCR_AIAllocateActionsForDefendActivity::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AIAllocateActionsForDefendActivity.c:16
SCR_AIAllocateActionsForDefendActivity::m_groupOwner
SCR_AIGroup m_groupOwner
Definition
SCR_AIAllocateActionsForDefendActivity.c:7
SCR_AIAllocateActionsForDefendActivity::m_RelatedActivity
SCR_AIDefendActivity m_RelatedActivity
Definition
SCR_AIAllocateActionsForDefendActivity.c:13
SCR_AIAllocateActionsForDefendActivity::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AIAllocateActionsForDefendActivity.c:178
SCR_AIAllocateActionsForDefendActivity::OccupyTurret
bool OccupyTurret(AIAgent who, BaseCompartmentSlot slot, bool teleport)
Definition
SCR_AIAllocateActionsForDefendActivity.c:123
SCR_AIAllocateActionsForDefendActivity::GetOnHoverDescription
static override string GetOnHoverDescription()
Definition
SCR_AIAllocateActionsForDefendActivity.c:189
SCR_AIAllocateActionsForDefendActivity::m_fPriorityLevel
float m_fPriorityLevel
Definition
SCR_AIAllocateActionsForDefendActivity.c:9
SCR_AIAllocateActionsForDefendActivity::m_Mailbox
SCR_MailboxComponent m_Mailbox
Definition
SCR_AIAllocateActionsForDefendActivity.c:12
SCR_AIAllocateActionsForDefendActivity::m_bWaypointRelated
bool m_bWaypointRelated
Definition
SCR_AIAllocateActionsForDefendActivity.c:8
SCR_AIAllocateActionsForDefendActivity::OnInit
override void OnInit(AIAgent owner)
Definition
SCR_AIAllocateActionsForDefendActivity.c:19
SCR_AIAllocateActionsForDefendActivity::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AIAllocateActionsForDefendActivity.c:37
SCR_AIAllocateActionsForDefendActivity::m_Utility
SCR_AIGroupUtilityComponent m_Utility
Definition
SCR_AIAllocateActionsForDefendActivity.c:11
SCR_AIAllocateActionsForDefendActivity::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AIAllocateActionsForDefendActivity.c:183
SCR_AIDefendActivity
Definition
SCR_AIDefendActivity.c:2
SCR_AIErrorMessages
Definition
NodeError.c:31
SCR_AIGroup
Definition
SCR_AIGroup.c:75
SCR_AIGroupUtilityComponent
Definition
SCR_AIGroupUtilityComponent.c:18
SCR_AIMessage_GetIn
Definition
SCR_AIMessage.c:614
SCR_AIMessage_PerformAction
Definition
SCR_AIMessage.c:565
SCR_AISmartActionComponent
Definition
SCR_AISmartActionComponent.c:10
SCR_AISmartActionComponent::ReserveAction
void ReserveAction(AIAgent owner)
Definition
SCR_AISmartActionComponent.c:18
SCR_AIVehicleUsageComponent
Definition
SCR_AIVehicleUsageComponent.c:30
SCR_AIVehicleUsageComponent::FindOnNearestParent
static SCR_AIVehicleUsageComponent FindOnNearestParent(notnull IEntity ent, out IEntity componentOwner)
Definition
SCR_AIVehicleUsageComponent.c:140
SCR_DefendWaypoint
Definition
SCR_DefendWaypoint.c:7
SCR_DefendWaypointPreset
Definition
SCR_DefendWaypointPreset.c:7
SCR_DefendWaypointPreset::GetUseTurrets
bool GetUseTurrets()
Definition
SCR_DefendWaypointPreset.c:33
SCR_DefendWaypointPreset::GetFractionOfSA
float GetFractionOfSA()
Definition
SCR_DefendWaypointPreset.c:45
ScriptComponent::GetOwner
proto external GenericEntity GetOwner()
Get owner entity.
TurretCompartmentSlot
Definition
TurretCompartmentSlot.c:13
vector
Definition
vector.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
TStringArray
array< string > TStringArray
Definition
Types.c:385
ECloseDoorAfterActions
ECloseDoorAfterActions
Definition
ECloseDoorAfterActions.c:13
scripts
Game
AI
ScriptedNodes
Groups
SCR_AIAllocateActionsForDefendActivity.c
Generated by
1.17.0