Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_UniversalInventoryStorageComponent.c
Go to the documentation of this file.
4
9{
10 [Attribute( "0", UIWidgets.EditBox, "How much weight it can carry")]
11 protected float m_fMaxWeight;
12
13 [Attribute( "0", UIWidgets.EditBox, "The ID of slots the inserted items will be visible in")]
14 protected ref array<int> m_aSlotsToShow;
15
16 [Attribute(desc: "Dictates how the entity gets other storage and sets them as linked storage or how it itself sets it as a linked storage of another storage. Do not use base class!")]
18
20 protected ref array<BaseInventoryStorageComponent> m_aLinkedStorages;
21
22 #ifndef DISABLE_INVENTORY
23 private SCR_ItemAttributeCollection m_Attributes;
24 protected float m_fWeight;
25 protected SCR_InventoryStorageManagerComponent pInventoryManager;
26 protected static const int MIN_VOLUME_TO_SHOW_ITEM_IN_SLOT = 200000;
27
28 protected int m_iNrOfNonRefundableItems = 0; //used for keeping track of all non refundable items inside of a storage
29
30 //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
31
32 //------------------------------------------------------------------------------------------------
34 float GetMaxLoad()
35 {
36 return m_fMaxWeight;
37 }
38
39 //------------------------------------------------------------------------------------------------
42 {
43 const int volumeBased = GetEstimatedCountFitForResource(prefab);
44 const float itemWeight = GetWeightFromResource(prefab);
45 const int weightBased = Math.Floor((m_fMaxWeight - GetTotalWeight()) / itemWeight);
46
47 if (volumeBased < weightBased)
48 return volumeBased;
49
50 return weightBased;
51 }
52
53 //------------------------------------------------------------------------------------------------
56 protected bool CheckParentWeightLimit(float weight)
57 {
58 IEntity parent = GetOwner().GetParent();
59 if (!parent || ChimeraCharacter.Cast(parent))
60 return true;
61
63 if (!parentStorage)
64 return true;
65
66 return parentStorage.IsAdditionalWeightOk(weight);
67 }
68
69 //------------------------------------------------------------------------------------------------
70 private SCR_ItemAttributeCollection GetAttributeCollection( IEntity item )
71 {
72 InventoryItemComponent pItemComp = GetItemComponent( item );
73 if( !pItemComp )
74 return null;
75
76 return SCR_ItemAttributeCollection.Cast( pItemComp.GetAttributes() );
77 }
78
79 //------------------------------------------------------------------------------------------------
84
85 //------------------------------------------------------------------------------------------------
86 bool IsAdditionalWeightOk( float fWeight )
87 {
88 if (!m_Attributes)
89 return false;
90
91 fWeight += GetTotalWeight() - m_Attributes.GetWeight();
92
93 return m_fMaxWeight >= fWeight;
94 }
95
96 //------------------------------------------------------------------------------------------------
97 override bool CanStoreItem(IEntity item, int slotID)
98 {
99 if (!super.CanStoreItem(item, slotID))
100 return false;
101
103 if (!pItemComp)
104 return false;
105
106 bool bVolumeOK = PerformVolumeValidation(item);
107 if (!bVolumeOK)
108 {
110 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_BIG);
111
112 return false;
113 }
114
115 bool bWeightOK = IsAdditionalWeightOk(pItemComp.GetTotalWeight());
116 if (!bWeightOK)
117 {
119 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY);
120
121 return false;
122 }
123
124 IEntity parent = GetOwner().GetParent();
125 if (parent)
126 {
127 if (parent == item.GetParent())
128 return true; // If transfered from my parent inventory to me then it has to be within parents allowed weight limit
129
130 return CheckParentWeightLimit(pItemComp.GetTotalWeight());
131 }
132
133 return true;
134 }
135
136 //------------------------------------------------------------------------------------------------
137 override bool CanStoreResource(ResourceName resourceName, int slotID)
138 {
139 if (!super.CanStoreResource(resourceName, slotID))
140 return false;
141
143 if (!bVolumeOK)
144 {
146 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_BIG);
147
148 return false;
149 }
150
151 float fWeight = GetWeightFromResource(resourceName);
152 bool bWeightOK = IsAdditionalWeightOk(fWeight);
153 if (!bWeightOK)
154 {
156 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY);
157
158 return false;
159 }
160
161 if (GetOwner().GetParent())
162 return CheckParentWeightLimit(fWeight);
163
164 return true;
165 }
166
167 //------------------------------------------------------------------------------------------------
168 override bool CanReplaceItem(IEntity nextItem, int slotID)
169 {
170 if (!super.CanReplaceItem(nextItem, slotID))
171 return false;
172
173 if (!nextItem)
174 return false;
175
176 IEntity item = Get(slotID);
177
178 if (!item)
179 return false;
180
181 // item is the item that is getting replaced by nextItem
182 // nextItem is the item that is replacing the item at slotID
183 // slotID is is the slot ID for the item that is getting replaced by nextItem
184
186 if(!itemComp)
187 return false;
188
189 InventoryItemComponent nextItemComp = GetItemComponent(nextItem);
190 if(!nextItemComp)
191 return false;
192
193 float itemVolume = itemComp.GetTotalVolume();
194 float nextItemVolume = nextItemComp.GetTotalVolume();
195 float occupiedVolumeWithoutItem = GetOccupiedSpace() - itemVolume;
196
197 bool bVolumeOK = occupiedVolumeWithoutItem + nextItemVolume <= GetMaxVolumeCapacity();
198 if (!bVolumeOK || !PerformDimensionValidation(nextItem))
199 {
201 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_BIG);
202
203 return false;
204 }
205
206 bool bWeightOK = IsAdditionalWeightOk(nextItemComp.GetTotalWeight() - itemComp.GetTotalWeight());
207 if (!bWeightOK)
208 {
210 pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY);
211
212 return false;
213 }
214
215 return true;
216 }
217
218 //------------------------------------------------------------------------------------------------
219 override void OnRemovedFromSlot(IEntity item, int slotID)
220 {
221 super.OnRemovedFromSlot(item, slotID);
222
223 GenericEntity pGenComp = GenericEntity.Cast( item );
225 pItemComponent.ShowOwner();
226 pItemComponent.EnablePhysics();
227
228 m_fWeight -= pItemComponent.GetTotalWeight();
229
230 SCR_ItemAttributeCollection refundItemAttributes = SCR_ItemAttributeCollection.Cast(pItemComponent.GetAttributes());
231 if (refundItemAttributes && !refundItemAttributes.IsRefundable())
233 }
234
235 //------------------------------------------------------------------------------------------------
236 protected override void OnAddedToSlot(IEntity item, int slotID)
237 {
238 super.OnAddedToSlot(item, slotID);
239
240 GenericEntity pGenComp = GenericEntity.Cast( item );
242 if( !pItemComponent )
243 return;
244
245 float fVol = pItemComponent.GetTotalVolume();
246 if ( m_aSlotsToShow.Find( slotID ) != -1 )
247 {
248 pItemComponent.ShowOwner();
249 }
250 else
251 {
252 if ( fVol >= MIN_VOLUME_TO_SHOW_ITEM_IN_SLOT )
253 pItemComponent.ShowOwner();
254 }
255
256 pItemComponent.DisablePhysics();
257 pItemComponent.ActivateOwner(false);
258
259 m_fWeight += pItemComponent.GetTotalWeight();
260
261 SCR_ItemAttributeCollection refundItemAttributes = SCR_ItemAttributeCollection.Cast(pItemComponent.GetAttributes());
262 if (refundItemAttributes && !refundItemAttributes.IsRefundable())
264 }
265
266 //------------------------------------------------------------------------ LINKED STORAGES ----------------------------------------------------------------------
267
268 //------------------------------------------------------------------------------------------------
272 int GetLinkedStorages(notnull out array<BaseInventoryStorageComponent> linkedStorages)
273 {
275 return 0;
276
277 linkedStorages.Copy(m_aLinkedStorages);
278 return linkedStorages.Count();
279 }
280
281 //------------------------------------------------------------------------------------------------
284 void AddLinkedStorage(BaseInventoryStorageComponent newLinkedStorage)
285 {
286 //~ Do not add self as linked storage
287 if (newLinkedStorage == this)
288 return;
289
292 //~ Already contains the storage
293 else if (m_aLinkedStorages.Contains(newLinkedStorage))
294 return;
295
296 m_aLinkedStorages.Insert(newLinkedStorage);
297 }
298
299 //------------------------------------------------------------------------------------------------
303 bool IsStorageALinkedChild(notnull BaseInventoryStorageComponent storage)
304 {
305 return m_aLinkedStorages.Contains(storage);
306 }
307
308 //------------------------------------------------------------------------------------------------
313
314 //------------------------------------------------------------------------------------------------
315 void SetNonRefundableItemCount(int refundableItemCount)
316 {
317 m_iNrOfNonRefundableItems = refundableItemCount;
318 }
319
320 //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
321
322 //------------------------------------------------------------------------------------------------
324 {
325 super.OnManagerChanged(manager);
326
327 pInventoryManager = SCR_InventoryStorageManagerComponent.Cast( manager );
328 }
329
330 //------------------------------------------------------------------------------------------------
331 // constructor
336 {
337 m_Attributes = SCR_ItemAttributeCollection.Cast(GetAttributes());
338 if (!m_Attributes)
339 return;
340
341 m_fWeight = m_Attributes.GetWeight();
342
344 m_LinkedStorageLogic.Init(this);
345 }
346 #else
347 private SCR_ItemAttributeCollection GetAttributeCollection( IEntity item );
348 protected InventoryItemComponent GetItemComponent( IEntity pItem );
349 protected bool IsVolumeOk( float fVolume );
350 protected bool IsWeightOk( float fWeight );
351 override bool CanStoreItem(IEntity item, int slotID);
352 override bool CanStoreResource(ResourceName resourceName, int slotID, int count);
353 override bool CanRemoveItem(IEntity item);
354 override void OnRemovedFromSlot(IEntity item, int slotID);
355 protected override void OnAddedToSlot(IEntity item, int slotID);
356 override void OnManagerChanged(InventoryStorageManagerComponent manager);
357// void SCR_UniversalInventoryStorageComponent( IEntityComponentSource src, IEntity ent, IEntity parent );
358 #endif
359}
ResourceName resourceName
Definition SCR_AIGroup.c:66
override bool CanStoreItem(IEntity item, int slotID)
Faction GetParent()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
bool IsStorageALinkedChild(notnull BaseInventoryStorageComponent storage)
void SetNonRefundableItemCount(int refundableItemCount)
ref SCR_BaseLinkedStorageLogic m_LinkedStorageLogic
InventoryItemComponent GetItemComponent(IEntity pItem)
int GetEstimatedCountFitForResourceWeight(ResourceName prefab)
Get an estimate of how many times the resource can fit in in this storage.
bool IsAdditionalWeightOk(float fWeight)
ref array< int > m_aSlotsToShow
ref array< BaseInventoryStorageComponent > m_aLinkedStorages
Storages that will be automatically closed and opened when the parent (this) storage is closed or ope...
float GetMaxLoad()
Returns how much weight the component can carry.
SCR_InventoryStorageManagerComponent pInventoryManager
int GetLinkedStorages(notnull out array< BaseInventoryStorageComponent > linkedStorages)
void SCR_UniversalInventoryStorageComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
bool CheckParentWeightLimit(float weight)
void AddLinkedStorage(BaseInventoryStorageComponent newLinkedStorage)
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
Definition Math.c:13
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
void OnRemovedFromSlot(IEntity item, int slotID)
proto external int GetEstimatedCountFitForResource(ResourceName resourceName)
Get an estimate of how many times the resource can fit in the inventory.
proto external bool PerformVolumeValidationForResource(ResourceName resourceName, bool includeDimensionValidation=true)
Performs prefab volume and (optionally) dimension validation.
event bool CanStoreResource(ResourceName resourceName, int slotID)
Implemented logics for can insert here, Manager will provide slotID of -1 in case slot is irrelevant.
proto external float GetWeightFromResource(ResourceName resourceName)
Get the weight of a prefab.
proto external bool PerformDimensionValidation(IEntity item)
Performs dimension validation.
proto external float GetMaxVolumeCapacity()
event bool CanReplaceItem(IEntity nextItem, int slotID)
Implemented logics for can replace to nextItem at slotID,.
proto external bool PerformVolumeValidation(IEntity item, bool includeDimensionValidation=true)
Performs item volume and (optionally) dimension validation.
void OnAddedToSlot(IEntity item, int slotID)
void OnManagerChanged(InventoryStorageManagerComponent manager)
event bool CanRemoveItem(IEntity item)
Implemented logics for can remove here,.
proto external float GetOccupiedSpace()
Returns amount of space occupied by attached items.
proto T Get(int n)