DayZ 1.26
DayZ Explorer by KGB
Загрузка...
Поиск...
Не найдено
Файл PlayerStomach.c

См. исходные тексты.

Структуры данных

class  StomachItem
 

Функции

void PlayerStomach (PlayerBase player)
 
float GetStomachVolume ()
 
float GetStomachTemperature ()
 
void ClearContents ()
 
void ReduceContents (float percent)
 
void SetAgentTransferFilter (int filter_agents)
 
int GetAgentTransferFilter ()
 
static void RegisterItem (string classname, int id)
 
static string GetClassnameFromID (int id)
 
static int GetIDFromClassname (string name)
 
static bool InitData ()
 
int GetStorageVersion ()
 
bool IsDigesting ()
 
int GetDigestingType ()
 
void UpdateStomachTemperature ()
 
void Update (float delta_time)
 
void ProcessNutrients (float delta_time)
 
void DigestAgents (int agents, float quantity)
 
float GetVolumeContainingAgent (eAgents agent)
 
float GetVolumeContainingAgent01 (eAgents agent)
 
void PrintUpdate ()
 
void AddToStomach (string class_name, float amount, int food_stage=0, int agents=0, float temperature=0)
 
void OnStoreSave (ParamsWriteContext ctx)
 
bool OnStoreLoad (ParamsReadContext ctx, int version)
 
int GetDebugObject (array< ref Param > object_out)
 

Переменные

class StomachItem DIGESTING_WATER = 1
 
const int DIGESTING_ENERGY = 2
 
const int quantity_bit_offset = 16
 
const int id_bit_offset = 4
 
static int CHECKSUM
 
const float DIGESTION_POINTS = PlayerConstants.DIGESTION_SPEED
 
const int ACCEPTABLE_QUANTITY_MAX = 32768
 
const int ACCEPTABLE_FOODSTAGE_MAX = FoodStageType.COUNT - 1
 
static ref map< string, intm_NamesToIDs = new map<string, int>
 
static ref map< int, stringm_IDsToNames = new map<int, string>
 
static const bool m_InitData = PlayerStomach.InitData()
 
ref array< ref StomachItemm_StomachContents = new array<ref StomachItem>
 
int m_AgentTransferFilter
 
bool m_Digesting
 
int m_DigestingType
 
PlayerBase m_Player
 
float m_StomachVolume
 
float m_StomachTemperature
 
const int STORAGE_VERSION = 106
 

Функции

◆ AddToStomach()

void AddToStomach ( string class_name,
float amount,
int food_stage = 0,
int agents = 0,
float temperature = 0 )
protected
391 {
393 return;
394 bool is_liquid;
395
396 NutritionalProfile profile = Liquid.GetNutritionalProfileByName(class_name);
397 if (profile)
398 {
399 is_liquid = true;
400 }
401 else
402 {
404 }
405
406 if (profile)
407 {
408 // sanity checks start
409 if (amount > ACCEPTABLE_QUANTITY_MAX || amount < 0)
410 {
411 amount = 0;
412 }
414 {
416 }
417 // sanity checks end
418
419 agents = agents | profile.GetAgents();
420 bool found = false;
421 int count = m_StomachContents.Count();
422 float fraction;
423 for(int i = 0; i < count; i++)
424 {
426 if (stomach_item.GetClassName() == class_name && stomach_item.m_Agents == agents)
427 {
428 if (is_liquid || stomach_item.GetFoodStage() == food_stage)
429 {
430 if (amount != 0)
431 fraction = (stomach_item.m_Amount + amount) / amount;
432 else
433 fraction = 1;
434
435 stomach_item.AddTemperature(temperature, fraction);
436 stomach_item.AddAmount(amount);
437 stomach_item.AddAgents(agents); //nutrition profile agents
438 found = true;
439 }
440 }
441 }
442
443 if (!found)
444 {
446 }
447
449 }
450 }
FoodStageType
Definition FoodStage.c:2
class OptionSelectorMultistate extends OptionSelector class_name
const int ACCEPTABLE_QUANTITY_MAX
Definition PlayerStomach.c:127
void UpdateStomachTemperature()
Definition PlayerStomach.c:270
const int ACCEPTABLE_FOODSTAGE_MAX
Definition PlayerStomach.c:128
ref array< ref StomachItem > m_StomachContents
Definition PlayerStomach.c:132
static int GetIDFromClassname(string name)
Definition PlayerStomach.c:202
Definition Edible_Base.c:2
static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname="", int food_stage=0)
Definition Edible_Base.c:434
Definition NutritionalProfile.c:2
Definition EntityAI.c:95
Definition PlayerStomach.c:2

