DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
Liquid.c
См. документацию.
1//extendable!
3{
8 float m_TemperatureLiquidThawThreshold = float.LOWEST;
9 float m_TemperatureLiquidBoilThreshold = Cooking.LIQUID_BOILING_POINT;
11
13
14 void LiquidInfo(string className, NutritionalProfile profile)
15 {
16 m_NutriProfile = profile;
17 Init(className);
18 }
19
20 protected void Init(string className)
21 {
22 string path = "cfgLiquidDefinitions " + className;
23 m_LiquidClassName = className;
24 g_Game.ConfigGetTextRaw(string.Format("%1 displayName", path), m_LiquidDisplayName);
25 g_Game.FormatRawConfigStringKeys(m_LiquidDisplayName);
26 m_LiquidType = g_Game.ConfigGetInt(string.Format("%1 type", path));
27 if (g_Game.ConfigIsExisting(string.Format("%1 liquidFreezeThreshold", path)))
28 m_TemperatureLiquidFreezeThreshold = g_Game.ConfigGetFloat(string.Format("%1 liquidFreezeThreshold", path));
29 if (g_Game.ConfigIsExisting(string.Format("%1 liquidThawThreshold", path)))
30 m_TemperatureLiquidThawThreshold = g_Game.ConfigGetFloat(string.Format("%1 liquidThawThreshold", path));
31 if (g_Game.ConfigIsExisting(string.Format("%1 liquidBoilingThreshold", path)))
32 m_TemperatureLiquidBoilThreshold = g_Game.ConfigGetFloat(string.Format("%1 liquidBoilingThreshold", path));
33 m_Flammability = g_Game.ConfigGetFloat(string.Format("%1 flammability", path));
34 }
35}
36
37class Liquid
38{
43 static bool m_Init = InitAllLiquids();
44
45 static string GetLiquidClassname(int liquid_type)
46 {
47 LiquidInfo info = m_LiquidInfosByType.Get(liquid_type);
48 if (info)
49 {
50 return info.m_LiquidClassName;
51 }
52
53 return "";
54 }
55
56 static bool InitAllLiquids()
57 {
58 if (!g_Game)
59 return false;
60
61 string cfg_classname = "cfgLiquidDefinitions";
62 string property_value = "NULL_PROPERTY";
63 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
64
65 for (int i = 0; i < cfg_item_count; i++)
66 {
67 string liquid_class_name;
68 g_Game.ConfigGetChildName(cfg_classname, i, liquid_class_name);
69 string liquid_full_path = string.Format("%1 %2",cfg_classname, liquid_class_name);
70 int config_liquid_type = g_Game.ConfigGetInt(string.Format("%1 type", liquid_full_path));
71
72 NutritionalProfile profile = SetUpNutritionalProfile(config_liquid_type, liquid_class_name);
73 LiquidInfo info = new LiquidInfo(liquid_class_name, profile);
74 m_LiquidInfosByType.Insert(config_liquid_type, info);
75 m_LiquidInfosByName.Insert(liquid_class_name, info);
76
77 //legacy stuff
78 m_AllLiquidsByType.Insert(config_liquid_type, profile);
79 m_AllLiquidsByName.Insert(liquid_class_name, profile);
80 }
81 return true;
82 }
83
84 //---------------------------------------------------------------------------------------------------------
85 static void Transfer(ItemBase source_ent, ItemBase target_ent, float quantity = -1)
86 {
87 if (!Liquid.CanTransfer(source_ent, target_ent))
88 return;
89
90 float source_quantity = source_ent.GetQuantity();
91 float target_quantity = target_ent.GetQuantity();
92 float targetCfgWeight = ItemBaseType.Cast(target_ent.GetEntityType()).m_ConfigWeight;
93 int source_liquid_type = source_ent.GetLiquidType();
94
95 float available_capacity = target_ent.GetQuantityMax() - target_quantity;
96 float quantity_to_transfer;
97 //transfers all
98 if (quantity == -1)
99 {
100 quantity_to_transfer = Math.Clamp(source_quantity,0,available_capacity);
101 }
102 //transfers exact ammount
103 else
104 {
105 quantity_to_transfer = Math.Clamp(Math.Min(source_quantity,quantity),0,available_capacity);
106 }
107
108 PluginTransmissionAgents m_mta = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
109 m_mta.TransmitAgents(source_ent, target_ent, AGT_TRANSFER_COPY);
110
111 source_ent.AddQuantity(-quantity_to_transfer);
112
113 float retultTemp = (source_ent.GetTemperature() * quantity_to_transfer + target_ent.GetTemperature() * (targetCfgWeight + target_quantity)) / (targetCfgWeight + target_quantity + quantity_to_transfer);
114 target_ent.SetTemperature(retultTemp);
115
116 AffectContainerOnTransfer(target_ent,source_liquid_type,quantity_to_transfer,source_ent.GetTemperature());
117
118 Liquid.FillContainer(target_ent,source_liquid_type,quantity_to_transfer);
119 }
120
121 static bool CanTransfer(ItemBase source_ent, ItemBase target_ent)
122 {
123 if (!source_ent || !target_ent)
124 return false;
125
126 Barrel_ColorBase barrelTarget = Barrel_ColorBase.Cast(target_ent);
127 Barrel_ColorBase barrelSource = Barrel_ColorBase.Cast(source_ent);
128 if ((barrelTarget && !barrelTarget.IsOpen()) || (barrelSource && !barrelSource.IsOpen()))
129 {
130 return false;
131 }
132
133 if (source_ent.GetIsFrozen())
134 {
135 return false;
136 }
137
138 float source_quantity = source_ent.GetQuantity();
139 if (source_quantity <= 0)
140 {
141 //Debug.Log("source has no quantity", "LiquidTransfer");
142 return false;//if there is nothing to transfer
143 }
144
145 int source_liquid_type = source_ent.GetLiquidType();
146 if (source_liquid_type < 1)
147 {
148 //Debug.Log("source has some quantity, but does not have a valid liquidType set, liquidType = "+ToString(source_liquid_type), "LiquidTransfer");
149 return false;//if source is not a container
150 }
151
152 if (!CanFillContainer(target_ent,source_liquid_type))
153 {
154 return false;
155 }
156
157 return true;
158 }
159
160 static void FillContainer(ItemBase container, int liquid_type, float amount)
161 {
162 if (!CanFillContainer(container,liquid_type))
163 {
164 return;
165 }
166 //filling
167 container.SetLiquidType(liquid_type);
168 container.AddQuantity(amount);
169 }
170
172 static void FillContainerEnviro(ItemBase container, int liquid_type, float amount, bool inject_agents = true)
173 {
174 float containerCfgWeight = ItemBaseType.Cast(container.GetEntityType()).m_ConfigWeight;
175 float retultTemp = (GetLiquidTypeEnviroTemperature(liquid_type) * amount + container.GetTemperature() * (containerCfgWeight + container.GetQuantity())) / (container.GetQuantity() + containerCfgWeight + amount);
176 container.SetTemperature(retultTemp);
177 AffectContainerOnFill(container,liquid_type,amount);
178
179 FillContainer(container, TranslateLiquidType(liquid_type), amount);
180
181 if (inject_agents)
182 {
183 PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
184 int agtSource;
185 switch (liquid_type)
186 {
187 case LIQUID_WATER:
191 agtSource = AGT_WATER_POND;
192 break;
193 case LIQUID_SNOW:
194 agtSource = AGT_SNOW;
195 break;
196 case LIQUID_HOTWATER:
197 agtSource = AGT_WATER_HOT_SPRING;
198 break;
199 default:
200 agtSource = AGT_NONE;
201 break;
202 }
203
204 plugin.TransmitAgents(NULL, container, agtSource, amount);
205 }
206 }
207
209 static void AffectContainerOnFill(ItemBase container, int liquid_type, float amount)
210 {
211 container.AffectLiquidContainerOnFill(liquid_type,amount);
212 }
213
214 static void AffectContainerOnTransfer(ItemBase container, int liquidType, float amount, float sourceLiquidTransfer)
215 {
216 container.AffectLiquidContainerOnTransfer(liquidType,amount,sourceLiquidTransfer);
217 }
218
219 static bool IsLiquidDrinkWater(int liquidType)
220 {
221 if (liquidType & (LIQUID_GROUP_DRINKWATER))
222 return true;
223 return false;
224 }
225
227 static int TranslateLiquidType(int liquidType)
228 {
229 if (IsLiquidDrinkWater(liquidType))
230 return LIQUID_WATER;
231 else
232 return liquidType;
233 }
234
235 static bool CanFillContainer(ItemBase container, int liquid_type, bool ignore_fullness_check = false)
236 {
237 if (!container)
238 return false;
239
240 bool is_container_full = container.IsFullQuantity();
241
242 if (is_container_full && !ignore_fullness_check)
243 {
244 //Debug.Log("container is full", "LiquidTransfer");
245 return false;
246
247 }
248 int container_mask = container.GetLiquidContainerMask();
249
250 if (container_mask == 0)
251 {
252 //Debug.Log("target is not a container", "LiquidTransfer");
253 return false;//if the target liquidContainerType is set to 0
254 }
255
256 if ((liquid_type & container_mask) == 0)
257 {
258 //Debug.Log("target liquidContainerType does not support this liquid type", "LiquidTransfer");
259 return false;
260 }
261
262 float container_quantity = container.GetQuantity();
263
264 int container_liquid_type = container.GetLiquidType();
265
266 if (container_quantity > 0 && container_liquid_type != liquid_type)
267 {
268 //Debug.Log("target is not empty AND is of different liquid type than liquid_type added in", "LiquidTransfer");
269 return false;
270 }
271 return true;
272 }
273
275
278 static float GetLiquidTypeEnviroTemperature(int liquidType)
279 {
280 float ret = g_Game.GetMission().GetWorldData().GetLiquidTypeEnviroTemperature(liquidType);
281 //ret = Math.Max(ret,GetLiquidFreezeThreshold(liquidType));
282
283 return ret;
284 }
285
286 private static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property = false)
287 {
288 string cfg_classname = "cfgLiquidDefinitions";
289 string property_value = "NULL_PROPERTY";
290 if (!g_Game)
291 return property_value;
292
293 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
294
295 for (int i = 0; i < cfg_item_count; i++)
296 {
297 string liquid_class_name;
298 g_Game.ConfigGetChildName(cfg_classname, i, liquid_class_name);
299 string liquid_full_path = string.Format("%1 %2", cfg_classname, liquid_class_name);
300 int config_liquid_type = g_Game.ConfigGetInt(string.Format("%1 type", liquid_full_path));
301
302 if (config_liquid_type == liquid_type)// found the specific class, now lets extract the values
303 {
304 if (!is_nutrition_property)
305 {
306 g_Game.ConfigGetText(string.Format("%1 %2", liquid_full_path, property_name), property_value);
307 return property_value;
308 }
309 else
310 {
311 g_Game.ConfigGetText(string.Format("%1 Nutrition %2", liquid_full_path, property_name), property_value);
312 return property_value;
313 }
314 }
315 }
316 return property_value;
317 }
318
320 {
321 LiquidInfo info = m_LiquidInfosByType.Get(liquid_type);
322 if (info && info.m_NutriProfile)
323 return info.m_NutriProfile;
324
325 return null;
326 }
327
329 {
331 if (info && info.m_NutriProfile)
332 return info.m_NutriProfile;
333
334 return null;
335 }
336
337 static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
338 {
340 profile.m_Energy = Liquid.GetLiquidConfigProperty(liquid_type, "energy", true).ToFloat();
341 profile.m_NutritionalIndex = Liquid.GetLiquidConfigProperty(liquid_type, "nutritionalIndex", true).ToFloat();
342 profile.m_FullnessIndex = Liquid.GetLiquidConfigProperty(liquid_type, "fullnessIndex", true).ToFloat();
343 profile.m_WaterContent = Liquid.GetLiquidConfigProperty(liquid_type, "water", true).ToFloat();
344 profile.m_Toxicity = Liquid.GetLiquidConfigProperty(liquid_type, "toxicity", true).ToFloat();
345 profile.m_Agents = Liquid.GetLiquidConfigProperty(liquid_type, "agents", true).ToInt();
346 profile.m_Digestibility = Liquid.GetLiquidConfigProperty(liquid_type, "digestibility", true).ToFloat();
347 profile.m_AgentsPerDigest = Liquid.GetLiquidConfigProperty(liquid_type, "agentsPerDigest", true).ToFloat();
348
349 profile.MarkAsLiquid(liquid_type, liquid_class_name);
350 return profile;
351 }
352
353 static int GetAgents(int liquid_type)
354 {
355 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetAgents();
356 }
357
358 static int GetAgentsPerDigest(int liquidType)
359 {
360 return m_LiquidInfosByType.Get(liquidType).m_NutriProfile.m_AgentsPerDigest;
361 }
362
363 static float GetToxicity(int liquid_type)
364 {
365 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetToxicity();
366 }
367
368 static float GetWaterContent(int liquid_type)
369 {
370 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetWaterContent();
371 }
372
373 static float GetEnergy(int liquid_type)
374 {
375 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetEnergy();
376 }
377
378 static float GetNutritionalIndex(int liquid_type)
379 {
380 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetNutritionalIndex();
381 }
382
383 static string GetDisplayName(int liquid_type)
384 {
385 return m_LiquidInfosByType.Get(liquid_type).m_LiquidDisplayName;
386 }
387
388 static float GetFlammability(int liquid_type)
389 {
390 return m_LiquidInfosByType.Get(liquid_type).m_Flammability;
391 }
392
393 static float GetFullness(int liquid_type)
394 {
395 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetFullnessIndex();
396 }
397
398 static float GetDigestibility(int liquid_type)
399 {
400 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetDigestibility();
401 }
402
403 static float GetFreezeThreshold(int liquid_type)
404 {
405 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidFreezeThreshold;
406 }
407
408 static float GetThawThreshold(int liquid_type)
409 {
410 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidThawThreshold;
411 }
412
413 static float GetBoilThreshold(int liquid_type)
414 {
415 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidBoilThreshold;
416 }
417
419//deprecated methods below
421 static string GetName(int liquid_type)
422 {
423 return Liquid.GetLiquidConfigProperty(liquid_type, "name");
424 }
425};
DayZGame g_Game
Определения DayZGame.c:4074
override Widget Init()
Определения DayZGame.c:127
static float GetAgentsPerDigest(ItemBase item, string className="", int foodStage=0)
Определения Edible_Base.c:1610
float GetEnergy()
Определения ItemBase.c:3613
override int GetAgents()
Определения ItemBase.c:3999
static bool InitAllLiquids()
Определения Liquid.c:56
static ref map< string, ref LiquidInfo > m_LiquidInfosByName
Определения Liquid.c:42
class LiquidInfo m_AllLiquidsByType
static float GetToxicity(int liquid_type)
Определения Liquid.c:363
static float GetDigestibility(int liquid_type)
Определения Liquid.c:398
static ref map< int, ref LiquidInfo > m_LiquidInfosByType
Определения Liquid.c:41
static NutritionalProfile GetNutritionalProfileByType(int liquid_type)
Определения Liquid.c:319
static void FillContainerEnviro(ItemBase container, int liquid_type, float amount, bool inject_agents=true)
Filled from any enviro source (fuel feed, pond, snow...)
Определения Liquid.c:172
static float GetNutritionalIndex(int liquid_type)
Определения Liquid.c:378
static float GetFullness(int liquid_type)
Определения Liquid.c:393
static bool m_Init
Определения Liquid.c:43
static bool CanFillContainer(ItemBase container, int liquid_type, bool ignore_fullness_check=false)
Определения Liquid.c:235
static string GetLiquidClassname(int liquid_type)
Определения Liquid.c:45
static void AffectContainerOnTransfer(ItemBase container, int liquidType, float amount, float sourceLiquidTransfer)
Определения Liquid.c:214
static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
Определения Liquid.c:337
static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property=false)
Определения Liquid.c:286
static float GetFreezeThreshold(int liquid_type)
Определения Liquid.c:403
static float GetFlammability(int liquid_type)
Определения Liquid.c:388
static bool CanTransfer(ItemBase source_ent, ItemBase target_ent)
Определения Liquid.c:121
static float GetBoilThreshold(int liquid_type)
Определения Liquid.c:413
static float GetThawThreshold(int liquid_type)
Определения Liquid.c:408
static void Transfer(ItemBase source_ent, ItemBase target_ent, float quantity=-1)
Определения Liquid.c:85
static bool IsLiquidDrinkWater(int liquidType)
Определения Liquid.c:219
static int TranslateLiquidType(int liquidType)
Translates 'administrative' liquid types into liquid types with valid config class.
Определения Liquid.c:227
static NutritionalProfile GetNutritionalProfileByName(string class_name)
Определения Liquid.c:328
static void FillContainer(ItemBase container, int liquid_type, float amount)
Определения Liquid.c:160
static float GetLiquidTypeEnviroTemperature(int liquidType)
Gets liquid temperature from the enviroment.
Определения Liquid.c:278
static ref map< string, ref NutritionalProfile > m_AllLiquidsByName
Определения Liquid.c:40
static string GetDisplayName(int liquid_type)
Определения Liquid.c:383
static void AffectContainerOnFill(ItemBase container, int liquid_type, float amount)
from enviro source
Определения Liquid.c:209
static float GetWaterContent(int liquid_type)
Определения Liquid.c:368
string path
Определения OptionSelectorMultistate.c:142
class OptionSelectorMultistate extends OptionSelector class_name
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:326
override bool IsOpen()
Определения Barrel_ColorBase.c:125
Определения ItemBaseType.c:5
ref NutritionalProfile m_NutriProfile
Определения Liquid.c:12
float m_TemperatureLiquidFreezeThreshold
Определения Liquid.c:7
float m_TemperatureLiquidBoilThreshold
Определения Liquid.c:9
float m_TemperatureLiquidThawThreshold
Определения Liquid.c:8
float m_Flammability
Определения Liquid.c:10
string m_LiquidClassName
Определения Liquid.c:4
string m_LiquidDisplayName
Определения Liquid.c:5
void Init(string className)
Определения Liquid.c:20
void LiquidInfo(string className, NutritionalProfile profile)
Определения Liquid.c:14
int m_LiquidType
Определения Liquid.c:6
Определения Liquid.c:3
Определения EnMath.c:7
float m_Digestibility
Определения NutritionalProfile.c:11
void MarkAsLiquid(int liquid_type, string classname)
Определения NutritionalProfile.c:26
float m_WaterContent
Определения NutritionalProfile.c:4
float m_FullnessIndex
Определения NutritionalProfile.c:6
float m_Toxicity
Определения NutritionalProfile.c:7
float m_Energy
Определения NutritionalProfile.c:3
int m_Agents
Определения NutritionalProfile.c:9
float m_AgentsPerDigest
Определения NutritionalProfile.c:12
float m_NutritionalIndex
Определения NutritionalProfile.c:5
Определения Transport.c:70
const int AGT_NONE
Определения 3_Game/DayZ/constants.c:530
const int AGT_TRANSFER_COPY
Определения 3_Game/DayZ/constants.c:534
const int AGT_WATER_HOT_SPRING
Определения 3_Game/DayZ/constants.c:544
const int AGT_WATER_POND
Определения 3_Game/DayZ/constants.c:536
const int AGT_SNOW
Определения 3_Game/DayZ/constants.c:542
const int LIQUID_STILLWATER
Определения 3_Game/DayZ/constants.c:589
const int LIQUID_HOTWATER
Определения 3_Game/DayZ/constants.c:590
const int LIQUID_GROUP_DRINKWATER
Определения 3_Game/DayZ/constants.c:593
const int LIQUID_FRESHWATER
Определения 3_Game/DayZ/constants.c:588
const int LIQUID_WATER
Определения 3_Game/DayZ/constants.c:578
const int LIQUID_RIVERWATER
Определения 3_Game/DayZ/constants.c:579
const int LIQUID_SNOW
Определения 3_Game/DayZ/constants.c:586
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'.
proto native owned string GetName()
Test name getter. Strictly for UI porposes!
Определения SyncedValue.c:119