Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
portablegasstove.c
Go to the documentation of this file.
1 class PortableGasStove extends ItemBase
2 {
3  StoveLight m_Light;
4 
5  protected const string FLAME_BUTANE_ON = "dz\\gear\\cooking\\data\\flame_butane_ca.paa";
6  protected const string FLAME_BUTANE_OFF = "";
7  typename ATTACHMENT_COOKING_POT = Pot;
8  typename ATTACHMENT_FRYING_PAN = FryingPan;
9  typename ATTACHMENT_CAULDRON = Cauldron;
10 
11  //cooking
12  protected const float PARAM_COOKING_TEMP_THRESHOLD = 100; //temperature threshold for starting coooking process (degree Celsius)
13  protected const float PARAM_COOKING_EQUIP_TEMP_INCREASE = 10; //how much will temperature increase when attached on burning fireplace (degree Celsius)
14  protected const float PARAM_COOKING_EQUIP_MAX_TEMP = 250; //maximum temperature of attached cooking equipment (degree Celsius)
15  protected const float PARAM_COOKING_TIME_INC_COEF = 0.5; //cooking time increase coeficient, can be used when balancing how fast a food can be cooked
16 
17  private float m_TimeFactor;
18  //
19  ref Cooking m_CookingProcess;
21 
22  //sound
23  const string SOUND_BURNING = "portablegasstove_burn_SoundSet";
24  const string SOUND_TURN_ON = "portablegasstove_turn_on_SoundSet";
25  const string SOUND_TURN_OFF = "portablegasstove_turn_off_SoundSet";
26 
27  protected EffectSound m_SoundBurningLoop;
28  protected EffectSound m_SoundTurnOn;
29  protected EffectSound m_SoundTurnOff;
30 
33  protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConst;
34 
35  //cooking equipment
37  {
38  return m_CookingEquipment;
39  }
40 
41  void SetCookingEquipment(ItemBase equipment)
42  {
43  m_CookingEquipment = equipment;
44  }
45 
47  {
48  if (m_CookingProcess)
49  {
50  m_CookingProcess.TerminateCookingSounds(pItem);
51  }
52 
53  SetCookingEquipment(null);
54  }
55 
56  //Destroy
57  void DestroyFireplace()
58  {
59  //delete object
60  GetGame().ObjectDelete(this);
61  }
62 
63  override void EEInit()
64  {
65  super.EEInit();
66 
67  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
68  {
70  m_UTSSettings.m_ManualUpdate = true;
71  m_UTSSettings.m_TemperatureMin = 0;
72  m_UTSSettings.m_TemperatureMax = 1000;
73  m_UTSSettings.m_RangeFull = 1;
74  m_UTSSettings.m_RangeMax = 2;
75  m_UTSSettings.m_TemperatureCap = 10;
76 
77  m_UTSLConst = new UniversalTemperatureSourceLambdaConstant();
78  m_UTSource = new UniversalTemperatureSource(this, m_UTSSettings, m_UTSLConst);
79  }
80  }
81 
82  //--- ATTACHMENTS
83  override void EEItemAttached(EntityAI item, string slot_name)
84  {
85  super.EEItemAttached(item, slot_name);
86 
87  //cookware
88  switch (item.Type())
89  {
93  SetCookingEquipment(ItemBase.Cast(item));
94  RefreshFlameVisual(m_EM.IsSwitchedOn(), true);
95  break;
96  }
97  }
98 
99  override void EEItemDetached(EntityAI item, string slot_name)
100  {
101  super.EEItemDetached(item, slot_name);
102 
103  //cookware
104  switch (item.Type())
105  {
106  case ATTACHMENT_CAULDRON:
109  RemoveCookingAudioVisuals();
110  //remove cooking equipment reference
111  ClearCookingEquipment(ItemBase.Cast(item));
112  RefreshFlameVisual(m_EM.IsSwitchedOn(), false);
113  break;
114  }
115  }
116 
117  //--- POWER EVENTS
118  override void OnSwitchOn()
119  {
120  super.OnSwitchOn();
121 
122  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
123  {
124  m_UTSource.SetDefferedActive(true, 3.0);
125  }
126 
127  //sound (client only)
128  SoundTurnOn();
129  }
130 
131  override void OnSwitchOff()
132  {
133  super.OnSwitchOff();
134 
135  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
136  {
137  m_UTSource.SetDefferedActive(false, 5.0);
138  }
139 
140  //sound (client only)
141  SoundTurnOff();
143  {
144  m_CookingProcess.TerminateCookingSounds(GetCookingEquipment());
145  }
146  }
147 
148  override void OnWorkStart()
149  {
150  super.OnWorkStart();
151 
152  #ifndef SERVER
153  m_Light = StoveLight.Cast(ScriptedLightBase.CreateLight(StoveLight, "0 0 0"));
154  m_Light.AttachOnMemoryPoint(this, "light");
155  #endif
156 
157  //refresh visual
158  RefreshFlameVisual(true, GetCookingEquipment() != null);
159 
160  //sound (client only)
161  SoundBurningStart();
162  }
163 
164  override void OnWorkStop()
165  {
166  #ifndef SERVER
167  if (m_Light)
168  {
169  m_Light.FadeOut();
170  }
171  #endif
172 
173  //refresh visual
174  RefreshFlameVisual(false, false);
175  //stop steam particle
176  RemoveCookingAudioVisuals();
177  //sound (client only)
178  SoundBurningStop();
179  }
180 
181  //on update
182  override void OnWork(float consumed_energy)
183  {
184  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
185  {
186  m_UTSource.Update(m_UTSSettings, m_UTSLConst);
187  }
188 
189  //manage cooking equipment
190  if (GetCookingEquipment())
191  {
192  if (GetGame() && GetGame().IsServer())
193  {
194  float cook_equip_temp = GetCookingEquipment().GetTemperature();
195 
196  //start cooking
197  if (cook_equip_temp >= PARAM_COOKING_TEMP_THRESHOLD)
198  {
199  m_TimeFactor = consumed_energy;
201  }
202 
203  //set temperature to cooking equipment
204  cook_equip_temp = cook_equip_temp + (PARAM_COOKING_EQUIP_TEMP_INCREASE * consumed_energy);
205  cook_equip_temp = Math.Clamp(cook_equip_temp, 0, PARAM_COOKING_EQUIP_MAX_TEMP);
206  GetCookingEquipment().SetTemperature(cook_equip_temp);
208  GetCookingEquipment().DecreaseHealth(GameConstants.FIRE_ATTACHMENT_DAMAGE_PER_SECOND * GetCompEM().GetUpdateInterval(), false);
209  }
210  }
211  }
212 
213  void CookWithEquipment()
214  {
215  if (m_CookingProcess == null)
216  {
217  m_CookingProcess = new Cooking();
218  }
219 
220  m_CookingProcess.CookWithEquipment(GetCookingEquipment(), PARAM_COOKING_TIME_INC_COEF * m_TimeFactor);
221  }
222 
223  protected void RefreshFlameVisual(bool working = false, bool hasAttachment = false)
224  {
225  if (!working)
226  {
227  SetObjectTexture(0, FLAME_BUTANE_OFF);
228  SetObjectTexture(1, FLAME_BUTANE_OFF);
229 
230  return;
231  }
232 
233  if (!hasAttachment)
234  {
236  SetObjectTexture(0, FLAME_BUTANE_ON);
237  SetObjectTexture(1, FLAME_BUTANE_OFF);
238  }
239  else
240  {
242  SetObjectTexture(0, FLAME_BUTANE_OFF);
243  SetObjectTexture(1, FLAME_BUTANE_ON);
244  }
245  }
246 
247  //================================================================
248  // PARTICLES
249  //================================================================
250  //cooking equipment steam
251  protected void RemoveCookingAudioVisuals()
252  {
253  ItemBase cookEquipment = GetCookingEquipment();
254  if (cookEquipment)
255  {
256  switch (cookEquipment.Type())
257  {
258  case ATTACHMENT_CAULDRON:
260  Bottle_Base cookingPot = Bottle_Base.Cast(cookEquipment);
261  cookingPot.RemoveAudioVisualsOnClient();
262  break;
264  FryingPan fryingPan = FryingPan.Cast(cookEquipment);
265  fryingPan.RemoveAudioVisualsOnClient();
266  break;
267  }
268  }
269  }
270 
271  //================================================================
272  // SOUNDS
273  //================================================================
274  protected void SoundBurningStart()
275  {
276  PlaySoundSetLoop(m_SoundBurningLoop, SOUND_BURNING, 0.1, 0.3);
277  }
278 
279  protected void SoundBurningStop()
280  {
281  StopSoundSet(m_SoundBurningLoop);
282  }
283 
284  protected void SoundTurnOn()
285  {
286  PlaySoundSet(m_SoundTurnOn, SOUND_TURN_ON, 0.1, 0.1);
287  }
288 
289  protected void SoundTurnOff()
290  {
291  PlaySoundSet(m_SoundTurnOff, SOUND_TURN_OFF, 0.1, 0.1);
292  }
293 
294  //================================================================
295  // CONDITIONS
296  //================================================================
297  //this into/outo parent.Cargo
298  override bool CanPutInCargo(EntityAI parent)
299  {
300  if (!super.CanPutInCargo(parent))
301  return false;
302 
303  if (GetCompEM().IsSwitchedOn())
304  return false;
305 
306  //can 'parent' be attached to 'this' (->assumed smaller size than 'this')?
307  if (parent)
308  {
309  int slotId;
310  for (int i = 0; i < GetInventory().GetAttachmentSlotsCount(); i++)
311  {
312  slotId = GetInventory().GetAttachmentSlotId(i);
313  if (parent.GetInventory().HasInventorySlot(slotId))
314  {
315  //Print("CanPutInCargo | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
316  return false;
317  }
318  }
319  }
320 
321  return true;
322  }
323 
324  override bool CanRemoveFromCargo(EntityAI parent)
325  {
326  return true;
327  }
328 
329  override bool CanReceiveAttachment(EntityAI attachment, int slotId)
330  {
332  EntityAI ent = this;
333  EntityAI parent;
334  while (ent)
335  {
336  if (ent.GetInventory().GetCurrentInventoryLocation(loc) && loc.IsValid())
337  {
338  if (loc.GetType() == InventoryLocationType.CARGO)
339  {
340  parent = ent.GetHierarchyParent();
341  if (parent && parent.GetInventory().HasInventorySlot(slotId))
342  {
343  //Print("CanReceiveAttachment | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
344  return false;
345  }
346  }
347  }
348 
349  ent = ent.GetHierarchyParent();
350  }
351 
352  return super.CanReceiveAttachment(attachment, slotId);
353  }
354 
355  override bool CanLoadAttachment(EntityAI attachment)
356  {
357  int slotId;
358  for (int i = 0; i < attachment.GetInventory().GetSlotIdCount(); i++)
359  {
360  slotId = attachment.GetInventory().GetSlotId(i);
361  if (GetInventory().HasAttachmentSlot(slotId))
362  {
364  EntityAI ent = this;
365  EntityAI parent;
366  while (ent)
367  {
368  if (ent.GetInventory().GetCurrentInventoryLocation(loc) && loc.IsValid())
369  {
370  if (loc.GetType() == InventoryLocationType.CARGO)
371  {
372  parent = ent.GetHierarchyParent();
373  if (parent.GetInventory().HasInventorySlot(slotId))
374  {
375  //Print("CanLoadAttachment | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
376  return false;
377  }
378  }
379  }
380 
381  ent = ent.GetHierarchyParent();
382  }
383  }
384  }
385 
386  return super.CanLoadAttachment(attachment);
387  }
388 
389  //hands
390  override bool CanPutIntoHands(EntityAI parent)
391  {
392  if (!super.CanPutIntoHands(parent))
393  {
394  return false;
395  }
396 
397  return !GetCompEM().IsSwitchedOn();
398  }
399 
400  //================================================================
401  // ITEM-TO-ITEM FIRE DISTRIBUTION
402  //================================================================
403 
404  override bool IsIgnited()
405  {
406  return GetCompEM().IsWorking();
407  }
408 
409  override bool CanIgniteItem(EntityAI ignite_target = NULL)
410  {
411  return GetCompEM().IsWorking();
412  }
413 
414  override void SetActions()
415  {
416  super.SetActions();
417 
421  }
422 
423  //Debug menu Spawn Ground Special
424  override void OnDebugSpawn()
425  {
426  EntityAI entity;
427  if ( Class.CastTo(entity, this) )
428  {
429  GetInventory().CreateInInventory("LargeGasCanister");
430  GetInventory().CreateInInventory("Pot");
431 
432  SpawnEntityOnGroundPos("WaterBottle", entity.GetPosition() + Vector(0.2, 0, 0));
433  }
434  }
435 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
m_UTSource
protected ref UniversalTemperatureSource m_UTSource
Definition: fireplacebase.c:224
ATTACHMENT_CAULDRON
ATTACHMENT_CAULDRON
Definition: fireplacebase.c:208
m_CookingProcess
protected ref Cooking m_CookingProcess
determines how fast will the fuel item burn before spending (lower is better)
Definition: fireplacebase.c:40
ClearCookingEquipment
void ClearCookingEquipment(ItemBase pItem)
Definition: fireplacebase.c:550
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
SetCookingEquipment
void SetCookingEquipment(ItemBase equipment)
Definition: fireplacebase.c:545
UniversalTemperatureSource
original Timer deletes m_params which is unwanted
Definition: universaltemperaturesource.c:25
Bottle_Base
Definition: canistergasoline.c:1
m_UTSSettings
protected ref UniversalTemperatureSourceSettings m_UTSSettings
Definition: fireplacebase.c:225
OnDebugSpawn
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
Definition: hatchback_02.c:404
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
CanPutIntoHands
override bool CanPutIntoHands(EntityAI parent)
Definition: explosivesbase.c:257
CanPutInCargo
override bool CanPutInCargo(EntityAI parent)
Definition: explosivesbase.c:247
UniversalTemperatureSourceSettings
Definition: universaltemperaturesource.c:1
ActionLightItemOnFire
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
Definition: actionlightitemonfire.c:11
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
OnWork
override void OnWork(float consumed_energy)
Definition: smokegrenadebase.c:195
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ScriptedLightBase
Definition: pointlightbase.c:1
ATTACHMENT_FRYING_PAN
ATTACHMENT_FRYING_PAN
Definition: fireplacebase.c:207
SetActions
void SetActions()
Definition: advancedcommunication.c:79
CanRemoveFromCargo
override bool CanRemoveFromCargo(EntityAI parent)
Definition: basebuildingbase.c:927
PARAM_COOKING_EQUIP_TEMP_INCREASE
const float PARAM_COOKING_EQUIP_TEMP_INCREASE
maximum temperature of attached cooking equipment (degree Celsius)
Definition: fireplacebase.c:81
GetCookingEquipment
ItemBase GetCookingEquipment()
Definition: fireplacebase.c:540
GameConstants
Definition: constants.c:612
EEInit
override void EEInit()
Definition: contaminatedarea.c:27
CanLoadAttachment
override bool CanLoadAttachment(EntityAI attachment)
Definition: container_base.c:64
PARAM_COOKING_TEMP_THRESHOLD
const float PARAM_COOKING_TEMP_THRESHOLD
cooking
Definition: fireplacebase.c:79
ATTACHMENT_COOKING_POT
ATTACHMENT_COOKING_POT
Definition: fireplacebase.c:206
DestroyFireplace
void DestroyFireplace()
[DEPRECATED]
Definition: fireplacebase.c:591
m_CookingEquipment
protected ItemBase m_CookingEquipment
Definition: fireplacebase.c:106
Math
Definition: enmath.c:6
ActionTurnOffWhileOnGround
Definition: actionturnoffwhileonground.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EEItemAttached
override void EEItemAttached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:520
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
CanReceiveAttachment
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition: basebuildingbase.c:895
EEItemDetached
override void EEItemDetached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:529
EntityAI
Definition: building.c:5
ActionTurnOnWhileOnGround
Definition: actionturnonwhileonground.c:1
PARAM_COOKING_EQUIP_MAX_TEMP
const float PARAM_COOKING_EQUIP_MAX_TEMP
temperature threshold for starting coooking process (degree Celsius)
Definition: fireplacebase.c:80
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175
CookWithEquipment
int CookWithEquipment(ItemBase cooking_equipment, float cooking_time_coef=1)
Definition: cooking.c:78