Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetMemberByGoal.c
Go to the documentation of this file.
2 {
3  NONE,
4  HEAL,
6 };
7 
8 class SCR_AIGetMemberByGoal: AITaskScripted
9 {
10  static const string PORT_REQUIREMENTS_IN = "RequirementsIn";
11  static const string PORT_ENTITY_IN = "EntityIn";
12  static const string PORT_GROUP_MEMBER_OUT = "GroupMemberOut";
13  static const string PORT_IS_UNIQUE_OUT = "IsUniqueOut";
14  static const string PORT_AGENTS_EXCLUDE_ARRAY = "AgentsExcludeArray";
15 
16  [Attribute("0", UIWidgets.ComboBox, "Find member best for goal", "", ParamEnumArray.FromEnum(EGroupGoals) )]
17  protected EGroupGoals m_goalToAchieve;
18 
19  SCR_AIGroupUtilityComponent m_GroupUtilityComponent;
20 
21  //------------------------------------------------------------------------------------------------
22  override bool VisibleInPalette() {return true;}
23 
24  //------------------------------------------------------------------------------------------------
25  override void OnInit(AIAgent owner)
26  {
27  AIGroup group = AIGroup.Cast(owner);
28  if (group)
29  m_GroupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(group.FindComponent(SCR_AIGroupUtilityComponent));
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
34  {
35  if (!m_GroupUtilityComponent || !m_GroupUtilityComponent.m_aInfoComponents)
36  return ENodeResult.FAIL;
37 
38  bool notFound = true, isUnique = true, isRolePresent = false;
39  SCR_AIInfoComponent aIInfoComponent;
40 
41  typename magazineWell;
42  int magazineMaxCountIndex,magazineCount,magazineMaxCount = 0;
43 
44  IEntity inEntity;
45  GetVariableIn(PORT_ENTITY_IN, inEntity);
46 
47  if (m_goalToAchieve == EGroupGoals.RESUPPLY && !GetVariableIn(PORT_REQUIREMENTS_IN, magazineWell))
48  Debug.Error("No MagazineWell provided for resupply?!");
49 
50  array<AIAgent> agentsExclude;
51  if (!GetVariableIn(PORT_AGENTS_EXCLUDE_ARRAY, agentsExclude))
52  agentsExclude = {};
53 
54  int selectedIndex = m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex;
55 
56  int length = m_GroupUtilityComponent.m_aInfoComponents.Count();
57  for (int i = 0; i < length; i++)
58  {
59  aIInfoComponent = m_GroupUtilityComponent.m_aInfoComponents[(i + selectedIndex) % length];
60  if( !aIInfoComponent )
61  return ENodeResult.FAIL;
62  //prevent selecting requesting EntityID
63  AIAgent agent = AIAgent.Cast(aIInfoComponent.GetOwner());
64  if(!agent)
65  continue;
66  if(agent.GetControlledEntity() == inEntity)
67  continue;
68  if(agentsExclude.Contains(agent))
69  continue;
70  if (aIInfoComponent.HasUnitState(EUnitState.UNCONSCIOUS))
71  continue;
72 
73 
74  switch (m_goalToAchieve)
75  {
76  case EGroupGoals.RESUPPLY:
77  {
78  magazineCount = aIInfoComponent.GetMagazineCountByWellType(magazineWell);
79  if (magazineCount > magazineMaxCount)
80  {
81  if (isRolePresent)
82  isUnique = false;
83  else
84  isRolePresent = true;
85  magazineMaxCount = magazineCount;
86  magazineMaxCountIndex = i;
87  if (aIInfoComponent.GetAIState() == EUnitAIState.AVAILABLE)
88  {
89  if (notFound)
90  {
91  notFound = false;
92  selectedIndex = (i + selectedIndex) % length;
93  }
94  else
95  {
96  selectedIndex = (i + selectedIndex) % length;
97  isUnique = false;
98  }
99  }
100  }
101  break;
102  }
103  case EGroupGoals.HEAL:
104  {
105  if (aIInfoComponent.HasRole(EUnitRole.MEDIC))
106  {
107  isRolePresent = true;
108  if (aIInfoComponent.GetAIState() == EUnitAIState.AVAILABLE)
109  {
110  if (notFound)
111  {
112  notFound = false;
113  selectedIndex = (i + selectedIndex) % length;
114  }
115  else
116  isUnique = false;
117  }
118  }
119  break;
120  }
121  }
122  }
123 
124  if (length != 0)
125  m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = (selectedIndex + 1) % length; // If we don't do +1, next time we start checking same member
126  else
127  m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = 0;
128 
129  if (!isRolePresent)
130  {
131  return ENodeResult.FAIL;
132  }
133 
134  if (!notFound)
135  {
136  AIAgent agent = AIAgent.Cast(m_GroupUtilityComponent.m_aInfoComponents[selectedIndex].GetOwner());
137  if (agent)
138  SetVariableOut(PORT_GROUP_MEMBER_OUT,agent);
139  else
140  return ENodeResult.FAIL;
141 
142  SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
143  return ENodeResult.SUCCESS;
144  }
145  else if (m_goalToAchieve == EGroupGoals.RESUPPLY && isUnique) // I have only one unit that is not available = unit that requested the resupply
146  {
147  ClearVariable(PORT_GROUP_MEMBER_OUT);
148  SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
149  return ENodeResult.FAIL;
150  }
151 
152  ClearVariable(PORT_GROUP_MEMBER_OUT);
153  ClearVariable(PORT_IS_UNIQUE_OUT);
154 
155 
156  return ENodeResult.RUNNING;
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  override protected bool CanReturnRunning()
161  {
162  return true;
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  protected static ref TStringArray s_aVarsOut = {
167  PORT_GROUP_MEMBER_OUT,
168  PORT_IS_UNIQUE_OUT
169  };
170  override TStringArray GetVariablesOut()
171  {
172  return s_aVarsOut;
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  protected static ref TStringArray s_aVarsIn = {
177  PORT_REQUIREMENTS_IN,
178  PORT_ENTITY_IN,
179  PORT_AGENTS_EXCLUDE_ARRAY
180  };
181  override TStringArray GetVariablesIn()
182  {
183  return s_aVarsIn;
184  }
185 
186  //------------------------------------------------------------------------------------------------
187  protected override string GetNodeMiddleText()
188  {
189  return "Goal " + typename.EnumToString(EGroupGoals,m_goalToAchieve);
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  protected override string GetOnHoverDescription()
194  {
195  return "Getter returns group member available for specific role";
196  }
197 };
HEAL
@ HEAL
Definition: SCR_AIGetMemberByGoal.c:4
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
EGroupGoals
EGroupGoals
Definition: SCR_AIGetMemberByGoal.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
RESUPPLY
@ RESUPPLY
Definition: SCR_AIGetMemberByGoal.c:5
SCR_AIGetMemberByGoal
Definition: SCR_AIGetMemberByGoal.c:8
NONE
@ NONE
Definition: SCR_AIGetMemberByGoal.c:3