Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterIdentityBioGroupConfig.c
Go to the documentation of this file.
1[BaseContainerProps(configRoot: true), BaseContainerCustomDoubleTitleField("m_sBioGroupID", "m_iWeight")]
3{
4 [Attribute(desc: "A list of Bio Lists that are specific for a gender (other then NEUTRAL). Each list needs a specific gender, never have two list holders with the same gender!", category: "Identities")]
5 protected ref array<ref SCR_GenderSpecificIdentityBios> m_aGenderSpecificIdentityLists;
6
7 [Attribute(SCR_ECharacterIdentityBioGroupType.MILITARY_AND_CIVILIAN.ToString(), desc: "If the identity is valid for Military and/or Civilian factions. Note that giving a Civilian only idientity to a military faction (added in the Needs Faction list) will cause the bio's to never be randomized", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_ECharacterIdentityBioGroupType), category: "Requirements")]
10 [Attribute(SCR_EIdentityCharacterControlType.PLAYER_AND_AI.ToString(), desc: "Who can have the identities? Players and AI or just Players/AI only", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(SCR_EIdentityCharacterControlType), category: "Requirements")]
12
15
16 //------------------------------------------------------------------------------------------------
17 override bool IsValidFaction(string factionKey)
18 {
19 if (!super.IsValidFaction(factionKey))
20 return false;
21
22 //~ Doesn't matter if it is military or civilian
24 return true;
25
26 SCR_Faction faction = SCR_Faction.Cast(GetGame().GetFactionManager().GetFactionByKey(factionKey));
27 if (!faction)
29
30 //~ No faction found for some reason so default to if military
31 if (faction.IsMilitary())
33 else
35 }
36
37 //------------------------------------------------------------------------------------------------
38 override bool IsValidFaction(int factionIndex)
39 {
40 if (!super.IsValidFaction(factionIndex))
41 return false;
42
43 //~ Doesn't matter if it is military or civilian
45 return true;
46
47 //~ No faction found for some reason so default to if military
48 SCR_Faction faction = SCR_Faction.Cast(GetGame().GetFactionManager().GetFactionByIndex(factionIndex));
49
50 if (!faction || faction.IsMilitary())
52 else
54 }
55
56 //------------------------------------------------------------------------------------------------
57 override bool IsValidForRandomization(IEntity entity, SCR_ExtendedIdentityComponent extendedIdentity)
58 {
59 //~ List is already valid so no need to check genders
60 if (super.IsValidForRandomization(entity, extendedIdentity))
61 return true;
62
63 //~ Check if Weight is 0 or less else check if there are availible character identities
64 if (m_iWeight <= 0)
65 return false;
66
67 //~ Check the control type (Player/AI)
69 {
70 SCR_ExtendedCharacterIdentityComponent extendedCharacterIdentity = SCR_ExtendedCharacterIdentityComponent.Cast(extendedIdentity);
71 if (extendedCharacterIdentity)
72 {
73 if (extendedCharacterIdentity.GetPlayerID() > 0)
74 {
76 return false;
77 }
78 else
79 {
81 return false;
82 }
83 }
84 }
85
86 SCR_EIdentityGender entityGender = GetEntityGender(entity);
87 //~ Gender neutral list where already checked thus there are no identities left for this character
88 if (entityGender == SCR_EIdentityGender.NEUTRAL)
89 return false;
90
91 array<int> foundIndexes;
92 if (m_mAvailableGenderSpecificBioIndexLists.Find(entityGender, foundIndexes))
93 return !foundIndexes.IsEmpty();
94
95 //~ No valid list for given gender
96 return false;
97 }
98
99 //------------------------------------------------------------------------------------------------
101 {
102 SCR_IdentityBio bio = super.GetIdentityBio(entity, index);
103 if (bio)
104 return bio;
105
106 index -= m_aIdentityList.Count();
107
108 if (index < 0)
109 return null;
110
111 SCR_EIdentityGender gender = GetEntityGender(entity);
112 if (gender == SCR_EIdentityGender.NEUTRAL || !m_mAvailableGenderSpecificBioIndexLists.Contains(gender))
113 return null;
114
115 foreach(SCR_GenderSpecificIdentityBios genderSpecificList: m_aGenderSpecificIdentityLists)
116 {
117 if (genderSpecificList.GetGender() == gender)
118 {
119 array<ref SCR_IdentityBio> identityBioList = {};
120 if (index >= genderSpecificList.GetIdentityBioList(identityBioList))
121 return null;
122
123 return identityBioList[index];
124 }
125 }
126
127 //~ Index invalid
128 return null;
129 }
130
131 //------------------------------------------------------------------------------------------------
132 override void AssignRandomAvailableBio(RandomGenerator randomizer, IEntity entity, out int index, out SCR_IdentityBio bio)
133 {
134 //~ Gender is neutral or no list for specific gender so grab from default list only
135 SCR_EIdentityGender gender = GetEntityGender(entity);
136 if (gender == SCR_EIdentityGender.NEUTRAL || !m_mAvailableGenderSpecificBioIndexLists.Contains(gender))
137 {
138 super.AssignRandomAvailableBio(randomizer, entity, index, bio);
139 return;
140 }
141
142 int count = m_aAvailableIdentityBioIndexList.Count();
143 int genderSpecificCount = m_mAvailableGenderSpecificBioIndexLists[gender].Count();
144
145 int random = randomizer.RandInt(0, count + genderSpecificCount);
146
147 //~ Neutral gender bio
148 if (random < count)
149 {
151 bio = OnCharacterBioAssigned(entity, index);
152 return;
153 }
154 //~ Gender Specific bio
155 else
156 {
157 index = m_mAvailableGenderSpecificBioIndexLists[gender][random - count] + m_aIdentityList.Count();
158 bio = OnCharacterBioAssigned(entity, index);
159 return;
161 }
162
163 //------------------------------------------------------------------------------------------------
165 {
166 //~ Check if gender neutral bio was assigned
167 SCR_IdentityBio bio = super.OnCharacterBioAssigned(entity, index);
168 if (bio != null)
169 return bio;
170
171 //~ Gender Specific Bio was assigned
172 index -= m_aIdentityList.Count();
173
174 if (index < 0)
175 return null;
176
177 //~ Gender is NEUTRAL so index is invalid
178 SCR_EIdentityGender gender = GetEntityGender(entity);
179 if (gender == SCR_EIdentityGender.NEUTRAL || !m_mAvailableGenderSpecificBioIndexLists.Contains(gender))
180 return null;
181
182 array<ref SCR_IdentityBio> identityBioList = {};
183
184 foreach(SCR_GenderSpecificIdentityBios specificBioList: m_aGenderSpecificIdentityLists)
185 {
186 if (specificBioList.GetGender() == gender)
187 {
188 specificBioList.GetIdentityBioList(identityBioList);
189 break;
190 }
191 }
192
193 //~ Invalid index
194 if (!identityBioList.IsIndexValid(index))
195 return null;
196
197 bio = identityBioList[index];
198 if (!bio)
199 return null;
200
201 //~ Weight zero will never remove from available
202 if (m_iWeight <= 0)
203 return bio;
204
205 //~ Remove from available bios
207
208 //~ Add to unavailible bios (If not unique as unique bio's can only be assigned once per game)
209 if (!bio.IsUnique() && !m_mUnavailableGenderSpecificBioIndexLists[gender].Contains(index))
210 {
212 }
213
214 //~ Refill available list if empty
216 {
217 foreach (int unavailableIndex : m_mUnavailableGenderSpecificBioIndexLists[gender])
218 {
219 m_mAvailableGenderSpecificBioIndexLists[gender].Insert(unavailableIndex);
220 }
221
223 }
224
225 return bio;
226 }
227
228 //------------------------------------------------------------------------------------------------
229 override void ResetAvailable()
230 {
231 super.ResetAvailable();
232
235 else
237
240 else
242
243 int count;
244 SCR_EIdentityGender gender;
245
246 foreach(SCR_GenderSpecificIdentityBios genderSpecificList: m_aGenderSpecificIdentityLists)
247 {
248 gender = genderSpecificList.GetGender();
249
250 m_mAvailableGenderSpecificBioIndexLists.Insert(gender, new array<int>);
251 m_mUnavailableGenderSpecificBioIndexLists.Insert(gender, new array<int>);
252
253 count = genderSpecificList.GetIdentityBioListCount();
254
255 for(int i = 0; i < count; i++)
256 {
258 }
259 }
261
262 //------------------------------------------------------------------------------------------------
263 //~ Returns NEUTRAL if no gender found
265 {
267 if (!characterExtendedIdentityComponent)
268 return SCR_EIdentityGender.NEUTRAL;
269
270 return characterExtendedIdentityComponent.GetGender();
271 }
272
273 //------------------------------------------------------------------------------------------------
274 protected override void DelayedInit()
275 {
276 super.DelayedInit();
277
278 int genderSpecificEntryCount = 0;
279
280 foreach (SCR_GenderSpecificIdentityBios genderSpecific : m_aGenderSpecificIdentityLists)
281 {
282 if (!genderSpecific)
283 continue;
284
285 genderSpecificEntryCount += genderSpecific.GetIdentityBioListCount();
286 }
287
288 //~ Highly unlikely that this happens but will send an error if it happens
289 if (m_aIdentityList.Count() + genderSpecificEntryCount > SCR_IdentityManagerComponent.MAX_IDENTITY_ENTRIES)
290 {
291 PrintFormat("'SCR_CharacterIdentityBioGroupConfig' - %1: Identity entries count is greater than %2 which will break replication", m_sBioGroupID, SCR_IdentityManagerComponent.MAX_IDENTITY_ENTRIES, level: LogLevel.ERROR);
293 }
294
295 //------------------------------------------------------------------------------------------------
296 protected override void SetAdditionalWeight()
297 {
298 if (m_iWeight <= 0 || m_fEntryAmountWeightMulti <= 0)
299 return;
300
301 int genderSpecificEntryCount = 0;
302
303 foreach (SCR_GenderSpecificIdentityBios genderSpecific : m_aGenderSpecificIdentityLists)
304 {
305 if (!genderSpecific)
306 continue;
307
308 genderSpecificEntryCount += genderSpecific.GetIdentityBioListCount();
309 }
310
311 //~ Set Additional Weight for each entry
313 m_iWeight = m_iWeight + ((m_aIdentityList.Count() + genderSpecificEntryCount) * m_fEntryAmountWeightMulti);
314 }
315
316 //------------------------------------------------------------------------------------------------
318 {
320 return;
321
322 //~ Safty check
323 foreach(SCR_GenderSpecificIdentityBios genderSpecificList: m_aGenderSpecificIdentityLists)
324 {
325 if (genderSpecificList.GetGender() == SCR_EIdentityGender.NEUTRAL)
326 {
327 Print(string.Format("'SCR_CharacterIdentityBioGroupConfig', CharacterIdentityBioGroup '%1' has a specific gender list for gender NEUTRAL! use the default list for gender neutral Bios!", m_sBioGroupID), LogLevel.ERROR);
328 continue;
329 }
330
331 foreach(SCR_GenderSpecificIdentityBios genderCheck: m_aGenderSpecificIdentityLists)
332 {
333 if (genderSpecificList != genderCheck && genderSpecificList.GetGender() == genderCheck.GetGender())
334 {
335 Print(string.Format("'SCR_CharacterIdentityBioGroupConfig', CharacterIdentityBioGroup '%1' has two (or more) gender specific lists for the same gender! This should never happen!", m_sBioGroupID), LogLevel.ERROR);
336 return;
337 }
338 }
339 }
340 }
341}
342
344class SCR_GenderSpecificIdentityBios
345{
346 [Attribute("1", desc: "Genders required for the bio's to be valid. For gender neutral use the default entity list (m_aIdentityList)", uiwidget: UIWidgets.SearchComboBox, enumType: SCR_EIdentityGender)]
347 protected SCR_EIdentityGender m_eSpecificGender;
348
349 [Attribute(desc: "List of character bio's in group for a specific gender. If the bio group is chosen in the randomizer and the entity is the correct gender then these are added to the randomizer.")]
350 protected ref array<ref SCR_IdentityBio> m_aIdentityList;
351
352 //------------------------------------------------------------------------------------------------
353 SCR_EIdentityGender GetGender()
354 {
355 return m_eSpecificGender;
356 }
357
358 //------------------------------------------------------------------------------------------------
359 int GetIdentityBioList(notnull array<ref SCR_IdentityBio> identityBioList)
360 {
361 identityBioList.Clear();
362
363 foreach(SCR_IdentityBio bio: m_aIdentityList)
364 {
365 identityBioList.Insert(bio);
366 }
367
368 return identityBioList.Count();
369 }
370
371 //------------------------------------------------------------------------------------------------
372 int GetIdentityBioListCount()
373 {
374 return m_aIdentityList.Count();
375 }
376}
377
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_CharacterIdentityBioGroupConfig SCR_IdentityBioGroupConfig SCR_BaseContainerCustomTitleEnum(SCR_EIdentityGender, "m_eSpecificGender")
SCR_ECharacterIdentityBioGroupType m_eIdentityGroupType
SCR_CharacterIdentityBioGroupConfig SCR_IdentityBioGroupConfig BaseContainerProps()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EIdentityGender
class SCR_FactionHomeTerritoryConfig BaseContainerCustomDoubleTitleField("m_sID", "m_iWeight")
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
override bool IsValidForRandomization(IEntity entity, SCR_ExtendedIdentityComponent extendedIdentity)
ref map< SCR_EIdentityGender, ref array< int > > m_mAvailableGenderSpecificBioIndexLists
override SCR_IdentityBio GetIdentityBio(IEntity entity, int index)
ref array< ref SCR_GenderSpecificIdentityBios > m_aGenderSpecificIdentityLists
override void AssignRandomAvailableBio(RandomGenerator randomizer, IEntity entity, out int index, out SCR_IdentityBio bio)
SCR_EIdentityGender GetEntityGender(IEntity entity)
SCR_ECharacterIdentityBioGroupType m_eIdentityGroupType
ref map< SCR_EIdentityGender, ref array< int > > m_mUnavailableGenderSpecificBioIndexLists
override SCR_IdentityBio OnCharacterBioAssigned(IEntity entity, int index)
SCR_EIdentityCharacterControlType m_eCharacterControlTypes
bool IsMilitary()
static bool IsEditMode()
Definition Functions.c:1566
ref array< ref SCR_IdentityBio > m_aIdentityList
Definition Types.c:486
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
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
proto external Faction GetFactionByIndex(int index)
FactionManagerClass GenericEntityClass GetFactionByKey(FactionKey factionKey)
proto native bool IsEmpty()