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";
16 [
Attribute(
"0", UIWidgets.ComboBox,
"Find member best for goal",
"", ParamEnumArray.FromEnum(
EGroupGoals) )]
19 SCR_AIGroupUtilityComponent m_GroupUtilityComponent;
22 override bool VisibleInPalette() {
return true;}
25 override void OnInit(AIAgent owner)
27 AIGroup group = AIGroup.Cast(owner);
29 m_GroupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(group.FindComponent(SCR_AIGroupUtilityComponent));
33 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
35 if (!m_GroupUtilityComponent || !m_GroupUtilityComponent.m_aInfoComponents)
36 return ENodeResult.FAIL;
38 bool notFound =
true, isUnique =
true, isRolePresent =
false;
39 SCR_AIInfoComponent aIInfoComponent;
41 typename magazineWell;
42 int magazineMaxCountIndex,magazineCount,magazineMaxCount = 0;
45 GetVariableIn(PORT_ENTITY_IN, inEntity);
47 if (m_goalToAchieve ==
EGroupGoals.RESUPPLY && !GetVariableIn(PORT_REQUIREMENTS_IN, magazineWell))
48 Debug.Error(
"No MagazineWell provided for resupply?!");
50 array<AIAgent> agentsExclude;
51 if (!GetVariableIn(PORT_AGENTS_EXCLUDE_ARRAY, agentsExclude))
54 int selectedIndex = m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex;
56 int length = m_GroupUtilityComponent.m_aInfoComponents.Count();
57 for (
int i = 0; i < length; i++)
59 aIInfoComponent = m_GroupUtilityComponent.m_aInfoComponents[(i + selectedIndex) % length];
60 if( !aIInfoComponent )
61 return ENodeResult.FAIL;
63 AIAgent agent = AIAgent.Cast(aIInfoComponent.GetOwner());
66 if(agent.GetControlledEntity() == inEntity)
68 if(agentsExclude.Contains(agent))
70 if (aIInfoComponent.HasUnitState(EUnitState.UNCONSCIOUS))
74 switch (m_goalToAchieve)
78 magazineCount = aIInfoComponent.GetMagazineCountByWellType(magazineWell);
79 if (magazineCount > magazineMaxCount)
85 magazineMaxCount = magazineCount;
86 magazineMaxCountIndex = i;
87 if (aIInfoComponent.GetAIState() == EUnitAIState.AVAILABLE)
92 selectedIndex = (i + selectedIndex) % length;
96 selectedIndex = (i + selectedIndex) % length;
105 if (aIInfoComponent.HasRole(EUnitRole.MEDIC))
107 isRolePresent =
true;
108 if (aIInfoComponent.GetAIState() == EUnitAIState.AVAILABLE)
113 selectedIndex = (i + selectedIndex) % length;
125 m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = (selectedIndex + 1) % length;
127 m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = 0;
131 return ENodeResult.FAIL;
136 AIAgent agent = AIAgent.Cast(m_GroupUtilityComponent.m_aInfoComponents[selectedIndex].GetOwner());
138 SetVariableOut(PORT_GROUP_MEMBER_OUT,agent);
140 return ENodeResult.FAIL;
142 SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
143 return ENodeResult.SUCCESS;
145 else if (m_goalToAchieve ==
EGroupGoals.RESUPPLY && isUnique)
147 ClearVariable(PORT_GROUP_MEMBER_OUT);
148 SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
149 return ENodeResult.FAIL;
152 ClearVariable(PORT_GROUP_MEMBER_OUT);
153 ClearVariable(PORT_IS_UNIQUE_OUT);
156 return ENodeResult.RUNNING;
160 override protected bool CanReturnRunning()
166 protected static ref TStringArray s_aVarsOut = {
167 PORT_GROUP_MEMBER_OUT,
170 override TStringArray GetVariablesOut()
176 protected static ref TStringArray s_aVarsIn = {
177 PORT_REQUIREMENTS_IN,
179 PORT_AGENTS_EXCLUDE_ARRAY
181 override TStringArray GetVariablesIn()
187 protected override string GetNodeMiddleText()
189 return "Goal " +
typename.EnumToString(
EGroupGoals,m_goalToAchieve);
193 protected override string GetOnHoverDescription()
195 return "Getter returns group member available for specific role";