DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Cooking.c
Go to the documentation of this file.
2{
3 NONE = 0, //no cooking method available
4 BAKING = 1,
5 BOILING = 2,
6 DRYING = 3,
7 TIME = 4,
8
11
12class Cooking
13{
14 static const float TIME_WITH_SUPPORT_MATERIAL_COEF = 1.0;
15 static const float TIME_WITHOUT_SUPPORT_MATERIAL_COEF = 2.0;
16
17 static const float COOKING_FOOD_TIME_INC_VALUE = 2;
18 static const float COOKING_LARD_DECREASE_COEF = 25;
21
22 static const float DEFAULT_COOKING_TEMPERATURE = 150; //default temperature for cooking (e.g. cooking on stick)
23 static const float FOOD_MAX_COOKING_TEMPERATURE = 150; //
24 static const float PARAM_BURN_DAMAGE_COEF = 0.05; //value for calculating damage on items located in fireplace CargoGrid
25
26 static const float LIQUID_BOILING_POINT = 150; //boiling point for liquids
27 static const float LIQUID_VAPOR_QUANTITY = 2; //vapor quantity
28
29 typename COOKING_EQUIPMENT_POT = Pot;
30 typename COOKING_EQUIPMENT_FRYINGPAN = FryingPan;
31 typename COOKING_EQUIPMENT_CAULDRON = Cauldron;
32 typename COOKING_INGREDIENT_LARD = Lard;
33
34 void ProcessItemToCook(notnull ItemBase pItem, ItemBase cookingEquip, Param2<CookingMethodType, float> pCookingMethod, out Param2<bool, bool> pStateFlags)
35 {
36 Edible_Base item_to_cook = Edible_Base.Cast(pItem);
37
39 pStateFlags = new Param2<bool, bool>(false, false);
40
41 if (item_to_cook && item_to_cook.CanBeCooked())
42 {
44 item_to_cook.MakeSoundsOnClient(true);
45
47 UpdateCookingState(item_to_cook, pCookingMethod.param1, cookingEquip, pCookingMethod.param2);
48
49 //check for done state for boiling and drying
50 if (item_to_cook.IsFoodBoiled() || item_to_cook.IsFoodDried())
51 {
52 pStateFlags.param1 = true;
53 }
55 else if (item_to_cook.IsFoodBaked() && item_to_cook.Type() != Lard)
56 {
57 pStateFlags.param1 = true;
58 }
60 else if (item_to_cook.IsFoodBurned())
61 {
62 pStateFlags.param2 = true;
63 }
64 }
65 else
66 {
67 //damage item
68 pItem.DecreaseHealth("", "", PARAM_BURN_DAMAGE_COEF * 100);
69
70 //add temperature to item
71 AddTemperatureToItem(pItem, null, 0);
72 }
73 }
74
75 //COOKING PROCESS
76 //--- Cooking with equipment (pot)
77 //Returns 1 if the item changed its cooking stage, 0 if not
78 int CookWithEquipment(ItemBase cooking_equipment, float cooking_time_coef = 1)
79 {
80 bool is_empty;
81
82 //check cooking conditions
83 if (cooking_equipment == null)
84 {
85 return 0;
86 }
87
88 if (cooking_equipment.IsRuined())
89 {
90 return 0;
91 }
92
93 //manage items in cooking equipment
94 Param2<bool, bool> stateFlags = new Param2<bool, bool>(false, false); // 1st - done; 2nd - burned
95 Param2<CookingMethodType, float> cookingMethodWithTime = GetCookingMethodWithTimeOverride(cooking_equipment);
96
98 if (cooking_time_coef != 1)
99 {
100 cookingMethodWithTime.param2 = cooking_time_coef;
101 }
102
103 CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
104 if (cargo)
105 {
106 is_empty = cargo.GetItemCount() == 0;
107
108 //process items
109 for (int i = 0; i < cargo.GetItemCount(); i++)
110 {
111 ProcessItemToCook(ItemBase.Cast(cargo.GetItem(i)), cooking_equipment, cookingMethodWithTime, stateFlags);
112 }
113 }
114 else
115 {
116 ProcessItemToCook(cooking_equipment, cooking_equipment, cookingMethodWithTime, stateFlags);
117 }
118
119 //manage cooking equipment
120 Bottle_Base bottle_base = Bottle_Base.Cast(cooking_equipment);
121 if ( bottle_base )
122 {
123 float cooking_equipment_temp = cooking_equipment.GetTemperature();
124 bool is_water_boiling;
125
126 //handle water boiling
127 if (cooking_equipment_temp >= LIQUID_BOILING_POINT)
128 {
129 //remove agents
130 cooking_equipment.RemoveAllAgents();
131
132 if (cooking_equipment.GetQuantity() > 0)
133 {
134 is_water_boiling = true;
135
136 //vaporize liquid
137 cooking_equipment.AddQuantity(-LIQUID_VAPOR_QUANTITY);
138 };
139 }
140
141 //handle audio visuals
142 bottle_base.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
143 }
144
145 FryingPan frying_pan = FryingPan.Cast(cooking_equipment);
146 if (frying_pan && !bottle_base)
147 {
148 //handle audio visuals
149 frying_pan.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
150 }
151
152 return 1;
153 }
154
155 //Returns 1 if the item changed its cooking stage, 0 if not
156 int CookOnStick( Edible_Base item_to_cook, float cook_time_inc )
157 {
158 if ( item_to_cook && item_to_cook.CanBeCookedOnStick() )
159 {
160 //update food
161 return UpdateCookingStateOnStick( item_to_cook, cook_time_inc );
162 }
163
164 return 0;
165 }
166
167 //Returns 1 if the item changed its cooking stage, 0 if not
168 protected int UpdateCookingState(Edible_Base item_to_cook, CookingMethodType cooking_method, ItemBase cooking_equipment, float cooking_time_coef)
169 {
170 //food properties
171 float food_temperature = item_to_cook.GetTemperature();
172
173 //{min_temperature, time_to_cook, max_temperature (optional)}
174 //get next stage name - if next stage is not defined, next stage name will be empty "" and no cooking properties (food_min_temp, food_time_to_cook, food_max_temp) will be set
175 FoodStageType new_stage_type = item_to_cook.GetNextFoodStageType(cooking_method);
176
177 float food_min_temp = 0;
178 float food_time_to_cook = 0;
179 float food_max_temp = -1;
180
181 //Set next stage cooking properties if next stage possible
182 if (item_to_cook.CanChangeToNewStage(cooking_method)) // new_stage_type != NONE
183 {
184 array<float> next_stage_cooking_properties = new array<float>();
185 next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage(new_stage_type, null, item_to_cook.GetType());
186
187 food_min_temp = next_stage_cooking_properties.Get(eCookingPropertyIndices.MIN_TEMP);
188 food_time_to_cook = next_stage_cooking_properties.Get(eCookingPropertyIndices.COOK_TIME);
189 // The last element is optional and might not exist
190 if (next_stage_cooking_properties.Count() > 2)
191 {
192 food_max_temp = next_stage_cooking_properties.Get(eCookingPropertyIndices.MAX_TEMP);
193 }
194 }
195
196 //add temperature
197 AddTemperatureToItem(item_to_cook, cooking_equipment, food_min_temp);
198
199 //add cooking time if the food can be cooked by this method
200 if (food_min_temp > 0 && food_temperature >= food_min_temp)
201 {
202 float new_cooking_time = item_to_cook.GetCookingTime() + COOKING_FOOD_TIME_INC_VALUE * cooking_time_coef;
203 item_to_cook.SetCookingTime(new_cooking_time);
204
205 //progress to next stage
206 if (item_to_cook.GetCookingTime() >= food_time_to_cook)
207 {
208 //if max temp is defined check next food stage
209 if (food_max_temp >= 0)
210 {
211 if (food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED)
212 {
213 new_stage_type = FoodStageType.BURNED;
214 }
215 }
216
218 item_to_cook.ChangeFoodStage(new_stage_type);
220 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
221
222 if (cooking_equipment)
223 {
224 if (cooking_method == CookingMethodType.BAKING)
225 {
226 ItemBase lard = GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment);
227 if (lard)
228 {
229 //decrease lard quantity
230 float lardQuantity = lard.GetQuantity() - COOKING_LARD_DECREASE_COEF;
231 lardQuantity = Math.Clamp(lardQuantity, 0, lard.GetQuantityMax());
232 lard.SetQuantity(lardQuantity);
233 }
234 else
235 {
238 }
239 }
240 }
241 else
242 {
245 }
246
247 //reset cooking time
248 item_to_cook.SetCookingTime(0);
249
250 return 1;
251 }
252 }
253
254 return 0;
255 }
256
257 //Returns 1 if the item changed its cooking stage, 0 if not
258 protected int UpdateCookingStateOnStick( Edible_Base item_to_cook, float cook_time_inc )
259 {
260 //food properties
261 float food_temperature = item_to_cook.GetTemperature();
262
263 //{min_temperature, time_to_cook, max_temperature (optional)}
264 //get next stage name - if next stage is not defined, next stage name will be empty "" and no cooking properties (food_min_temp, food_time_to_cook, food_max_temp) will be set
265 FoodStageType new_stage_type = item_to_cook.GetNextFoodStageType( CookingMethodType.BAKING );
266 float food_min_temp = 0;
267 float food_time_to_cook = 0;
268 float food_max_temp = -1;
269 bool is_done = false; // baked
270 bool is_burned = false; // burned
271
272 //Set next stage cooking properties if next stage possible
273 if ( item_to_cook.CanChangeToNewStage( CookingMethodType.BAKING ) )
274 {
275 array<float> next_stage_cooking_properties = new array<float>;
276 next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage( new_stage_type, null, item_to_cook.GetType() );
277
278 food_min_temp = next_stage_cooking_properties.Get( eCookingPropertyIndices.MIN_TEMP );
279 food_time_to_cook = next_stage_cooking_properties.Get( eCookingPropertyIndices.COOK_TIME );
280 // The last element is optional and might not exist
281 if ( next_stage_cooking_properties.Count() > 2 )
282 food_max_temp = next_stage_cooking_properties.Get( eCookingPropertyIndices.MAX_TEMP );
283 }
284
285
286 // refresh audio
287 if (item_to_cook.GetInventory().IsAttachment())
288 {
289 item_to_cook.MakeSoundsOnClient(true);
290 //add temperature
291 AddTemperatureToItem(item_to_cook, null, food_min_temp);
292 }
293
294 //add cooking time if the food can be cooked by this method
295 if ( food_min_temp > 0 && food_temperature >= food_min_temp )
296 {
297 float new_cooking_time = item_to_cook.GetCookingTime() + cook_time_inc;
298 item_to_cook.SetCookingTime( new_cooking_time );
299
300 //progress to next stage
301 if ( item_to_cook.GetCookingTime() >= food_time_to_cook )
302 {
303 //if max temp is defined check next food stage
304 if ( food_max_temp >= 0 )
305 {
306 if ( food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED )
307 {
308 new_stage_type = FoodStageType.BURNED;
309 }
310 }
311
312 //change food stage
313 item_to_cook.ChangeFoodStage( new_stage_type );
314 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
315
317
318 //reset cooking time
319 item_to_cook.SetCookingTime( 0 );
320 return 1;
321 }
322 }
323
324 return 0;
325 }
326
327 void SmokeItem(Edible_Base item_to_cook, float cook_time_inc)
328 {
329 if (item_to_cook)
330 {
331 float new_cook_time = item_to_cook.GetCookingTime() + cook_time_inc;
332 float drying_cook_time = FoodStage.GetCookingPropertyFromIndex(eCookingPropertyIndices.COOK_TIME, FoodStageType.DRIED, null, item_to_cook.GetType());
333
334 switch (item_to_cook.GetFoodStageType())
335 {
336 case FoodStageType.RAW:
337 item_to_cook.SetCookingTime(new_cook_time);
338
339 if (item_to_cook.GetCookingTime() >= drying_cook_time)
340 {
341 item_to_cook.ChangeFoodStage(FoodStageType.DRIED);
342 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
343 item_to_cook.SetCookingTime(0);
344 }
345 break;
346 default:
347 item_to_cook.SetCookingTime(new_cook_time);
348
349 if (item_to_cook.GetCookingTime() >= drying_cook_time)
350 {
351 item_to_cook.ChangeFoodStage(FoodStageType.BURNED);
352 item_to_cook.RemoveAllAgents();
353 item_to_cook.SetCookingTime(0);
354 }
355 break;
356 }
357 }
358 }
359
361 {
362 Edible_Base edible;
363 if (pItem)
364 {
365 if (pItem.GetInventory()) // cookware
366 {
367 CargoBase cargo = pItem.GetInventory().GetCargo();
368 if (cargo)
369 {
370 for (int i = 0; i < cargo.GetItemCount(); i++)
371 {
372 edible = Edible_Base.Cast(cargo.GetItem(i));
373 if (edible)
374 {
375 edible.MakeSoundsOnClient(false);
376 }
377 }
378 }
379 }
380 else
381 {
382 edible = Edible_Base.Cast(pItem);
383 if (edible)
384 {
385 edible.MakeSoundsOnClient(false);
386 }
387 }
388 }
389 }
390
392 protected ItemBase GetItemTypeFromCargo( typename item_type, ItemBase cooking_equipment )
393 {
394 CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
395 if (cargo)
396 {
397 for (int i = 0; i < cargo.GetItemCount(); i++)
398 {
399 EntityAI entity = cargo.GetItem(i);
400 if (entity.Type() == item_type)
401 {
402 ItemBase item = ItemBase.Cast(entity);
403
404 return item;
405 }
406 }
407 }
408
409 return null;
410 }
411
413 protected CookingMethodType GetCookingMethod(ItemBase cooking_equipment)
414 {
415 if (cooking_equipment.Type() == COOKING_EQUIPMENT_POT || cooking_equipment.Type() == COOKING_EQUIPMENT_CAULDRON)
416 {
417 //has water, but not petrol dammit X)
418 if (cooking_equipment.GetQuantity() > 0 && cooking_equipment.GetLiquidType() != LIQUID_GASOLINE)
419 {
420 return CookingMethodType.BOILING;
421 }
422
423 //has lard in cargo
424 if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
425 {
426 return CookingMethodType.BAKING;
427 }
428 return CookingMethodType.DRYING;
429 }
430
431 if (cooking_equipment.Type() == COOKING_EQUIPMENT_FRYINGPAN)
432 {
433 if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
434 {
435 return CookingMethodType.BAKING;
436 }
437 return CookingMethodType.DRYING;
438 }
439
440 return CookingMethodType.NONE;
441 }
442
444 {
446
447 switch (cooking_equipment.Type())
448 {
452 if (cooking_equipment.GetQuantity() > 0)
453 {
454 if (cooking_equipment.GetLiquidType() == LIQUID_GASOLINE)
455 {
458 break;
459 }
460
462 break;
463 }
464
465 if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
466 {
467 //has lard in cargo, slower process
469 break;
470 }
471
473 break;
474
475 default:
477 break;
478 }
479
480 return val;
481 }
482
484 {
485 Edible_Base food_on_stick = Edible_Base.Cast( stick_item.GetAttachmentByType( Edible_Base ) );
486
487 return food_on_stick;
488 }
489
490 float GetTimeToCook( Edible_Base item_to_cook, CookingMethodType cooking_method )
491 {
492 FoodStageType food_stage_type = item_to_cook.GetNextFoodStageType( cooking_method );
493 return FoodStage.GetCookingPropertyFromIndex( eCookingPropertyIndices.COOK_TIME, food_stage_type, null, item_to_cook.GetType());
494 }
495
496 float GetMinTempToCook( Edible_Base item_to_cook, CookingMethodType cooking_method )
497 {
498 FoodStageType food_stage_type = item_to_cook.GetNextFoodStageType( cooking_method );
499 return FoodStage.GetCookingPropertyFromIndex( eCookingPropertyIndices.MIN_TEMP, food_stage_type, null, item_to_cook.GetType());
500 }
501
502 //add temperature to item
503 protected void AddTemperatureToItem( ItemBase cooked_item, ItemBase cooking_equipment, float min_temperature )
504 {
505 if ( cooked_item.GetTemperatureMax() >= FireplaceBase.PARAM_ITEM_HEAT_MIN_TEMP )
506 {
507 float item_temperature = cooked_item.GetTemperature();
508
509 //set actual cooking temperature
510 float actual_cooking_temp = DEFAULT_COOKING_TEMPERATURE; //default
511 if ( cooking_equipment )
512 {
513 actual_cooking_temp = cooking_equipment.GetTemperature();
514 }
515
516 //add temperature
517 if ( actual_cooking_temp > item_temperature )
518 {
519 item_temperature = actual_cooking_temp * 0.5;
520 item_temperature = Math.Clamp( item_temperature, min_temperature, FOOD_MAX_COOKING_TEMPERATURE );
521
522 //set new temperature
523 if ( GetGame() && GetGame().IsServer() )
524 {
525 cooked_item.SetTemperature( item_temperature );
526 }
527 }
528 }
529 }
530
531 protected void DecreaseCookedItemQuantity(notnull Edible_Base pItem, float pAmount = 0.0)
532 {
533 if (GetGame().IsServer())
534 {
535 float quantity = pItem.GetQuantity() - pAmount;
536 quantity = Math.Clamp(quantity, 0, pItem.GetQuantityMax());
537 pItem.SetQuantity(quantity);
538 }
539 }
540}
float GetMinTempToCook(Edible_Base item_to_cook, CookingMethodType cooking_method)
Definition Cooking.c:496
static const float COOKING_FOOD_TIME_INC_VALUE
time modifier used when using support material
Definition Cooking.c:17
COOKING_EQUIPMENT_CAULDRON
Definition Cooking.c:31
void TerminateCookingSounds(ItemBase pItem)
Definition Cooking.c:360
static const float COOKING_LARD_DECREASE_COEF
time increase when cooking a food
Definition Cooking.c:18
protected ItemBase GetItemTypeFromCargo(typename item_type, ItemBase cooking_equipment)
Cooking data.
Definition Cooking.c:392
Edible_Base GetFoodOnStick(ItemBase stick_item)
Definition Cooking.c:483
static const float COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_NONE
how many units from quantity of lard are remove at each stage
Definition Cooking.c:19
void ProcessItemToCook(notnull ItemBase pItem, ItemBase cookingEquip, Param2< CookingMethodType, float > pCookingMethod, out Param2< bool, bool > pStateFlags)
Definition Cooking.c:34
static const float DEFAULT_COOKING_TEMPERATURE
NOT USED.
Definition Cooking.c:22
CookingMethodType
Definition Cooking.c:2
@ COUNT
Definition Cooking.c:9
@ BAKING
Definition Cooking.c:4
@ DRYING
Definition Cooking.c:6
@ BOILING
Definition Cooking.c:5
@ NONE
Definition Cooking.c:3
@ TIME
Definition Cooking.c:7
protected void AddTemperatureToItem(ItemBase cooked_item, ItemBase cooking_equipment, float min_temperature)
Definition Cooking.c:503
protected CookingMethodType GetCookingMethod(ItemBase cooking_equipment)
DEPREACTED.
Definition Cooking.c:413
static const float LIQUID_BOILING_POINT
Definition Cooking.c:26
float GetTimeToCook(Edible_Base item_to_cook, CookingMethodType cooking_method)
Definition Cooking.c:490
static const float PARAM_BURN_DAMAGE_COEF
Definition Cooking.c:24
protected int UpdateCookingState(Edible_Base item_to_cook, CookingMethodType cooking_method, ItemBase cooking_equipment, float cooking_time_coef)
Definition Cooking.c:168
static const float LIQUID_VAPOR_QUANTITY
Definition Cooking.c:27
void SmokeItem(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:327
COOKING_EQUIPMENT_POT
Definition Cooking.c:29
enum CookingMethodType TIME_WITH_SUPPORT_MATERIAL_COEF
static const float FOOD_MAX_COOKING_TEMPERATURE
Definition Cooking.c:23
COOKING_INGREDIENT_LARD
Definition Cooking.c:32
protected void DecreaseCookedItemQuantity(notnull Edible_Base pItem, float pAmount=0.0)
Definition Cooking.c:531
int CookOnStick(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:156
protected int UpdateCookingStateOnStick(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:258
static const float TIME_WITHOUT_SUPPORT_MATERIAL_COEF
time modifier used when not using support material
Definition Cooking.c:15
COOKING_EQUIPMENT_FRYINGPAN
Definition Cooking.c:30
static const float COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_LARD
how many units from quantity of item are removed at each stage when support material is NOT used
Definition Cooking.c:20
protected Param2< CookingMethodType, float > GetCookingMethodWithTimeOverride(ItemBase cooking_equipment)
Definition Cooking.c:443
eAgents
Definition EAgents.c:3
protected void CookWithEquipment()
FoodStageType
Definition FoodStage.c:2
represents base for cargo storage for entities
Definition Cargo.c:7
proto native int GetItemCount()
proto native EntityAI GetItem(int index)
override bool CanBeCookedOnStick()
override bool CanBeCooked()
Definition EnMath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
const int LIQUID_GASOLINE
Definition constants.c:493
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'.