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_ChimeraAIAgent.c
Go to the documentation of this file.
1
class
SCR_ChimeraAIAgentClass
:
ChimeraAIAgentClass
2
{
3
};
4
5
class
SCR_ChimeraAIAgent
: ChimeraAIAgent
6
{
7
// Current waypoint of our group
8
AIWaypoint m_GroupWaypoint;
9
SCR_AIUtilityComponent m_UtilityComponent;
10
SCR_AIInfoComponent
m_InfoComponent;
11
12
protected
SCR_CharacterControllerComponent
m_CharacterController
;
13
protected
FactionAffiliationComponent
m_FactionAffiliationComponent
;
14
protected
int
m_iPendingPlayerId
;
15
16
//------------------------------------------------------------------------------------------------
17
override
void
EOnInit
(
IEntity
owner)
18
{
19
IEntity
controlledEntity =
GetControlledEntity
();
20
if
(!controlledEntity)
21
return
;
22
23
ChimeraCharacter
character =
ChimeraCharacter
.Cast(controlledEntity);
24
if
(character)
25
{
26
m_CharacterController
=
SCR_CharacterControllerComponent
.Cast(character.GetCharacterController());
27
if
(
m_CharacterController
)
28
m_CharacterController
.m_OnLifeStateChanged.Insert(
OnLifeStateChanged
);
29
}
30
31
GetGame
().GetCallqueue().CallLater(
EnsureAILimit
, 1,
false
);
32
33
m_FactionAffiliationComponent
= FactionAffiliationComponent.Cast(controlledEntity.
FindComponent
(FactionAffiliationComponent));
34
m_InfoComponent =
SCR_AIInfoComponent
.Cast(FindComponent(
SCR_AIInfoComponent
));
35
m_UtilityComponent = SCR_AIUtilityComponent.Cast(FindComponent(SCR_AIUtilityComponent));
36
}
37
38
//------------------------------------------------------------------------------------------------
39
void
~SCR_ChimeraAIAgent
()
40
{
41
if
(
m_CharacterController
)
42
m_CharacterController
.m_OnLifeStateChanged.Remove(
OnLifeStateChanged
);
43
}
44
45
//------------------------------------------------------------------------------------------------
46
void
EnsureAILimit
()
47
{
48
auto
aiWorld =
GetGame
().GetAIWorld();
49
if
(!aiWorld)
50
return
;
51
52
if
(aiWorld.CanLimitedAIBeAdded())
53
return
;
54
55
IEntity
controlledEntity =
GetControlledEntity
();
56
if
(!
EntityUtils
.IsPlayer(controlledEntity) && !
IsPlayerPending_S
())
// Ensure that pending players can spawn
57
{
58
SCR_EntityHelper
.DeleteEntityAndChildren(controlledEntity);
59
}
60
}
61
62
//------------------------------------------------------------------------------------------------
63
protected
void
SendWoundedMsg
()
64
{
65
IEntity
controlled =
GetControlledEntity
();
66
67
SCR_CharacterDamageManagerComponent
damageMgr =
SCR_CharacterDamageManagerComponent
.Cast(controlled.
FindComponent
(
SCR_CharacterDamageManagerComponent
));
68
if
(!damageMgr)
69
return
;
70
71
if
(!damageMgr.
IsBleeding
())
72
return
;
73
74
SCR_AIGroup
msgReceiverGroup = null;
75
76
// if wounded is AI
77
SCR_AIGroup
myGroup =
SCR_AIGroup
.Cast(
GetParentGroup
());
78
if
(myGroup)
79
msgReceiverGroup = myGroup;
// Send to AI group
80
81
// if wounded is player
82
int
playerId =
GetGame
().GetPlayerManager().GetPlayerIdFromControlledEntity(controlled);
83
if
(playerId != 0)
84
{
85
SCR_GroupsManagerComponent
groupsManager =
SCR_GroupsManagerComponent
.GetInstance();
86
if
(!groupsManager)
87
return
;
88
89
SCR_AIGroup
playerGroup = groupsManager.GetPlayerGroup(playerId);
90
if
(!playerGroup)
91
return
;
92
93
SCR_AIGroup
slaveGroup = playerGroup.
GetSlave
();
94
95
if
(slaveGroup)
96
msgReceiverGroup = slaveGroup;
// Send to our slave group - this is the one which has AIs and will heal us
97
else
98
msgReceiverGroup = playerGroup;
// Send to our group
99
}
100
101
if
(!msgReceiverGroup)
102
return
;
103
104
// Inject message to the group mailbox directly.
105
// This bypasses problems of our own mailbox being disabled (because character is possessed by GM, or because we are unconscious)
106
AICommunicationComponent comms = msgReceiverGroup.GetCommunicationComponent();
107
if
(!comms)
108
return
;
109
110
SCR_AIMessage_Wounded
msg =
SCR_AIMessage_Wounded
.Create(
GetControlledEntity
());
111
msg.SetReceiver(msgReceiverGroup);
112
comms.RequestBroadcast(msg, msgReceiverGroup);
113
}
114
115
//------------------------------------------------------------------------------------------------
116
void
OnLifeStateChanged
(
ECharacterLifeState
previousLifeState,
ECharacterLifeState
newLifeState)
117
{
118
if
(newLifeState ==
ECharacterLifeState
.INCAPACITATED)
119
{
120
// first send message and then deactivate otherwise message won't be sent
121
SendWoundedMsg
();
122
GetControlComponent
().DeactivateAI();
123
124
SCR_AICommsHandler
commsHandler = m_UtilityComponent.m_CommsHandler;
125
if
(commsHandler)
126
commsHandler.
SetSuspended
(
true
);
127
128
return
;
129
}
130
else
if
(newLifeState ==
ECharacterLifeState
.DEAD)
131
{
132
GetControlComponent
().DeactivateAI();
133
SCR_AICommsHandler
commsHandler = m_UtilityComponent.m_CommsHandler;
134
if
(commsHandler)
135
commsHandler.
Reset
();
136
137
return
;
138
}
139
else
if
(newLifeState ==
ECharacterLifeState
.ALIVE)
140
{
141
bool
possesingMainEntity =
false
;
142
array<int> players =
new
array<int>;
143
GetGame
().GetPlayerManager().GetPlayers(players);
144
foreach
(
int
playerId: players)
145
{
146
if
(SCR_PossessingManagerComponent.GetPlayerMainEntity(playerId) ==
GetControlledEntity
())
147
{
148
possesingMainEntity =
true
;
149
break
;
150
}
151
}
152
153
if
(!
EntityUtils
.IsPlayer(
GetControlledEntity
()) && !possesingMainEntity)
154
GetControlComponent
().ActivateAI();
155
156
AICommunicationComponent comms =
GetCommunicationComponent
();
157
if
(comms)
158
{
159
// Clear orders, it doesn't matter if we have missed them
160
comms.ClearOrders();
161
162
// Don't clear messages, we will process them to catch up with goals from group
163
// This is crucial to resume to group orders
164
165
// Clear danger events, it doesn't matter if we have missed them
166
ClearDangerEvents
(
GetDangerEventsCount
());
167
}
168
169
SCR_AICommsHandler
commsHandler = m_UtilityComponent.m_CommsHandler;
170
if
(commsHandler)
171
commsHandler.
SetSuspended
(
false
);
172
}
173
}
174
175
//------------------------------------------------------------------------------------------------
177
bool
IsPerceivedEnemy
(
IEntity
entity)
178
{
179
Faction
otherFaction = SCR_AIFactionHandling.GetEntityPerceivedFaction(entity);
180
181
Faction
myFaction;
182
if
(
m_FactionAffiliationComponent
)
183
myFaction =
m_FactionAffiliationComponent
.GetAffiliatedFaction();
184
185
if
(!otherFaction || !myFaction)
186
return
false
;
187
188
return
myFaction.IsFactionEnemy(otherFaction);
189
}
190
191
//------------------------------------------------------------------------------------------------
192
bool
IsEnemy
(
IEntity
entity)
193
{
194
Faction
otherFaction = SCR_AIFactionHandling.GetEntityFaction(entity);
195
196
return
IsEnemy
(otherFaction);
197
}
198
199
//------------------------------------------------------------------------------------------------
200
bool
IsEnemy
(
Faction
otherFaction)
201
{
202
Faction
myFaction;
203
if
(
m_FactionAffiliationComponent
)
204
myFaction =
m_FactionAffiliationComponent
.GetAffiliatedFaction();
205
206
if
(!otherFaction || !myFaction)
207
return
false
;
208
209
return
myFaction.IsFactionEnemy(otherFaction);
210
}
211
212
//------------------------------------------------------------------------------------------------
213
void
OnGroupWaypointChanged
(AIWaypoint newWaypoint)
214
{
215
m_GroupWaypoint = newWaypoint;
216
}
217
218
//------------------------------------------------------------------------------------------------
219
void
SetPlayerPending_S
(
int
playerId)
220
{
221
if
(
m_iPendingPlayerId
!= 0 && playerId != 0)
222
{
223
Print
(
"Trying to set pending player on an already pending agent!"
,
LogLevel
.ERROR);
224
return
;
225
}
226
227
m_iPendingPlayerId
= playerId;
228
}
229
230
//------------------------------------------------------------------------------------------------
231
bool
IsPlayerPending_S
()
232
{
233
return
m_iPendingPlayerId
!= 0;
234
}
235
236
//------------------------------------------------------------------------------------------------
237
bool
ShouldAbortLoiterFast
()
238
{
239
if
(!m_UtilityComponent)
240
return
false
;
241
return
m_UtilityComponent.FindActionOfInheritedType(
SCR_AIAttackBehavior
) != null;
242
}
243
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_GroupsManagerComponent.c:1747
ChimeraAIAgentClass
Definition
ChimeraAIAgent.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
EntityUtils
Definition
EntityUtils.c:13
Faction
Definition
Faction.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
SCR_AIAttackBehavior
Definition
SCR_AIAttackBehavior.c:2
SCR_AICommsHandler
Definition
SCR_AICommsHandler.c:20
SCR_AICommsHandler::SetSuspended
void SetSuspended(bool suspended)
Definition
SCR_AICommsHandler.c:190
SCR_AICommsHandler::Reset
void Reset()
Fails and clears all requests, resets to initial state.
Definition
SCR_AICommsHandler.c:316
SCR_AIGroup
Definition
SCR_AIGroup.c:75
SCR_AIGroup::GetSlave
SCR_AIGroup GetSlave()
Definition
SCR_AIGroup.c:2604
SCR_AIInfoComponent
Definition
SCR_AIInfoComponent.c:46
SCR_AIMessage_Wounded
Definition
SCR_AIMessage.c:208
SCR_CharacterControllerComponent
Definition
SCR_CharacterControllerComponent.c:36
SCR_CharacterDamageManagerComponent
Definition
SCR_CharacterDamageManagerComponent.c:19
SCR_CharacterDamageManagerComponent::IsBleeding
bool IsBleeding()
the official and globally used way of checking if bleeding tests for any PERSISTENT damage effects of...
Definition
SCR_CharacterDamageManagerComponent.c:1336
SCR_ChimeraAIAgentClass
Definition
SCR_ChimeraAIAgent.c:2
SCR_ChimeraAIAgent
Definition
SCR_ChimeraAIAgent.c:6
SCR_ChimeraAIAgent::SendWoundedMsg
void SendWoundedMsg()
Definition
SCR_ChimeraAIAgent.c:63
SCR_ChimeraAIAgent::IsPlayerPending_S
bool IsPlayerPending_S()
Definition
SCR_ChimeraAIAgent.c:231
SCR_ChimeraAIAgent::m_iPendingPlayerId
int m_iPendingPlayerId
Definition
SCR_ChimeraAIAgent.c:14
SCR_ChimeraAIAgent::OnGroupWaypointChanged
void OnGroupWaypointChanged(AIWaypoint newWaypoint)
Definition
SCR_ChimeraAIAgent.c:213
SCR_ChimeraAIAgent::EnsureAILimit
void EnsureAILimit()
Definition
SCR_ChimeraAIAgent.c:46
SCR_ChimeraAIAgent::m_FactionAffiliationComponent
FactionAffiliationComponent m_FactionAffiliationComponent
Definition
SCR_ChimeraAIAgent.c:13
SCR_ChimeraAIAgent::IsPerceivedEnemy
bool IsPerceivedEnemy(IEntity entity)
Checks if this agent perceives the entity as enemy.
Definition
SCR_ChimeraAIAgent.c:177
SCR_ChimeraAIAgent::ShouldAbortLoiterFast
bool ShouldAbortLoiterFast()
Definition
SCR_ChimeraAIAgent.c:237
SCR_ChimeraAIAgent::m_CharacterController
SCR_CharacterControllerComponent m_CharacterController
Definition
SCR_ChimeraAIAgent.c:12
SCR_ChimeraAIAgent::SetPlayerPending_S
void SetPlayerPending_S(int playerId)
Definition
SCR_ChimeraAIAgent.c:219
SCR_ChimeraAIAgent::~SCR_ChimeraAIAgent
void ~SCR_ChimeraAIAgent()
Definition
SCR_ChimeraAIAgent.c:39
SCR_ChimeraAIAgent::EOnInit
override void EOnInit(IEntity owner)
Definition
SCR_ChimeraAIAgent.c:17
SCR_ChimeraAIAgent::IsEnemy
bool IsEnemy(IEntity entity)
Definition
SCR_ChimeraAIAgent.c:192
SCR_ChimeraAIAgent::OnLifeStateChanged
void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
Definition
SCR_ChimeraAIAgent.c:116
SCR_ChimeraAIAgent::IsEnemy
bool IsEnemy(Faction otherFaction)
Definition
SCR_ChimeraAIAgent.c:200
SCR_EntityHelper
Definition
SCR_EntityHelper.c:2
GetControlComponent
proto external AIControlComponent GetControlComponent()
GetCommunicationComponent
proto external AICommunicationComponent GetCommunicationComponent()
GetParentGroup
proto external AIGroup GetParentGroup()
GetDangerEventsCount
proto external int GetDangerEventsCount()
ClearDangerEvents
proto external void ClearDangerEvents(int howMany)
GetControlledEntity
SCR_EditableEntityComponent GetControlledEntity()
Definition
SCR_EditablePlayerDelegateComponent.c:90
ECharacterLifeState
ECharacterLifeState
Definition
ECharacterLifeState.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
scripts
Game
AI
SCR_ChimeraAIAgent.c
Generated by
1.17.0