Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditableEntityComponentClass.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3{
4 [Attribute("0", UIWidgets.ComboBox, category: "Editable Entity", desc: "System type of the entity.", enums: ParamEnumArray.FromEnum(EEditableEntityType))]
6
7 [Attribute(category: "Visualization", desc: "GUI representation")]
8 protected ref SCR_UIInfo m_UIInfo;
9
10 [Attribute("", UIWidgets.Auto, category: "Visualization", desc: "Bone to which the icon is attached to")]
11 protected string m_sIconBoneName;
12
13 [Attribute(category: "Editable Entity")]
15
16 [Attribute(desc: "When spawning the editable entity and the data is set it will randomly grab a variant depending on the weight set. Any variant needs to have an editable entity component.\n\nLeave class null if there are no variants that need to be randomized", category: "Variants")]
18
19 //------------------------------------------------------------------------------------------------
24 {
25 Resource prefabResource = Resource.Load(prefab);
26 if (!prefabResource.IsValid())
27 return prefab;
28
29 IEntityComponentSource componentSource = SCR_BaseContainerTools.FindComponentSource(prefabResource, SCR_EditableEntityComponent);
30 if (!componentSource)
31 return prefab;
32
34 componentSource.Get("m_VariantData", variantData);
35
36 if (!variantData)
37 return prefab;
38
39 array<SCR_EditableEntityVariant> variants = {};
40 if (variantData.GetVariants(variants) == 0)
41 return prefab;
42
43 //~ Created weighted array for randomization
44 SCR_WeightedArray<ResourceName> weightedArray = new SCR_WeightedArray<ResourceName>();
45
46 foreach (SCR_EditableEntityVariant variant : variants)
47 {
48 prefabResource = Resource.Load(variant.m_sVariantPrefab);
49 if (!prefabResource.IsValid())
50 continue;
51
52 //~ Editable entities only
53 if (!GetEditableEntitySource(prefabResource))
54 continue;
55
56 //~ Add to randomizer
57 weightedArray.Insert(variant.m_sVariantPrefab, variant.m_iRandomizerWeight);
58 }
59
60 //~ No variants to randomize
61 if (weightedArray.IsEmpty())
62 return prefab;
63
64 //~ Add default variant to randomizer
65 if (variantData.m_bRandomizeDefaultVariant)
66 weightedArray.Insert(prefab, variantData.m_iDefaultVariantRandomizerWeight);
67
68 //~ Get random variant
69 ResourceName randomVariant;
70 weightedArray.GetRandomValue(randomVariant);
71
72 //~ Return random variant
73 return randomVariant;
74 }
75
76 //------------------------------------------------------------------------------------------------
80 static bool HasVariants(ResourceName prefab)
81 {
82 Resource prefabResource = Resource.Load(prefab);
83 if (!prefabResource.IsValid())
84 return false;
85
86 IEntityComponentSource componentSource = SCR_BaseContainerTools.FindComponentSource(prefabResource, SCR_EditableEntityComponent);
87 if (!componentSource)
88 return false;
89
91 componentSource.Get("m_VariantData", variantData);
92
93 if (!variantData)
94 return false;
95
96 array<SCR_EditableEntityVariant> variants = {};
97 return variantData.GetVariants(variants) > 0;
98 }
99
100 //------------------------------------------------------------------------------------------------
107
108 //------------------------------------------------------------------------------------------------
112 {
113 return m_UIInfo;
114 }
115
116 //------------------------------------------------------------------------------------------------
120 {
121 return m_sIconBoneName;
122 }
123
124 //------------------------------------------------------------------------------------------------
138
139 //------------------------------------------------------------------------------------------------
144 {
145 if (!entityResource)
146 return null;
147
148 BaseResourceObject entityBase = entityResource.GetResource();
149 if (!entityBase)
150 return null;
151
152 IEntitySource entitySource = entityBase.ToEntitySource();
153 if (!entitySource)
154 return null;
155
156 return GetEditableEntitySource(entitySource);
157 }
158
159 //------------------------------------------------------------------------------------------------
164 {
165 if (!entitySource)
166 return null;
167
168 int componentsCount = entitySource.GetComponentCount();
169 for (int i = 0; i < componentsCount; i++)
170 {
171 IEntityComponentSource componentSource = entitySource.GetComponent(i);
172 if (componentSource.GetClassName().ToType().IsInherited(SCR_EditableEntityComponent))
173 return componentSource;
174 }
175 return null;
176 }
177
178 //------------------------------------------------------------------------------------------------
183 {
184 BaseContainer infoSource = componentSource.GetObject("m_UIInfo");
185 if (!infoSource)
186 return null;
187
188 SCR_EditableEntityUIInfo info = SCR_EditableEntityUIInfo.Cast(BaseContainerTools.CreateInstanceFromContainer(infoSource));
189 info.InitFromSource(componentSource);
190 return info;
191 }
192
193 //------------------------------------------------------------------------------------------------
198 {
200 componentSource.Get("m_EntityType", type);
201 return type;
202 }
203
204 //------------------------------------------------------------------------------------------------
209 {
210 BaseContainer container = componentSource.GetObject("m_EntityInteraction");
211 if (container)
212 return SCR_EditableEntityInteraction.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
213
215 if (core)
216 return core.GetEntityInteraction(GetEntityType(componentSource));
217 else
218 return null;
219 }
220
221 //------------------------------------------------------------------------------------------------
226 {
227 BaseContainer info = componentSource.GetObject("m_UIInfo");
228 if (!info)
229 return ResourceName.Empty;
230
231 ResourceName slotPrefab;
232 info.Get("m_SlotPrefab", slotPrefab);
233 return slotPrefab;
234 }
235
236 //------------------------------------------------------------------------------------------------
241 {
243 componentSource.Get("m_Flags", flags);
244 return flags;
245 }
246
247 //------------------------------------------------------------------------------------------------
252 static bool HasFlag(IEntityComponentSource componentSource, EEditableEntityFlag flag)
253 {
255 componentSource.Get("m_Flags", flags);
256 return flags & flag;
257 }
258
259 //------------------------------------------------------------------------------------------------
265 static bool GetEntitySourceBudgetCost(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetValues)
266 {
267 if (!editableEntitySource)
268 return false;
269
270 SCR_EditableEntityUIInfo editableEntityUIInfo = SCR_EditableEntityComponentClass.GetInfo(editableEntitySource);
271 if (editableEntityUIInfo)
272 return editableEntityUIInfo.GetEntityBudgetCost(budgetValues);
273
274 return !budgetValues.IsEmpty();
275 }
276
277 //------------------------------------------------------------------------------------------------
282 static bool GetEntitySourceChildrenBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetValues)
283 {
284 if (!editableEntitySource)
285 return false;
286
287 SCR_EditableEntityUIInfo editableEntityUIInfo = SCR_EditableEntityComponentClass.GetInfo(editableEntitySource);
288 if (editableEntityUIInfo)
289 editableEntityUIInfo.GetEntityChildrenBudgetCost(budgetValues);
290
291 return !budgetValues.IsEmpty();
292 }
293}
SCR_EAIThreatSectorFlags flags
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
EDamageType type
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static IEntityComponentSource GetEditableEntitySource(IEntitySource entitySource)
static ResourceName GetRandomVariant(ResourceName prefab)
static ResourceName GetSlotPrefab(IEntityComponentSource componentSource)
static bool HasVariants(ResourceName prefab)
ref SCR_EditableEntityVariantData m_VariantData
static EEditableEntityType GetEntityType(IEntityComponentSource componentSource)
static SCR_EditableEntityInteraction GetEntityInteraction(IEntityComponentSource componentSource)
ref SCR_EditableEntityInteraction m_EntityInteraction
static bool HasFlag(IEntityComponentSource componentSource, EEditableEntityFlag flag)
static SCR_EditableEntityUIInfo GetInfo(IEntityComponentSource componentSource)
static bool GetEntitySourceBudgetCost(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetValues)
SCR_EditableEntityInteraction GetEntityInteraction()
static IEntityComponentSource GetEditableEntitySource(Resource entityResource)
static EEditableEntityFlag GetEntityFlags(IEntityComponentSource componentSource)
static bool GetEntitySourceChildrenBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetValues)
SCR_EditableEntityInteraction GetEntityInteraction(EEditableEntityType type)
void InitFromSource(IEntityComponentSource componentSource)
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
void GetEntityChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get only Entity's children budget costs, i.e. cost of entities inside a composition entitiy.
int GetVariants(out notnull array< SCR_EditableEntityVariant > variants)
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
EEditableEntityFlag
Unique flags of the entity.
SCR_FieldOfViewSettings Attribute