Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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
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
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.m_Value.ToString();
101 }
102
103 override bool OnMessage(AIMessage msg)
104 {
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 static 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 static override bool VisibleInPalette() { return true; }
142};
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref SCR_BTParam< float > m_fPriorityLevel
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
TStringArray GetPortNames()
ResourceName m_sBehaviorTree
void Fail(bool doNotCompleteWaypoint)
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
override TStringArray GetVariablesOut()
Base class for all messages related to AI.
Definition AIMessage.c:14
static override bool VisibleInPalette()
override bool OnMessage(AIMessage msg)
static ref array< ref SCR_AIActivityFeatureBase > s_ActivityFeatures
override array< ref SCR_AIActivityFeatureBase > GetActivityFeatures()
override string GetActionDebugInfo()
override float CustomEvaluate()
void SCR_AIHealActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, IEntity ent, float priority=PRIORITY_ACTIVITY_HEAL, float priorityLevel=PRIORITY_LEVEL_NORMAL)
void InitParameters(IEntity entity, array< AIAgent > medicsToExclude, float priorityLevel)
static override bool VisibleInPalette()
override TStringArray GetVariablesIn()
static ref TStringArray s_aVarsIn
array< string > TStringArray
Definition Types.c:385
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.