Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIInfoComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/AI", description: "Component for AI checking state of characters")]
5
6enum EUnitRole
7{
8 NONE = 0,
10 MEDIC = 2,
14 SNIPER = 32,
17}
18
19enum EUnitState
20{
21 NONE = 0,
22 WOUNDED = 1,
23 IN_TURRET = 2,
24 IN_VEHICLE = 4,
25 PILOT = 8,
26 UNCONSCIOUS = 16
27}
28
29enum EUnitAIState
30{
31 AVAILABLE,
32 BUSY,
33 UNRESPONSIVE,
34}
35
36void SCR_AIOnCompartmentEntered(AIAgent agent, IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move);
38
39void SCR_AIOnCompartmentLeft(AIAgent agent, IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move);
41
44
45class SCR_AIInfoComponent : SCR_AIInfoBaseComponent
46{
47 protected EUnitState m_iUnitStates;
48 protected EUnitAIState m_iAIStates;
49 protected SCR_InventoryStorageManagerComponent m_inventoryManagerComponent;
50 protected BaseWeaponManagerComponent m_weaponManagerComponent;
54 protected SCR_AICombatComponent m_CombatComponent;
56 PerceptionComponent m_Perception;
57
58 ref ScriptInvokerBase<SCR_AIOnCompartmentEntered> m_OnCompartmentEntered = new ScriptInvokerBase<SCR_AIOnCompartmentEntered>();
59 ref ScriptInvokerBase<SCR_AIOnCompartmentLeft> m_OnCompartmentLeft = new ScriptInvokerBase<SCR_AIOnCompartmentLeft>();
60 ref ScriptInvokerBase<SCR_AIOnAgentLifeStateChanged> m_OnAgentLifeStateChanged = new ScriptInvokerBase<SCR_AIOnAgentLifeStateChanged>();
61
63 protected float m_fUnconsciousBloodLevel;
64
65 //------------------------------------------------------------------------------------------------
66 override protected void OnPostInit(IEntity owner)
67 {
68 super.OnPostInit(owner);
69 SetEventMask(owner, EntityEvent.INIT);
70 }
71
72 //------------------------------------------------------------------------------------------------
77 void OnVehicleEntered( IEntity vehicle, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
78 {
79 m_OnCompartmentEntered.Invoke(AIAgent.Cast(GetOwner()), vehicle, manager, mgrID, slotID, move);
80
81 AddUnitState(EUnitState.IN_VEHICLE);
82
83 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
84 ECompartmentType compType = compSlot.GetType();
85 if (compType == ECompartmentType.TURRET)
86 AddUnitState(EUnitState.IN_TURRET);
87 else if (compType == ECompartmentType.PILOT)
88 AddUnitState(EUnitState.PILOT);
89 }
90
91 //------------------------------------------------------------------------------------------------
96 void OnVehicleLeft( IEntity vehicle, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
97 {
98 m_OnCompartmentLeft.Invoke(AIAgent.Cast(GetOwner()), vehicle, manager, mgrID, slotID, move);
99
100 RemoveUnitState(EUnitState.IN_VEHICLE);
101
102 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
103 ECompartmentType compType = compSlot.GetType();
104 if (compType == ECompartmentType.TURRET)
105 RemoveUnitState(EUnitState.IN_TURRET);
106 else if (compType == ECompartmentType.PILOT)
107 RemoveUnitState(EUnitState.PILOT);
108 }
109
110
111 //------------------------------------------------------------------------------------------------
114 {
115 m_BloodHitZone = m_DamageManager.GetBloodHitZone();
116 if (m_BloodHitZone)
117 m_fUnconsciousBloodLevel = m_BloodHitZone.GetMaxHealth() * m_BloodHitZone.GetDamageStateThreshold(EDamageState.STATE3);
118 }
119
120 //------------------------------------------------------------------------------------------------
121 override protected void EOnInit(IEntity owner)
122 {
123 IEntity ent = owner;
124 AIAgent agent = AIAgent.Cast(owner);
125 if (agent)
126 ent = agent.GetControlledEntity();
127
128 if (ent)
129 {
130 m_inventoryManagerComponent = SCR_InventoryStorageManagerComponent.Cast(ent.FindComponent(SCR_InventoryStorageManagerComponent));
131 m_weaponManagerComponent = BaseWeaponManagerComponent.Cast(ent.FindComponent(BaseWeaponManagerComponent));
134 m_CombatComponent = SCR_AICombatComponent.Cast(ent.FindComponent(SCR_AICombatComponent));
135
138 m_CharacterController.m_OnLifeStateChanged.Insert(OnLifeStateChanged);
139
140 m_Perception = PerceptionComponent.Cast(ent.FindComponent(PerceptionComponent));
141 }
142
144 {
145 m_CompartmentAccessComponent.GetOnCompartmentEntered().Insert(OnVehicleEntered);
146 m_CompartmentAccessComponent.GetOnCompartmentLeft().Insert(OnVehicleLeft);
147 }
148
149 if (m_DamageManager)
150 {
152 m_DamageManager.GetOnDamageEffectAdded().Insert(OnDamageEffectAdded);
153 m_DamageManager.GetOnDamageEffectRemoved().Insert(OnDamageEffectRemoved);
155 }
156 }
157
158 //------------------------------------------------------------------------------------------------
159 // destructor
161 {
163 m_CharacterController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
164 }
165
166 //------------------------------------------------------------------------------------------------
167 override protected void OnDelete(IEntity owner)
168 {
170 {
171 m_CompartmentAccessComponent.GetOnCompartmentEntered().Remove(OnVehicleEntered);
172 m_CompartmentAccessComponent.GetOnCompartmentLeft().Remove(OnVehicleLeft);
173 }
174
175 if (m_DamageManager)
176 {
177 m_DamageManager.GetOnDamageEffectAdded().Remove(OnDamageEffectAdded);
178 m_DamageManager.GetOnDamageEffectRemoved().Remove(OnDamageEffectRemoved);
179 }
180 }
181
182 //------------------------------------------------------------------------------------------------
183 SCR_AICombatComponent GetCombatComponent()
184 {
185 return m_CombatComponent;
186 }
187
188 //------------------------------------------------------------------------------------------------
192 bool IsOwnerAgent(AIAgent agent)
193 {
194 return GetOwner() == agent;
195 }
196
197//----------- BIT operations on Roles
198
199 //------------------------------------------------------------------------------------------------
203 bool HasRole(EUnitRole role)
204 {
205 switch (role)
206 {
207 case EUnitRole.MEDIC: return m_inventoryManagerComponent.GetHealthComponentCount() > 0;
208 case EUnitRole.MACHINEGUNNER: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_MACHINEGUN);
209 case EUnitRole.RIFLEMAN: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_RIFLE);
210 case EUnitRole.AT_SPECIALIST: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_ROCKETLAUNCHER);
211 case EUnitRole.GRENADIER: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_GRENADELAUNCHER); // todo right now it will not detect a UGL muzzle, because weapon type is still rifle
212 case EUnitRole.SNIPER: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_SNIPERRIFLE);
213 case EUnitRole.HAS_SMOKE_GRENADE: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_SMOKEGRENADE);
214 case EUnitRole.HAS_FRAG_GRENADE: return m_CombatComponent.HasWeaponOfType(EWeaponType.WT_FRAGGRENADE);
215 }
216
217 return false;
218 }
219
220 //------------------------------------------------------------------------------------------------
223 EUnitRole GetRoles()
224 {
225 typename t = EUnitRole;
226 int tVarCount = t.GetVariableCount();
227 EUnitRole roles = 0;
228 for (int i = 0; i < tVarCount; i++)
229 {
230 EUnitRole flag;
231 t.GetVariableValue(null, i, flag);
232 if (flag && HasRole(flag))
233 roles |= flag;
234 }
235 return roles;
236 }
237
238//---------- BIT operation on States
239
240 //------------------------------------------------------------------------------------------------
243 void AddUnitState(EUnitState state)
244 {
246 }
247
248 //------------------------------------------------------------------------------------------------
251 void RemoveUnitState(EUnitState state)
252 {
253 if (HasUnitState(state))
254 m_iUnitStates = m_iUnitStates & ~state;
255 }
256
257 //------------------------------------------------------------------------------------------------
261 bool HasUnitState(EUnitState state)
262 {
263 return ( m_iUnitStates & state );
264 }
265
266 //------------------------------------------------------------------------------------------------
269 EUnitState GetUnitStates()
270 {
271 return m_iUnitStates;
272 }
273
274//--------- AI states are disjoined - one can be in only one state at the time
275
276 //------------------------------------------------------------------------------------------------
278 void SetAIState(EUnitAIState state)
279 {
280 m_iAIStates = state;
281 }
282
283 //------------------------------------------------------------------------------------------------
285 EUnitAIState GetAIState()
286 {
287 return m_iAIStates;
288 }
289
290//-------- Info about magazines available to SCR_AIResupplyActivity
291
292 //------------------------------------------------------------------------------------------------
295 int GetMagazineCountByWellType(typename magazinyWellType)
296 {
297 return m_CombatComponent.GetMagazineCount(magazinyWellType, false);
298 }
299
300 //------------------------------------------------------------------------------------------------
304 {
305 m_ThreatSystem = threatSystem;
306 }
307
308 //------------------------------------------------------------------------------------------------
310 EAIThreatState GetThreatState()
311 {
312 if (m_ThreatSystem)
313 return m_ThreatSystem.GetState();
314 else
315 return EAIThreatState.SAFE;
316 }
317
318 //------------------------------------------------------------------------------------------------
324
325 //------------------------------------------------------------------------------------------------
326 // Some obsolete functionality which we don't use
327
328 [Obsolete()]
330
331 [Obsolete()]
333
334 [Obsolete()]
336
337 [Obsolete()]
339
340//-------- Evaluation of wounded state of AI
341
342 //------------------------------------------------------------------------------------------------
344 protected void EvaluateWoundedState()
345 {
346 if (m_DamageManager.IsBleeding())
347 AddUnitState(EUnitState.WOUNDED);
348 else
349 RemoveUnitState(EUnitState.WOUNDED);
350 }
351
352 //------------------------------------------------------------------------------------------------
353 protected void OnDamageEffectAdded(notnull SCR_DamageEffect dmgEffect)
354 {
355 if (dmgEffect.GetDamageType() != EDamageType.BLEEDING || !DotDamageEffect.Cast(dmgEffect))
356 return;
357
359 }
360
361 //------------------------------------------------------------------------------------------------
362 protected void OnDamageEffectRemoved(notnull SCR_DamageEffect dmgEffect)
363 {
364 if (dmgEffect.GetDamageType() != EDamageType.BLEEDING || !DotDamageEffect.Cast(dmgEffect))
365 return;
366
368 }
369
370 //------------------------------------------------------------------------------------------------
372 void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
373 {
374 if (newLifeState != ECharacterLifeState.INCAPACITATED)
375 RemoveUnitState(EUnitState.UNCONSCIOUS);
376 else
377 AddUnitState(EUnitState.UNCONSCIOUS);
378
379 AIAgent agent = AIAgent.Cast(GetOwner());
380 if (!agent)
381 return;
382
383 IEntity vehicle;
384 // find which vehicle this agent is in
385 if (HasUnitState(EUnitState.IN_VEHICLE))
386 {
387 ChimeraCharacter ent = ChimeraCharacter.Cast(agent.GetControlledEntity());
388 if (!ent)
389 return;
390
391 CompartmentAccessComponent compartComp = ent.GetCompartmentAccessComponent();
392 if (!compartComp)
393 return;
394
395 vehicle = compartComp.GetVehicleIn(ent);
396
397 }
398 m_OnAgentLifeStateChanged.Invoke(agent, this, vehicle, newLifeState);
399 }
400
401 //------------------------------------------------------------------------------------------------
404 {
406 return -1;
407
408 float bleedingPerSec = m_BloodHitZone.GetTotalBleedingAmount();
409 float timeToUnconscious = -1;
410
411 if (bleedingPerSec > 0)
412 timeToUnconscious = (m_BloodHitZone.GetHealth() - m_fUnconsciousBloodLevel) / bleedingPerSec;
413
414 return timeToUnconscious;
415 }
416
417
418//-------- Debugging
419
420 //------------------------------------------------------------------------------------------------
423 // Used in SCR_AIDebugInfoComponent
425 {
426 string str;
427 str = str + string.Format("\n%1 %2", m_iAIStates, typename.EnumToString(EUnitAIState, m_iAIStates));
428 w.SetText(str);
429 }
430
431 //------------------------------------------------------------------------------------------------
434 {
435 AIAgent agent = AIAgent.Cast(GetOwner());
436
437 SCR_CallsignCharacterComponent callsignComp = SCR_CallsignCharacterComponent.Cast(agent.GetControlledEntity().FindComponent(SCR_CallsignCharacterComponent));
438
439 FactionAffiliationComponent factionComp = FactionAffiliationComponent.Cast(agent.GetControlledEntity().FindComponent(FactionAffiliationComponent));
440
441 string str;
442
443 if (factionComp)
444 {
445 string faction = factionComp.GetAffiliatedFaction().GetFactionKey();
446 str = str + string.Format("[%1] ", faction);
447 }
448
449 if (callsignComp)
450 {
451 string company, platoon, squad, character, format;
452 bool setCallsign = callsignComp.GetCallsignNames(company, platoon, squad, character, format);
453 if (setCallsign)
454 {
455 string callsign = WidgetManager.Translate(format, company, platoon, squad, character);
456 str = str + string.Format(" %1", callsign);
457 }
458 }
459 return str;
460 }
461}
ECompartmentType
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_AIInfoComponentClass HAS_FRAG_GRENADE
SCR_AIInfoComponentClass RIFLEMAN
SCR_AIInfoComponentClass MACHINEGUNNER
SCR_AIInfoComponentClass SNIPER
func SCR_AIOnAgentLifeStateChanged
SCR_AIInfoComponentClass MEDIC
SCR_AIInfoComponentClass HAS_SMOKE_GRENADE
SCR_AIInfoComponentClass GRENADIER
SCR_AIInfoComponentClass AT_SPECIALIST
func SCR_AIOnCompartmentLeft
func SCR_AIOnCompartmentEntered
@ WOUNDED
@ UNCONSCIOUS
SCR_CommunicationSoundComponentClass PILOT
proto external Managed FindComponent(typename typeName)
SCR_CompartmentAccessComponent m_CompartmentAccessComponent
SCR_AICombatComponent m_CombatComponent
void AddUnitState(EUnitState state)
void SetMovementType(EMovementType mode)
SCR_CharacterDamageManagerComponent m_DamageManager
SCR_InventoryStorageManagerComponent m_inventoryManagerComponent
bool HasUnitState(EUnitState state)
void EOnInit(IEntity owner)
void EvaluateWoundedState()
Returns true when state has changed and we must invoke an event.
SCR_AICombatComponent GetCombatComponent()
void OnDamageEffectRemoved(notnull SCR_DamageEffect dmgEffect)
SCR_CharacterControllerComponent m_CharacterController
BaseWeaponManagerComponent m_weaponManagerComponent
void InitThreatSystem(SCR_AIThreatSystem threatSystem)
void OnDelete(IEntity owner)
EMovementType GetMovementType()
PerceptionComponent m_Perception
void OnPostInit(IEntity owner)
void SetAIState(EUnitAIState state)
int GetMagazineCountByWellType(typename magazinyWellType)
ref ScriptInvokerBase< SCR_AIOnCompartmentLeft > m_OnCompartmentLeft
void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
void OnVehicleEntered(IEntity vehicle, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
ECharacterStance GetStance()
void OnVehicleLeft(IEntity vehicle, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
bool IsOwnerAgent(AIAgent agent)
void OnDamageEffectAdded(notnull SCR_DamageEffect dmgEffect)
SCR_CharacterBloodHitZone m_BloodHitZone
ref ScriptInvokerBase< SCR_AIOnCompartmentEntered > m_OnCompartmentEntered
void DebugPrintToWidget(TextWidget w)
void RemoveUnitState(EUnitState state)
SCR_AIThreatSystem GetThreatSystem()
void SetStance(ECharacterStance stance)
bool HasRole(EUnitRole role)
SCR_AIThreatSystem m_ThreatSystem
EAIThreatState GetThreatState()
ref ScriptInvokerBase< SCR_AIOnAgentLifeStateChanged > m_OnAgentLifeStateChanged
Blood - does not receive damage directly, only via scripted events.
IEntity GetOwner()
Owner entity of the fuel tank.
ECharacterStance
EMovementType
ECharacterLifeState
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EDamageType
Definition EDamageType.c:13
EDamageState
EWeaponType
Definition EWeaponType.c:13