Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FactionCallsignData.c
Go to the documentation of this file.
3 {
4  protected ref map<int, ref SCR_CallsignCompanyData> m_mCompanyCallsigns = new map<int, ref SCR_CallsignCompanyData>();
5  protected ref map<int, ref SCR_CallsignCompanyData> m_mCompanyOverflowCallsigns = new map<int, ref SCR_CallsignCompanyData>();
6 
7  protected int m_iOverflowIndex;
8  protected bool m_bRandomizedCallsigns;
9 
10  //------------------------------------------------------------------------------------------------
11  // constructor
13  void SCR_FactionCallsignData(SCR_FactionCallsignInfo factionCallsignInfo)
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  Math.Randomize(-1);
52  random = Math.RandomInt(0, m_mCompanyCallsigns.Count());
53  company = m_mCompanyCallsigns.GetKey(random);
54  randomCompany = m_mCompanyCallsigns.GetElement(random);
55  }
56 
57  //Use overflow companies
58  else if (!m_mCompanyOverflowCallsigns.IsEmpty())
59  {
60  Math.Randomize(-1);
61  random = Math.RandomInt(0, m_mCompanyOverflowCallsigns.Count());
62  company = m_mCompanyOverflowCallsigns.GetKey(random);
63  randomCompany = m_mCompanyOverflowCallsigns.GetElement(random);
64  }
65  //No companies available
66  else
67  {
68  return false;
69  }
70 
71  randomCompany.GetRandomCallsign(platoon, squad);
72 
73  return true;
74  }
75 
76  //------------------------------------------------------------------------------------------------
83  // TODO: availible -> available
84  bool GetFirstAvailibleCallsign(out int firstAvailableCompany, out int firstAvailablePlatoon, out int firstAvailableSquad)
85  {
86  firstAvailableCompany = int.MAX;
87  SCR_CallsignCompanyData firstAvailableCompanyData;
88 
89  //Default companies still available
90  if (!m_mCompanyCallsigns.IsEmpty())
91  {
92  foreach (int index, SCR_CallsignCompanyData company: m_mCompanyCallsigns)
93  {
94  if (index < firstAvailableCompany)
95  {
96  firstAvailableCompany = index;
97  firstAvailableCompanyData = company;
98  }
99  }
100  }
101  //Use overflow companies
102  else if (!m_mCompanyOverflowCallsigns.IsEmpty())
103  {
104  foreach (int index, SCR_CallsignCompanyData company: m_mCompanyOverflowCallsigns)
105  {
106  if (index < firstAvailableCompany)
107  {
108  firstAvailableCompany = index;
109  firstAvailableCompanyData = company;
110  }
111  }
112  }
113  //No companies available
114  else
115  {
116  return false;
117  }
118 
119  firstAvailableCompanyData.GetFirstAvailibleCallsign(firstAvailablePlatoon, firstAvailableSquad);
120  return true;
121  }
122 
123  //------------------------------------------------------------------------------------------------
130  bool GetSpecificCompanyCallsign(out int company, out int platoon, out int squad)
131  {
132  SCR_CallsignCompanyData companyData;
133 
134  //Get specific company
135  if (!m_mCompanyCallsigns.Find(company, companyData))
136  m_mCompanyOverflowCallsigns.Find(company, companyData);
137 
138  //Specific company found
139  if (companyData)
140  {
141  if (!m_bRandomizedCallsigns)
142  companyData.GetFirstAvailibleCallsign(platoon, squad);
143  else
144  companyData.GetRandomCallsign(platoon, squad);
145  }
146  //Company not available, use default logics
147  else
148  {
149  if (!m_bRandomizedCallsigns)
150  return GetFirstAvailibleCallsign(company, platoon, squad);
151  else
152  return GetRandomCallsign(company, platoon, squad);
153  }
154 
155  return true;
156  }
157 
158  //------------------------------------------------------------------------------------------------
163  void AddCallsign(int companyIndex, int platoonIndex, int squadIndex)
164  {
165  SCR_CallsignCompanyData companyData;
166 
167  if (companyIndex < m_iOverflowIndex)
168  {
169  if (m_mCompanyCallsigns.Find(companyIndex, companyData))
170  {
171  companyData.AddCallsign(platoonIndex, squadIndex);
172  }
173  else
174  {
175  companyData = new SCR_CallsignCompanyData();
176  companyData.AddCallsign(platoonIndex, squadIndex);
177  m_mCompanyCallsigns.Insert(companyIndex, companyData);
178  }
179  }
180  else
181  {
182  if (m_mCompanyOverflowCallsigns.Find(companyIndex, companyData))
183  {
184  companyData.AddCallsign(platoonIndex, squadIndex);
185  }
186  else
187  {
188  companyData = new SCR_CallsignCompanyData();
189  companyData.AddCallsign(platoonIndex, squadIndex);
190  m_mCompanyOverflowCallsigns.Insert(companyIndex, companyData);
191  }
192  }
193  }
194 
195  //------------------------------------------------------------------------------------------------
200  void RemoveCallsign(int companyIndex, int platoonIndex, int squadIndex)
201  {
202  SCR_CallsignCompanyData companyData;
203 
204  if (companyIndex < m_iOverflowIndex)
205  {
206  if (m_mCompanyCallsigns.Find(companyIndex, companyData))
207  {
208  //Check if all platoons are used then remove company
209  if (companyData.RemoveCallsign(platoonIndex, squadIndex))
210  {
211  m_mCompanyCallsigns.Remove(companyIndex);
212  }
213  }
214  }
215  else
216  {
217  if (m_mCompanyOverflowCallsigns.Find(companyIndex, companyData))
218  {
219  //Check if all platoons are used then remove company
220  if (companyData.RemoveCallsign(platoonIndex, squadIndex))
221  {
222  m_mCompanyOverflowCallsigns.Remove(companyIndex);
223  }
224  }
225  }
226  }
227 }
SCR_FactionCallsignData
For each faction, holds available companies, which in turn hold available platoons,...
Definition: SCR_FactionCallsignData.c:2
SCR_FactionCallsignInfo
Definition: SCR_FactionCallsignInfo.c:5
SCR_CallsignCompanyData
Definition: SCR_CallsignCompanyData.c:4
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17