Перекрестные ссылки ACCEPTABLE_FOODSTAGE_MAX, ACCEPTABLE_QUANTITY_MAX, class_name, GetIDFromClassname(), Edible_Base::GetNutritionalProfile(), m_StomachContents и UpdateStomachTemperature().

Используется в OnStoreLoad().

◆ ClearContents()

void ClearContents ( )
protected
159 {
160 m_StomachContents.Clear();
161 m_StomachVolume = 0.0;
163 }
float m_StomachTemperature
Definition PlayerStomach.c:138
float m_StomachVolume
Definition PlayerStomach.c:137

Перекрестные ссылки m_StomachContents, m_StomachTemperature и m_StomachVolume.

◆ DigestAgents()

void DigestAgents ( int agents,
float quantity )
protected
333 {
334 if (!agents)
335 return;
336 agents = agents & (~m_AgentTransferFilter);//filter against the agent filter mask
337 int highest_bit = Math.Log2(agents) + 1;
338 for(int i = 0; i < highest_bit;i++)
339 {
340 int agent = (1 << i)& agents;
341 if (agent)
342 {
343 m_Player.m_AgentPool.DigestAgent(agent, quantity);
344 }
345 }
346 }
PlayerBase m_Player
Definition PlayerStomach.c:136
Definition EnMath.c:7
static proto float Log2(float x)
Returns the binary (base-2) logarithm of x.

Перекрестные ссылки Math::Log2() и m_Player.

Используется в ProcessNutrients().

◆ GetAgentTransferFilter()

int GetAgentTransferFilter ( )
protected
185 {
187 }
int m_AgentTransferFilter
Definition PlayerStomach.c:133

Перекрестные ссылки m_AgentTransferFilter.

◆ GetClassnameFromID()

static string GetClassnameFromID ( int id)
staticprotected
198 {
199 return m_IDsToNames.Get(id);
200 }
static ref map< int, string > m_IDsToNames
Definition PlayerStomach.c:130

Перекрестные ссылки m_IDsToNames.

Используется в OnStoreLoad().

◆ GetDebugObject()

int GetDebugObject ( array< ref Param > object_out)
protected
525 {
526 int count = m_StomachContents.Count();
527 for(int i = 0; i < m_StomachContents.Count();i++)
528 {
529 int id = PlayerStomach.GetIDFromClassname(m_StomachContents.Get(i).m_ClassName);
530 int food_stage = m_StomachContents.Get(i).m_FoodStage;
531 int agents = m_StomachContents.Get(i).m_Agents;
532 float amount = m_StomachContents.Get(i).m_Amount;
533 float temperature = m_StomachContents.Get(i).GetTemperature();
535 object_out.Insert(p5);
536 }
538 object_out.Insert(p1);
540 object_out.Insert(paramTemp);
541 return count;
542
543 }
void PlayerStomach(PlayerBase player)
Definition PlayerStomach.c:142

Перекрестные ссылки m_StomachContents, m_StomachTemperature, m_StomachVolume и PlayerStomach().

◆ GetDigestingType()

int GetDigestingType ( )
protected
266 {
267 return m_DigestingType;
268 }
int m_DigestingType
Definition PlayerStomach.c:135

Перекрестные ссылки m_DigestingType.

◆ GetIDFromClassname()

static int GetIDFromClassname ( string name)
staticprotected
203 {
204 if (!m_NamesToIDs.Contains(name))
205 return -1;
206 return m_NamesToIDs.Get(name);
207 }
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
static ref map< string, int > m_NamesToIDs
Definition PlayerStomach.c:129

Перекрестные ссылки m_NamesToIDs и name.

Используется в AddToStomach().

◆ GetStomachTemperature()

float GetStomachTemperature ( )
protected
154 {
156 }

