Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GroupIdentityComponent.c
Go to the documentation of this file.
3 
4 [ComponentEditorProps(category: "GameScripted/Misc", description: "")]
5 class SCR_GroupIdentityComponentClass : ScriptComponentClass
6 {
7 }
8 
9 class SCR_GroupIdentityComponent : ScriptComponent
10 {
11  [Attribute()]
12  protected ref SCR_MilitarySymbol m_MilitarySymbol;
13 
14  [Attribute(desc: "When enabled, the group will use the identity defined in 'Military Symbol' attribute and ignore automatic evaluation.")]
15  protected bool m_bForced;
16 
17  protected SCR_AIGroup m_Group;
18  protected int m_iNameID = -1;
20  protected ref ScriptInvokerBase<SCR_GroupIdentityComponent_OnChange> m_OnIdentityChange = new ScriptInvokerBase<SCR_GroupIdentityComponent_OnChange>();
21 
22  //------------------------------------------------------------------------------------------------
26  {
27  return m_MilitarySymbol;
28  }
29 
30  //------------------------------------------------------------------------------------------------
34  {
35  return m_sName;
36  }
37 
38  //------------------------------------------------------------------------------------------------
40  ScriptInvokerBase<SCR_GroupIdentityComponent_OnChange> GetOnIdentityChange()
41  {
42  return m_OnIdentityChange;
43  }
44 
45  //------------------------------------------------------------------------------------------------
48  {
49  //--- Server only
50  if (Replication.IsClient())
51  return;
52 
53  //--- Save the current symbol for later comparison
54  SCR_MilitarySymbol original = new SCR_MilitarySymbol();
55  original.CopyFrom(m_MilitarySymbol);
56 
57  //--- Update military symbol
59  SCR_MilitarySymbolRuleSet ruleSet = core.GetSymbolRuleSet();
60  ruleSet.UpdateSymbol(m_MilitarySymbol, m_Group);
61 
62  //--- Broadcast the symbol if it changed
63  if (!m_MilitarySymbol.IsEqual(original) || m_iNameID == -1)
64  {
65  //--- Get name based on the symbol
66  SCR_GroupNameConfig nameManager = core.GetNames();
67  int nameID = nameManager.GetGroupNameID(m_MilitarySymbol);
68 
69  //--- Apply changes
70  UpdateIdentityBroadcast(nameID, m_MilitarySymbol);
71  Rpc(UpdateIdentityBroadcast, nameID, m_MilitarySymbol);
72  }
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
77  protected void UpdateIdentityBroadcast(int nameID, SCR_MilitarySymbol symbol)
78  {
80  SCR_GroupNameConfig nameManager = core.GetNames();
81 
82  m_MilitarySymbol = symbol;
83  m_iNameID = nameID;
84  m_sName = nameManager.GetGroupName(m_iNameID);
85 
86  m_OnIdentityChange.Invoke(m_MilitarySymbol, m_sName);
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  protected void OnGroupInit(SCR_AIGroup aiGroup)
91  {
93  m_Group.GetOnAgentAdded().Insert(OnAgentAdded);
94  m_Group.GetOnAgentRemoved().Insert(OnAgentRemoved);
95  m_Group.GetOnAgentRemoved().Remove(OnAgentRemoved);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  protected void OnAgentAdded()
100  {
101  UpdateIdentity();
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  protected void OnAgentRemoved()
106  {
107  UpdateIdentity();
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  override bool RplSave(ScriptBitWriter writer)
112  {
113  m_MilitarySymbol.OnRplSave(writer);
114  writer.WriteInt(m_iNameID);
115 
116  return true;
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  //--- JIP on client
121  override bool RplLoad(ScriptBitReader reader)
122  {
123  m_MilitarySymbol.OnRplLoad(reader);
124  reader.ReadInt(m_iNameID);
125 
126  UpdateIdentityBroadcast(m_iNameID, m_MilitarySymbol);
127 
128  return true;
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  override void OnPostInit(IEntity owner)
133  {
134  if (SCR_Global.IsEditMode(owner))
135  return;
136 
137  m_Group = SCR_AIGroup.Cast(owner);
138  if (!m_Group)
139  {
140  Print("SCR_GroupIdentityComponent must be attached to SCR_AIGroup!", LogLevel.WARNING);
141  return;
142  }
143 
144  if (!m_bForced)
145  m_Group.GetOnInit().Insert(OnGroupInit);
146  //--- ToDo: When member gets in/out of vehicle
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  override void OnDelete(IEntity owner)
151  {
152  if (!m_bForced && m_Group)
153  {
154  m_Group.GetOnInit().Remove(OnGroupInit);
155  m_Group.GetOnAgentAdded().Remove(OnAgentAdded);
156  m_Group.GetOnAgentRemoved().Remove(OnAgentRemoved);
157  }
158  }
159 }
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_GroupIdentityComponent.c:111
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
GetMilitarySymbol
SCR_MilitarySymbol GetMilitarySymbol()
Definition: SCR_GroupIdentityComponent.c:25
OnAgentAdded
protected void OnAgentAdded()
Definition: SCR_GroupIdentityComponent.c:99
SCR_MilitarySymbol
Definition: SCR_MilitarySymbol.c:2
SCR_GroupIdentityCore
Definition: SCR_GroupIdentityCore.c:2
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
SCR_GroupNameConfig
Definition: SCR_GroupNameConfig.c:2
SCR_GroupIdentityComponentClass
Definition: SCR_GroupIdentityComponent.c:5
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_GroupIdentityComponent.c:150
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_MilitarySymbolRuleSet
Definition: SCR_MilitarySymbolRuleSet.c:2
GetOnIdentityChange
ScriptInvokerBase< SCR_GroupIdentityComponent_OnChange > GetOnIdentityChange()
Definition: SCR_GroupIdentityComponent.c:40
m_Group
protected SCR_AIGroup m_Group
Definition: SCR_GroupIdentityComponent.c:17
Attribute
SCR_GroupIdentityComponentClass ScriptComponentClass Attribute()] protected ref SCR_MilitarySymbol m_MilitarySymbol
Post-process effect of scripted camera.
OnAgentRemoved
protected void OnAgentRemoved()
Definition: SCR_GroupIdentityComponent.c:105
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_GroupIdentityComponent.c:132
GetGroupName
LocalizedString GetGroupName()
Definition: SCR_GroupIdentityComponent.c:33
m_OnIdentityChange
protected ref ScriptInvokerBase< SCR_GroupIdentityComponent_OnChange > m_OnIdentityChange
Definition: SCR_GroupIdentityComponent.c:20
SCR_Global
Definition: Functions.c:6
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_GroupIdentityComponent.c:121
SCR_AIGroup
Definition: SCR_AIGroup.c:68
m_iNameID
protected int m_iNameID
Definition: SCR_GroupIdentityComponent.c:18
SCR_GroupIdentityComponent_OnChange
func SCR_GroupIdentityComponent_OnChange
Definition: SCR_GroupIdentityComponent.c:2
m_bForced
protected bool m_bForced
Definition: SCR_GroupIdentityComponent.c:15
OnGroupInit
protected void OnGroupInit(SCR_AIGroup aiGroup)
Definition: SCR_GroupIdentityComponent.c:90
UpdateIdentityBroadcast
protected void UpdateIdentityBroadcast(int nameID, SCR_MilitarySymbol symbol)
Definition: SCR_GroupIdentityComponent.c:77
UpdateIdentity
void UpdateIdentity()
Update group identity based on its current state.
Definition: SCR_GroupIdentityComponent.c:47
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19
LocalizedString
Definition: LocalizedString.c:21
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180