DayZ 1.24
Loading...
Searching...
No Matches
Edible_Base.c
Go to the documentation of this file.
2{
3 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
4
5 const string SOUND_BAKING_START = "Baking_SoundSet";
6 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
7 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
8
9 protected bool m_MakeCookingSounds;
12 protected string m_SoundPlaying;
14 protected float m_DecayTimer;
15 protected float m_DecayDelta = 0.0;
17
19
21 {
22 if (HasFoodStage())
23 {
24 m_FoodStage = new FoodStage(this);
25
26 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
27 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
28 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
29 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
30 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
31
32 m_SoundPlaying = "";
34 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
35 RegisterNetSyncVariableBool("m_MakeCookingSounds");
36 }
37 }
38
39 override void EEInit()
40 {
41 super.EEInit();
42
44 }
45
46 override void EEDelete(EntityAI parent)
47 {
48 super.EEDelete(parent);
49
51 }
52
54 {
55 super.EEItemLocationChanged(oldLoc, newLoc);
56
58 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
59 {
60 switch (oldLoc.GetParent().GetType())
61 {
62 case "FryingPan":
63 case "Pot":
64 case "Cauldron":
65 case "SharpWoodenStick":
66 MakeSoundsOnClient(false);
67 break;
68 }
69
71 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
72 MakeSoundsOnClient(false);
73 }
74 }
75
77 {
78 if (GetFoodStage())
79 GetFoodStage().UpdateVisuals();
80 }
81
82 bool Consume(float amount, PlayerBase consumer)
83 {
84 AddQuantity(-amount, false, false);
85 OnConsume(amount, consumer);
86
87 return true;
88 }
89
90 void OnConsume(float amount, PlayerBase consumer);
91
92 //food staging
93 override bool CanBeCooked()
94 {
95 return false;
96 }
97
98 override bool CanBeCookedOnStick()
99 {
100 return false;
101 }
102
103 //================================================================
104 // SYNCHRONIZATION
105 //================================================================
107 {
108 SetSynchDirty();
109
110 if (GetGame().IsMultiplayer())
112 }
113
115 {
116 super.OnVariablesSynchronized();
117
119
120 //update audio
122 RefreshAudio();
123 else
124 RemoveAudio();
125 }
126
127 //================================================================
128 // AUDIO EFFECTS (WHEN ON DCS)
129 //================================================================
137
138 protected void RefreshAudio()
139 {
140 string soundName = "";
141
143
144 switch (GetFoodStageType())
145 {
146 case FoodStageType.RAW:
148 if (nextFoodState == FoodStageType.BOILED)
149 soundName = "";
150 break;
151 case FoodStageType.BAKED:
153 break;
154 case FoodStageType.BURNED:
156 break;
157 default:
158 soundName = "";
159 break;
160 }
161
163 }
164
165 protected void RemoveAudio()
166 {
167 m_MakeCookingSounds = false;
169 }
170
171 //================================================================
172 // SERIALIZATION
173 //================================================================
175 {
176 super.OnStoreSave(ctx);
177
178 if (GetFoodStage())
179 GetFoodStage().OnStoreSave(ctx);
180
181 // food decay
182 ctx.Write(m_DecayTimer);
183 ctx.Write(m_LastDecayStage);
184 }
185
186 override bool OnStoreLoad(ParamsReadContext ctx, int version)
187 {
188 if (!super.OnStoreLoad(ctx, version))
189 return false;
190
191 if (GetFoodStage())
192 {
193 if (!GetFoodStage().OnStoreLoad(ctx, version))
194 return false;
195 }
196
197 if (version >= 115)
198 {
199 if (!ctx.Read(m_DecayTimer))
200 {
201 m_DecayTimer = 0.0;
202 return false;
203 }
204 if (!ctx.Read(m_LastDecayStage))
205 {
207 return false;
208 }
209 }
210
211 return true;
212 }
213
214 override void AfterStoreLoad()
215 {
216 super.AfterStoreLoad();
217
218 Synchronize();
219 }
220
221 //get food stage
223 {
224 return m_FoodStage;
225 }
226
227 //food types
228 override bool IsMeat()
229 {
230 return false;
231 }
232
233 override bool IsCorpse()
234 {
235 return false;
236 }
237
238 override bool IsFruit()
239 {
240 return false;
241 }
242
243 override bool IsMushroom()
244 {
245 return false;
246 }
247
248 //================================================================
249 // NUTRITIONAL VALUES
250 //================================================================
251 //food properties
252 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
253 {
255 if (food_item && food_item.GetFoodStage())
256 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
257 else if (classname != "" && food_stage)
258 return FoodStage.GetFullnessIndex(null, food_stage, classname);
259 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
260 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
261
262 }
263
264 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
265 {
267 if (food_item && food_item.GetFoodStage())
268 return FoodStage.GetEnergy(food_item.GetFoodStage());
269 else if (classname != "" && food_stage)
270 return FoodStage.GetEnergy(null, food_stage, classname);
271 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
272 return GetGame().ConfigGetFloat(class_path + " energy");
273 }
274
275 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
276 {
278 if (food_item && food_item.GetFoodStage())
279 return FoodStage.GetWater(food_item.GetFoodStage());
280 else if (classname != "" && food_stage)
281 return FoodStage.GetWater(null, food_stage, classname);
282 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
283 return GetGame().ConfigGetFloat(class_path + " water");
284 }
285
286 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
287 {
289 if (food_item && food_item.GetFoodStage())
290 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
291 else if (classname != "" && food_stage)
292 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
293 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
294 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
295
296 }
297
298 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
299 {
301 if (food_item && food_item.GetFoodStage())
302 return FoodStage.GetToxicity(food_item.GetFoodStage());
303 else if (classname != "" && food_stage)
304 return FoodStage.GetToxicity(null, food_stage, classname);
305 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
306 return GetGame().ConfigGetFloat(class_path + " toxicity");
307 }
308
309 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
310 {
312 if (food_item && food_item.GetFoodStage())
313 return FoodStage.GetAgents(food_item.GetFoodStage());
314 else if (classname != "" && food_stage)
315 return FoodStage.GetAgents(null, food_stage, classname);
316 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
317 return GetGame().ConfigGetInt(class_path + " agents");
318 }
319
320 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
321 {
323 if (food_item && food_item.GetFoodStage())
324 return FoodStage.GetDigestibility(food_item.GetFoodStage());
325 else if (classname != "" && food_stage)
326 return FoodStage.GetDigestibility(null, food_stage, classname);
327 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
328 return GetGame().ConfigGetInt(class_path + " digestibility");
329 }
330
335
336 //================================================================
337 // FOOD STAGING
338 //================================================================
340 {
341 return GetFoodStage().GetFoodStageType();
342 }
343
344 //food stage states
346 {
347 if (GetFoodStage())
348 return GetFoodStage().IsFoodRaw();
349
350 return false;
351 }
352
354 {
355 if (GetFoodStage())
356 return GetFoodStage().IsFoodBaked();
357
358 return false;
359 }
360
362 {
363 if (GetFoodStage())
364 return GetFoodStage().IsFoodBoiled();
365
366 return false;
367 }
368
370 {
371 if (GetFoodStage())
372 return GetFoodStage().IsFoodDried();
373
374 return false;
375 }
376
378 {
379 if (GetFoodStage())
380 return GetFoodStage().IsFoodBurned();
381
382 return false;
383 }
384
386 {
387 if (GetFoodStage())
388 return GetFoodStage().IsFoodRotten();
389
390 return false;
391 }
392
393 //food stage change
398
403
405 {
406 return GetFoodStage().GetFoodStageName(food_stage_type);
407 }
408
410 {
411 return GetFoodStage().CanChangeToNewStage(cooking_method);
412 }
413
414 //Use this to receive food stage from another Edible_Base
416 {
417 if (!source.HasFoodStage())
418 return;
419 m_LastDecayStage = source.GetLastDecayStage();
420 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
421 m_DecayTimer = source.GetDecayTimer();
422 m_DecayDelta = source.GetDecayDelta();
423 }
424
425 //================================================================
426 // COOKING
427 //================================================================
428 //cooking time
430 {
431 return GetFoodStage().GetCookingTime();
432 }
433
435 {
436 GetFoodStage().SetCookingTime(time);
437
438 //synchronize when calling on server
439 Synchronize();
440 }
441
442 //replace edible with new item (opening cans)
444 {
445 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
446 if (player)
447 {
449 player.ServerReplaceItemInHandsWithNew(lambda);
450 }
451 else
452 Error("ReplaceEdibleWithNew - cannot use edible without player");
453 }
454
455 override void SetActions()
456 {
457 super.SetActions();
458
459 AddAction(ActionAttach);
461 }
462
463 protected void SoundCookingStart(string sound_name)
464 {
465#ifndef SERVER
467 {
469
472 }
473#endif
474 }
475
476 protected void SoundCookingStop()
477 {
478#ifndef SERVER
480 {
483 m_SoundPlaying = "";
484 }
485#endif
486 }
487
488 override bool CanHaveTemperature()
489 {
490 return true;
491 }
492
493 override bool CanDecay()
494 {
495 return false;
496 }
497
498 override bool CanProcessDecay()
499 {
500 return (GetFoodStageType() != FoodStageType.ROTTEN);
501 }
502
503 override void ProcessDecay(float delta, bool hasRootAsPlayer)
504 {
505 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
506 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
507 if (hasRootAsPlayer)
509
510 /*Print( "-------------------------" );
511 Print( this );
512 Print( m_DecayTimer );
513 Print( m_DecayDelta );
514 Print( m_LastDecayStage );*/
515
516 if (IsFruit() || IsMushroom())
517 {
518 // fruit, vegetables and mushrooms
520 {
521 switch (GetFoodStageType())
522 {
523 case FoodStageType.RAW:
526 break;
527
528 case FoodStageType.BOILED:
531 break;
532
533 case FoodStageType.BAKED:
536 break;
537
538 case FoodStageType.DRIED:
539 case FoodStageType.BURNED:
540 case FoodStageType.ROTTEN:
541 default:
542 m_DecayTimer = -1;
544 return;
545 }
546
547 //m_DecayTimer = m_DecayTimer / 1000.0;
548 }
549
551
552 if (m_DecayTimer <= 0)
553 {
555 {
556 // switch to decayed stage
557 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
560 {
561 int rng = Math.RandomIntInclusive(0, 100);
564 else
565 {
568 else
570 }
571 }
572 }
573 }
574
575 }
576 else if (IsMeat())
577 {
578 // meat
580 {
581 switch (GetFoodStageType())
582 {
583 case FoodStageType.RAW:
586 break;
587
588 case FoodStageType.BOILED:
591 break;
592
593 case FoodStageType.BAKED:
596 break;
597
598 case FoodStageType.DRIED:
601 break;
602
603 case FoodStageType.BURNED:
604 case FoodStageType.ROTTEN:
605 default:
606 m_DecayTimer = -1;
608 return;
609 }
610 }
611
613
614 if (m_DecayTimer <= 0)
615 {
617 {
618 // switch to decayed stage
621 }
622 }
623 }
624 else if (IsCorpse())
625 {
626 // corpse
628 {
629 switch (GetFoodStageType())
630 {
631 case FoodStageType.RAW:
634 break;
635
636 case FoodStageType.BURNED:
637 case FoodStageType.ROTTEN:
638 default:
639 m_DecayTimer = -1;
641 return;
642 }
643 }
644
646
647 if (m_DecayTimer <= 0)
648 {
650 {
651 // switch to decayed stage
654 }
655 }
656 }
657 else
658 {
659 // opened cans
661
662 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
663 {
666 //m_DecayTimer = m_DecayTimer / 1000.0;
667 }
668 else
669 {
670 if (m_DecayTimer <= 0)
671 {
672 InsertAgent(eAgents.FOOD_POISON, 1);
673 m_DecayTimer = -1;
674 }
675 }
676 }
677
678 m_DecayDelta = 0.0;
679 }
680
682 {
683 super.GetDebugActions(outputList);
684
685 if (HasFoodStage())
686 {
687 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
688 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
689 }
690 }
691
693 {
694 super.OnAction(action_id, player, ctx);
695
696 if (GetGame().IsServer())
697 {
698 if (action_id == EActions.FOOD_STAGE_PREV)
699 {
701 if (food_stage_prev <= 0)
702 food_stage_prev = FoodStageType.COUNT - 1;
704 return true;
705 }
706 else if (action_id == EActions.FOOD_STAGE_NEXT)
707 {
709 if (food_stage_next >= FoodStageType.COUNT)
712 return true;
713 }
714 }
715 return false;
716 }
717
718 override string GetDebugText()
719 {
720 string debug_output;
721
722 debug_output = super.GetDebugText();
723
724 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
725 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
726
727 return debug_output;
728 }
729
730 //================================================================
731 // GENERAL GETTERS
732 //================================================================
733
735 {
736 return m_DecayTimer;
737 }
738
740 {
741 return m_DecayDelta;
742 }
743
748}
749
751{
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
void ActionDetach()
void AddAction(typename actionName)
CookingMethodType
Definition Cooking.c:2
EActions
Definition EActions.c:2
eAgents
Definition EAgents.c:3
Edible_Base ItemBase ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player)
FoodStageType
Definition FoodStage.c:2
InventoryLocationType
types of Inventory Location
override void InsertAgent(int agent, float count=1)
Definition ItemBase.c:8539
bool AddQuantity(float value, bool destroy_config=true, bool destroy_forced=false)
add item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity re...
Definition ItemBase.c:7900
bool HasFoodStage()
Definition ItemBase.c:7038
class JsonUndergroundAreaTriggerData GetPosition
override void OnStoreSave(ParamsWriteContext ctx)
void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod=CookingMethodType.NONE)
bool IsFoodRaw()
void Synchronize()
FoodStageType GetFoodStageType()
string m_SoundPlaying
Definition Edible_Base.c:12
void OnConsume(float amount, PlayerBase consumer)
float m_DecayDelta
Definition Edible_Base.c:15
void Edible_Base()
Definition Edible_Base.c:20
override bool CanBeCookedOnStick()
Definition Edible_Base.c:98
override string GetDebugText()
EffectSound m_SoundEffectCooking
DEPRECATED.
Definition Edible_Base.c:11
float GetDecayDelta()
bool m_MakeCookingSounds
Definition Edible_Base.c:9
FoodStageType GetNextFoodStageType(CookingMethodType cooking_method)
bool IsFoodBoiled()
const string SOUND_BAKING_DONE
Definition Edible_Base.c:6
override bool IsMushroom()
override void OnVariablesSynchronized()
override bool IsFruit()
float GetDecayTimer()
void SoundCookingStart(string sound_name)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
override bool IsCorpse()
bool Consume(float amount, PlayerBase consumer)
Definition Edible_Base.c:82
override bool CanDecay()
const string SOUND_BAKING_START
Definition Edible_Base.c:5
static float GetFoodTotalVolume(ItemBase item, string classname="", int food_stage=0)
string GetFoodStageName(FoodStageType food_stage_type)
void SoundCookingStop()
static float GetFoodEnergy(ItemBase item, string classname="", int food_stage=0)
override bool IsMeat()
float GetCookingTime()
CookingMethodType m_CookedByMethod
Definition Edible_Base.c:18
void UpdateVisuals()
Definition Edible_Base.c:76
void SetCookingTime(float time)
static float GetFoodDigestibility(ItemBase item, string classname="", int food_stage=0)
void RefreshAudio()
override void ProcessDecay(float delta, bool hasRootAsPlayer)
override bool CanBeCooked()
Definition Edible_Base.c:93
FoodStageType GetLastDecayStage()
override void SetActions()
override bool CanHaveTemperature()
SoundOnVehicle m_SoundCooking
Definition Edible_Base.c:10
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
Definition Edible_Base.c:53
const string SOUND_BURNING_DONE
Definition Edible_Base.c:7
float m_DecayTimer
Definition Edible_Base.c:14
static float GetFoodToxicity(ItemBase item, string classname="", int food_stage=0)
static float GetFoodNutritionalIndex(ItemBase item, string classname="", int food_stage=0)
override void EEDelete(EntityAI parent)
Definition Edible_Base.c:46
static int GetFoodAgents(ItemBase item, string classname="", int food_stage=0)
override bool CanProcessDecay()
bool IsFoodRotten()
void ChangeFoodStage(FoodStageType new_food_stage_type)
void RemoveAudio()
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
bool IsFoodBaked()
override void EEInit()
Definition Edible_Base.c:39
bool CanChangeToNewStage(CookingMethodType cooking_method)
ref FoodStage m_FoodStage
Definition Edible_Base.c:13
FoodStageType m_LastDecayStage
Definition Edible_Base.c:16
override void AfterStoreLoad()
bool IsFoodDried()
void ReplaceEdibleWithNew(string typeName)
static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname="", int food_stage=0)
const string DIRECT_COOKING_SLOT_NAME
Definition Edible_Base.c:3
static float GetFoodWater(ItemBase item, string classname="", int food_stage=0)
bool IsFoodBurned()
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
void TransferFoodStage(notnull Edible_Base source)
FoodStage GetFoodStage()
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override void Stop()
Stops sound.
InventoryLocation.
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
Definition EnMath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const float DECAY_FOOD_BAKED_FRVG
Definition constants.c:894
const float DECAY_FOOD_CAN_OPEN
Definition constants.c:896
const float DECAY_FOOD_RAW_FRVG
Definition constants.c:890
const int DECAY_TIMER_RANDOM_PERCENTAGE
Definition constants.c:898
const int DECAY_FOOD_FRVG_DRIED_CHANCE
Definition constants.c:897
const float DECAY_FOOD_RAW_MEAT
Definition constants.c:888
const float DECAY_FOOD_BAKED_MEAT
Definition constants.c:893
const float DECAY_FOOD_BOILED_MEAT
Definition constants.c:891
const float DECAY_FOOD_BOILED_FRVG
Definition constants.c:892
const float DECAY_FOOD_DRIED_MEAT
Definition constants.c:895
const float DECAY_FOOD_RAW_CORPSE
Definition constants.c:889
const float DECAY_RATE_ON_PLAYER
Definition constants.c:899
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
const int SAT_DEBUG_ACTION
Definition constants.c:424