Перекрестные ссылки m_StomachTemperature.

◆ GetStomachVolume()

float GetStomachVolume ( )
protected
149 {
150 return m_StomachVolume;
151 }

Перекрестные ссылки m_StomachVolume.

Используется в GetVolumeContainingAgent01().

◆ GetStorageVersion()

int GetStorageVersion ( )
protected
256 {
257 return STORAGE_VERSION;
258 }
const int STORAGE_VERSION
Definition PlayerStomach.c:139

Перекрестные ссылки STORAGE_VERSION.

◆ GetVolumeContainingAgent()

float GetVolumeContainingAgent ( eAgents agent)
protected
349 {
350 float amountByAgent = 0.0;
352 {
353 if ((item.m_Agents & agent) == agent)
354 amountByAgent += item.m_Amount;
355 }
356
357 return amountByAgent;
358 }

Перекрестные ссылки m_StomachContents.

Используется в GetVolumeContainingAgent01().

◆ GetVolumeContainingAgent01()

float GetVolumeContainingAgent01 ( eAgents agent)
protected
361 {
362 float amount = GetVolumeContainingAgent(agent);
363
364 if (amount > 0.0)
365 return Math.InverseLerp(0.0, GetStomachVolume(), amount);
366
367 return 0.0;
368 }
float GetStomachVolume()
Definition PlayerStomach.c:148
float GetVolumeContainingAgent(eAgents agent)
Definition PlayerStomach.c:348
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...

Перекрестные ссылки GetStomachVolume(), GetVolumeContainingAgent() и Math::InverseLerp().

◆ InitData()

static bool InitData ( )
staticprotected
210 {
212
213 all_paths.Insert("CfgVehicles");
214 all_paths.Insert("cfgLiquidDefinitions");
215
216 string config_path;
217 string child_name;
218 int scope;
219 string path;
221 for(int i = 0; i < all_paths.Count(); i++)
222 {
223 config_path = all_paths.Get(i);
224 int children_count = GetGame().ConfigGetChildrenCount(config_path);
225
226 for(int x = 0; x < children_count; x++)
227 {
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)
233 {
234 should_check = 0;
235 }
236
237 if (should_check)
238 {
239 bool has_nutrition = GetGame().ConfigIsExisting(path + " Nutrition");
240 bool has_stages = GetGame().ConfigIsExisting(path + " Food");
241
243 {
244 //Print("child name:" + child_name);
245 RegisterItem(child_name, consumable_count);//consumable_count value serves as an unique ID for each item
247 }
248 }
249 }
250 }
251 //Print("consumable_count " + consumable_count);
252 return true;
253 }
Icon x
string path
Definition OptionSelectorMultistate.c:142
static void RegisterItem(string classname, int id)
Definition PlayerStomach.c:189
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition IsBoxCollidingGeometryProxyClasses.c:28
proto native CGame GetGame()
array< string > TStringArray
Definition EnScript.c:685

Перекрестные ссылки GetGame(), path, RegisterItem() и x.

◆ IsDigesting()

bool IsDigesting ( )
protected
261 {
262 return (m_DigestingType != 0);
263 }

Перекрестные ссылки m_DigestingType.

◆ OnStoreLoad()

