Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIHealActivity.c
Go to the documentation of this file.
2 {
3  const string GROUP_MEMBERS_EXCLUDE_PORT = "AgentsExclude";
4  const string MEDIC_PORT = "MedicEntity";
5 
6  const int TIMEOUT_FAILED = 5*60*1000;
7 
8  ref SCR_BTParam<IEntity> m_EntityToHeal = new SCR_BTParam<IEntity>(SCR_AIActionTask.ENTITY_PORT);
9 
10  // Selected medic. Assigned from behavior tree.
11  ref SCR_BTParam<IEntity> m_MedicEntity = new SCR_BTParam<IEntity>(MEDIC_PORT);
12 
13  // BTParam can't hold a ref to object, so we hold a ref to it ourselves through a member variable
14  ref array<AIAgent> m_aMedicsExclude = {};
15  ref SCR_BTParam<array<AIAgent>> m_aMedicsExcludeParam = new SCR_BTParam<array<AIAgent>>(GROUP_MEMBERS_EXCLUDE_PORT);
16 
17  protected float m_fTimeCreated_world; // World time when this was created
18 
19  protected float m_fTimeCheckConditions_world;
20 
21  // Features
22  static ref array<ref SCR_AIActivityFeatureBase> s_ActivityFeatures = {new SCR_AIHealActivitySmokeCoverFeature()};
23  override array<ref SCR_AIActivityFeatureBase> GetActivityFeatures() { return s_ActivityFeatures; }
24 
25  override float CustomEvaluate()
26  {
27  float worldTime = GetGame().GetWorld().GetWorldTime();
28 
29  if (worldTime - m_fTimeCheckConditions_world > 2500)
30  {
31  // Fail if target is null or destroyed
32  if (!SCR_AIDamageHandling.IsAlive(m_EntityToHeal.m_Value))
33  {
34  #ifdef AI_DEBUG
35  AddDebugMessage("Target entity is null or destroyed, action failed.");
36  #endif
37 
38  Fail();
39  return 0;
40  }
41 
42  // Complete if entity is not wounded any more
43  if (!SCR_AIDamageHandling.IsCharacterWounded(m_EntityToHeal.m_Value))
44  {
45  Complete();
46  return 0;
47  }
48 
49  // Replan if medic is null or destroyed
50  if (!SCR_AIDamageHandling.IsAlive(m_MedicEntity.m_Value))
51  {
52  SetActionIsSuspended(false);
53  }
54 
55  m_fTimeCheckConditions_world = worldTime;
56  }
57 
58  // Fail on timeout
59  if (worldTime - m_fTimeCreated_world > TIMEOUT_FAILED)
60  {
61  #ifdef AI_DEBUG
62  AddDebugMessage("Timeout, action failed.");
63  #endif
64 
65  Fail();
66  return 0;
67  }
68 
69 
70 
71  return GetPriority();
72  }
73 
74  void InitParameters(IEntity entity, array<AIAgent> medicsToExclude, float priorityLevel)
75  {
76  IEntity medic = null;
77  m_EntityToHeal.Init(this, entity);
78  m_aMedicsExcludeParam.Init(this, medicsToExclude);
79  m_fPriorityLevel.Init(this,priorityLevel);
80  m_MedicEntity.Init(this, medic); // Must use a variable, otherwise null directly doesn't work with templates.
81  }
82 
83  //-------------------------------------------------------------------------------------------------------
84  void SCR_AIHealActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, IEntity ent, float priority = PRIORITY_ACTIVITY_HEAL, float priorityLevel = PRIORITY_LEVEL_NORMAL)
85  {
86  m_sBehaviorTree = "AI/BehaviorTrees/Chimera/Group/ActivityHeal.bt";
87  SetPriority(priority);
88  InitParameters(ent, m_aMedicsExclude, priorityLevel);
89  SetIsUniqueInActionQueue(false);
90 
91  auto game = GetGame();
92  if (game)
93  {
94  m_fTimeCreated_world = game.GetWorld().GetWorldTime();
95  }
96  }
97 
98  override string GetActionDebugInfo()
99  {
100  return this.ToString() + " healing unit " + m_EntityToHeal.ValueToString();
101  }
102 
103  override bool OnMessage(AIMessage msg)
104  {
105  SCR_AIMessage_HealFailed healFailed = SCR_AIMessage_HealFailed.Cast(msg);
106 
107  if (healFailed)
108  {
109  // Did someone fail to heal our entity?
110  if (healFailed.m_TargetEntity != m_EntityToHeal.m_Value)
111  return false;
112 
113  // Don't pick this medic any more
114  m_aMedicsExclude.Insert(healFailed.GetSender());
115 
116  #ifdef AI_DEBUG
117  AddDebugMessage(string.Format("Medic %1 has failed the action. MedicsExclude: %2", healFailed.GetSender(), m_aMedicsExclude));
118  #endif
119 
120  // Request re-run of this activity
121  SetActionIsSuspended(false);
122  return true;
123  }
124 
125  return false;
126  }
127 };
128 
130 {
131  static ref TStringArray s_aVarsOut = (new SCR_AIHealActivity(null, null, null)).GetPortNames();
132  override TStringArray GetVariablesOut() { return s_aVarsOut; }
133 
134  override bool VisibleInPalette() { return true; }
135 };
136 
138 {
139  protected static ref TStringArray s_aVarsIn = (new SCR_AIHealActivity(null, null, null)).GetPortNames();
140  override TStringArray GetVariablesIn() { return s_aVarsIn; }
141  override bool VisibleInPalette() { return true; }
142 };
SCR_AIDamageHandling
Definition: SCR_AIUtils.c:246
SCR_AISetHealActivityParameters
Definition: SCR_AIHealActivity.c:137
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_AIHealActivity
Definition: SCR_AIHealActivity.c:1
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
SCR_AIGetHealActivityParameters
Definition: SCR_AIHealActivity.c:129
GetPriority
int GetPriority()
Definition: SCR_BaseManualCameraComponent.c:107
SCR_AISetActionParameters
Definition: SCR_AISetActionParameters.c:7
SCR_AIGetActionParameters
Definition: SCR_AIGetActionParameters.c:22
SCR_AIMessage_HealFailed
Definition: SCR_AIMessage.c:251
SCR_AIActionTask
Definition: SCR_AIBehaviorTask.c:1