Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIHealingBehavior.c
Go to the documentation of this file.
1 // AI healing behaviour
2 // TODO: You have to handle situation, in which movement can be disabled (in AIConfig component)
3 
5 {
6  IEntity m_EntityToHeal;
7 
8  SCR_AIInfoComponent m_AIInfo;
9  SCR_DamageManagerComponent m_DamageManager;
10 
11  protected const float PRIORITY_DELAY_MIN_MS = 800.0; // Delay until action returns its max priority
12  protected const float PRIORITY_DELAY_MAX_MS = 1200.0;
13 
14  protected const float MAX_TIME_TO_UNCON_HIGH_PRIORITY_S = 30; // Time in seconds to losing consciousness below which we treat healing ourselves as high priority
15 
16  protected float m_fTimeCreated_ms;
17  protected float m_fPriorityDelay_ms;
18 
19  //-------------------------------------------------------------------------------------------------------------------------------
21  void SCR_AIHealBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, IEntity entityToHeal, bool allowHealMove, float priority = PRIORITY_BEHAVIOR_HEAL, float priorityLevel = PRIORITY_LEVEL_NORMAL)
22  {
23  m_sBehaviorTree = "AI/BehaviorTrees/Chimera/Soldier/Heal.bt";
24  m_EntityToHeal = entityToHeal;
25  SetPriority(priority);
26  m_fPriorityLevel.m_Value = priorityLevel;
27  m_fTimeCreated_ms = GetGame().GetWorld().GetWorldTime();
28  m_fPriorityDelay_ms = Math.RandomFloat(PRIORITY_DELAY_MIN_MS, PRIORITY_DELAY_MAX_MS);
29 
30  SCR_AIUtilityComponent aiUtilComp = SCR_AIUtilityComponent.Cast(utility);
31  if (!aiUtilComp)
32  return;
33 
34  IEntity owner = aiUtilComp.m_OwnerEntity;
35  if (owner)
36  {
37  m_DamageManager = SCR_DamageManagerComponent.Cast(owner.FindComponent(SCR_DamageManagerComponent));
38  m_AIInfo = aiUtilComp.m_AIInfo;
39  }
40  }
41 
42  override void OnActionCompleted()
43  {
44  super.OnActionCompleted();
45 #ifdef WORKBENCH
46  SCR_AIDebugVisualization.VisualizeMessage(m_Utility.m_OwnerEntity, "Unit healed", EAIDebugCategory.INFO, 5);
47 #endif
48  }
49 
50  override float CustomEvaluate()
51  {
52  if (!(GetGame().GetWorld().GetWorldTime() - m_fTimeCreated_ms > m_fPriorityDelay_ms))
53  return 0;
54 
55  // We should heal ourselves with high priority if time to uncon is lower then treshold
56  if (m_AIInfo && m_AIInfo.GetBleedTimeToUnconscious() < MAX_TIME_TO_UNCON_HIGH_PRIORITY_S)
57  return PRIORITY_BEHAVIOR_HEAL_HIGH_PRIORITY;
58 
59  if (m_Utility.m_ThreatSystem.GetThreatMeasureWithoutInjuryFactor() < SCR_AIThreatSystem.VIGILANT_THRESHOLD)
60  return GetPriority();
61 
62  return 0;
63  }
64 };
SCR_AIDebugVisualization
Definition: SCR_AIDebugVisualization.c:9
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
GetPriority
int GetPriority()
Definition: SCR_BaseManualCameraComponent.c:107
EAIDebugCategory
EAIDebugCategory
Definition: SCR_AIWorld.c:11
SCR_AIHealBehavior
Definition: SCR_AIHealingBehavior.c:4
m_AIInfo
SCR_AIInfoComponent m_AIInfo
Definition: SCR_AIUtilityComponent.c:11
m_DamageManager
DamageManagerComponent m_DamageManager
Definition: SCR_AITargetInfo.c:19
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1
SCR_AIThreatSystem
Definition: SCR_AIThreatSystem.c:17