Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionCallsignData.c
Go to the documentation of this file.
1
3{
6
7 protected int m_iOverflowIndex;
8 protected bool m_bRandomizedCallsigns;
9
10 //------------------------------------------------------------------------------------------------
11 // constructor
14 {
15 m_iOverflowIndex = factionCallsignInfo.GetCompanyOverflowIndex();
16 m_bRandomizedCallsigns = factionCallsignInfo.GetIsAssignedRandomly();
17
18 array<ref SCR_CallsignInfo> companyArray = {};
19 factionCallsignInfo.GetCompanyArray(companyArray);
20 int count = companyArray.Count();
21
22 for(int i = 0; i < count; i++)
23 {
25 companyData.Init(factionCallsignInfo);
26
27 //Check if overflow company and add it to correct map
28 if (i < m_iOverflowIndex)
29 m_mCompanyCallsigns.Insert(i, companyData);
30 //Overflow means it only grabs these if non of the default companies are available
31 else
32 m_mCompanyOverflowCallsigns.Insert(i, companyData);
33 }
34 }
35
36 //------------------------------------------------------------------------------------------------
43 bool GetRandomCallsign(out int company, out int platoon, out int squad)
44 {
45 SCR_CallsignCompanyData randomCompany;
46 int random;
47
48 //Default companies still available
49 if (!m_mCompanyCallsigns.IsEmpty())
50 {
51 random = Math.RandomInt(0, m_mCompanyCallsigns.Count());
52 company = m_mCompanyCallsigns.GetKey(random);
53 randomCompany = m_mCompanyCallsigns.GetElement(random);
54 }
55
56 //Use overflow companies
57 else if (!m_mCompanyOverflowCallsigns.IsEmpty())
58 {
59 random = Math.RandomInt(0, m_mCompanyOverflowCallsigns.Count());
60 company = m_mCompanyOverflowCallsigns.GetKey(random);
61 randomCompany = m_mCompanyOverflowCallsigns.GetElement(random);
62 }
63 //No companies available
64 else
65 {
66 return false;
67 }
68
69 randomCompany.GetRandomCallsign(platoon, squad);
70
71 return true;
72 }
73
74 //------------------------------------------------------------------------------------------------
81 // TODO: availible -> available
82 bool GetFirstAvailibleCallsign(out int firstAvailableCompany, out int firstAvailablePlatoon, out int firstAvailableSquad)
83 {
84 firstAvailableCompany = int.MAX;
85 SCR_CallsignCompanyData firstAvailableCompanyData;
86
87 //Default companies still available
88 if (!m_mCompanyCallsigns.IsEmpty())
89 {
91 {
92 if (index < firstAvailableCompany)
93 {
94 firstAvailableCompany = index;
95 firstAvailableCompanyData = company;
96 }
97 }
98 }
99 //Use overflow companies
100 else if (!m_mCompanyOverflowCallsigns.IsEmpty())
101 {
103 {
104 if (index < firstAvailableCompany)
105 {
106 firstAvailableCompany = index;
107 firstAvailableCompanyData = company;
108 }
109 }
110 }
111 //No companies available
112 else
113 {
114 return false;
115 }
116
117 firstAvailableCompanyData.GetFirstAvailibleCallsign(firstAvailablePlatoon, firstAvailableSquad);
118 return true;
119 }
120
121 //------------------------------------------------------------------------------------------------
128 bool GetSpecificCompanyCallsign(out int company, out int platoon, out int squad)
129 {
130 SCR_CallsignCompanyData companyData;
131
132 //Get specific company
133 if (!m_mCompanyCallsigns.Find(company, companyData))
134 m_mCompanyOverflowCallsigns.Find(company, companyData);
135
136 //Specific company found
137 if (companyData)
138 {
140 companyData.GetFirstAvailibleCallsign(platoon, squad);
141 else
142 companyData.GetRandomCallsign(platoon, squad);
143 }
144 //Company not available, use default logics
145 else
146 {
148 return GetFirstAvailibleCallsign(company, platoon, squad);
149 else
150 return GetRandomCallsign(company, platoon, squad);
151 }
152
153 return true;
154 }
155
156 //------------------------------------------------------------------------------------------------
164 bool GetGroupRoleSpecificCompanyCallsign(notnull SCR_AIGroup group, out int company, out int platoon, out int squad)
165 {
166 SCR_Faction groupFaction = SCR_Faction.Cast(group.GetFaction());
167 if (!groupFaction)
168 return false;
169
170 SCR_FactionCallsignInfo factionCallsignInfo = groupFaction.GetCallsignInfo();
171 if (!factionCallsignInfo)
172 return false;
173
174 array<int> companyIndexes = {};
175 SCR_EGroupRole groupRole = group.GetGroupRole();
176 if (!factionCallsignInfo.GetGroupRoleSpecificCompanies(groupRole, companyIndexes))
177 return false;
178
179 company = int.MAX;
180 SCR_CallsignCompanyData companyData;
181 foreach (int companyIndex : companyIndexes)
182 {
183 if (!m_mCompanyCallsigns.Find(companyIndex, companyData))
184 continue;
185
186 if (!companyData || !companyData.GetFirstAvailableSquadCallsign(platoon, squad))
187 continue;
188
189 company = companyIndex;
190 break;
191 }
192
193 if (company != int.MAX)
194 return true;
195
196 // No available companies for group, use one of the overflow companies instead
197 if (!m_mCompanyOverflowCallsigns.IsEmpty())
198 return false;
199
200 int overflowCompaniesCount = m_mCompanyOverflowCallsigns.Count();
201 int companyIndex;
202 for (int i = 0; i < overflowCompaniesCount; i++)
203 {
204 companyIndex = m_mCompanyOverflowCallsigns.GetKey(i);
205 if (!m_mCompanyCallsigns.Find(companyIndex, companyData))
206 continue;
207
208 if (!companyData || !companyData.GetFirstAvailableSquadCallsign(platoon, squad))
209 continue;
210
211 company = companyIndex;
212 break;
213 }
214
215 // Return false if no available company found in group role specific companies nor overflow companies
216 return company != int.MAX;
217 }
218
219 //------------------------------------------------------------------------------------------------
224 void AddCallsign(int companyIndex, int platoonIndex, int squadIndex)
225 {
226 SCR_CallsignCompanyData companyData;
227
228 if (companyIndex < m_iOverflowIndex)
229 {
230 if (m_mCompanyCallsigns.Find(companyIndex, companyData))
231 {
232 companyData.AddCallsign(platoonIndex, squadIndex);
233 }
234 else
235 {
236 companyData = new SCR_CallsignCompanyData();
237 companyData.AddCallsign(platoonIndex, squadIndex);
238 m_mCompanyCallsigns.Insert(companyIndex, companyData);
239 }
240 }
241 else
242 {
243 if (m_mCompanyOverflowCallsigns.Find(companyIndex, companyData))
244 {
245 companyData.AddCallsign(platoonIndex, squadIndex);
246 }
247 else
248 {
249 companyData = new SCR_CallsignCompanyData();
250 companyData.AddCallsign(platoonIndex, squadIndex);
251 m_mCompanyOverflowCallsigns.Insert(companyIndex, companyData);
252 }
253 }
254 }
255
256 //------------------------------------------------------------------------------------------------
261 void RemoveCallsign(int companyIndex, int platoonIndex, int squadIndex)
262 {
263 SCR_CallsignCompanyData companyData;
264
265 if (companyIndex < m_iOverflowIndex)
266 {
267 if (m_mCompanyCallsigns.Find(companyIndex, companyData))
268 {
269 //Check if all platoons are used then remove company
270 if (companyData.RemoveCallsign(platoonIndex, squadIndex))
271 {
272 m_mCompanyCallsigns.Remove(companyIndex);
273 }
274 }
275 }
276 else
277 {
278 if (m_mCompanyOverflowCallsigns.Find(companyIndex, companyData))
279 {
280 //Check if all platoons are used then remove company
281 if (companyData.RemoveCallsign(platoonIndex, squadIndex))
282 {
283 m_mCompanyOverflowCallsigns.Remove(companyIndex);
284 }
285 }
286 }
287 }
288}
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EGroupRole
Group roles.
Definition Math.c:13
Removes callsign from availible callsign pool param platoon index param squad index *bool RemoveCallsign(int plattonIndex, int squadIndex)
Init Company creating all the platoons within which in turn create the availible squads within param factionCallsignInfo specific callsign info for faction *void Init(SCR_FactionCallsignInfo factionCallsignInfo)
Adds callsign back to availible callsign pool param platoon index param squad index *void AddCallsign(int platoonIndex, int squadIndex)
bool GetFirstAvailableSquadCallsign(out int firstAvailablePlatoon, out int firstAvailableSquad)
Gets platoon and squad index randomly from availible callsigns param[out] platoon index param[out] squad index return bool true if succesfully found a callsign *void GetRandomCallsign(out int platoon, out int squad)
Goes through all availible platoons and squads and gets the first availible Meaning if platoon is taken it will get next not param[out] platoon index param[out] squad index return bool true if succesfully found a callsign *void GetFirstAvailibleCallsign(out int firstAvailiblePlatoon, out int firstAvailibleSquad)
void AddCallsign(int companyIndex, int platoonIndex, int squadIndex)
ref map< int, ref SCR_CallsignCompanyData > m_mCompanyOverflowCallsigns
bool GetRandomCallsign(out int company, out int platoon, out int squad)
bool GetSpecificCompanyCallsign(out int company, out int platoon, out int squad)
void RemoveCallsign(int companyIndex, int platoonIndex, int squadIndex)
bool GetGroupRoleSpecificCompanyCallsign(notnull SCR_AIGroup group, out int company, out int platoon, out int squad)
bool GetFirstAvailibleCallsign(out int firstAvailableCompany, out int firstAvailablePlatoon, out int firstAvailableSquad)
void SCR_FactionCallsignData(SCR_FactionCallsignInfo factionCallsignInfo)
ref map< int, ref SCR_CallsignCompanyData > m_mCompanyCallsigns
bool GetGroupRoleSpecificCompanies(SCR_EGroupRole groupRole, notnull out array< int > companyIndexes)
void GetCompanyArray(notnull array< ref SCR_CallsignInfo > companyArray)
SCR_FactionCallsignInfo GetCallsignInfo()
Definition Types.c:486
@ MAX