Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CharacterRankComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted", description: "Handles the character's rank.", color: "0 0 255 255")]
2 class SCR_CharacterRankComponentClass: ScriptComponentClass
3 {
4 }
5 
7 {
8  [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "Rank", enums: ParamEnumArray.FromEnum(SCR_ECharacterRank))]
9  protected SCR_ECharacterRank m_iRank;
10 
11  protected IEntity m_Owner;
12  static ref ScriptInvoker s_OnRankChanged = new ScriptInvoker();
13 
14  //------------------------------------------------------------------------------------------------
19  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
20  void RpcDoSetCharacterRank(SCR_ECharacterRank newRank, SCR_ECharacterRank prevRank, bool silent)
21  {
22  SCR_ECharacterRank oldRank = m_iRank;
23  m_iRank = newRank;
24  OnRankChanged(oldRank, newRank, silent);
25  }
26 
27  //------------------------------------------------------------------------------------------------
30  static SCR_CharacterRankComponent GetCharacterRankComponent(IEntity unit)
31  {
32  return SCR_CharacterRankComponent.Cast(unit.FindComponent(SCR_CharacterRankComponent));
33  }
34 
35  //------------------------------------------------------------------------------------------------
38  void SetCharacterRank(SCR_ECharacterRank rank, bool silent = false)
39  {
40  if (rank != m_iRank)
41  {
42  Rpc(RpcDoSetCharacterRank, rank, m_iRank, silent);
43  RpcDoSetCharacterRank(rank, m_iRank, silent);
44  }
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  protected void OnRankChanged(SCR_ECharacterRank prevRank, SCR_ECharacterRank newRank, bool silent)
49  {
50  s_OnRankChanged.Invoke(prevRank, newRank, m_Owner, silent);
51  }
52 
53  //------------------------------------------------------------------------------------------------
57  static SCR_ECharacterRank GetCharacterRank(IEntity unit)
58  {
59  if (!unit)
60  return SCR_ECharacterRank.INVALID;
61 
62  SCR_CharacterRankComponent comp = GetCharacterRankComponent(unit);
63 
64  if (!comp)
65  return SCR_ECharacterRank.INVALID;
66 
67  return comp.GetCharacterRank();
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected SCR_Faction GetCharacterFaction(IEntity unit)
72  {
73  if (!unit)
74  return null;
75 
76  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(unit);
77  if (!character)
78  return null;
79 
80  Faction faction = character.GetFaction();
81  if (!faction)
82  return null;
83 
84  return SCR_Faction.Cast(faction);
85  }
86 
87  //------------------------------------------------------------------------------------------------
90  static string GetCharacterRankName(IEntity unit)
91  {
92  if (!unit)
93  return "";
94 
95  SCR_CharacterRankComponent comp = GetCharacterRankComponent(unit);
96 
97  if (!comp)
98  return "";
99 
100  SCR_ECharacterRank rank = comp.GetCharacterRank();
101  SCR_Faction faction = comp.GetCharacterFaction(unit);
102 
103  if (!faction)
104  return "";
105 
106  return faction.GetRankName(rank);
107  }
108 
109  //------------------------------------------------------------------------------------------------
112  static string GetCharacterRankNameUpperCase(IEntity unit)
113  {
114  if (!unit)
115  return "";
116 
117  SCR_CharacterRankComponent comp = GetCharacterRankComponent(unit);
118 
119  if (!comp)
120  return "";
121 
122  SCR_ECharacterRank rank = comp.GetCharacterRank();
123  SCR_Faction faction = comp.GetCharacterFaction(unit);
124 
125  if (!faction)
126  return "";
127 
128  return faction.GetRankNameUpperCase(rank);
129  }
130 
131  //------------------------------------------------------------------------------------------------
134  static string GetCharacterRankNameShort(IEntity unit)
135  {
136  if (!unit)
137  return "";
138 
139  SCR_CharacterRankComponent comp = GetCharacterRankComponent(unit);
140 
141  if (!comp)
142  return "";
143 
144  SCR_ECharacterRank rank = comp.GetCharacterRank();
145  SCR_Faction faction = comp.GetCharacterFaction(unit);
146 
147  if (!faction)
148  return "";
149 
150  return faction.GetRankNameShort(rank);
151  }
152 
153  //------------------------------------------------------------------------------------------------
156  static ResourceName GetCharacterRankInsignia(IEntity unit)
157  {
158  if (!unit)
159  return "";
160 
161  SCR_CharacterRankComponent comp = GetCharacterRankComponent(unit);
162 
163  if (!comp)
164  return "";
165 
166  SCR_ECharacterRank rank = comp.GetCharacterRank();
167  SCR_Faction faction = comp.GetCharacterFaction(unit);
168 
169  if (!faction)
170  return "";
171 
172  return faction.GetRankInsignia(rank);
173  }
174 
175  //------------------------------------------------------------------------------------------------
177  {
178  return m_iRank;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  override bool RplSave(ScriptBitWriter writer)
183  {
184  writer.WriteIntRange(m_iRank, 0, SCR_ECharacterRank.INVALID-1);
185 
186  return true;
187  }
188 
189  //-----------------------------------------------------------------------------------------------------------------------
190  override bool RplLoad(ScriptBitReader reader)
191  {
192  reader.ReadIntRange(m_iRank, 0, SCR_ECharacterRank.INVALID-1);
193 
194  return true;
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  override void OnPostInit(IEntity owner)
199  {
200  if (!ChimeraCharacter.Cast(owner))
201  Print("SCR_CharacterRankComponent must be attached to ChimeraCharacter!", LogLevel.ERROR);
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  // constructor
209  void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
210  {
211  m_Owner = ent;
212  }
213 }
214 
217 {
218  [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "Rank ID set in FactionManager", enums: ParamEnumArray.FromEnum(SCR_ECharacterRank))]
219  protected SCR_ECharacterRank m_iRank;
220 
221  [Attribute(defvalue: "", uiwidget: UIWidgets.EditBox, desc: "Rank name")]
222  protected string m_sRankName;
223 
224  [Attribute(defvalue: "", uiwidget: UIWidgets.EditBox, desc: "Rank name (upper case)")]
225  protected string m_sRankNameUpper;
226 
227  [Attribute(defvalue: "", uiwidget: UIWidgets.EditBox, desc: "Rank name (short)")]
228  protected string m_sRankNameShort;
229 
230  [Attribute("", "Rank insignia quad name in MilitaryIcons.imageset")]
231  protected string m_sInsignia;
232 
233  //------------------------------------------------------------------------------------------------
235  SCR_ECharacterRank GetRankID()
236  {
237  return m_iRank;
238  }
239 
240  //------------------------------------------------------------------------------------------------
242  string GetRankName()
243  {
244  return m_sRankName;
245  }
246 
247  //------------------------------------------------------------------------------------------------
249  string GetRankNameUpperCase()
250  {
251  return m_sRankNameUpper;
252  }
253 
254  //------------------------------------------------------------------------------------------------
256  string GetRankNameShort()
257  {
258  return m_sRankNameShort;
259  }
260 
261  //------------------------------------------------------------------------------------------------
263  string GetRankInsignia()
264  {
265  return m_sInsignia;
266  }
267 }
268 
270 class SCR_RankID
271 {
272  [Attribute(defvalue: "1", uiwidget: UIWidgets.ComboBox, desc: "Rank ID", enums: ParamEnumArray.FromEnum(SCR_ECharacterRank))]
273  protected SCR_ECharacterRank m_iRank;
274 
275  [Attribute("0", UIWidgets.CheckBox, "Renegade", "Is this rank considered hostile by friendlies?")]
276  protected bool m_bIsRenegade;
277 
278  [Attribute("100", UIWidgets.EditBox, "XP required to get promoted to this rank.")]
279  protected int m_iRequiredXP;
280 
281  //------------------------------------------------------------------------------------------------
284  {
285  return m_iRank;
286  }
287 
288  //------------------------------------------------------------------------------------------------
291  bool IsRankRenegade()
292  {
293  return m_bIsRenegade;
294  }
295 
296  //------------------------------------------------------------------------------------------------
298  int GetRequiredRankXP()
299  {
300  return m_iRequiredXP;
301  }
302 }
303 
304 //~ Character ranks. Take note to update any changes in SCR_EntityCatalogSpawnerData and EEditableEntityBudget
306 {
327 }
GetCharacterFaction
protected SCR_Faction GetCharacterFaction(IEntity unit)
Definition: SCR_CharacterRankComponent.c:71
CUSTOM1
@ CUSTOM1
Definition: SCR_CharacterRankComponent.c:316
CUSTOM3
@ CUSTOM3
Definition: SCR_CharacterRankComponent.c:318
RpcDoSetCharacterRank
void RpcDoSetCharacterRank(SCR_ECharacterRank newRank, SCR_ECharacterRank prevRank, bool silent)
Definition: SCR_CharacterRankComponent.c:20
SERGEANT
@ SERGEANT
Definition: SCR_CharacterRankComponent.c:310
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_Owner
protected IEntity m_Owner
Definition: SCR_CharacterRankComponent.c:11
m_sInsignia
protected string m_sInsignia
Definition: SCR_CharacterRankComponent.c:223
CUSTOM4
@ CUSTOM4
Definition: SCR_CharacterRankComponent.c:319
MAJOR
@ MAJOR
Definition: SCR_CharacterRankComponent.c:313
LIEUTENANT
@ LIEUTENANT
Definition: SCR_CharacterRankComponent.c:311
m_iRank
protected SCR_ECharacterRank m_iRank
Definition: SCR_CharacterRankComponent.c:211
CUSTOM7
@ CUSTOM7
Definition: SCR_CharacterRankComponent.c:322
SCR_ECharacterRank
SCR_ECharacterRank
Definition: SCR_CharacterRankComponent.c:305
m_iRank
protected SCR_ECharacterRank m_iRank
Definition: SCR_CampaignBuildingProviderComponent.c:33
GetCharacterRank
protected SCR_ECharacterRank GetCharacterRank()
Definition: SCR_CharacterRankComponent.c:176
CUSTOM10
@ CUSTOM10
Definition: SCR_CharacterRankComponent.c:325
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
m_sRankNameShort
protected string m_sRankNameShort
Definition: SCR_CharacterRankComponent.c:220
CUSTOM8
@ CUSTOM8
Definition: SCR_CharacterRankComponent.c:323
CUSTOM2
@ CUSTOM2
Definition: SCR_CharacterRankComponent.c:317
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_CharacterRankComponent.c:190
IsRankRenegade
bool IsRankRenegade(SCR_ECharacterRank rankID)
Definition: SCR_FactionManager.c:280
SCR_CharacterRankComponent
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CharacterRankComponent.c:209
RENEGADE
@ RENEGADE
Definition: SCR_CharacterRankComponent.c:307
SCR_CharacterRankComponentClass
Definition: SCR_CharacterRankComponent.c:2
GENERAL
@ GENERAL
Definition: SCR_CharacterRankComponent.c:315
COLONEL
@ COLONEL
Definition: SCR_CharacterRankComponent.c:314
Attribute
SCR_CharacterRankComponentClass ScriptComponentClass Attribute(defvalue:"1", uiwidget:UIWidgets.ComboBox, desc:"Rank", enums:ParamEnumArray.FromEnum(SCR_ECharacterRank))] protected SCR_ECharacterRank m_iRank
OnRankChanged
protected void OnRankChanged(SCR_ECharacterRank prevRank, SCR_ECharacterRank newRank, bool silent)
Definition: SCR_CharacterRankComponent.c:48
INVALID
@ INVALID
Missing components, or obstruction test was not possible.
Definition: SCR_CharacterRankComponent.c:326
GetRequiredRankXP
int GetRequiredRankXP(SCR_ECharacterRank rankID)
Definition: SCR_FactionManager.c:293
m_sRankName
protected string m_sRankName
Definition: SCR_CharacterRankComponent.c:214
CUSTOM6
@ CUSTOM6
Definition: SCR_CharacterRankComponent.c:321
PRIVATE
@ PRIVATE
Definition: SCR_CharacterRankComponent.c:308
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CharacterRankComponent.c:198
SCR_CharacterRank
Definition: SCR_CharacterRankComponent.c:216
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_CharacterRankComponent.c:182
Faction
Definition: Faction.c:12
m_sRankNameUpper
protected string m_sRankNameUpper
Definition: SCR_CharacterRankComponent.c:217
CAPTAIN
@ CAPTAIN
Definition: SCR_CharacterRankComponent.c:312
GetRankID
SCR_ECharacterRank GetRankID()
Definition: SCR_CharacterRankComponent.c:227
CORPORAL
@ CORPORAL
Definition: SCR_CharacterRankComponent.c:309
BaseContainerProps
class SCR_CharacterRank BaseContainerProps()] class SCR_RankID
Definition: SCR_CharacterRankComponent.c:269
SetCharacterRank
void SetCharacterRank(SCR_ECharacterRank rank, bool silent=false)
Definition: SCR_CharacterRankComponent.c:38
CUSTOM5
@ CUSTOM5
Definition: SCR_CharacterRankComponent.c:320
SCR_Faction
Definition: SCR_Faction.c:6
CUSTOM9
@ CUSTOM9
Definition: SCR_CharacterRankComponent.c:324
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180