3 static const string WAYPOINT_ENTITY_IN =
"WaypointEntityIn";
5 private EAIWaypointCompletionType m_eCompletionType;
6 private int m_iNumberOfSALeft = 0;
7 private ENodeResult m_eSACompletedResult = ENodeResult.RUNNING;
8 private bool m_bLeaderWasSuccessful;
9 private bool m_bIsRegisteredTags =
false;
12 private ref array<string> m_arrayOfTags;
13 private AIAgent m_leaderAgent;
15 private IEntity m_SmartActionEntity;
17 private string m_smartActionTag;
18 private ref array<Managed> m_smartActionComponents;
21 protected static ref TStringArray s_aVarsIn = {
24 override TStringArray GetVariablesIn()
30 protected override void OnInit(AIAgent owner)
32 m_smartActionComponents =
new array<Managed>;
33 m_arrayOfTags =
new array<string>;
37 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
39 AIWaypoint targetWaypoint;
40 GetVariableIn(
"WaypointEntityIn", targetWaypoint);
44 NodeError(
this, owner,
"Waypoint parameter is not of correct type");
45 return ENodeResult.FAIL;
48 AIGroup group = AIGroup.Cast(owner);
50 m_leaderAgent = group.GetLeaderAgent();
51 else m_leaderAgent = owner;
55 if (m_prevWaypoint != m_waypoint)
59 if (m_prevWaypoint && m_smartActionComponents)
60 UnregisterSmartActionsWithTag(m_smartActionTag,m_smartActionComponents);
62 m_eCompletionType = targetWaypoint.GetCompletionType();
63 m_waypoint.GetSmartActionEntity(m_SmartActionEntity, m_smartActionTag);
64 if (!m_SmartActionEntity || m_smartActionTag.IsEmpty())
65 NodeError(
this, owner,
"Waypoint is not set properly");
67 FindAllSmartActionComponents(m_SmartActionEntity,m_smartActionComponents);
68 m_iNumberOfSALeft = RegisterSmartActionsWithTag(m_smartActionTag, m_smartActionComponents);
69 m_prevWaypoint = m_waypoint;
73 switch (m_eCompletionType)
75 case EAIWaypointCompletionType.All:
78 if (m_eSACompletedResult == ENodeResult.FAIL)
81 return ENodeResult.FAIL;
83 else if (m_iNumberOfSALeft == 0)
86 return ENodeResult.SUCCESS;
90 case EAIWaypointCompletionType.Any:
93 if (m_eSACompletedResult == ENodeResult.SUCCESS)
96 return ENodeResult.SUCCESS;
98 else if (m_iNumberOfSALeft == 0)
101 return ENodeResult.FAIL;
105 case EAIWaypointCompletionType.Leader:
107 if (m_bLeaderWasSuccessful)
110 return ENodeResult.SUCCESS;
112 else if (m_iNumberOfSALeft == 0)
115 return ENodeResult.FAIL;
120 return ENodeResult.RUNNING;
124 override void OnAbort(AIAgent owner, Node nodeCausingAbort)
130 int FindAllSmartActionComponents(IEntity entityContainingSmartActions, out array<Managed> smartActionComponents)
133 IEntity child = entityContainingSmartActions.GetChildren();
136 array<Managed> smartActionComponentsOfOneEntity = {};
138 smartActionComponents.InsertAll(smartActionComponentsOfOneEntity);
139 child = child.GetSibling();
141 return smartActionComponents.Count();
145 int RegisterSmartActionsWithTag(
string tag, array<Managed> smartActionComponents)
148 foreach (Managed managedComp : smartActionComponents)
151 comp.GetTags(m_arrayOfTags);
152 if (m_arrayOfTags.Contains(tag))
155 comp.GetOnActionEnd().Insert(OnSmartActionEnd);
156 comp.GetOnActionFailed().Insert(OnSmartActionFailed);
159 m_bIsRegisteredTags =
true;
164 void UnregisterSmartActionsWithTag(
string tag, array<Managed> smartActionComponents)
166 if (!m_bIsRegisteredTags)
169 foreach (Managed managedComp : smartActionComponents)
174 comp.GetTags(m_arrayOfTags);
175 if (m_arrayOfTags.Contains(tag))
177 comp.GetOnActionEnd().Remove(OnSmartActionEnd);
178 comp.GetOnActionFailed().Remove(OnSmartActionFailed);
182 m_arrayOfTags.Clear();
183 m_smartActionComponents =
null;
184 m_bIsRegisteredTags =
false;
188 void OnSmartActionEnd(AIAgent user)
190 m_iNumberOfSALeft = Math.Max(m_iNumberOfSALeft - 1,0);
191 if (user == m_leaderAgent)
192 m_bLeaderWasSuccessful =
true;
193 m_eSACompletedResult = ENodeResult.SUCCESS;
197 void OnSmartActionFailed(AIAgent user)
199 m_iNumberOfSALeft = Math.Max(m_iNumberOfSALeft - 1,0);
200 m_eSACompletedResult = ENodeResult.FAIL;
204 private void ResetVariables()
206 UnregisterSmartActionsWithTag(m_smartActionTag, m_smartActionComponents);
207 m_iNumberOfSALeft = 0;
208 m_eSACompletedResult = ENodeResult.RUNNING;
209 m_bLeaderWasSuccessful =
false;
210 m_leaderAgent =
null;
215 protected override bool VisibleInPalette()
221 override bool CanReturnRunning()
227 protected override string GetOnHoverDescription()
229 return "Node that checks if smart actions from given waypoint have been completed depending on settings of the waypoint, returns SUCCESS if they were.";