DayZ 1.28
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 isContainerFull = container.IsFullQuantity();
240 if (isContainerFull && !ignore_fullness_check)
241 {
242 //Debug.Log("container is full", "LiquidTransfer");
243 return false;
244
245 }
246
247 int containerMask = container.GetLiquidContainerMask();
248 if (containerMask == 0)
249 {
250 //Debug.Log("target is not a container", "LiquidTransfer");
251 return false;//if the target liquidContainerType is set to 0
252 }
253
254 if ((liquid_type & containerMask) == 0)
255 {
256 //Debug.Log("target liquidContainerType does not support this liquid type", "LiquidTransfer");
257 return false;
258 }
259
260 float containerQuantity = container.GetQuantity();
261
262 int containerLiquidType = container.GetLiquidType();
263
264 if (containerQuantity > 0 && containerLiquidType != TranslateLiquidType(liquid_type))
265 {
266 //Debug.Log("target is not empty AND is of different liquid type than liquid_type added in", "LiquidTransfer");
267 return false;
268 }
269 return true;
270 }
271
273
276 static float GetLiquidTypeEnviroTemperature(int liquidType)
277 {
279 //ret = Math.Max(ret,GetLiquidFreezeThreshold(liquidType));
280
281 return ret;
282 }
283
284 private static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property = false)
285 {
286 string cfg_classname = "cfgLiquidDefinitions";
287 string property_value = "NULL_PROPERTY";
288 if (!g_Game)
289 return property_value;
290
291 int cfg_item_count = g_Game.ConfigGetChildrenCount(cfg_classname);
292
293 for (int i = 0; i < cfg_item_count; i++)
294 {
295 string liquid_class_name;
296 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
297 string liquid_full_path = string.Format("%1 %2", cfg_classname, liquid_class_name);
298 int config_liquid_type = GetGame().ConfigGetInt(string.Format("%1 type", liquid_full_path));
299
300 if (config_liquid_type == liquid_type)// found the specific class, now lets extract the values
301 {
302 if (!is_nutrition_property)
303 {
304 GetGame().ConfigGetText(string.Format("%1 %2", liquid_full_path, property_name), property_value);
305 return property_value;
306 }
307 else
308 {
309 GetGame().ConfigGetText(string.Format("%1 Nutrition %2", liquid_full_path, property_name), property_value);
310 return property_value;
311 }
312 }
313 }
314 return property_value;
315 }
316
318 {
319 LiquidInfo info = m_LiquidInfosByType.Get(liquid_type);
320 if (info && info.m_NutriProfile)
321 return info.m_NutriProfile;
322
323 return null;
324 }
325
327 {
329 if (info && info.m_NutriProfile)
330 return info.m_NutriProfile;
331
332 return null;
333 }
334
335 static NutritionalProfile SetUpNutritionalProfile(int liquid_type, string liquid_class_name)
336 {
338 profile.m_Energy = Liquid.GetLiquidConfigProperty(liquid_type, "energy", true).ToFloat();
339 profile.m_NutritionalIndex = Liquid.GetLiquidConfigProperty(liquid_type, "nutritionalIndex", true).ToFloat();
340 profile.m_FullnessIndex = Liquid.GetLiquidConfigProperty(liquid_type, "fullnessIndex", true).ToFloat();
341 profile.m_WaterContent = Liquid.GetLiquidConfigProperty(liquid_type, "water", true).ToFloat();
342 profile.m_Toxicity = Liquid.GetLiquidConfigProperty(liquid_type, "toxicity", true).ToFloat();
343 profile.m_Agents = Liquid.GetLiquidConfigProperty(liquid_type, "agents", true).ToInt();
344 profile.m_Digestibility = Liquid.GetLiquidConfigProperty(liquid_type, "digestibility", true).ToFloat();
345 profile.m_AgentsPerDigest = Liquid.GetLiquidConfigProperty(liquid_type, "agentsPerDigest", true).ToFloat();
346
347 profile.MarkAsLiquid(liquid_type, liquid_class_name);
348 return profile;
349 }
350
351 static int GetAgents(int liquid_type)
352 {
353 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetAgents();
354 }
355
356 static int GetAgentsPerDigest(int liquidType)
357 {
358 return m_LiquidInfosByType.Get(liquidType).m_NutriProfile.m_AgentsPerDigest;
359 }
360
361 static float GetToxicity(int liquid_type)
362 {
363 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetToxicity();
364 }
365
366 static float GetWaterContent(int liquid_type)
367 {
368 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetWaterContent();
369 }
370
371 static float GetEnergy(int liquid_type)
372 {
373 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetEnergy();
374 }
375
376 static float GetNutritionalIndex(int liquid_type)
377 {
378 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetNutritionalIndex();
379 }
380
381 static string GetDisplayName(int liquid_type)
382 {
383 return m_LiquidInfosByType.Get(liquid_type).m_LiquidDisplayName;
384 }
385
386 static float GetFlammability(int liquid_type)
387 {
388 return m_LiquidInfosByType.Get(liquid_type).m_Flammability;
389 }
390
391 static float GetFullness(int liquid_type)
392 {
393 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetFullnessIndex();
394 }
395
396 static float GetDigestibility(int liquid_type)
397 {
398 return m_LiquidInfosByType.Get(liquid_type).m_NutriProfile.GetDigestibility();
399 }
400
401 static float GetFreezeThreshold(int liquid_type)
402 {
403 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidFreezeThreshold;
404 }
405
406 static float GetThawThreshold(int liquid_type)
407 {
408 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidThawThreshold;
409 }
410
411 static float GetBoilThreshold(int liquid_type)
412 {
413 return m_LiquidInfosByType.Get(liquid_type).m_TemperatureLiquidBoilThreshold;
414 }
415
417//deprecated methods below
419 static string GetName(int liquid_type)
420 {
421 return Liquid.GetLiquidConfigProperty(liquid_type, "name");
422 }
423};
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:1606
float GetEnergy()
Определения ItemBase.c:8420
override int GetAgents()
Определения ItemBase.c:8810
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:361
static float GetDigestibility(int liquid_type)
Определения Liquid.c:396
static ref map< int, ref LiquidInfo > m_LiquidInfosByType
Определения Liquid.c:41
static NutritionalProfile GetNutritionalProfileByType(int liquid_type)
Определения Liquid.c:317
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:376
static float GetFullness(int liquid_type)
Определения Liquid.c:391
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:335
static string GetLiquidConfigProperty(int liquid_type, string property_name, bool is_nutrition_property=false)
Определения Liquid.c:284
static float GetFreezeThreshold(int liquid_type)
Определения Liquid.c:401
static float GetFlammability(int liquid_type)
Определения Liquid.c:386
static bool CanTransfer(ItemBase source_ent, ItemBase target_ent)
Определения Liquid.c:121
static float GetBoilThreshold(int liquid_type)
Определения Liquid.c:411
static float GetThawThreshold(int liquid_type)
Определения Liquid.c:406
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:326
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:276
static ref map< string, ref NutritionalProfile > m_AllLiquidsByName
Определения Liquid.c:40
static string GetDisplayName(int liquid_type)
Определения Liquid.c:381
static void AffectContainerOnFill(ItemBase container, int liquid_type, float amount)
from enviro source
Определения Liquid.c:208
static float GetWaterContent(int liquid_type)
Определения Liquid.c:366
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.
Определения Global/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()
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
Определения 3_Game/constants.c:496
const int AGT_TRANSFER_COPY
Определения 3_Game/constants.c:500
const int AGT_WATER_HOT_SPRING
Определения 3_Game/constants.c:510
const int AGT_WATER_POND
Определения 3_Game/constants.c:502
const int AGT_SNOW
Определения 3_Game/constants.c:508
const int LIQUID_STILLWATER
Определения 3_Game/constants.c:552
const int LIQUID_HOTWATER
Определения 3_Game/constants.c:553
const int LIQUID_GROUP_DRINKWATER
Определения 3_Game/constants.c:556
const int LIQUID_FRESHWATER
Определения 3_Game/constants.c:551
const int LIQUID_WATER
Определения 3_Game/constants.c:541
const int LIQUID_RIVERWATER
Определения 3_Game/constants.c:542
const int LIQUID_SNOW
Определения 3_Game/constants.c:549
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