6 static bool m_Init = InitAllLiquids();
8 static string GetLiquidClassname(
int liquid_type)
13 return liquid.GetLiquidClassname();
19 static bool InitAllLiquids()
21 string cfg_classname =
"cfgLiquidDefinitions";
22 string property_value =
"NULL_PROPERTY";
23 int cfg_item_count =
g_Game.ConfigGetChildrenCount(cfg_classname);
25 for (
int i = 0; i < cfg_item_count; i++)
27 string liquid_class_name;
28 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
29 string liquid_full_path =
string.Format(
"%1 %2",cfg_classname, liquid_class_name);
30 int config_liquid_type =
GetGame().ConfigGetInt(
string.Format(
"%1 type", liquid_full_path));
31 m_AllLiquidsByType.Insert(config_liquid_type, SetUpNutritionalProfile(config_liquid_type, liquid_class_name));
32 m_AllLiquidsByName.Insert(liquid_class_name, SetUpNutritionalProfile(config_liquid_type, liquid_class_name));
39 static void Transfer(
ItemBase source_ent,
ItemBase target_ent,
float quantity = -1)
41 if (!
Liquid.CanTransfer(source_ent, target_ent))
49 float source_quantity = source.GetQuantity();
50 float target_quantity = target.GetQuantity();
51 int source_liquid_type = source.GetLiquidType();
52 int target_liquid_type = target.GetLiquidType();
53 int target_mask = target_ent.ConfigGetFloat(
"liquidContainerType");
54 int source_mask = source_ent.ConfigGetFloat(
"liquidContainerType");
56 float available_capacity = target.GetQuantityMax() - target_quantity;
64 float quantity_to_transfer;
68 quantity_to_transfer =
Math.Clamp(source_quantity,0,available_capacity);
73 quantity_to_transfer =
Math.Clamp(
Math.Min(source_quantity,quantity),0,available_capacity);
77 PluginTransmissionAgents m_mta = PluginTransmissionAgents.Cast(
GetPlugin(PluginTransmissionAgents));
80 source.AddQuantity(-quantity_to_transfer);
82 Liquid.FillContainer(target_ent,source_liquid_type,quantity_to_transfer);
87 if (!source_ent || !target_ent)
90 if (!source_ent.IsItemBase() || !target_ent.IsItemBase())
98 if ((barrelTarget && !barrelTarget.IsOpen()) || (barrelSource && !barrelSource.IsOpen()))
105 float source_quantity = source_ent.GetQuantity();
106 if (source_quantity <= 0)
112 int source_liquid_type = source_ent.GetLiquidType();
113 if (source_liquid_type < 1)
119 if (!CanFillContainer(target_ent,source_liquid_type))
127 static void FillContainer(
ItemBase container,
int liquid_type,
float amount)
129 if (!CanFillContainer(container,liquid_type))
134 container.SetLiquidType(liquid_type);
135 container.AddQuantity(amount);
139 static void FillContainerEnviro(
ItemBase container,
int liquid_type,
float amount,
bool inject_agents =
false)
141 FillContainer(container,liquid_type,amount);
144 PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(
GetPlugin(PluginTransmissionAgents));
149 static bool CanFillContainer(
ItemBase container,
int liquid_type,
bool ignore_fullness_check =
false)
154 bool is_container_full = container.IsFullQuantity();
156 if (is_container_full && !ignore_fullness_check)
162 int container_mask = container.ConfigGetFloat(
"liquidContainerType");
164 if (container_mask == 0)
170 if ((liquid_type & container_mask) == 0)
176 float container_quantity = container.GetQuantity();
178 int container_liquid_type = container.GetLiquidType();
180 if (container_quantity > 0 && container_liquid_type != liquid_type)
188 private static string GetLiquidConfigProperty(
int liquid_type,
string property_name,
bool is_nutrition_property =
false)
190 string cfg_classname =
"cfgLiquidDefinitions";
191 string property_value =
"NULL_PROPERTY";
192 int cfg_item_count =
g_Game.ConfigGetChildrenCount(cfg_classname);
194 for (
int i = 0; i < cfg_item_count; i++)
196 string liquid_class_name;
197 GetGame().ConfigGetChildName(cfg_classname, i, liquid_class_name);
198 string liquid_full_path =
string.Format(
"%1 %2", cfg_classname, liquid_class_name);
199 int config_liquid_type =
GetGame().ConfigGetInt(
string.Format(
"%1 type", liquid_full_path));
201 if (config_liquid_type == liquid_type)
203 if (!is_nutrition_property)
205 GetGame().ConfigGetText(
string.Format(
"%1 %2", liquid_full_path, property_name), property_value);
206 return property_value;
210 GetGame().ConfigGetText(
string.Format(
"%1 Nutrition %2", liquid_full_path, property_name), property_value);
211 return property_value;
215 return property_value;
220 return m_AllLiquidsByType.Get(liquid_type);
228 static NutritionalProfile SetUpNutritionalProfile(
int liquid_type,
string liquid_class_name)
230 float energy = GetEnergy(liquid_type);
231 float nutritional_index = GetNutritionalIndex(liquid_type);
232 float volume = GetFullness(liquid_type);
233 float water_content = GetWaterContent(liquid_type);
234 float toxicity = GetToxicity(liquid_type);
235 int agents = GetAgents(liquid_type);
236 float digest = GetDigestibility(liquid_type);
238 profile.MarkAsLiquid(liquid_type, liquid_class_name);
242 static int GetAgents(
int liquid_type)
244 return Liquid.GetLiquidConfigProperty(liquid_type,
"agents",
true).ToInt();
247 static float GetToxicity(
int liquid_type)
249 return Liquid.GetLiquidConfigProperty(liquid_type,
"toxicity",
true).ToFloat();
252 static float GetWaterContent(
int liquid_type)
254 return Liquid.GetLiquidConfigProperty(liquid_type,
"water",
true).ToFloat();
257 static float GetEnergy(
int liquid_type)
259 return Liquid.GetLiquidConfigProperty(liquid_type,
"energy",
true).ToFloat();
262 static float GetNutritionalIndex(
int liquid_type)
264 return Liquid.GetLiquidConfigProperty(liquid_type,
"nutritionalIndex",
true).ToFloat();
267 static string GetName(
int liquid_type)
269 return Liquid.GetLiquidConfigProperty(liquid_type,
"name");
272 static float GetFlammability(
int liquid_type)
274 return Liquid.GetLiquidConfigProperty(liquid_type,
"flammability").ToFloat();
277 static float GetFullness(
int liquid_type)
279 return Liquid.GetLiquidConfigProperty(liquid_type,
"fullnessIndex",
true).ToFloat();
282 static float GetDigestibility(
int liquid_type)
284 return Liquid.GetLiquidConfigProperty(liquid_type,
"digestibility",
true).ToFloat();