Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CallsignCharacterComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Callsign", description: "")]
3 {
4 }
5 
7 class SCR_CallsignCharacterComponent : SCR_CallsignBaseComponent
8 {
9  //Broadcast
10  protected int m_iCharacterCallsign = -1;
12  protected bool m_bAloneInGroup = false;
13  protected int m_iFactioniD = -1;
14  protected int m_iPlayerId = 0; //~ Set on server only
15 
16  //------------------------------------------------------------------------------------------------
17  override bool GetCallsignNames(out string company, out string platoon, out string squad, out string character, out string format)
18  {
19  int companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignNumber, characterRoleCallsignIndex;
20  character = string.Empty;
21 
22  if (!GetCallsignIndexes(companyCallsignIndex, platoonCallsignIndex, squadCallsignIndex, characterCallsignNumber, characterRoleCallsignIndex))
23  return false;
24 
25  //Get character callsign if not alone in group or if player, or has a role and that role is not leader (AI only) (Can't really be a leader of yourself)
26  bool showCharacterCallsign = !GetIsCharacterAloneInGroup() || (m_iPlayerId > 0 || SCR_PossessingManagerComponent.GetPlayerIdFromMainEntity(GetOwner()) > 0);
27 
28  //No callsign data
29  if (!SetCallsignInfo())
30  {
31  company = companyCallsignIndex.ToString();
32  platoon = platoonCallsignIndex.ToString();
33  squad = squadCallsignIndex.ToString();
34  character = characterCallsignNumber.ToString();
35  format = "ERROR %1-%2-%3-%4";
36 
37  return true;
38  }
39 
40  company = m_CallsignInfo.GetCompanyCallsignName(companyCallsignIndex);
41  platoon = m_CallsignInfo.GetPlatoonCallsignName(platoonCallsignIndex);
42  squad = m_CallsignInfo.GetSquadCallsignName(squadCallsignIndex);
43 
44  //Character callsign
45  if (showCharacterCallsign)
46  {
47  if (characterRoleCallsignIndex >= 0)
48  character = m_CallsignInfo.GetCharacterRoleCallsignName(characterRoleCallsignIndex);
49  else
50  character = characterCallsignNumber.ToString();
51  }
52 
53  format = m_CallsignInfo.GetCallsignFormat(showCharacterCallsign, characterRoleCallsignIndex);
54  return true;
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  override bool GetCallsignIndexes(out int companyIndex, out int platoonIndex, out int squadIndex, out int characterNumber = -1, out ERoleCallsign characterRole = ERoleCallsign.NONE)
59  {
60  if (m_iCompanyCallsign < 0 || m_iPlatoonCallsign < 0 || m_iSquadCallsign < 0)
61  {
62  companyIndex = -1;
63  platoonIndex = -1;
64  squadIndex = -1;
65  return false;
66  }
67 
68  companyIndex = m_iCompanyCallsign;
69  platoonIndex = m_iPlatoonCallsign;
70  squadIndex = m_iSquadCallsign;
71 
72  GetCharacterAndRoleCallsign(characterNumber, characterRole);
73  return true;
74  }
75 
76 
77  //------------------------------------------------------------------------------------------------
86  void AssignCharacterCallsign(Faction faction, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign role, bool aloneInGroup)
87  {
88  if (!m_bIsServer)
89  return;
90 
91  //On Faction changed
92  if (m_Faction != faction && faction != null)
93  {
94  FactionManager factionManager = GetGame().GetFactionManager();
95  if (factionManager)
96  {
97  int factionId = factionManager.GetFactionIndex(faction);
98  m_Faction = faction;
99  Rpc(SetFactionBroadCast, factionId);
100  }
101  }
102 
103  if (companyIndex == m_iCompanyCallsign && m_iPlatoonCallsign == platoonIndex && m_iSquadCallsign == squadIndex && m_iCharacterCallsign == characterNumber && m_iRoleCallsign == role && m_bAloneInGroup == aloneInGroup)
104  return;
105 
106  //If group did not change
107  if (companyIndex == m_iCompanyCallsign && m_iPlatoonCallsign == platoonIndex && m_iSquadCallsign == squadIndex && m_bAloneInGroup == aloneInGroup)
108  {
109  //If role did not change
110  if (m_iRoleCallsign == role)
111  {
112  AssignCharacterCallsignBroadcast(characterNumber);
113  Rpc(AssignCharacterCallsignBroadcast, characterNumber);
114  }
115  //If role did change
116  else
117  {
118  AssignCharacterAndRoleCallsignBroadcast(characterNumber, role);
119  Rpc(AssignCharacterAndRoleCallsignBroadcast, characterNumber, role);
120  }
121  }
122  //If group did change but not role
123  else if (m_iRoleCallsign == role)
124  {
125  AssignCallsignNoRoleBroadcast(companyIndex, platoonIndex, squadIndex, characterNumber, aloneInGroup);
126  Rpc(AssignCallsignNoRoleBroadcast, companyIndex, platoonIndex, squadIndex, characterNumber, aloneInGroup);
127  }
128  //If role and group changed
129  else
130  {
131  AssignCallsignBroadcast(companyIndex, platoonIndex, squadIndex, characterNumber, role, aloneInGroup);
132  Rpc(AssignCallsignBroadcast, companyIndex, platoonIndex, squadIndex, characterNumber, role, aloneInGroup);
133  }
134  }
135 
136  //------------------------------------------------------------------------------------------------
140  {
141  if (!m_bIsServer)
142  return;
143 
144  //If role did not change
145  if (m_iRoleCallsign == roleCallsignIndex)
146  return;
147 
148  AssignRoleCallsignBroadcast(roleCallsignIndex);
149  Rpc(AssignRoleCallsignBroadcast, roleCallsignIndex);
150  }
151 
152  //------------------------------------------------------------------------------------------------
156  void UpdateCharacterCallsignAndRole(int characterCallsign, ERoleCallsign roleCallsignIndex)
157  {
158  if (!m_bIsServer)
159  return;
160 
161  //If callsigns did not change
162  if (m_iCharacterCallsign == characterCallsign && m_iRoleCallsign == roleCallsignIndex)
163  return;
164 
165  AssignCharacterAndRoleCallsignBroadcast(characterCallsign, roleCallsignIndex);
166  Rpc(AssignCharacterAndRoleCallsignBroadcast, characterCallsign, roleCallsignIndex);
167  }
168 
169  //------------------------------------------------------------------------------------------------
171  override void ClearCallsigns()
172  {
173  super.ClearCallsigns();
175  m_iRoleCallsign = -1;
176  }
177 
178  //------------------------------------------------------------------------------------------------
181  {
182  if (!m_bIsServer)
183  return;
184 
185  m_iRoleCallsign = -1;
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
190  protected void AssignCallsignBroadcast(int company, int platoon, int squad, int character, int role, bool aloneInGroup)
191  {
192  m_iCompanyCallsign = company;
193  m_iPlatoonCallsign = platoon;
194  m_iSquadCallsign = squad;
195  m_iCharacterCallsign = character;
196  m_iRoleCallsign = role;
197  m_bAloneInGroup = aloneInGroup;
198 
199  Event_OnCallsignChanged.Invoke(m_iCompanyCallsign, m_iPlatoonCallsign, m_iSquadCallsign, m_iCharacterCallsign, m_iRoleCallsign);
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
204  protected void AssignCallsignNoRoleBroadcast(int company, int platoon, int squad, int character, bool aloneInGroup)
205  {
206  m_iCompanyCallsign = company;
207  m_iPlatoonCallsign = platoon;
208  m_iSquadCallsign = squad;
209  m_iCharacterCallsign = character;
210  m_bAloneInGroup = aloneInGroup;
211 
212  Event_OnCallsignChanged.Invoke(m_iCompanyCallsign, m_iPlatoonCallsign, m_iSquadCallsign, m_iCharacterCallsign, m_iRoleCallsign);
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
217  protected void AssignCharacterAndRoleCallsignBroadcast(int character, int role)
218  {
219  m_iCharacterCallsign = character;
220  m_iRoleCallsign = role;
221 
222  Event_OnCallsignChanged.Invoke(m_iCompanyCallsign, m_iPlatoonCallsign, m_iSquadCallsign, m_iCharacterCallsign, m_iRoleCallsign);
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
227  protected void AssignCharacterCallsignBroadcast(int character)
228  {
229  m_iCharacterCallsign = character;
230 
231  Event_OnCallsignChanged.Invoke(m_iCompanyCallsign, m_iPlatoonCallsign, m_iSquadCallsign, m_iCharacterCallsign, m_iRoleCallsign);
232  }
233 
234  //------------------------------------------------------------------------------------------------
235  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
236  protected void AssignRoleCallsignBroadcast(int role)
237  {
238  m_iRoleCallsign = role;
239 
240  Event_OnCallsignChanged.Invoke(m_iCompanyCallsign, m_iPlatoonCallsign, m_iSquadCallsign, m_iCharacterCallsign, m_iRoleCallsign);
241  }
242 
243  //------------------------------------------------------------------------------------------------
244  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
245  protected void SetAloneInGroupBroadcast(bool isAloneInGroup)
246  {
247  m_bAloneInGroup = isAloneInGroup;
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
252  protected void SetFactionBroadCast(int factionID)
253  {
254  m_iFactioniD = factionID;
255 
256  FactionManager factionManager = GetGame().GetFactionManager();
257  if (!factionManager)
258  return;
259 
260  Faction faction = factionManager.GetFactionByIndex(factionID);
261 
262  if (faction != m_Faction && faction != null)
263  {
264  m_Faction = faction;
265  m_CallsignInfo = null;
266  }
267  }
268 
269  //------------------------------------------------------------------------------------------------
272  {
273  return m_bAloneInGroup;
274  }
275 
276  //------------------------------------------------------------------------------------------------
280  {
281  return m_iCharacterCallsign;
282  }
283 
284  //------------------------------------------------------------------------------------------------
288  {
289  if (m_iRoleCallsign >= 0)
290  return m_iRoleCallsign;
291  else
292  return m_iCharacterCallsign;
293  }
294 
295  //------------------------------------------------------------------------------------------------
299  void GetCharacterAndRoleCallsign(out int character, out int role)
300  {
301  character = m_iCharacterCallsign;
302  role = m_iRoleCallsign;
303  }
304 
305  //------------------------------------------------------------------------------------------------
309  bool GetCharacterCallsignName(out string characterCallsignName)
310  {
311  if(m_iCharacterCallsign == -1)
312  return false;
313 
314  if (m_iRoleCallsign >= 0)
315  characterCallsignName = m_CallsignInfo.GetCharacterRoleCallsignName(m_iRoleCallsign);
316  else
317  m_iCharacterCallsign.ToString();
318 
319  return true;
320  }
321 
322  //------------------------------------------------------------------------------------------------
323  //~ Server only. On Player callsign changed
324  protected void OnPlayerCallsignChanged(int playerId, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign characterRole)
325  {
326  //~ This player's callsign was not changed
327  if (playerId != m_iPlayerId)
328  return;
329 
330  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
331  if (!groupManager)
332  {
333  AssignCharacterCallsign(null, -1, -1, -1, -1, -1, true);
334  return;
335  }
336 
337  //~ No group so remove callsign
338  SCR_AIGroup playerGroup = groupManager.GetPlayerGroup(playerId);
339  if (!playerGroup)
340  {
341  AssignCharacterCallsign(null, -1, -1, -1, -1, -1, true);
342  return;
343  }
344 
345  AssignCharacterCallsign(playerGroup.GetFaction(), companyIndex, platoonIndex, squadIndex, characterNumber, characterRole, playerGroup.GetPlayerAndAgentCount(true) <= 1);
346  }
347 
348  //------------------------------------------------------------------------------------------------
351  void InitPlayerOnServer(int playerId)
352  {
353  if (playerId <= 0 || m_iPlayerId > 0)
354  return;
355 
356  m_iPlayerId = playerId;
357 
358  //~ Subscribe to player callsign changed
359  m_CallsignManager.GetOnPlayerCallsignChanged().Insert(OnPlayerCallsignChanged);
360  }
361 
362  //------------------------------------------------------------------------------------------------
363  override bool RplSave(ScriptBitWriter writer)
364  {
365  writer.WriteInt(m_iCompanyCallsign);
366  writer.WriteInt(m_iPlatoonCallsign);
367  writer.WriteInt(m_iSquadCallsign);
368  writer.WriteInt(m_iCharacterCallsign);
369  writer.WriteInt(m_iRoleCallsign);
370  writer.WriteBool(m_bAloneInGroup);
371  writer.WriteInt(m_iFactioniD);
372 
373  return true;
374  }
375 
376  //------------------------------------------------------------------------------------------------
377  override bool RplLoad(ScriptBitReader reader)
378  {
379  int company, platoon, squad, character, role, factionID;
380  bool aloneInGroup;
381 
382  reader.ReadInt(company);
383  reader.ReadInt(platoon);
384  reader.ReadInt(squad);
385  reader.ReadInt(character);
386  reader.ReadInt(role);
387  reader.ReadBool(aloneInGroup);
388  reader.ReadInt(factionID);
389 
390  AssignCallsignBroadcast(company, platoon, squad, character, role, aloneInGroup);
391  SetFactionBroadCast(factionID);
392 
393  return true;
394  }
395 
396  //------------------------------------------------------------------------------------------------
397  // destructor
399  {
400  if (!m_bIsServer || m_iPlayerId <= 0 || !m_CallsignManager)
401  return;
402 
403  //~ Remove Player CallsignChanged
404  m_CallsignManager.GetOnPlayerCallsignChanged().Remove(OnPlayerCallsignChanged);
405  }
406 }
GetCharacterOrRoleCallsignIndex
int GetCharacterOrRoleCallsignIndex()
Definition: SCR_CallsignCharacterComponent.c:287
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
AssignRoleCallsignBroadcast
protected void AssignRoleCallsignBroadcast(int role)
Definition: SCR_CallsignCharacterComponent.c:236
GetCharacterCallsignName
bool GetCharacterCallsignName(out string characterCallsignName)
Definition: SCR_CallsignCharacterComponent.c:309
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ClearCallsigns
override void ClearCallsigns()
Called on server only before assigning new callsign to make sure everything is clear....
Definition: SCR_CallsignCharacterComponent.c:171
ERoleCallsign
ERoleCallsign
Definition: ERoleCallsign.c:4
GetCharacterAndRoleCallsign
void GetCharacterAndRoleCallsign(out int character, out int role)
Definition: SCR_CallsignCharacterComponent.c:299
AssignCallsignNoRoleBroadcast
protected void AssignCallsignNoRoleBroadcast(int company, int platoon, int squad, int character, bool aloneInGroup)
Definition: SCR_CallsignCharacterComponent.c:204
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
m_iRoleCallsign
protected ERoleCallsign m_iRoleCallsign
Definition: SCR_CallsignCharacterComponent.c:11
SCR_CallsignBaseComponent
Component of assigning and storing squad names.
Definition: SCR_CallsignBaseComponent.c:11
GetCallsignNames
override bool GetCallsignNames(out string company, out string platoon, out string squad, out string character, out string format)
Definition: SCR_CallsignCharacterComponent.c:17
GetCharacterCallsignIndex
int GetCharacterCallsignIndex()
Definition: SCR_CallsignCharacterComponent.c:279
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_CallsignCharacterComponent.c:377
m_CallsignInfo
protected ref SCR_FactionCallsignInfo m_CallsignInfo
Definition: SCR_Faction.c:29
m_iCharacterCallsign
SCR_CallsignCharacterComponentClass m_iCharacterCallsign
Component of assigning and storing squad names.
UpdateCharacterRoleCallsign
void UpdateCharacterRoleCallsign(ERoleCallsign roleCallsignIndex)
Definition: SCR_CallsignCharacterComponent.c:139
UpdateCharacterCallsignAndRole
void UpdateCharacterCallsignAndRole(int characterCallsign, ERoleCallsign roleCallsignIndex)
Definition: SCR_CallsignCharacterComponent.c:156
GetCallsignIndexes
override bool GetCallsignIndexes(out int companyIndex, out int platoonIndex, out int squadIndex, out int characterNumber=-1, out ERoleCallsign characterRole=ERoleCallsign.NONE)
Definition: SCR_CallsignCharacterComponent.c:58
m_bAloneInGroup
protected bool m_bAloneInGroup
Definition: SCR_CallsignCharacterComponent.c:12
InitPlayerOnServer
void InitPlayerOnServer(int playerId)
Definition: SCR_CallsignCharacterComponent.c:351
SetAloneInGroupBroadcast
protected void SetAloneInGroupBroadcast(bool isAloneInGroup)
Definition: SCR_CallsignCharacterComponent.c:245
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_iPlayerId
protected int m_iPlayerId
Definition: SCR_CallsignCharacterComponent.c:14
Faction
Definition: Faction.c:12
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
m_iFactioniD
protected int m_iFactioniD
Definition: SCR_CallsignCharacterComponent.c:13
OnPlayerCallsignChanged
protected void OnPlayerCallsignChanged(int playerId, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign characterRole)
Definition: SCR_CallsignCharacterComponent.c:324
SetFactionBroadCast
protected void SetFactionBroadCast(int factionID)
Definition: SCR_CallsignCharacterComponent.c:252
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_CallsignCharacterComponent.c:363
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_CallsignCharacterComponentClass
Definition: SCR_CallsignCharacterComponent.c:2
GetIsCharacterAloneInGroup
bool GetIsCharacterAloneInGroup()
Definition: SCR_CallsignCharacterComponent.c:271
AssignCharacterCallsignBroadcast
protected void AssignCharacterCallsignBroadcast(int character)
Definition: SCR_CallsignCharacterComponent.c:227
SCR_CallsignBaseComponentClass
Definition: SCR_CallsignBaseComponent.c:2
m_Faction
Faction m_Faction
Definition: SCR_AITargetInfo.c:18
AssignCharacterAndRoleCallsignBroadcast
protected void AssignCharacterAndRoleCallsignBroadcast(int character, int role)
Definition: SCR_CallsignCharacterComponent.c:217
ClearCharacterRoleCallsign
void ClearCharacterRoleCallsign()
Called on server only before assigning new role callsign to make sure everything is clear....
Definition: SCR_CallsignCharacterComponent.c:180
~SCR_CallsignCharacterComponent
void ~SCR_CallsignCharacterComponent()
Definition: SCR_CallsignCharacterComponent.c:398
AssignCallsignBroadcast
protected void AssignCallsignBroadcast(int company, int platoon, int squad, int character, int role, bool aloneInGroup)
Definition: SCR_CallsignCharacterComponent.c:190
AssignCharacterCallsign
void AssignCharacterCallsign(Faction faction, int companyIndex, int platoonIndex, int squadIndex, int characterNumber, ERoleCallsign role, bool aloneInGroup)
Definition: SCR_CallsignCharacterComponent.c:86
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180