DayZ 1.24
Loading...
Searching...
No Matches
Liquid.c
Go to the documentation of this file.
1class Liquid
2{
5
6 static bool m_Init = InitAllLiquids();
7
8 static string GetLiquidClassname(int liquid_type)
9 {
11 if (liquid)
12 return liquid.GetLiquidClassname();
13
14 return "";
15 }
16
17 static bool InitAllLiquids()
18 {
19 string cfg_classname = "cfgLiquidDefinitions";
20 string property_value = "NULL_PROPERTY";
21 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
22
23 for (int i = 0; i < cfg_item_count; i++)
24 {
25 string liquid_class_name;
26 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
27 string liquid_full_path = string.Format("%1 %2", cfg_classname, liquid_class_name);
28 int config_liquid_type = GetGame().ConfigGetInt(string.Format("%1 type", liquid_full_path));
31
32 }
33 return true;
34 }
35
36 //---------------------------------------------------------------------------------------------------------
38 {
40 return;
41
44
45 // Debug.Log("Transfer, source:"+source.ToString()+" target: "+target.ToString(), "LiquidTransfer");
46
47 float source_quantity = source.GetQuantity();
48 float target_quantity = target.GetQuantity();
49 int source_liquid_type = source.GetLiquidType();
50 int target_liquid_type = target.GetLiquidType();
51 int target_mask = target_ent.ConfigGetFloat("liquidContainerType");
52 int source_mask = source_ent.ConfigGetFloat("liquidContainerType");
53
54 float available_capacity = target.GetQuantityMax() - target_quantity;
55
56 // Debug.Log("target_mask ="+target_mask.ToString(), "LiquidTransfer");
57 // Debug.Log("source_mask ="+source_mask.ToString(), "LiquidTransfer");
58 // Debug.Log("source_liquid_type ="+source_liquid_type.ToString(), "LiquidTransfer");
59 // Debug.Log("target_liquid_type ="+target_liquid_type.ToString(), "LiquidTransfer");
60
61 //target.GetBloodType(source_liquid_type);//override target liquidType
63 //transfers all
64 if (quantity == -1)
66 //transfers exact ammount
67 else
69
70 //target.AddQuantity(quantity_to_transfer);
71 PluginTransmissionAgents m_mta = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
73
74 source.AddQuantity(-quantity_to_transfer);
75
77 }
78
80 {
81 if (!source_ent || !target_ent)
82 return false;
83
84 if (!source_ent.IsItemBase() || !target_ent.IsItemBase())
85 {
86 //Debug.Log("One of the Items is not of ItemBase type", "LiquidTransfer");
87 return false;
88 }
89
92 if ((barrelTarget && !barrelTarget.IsOpen()) || (barrelSource && !barrelSource.IsOpen()))
93 return false;
94
95
96 float source_quantity = source_ent.GetQuantity();
97 if (source_quantity <= 0)
98 {
99 //Debug.Log("source has no quantity", "LiquidTransfer");
100 return false;//if there is nothing to transfer
101 }
102
103 int source_liquid_type = source_ent.GetLiquidType();
104 if (source_liquid_type < 1)
105 {
106 //Debug.Log("source has some quantity, but does not have a valid liquidType set, liquidType = "+ToString(source_liquid_type), "LiquidTransfer");
107 return false;//if source is not a container
108 }
109
111 return false;
112
113
114 return true;
115 }
116 static void FillContainer(ItemBase container, int liquid_type, float amount)
117 {
119 return;
120 //filling
121 container.SetLiquidType(liquid_type);
122 container.AddQuantity(amount);
123
124 }
125
126 static void FillContainerEnviro(ItemBase container, int liquid_type, float amount, bool inject_agents = false)
127 {
129 if (inject_agents)
130 {
131 PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
132 plugin.TransmitAgents(NULL, container, AGT_WATER_POND, amount);
133 }
134 }
135
137 {
138 if (!container)
139 return false;
140
141 bool is_container_full = container.IsFullQuantity();
142
144 {
145 //Debug.Log("container is full", "LiquidTransfer");
146 return false;
147
148 }
149 int container_mask = container.ConfigGetFloat("liquidContainerType");
150
151 if (container_mask == 0)
152 {
153 //Debug.Log("target is not a container", "LiquidTransfer");
154 return false;//if the target liquidContainerType is set to 0
155 }
156
157 if ((liquid_type & container_mask) == 0)
158 {
159 //Debug.Log("target liquidContainerType does not support this liquid type", "LiquidTransfer");
160 return false;
161 }
162
163 float container_quantity = container.GetQuantity();
164
165 int container_liquid_type = container.GetLiquidType();
166
168 {
169 //Debug.Log("target is not empty AND is of different liquid type than liquid_type added in", "LiquidTransfer");
170 return false;
171 }
172 return true;
173 }
174
175 private static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property = false)
176 {
177 string cfg_classname = "cfgLiquidDefinitions";
178 string property_value = "NULL_PROPERTY";
179 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
180
181 for (int i = 0; i < cfg_item_count; i++)
182 {
183 string liquid_class_name;
184 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
185 string liquid_full_path = string.Format("%1 %2", cfg_classname, liquid_class_name);
186 int config_liquid_type = GetGame().ConfigGetInt(string.Format("%1 type", liquid_full_path));
187
188 if (config_liquid_type == liquid_type)// found the specific class, now lets extract the values
189 {
191 {
192 GetGame().ConfigGetText(string.Format("%1 %2", liquid_full_path, property_name), property_value);
193 return property_value;
194 }
195 else
196 {
197 GetGame().ConfigGetText(string.Format("%1 Nutrition %2", liquid_full_path, property_name), property_value);
198 return property_value;
199 }
200 }
201 }
202 return property_value;
203 }
204
209
214
228
229 static int GetAgents(int liquid_type)
230 {
231 return Liquid.GetLiquidConfigProperty(liquid_type, "agents", true).ToInt();
232 }
233
234 static float GetToxicity(int liquid_type)
235 {
236 return Liquid.GetLiquidConfigProperty(liquid_type, "toxicity", true).ToFloat();
237 }
238
239 static float GetWaterContent(int liquid_type)
240 {
241 return Liquid.GetLiquidConfigProperty(liquid_type, "water", true).ToFloat();
242 }
243
244 static float GetEnergy(int liquid_type)
245 {
246 return Liquid.GetLiquidConfigProperty(liquid_type, "energy", true).ToFloat();
247 }
248
250 {
251 return Liquid.GetLiquidConfigProperty(liquid_type, "nutritionalIndex", true).ToFloat();
252 }
253
254 static string GetName(int liquid_type)
255 {
257 }
258
259 static float GetFlammability(int liquid_type)
260 {
261 return Liquid.GetLiquidConfigProperty(liquid_type, "flammability").ToFloat();
262 }
263
264 static float GetFullness(int liquid_type)
265 {
266 return Liquid.GetLiquidConfigProperty(liquid_type, "fullnessIndex", true).ToFloat();
267 }
268
270 {
271 return Liquid.GetLiquidConfigProperty(liquid_type, "digestibility", true).ToFloat();
272 }
273
274};
DayZGame g_Game
Definition DayZGame.c:3528
float GetEnergy()
Definition ItemBase.c:8140
override int GetAgents()
Definition ItemBase.c:8554
class OptionSelectorMultistate extends OptionSelector class_name
PluginBase GetPlugin(typename plugin_type)
Definition Liquid.c:2
static float GetNutritionalIndex(int liquid_type)
Definition Liquid.c:249
static bool InitAllLiquids()
Definition Liquid.c:17
static float GetToxicity(int liquid_type)
Definition Liquid.c:234
static void Transfer(ItemBase source_ent, ItemBase target_ent, float quantity=-1)
Definition Liquid.c:37
static NutritionalProfile GetNutritionalProfileByType(int liquid_type)
Definition Liquid.c:205
static float GetFlammability(int liquid_type)
Definition Liquid.c:259
static float GetFullness(int liquid_type)
Definition Liquid.c:264
static void FillContainerEnviro(ItemBase container, int liquid_type, float amount, bool inject_agents=false)
Definition Liquid.c:126
static float GetWaterContent(int liquid_type)
Definition Liquid.c:239
static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
Definition Liquid.c:215
static int GetAgents(int liquid_type)
Definition Liquid.c:229
static void FillContainer(ItemBase container, int liquid_type, float amount)
Definition Liquid.c:116
static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property=false)
Definition Liquid.c:175
static ref map< string, ref NutritionalProfile > m_AllLiquidsByName
Definition Liquid.c:4
static bool m_Init
Definition Liquid.c:6
static float GetEnergy(int liquid_type)
Definition Liquid.c:244
static bool CanFillContainer(ItemBase container, int liquid_type, bool ignore_fullness_check=false)
Definition Liquid.c:136
static string GetName(int liquid_type)
Definition Liquid.c:254
static ref map< int, ref NutritionalProfile > m_AllLiquidsByType
Definition Liquid.c:3
static NutritionalProfile GetNutritionalProfileByName(string class_name)
Definition Liquid.c:210
static bool CanTransfer(ItemBase source_ent, ItemBase target_ent)
Definition Liquid.c:79
static float GetDigestibility(int liquid_type)
Definition Liquid.c:269
static string GetLiquidClassname(int liquid_type)
Definition Liquid.c:8
Definition EnMath.c:7
proto native CGame GetGame()
const int AGT_TRANSFER_COPY
Definition constants.c:469
const int AGT_WATER_POND
Definition constants.c:471
static proto float Min(float x, float y)
Returns smaller of two given values.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.