Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIFindResupplier.c
Go to the documentation of this file.
2{
3 static const string PORT_REQUIREMENTS_IN = "RequirementsIn";
4 static const string PORT_ENTITY_IN = "EntityIn";
5 static const string PORT_GROUP_MEMBER_OUT = "GroupMemberOut";
6 static const string PORT_IS_UNIQUE_OUT = "IsUniqueOut";
7 static const string PORT_AGENTS_EXCLUDE_ARRAY = "AgentsExcludeArray";
8
9 SCR_AIGroupUtilityComponent m_GroupUtilityComponent;
10
11 //------------------------------------------------------------------------------------------------
12 static override bool VisibleInPalette() {return true;}
13
14 //------------------------------------------------------------------------------------------------
15 override void OnInit(AIAgent owner)
16 {
17 AIGroup group = AIGroup.Cast(owner);
18 if (group)
19 m_GroupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(group.FindComponent(SCR_AIGroupUtilityComponent));
20 }
21
22 //------------------------------------------------------------------------------------------------
23 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
24 {
25 if (!m_GroupUtilityComponent || !m_GroupUtilityComponent.m_aInfoComponents)
26 return ENodeResult.FAIL;
27
28 bool notFound = true, isUnique = true, isRolePresent = false;
29 SCR_AIInfoComponent aIInfoComponent;
30
31 typename magazineWell;
32 int magazineMaxCountIndex,magazineCount,magazineMaxCount = 0;
33
34 IEntity inEntity;
35 GetVariableIn(PORT_ENTITY_IN, inEntity);
36
37 if (!GetVariableIn(PORT_REQUIREMENTS_IN, magazineWell))
38 Debug.Error("No MagazineWell provided for resupply?!");
39
40 array<AIAgent> agentsExclude;
41 if (!GetVariableIn(PORT_AGENTS_EXCLUDE_ARRAY, agentsExclude))
42 agentsExclude = {};
43
44 int selectedIndex = m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex;
45
46 int length = m_GroupUtilityComponent.m_aInfoComponents.Count();
47 for (int i = 0; i < length; i++)
48 {
49 aIInfoComponent = m_GroupUtilityComponent.m_aInfoComponents[(i + selectedIndex) % length];
50 if( !aIInfoComponent )
51 return ENodeResult.FAIL;
52 //prevent selecting requesting EntityID
53 AIAgent agent = AIAgent.Cast(aIInfoComponent.GetOwner());
54 if(!agent)
55 continue;
56 if(agent.GetControlledEntity() == inEntity)
57 continue;
58 if(agentsExclude.Contains(agent))
59 continue;
60 if (aIInfoComponent.HasUnitState(EUnitState.UNCONSCIOUS))
61 continue;
62
63
64 magazineCount = aIInfoComponent.GetMagazineCountByWellType(magazineWell);
65 if (magazineCount > magazineMaxCount)
66 {
67 if (isRolePresent)
68 isUnique = false;
69 else
70 isRolePresent = true;
71 magazineMaxCount = magazineCount;
72 magazineMaxCountIndex = i;
73 if (aIInfoComponent.GetAIState() == EUnitAIState.AVAILABLE)
74 {
75 if (notFound)
76 {
77 notFound = false;
78 selectedIndex = (i + selectedIndex) % length;
79 }
80 else
81 {
82 selectedIndex = (i + selectedIndex) % length;
83 isUnique = false;
84 }
85 }
86 }
87 }
88
89 if (length != 0)
90 m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = (selectedIndex + 1) % length; // If we don't do +1, next time we start checking same member
91 else
92 m_GroupUtilityComponent.m_iGetMemberByGoalNextIndex = 0;
93
94 if (!isRolePresent)
95 {
96 return ENodeResult.FAIL;
97 }
98
99 if (!notFound)
100 {
101 AIAgent agent = AIAgent.Cast(m_GroupUtilityComponent.m_aInfoComponents[selectedIndex].GetOwner());
102 if (agent)
103 SetVariableOut(PORT_GROUP_MEMBER_OUT,agent);
104 else
105 return ENodeResult.FAIL;
106
107 SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
108 return ENodeResult.SUCCESS;
109 }
110 else if (isUnique) // I have only one unit that is not available = unit that requested the resupply
111 {
112 ClearVariable(PORT_GROUP_MEMBER_OUT);
113 SetVariableOut(PORT_IS_UNIQUE_OUT,isUnique);
114 return ENodeResult.FAIL;
115 }
116
117 ClearVariable(PORT_GROUP_MEMBER_OUT);
118 ClearVariable(PORT_IS_UNIQUE_OUT);
119
120
121 return ENodeResult.RUNNING;
122 }
123
124 //------------------------------------------------------------------------------------------------
125 static override protected bool CanReturnRunning()
126 {
127 return true;
128 }
129
130 //------------------------------------------------------------------------------------------------
131 protected static ref TStringArray s_aVarsOut = {
132 PORT_GROUP_MEMBER_OUT,
133 PORT_IS_UNIQUE_OUT
134 };
136 {
137 return s_aVarsOut;
138 }
139
140 //------------------------------------------------------------------------------------------------
141 protected static ref TStringArray s_aVarsIn = {
142 PORT_REQUIREMENTS_IN,
143 PORT_ENTITY_IN,
144 PORT_AGENTS_EXCLUDE_ARRAY
145 };
147 {
148 return s_aVarsIn;
149 }
150
151 //------------------------------------------------------------------------------------------------
152 protected static override string GetOnHoverDescription()
153 {
154 return "Getter returns group member available for ressuply";
155 }
156};
Definition Debug.c:13
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
bool VisibleInPalette()
proto void ClearVariable(string name)
static override string GetOnHoverDescription()
static ref TStringArray s_aVarsIn
static ref TStringArray s_aVarsOut
override TStringArray GetVariablesOut()
override TStringArray GetVariablesIn()
bool HasUnitState(EUnitState state)
int GetMagazineCountByWellType(typename magazinyWellType)
ENodeResult
Definition ENodeResult.c:13
array< string > TStringArray
Definition Types.c:385