43 void SetFoodStage(
int food_stage)
55 void AddAmount(
float amount)
60 void AddAgents(
int agents)
67 bool ProcessDigestion(
float digestion_points, out
float water, out
float energy, out
float toxicity, out
float volume, out
int agents, out
float consumed_amount)
70 consumed_amount = GetNutritions(digestion_points, m_Profile, water, energy, toxicity );
71 m_Amount -= consumed_amount;
72 volume = m_Profile.GetFullnessIndex() * m_Amount;
73 return( m_Amount < 0.001 );
76 float GetNutritions(
float digestion_points,
NutritionalProfile profile, out
float water, out
float energy, out
float toxicity )
78 float energy_per_unit = profile.GetEnergy() / 100;
79 float water_per_unit = profile.GetWaterContent() / 100;
80 float toxicity_per_unit = profile.GetToxicity();
81 float digestability = profile.GetDigestibility();
83 if(digestability == 0)
88 float consumed_quantity = digestion_points * digestability;
90 if( m_Amount < consumed_quantity )
92 consumed_quantity = m_Amount;
94 if ( consumed_quantity > 0 )
96 water = consumed_quantity * water_per_unit;
97 energy = consumed_quantity * energy_per_unit;
98 toxicity = consumed_quantity * toxicity_per_unit;
100 return consumed_quantity;
159 static void RegisterItem(
string classname,
int id)
161 int hash = classname.Hash();
162 CHECKSUM = CHECKSUM^hash;
165 m_NamesToIDs.Insert(classname,
id);
166 m_IDsToNames.Insert(
id, classname);
169 static string GetClassnameFromID(
int id)
171 return m_IDsToNames.Get(
id);
174 static int GetIDFromClassname(
string name)
176 if(!m_NamesToIDs.Contains(
name))
178 return m_NamesToIDs.Get(
name);
181 static bool InitData()
185 all_paths.Insert(
"CfgVehicles");
186 all_paths.Insert(
"cfgLiquidDefinitions");
192 int consumable_count;
193 for(
int i = 0; i < all_paths.Count(); i++)
195 config_path = all_paths.Get(i);
196 int children_count =
GetGame().ConfigGetChildrenCount(config_path);
198 for(
int x = 0;
x < children_count;
x++)
200 GetGame().ConfigGetChildName(config_path,
x, child_name);
201 path = config_path +
" " + child_name;
202 scope =
GetGame().ConfigGetInt( config_path +
" " + child_name +
" scope" );
203 bool should_check = 1;
204 if( config_path ==
"CfgVehicles" && scope == 0)
211 bool has_nutrition =
GetGame().ConfigIsExisting(
path +
" Nutrition");
212 bool has_stages =
GetGame().ConfigIsExisting(
path +
" Food");
214 if(has_nutrition || has_stages)
217 RegisterItem(child_name, consumable_count);
253 if(stomach_items_count == 0)
256 float digestion_points_per_item = (
DIGESTION_POINTS / stomach_items_count) * delta_time;
261 float water, energy, toxicity, volume, consumed_amount;
263 if(item.ProcessDigestion( digestion_points_per_item, water, energy, toxicity, volume, agents, consumed_amount ))
269 m_Player.GetStatEnergy().Add(energy);
292 int highest_bit =
Math.Log2(agents) + 1;
293 for(
int i = 0; i < highest_bit;i++)
295 int agent = (1 << i)& agents;
298 m_Player.m_AgentPool.DigestAgent(agent, quantity);
305 Print(
"================================");
313 Print(
"itemname:" + itemname);
314 Print(
"amount:" + amount);
315 Print(
"food_stage:" + food_stage);
316 Print(
"agents:" + agents);
320 Print(
"================================");
352 agents = agents | profile.GetAgents();
357 if(stomach_item.GetClassName() ==
class_name )
359 if (is_liquid || stomach_item.GetFoodStage() == food_stage)
361 stomach_item.AddAmount(amount);
362 stomach_item.AddAgents(agents);
383 int id =
PlayerStomach.GetIDFromClassname(stomach_item.m_ClassName);
387 int write_result = stomach_item.m_FoodStage | (
id <<
id_bit_offset );
389 ctx.Write( write_result );
390 ctx.Write( stomach_item.m_Agents );
399 if(!ctx.Read(checksum))
408 for(
int i = 0; i < count; i++)
411 if(!ctx.Read(value) )
415 if(!ctx.Read(agents) )
419 if(checksum == CHECKSUM)
425 int food_stage = value & food_mask;
430 string classname = GetClassnameFromID(
id);
435 if(checksum != CHECKSUM)
437 Print(
"Stomach checksum fail");
451 Param4<int,int,int,float> p4 =
new Param4<int,int,int,float>(
id, food_stage, agents, amount);
452 object_out.Insert(p4);
455 object_out.Insert(p1);