DayZ 1.24
Loading...
Searching...
No Matches
QuantityConversions.c
Go to the documentation of this file.
2{
3 static string GetItemQuantityText(EntityAI item, bool showMax = false)
4 {
5 string quantity_text = "";
6 if (item.IsInherited(InventoryItem))
7 {
10 float quantity = item_base.GetQuantity();
11 int ammo;
12 if (item.IsMagazine())
13 {
16 ammo = magazine_item.GetAmmoCount();
17
18 return ammo.ToString();
19 }
20 else if (item.IsInherited(ItemBook))
21 return "";
22 int stack_max = item.GetQuantityMax();
23
24 //int max = item.ConfigGetInt("varQuantityMax");
25 //string unit = item.ConfigGetString("stackedUnit");
26
27 if (stack_max > 0)
28 {
29 if (stack_max == 1)
30 {
31 if (quantity > 1)
32 {
33 if (showMax)
34 quantity_text = string.Format("%1/%2", quantity.ToString(), stack_max.ToString());
35 //quantity_text = string.Format("%i/%i", quantity, stack_max );
36 else
37 quantity_text = quantity.ToString();
38 }
39 else
40 quantity_text = "";
41 }
42 else
43 {
44 if (showMax)
45 quantity_text = string.Format("%1/%2", quantity.ToString(), stack_max.ToString());
46 //quantity_text = string.Format("%i/%i", quantity, stack_max );
47 else
48 quantity_text = quantity.ToString();
49 // if (unit == "ml")
50 // {
51 // float liters = round(quantity / 1000.0);
52 // if ( quantity < 2000 )
53 // {
54 // liters = ( round( (quantity / 100.0) ) ) / 10;
55 // }
56 // quantity_text = ftoa(liters) + "l";
57 // }
58 // else
59 // {
60 // quantity_text = itoa(quantity) + unit;
61 // }
62 }
63 }
64 }
65 return quantity_text;
66 }
67
69 {
70 float quantity = 0;
71 if (item.IsInherited(InventoryItem))
72 {
75 if (item_base)
76 {
77 if (item.IsMagazine())
78 {
81 quantity = magazine_item.GetAmmoCount();
82 }
83 else
84 quantity = item_base.GetQuantity();
85 }
86 }
87 return quantity;
88 }
89
91 {
92 float quantity = 0;
93 if (item.IsInherited(InventoryItem))
94 {
97 if (item_base)
98 {
99 if (item.IsMagazine())
100 {
103 quantity = magazine_item.GetAmmoMax();
104 }
105 else
106 quantity = item_base.GetQuantityMax();
107 }
108 }
109 return quantity;
110 }
111
112 static void GetItemQuantity(InventoryItem item, out float q_cur, out float q_min, out float q_max)
113 {
114 if (item.IsInherited(InventoryItem))
115 {
118 if (item.IsMagazine())
119 {
122 q_cur = magazine_item.GetAmmoCount();
123 q_min = 0;
124 q_max = magazine_item.GetAmmoMax();
125 }
126 else
127 {
128 q_cur = item_base.GetQuantity();
129 q_min = item_base.GetQuantityMin();
130 q_max = item_base.GetQuantityMax();
131 }
132 }
133 }
134
136 {
137 ItemBase ib;
138 if (Class.CastTo(ib, item))
139 {
140 if (item.IsMagazine())
141 return QUANTITY_COUNT;
142
143 if (!ib.m_CanShowQuantity)
144 return QUANTITY_HIDDEN;
145
146 int max = item.GetQuantityMax();
147 if (max > 0)
148 {
149 if (ib.m_HasQuantityBar)
150 return QUANTITY_PROGRESS;
151 else
152 {
153 if (max == 1)
154 return QUANTITY_HIDDEN;
155 else
156 return QUANTITY_COUNT;
157 }
158 }
159 }
160 return QUANTITY_HIDDEN;
161 }
162}
Super root of all classes in Enforce script.
Definition EnScript.c:11
static void GetItemQuantity(InventoryItem item, out float q_cur, out float q_min, out float q_max)
static float GetItemQuantity(InventoryItem item)
static int HasItemQuantity(notnull EntityAI item)
static float GetItemQuantityMax(InventoryItem item)
static string GetItemQuantityText(EntityAI item, bool showMax=false)
const int QUANTITY_PROGRESS
Definition constants.c:484
const int QUANTITY_COUNT
Definition constants.c:483
const int QUANTITY_HIDDEN
Definition constants.c:482
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.