bool OnStoreLoad ( ParamsReadContext ctx,
int version )
protected
475 {
476 int checksum, count;
477 if (!ctx.Read(checksum))
478 {
479 return false;
480 }
481
482 if (!ctx.Read(count))
483 {
484 return false;
485 }
486 for(int i = 0; i < count; i++)
487 {
489 if (!ctx.Read(value))
490 {
491 return false;
492 }
493 if (!ctx.Read(agents))
494 {
495 return false;
496 }
497 if (!ctx.Read(temperature))
498 {
499 return false;
500 }
501 if (checksum == CHECKSUM)//if checksum matches, add to stomach, otherwise throw the data away but go through the de-serialization to keep the stream intact
502 {
503 int amount = value >> quantity_bit_offset;//isolate amount bits
504 int id_mask = Math.Pow(2, quantity_bit_offset) - 1;
505 int id = (id_mask & value) >> id_bit_offset;//isolate id bits
506 int food_mask = Math.Pow(2, id_bit_offset) - 1;
507 int food_stage = value & food_mask;
508 //Print("LOAD value:" + value);
509 //Print("LOAD id:" + id);
510 //Print("LOAD id_bit_offset:" + id_bit_offset);
511 //Print("LOAD food_stage:" + food_stage);
512 string classname = GetClassnameFromID(id);
514 }
515 }
516 //Print("LOAD checksum:" + checksum);
517 if (checksum != CHECKSUM)
518 {
519 Print("Stomach checksum fail");
520 }
521 return true;
522 }
void AddToStomach(string class_name, float amount, int food_stage=0, int agents=0, float temperature=0)
Definition PlayerStomach.c:390
static int CHECKSUM
Definition PlayerStomach.c:125
const int quantity_bit_offset
Definition PlayerStomach.c:123
static string GetClassnameFromID(int id)
Definition PlayerStomach.c:197
const int id_bit_offset
Definition PlayerStomach.c:124
proto void Print(void var)
Prints content of variable to console/log.
static proto float Pow(float v, float power)
Return power of v ^ power.

Перекрестные ссылки AddToStomach(), CHECKSUM, GetClassnameFromID(), id_bit_offset, Math::Pow(), Print() и quantity_bit_offset.

◆ OnStoreSave()

void OnStoreSave ( ParamsWriteContext ctx)
protected
453 {
454 ctx.Write(PlayerStomach.CHECKSUM);
455 ctx.Write(m_StomachContents.Count());
457 for(int i = 0; i < m_StomachContents.Count();i++)
458 {
460 int id = PlayerStomach.GetIDFromClassname(stomach_item.m_ClassName);
461 //Print("SAVE id:" + id);
462 //Print("SAVE id_bit_offset:" + id_bit_offset);
463
464 int write_result = stomach_item.m_FoodStage | (id << id_bit_offset);
466 ctx.Write(write_result);
467 ctx.Write(stomach_item.m_Agents);
468 ctx.Write((int)stomach_item.GetTemperature());
469 //Print("SAVE write_result:" + write_result);
470 }
471 //Print("SAVE CHECKSUM:" + PlayerStomach.CHECKSUM);
472 }
Param3 int

Перекрестные ссылки id_bit_offset, m_StomachContents, PlayerStomach() и quantity_bit_offset.

◆ PlayerStomach()

void PlayerStomach ( PlayerBase player)
protected
143 {
145 }

Перекрестные ссылки m_Player.

Используется в GetDebugObject(), ManBase::Init(), OnStoreSave(), HungerMdfr::OnTick(), ThirstMdfr::OnTick() и HudDebugWinBase::SetContentValues().

◆ PrintUpdate()

void PrintUpdate ( )
protected
371 {
372 Print("================================");
373 for(int i = 0; i < m_StomachContents.Count(); i++)
374 {
375 string itemname = m_StomachContents.Get(i).m_ClassName;
376 float amount = m_StomachContents.Get(i).GetAmount();
377 int food_stage = m_StomachContents.Get(i).GetFoodStage();
378 int agents = m_StomachContents.Get(i).m_Agents;
379 Print(">");
380 Print("itemname:" + itemname);
381 Print("amount:" + amount);
382 Print("food_stage:" + food_stage);
383 Print("agents:" + agents);
384 Print(">");
385 }
386 Print("m_StomachVolume:" + m_StomachVolume);
387 Print("================================");
388 }

Перекрестные ссылки m_StomachContents, m_StomachVolume и Print().

◆ ProcessNutrients()

void ProcessNutrients ( float delta_time)
protected
295 {
298 m_DigestingType = 0;
299 if (stomach_items_count == 0)
300 return;
301
303 m_StomachVolume = 0;//reset, it's accumulated with each pass
304 for (int i = stomach_items_count - 1; i >= 0; i--)
305 {
308 int agents;
310 {
311 m_StomachContents.Remove(i);
313 }
315 m_Player.GetStatEnergy().Add(energy);
316 m_Player.GetStatWater().Add(water);
317
318 if (energy > 0)
319 {
321 }
322
323 if (water > 0)
324 {
326 }
327
329 }
330 }
const float DIGESTION_POINTS
Definition PlayerStomach.c:126
class StomachItem DIGESTING_WATER
void DigestAgents(int agents, float quantity)
Definition PlayerStomach.c:332
const int DIGESTING_ENERGY
Definition PlayerStomach.c:121

