DayZ 1.27
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 GetGame().ConfigGetTextRaw(string.Format("%1 displayName", path), m_LiquidDisplayName);
26 m_LiquidType = GetGame().ConfigGetInt(string.Format("%1 type", path));
27 if (GetGame().ConfigIsExisting(string.Format("%1 liquidFreezeThreshold", path)))
28 m_TemperatureLiquidFreezeThreshold = GetGame().ConfigGetFloat(string.Format("%1 liquidFreezeThreshold", path));
29 if (GetGame().ConfigIsExisting(string.Format("%1 liquidThawThreshold", path)))
30 m_TemperatureLiquidThawThreshold = GetGame().ConfigGetFloat(string.Format("%1 liquidThawThreshold", path));
31 if (GetGame().ConfigIsExisting(string.Format("%1 liquidBoilingThreshold", path)))
32 m_TemperatureLiquidBoilThreshold = GetGame().ConfigGetFloat(string.Format("%1 liquidBoilingThreshold", path));
33 m_Flammability = GetGame().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 GetGame().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 = GetGame().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 = target_ent.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 = container.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 {
190 agtSource = AGT_WATER_POND;
191 break;
192 case LIQUID_SNOW:
193 agtSource = AGT_SNOW;
194 break;
195 case LIQUID_HOTWATER:
196 agtSource = AGT_WATER_HOT_SPRING;
197 break;
198 default:
199 agtSource = AGT_NONE;
200 break;
201 }
202
203 plugin.TransmitAgents(NULL, container, agtSource, amount);
204 }
205 }
206
208 static void AffectContainerOnFill(ItemBase container, int liquid_type, float amount)
209 {
210 container.AffectLiquidContainerOnFill(liquid_type,amount);
211 }
212
213 static void AffectContainerOnTransfer(ItemBase container, int liquidType, float amount, float sourceLiquidTransfer)
214 {
215 container.AffectLiquidContainerOnTransfer(liquidType,amount,sourceLiquidTransfer);
216 }
217
218 static bool IsLiquidDrinkWater(int liquidType)
219 {
220 if (liquidType & (LIQUID_GROUP_DRINKWATER))
221 return true;
222 return false;
223 }
224
226 static int TranslateLiquidType(int liquidType)
227 {
228 if (IsLiquidDrinkWater(liquidType))
229 return LIQUID_WATER;
230 else
231 return liquidType;
232 }
233
234 static bool CanFillContainer(ItemBase container, int liquid_type, bool ignore_fullness_check = false)
235 {
236 if (!container)
237 return false;
238
239 bool is_container_full = container.IsFullQuantity();
240
241 if (is_container_full && !ignore_fullness_check)
242 {
243 //Debug.Log("container is full", "LiquidTransfer");
244 return false;
245
246 }
247 int container_mask = container.GetLiquidContainerMask();
248
249 if (container_mask == 0)
250 {
251 //Debug.Log("target is not a container", "LiquidTransfer");
252 return false;//if the target liquidContainerType is set to 0
253 }
254
255 if ((liquid_type & container_mask) == 0)
256 {
257 //Debug.Log("target liquidContainerType does not support this liquid type", "LiquidTransfer");
258 return false;
259 }
260
261 float container_quantity = container.GetQuantity();
262
263 int container_liquid_type = container.GetLiquidType();
264
265 if (container_quantity > 0 && container_liquid_type != liquid_type)
266 {
267 //Debug.Log("target is not empty AND is of different liquid type than liquid_type added in", "LiquidTransfer");
268 return false;
269 }
270 return true;
271 }
272
274
277 static float GetLiquidTypeEnviroTemperature(int liquidType)
278 {
280 //ret = Math.Max(ret,GetLiquidFreezeThreshold(liquidType));
281
282 return ret;
283 }
284
285 private static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property = false)
286 {
287 string cfg_classname = "cfgLiquidDefinitions";
288 string property_value = "NULL_PROPERTY";
289 if (!g_Game)
290 return property_value;
291
292 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
293
294 for (int i = 0; i < cfg_item_count; i++)
295 {
296 string liquid_class_name;
297 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
298 string liquid_full_path = string.Format("%1 %2", cfg_classname, liquid_class_name);
299 int config_liquid_type = GetGame().ConfigGetInt(string.Format("%1 type", liquid_full_path));
300
301 if (config_liquid_type == liquid_type)// found the specific class, now lets extract the values
302 {
303 if (!is_nutrition_property)
304 {
305 GetGame().ConfigGetText(string.Format("%1 %2", liquid_full_path, property_name), property_value);
306 return property_value;
307 }
308 else
309 {
310 GetGame().ConfigGetText(string.Format("%1 Nutrition %2", liquid_full_path, property_name), property_value);
311 return property_value;
312 }
313 }
314 }
315 return property_value;
316 }
317
319 {
320 LiquidInfo info = m_LiquidInfosByType.Get(liquid_type);
321 if (info && info.m_NutriProfile)
322 return info.m_NutriProfile;
323
324 return null;
325 }
326
328 {
330 if (info && info.m_NutriProfile)
331 return info.m_NutriProfile;
332
333 return null;
334 }
335
336 static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
337 {
339 profile.m_Energy = Liquid.GetLiquidConfigProperty(liquid_type, "energy", true).ToFloat();
340 profile.m_NutritionalIndex = Liquid.GetLiquidConfigProperty(liquid_type, "nutritionalIndex", true).ToFloat();
341 profile.m_FullnessIndex = Liquid.GetLiquidConfigProperty(liquid_type, "fullnessIndex", true).ToFloat();
342 profile.m_WaterContent = Liquid.GetLiquidConfigProperty(liquid_type, "water", true).ToFloat();
343 profile.m_Toxicity = Liquid.GetLiquidConfigProperty(liquid_type, "toxicity", true).ToFloat();
344 profile.m_Agents = Liquid.GetLiquidConfigProperty(liquid_type, "agents", true).ToInt();
345 profile.m_Digestibility = Liquid.GetLiquidConfigProperty(liquid_type, "digestibility", true).ToFloat();
346 profile.m_AgentsPerDigest = Liquid.GetLiquidConfigProperty(liquid_type, "agentsPerDigest", true).ToFloat();
347
348 profile.MarkAsLiquid(liquid_type, liquid_class_name);
349 return profile;
350 }
351
352 static int GetAgents(int liquid_type)
353 {
354 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetAgents();
355 }
356
357 static int GetAgentsPerDigest(int liquidType)
358 {
359 return m_LiquidInfosByType.Get(liquidType).m_NutriProfile.m_AgentsPerDigest;
360 }
361
362 static float GetToxicity(int liquid_type)
363 {
364 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetToxicity();
365 }
366
367 static float GetWaterContent(int liquid_type)
368 {
369 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetWaterContent();
370 }
371
372 static float GetEnergy(int liquid_type)
373 {
374 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetEnergy();
375 }
376
377 static float GetNutritionalIndex(int liquid_type)
378 {
379 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetNutritionalIndex();
380 }
381
382 static string GetDisplayName(int liquid_type)
383 {
384 return m_LiquidInfosByType.Get(liquid_type).m_LiquidDisplayName;
385 }
386
387 static float GetFlammability(int liquid_type)
388 {
389 return m_LiquidInfosByType.Get(liquid_type).m_Flammability;
390 }
391
392 static float GetFullness(int liquid_type)
393 {
394 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetFullnessIndex();
395 }
396
397 static float GetDigestibility(int liquid_type)
398 {
399 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetDigestibility();
400 }
401
402 static float GetFreezeThreshold(int liquid_type)
403 {
404 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidFreezeThreshold;
405 }
406
407 static float GetThawThreshold(int liquid_type)
408 {
409 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidThawThreshold;
410 }
411
412 static float GetBoilThreshold(int liquid_type)
413 {
414 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidBoilThreshold;
415 }
416
418//deprecated methods below
420 static string GetName(int liquid_type)
421 {
422 return Liquid.GetLiquidConfigProperty(liquid_type, "name");
423 }
424};
map
Определения ControlsXboxNew.c:4
DayZGame g_Game
Определения DayZGame.c:3868
override Widget Init()
Определения DayZGame.c:127
static float GetAgentsPerDigest(ItemBase item, string className="", int foodStage=0)
Определения Edible_Base.c:1605
float GetEnergy()
Определения ItemBase.c:8278
override int GetAgents()
Определения ItemBase.c:8668
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:362
static float GetDigestibility(int liquid_type)
Определения Liquid.c:397
static ref map< int, ref LiquidInfo > m_LiquidInfosByType
Определения Liquid.c:41
static NutritionalProfile GetNutritionalProfileByType(int liquid_type)
Определения Liquid.c:318
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:377
static float GetFullness(int liquid_type)
Определения Liquid.c:392
static bool m_Init
Определения Liquid.c:43
static bool CanFillContainer(ItemBase container, int liquid_type, bool ignore_fullness_check=false)
Определения Liquid.c:234
static string GetLiquidClassname(int liquid_type)
Определения Liquid.c:45
static void AffectContainerOnTransfer(ItemBase container, int liquidType, float amount, float sourceLiquidTransfer)
Определения Liquid.c:213
static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
Определения Liquid.c:336
static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property=false)
Определения Liquid.c:285
static float GetFreezeThreshold(int liquid_type)
Определения Liquid.c:402
static float GetFlammability(int liquid_type)
Определения Liquid.c:387
static bool CanTransfer(ItemBase source_ent, ItemBase target_ent)
Определения Liquid.c:121
static float GetBoilThreshold(int liquid_type)
Определения Liquid.c:412
static float GetThawThreshold(int liquid_type)
Определения Liquid.c:407
static void Transfer(ItemBase source_ent, ItemBase target_ent, float quantity=-1)
Определения Liquid.c:85
static bool IsLiquidDrinkWater(int liquidType)
Определения Liquid.c:218
static int TranslateLiquidType(int liquidType)
Translates 'administrative' liquid types into liquid types with valid config class.
Определения Liquid.c:226
static NutritionalProfile GetNutritionalProfileByName(string class_name)
Определения Liquid.c:327
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:277
static ref map< string, ref NutritionalProfile > m_AllLiquidsByName
Определения Liquid.c:40
static string GetDisplayName(int liquid_type)
Определения Liquid.c:382
static void AffectContainerOnFill(ItemBase container, int liquid_type, float amount)
from enviro source
Определения Liquid.c:208
static float GetWaterContent(int liquid_type)
Определения Liquid.c:367
string path
Определения OptionSelectorMultistate.c:142
class OptionSelectorMultistate extends OptionSelector class_name
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:316
override bool IsOpen()
Определения Barrel_ColorBase.c:125
proto bool ConfigGetChildName(string path, int index, out string name)
Get name of subclass in config class on path.
proto native float ConfigGetFloat(string path)
Get float value from config on path.
proto bool ConfigGetTextRaw(string path, out string value)
Get raw string value from config on path.
bool FormatRawConfigStringKeys(inout string value)
Changes localization key format to script-friendly format.
Определения Game.c:475
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native Mission GetMission()
Определения InventoryItem.c:731
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
WorldData GetWorldData()
Определения gameplay.c:743
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
float GetLiquidTypeEnviroTemperature(int liquidType)
Определения WorldData.c:228
proto native CGame GetGame()
const int AGT_NONE
Определения constants.c:494
const int AGT_TRANSFER_COPY
Определения constants.c:498
const int AGT_WATER_HOT_SPRING
Определения constants.c:508
const int AGT_WATER_POND
Определения constants.c:500
const int AGT_SNOW
Определения constants.c:506
const int LIQUID_STILLWATER
Определения constants.c:550
const int LIQUID_HOTWATER
Определения constants.c:551
const int LIQUID_GROUP_DRINKWATER
Определения constants.c:554
const int LIQUID_FRESHWATER
Определения constants.c:549
const int LIQUID_WATER
Определения constants.c:539
const int LIQUID_RIVERWATER
Определения constants.c:540
const int LIQUID_SNOW
Определения constants.c:547
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