Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ExtendedIdentityComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Misc", description: "")]
6{
7 [Attribute(desc: "The type of which Identities are obtained from. NEVER CHANGE ON RUN TIME!", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_EIdentityType))]
9
10 [Attribute(desc: "Holds all the set identity values of the entity")]
12
13 [Attribute(desc: "Leave empty to auto assign.")]
14 protected ref SCR_IdentityBio m_IdentityBio; //~ Bio data
15
16 [Attribute("18", "When randomizing character age. This is the min age the character can be. Age is randomized between min(included) and max(included)", params: "18 inf 1")]
17 protected int m_iMinRandomAge;
18
19 [Attribute("26", "When randomizing character age. This is the max age the character can be. Age is randomized between min(included) and max(included)", params: "18 inf 1")]
20 protected int m_iMaxRandomAge;
21
22 [Attribute("1", desc: "If true will randomize any identity varriables that are not yet filled in")]
24
25 //~ For replication optimalization these two indexes are combined into one int
26 protected int m_iBioGroupIndex = -1; //~ Bio's are divided in groups. Each group has a weight which dictates the rarity
27 protected int m_iBioIndex = -1; //~ Index of bio within the group
28
29 //~ Seed assigned in randomization. Same for client as it is for server
30 protected int m_RandomizeSeed = -1;
32
33 protected bool m_bDelayedInitCalled;
34
35 //======================================== SEEDED RANDOMIZATION ========================================\\
36 //------------------------------------------------------------------------------------------------
40 {
41 return m_RandomizeSeed;
42 }
43
44 //------------------------------------------------------------------------------------------------
48 {
50 if (!identityManager)
51 return;
52
53 //~ Randomize seed
54 int seed = Math.RandomInt(0, 0x7FFF);
55
56 #ifdef WORKBENCH
57 //~ Seed overwrite, Workbench only
58 if (identityManager.m_DebugRandomizeSeedOverwrite > -1)
59 seed = identityManager.m_DebugRandomizeSeedOverwrite;
60 #endif
61
62 //~ Create randomizer on server
64 m_Randomizer.SetSeed(seed);
65
66 //~ Assign a random bio using randomizer
68
69 //~ Only set seed as bio is al;ready set
71 //~ Broadcast seed and combined bio group index and bio index
73 }
74
75 //------------------------------------------------------------------------------------------------
76 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
77 protected void RandomizeIdentityBroadcast(int seed, int combinedBioIndex)
78 {
79 m_RandomizeSeed = seed;
80 RandomizeIdentity(combinedBioIndex);
81 }
82
83 //------------------------------------------------------------------------------------------------
84 //~ Randomizes the identity variables of entity
85 protected void RandomizeIdentity(int combinedBioIndex)
86 {
87 if (m_RandomizeSeed == -1)
88 {
89 Print("SCR_ExtendedIdentityComponent cannot randomize Identity as seed was not set!", LogLevel.DEBUG);
90 return;
91 }
92
94 {
95 Print("SCR_ExtendedIdentityComponent cannot randomize Identity as m_ExtendedIdentity is null!", LogLevel.DEBUG);
96 return;
97 }
98
99 //~ Create randomizer (Client only)
100 if (!m_Randomizer)
101 {
104
105 //~ Bio was assigned by server. In order to keep all other randomization the same it will execute the randomize twice to sync up with server
106 //~ The Randomize Bio will first randomize group using randomizer then randomize index on server. Hence it is called here twice
107 m_Randomizer.RandInt(0, 1);
108 m_Randomizer.RandInt(0, 1);
109 }
110
111 //~ Faction always first
112 if (m_ExtendedIdentity.GetFactionOfOriginKey().IsEmpty())
114
115 //~ Assign bio if none assigned. Always assign bio just after faction
116 if (!m_IdentityBio && combinedBioIndex >= 0)
117 AssignBio(combinedBioIndex);
118
119 if (m_ExtendedIdentity.GetAge() <= -1)
120 RandomizeAge();
121
122 if (m_ExtendedIdentity.GetMonthOfCreation() <= 0)
124
125 if (m_ExtendedIdentity.GetDayOfCreation() <= 0)
126 SetRandomDayOfCreation(m_ExtendedIdentity.GetMonthOfCreation());
127
128 //~ Any other logic that needs to be executed after all inherented version have executed their Identity logic
129 GetGame().GetCallqueue().CallLater(DelayedRandomizeIdentity);
130 }
131
132 //------------------------------------------------------------------------------------------------
133 //~ Called after all other identiy vars are randomzized
135 {
136 //~ For characters Place of origin is only randomized on server. So make sure it is called last
137 if (!m_ExtendedIdentity.GetPlaceOfOriginUIInfo())
139
140 //~ Delete randomizer next frame after all identities are randomized in class (As well as any inhereted classes)
142 }
143
144 //------------------------------------------------------------------------------------------------
145 protected void DeleteRandomizer()
146 {
147 if (m_Randomizer)
148 delete m_Randomizer;
149 }
150
151 //------------------------------------------------------------------------------------------------
159
160 //------------------------------------------------------------------------------------------------
165 {
166 if (!newExtendedIdentity || !m_ExtendedIdentity)
167 return;
168
169 //~ Faction first
170 if (newExtendedIdentity.GetFactionOfOriginIndex() > -1)
171 m_ExtendedIdentity.SetFactionOfOrigin(newExtendedIdentity.GetFactionOfOriginIndex());
172
173 if (newExtendedIdentity.GetAge() > -1)
174 m_ExtendedIdentity.SetAge(newExtendedIdentity.GetAge());
175
176 if (newExtendedIdentity.GetMonthOfCreation() > 0)
177 m_ExtendedIdentity.SetMonthOfCreation(newExtendedIdentity.GetMonthOfCreation());
178
179 if (newExtendedIdentity.GetDayOfCreation() > 0)
180 m_ExtendedIdentity.SetDayOfCreation(newExtendedIdentity.GetDayOfCreation());
181
182 if (newExtendedIdentity.GetPlaceOfOriginIndex() > -1)
183 m_ExtendedIdentity.SetPlaceOfOriginIndex(newExtendedIdentity.GetPlaceOfOriginIndex());
184
185 if (newExtendedIdentity.GetPlaceOfOriginUIInfo())
186 m_ExtendedIdentity.SetPlaceOfOrigin(newExtendedIdentity.GetPlaceOfOriginUIInfo(), true);
187 }
188
189 //======================================== FACTION OF ORIGIN ========================================\\
190 //------------------------------------------------------------------------------------------------
191 protected void InitFactionOfOrigin()
192 {
193 IEntity owner = GetOwner();
194 if (!owner)
195 return;
196
197 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(owner.FindComponent(FactionAffiliationComponent));
198 if (!factionAffiliation || (!factionAffiliation.GetAffiliatedFaction() && !factionAffiliation.GetDefaultAffiliatedFaction()))
199 return;
200
201 FactionManager factionManager = GetGame().GetFactionManager();
202 if (!factionManager)
203 return;
204
205 if (factionAffiliation.GetDefaultAffiliatedFaction())
206 m_ExtendedIdentity.SetFactionOfOrigin(factionManager.GetFactionIndex(factionAffiliation.GetDefaultAffiliatedFaction()));
207 else
208 m_ExtendedIdentity.SetFactionOfOrigin(factionManager.GetFactionIndex(factionAffiliation.GetAffiliatedFaction()));
209 }
210
211 //======================================== BIO ========================================\\
212 //------------------------------------------------------------------------------------------------
220
221 //------------------------------------------------------------------------------------------------
225 void GetBioIndexes(out int bioGroupIndex, out int bioIndex)
226 {
227 bioGroupIndex = m_iBioGroupIndex;
228 bioIndex = m_iBioIndex;
229 }
230
231 //------------------------------------------------------------------------------------------------
233 protected void AssignRandomBioServer()
234 {
235 if (!m_Randomizer)
236 return;
237
238 //~ Faction always first
239 if (m_ExtendedIdentity.GetFactionOfOriginKey().IsEmpty())
241
243 if (!identityManager)
244 return;
245
246 //~ Assigns the bio and removes it from the randomize pool
248
249 #ifdef WORKBENCH
250 //~ Bio overwrite, Workbench only
251 if (identityManager.m_DebugBioGroupIndexOverwrite > -1)
253
254 if (identityManager.m_DebugBioIndexOverwrite > -1)
255 m_iBioIndex = identityManager.m_DebugBioIndexOverwrite;
256
257 if (identityManager.m_DebugBioGroupIndexOverwrite > -1 || identityManager.m_DebugBioIndexOverwrite > -1)
258 identityBio = identityManager.GetBioFromIndexes(GetOwner(), m_eIdentityType, m_iBioGroupIndex, m_iBioIndex);
259 #endif
260
261 if (!identityBio)
262 {
263 Print(string.Format("'SCR_ExtendedIdentityComponent' given type (%1) and index bio group: %2 and bio index: %3 are invalid!", typename.EnumToString(SCR_EIdentityType, m_eIdentityType), m_iBioGroupIndex, m_iBioIndex),LogLevel.ERROR);
264 return;
265 }
266
267 AssignBio(identityBio);
268 }
269
270 //------------------------------------------------------------------------------------------------
274 void AssignBio(int combinedBioIndex)
275 {
277 if (!identityManager)
278 return;
279
280 identityManager.GetBioIndexesFromCombined(combinedBioIndex, m_iBioGroupIndex, m_iBioIndex);
282 }
283
284 //------------------------------------------------------------------------------------------------
288 void AssignBio(SCR_IdentityBio identityBio)
289 {
290 m_IdentityBio = identityBio;
291
293 if (!advanceOverwrite)
294 return;
295
297 }
298
299 //======================================== AGE ========================================\\
300 //------------------------------------------------------------------------------------------------
302 protected void RandomizeAge()
303 {
304 if (!m_Randomizer)
305 return;
306
308 }
309
310 //======================================== BIRTH/CREATION DATE ========================================\\
311 //---------------------------------------- Month of Birth/Creation ----------------------------------------\\
312 //! Set random month of birth of character
314 {
315 if (!m_Randomizer)
316 return;
317
318 m_ExtendedIdentity.SetMonthOfCreation(m_Randomizer.RandIntInclusive(1, 12));
319 }
320
321 //---------------------------------------- Day of Birth/Creation ----------------------------------------\\
322 //! Set random day of birth of character
323 void SetRandomDayOfCreation(int month = -1)
324 {
325 if (!m_Randomizer)
326 return;
327
328 int maxDay = 28;
329
330 //~ No month given so never set day of birth later then 28
331 if (month <= 0)
332 {
333 m_ExtendedIdentity.SetDayOfCreation(m_Randomizer.RandIntInclusive(1, maxDay));
334 return;
335 }
336
337 BaseGameMode gameMode = GetGame().GetGameMode();
338 if (!gameMode)
339 return;
340
341 ChimeraWorld world = ChimeraWorld.CastFrom(gameMode.GetWorld());
342 if (!world)
343 return;
344
345 //~ No time and weather manager so can never check if date is valid. Never set day of birth later then 28
346 TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
347 if (!timeManager)
348 {
349 m_ExtendedIdentity.SetDayOfCreation(m_Randomizer.RandIntInclusive(1, maxDay));
350 return;
351 }
352
353 //~ Get last day of the month (Can never have day of birth on a leap day as 1990 is not a leap day and year is seperate from age)
354 while (timeManager.CheckValidDate(1990, month, maxDay +1))
355 {
356 maxDay++;
357 }
358
359 m_ExtendedIdentity.SetDayOfCreation(m_Randomizer.RandIntInclusive(1, maxDay));
360 }
361
362 //======================================== PLACE OF CREATION ========================================\\
363 //------------------------------------------------------------------------------------------------
364 protected void RandomizePlaceOfOrigin()
365 {
367 return;
368
369 int factionOfOrigin = m_ExtendedIdentity.GetFactionOfOriginIndex();
370 if (factionOfOrigin <= -1)
371 return;
372
373 FactionManager factionManager = GetGame().GetFactionManager();
374 if (!factionManager)
375 return;
376
377 SCR_Faction scrFaction = SCR_Faction.Cast(factionManager.GetFactionByIndex(factionOfOrigin));
378 if (!scrFaction)
379 return;
380
382 if (!territory)
383 return;
384
385 m_ExtendedIdentity.SetPlaceOfOriginIndex(territory.GetRandomHomeTerritoryIndex(m_Randomizer));
386 }
387
388 //======================================== OTHERS ========================================\\
389 //------------------------------------------------------------------------------------------------
394
395 //======================================== RPL ========================================\\
396 //------------------------------------------------------------------------------------------------
397 override bool RplSave(ScriptBitWriter writer)
398 {
400 if (!identityManager)
401 return false;
402
403 writer.WriteInt(m_RandomizeSeed);
404 writer.WriteInt(identityManager.CombineBioIndexes(m_iBioGroupIndex, m_iBioIndex));
405
406 return true;
407 }
408
409 //------------------------------------------------------------------------------------------------
410 override bool RplLoad(ScriptBitReader reader)
411 {
412 int seed, combinedBioIndex;
413 reader.ReadInt(seed);
414 reader.ReadInt(combinedBioIndex);
415
416 RandomizeIdentityBroadcast(seed, combinedBioIndex);
417 return true;
418 }
419
420 //======================================== INIT/DESTROY ========================================\\
421 //------------------------------------------------------------------------------------------------
422 override void OnPostInit(IEntity owner)
423 {
425 {
426 Print("'SCR_ExtendedIdentityComponent' Identity is null", LogLevel.ERROR);
427 return;
428 }
429
431 if (!gameMode || !gameMode.IsMaster())
432 return;
433
434 //~ If entity is not in the same world as the Game mode it is a preview so do not generate the identity
435 if (owner.GetWorld() != gameMode.GetWorld())
436 return;
437
438 SetEventMask(owner, EntityEvent.INIT);
439 }
440
441 //------------------------------------------------------------------------------------------------
442 override void EOnInit(IEntity owner)
443 {
444 //~ Add delay so system knows properly that the character is a player or not and all componenst are initialized
445 GetGame().GetCallqueue().CallLater(DelayedInit, param1: owner);
446 }
447
448 //------------------------------------------------------------------------------------------------
450 {
451 //corner case where DelayedInit gets queued and entity is already deleted.
452 if(!owner)
453 return;
454
456
459 }
460};
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_BaseGameMode GetGameMode()
SCR_EIdentityType
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external int SetEventMask(notnull IEntity owner, int mask)
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)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Definition Math.c:13
sealed bool IsMaster()
void AssignRandomBioServer()
Assign random bio (Server Only).
void RandomizeAge()
Set controlled random age of entity in years.
void OverwriteExtendedIdentity(SCR_ExtendedIdentity newExtendedIdentity)
void AssignBio(SCR_IdentityBio identityBio)
override bool RplLoad(ScriptBitReader reader)
void GetBioIndexes(out int bioGroupIndex, out int bioIndex)
void RandomizeIdentityBroadcast(int seed, int combinedBioIndex)
override bool RplSave(ScriptBitWriter writer)
void RandomizeIdentity(int combinedBioIndex)
int GetRandomHomeTerritoryIndex(RandomGenerator randomizer=null, bool useWeightedRandom=true)
SCR_FactionHomeTerritoryConfig GetFactionHomeTerritoryConfig()
static SCR_IdentityManagerComponent GetInstance()
SCR_IdentityBio GetBioFromIndexes(IEntity entity, SCR_EIdentityType identityType, int bioGroupIndex, int bioIndex)
SCR_IdentityBio AssignRandomAvailableBio(RandomGenerator randomizer, IEntity entity, SCR_EIdentityType identityType, int factionIndex, out int bioGroupIndex, out int bioIndex, bool useRandomWeighted=true)
int CombineBioIndexes(int bioGroupIndex, int bioIndex)
void GetBioIndexesFromCombined(int combinedIndexes, out int bioGroupIndex, out int bioIndex)
proto external GenericEntity GetOwner()
Get owner entity.
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
EntityEvent
Various entity events.
Definition EntityEvent.c:14
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
Tuple param1