Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GroupIdentityComponent.c
Go to the documentation of this file.
3
4[ComponentEditorProps(category: "GameScripted/Misc", description: "")]
8
9class 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
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
55 original.CopyFrom(m_MilitarySymbol);
56
57 //--- Update military symbol
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 {
102 }
103
104 //------------------------------------------------------------------------------------------------
105 protected void OnAgentRemoved()
106 {
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}
SCR_AIGroupSettingsComponentClass m_Group
void OnAgentRemoved(AIGroup group, AIAgent agent)
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
func SCR_GroupIdentityComponent_OnChange
ScriptInvokerBase< SCR_GroupIdentityComponent_OnChange > GetOnIdentityChange()
SCR_MilitarySymbol GetMilitarySymbol()
void OnGroupInit(SCR_AIGroup aiGroup)
void UpdateIdentityBroadcast(int nameID, SCR_MilitarySymbol symbol)
LocalizedString m_sName
ref ScriptInvokerBase< SCR_GroupIdentityComponent_OnChange > m_OnIdentityChange
LocalizedString GetGroupName()
void UpdateIdentity()
Update group identity based on its current state.
void OnAgentAdded()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
Main replication API.
Definition Replication.c:14
static bool IsEditMode()
Definition Functions.c:1566
SCR_MilitarySymbolRuleSet GetSymbolRuleSet()
SCR_GroupNameConfig GetNames()
LocalizedString GetGroupName(SCR_MilitarySymbol symbol)
int GetGroupNameID(SCR_MilitarySymbol symbol)
void CopyFrom(SCR_MilitarySymbol from)
void UpdateSymbol(out notnull SCR_MilitarySymbol outSymbol, SCR_Faction faction)
bool RplLoad(ScriptBitReader reader)
bool RplSave(ScriptBitWriter writer)
void OnAgentAdded(AIAgent agent)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14