DayZ 1.24
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;
33
35 {
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, pCookingMethod.param1);
45
48
49 //check for done state for boiling and drying
50 if (item_to_cook.IsFoodBoiled() || item_to_cook.IsFoodDried())
51 pStateFlags.param1 = true;
53 else if (item_to_cook.IsFoodBaked() && item_to_cook.Type() != Lard)
54 pStateFlags.param1 = true;
56 else if (item_to_cook.IsFoodBurned())
57 pStateFlags.param2 = true;
58 }
59 else
60 {
61 //damage item
62 pItem.DecreaseHealth("", "", PARAM_BURN_DAMAGE_COEF * 100);
63
64 //add temperature to item
66 }
67 }
68
69 //COOKING PROCESS
70 //--- Cooking with equipment (pot)
71 //Returns 1 if the item changed its cooking stage, 0 if not
73 {
74 bool is_empty;
75
76 //check cooking conditions
78 return 0;
79
80 if (cooking_equipment.IsRuined())
81 return 0;
82
83 //manage items in cooking equipment
84 Param2<bool, bool> stateFlags = new Param2<bool, bool>(false, false); // 1st - done; 2nd - burned
86
88 if (cooking_time_coef != 1)
90
91 CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
92 if (cargo)
93 {
94 is_empty = cargo.GetItemCount() == 0;
95
96 //process items
97 for (int i = 0; i < cargo.GetItemCount(); i++)
99 }
100 else
102
103 //manage cooking equipment
105 if (bottle_base)
106 {
107 float cookingEquipmentTemp = cooking_equipment.GetTemperature();
108
109 //handle water boiling
111 {
112 //remove agents
113 cooking_equipment.RemoveAllAgents();
114
115 if (cooking_equipment.GetQuantity() > 0)
116 {
117 //vaporize liquid
119 }
120 }
121
122 //handle audio visuals
123 bottle_base.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
124 }
125
126 FryingPan frying_pan = FryingPan.Cast(cooking_equipment);
127 if (frying_pan && !bottle_base)
128 {
129 //handle audio visuals
130 frying_pan.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
131 }
132
133 return 1;
134 }
135
136 //Returns 1 if the item changed its cooking stage, 0 if not
138 {
139 if (item_to_cook && item_to_cook.CanBeCookedOnStick())
140 {
141 //update food
143 }
144
145 return 0;
146 }
147
148 //Returns 1 if the item changed its cooking stage, 0 if not
150 {
151 //food properties
152 float food_temperature = item_to_cook.GetTemperature();
153
154 //{min_temperature, time_to_cook, max_temperature (optional)}
155 //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
157
158 float food_min_temp = 0;
159 float food_time_to_cook = 0;
160 float food_max_temp = -1;
161
162 //Set next stage cooking properties if next stage possible
163 if (item_to_cook.CanChangeToNewStage(cooking_method)) // new_stage_type != NONE
164 {
166 next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage(new_stage_type, null, item_to_cook.GetType());
167
170 // The last element is optional and might not exist
171 if (next_stage_cooking_properties.Count() > 2)
173 }
174
175 //add temperature
177
178 //add cooking time if the food can be cooked by this method
180 {
182 item_to_cook.SetCookingTime(new_cooking_time);
183
184 //progress to next stage
185 if (item_to_cook.GetCookingTime() >= food_time_to_cook)
186 {
187 //if max temp is defined check next food stage
188 if (food_max_temp >= 0)
189 {
190 if (food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED)
192 }
193
195 item_to_cook.ChangeFoodStage(new_stage_type);
197 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
198
200 {
201 if (cooking_method == CookingMethodType.BAKING)
202 {
204 if (lard)
205 {
206 //decrease lard quantity
207 float lardQuantity = lard.GetQuantity() - COOKING_LARD_DECREASE_COEF;
208 lardQuantity = Math.Clamp(lardQuantity, 0, lard.GetQuantityMax());
209 lard.SetQuantity(lardQuantity);
210 }
211 else
212 {
215 }
216 }
217 }
218 else
219 {
222 }
223
224 //reset cooking time
225 item_to_cook.SetCookingTime(0);
226
227 return 1;
228 }
229 }
230
231 return 0;
232 }
233
234 //Returns 1 if the item changed its cooking stage, 0 if not
236 {
237 //food properties
238 float food_temperature = item_to_cook.GetTemperature();
239
240 //{min_temperature, time_to_cook, max_temperature (optional)}
241 //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
242 FoodStageType new_stage_type = item_to_cook.GetNextFoodStageType(CookingMethodType.BAKING);
243 float food_min_temp = 0;
244 float food_time_to_cook = 0;
245 float food_max_temp = -1;
246 bool is_done = false; // baked
247 bool is_burned = false; // burned
248
249 //Set next stage cooking properties if next stage possible
250 if (item_to_cook.CanChangeToNewStage(CookingMethodType.BAKING))
251 {
253 next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage(new_stage_type, null, item_to_cook.GetType());
254
257 // The last element is optional and might not exist
258 if (next_stage_cooking_properties.Count() > 2)
260 }
261
262
263 // refresh audio
264 if (item_to_cook.GetInventory().IsAttachment())
265 {
266 item_to_cook.MakeSoundsOnClient(true, CookingMethodType.BAKING);
267 //add temperature
269 }
270
271 //add cooking time if the food can be cooked by this method
273 {
274 float new_cooking_time = item_to_cook.GetCookingTime() + cook_time_inc;
275 item_to_cook.SetCookingTime(new_cooking_time);
276
277 //progress to next stage
278 if (item_to_cook.GetCookingTime() >= food_time_to_cook)
279 {
280 //if max temp is defined check next food stage
281 if (food_max_temp >= 0)
282 {
283 if (food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED)
285 }
286
287 //change food stage
288 item_to_cook.ChangeFoodStage(new_stage_type);
289 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
290
292
293 //reset cooking time
294 item_to_cook.SetCookingTime(0);
295 return 1;
296 }
297 }
298
299 return 0;
300 }
301
303 {
304 if (item_to_cook)
305 {
306 float new_cook_time = item_to_cook.GetCookingTime() + cook_time_inc;
307 float drying_cook_time = FoodStage.GetCookingPropertyFromIndex(eCookingPropertyIndices.COOK_TIME, FoodStageType.DRIED, null, item_to_cook.GetType());
308
309 switch (item_to_cook.GetFoodStageType())
310 {
311 case FoodStageType.RAW:
312 item_to_cook.SetCookingTime(new_cook_time);
313
314 if (item_to_cook.GetCookingTime() >= drying_cook_time)
315 {
316 item_to_cook.ChangeFoodStage(FoodStageType.DRIED);
317 item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
318 item_to_cook.SetCookingTime(0);
319 }
320 break;
321 default:
322 item_to_cook.SetCookingTime(new_cook_time);
323
324 if (item_to_cook.GetCookingTime() >= drying_cook_time)
325 {
326 item_to_cook.ChangeFoodStage(FoodStageType.BURNED);
327 item_to_cook.RemoveAllAgents();
328 item_to_cook.SetCookingTime(0);
329 }
330 break;
331 }
332 }
333 }
334
336 {
338 if (pItem)
339 {
340 if (pItem.GetInventory()) // cookware
341 {
342 CargoBase cargo = pItem.GetInventory().GetCargo();
343 if (cargo)
344 {
345 for (int i = 0; i < cargo.GetItemCount(); i++)
346 {
347 edible = Edible_Base.Cast(cargo.GetItem(i));
348 if (edible)
349 edible.MakeSoundsOnClient(false);
350 }
351 }
352 }
353 else
354 {
355 edible = Edible_Base.Cast(pItem);
356 if (edible)
357 edible.MakeSoundsOnClient(false);
358 }
359 }
360 }
361
364 {
365 CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
366 if (cargo)
367 {
368 for (int i = 0; i < cargo.GetItemCount(); i++)
369 {
370 EntityAI entity = cargo.GetItem(i);
371 if (entity.Type() == item_type)
372 {
374
375 return item;
376 }
377 }
378 }
379
380 return null;
381 }
382
385 {
387 {
388 //has water, but not petrol dammit X)
389 if (cooking_equipment.GetQuantity() > 0 && cooking_equipment.GetLiquidType() != LIQUID_GASOLINE)
390 return CookingMethodType.BOILING;
391
392 //has lard in cargo
394 return CookingMethodType.BAKING;
395 return CookingMethodType.DRYING;
396 }
397
399 {
401 return CookingMethodType.BAKING;
402 return CookingMethodType.DRYING;
403 }
404
405 return CookingMethodType.NONE;
406 }
407
409 {
411
412 switch (cooking_equipment.Type())
413 {
417 if (cooking_equipment.GetQuantity() > 0)
418 {
419 if (cooking_equipment.GetLiquidType() == LIQUID_GASOLINE)
420 {
423 break;
424 }
425
427 break;
428 }
429
431 {
432 //has lard in cargo, slower process
434 break;
435 }
436
437 if (cooking_equipment.GetInventory().GetCargo().GetItemCount() > 0)
438 {
440 break;
441 }
442
444 break;
445
446 default:
448 break;
449 }
450
451 return val;
452 }
453
460
462 {
464 return FoodStage.GetCookingPropertyFromIndex(eCookingPropertyIndices.COOK_TIME, food_stage_type, null, item_to_cook.GetType());
465 }
466
472
473 //add temperature to item
475 {
476 if (cooked_item.GetTemperatureMax() >= FireplaceBase.PARAM_ITEM_HEAT_MIN_TEMP)
477 {
478 float item_temperature = cooked_item.GetTemperature();
479
480 //set actual cooking temperature
483 actual_cooking_temp = cooking_equipment.GetTemperature();
484
485 //add temperature
487 {
490
491 //set new temperature
492 if (GetGame() && GetGame().IsServer())
493 cooked_item.SetTemperature(item_temperature);
494 }
495 }
496 }
497
499 {
500 if (GetGame().IsServer())
501 {
502 float quantity = pItem.GetQuantity() - pAmount;
503 quantity = Math.Clamp(quantity, 0, pItem.GetQuantityMax());
504 pItem.SetQuantity(quantity);
505 }
506 }
507}
float GetMinTempToCook(Edible_Base item_to_cook, CookingMethodType cooking_method)
Definition Cooking.c:467
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:335
static const float COOKING_LARD_DECREASE_COEF
time increase when cooking a food
Definition Cooking.c:18
Edible_Base GetFoodOnStick(ItemBase stick_item)
Definition Cooking.c:454
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
Param2< CookingMethodType, float > GetCookingMethodWithTimeOverride(ItemBase cooking_equipment)
Definition Cooking.c:408
static const float LIQUID_BOILING_POINT
Definition Cooking.c:26
float GetTimeToCook(Edible_Base item_to_cook, CookingMethodType cooking_method)
Definition Cooking.c:461
static const float PARAM_BURN_DAMAGE_COEF
Definition Cooking.c:24
CookingMethodType GetCookingMethod(ItemBase cooking_equipment)
DEPREACTED.
Definition Cooking.c:384
static const float LIQUID_VAPOR_QUANTITY
Definition Cooking.c:27
void SmokeItem(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:302
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
void DecreaseCookedItemQuantity(notnull Edible_Base pItem, float pAmount=0.0)
Definition Cooking.c:498
int CookOnStick(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:137
int UpdateCookingState(Edible_Base item_to_cook, CookingMethodType cooking_method, ItemBase cooking_equipment, float cooking_time_coef)
Definition Cooking.c:149
int UpdateCookingStateOnStick(Edible_Base item_to_cook, float cook_time_inc)
Definition Cooking.c:235
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
void AddTemperatureToItem(ItemBase cooked_item, ItemBase cooking_equipment, float min_temperature)
Definition Cooking.c:474
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
ItemBase GetItemTypeFromCargo(typename item_type, ItemBase cooking_equipment)
Cooking data.
Definition Cooking.c:363
eAgents
Definition EAgents.c:3
void CookWithEquipment()
FoodStageType
Definition FoodStage.c:2
represents base for cargo storage for entities
Definition Cargo.c:7
Definition EnMath.c:7
proto native CGame GetGame()
const int LIQUID_GASOLINE
Definition constants.c:508
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'.