DayZ 1.24
Loading...
Searching...
No Matches
PortableGasStove.c
Go to the documentation of this file.
1class 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 //
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
34
35 //cooking equipment
40
45
47 {
49 m_CookingProcess.TerminateCookingSounds(pItem);
50
52 }
53
54 //Destroy
56 {
57 //delete object
58 GetGame().ObjectDelete(this);
59 }
60
61 override void EEInit()
62 {
63 super.EEInit();
64
65 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
66 {
68 m_UTSSettings.m_ManualUpdate = true;
69 m_UTSSettings.m_TemperatureMin = 0;
70 m_UTSSettings.m_TemperatureMax = 1000;
71 m_UTSSettings.m_RangeFull = 1;
72 m_UTSSettings.m_RangeMax = 2;
73 m_UTSSettings.m_TemperatureCap = 10;
74
76 m_UTSource = new UniversalTemperatureSource(this, m_UTSSettings, m_UTSLConst);
77 }
78 }
79
80 //--- ATTACHMENTS
81 override void EEItemAttached(EntityAI item, string slot_name)
82 {
83 super.EEItemAttached(item, slot_name);
84
85 //cookware
86 switch (item.Type())
87 {
92 RefreshFlameVisual(m_EM.IsSwitchedOn(), true);
93 break;
94 }
95 }
96
97 override void EEItemDetached(EntityAI item, string slot_name)
98 {
99 super.EEItemDetached(item, slot_name);
100
101 //cookware
102 switch (item.Type())
103 {
107 RemoveCookingAudioVisuals();
108 //remove cooking equipment reference
110 RefreshFlameVisual(m_EM.IsSwitchedOn(), false);
111 break;
112 }
113 }
114
115 //--- POWER EVENTS
116 override void OnSwitchOn()
117 {
118 super.OnSwitchOn();
119
120 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
121 m_UTSource.SetDefferedActive(true, 3.0);
122
123 //sound (client only)
124 SoundTurnOn();
125 }
126
127 override void OnSwitchOff()
128 {
129 super.OnSwitchOff();
130
131 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
132 m_UTSource.SetDefferedActive(false, 5.0);
133
134 //sound (client only)
135 SoundTurnOff();
137 m_CookingProcess.TerminateCookingSounds(GetCookingEquipment());
138 }
139
140 override void OnWorkStart()
141 {
142 super.OnWorkStart();
143
144#ifndef SERVER
145 m_Light = StoveLight.Cast(ScriptedLightBase.CreateLight(StoveLight, "0 0 0"));
146 m_Light.AttachOnMemoryPoint(this, "light");
147#endif
148
149 //refresh visual
150 RefreshFlameVisual(true, GetCookingEquipment() != null);
151
152 //sound (client only)
153 SoundBurningStart();
154 }
155
156 override void OnWorkStop()
157 {
158#ifndef SERVER
159 if (m_Light)
160 m_Light.FadeOut();
161#endif
162
163 //refresh visual
164 RefreshFlameVisual(false, false);
165 //stop steam particle
166 RemoveCookingAudioVisuals();
167 //sound (client only)
168 SoundBurningStop();
169 }
170
171 //on update
172 override void OnWork(float consumed_energy)
173 {
174 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
175 m_UTSource.Update(m_UTSSettings, m_UTSLConst);
176
177 //manage cooking equipment
179 {
180 if (GetGame() && GetGame().IsServer())
181 {
182 float cook_equip_temp = GetCookingEquipment().GetTemperature();
183
184 //start cooking
186 {
187 m_TimeFactor = consumed_energy;
189 }
190
191 //set temperature to cooking equipment
194 GetCookingEquipment().SetTemperature(cook_equip_temp);
196 GetCookingEquipment().DecreaseHealth(GameConstants.FIRE_ATTACHMENT_DAMAGE_PER_SECOND * GetCompEM().GetUpdateInterval(), false);
197 }
198 }
199 }
200
202 {
203 if (m_CookingProcess == null)
205
206 m_CookingProcess.CookWithEquipment(GetCookingEquipment(), PARAM_COOKING_TIME_INC_COEF * m_TimeFactor);
207 }
208
209 protected void RefreshFlameVisual(bool working = false, bool hasAttachment = false)
210 {
211 if (!working)
212 {
213 SetObjectTexture(0, FLAME_BUTANE_OFF);
214 SetObjectTexture(1, FLAME_BUTANE_OFF);
215
216 return;
217 }
218
219 if (!hasAttachment)
220 {
222 SetObjectTexture(0, FLAME_BUTANE_ON);
223 SetObjectTexture(1, FLAME_BUTANE_OFF);
224 }
225 else
226 {
228 SetObjectTexture(0, FLAME_BUTANE_OFF);
229 SetObjectTexture(1, FLAME_BUTANE_ON);
230 }
231 }
232
233 //================================================================
234 // PARTICLES
235 //================================================================
236 //cooking equipment steam
238 {
240 if (cookEquipment)
241 {
242 switch (cookEquipment.Type())
243 {
247 cookingPot.RemoveAudioVisualsOnClient();
248 break;
250 FryingPan fryingPan = FryingPan.Cast(cookEquipment);
251 fryingPan.RemoveAudioVisualsOnClient();
252 break;
253 }
254 }
255 }
256
257 //================================================================
258 // SOUNDS
259 //================================================================
260 protected void SoundBurningStart()
261 {
262 PlaySoundSetLoop(m_SoundBurningLoop, SOUND_BURNING, 0.1, 0.3);
263 }
264
265 protected void SoundBurningStop()
266 {
267 StopSoundSet(m_SoundBurningLoop);
268 }
269
270 protected void SoundTurnOn()
271 {
272 PlaySoundSet(m_SoundTurnOn, SOUND_TURN_ON, 0.1, 0.1);
273 }
274
275 protected void SoundTurnOff()
276 {
277 PlaySoundSet(m_SoundTurnOff, SOUND_TURN_OFF, 0.1, 0.1);
278 }
279
280 //================================================================
281 // CONDITIONS
282 //================================================================
283 //this into/outo parent.Cargo
284 override bool CanPutInCargo(EntityAI parent)
285 {
286 if (!super.CanPutInCargo(parent))
287 return false;
288
289 if (GetCompEM().IsSwitchedOn())
290 return false;
291
292 //can 'parent' be attached to 'this' (->assumed smaller size than 'this')?
293 if (parent)
294 {
295 int slotId;
296 for (int i = 0; i < GetInventory().GetAttachmentSlotsCount(); i++)
297 {
298 slotId = GetInventory().GetAttachmentSlotId(i);
299 if (parent.GetInventory().HasInventorySlot(slotId))
300 {
301 //Print("CanPutInCargo | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
302 return false;
303 }
304 }
305 }
306
307 return true;
308 }
309
310 override bool CanRemoveFromCargo(EntityAI parent)
311 {
312 return true;
313 }
314
316 {
318 EntityAI ent = this;
319 EntityAI parent;
320 while (ent)
321 {
322 if (ent.GetInventory().GetCurrentInventoryLocation(loc) && loc.IsValid())
323 {
324 if (loc.GetType() == InventoryLocationType.CARGO)
325 {
326 parent = ent.GetHierarchyParent();
327 if (parent && parent.GetInventory().HasInventorySlot(slotId))
328 {
329 //Print("CanReceiveAttachment | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
330 return false;
331 }
332 }
333 }
334
335 ent = ent.GetHierarchyParent();
336 }
337
338 return super.CanReceiveAttachment(attachment, slotId);
339 }
340
342 {
343 int slotId;
344 for (int i = 0; i < attachment.GetInventory().GetSlotIdCount(); i++)
345 {
346 slotId = attachment.GetInventory().GetSlotId(i);
347 if (GetInventory().HasAttachmentSlot(slotId))
348 {
350 EntityAI ent = this;
351 EntityAI parent;
352 while (ent)
353 {
354 if (ent.GetInventory().GetCurrentInventoryLocation(loc) && loc.IsValid())
355 {
356 if (loc.GetType() == InventoryLocationType.CARGO)
357 {
358 parent = ent.GetHierarchyParent();
359 if (parent.GetInventory().HasInventorySlot(slotId))
360 {
361 //Print("CanLoadAttachment | parent " + parent + " matches in slot name: " + InventorySlots.GetSlotName(slotId) + " of " + this);
362 return false;
363 }
364 }
365 }
366
367 ent = ent.GetHierarchyParent();
368 }
369 }
370 }
371
372 return super.CanLoadAttachment(attachment);
373 }
374
375 //hands
376 override bool CanPutIntoHands(EntityAI parent)
377 {
378 if (!super.CanPutIntoHands(parent))
379 return false;
380
381 return !GetCompEM().IsSwitchedOn();
382 }
383
384 //================================================================
385 // ITEM-TO-ITEM FIRE DISTRIBUTION
386 //================================================================
387
388 override bool IsIgnited()
389 {
390 return GetCompEM().IsWorking();
391 }
392
394 {
395 return GetCompEM().IsWorking();
396 }
397
406
407 //Debug menu Spawn Ground Special
408 override void OnDebugSpawn()
409 {
411 if (Class.CastTo(entity, this))
412 {
413 GetInventory().CreateInInventory("LargeGasCanister");
414 GetInventory().CreateInInventory("Pot");
415
416 SpawnEntityOnGroundPos("WaterBottle", entity.GetPosition() + Vector(0.2, 0, 0));
417 }
418 }
419}
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
void AddAction(typename actionName)
ExplosiveLight m_Light
light
ref UniversalTemperatureSourceSettings m_UTSSettings
ItemBase GetCookingEquipment()
ATTACHMENT_FRYING_PAN
ATTACHMENT_CAULDRON
ref Cooking m_CookingProcess
determines how fast will the fuel item burn before spending (lower is better)
void SetCookingEquipment(ItemBase equipment)
void CookWithEquipment()
ATTACHMENT_COOKING_POT
ref UniversalTemperatureSource m_UTSource
const float PARAM_COOKING_EQUIP_MAX_TEMP
temperature threshold for starting coooking process (degree Celsius)
ItemBase m_CookingEquipment
void ClearCookingEquipment()
DEPRECATED.
const float PARAM_COOKING_EQUIP_TEMP_INCREASE
maximum temperature of attached cooking equipment (degree Celsius)
const float PARAM_COOKING_TEMP_THRESHOLD
cooking
InventoryLocationType
types of Inventory Location
Super root of all classes in Enforce script.
Definition EnScript.c:11
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
InventoryLocation.
override void EEItemAttached(EntityAI item, string slot_name)
override void OnSwitchOn()
float m_TimeFactor
override void OnWork(float consumed_energy)
void RefreshFlameVisual(bool working=false, bool hasAttachment=false)
override void OnWorkStart()
ref UniversalTemperatureSource m_UTSource
DEPRECATED Attached spark plug item.
void SoundTurnOn()
ref Cooking m_CookingProcess
override bool CanPutIntoHands(EntityAI parent)
override void SetActions()
ref UniversalTemperatureSourceSettings m_UTSSettings
override bool CanLoadAttachment(EntityAI attachment)
void SoundBurningStart()
void RemoveCookingAudioVisuals()
void SetCookingEquipment(ItemBase equipment)
void SoundTurnOff()
void DestroyFireplace()
override bool IsIgnited()
override void OnWorkStop()
StoveLight m_Light
ItemBase m_CookingEquipment
void ClearCookingEquipment(ItemBase pItem)
void CookWithEquipment()
ref UniversalTemperatureSourceLambdaConstant m_UTSLConst
override void EEItemDetached(EntityAI item, string slot_name)
override bool CanRemoveFromCargo(EntityAI parent)
override void OnSwitchOff()
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
override bool CanPutInCargo(EntityAI parent)
override void EEInit()
override void OnDebugSpawn()
void SoundBurningStop()
override bool CanIgniteItem(EntityAI ignite_target=NULL)
ItemBase GetCookingEquipment()
Definition EnMath.c:7
original Timer deletes m_params which is unwanted
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const float FIRE_ATTACHMENT_DAMAGE_PER_SECOND
various damage per second constants
Definition constants.c:727
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
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'.