Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIDropMagazines.c
Go to the documentation of this file.
2{
3 static const string PORT_MAGAZINE_WELL = "MagazineWell";
4
5 [Attribute("0.5", UIWidgets.Slider, "Fraction of magazines to drop", "0 1 1" )]
6 protected float m_FractionOfMagazines;
7 [Attribute("", UIWidgets.EditBox, "Name of magazine well" )]
8 protected string m_sMagazineWellType;
9
10 private SCR_InventoryStorageManagerComponent m_Inventory;
11 private typename m_oMagazineWell;
12
13 //--------------------------------------------------------------------------------------------------------------------------
14 protected static ref TStringArray s_aVarsIn = {
15 PORT_MAGAZINE_WELL
16 };
18 {
19 return s_aVarsIn;
20 }
21
22 //--------------------------------------------------------------------------------------------------------------------------
23 override void OnInit(AIAgent owner)
24 {
25 IEntity ent = owner.GetControlledEntity();
26 if (ent)
27 {
28 m_Inventory = SCR_InventoryStorageManagerComponent.Cast(ent.FindComponent(SCR_InventoryStorageManagerComponent));
29 }
30 }
31
32 //--------------------------------------------------------------------------------------------------------------------------
33 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
34 {
35 if (!m_Inventory)
36 return ENodeResult.FAIL;
37
38 if(!GetVariableIn(PORT_MAGAZINE_WELL,m_oMagazineWell))
39 m_oMagazineWell = m_sMagazineWellType.ToType();
40
41 array<typename> components = {};
42 array<IEntity> foundItems = {};
43 components.Insert(MagazineComponent);
44
45 for (int i = m_Inventory.FindItemsWithComponents(foundItems,components, EStoragePurpose.PURPOSE_DEPOSIT)-1; i> -1; i--)
46 {
47 MagazineComponent magComp = MagazineComponent.Cast(foundItems[i].FindComponent(MagazineComponent));
48 if (magComp && magComp.GetMagazineWell().Type() != m_oMagazineWell)
49 {
50 foundItems.Remove(i);
51 }
52 }
53 // now I have only items that are magazines and have same well type
54
55 for (int i = 0, length = Math.Floor((foundItems.Count()-1) * m_FractionOfMagazines); i <= length; i++)
56 {
57 InventoryItemComponent pInvComp = InventoryItemComponent.Cast(foundItems[i].FindComponent(InventoryItemComponent));
58 InventoryStorageSlot parentSlot = pInvComp.GetParentSlot();
59 bool removed = m_Inventory.TryRemoveItemFromStorage(foundItems[i],parentSlot.GetStorage());
60 }
61 return ENodeResult.SUCCESS;
62 }
63
64 //--------------------------------------------------------------------------------------------------------------------------
65 protected static override bool VisibleInPalette()
66 {
67 return true;
68 }
69
70 //--------------------------------------------------------------------------------------------------------------------------
71 override protected string GetNodeMiddleText()
72 {
73 return "Drop " + (m_FractionOfMagazines*100).ToString() + "% of magazines to ground.";
74 }
75
76 //--------------------------------------------------------------------------------------------------------------------------
77 protected static override string GetOnHoverDescription()
78 {
79 return "AI task that drops all magazines of specified MagazineWell type.";
80 }
81};
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
proto bool GetVariableIn(string name, out void val)
override void OnInit(AIAgent owner)
static ref TStringArray s_aVarsIn
static override bool VisibleInPalette()
static override string GetOnHoverDescription()
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
override TStringArray GetVariablesIn()
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
EStoragePurpose
array< string > TStringArray
Definition Types.c:385
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.