Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ChimeraAIAgent.c
Go to the documentation of this file.
4
5class 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
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());
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 //------------------------------------------------------------------------------------------------
40 {
42 m_CharacterController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
43 }
44
45 //------------------------------------------------------------------------------------------------
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
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
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
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
167 }
168
169 SCR_AICommsHandler commsHandler = m_UtilityComponent.m_CommsHandler;
170 if (commsHandler)
171 commsHandler.SetSuspended(false);
172 }
173 }
174
175 //------------------------------------------------------------------------------------------------
178 {
179 Faction otherFaction = SCR_AIFactionHandling.GetEntityPerceivedFaction(entity);
180
181 Faction myFaction;
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;
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 //------------------------------------------------------------------------------------------------
232 {
233 return m_iPendingPlayerId != 0;
234 }
235
236 //------------------------------------------------------------------------------------------------
238 {
239 if (!m_UtilityComponent)
240 return false;
241 return m_UtilityComponent.FindActionOfInheritedType(SCR_AIAttackBehavior) != null;
242 }
243};
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
void SetSuspended(bool suspended)
void Reset()
Fails and clears all requests, resets to initial state.
SCR_AIGroup GetSlave()
bool IsBleeding()
the official and globally used way of checking if bleeding tests for any PERSISTENT damage effects of...
void OnGroupWaypointChanged(AIWaypoint newWaypoint)
FactionAffiliationComponent m_FactionAffiliationComponent
bool IsPerceivedEnemy(IEntity entity)
Checks if this agent perceives the entity as enemy.
SCR_CharacterControllerComponent m_CharacterController
void SetPlayerPending_S(int playerId)
override void EOnInit(IEntity owner)
bool IsEnemy(IEntity entity)
void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
bool IsEnemy(Faction otherFaction)
proto external AIControlComponent GetControlComponent()
proto external AICommunicationComponent GetCommunicationComponent()
proto external AIGroup GetParentGroup()
proto external int GetDangerEventsCount()
proto external void ClearDangerEvents(int howMany)
SCR_EditableEntityComponent GetControlledEntity()
ECharacterLifeState
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14