Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
EditablePrefabsLabel_CharacterRole.c
Go to the documentation of this file.
3{
4 [Attribute()]
6
7 protected ref array<EEditableEntityLabel> m_aRoleLabels = {};
8
9 //------------------------------------------------------------------------------------------------
10 override bool GetLabelValid(WorldEditorAPI api, IEntitySource entitySource, IEntityComponentSource componentSource, string targetPath, EEditableEntityType entityType, notnull array<EEditableEntityLabel> authoredLabels, out EEditableEntityLabel label)
11 {
12 if (authoredLabels.Contains(EEditableEntityLabel.ROLE_LEADER))
13 return false;
14
15 m_aRoleLabels.Clear();
16
17 CheckWeapons(entitySource);
18 CheckInventory(entitySource);
19 CheckLoadout(entitySource);
20
21 return GetRoleLabel(label);
22 }
23
24 //------------------------------------------------------------------------------------------------
25 protected void CheckWeapons(IEntitySource entitySource)
26 {
27 array<ref array<IEntityComponentSource>> weaponSlotComponents = {};
28 array<string> componentTypeArray = { "CharacterWeaponSlotComponent" };
29 int weaponSlotCount = SCR_BaseContainerTools.FindComponentSources(entitySource, componentTypeArray, weaponSlotComponents);
30
31 array<IEntityComponentSource> weaponSlotComponentSources = weaponSlotComponents.Get(0);
32
33 if (!weaponSlotComponentSources)
34 return;
35
36 Resource resource;
37 IEntitySource weaponSource;
38 IEntityComponentSource weaponComponentSource;
39 foreach (IEntityComponentSource weaponSlotComponent : weaponSlotComponentSources)
40 {
41 ResourceName weaponPrefab;
42 if (weaponSlotComponent.Get("WeaponTemplate", weaponPrefab))
43 {
44 if (!weaponPrefab)
45 continue;
46
47 resource = Resource.Load(weaponPrefab);
48 if (!resource.IsValid())
49 continue;
50
51 weaponSource = SCR_BaseContainerTools.FindEntitySource(resource);
52 if (!weaponSource)
53 continue;
54
55 weaponComponentSource = SCR_BaseContainerTools.FindComponentSource(weaponSource, "WeaponComponent");
56 if (!weaponComponentSource)
57 continue;
58
59 EWeaponType weaponType;
60 if (weaponComponentSource.Get("WeaponType", weaponType))
61 AddLabelForWeaponType(weaponType);
62
63 CheckWeaponAttachments(weaponComponentSource);
64 }
65 }
66 }
67
68 //------------------------------------------------------------------------------------------------
72 {
73 BaseContainer weaponComponent = weaponEntitySource.ToBaseContainer();
74 BaseContainerList weaponComponents = weaponComponent.GetObjectArray("components");
75
76 // Check WeaponComponent child components
77 BaseContainer container;
78 for (int i, count = weaponComponents.Count(); i < count; i++)
79 {
80 container = weaponComponents.Get(i);
81 if (container && container.GetClassName() == "AttachmentSlotComponent") // TODO: inherit?
82 {
83 string attachmentType;
84 container.Get("AttachmentType", attachmentType);
85 if (attachmentType == "underbarrel")
86 {
87 container = container.GetObject("AttachmentSlot"); // variable reuse
88 ResourceName attachmentPrefab;
89
90 // TODO check if underbarrel attachment is actually a grenade launcher.
91 if (container && container.Get("Prefab", attachmentPrefab))
92 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_GRENADIER);
93 }
94 }
95 }
96 }
97
98 //------------------------------------------------------------------------------------------------
99 protected void AddLabelForWeaponType(EWeaponType weaponType)
100 {
101 switch (weaponType)
102 {
103 case EWeaponType.WT_RIFLE:
104 {
105 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_RIFLEMAN);
106 break;
107 }
108 case EWeaponType.WT_MACHINEGUN:
109 {
110 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_MACHINEGUNNER);
111 break;
112 }
113 case EWeaponType.WT_ROCKETLAUNCHER:
114 {
115 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_ANTITANK);
116 break;
117 }
118 case EWeaponType.WT_GRENADELAUNCHER:
119 {
120 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_GRENADIER);
121 break;
122 }
123 case EWeaponType.WT_SNIPERRIFLE:
124 {
125 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_SHARPSHOOTER);
126 break;
127 }
128 }
129 }
130
131 //------------------------------------------------------------------------------------------------
134 void CheckLoadout(IEntitySource entitySource)
135 {
136 IEntityComponentSource inventoryManagerComponent = SCR_BaseContainerTools.FindComponentSource(entitySource, BaseLoadoutManagerComponent);
137 if (!inventoryManagerComponent)
138 return;
139
140 BaseContainerList slotList = inventoryManagerComponent.GetObjectArray("Slots");
141 if (!slotList)
142 return;
143
144 for (int i, count = slotList.Count(); i < count; i++)
145 {
146 BaseContainer slot = slotList.Get(i);
147 LoadoutAreaType slotArea;
148 if (!slot.Get("AreaType", slotArea))
149 continue;
150
151 ResourceName slotPrefab;
152 if (slotArea.IsInherited(LoadoutBackpackArea) && slot.Get("Prefab", slotPrefab))
153 {
154 Resource slotResource = Resource.Load(slotPrefab);
155 IEntityComponentSource radioComponentSource = SCR_BaseContainerTools.FindComponentSource(slotResource, SCR_RadioComponent);
156 ERadioCategory radioCategory;
157 if (radioComponentSource && radioComponentSource.Get("m_iRadioCategory", radioCategory) && radioCategory == ERadioCategory.MANPACK)
158 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_RADIOOPERATOR);
159 }
160 }
161 }
162
163 //------------------------------------------------------------------------------------------------
166 void CheckInventory(IEntitySource entitySource)
167 {
168 IEntityComponentSource inventoryManagerComponent = SCR_BaseContainerTools.FindComponentSource(entitySource, SCR_InventoryStorageManagerComponent);
169 if (!inventoryManagerComponent)
170 return;
171
172 BaseContainerList inventoryItems = inventoryManagerComponent.GetObjectArray("InitialInventoryItems");
173 if (!inventoryItems)
174 return;
175
176 int medicItemCount = 0;
177 for (int i, count = inventoryItems.Count(); i < count; i++)
178 {
179 BaseContainer inventoryItem = inventoryItems.Get(i);
180
181 array<ResourceName> prefabsToSpawn = {};
182 inventoryItem.Get("PrefabsToSpawn", prefabsToSpawn);
183
184 if (!prefabsToSpawn)
185 continue;
186
187 IEntityComponentSource consumableComponentSource;
188 BaseContainer consumableEffect;
189 foreach (ResourceName prefabToSpawn : prefabsToSpawn)
190 {
191 Resource inventoryPrefab = Resource.Load(prefabToSpawn);
192 if (!inventoryPrefab.IsValid())
193 continue;
194
195 consumableComponentSource = SCR_BaseContainerTools.FindComponentSource(inventoryPrefab, SCR_ConsumableItemComponent);
196 if (consumableComponentSource)
197 {
198 consumableEffect = consumableComponentSource.GetObject("m_ConsumableEffect");
199 if (consumableEffect)
200 {
201 SCR_EConsumableType consumableType;
202 if (consumableEffect.Get("m_eConsumableType", consumableType) && consumableType == SCR_EConsumableType.BANDAGE)
203 medicItemCount++;
204 }
205 }
206 }
207 }
208
209 if (medicItemCount >= m_MedicItemCountRequired)
210 m_aRoleLabels.Insert(EEditableEntityLabel.ROLE_MEDIC);
211 }
212
213 //------------------------------------------------------------------------------------------------
214 protected bool GetRoleLabel(out EEditableEntityLabel label)
215 {
216 label = EEditableEntityLabel.NONE;
217
218 if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_RADIOOPERATOR))
219 label = EEditableEntityLabel.ROLE_RADIOOPERATOR;
220 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_ANTITANK))
221 label = EEditableEntityLabel.ROLE_ANTITANK;
222 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_MACHINEGUNNER))
223 label = EEditableEntityLabel.ROLE_MACHINEGUNNER;
224 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_GRENADIER))
225 label = EEditableEntityLabel.ROLE_GRENADIER;
226 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_SHARPSHOOTER))
227 label = EEditableEntityLabel.ROLE_SHARPSHOOTER;
228 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_MEDIC))
229 label = EEditableEntityLabel.ROLE_MEDIC;
230 else if (m_aRoleLabels.Contains(EEditableEntityLabel.ROLE_RIFLEMAN))
231 label = EEditableEntityLabel.ROLE_RIFLEMAN;
232
233 return label != EEditableEntityLabel.NONE;
234 }
235}
EEditableEntityLabel
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
SCR_EConsumableType
Type of consumable gadget.
ERadioCategory
Radio slot.
bool GetRoleLabel(out EEditableEntityLabel label)
override bool GetLabelValid(WorldEditorAPI api, IEntitySource entitySource, IEntityComponentSource componentSource, string targetPath, EEditableEntityType entityType, notnull array< EEditableEntityLabel > authoredLabels, out EEditableEntityLabel label)
void CheckWeaponAttachments(IEntityComponentSource weaponEntitySource)
ref array< EEditableEntityLabel > m_aRoleLabels
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
SCR_FieldOfViewSettings Attribute
EWeaponType
Definition EWeaponType.c:13