74 float newTempFraction = (1/fraction) * temperature;
81 bool ProcessDigestion(
float digestion_points, out
float water, out
float energy, out
float toxicity, out
float volume, out
int agents, out
float consumed_amount)
84 consumed_amount =
GetNutritions(digestion_points, m_Profile, water, energy, toxicity);
85 m_Amount -= consumed_amount;
86 volume = m_Profile.GetFullnessIndex() * m_Amount;
87 return(m_Amount < 0.001);
92 float energy_per_unit = profile.GetEnergy() / 100;
93 float water_per_unit = profile.GetWaterContent() / 100;
94 float toxicity_per_unit = profile.GetToxicity();
95 float digestability = profile.GetDigestibility();
97 if (digestability == 0)
102 float consumed_quantity = digestion_points * digestability;
104 if (m_Amount < consumed_quantity)
106 consumed_quantity = m_Amount;
108 if (consumed_quantity > 0)
110 water = consumed_quantity * water_per_unit;
111 energy = consumed_quantity * energy_per_unit;
112 toxicity = consumed_quantity * toxicity_per_unit;
114 return consumed_quantity;
168 percent =
Math.Clamp(percent, 0, 100);
169 float reduction = percent * 0.01;
173 item.AddAmount( -(item.GetAmount() * reduction) );
189 static void RegisterItem(
string classname,
int id)
191 int hash = classname.Hash();
192 CHECKSUM = CHECKSUM^hash;
193 m_NamesToIDs.Insert(classname,
id);
194 m_IDsToNames.Insert(
id, classname);
197 static string GetClassnameFromID(
int id)
199 return m_IDsToNames.Get(
id);
202 static int GetIDFromClassname(
string name)
204 if (!m_NamesToIDs.Contains(
name))
206 return m_NamesToIDs.Get(
name);
209 static bool InitData()
213 all_paths.Insert(
"CfgVehicles");
214 all_paths.Insert(
"cfgLiquidDefinitions");
220 int consumable_count;
221 for(
int i = 0; i < all_paths.Count(); i++)
223 config_path = all_paths.Get(i);
224 int children_count =
GetGame().ConfigGetChildrenCount(config_path);
226 for(
int x = 0;
x < children_count;
x++)
228 GetGame().ConfigGetChildName(config_path,
x, child_name);
229 path = config_path +
" " + child_name;
230 scope =
GetGame().ConfigGetInt(config_path +
" " + child_name +
" scope");
231 bool should_check = 1;
232 if (config_path ==
"CfgVehicles" && scope == 0)
239 bool has_nutrition =
GetGame().ConfigIsExisting(
path +
" Nutrition");
240 bool has_stages =
GetGame().ConfigIsExisting(
path +
" Food");
242 if (has_nutrition || has_stages)
245 RegisterItem(child_name, consumable_count);
275 if (stomachItemsCount == 0)
280 for (
int i = 0; i < stomachItemsCount; i++)
289 void Update(
float delta_time)
300 if (stomachItemsCount == 0)
303 float digestionPointsPerItem = (
DIGESTION_POINTS / stomachItemsCount) * delta_time;
305 for (
int i = stomachItemsCount - 1; i >= 0; i--)
308 float water, energy, toxicity, volume, consumedAmount;
311 if (item.
ProcessDigestion(digestionPointsPerItem, water, energy, toxicity, volume, agents, consumedAmount))
318 m_Player.GetStatEnergy().Add(energy);
328 float amountOfAgents = item.m_Profile.m_AgentsPerDigest;
329 if (amountOfAgents == 0)
330 amountOfAgents = consumedAmount;
334 amountOfAgents =
Math.Max(amountOfAgents,
PlayerConstants.BLOODY_HANDS_FOOD_POISON_AGENT_INCREMENT);
345 agents = agents & (~m_AgentTransferFilter);
346 int highestBit =
Math.Log2(agents) + 1;
347 for (
int i = 0; i < highestBit; ++i)
349 int agent = (1 << i)& agents;
354 quantity += quantity * rndPct;
355 m_Player.m_AgentPool.DigestAgent(agent, quantity);
362 float amountByAgent = 0.0;
365 if ((item.m_Agents & agent) == agent)
366 amountByAgent += item.m_Amount;
369 return amountByAgent;
383 Print(
"================================");
391 Print(
"itemname:" + itemname);
392 Print(
"amount:" + amount);
393 Print(
"food_stage:" + food_stage);
394 Print(
"agents:" + agents);
398 Print(
"================================");
420 agents = agents | profile.GetAgents();
423 for(
int i = 0; i < count; i++)
428 if (profile.IsLiquid() || stomachItem.
GetFoodStage() == food_stage)
432 fraction = (stomachItem.m_Amount + amount) / amount;
457 int id =
PlayerStomach.GetIDFromClassname(stomachItem.m_ClassName);
461 int writeResult = stomachItem.m_FoodStage | (
id <<
id_bit_offset);
463 ctx.Write(writeResult);
464 ctx.Write(stomachItem.m_Agents);
474 if (!ctx.Read(checksum))
479 if (!ctx.Read(count))
483 for (
int i = 0; i < count; ++i)
485 int value, agents, temperature;
486 if (!ctx.Read(value))
489 if (!ctx.Read(agents))
492 if (version >= 140 && !ctx.Read(temperature))
495 if (checksum == CHECKSUM)
501 int food_stage = value & food_mask;
506 string classname = GetClassnameFromID(
id);
507 AddToStomach(classname, amount, food_stage, agents, temperature);
511 if (checksum != CHECKSUM)
513 Print(
"Stomach checksum fail");
528 Param5<int,int,int,float,float> p5 =
new Param5<int,int,int,float,float>(
id, food_stage, agents, amount, temperature);
529 object_out.Insert(p5);
532 object_out.Insert(p1);
534 object_out.Insert(paramTemp);
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname="", int food_stage=0)
Serialization general interface. Serializer API works with:
void SetFoodStage(int food_stage)
float GetNutritions(float digestion_points, NutritionalProfile profile, out float water, out float energy, out float toxicity)
void StomachItem(string class_name, float amount, NutritionalProfile profile, int foodstage, int agents, float temperature)
bool ProcessDigestion(float digestion_points, out float water, out float energy, out float toxicity, out float volume, out int agents, out float consumed_amount)
void AddTemperature(float temperature, float fraction)
void AddAmount(float amount)
void AddAgents(int agents)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ref FoodStage m_FoodStage
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
array< string > TStringArray
void OnStoreSave(ParamsWriteContext ctx)
class ModifierDebugObj STORAGE_VERSION
bool OnStoreLoad(ParamsReadContext ctx, int version)
class OptionSelectorMultistate extends OptionSelector class_name
void AddToStomach(string class_name, float amount, int food_stage=0, int agents=0, float temperature=0)
float GetVolumeContainingAgent01(eAgents agent)
void ReduceContents(float percent)
const int ACCEPTABLE_QUANTITY_MAX
void UpdateStomachTemperature()
const int ACCEPTABLE_FOODSTAGE_MAX
int GetAgentTransferFilter()
float GetStomachTemperature()
const float DIGESTION_POINTS
class StomachItem DIGESTING_WATER
const int quantity_bit_offset
void DigestAgents(int agents, float quantity)
int GetDebugObject(array< ref Param > object_out)
const int DIGESTING_ENERGY
void ProcessNutrients(float delta_time)
float m_StomachTemperature
void SetAgentTransferFilter(int filter_agents)
ref array< ref StomachItem > m_StomachContents
float GetVolumeContainingAgent(eAgents agent)
int m_AgentTransferFilter
void PlayerStomach(PlayerBase player)