DayZ 1.24
Loading...
Searching...
No Matches
FoodStage.c
Go to the documentation of this file.
2{
3 NONE = 0, //food stage not define
4 RAW = 1, //default
5 BAKED = 2,
6 BOILED = 3,
7 DRIED = 4,
8 BURNED = 5,
9 ROTTEN = 6,
10
11 COUNT //for net sync purposes
13
14// Used to make getting data more readable
16{
19 MAX_TEMP = 2
20}
21
22class FoodStage
23{
26 protected Edible_Base m_FoodItem;
27
28 protected int m_SelectionIndex; //visual properties
29 protected int m_TextureIndex;
30 protected int m_MaterialIndex;
31
32 protected float m_CookingTime;
33
34 // Lookup and search values
35 // STRINGs are mostly used for CONFIG searches
36 // INTs are mostly used for MAP searches
37 static const string VISUAL_PROPERTIES = "visual_properties";
38 static const string NUTRITION_PROPERTIES = "nutrition_properties";
39 static const string COOKING_PROPERTIES = "cooking_properties";
40 static const int VISUAL_PROPERTIES_HASH = VISUAL_PROPERTIES.Hash();
41 static const int NUTRITION_PROPERTIES_HASH = NUTRITION_PROPERTIES.Hash();
42 static const int COOKING_PROPERTIES_HASH = COOKING_PROPERTIES.Hash();
43
44 // The following will be filled in constructor
45 private static int m_StageRawHash = 0;
46 private static int m_StageBakedHash = 0;
47 private static int m_StageBoiledHash = 0;
48 private static int m_StageDriedHash = 0;
49 private static int m_StageBurnedHash = 0;
50 private static int m_StageRottenHash = 0;
51
52 // Cache food stage data for each Edible_Base
53 // Used to get information for specific Edible_Base
55 // Used to store food stage transitions for every Edible_Base
57 // Used to store the Hashed key of all possible food transitions ( including modded ones )
59
60 //constructor
62 {
63 //default
66
67 //reset cooking time
68 m_CookingTime = 0;
69
71
72 // We fill all FoodStageHash values
73 if (m_StageRawHash == 0)
74 m_StageRawHash = "Raw".Hash();
75 if (m_StageBakedHash == 0)
76 m_StageBakedHash = "Baked".Hash();
77 if (m_StageBoiledHash == 0)
78 m_StageBoiledHash = "Boiled".Hash();
79 if (m_StageDriedHash == 0)
80 m_StageDriedHash = "Dried".Hash();
81 if (m_StageBurnedHash == 0)
82 m_StageBurnedHash = "Burned".Hash();
83 if (m_StageRottenHash == 0)
84 m_StageRottenHash = "Rotten".Hash();
85
86 //get config data for all food stages
88
89 // Get all config data relative to food stage transitions
91
93 }
94
96 {
97 // We ensure we have the map is setup before trying to fill it
100
101 string foodType = m_FoodItem.GetType();
102 int hashedFood = foodType.Hash();
103
104 // We start to fill the map, we don't want duplicates of the same food type
106 {
108
109 for (int i = 1; i < FoodStageType.COUNT; ++i)
110 {
112
113 // Insert visual properties
115 string path = string.Format("CfgVehicles %1 Food FoodStages %2 visual_properties", foodType, GetFoodStageName(i));
116 GetGame().ConfigGetFloatArray(path, visual_properties);
117
119
120 // Insert nutrition properties
122 path = string.Format("CfgVehicles %1 Food FoodStages %2 nutrition_properties", foodType, GetFoodStageName(i));
123 GetGame().ConfigGetFloatArray(path, nutrition_properties);
124
126
127 // Insert cooking properties
129 path = string.Format("CfgVehicles %1 Food FoodStages %2 cooking_properties", foodType, GetFoodStageName(i));
130 GetGame().ConfigGetFloatArray(path, cooking_properties);
131
133
134 // Insert all properties for relevant food stage
136 }
137
139 }
140 }
141
143 {
144 // We ensure we have only one map and that it does exist
147
148 // We ensure we have our key array setup
151
152 string foodType = m_FoodItem.GetType();
153 int hashedFood = foodType.Hash();
154
155 // We start to fill the map, we don't want duplicates of the same food type
157 {
159
160 for (int i = 1; i < FoodStageType.COUNT; ++i)
161 {
163 string config_path = string.Format("CfgVehicles %1 Food FoodStageTransitions %2", foodType, GetFoodStageName(i));
164
165 for (int j = 0; j < GetGame().ConfigGetChildrenCount(config_path); ++j)
166 {
168 string classCheck; // Used to get any existing transition class
169 GetGame().ConfigGetChildName(config_path, j, classCheck);
170
171 string transition_path = string.Format("%1 %2", config_path, classCheck);
172 if (GetGame().ConfigIsExisting(transition_path))
173 {
174 int transitionClassHash = classCheck.Hash();
175 stageTransition.Insert(GetGame().ConfigGetInt(string.Format("%1 transition_to", transition_path)));
176 stageTransition.Insert(GetGame().ConfigGetInt(string.Format("%1 cooking_method", transition_path)));
178
179 // We only want one entry per key
182 }
183 }
184
186 }
187
189 }
190 }
191
192 //Food Stage Type
194 {
195 return m_FoodStageType;
196 }
197
199 {
201 }
202
203 //Selection index
204 int GetSelectionIndex()
205 {
206 return m_SelectionIndex;
207 }
208 void SetSelectionIndex(int index)
209 {
211 }
212
213 //Texture index
214 int GetTextureIndex()
215 {
216 return m_TextureIndex;
217 }
218 void SetTextureIndex(int index)
219 {
221 }
222
223 //Material index
224 int GetMaterialIndex()
225 {
226 return m_MaterialIndex;
227 }
228 void SetMaterialIndex(int index)
229 {
230 m_MaterialIndex = index;
231 }
232
233 //Food properties
234 protected static float GetNutritionPropertyFromIndex(int index, FoodStageType stage_type, FoodStage stage, string classname)
235 {
236 if (stage)
237 {
238 stage_type = stage.m_FoodStageType;
239 classname = stage.GetFoodItem().GetType();
240 }
241
244
246
249
251 return 0;
253 return 0;
255 return 0;
256
257 if (nutrition_properties.Count() > 0)
258 {
259 if (index > (nutrition_properties.Count() - 1))
260 return 0;
261 else
262 return nutrition_properties.Get(index);
263 }
264 //calculate nutrition properties from base stage and nutrition modifiers
265 else
266 {
267 // Will not attempt to optimize this as it is for a setup we do not support internally
268 //get modifiers class for nutrition values
269 string config_path = string.Format("CfgVehicles %1 Food nutrition_modifiers_class", classname);
270
271 if (GetGame().ConfigIsExisting(config_path))
272 {
273 string nutr_mod_class;
274 GetGame().ConfigGetText(config_path, nutr_mod_class);
275
276 config_path = string.Format("CfgVehicles NutritionModifiers %1 base_stage", nutr_mod_class);
277 string nutr_base_stage;
278 GetGame().ConfigGetText(config_path, nutr_base_stage);
279
280 //get nutrition values for food stage and modifiers
281 config_path = string.Format("CfgVehicles %1 Food FoodStages %2 nutrition_properties", classname, nutr_base_stage);
283 GetGame().ConfigGetFloatArray(config_path, base_nutr_properties);
284
285 config_path = string.Format("CfgVehicles NutritionModifiers %1 %2 nutrition_properties", nutr_mod_class, food_stage_name);
287 GetGame().ConfigGetFloatArray(config_path, nutr_mod_properties);
288
289 //base nutrition * food stage nutrition modifier
290 if (base_nutr_properties.Count() > 0 && nutr_mod_properties.Count() > 0)
292 }
293 }
294
295 return 0;
296 }
297
298 static float GetFullnessIndex(FoodStage stage, int stage_type = -1, string classname = "")
299 {
301 }
302
303 static float GetEnergy(FoodStage stage, int stage_type = -1, string classname = "")
304 {
306 }
307
308 static float GetWater(FoodStage stage, int stage_type = -1, string classname = "")
309 {
311 }
312
313 static float GetNutritionalIndex(FoodStage stage, int stage_type = -1, string classname = "")
314 {
316 }
317
318 static float GetToxicity(FoodStage stage, int stage_type = -1, string classname = "")
319 {
321 }
322
323 static int GetAgents(FoodStage stage, int stage_type = -1, string classname = "")
324 {
326 }
327
328 static float GetDigestibility(FoodStage stage, int stage_type = -1, string classname = "")
329 {
331 }
332
333 //Food item
334 protected Edible_Base GetFoodItem()
335 {
336 return m_FoodItem;
337 }
338
339 //Cooking time
340 float GetCookingTime()
341 {
342 return m_CookingTime;
343 }
344 void SetCookingTime(float time)
345 {
347 }
348
350 {
351 if (stage)
352 {
353 stage_type = stage.m_FoodStageType;
354 classname = stage.GetFoodItem().GetType();
355 }
356
359
361
364
367
369
370 if (cooking_properties.Count() > 0)
371 {
372 if (index > (cooking_properties.Count() - 1))
373 return -1;
374 else
375 return cooking_properties.Get(index);
376 }
377 return 0;
378 }
379
381 {
382 if (stage)
383 {
384 stage_type = stage.m_FoodStageType;
385 classname = stage.GetFoodItem().GetType();
386 }
387
390
392
395
398
400
401 if (cooking_properties.Count() > 0)
402 return cooking_properties;
403 return null;
404 }
405
406 //********************************************/
407 // FOOD STAGE CHANGE
408 //********************************************/
409 //Checks if food stage can be changed to another stage
411 {
413 return false;
414
415 return true;
416 }
417
418 //returns possible food stage type according to given cooking method
420 {
422
425
428
429 // We go through the key array, checking every possible transition
430 for (int i = 0; i < m_FoodStageTransitionKeys.Count(); ++i)
431 {
432 // We test if a given transition is setup on this item
434 if (food_transition)
435 {
436 // We now check if the given transition class is relevant
437 if (food_transition.Get(1) == cooking_method)
438 return food_transition.Get(0);
439 }
440 }
441
442 return FoodStageType.BURNED; //If the item cannot transition out of current state, burn it
443 }
444
446 {
449
450 //merge stages
451 //food stage type
453
455
459
460 if (visual_properties.Count() > 0)
461 {
462 //selection index
463 int index = visual_properties.Get(0);
464 if (index >= 0)
466 //texture index
467 index = visual_properties.Get(1);
468 if (index >= 0)
470 //material index
471 index = visual_properties.Get(2);
472 if (index >= 0)
473 SetMaterialIndex(index);
474 }
475
476 //refresh visual
477 GetFoodItem().Synchronize();
478 }
479
480 void UpdateVisuals()
481 {
482 //if item has food stages
484 {
486
487 array<string> config_selections = food_item.GetHiddenSelections();
488 array<string> config_textures = food_item.GetHiddenSelectionsTextures();
489 array<string> config_materials = food_item.GetHiddenSelectionsMaterials();
490
491 //selection index
492 int selection_index;
493 if (GetSelectionIndex() >= 0 && config_selections.Count() > GetSelectionIndex())
494 selection_index = GetSelectionIndex();
495
496 //texture index
497 int texture_index;
498 if (GetTextureIndex() >= 0 && config_textures.Count() > GetTextureIndex())
500
501 //material index
502 int material_index;
503 if (GetMaterialIndex() >= 0 && config_materials.Count() > GetMaterialIndex())
505
506 //hide all selection except the configured one
507 for (int i = 0; i < config_selections.Count(); i++)
508 {
510 food_item.SetAnimationPhase(config_selections.Get(i), 1);
511 }
512
513 //Debug
514 //Print( "item = " + food_item.GetType() + " selection index = " + GetSelectionIndex().ToString() + " texture index = " + GetTextureIndex().ToString() );
515
516 //show selection
517 food_item.SetAnimationPhase(config_selections.Get(selection_index), 0);
518 //set texture
520 //set materials
522 }
523
525 }
526
527 //Food States
528 //check food stages
530 {
532 return true;
533
534 return false;
535 }
536
537 bool IsFoodRaw()
538 {
539 return IsFoodInStage(FoodStageType.RAW);
540 }
541
542 bool IsFoodBaked()
543 {
544 return IsFoodInStage(FoodStageType.BAKED);
545 }
546
547 bool IsFoodBoiled()
548 {
549 return IsFoodInStage(FoodStageType.BOILED);
550 }
551
552 bool IsFoodDried()
553 {
554 return IsFoodInStage(FoodStageType.DRIED);
555 }
556
557 bool IsFoodBurned()
558 {
559 return IsFoodInStage(FoodStageType.BURNED);
560 }
561
562 bool IsFoodRotten()
563 {
564 return IsFoodInStage(FoodStageType.ROTTEN);
565 }
566
567 //get name of food stage type
569 {
570 switch (food_stage_type)
571 {
572 case FoodStageType.RAW: return "Raw";
573 case FoodStageType.BAKED: return "Baked";
574 case FoodStageType.BOILED: return "Boiled";
575 case FoodStageType.DRIED: return "Dried";
576 case FoodStageType.BURNED: return "Burned";
577 case FoodStageType.ROTTEN: return "Rotten";
578 }
579
580 return "Raw";
581 }
582
583 // Get hashed name of food stage type for quicker access
585 {
586 switch (food_stage_type)
587 {
588 case FoodStageType.RAW: return m_StageRawHash;
589 case FoodStageType.BAKED: return m_StageBakedHash;
590 case FoodStageType.BOILED: return m_StageBoiledHash;
591 case FoodStageType.DRIED: return m_StageDriedHash;
592 case FoodStageType.BURNED: return m_StageBurnedHash;
593 case FoodStageType.ROTTEN: return m_StageRottenHash;
594 }
595
596 return m_StageRawHash;
597 }
598
599 //================================================================
600 // SERIALIZATION
601 //================================================================
603 {
604 //Food stage type
605 ctx.Write(m_FoodStageType);
606
607 //Selection index
608 ctx.Write(m_SelectionIndex);
609
610 //Texture index
611 ctx.Write(m_TextureIndex);
612
613 //Material index
614 ctx.Write(m_MaterialIndex);
615 }
616
617 bool OnStoreLoad(ParamsReadContext ctx, int version)
618 {
619 //Food stage type
620 if (!ctx.Read(m_FoodStageType))
621 {
622 m_FoodStageType = FoodStageType.RAW; //set default
623 return false;
624 }
625
626 //Selection index
627 if (!ctx.Read(m_SelectionIndex))
628 {
629 m_SelectionIndex = 0; //set default
630 return false;
631 }
632
633 //Texture index
634 if (!ctx.Read(m_TextureIndex))
635 {
636 m_TextureIndex = 0; //set default
637 return false;
638 }
639
640 //Material index
641 if (!ctx.Read(m_MaterialIndex))
642 {
643 m_MaterialIndex = 0; //set default
644 return false;
645 }
646
647 return true;
648 }
649}
eBleedingSourceType GetType()
void UpdateVisuals()
CookingMethodType
Definition Cooking.c:2
bool IsFoodRotten()
bool IsFoodBaked()
bool CanChangeToNewStage(CookingMethodType cooking_method)
FoodStageType GetNextFoodStageType(CookingMethodType cooking_method)
void ChangeFoodStage(FoodStageType new_food_stage_type)
float GetCookingTime()
string GetFoodStageName(FoodStageType food_stage_type)
void SetCookingTime(float time)
FoodStageType GetFoodStageType()
bool IsFoodDried()
bool IsFoodRaw()
bool IsFoodBurned()
bool IsFoodBoiled()
enum FoodStageType MIN_TEMP
FoodStageType
Definition FoodStage.c:2
@ COUNT
Definition FoodStage.c:11
@ ROTTEN
Definition FoodStage.c:9
@ BOILED
Definition FoodStage.c:6
@ BAKED
Definition FoodStage.c:5
@ BURNED
Definition FoodStage.c:8
@ RAW
Definition FoodStage.c:4
@ NONE
Definition FoodStage.c:3
@ DRIED
Definition FoodStage.c:7
enum FoodStageType COOK_TIME
float GetEnergy()
Definition ItemBase.c:8140
override int GetAgents()
Definition ItemBase.c:8554
bool HasFoodStage()
Definition ItemBase.c:7038
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.