Перекрестные ссылки DigestAgents(), DIGESTING_ENERGY, DIGESTING_WATER, DIGESTION_POINTS, m_DigestingType, m_Player, m_StomachContents, m_StomachVolume и UpdateStomachTemperature().

Используется в Update().

◆ ReduceContents()

void ReduceContents ( float percent)
protected
167 {
168 percent = Math.Clamp(percent, 0, 100);
169 float reduction = percent * 0.01;
170
172 {
173 item.AddAmount( -(item.GetAmount() * reduction) );
174 }
175
177 }
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'.

Перекрестные ссылки Math::Clamp(), m_StomachContents и m_StomachVolume.

◆ RegisterItem()

static void RegisterItem ( string classname,
int id )
staticprotected
190 {
191 int hash = classname.Hash();
192 CHECKSUM = CHECKSUM^hash; //xor hash vs current checksum
193 m_NamesToIDs.Insert(classname, id);
194 m_IDsToNames.Insert(id, classname);
195 }

Перекрестные ссылки CHECKSUM, m_IDsToNames и m_NamesToIDs.

Используется в InitData().

◆ SetAgentTransferFilter()

void SetAgentTransferFilter ( int filter_agents)
protected
180 {
182 }

Перекрестные ссылки m_AgentTransferFilter.

◆ Update()

void Update ( float delta_time)
protected
290 {
292 }
void ProcessNutrients(float delta_time)
Definition PlayerStomach.c:294

Перекрестные ссылки ProcessNutrients().

◆ UpdateStomachTemperature()

void UpdateStomachTemperature ( )
protected
271 {
273
275 if (stomachItemsCount == 0)
276 return;
277
279
280 for (int i = 0; i < stomachItemsCount; i++)
281 {
283 m_StomachTemperature += item.GetTemperature();
284 }
285
287 }

Перекрестные ссылки m_StomachContents и m_StomachTemperature.

Используется в AddToStomach() и ProcessNutrients().

Переменные

◆ ACCEPTABLE_FOODSTAGE_MAX

const int ACCEPTABLE_FOODSTAGE_MAX = FoodStageType.COUNT - 1

Используется в AddToStomach().

◆ ACCEPTABLE_QUANTITY_MAX

const int ACCEPTABLE_QUANTITY_MAX = 32768

Используется в AddToStomach().

◆ CHECKSUM

int CHECKSUM
static

Используется в OnStoreLoad() и RegisterItem().

◆ DIGESTING_ENERGY

const int DIGESTING_ENERGY = 2

Используется в ProcessNutrients().

◆ DIGESTING_WATER

class StomachItem DIGESTING_WATER = 1

Используется в ProcessNutrients().

◆ DIGESTION_POINTS

Используется в ProcessNutrients().

◆ id_bit_offset

const int id_bit_offset = 4

Используется в OnStoreLoad() и OnStoreSave().

◆ m_AgentTransferFilter

int m_AgentTransferFilter

Используется в GetAgentTransferFilter() и SetAgentTransferFilter().

◆ m_Digesting

bool m_Digesting

◆ m_DigestingType

int m_DigestingType

Используется в GetDigestingType(), IsDigesting() и ProcessNutrients().

◆ m_IDsToNames

ref map<int, string> m_IDsToNames = new map<int, string>
static

Используется в GetClassnameFromID() и RegisterItem().

◆ m_InitData

const bool m_InitData = PlayerStomach.InitData()
static

◆ m_NamesToIDs

ref map<string, int> m_NamesToIDs = new map<string, int>
static

Используется в GetIDFromClassname() и RegisterItem().

◆ m_Player

PlayerBase m_Player

◆ m_StomachContents

◆ m_StomachTemperature

float m_StomachTemperature
protected

◆ m_StomachVolume

◆ quantity_bit_offset

const int quantity_bit_offset = 16

Используется в OnStoreLoad() и OnStoreSave().

◆ STORAGE_VERSION

const int STORAGE_VERSION = 106
protected