DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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 //
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
28 protected EffectSound m_SoundTurnOn;
30
33 protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConst;
34
35 //cooking equipment
37 {
38 return m_CookingEquipment;
39 }
40
42 {
43 m_CookingEquipment = equipment;
44 }
45
47 {
49 {
50 m_CookingProcess.TerminateCookingSounds(pItem);
51 }
52
54 }
55
56 //Destroy
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 {
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 {
110 //remove cooking equipment reference
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
159
160 //sound (client only)
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
177 //sound (client only)
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
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
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
252 {
253 ItemBase cookEquipment = GetCookingEquipment();
254 if (cookEquipment)
255 {
256 switch (cookEquipment.Type())
257 {
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 {
302 return false;
303 }
304
305 return !GetCompEM().IsSwitchedOn();
306 }
307
308 override bool CanRemoveFromCargo(EntityAI parent)
309 {
310 return true;
311 }
312
313 //hands
314 override bool CanPutIntoHands(EntityAI parent)
315 {
316 if (!super.CanPutIntoHands(parent))
317 {
318 return false;
319 }
320
321 return !GetCompEM().IsSwitchedOn();
322 }
323
324 //================================================================
325 // ITEM-TO-ITEM FIRE DISTRIBUTION
326 //================================================================
327
328 override bool IsIgnited()
329 {
330 return GetCompEM().IsWorking();
331 }
332
333 override bool CanIgniteItem(EntityAI ignite_target = NULL)
334 {
335 return GetCompEM().IsWorking();
336 }
337
338 override void SetActions()
339 {
340 super.SetActions();
341
345 }
346
347 //Debug menu Spawn Ground Special
348 override void OnDebugSpawn()
349 {
350 EntityAI entity;
351 if ( Class.CastTo(entity, this) )
352 {
353 GetInventory().CreateInInventory("LargeGasCanister");
354 GetInventory().CreateInInventory("Pot");
355
356 SpawnEntityOnGroundPos("WaterBottle", entity.GetPosition() + Vector(0.2, 0, 0));
357 }
358 }
359}
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
void AddAction(typename actionName)
protected ExplosiveLight m_Light
light
protected ref UniversalTemperatureSourceSettings m_UTSSettings
ATTACHMENT_FRYING_PAN
ATTACHMENT_CAULDRON
protected ItemBase m_CookingEquipment
protected ref UniversalTemperatureSource m_UTSource
ATTACHMENT_COOKING_POT
const float PARAM_COOKING_EQUIP_MAX_TEMP
temperature threshold for starting coooking process (degree Celsius)
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
protected ref Cooking m_CookingProcess
determines how fast will the fuel item burn before spending (lower is better)
proto native void ObjectDelete(Object obj)
Super root of all classes in Enforce script.
Definition EnScript.c:11
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
protected ref UniversalTemperatureSourceSettings m_UTSSettings
override void OnDebugSpawn()
ItemBase GetCookingEquipment()
protected void SoundTurnOn()
protected void SoundBurningStop()
Definition Blowtorch.c:56
void ClearCookingEquipment(ItemBase pItem)
void DestroyFireplace()
override void OnSwitchOn()
ref Cooking m_CookingProcess
override void EEInit()
override void OnSwitchOff()
override bool CanPutInCargo(EntityAI parent)
override void OnWorkStop()
void SetCookingEquipment(ItemBase equipment)
protected void RefreshFlameVisual(bool working=false, bool hasAttachment=false)
override bool IsIgnited()
protected void RefreshFlameVisual(bool working=false)
Definition Blowtorch.c:37
protected EffectSound m_SoundTurnOff
void CookWithEquipment()
protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConst
override void EEItemDetached(EntityAI item, string slot_name)
override void OnWork(float consumed_energy)
override bool CanIgniteItem(EntityAI ignite_target=NULL)
protected ref UniversalTemperatureSource m_UTSource
DEPRECATED Attached spark plug item.
protected EffectSound m_SoundTurnOn
override bool CanPutIntoHands(EntityAI parent)
override bool CanRemoveFromCargo(EntityAI parent)
override void OnWorkStart()
override void EEItemAttached(EntityAI item, string slot_name)
protected void RemoveCookingAudioVisuals()
StoveLight m_Light
protected EffectSound m_SoundBurningLoop
Definition Blowtorch.c:9
ItemBase m_CookingEquipment
private float m_TimeFactor
protected void SoundBurningStart()
Definition Blowtorch.c:51
protected void SoundTurnOff()
override void SetActions()
Definition EnMath.c:7
original Timer deletes m_params which is unwanted
float m_TemperatureMax
min temperature you can get from the TemperatureSource
float m_RangeFull
temperature cap that will limit the return value from GetTemperature method
bool m_ManualUpdate
if the Update is running periodically
float m_TemperatureMin
how often the Update is ticking
float m_RangeMax
range where the full temperature is given to receiver
float m_TemperatureCap
max temperature you can get from the TemperatureSource
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:712
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'.