Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
torch.c
Go to the documentation of this file.
2 {
3  void FlammableBase()
4  {
5  Init();
6  }
7 
8  private SoundOnVehicle m_LoopSoundEntity;
9  Particle m_FireParticle;
10  bool m_CanReceiveUpgrade; // Synchronized variable
11  bool m_IsBeingDestructed = false;
12 
13  float m_BurnTimePerRagEx;
14  float m_BurnTimePerFullLardEx;
15  float m_BurnTimePerFullFuelDoseEx;
16  float m_MaxConsumableLardQuantityEx;
17  float m_MaxConsumableFuelQuantityEx;
18  float m_WaterEvaporationByFireIntensityEx = 0.001;
19  int m_StartFadeOutOfLightAtQuantityEx = 3;
20 
21  int m_RagsUpgradedCount;//how many rags were upgraded with fuel/lard
22  bool m_ConsumeRagFlipFlop;//are we burning rag or fuel/lard
23  vector m_ParticleLocalPos = Vector(0, 0.50, 0);
24 
25  string m_DecraftResult = "WoodenStick";
26  TorchLight m_Light;
27  bool m_WasLit;//was this item ever lit ? (used for correct material setting after reconnect for extinguished flammable items)
28 
29  protected ref UniversalTemperatureSource m_UTSource;
30  protected ref UniversalTemperatureSourceSettings m_UTSSettings;
31  protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConstant;
32 
33  override void DeferredInit()
34  {
35  if(m_RagsUpgradedCount)
36  {
37  LockRags(true);
38  }
39  }
40 
41  void Init()
42  {
43  if ( m_BurnTimePerRagEx == 0 || m_BurnTimePerFullLardEx == 0 || m_MaxConsumableLardQuantityEx == 0 || m_MaxConsumableFuelQuantityEx == 0 )
44  {
45  string cfg_path = "CfgVehicles " + GetType();
46  m_BurnTimePerRagEx = GetGame().ConfigGetFloat( cfg_path + " burnTimePerRag" );
47  m_BurnTimePerFullLardEx = GetGame().ConfigGetFloat( cfg_path + " burnTimePerFullLardDose" );
48  m_BurnTimePerFullFuelDoseEx = GetGame().ConfigGetFloat( cfg_path + " burnTimePerFullFuelDose" );
49  m_MaxConsumableLardQuantityEx = GetGame().ConfigGetFloat( cfg_path + " maxConsumableLardDose" );
50  m_MaxConsumableFuelQuantityEx = GetGame().ConfigGetFloat( cfg_path + " maxConsumableFuelDose" );
51  }
52  RegisterNetSyncVariableBool("m_CanReceiveUpgrade");
53  }
54 
55  override void EEInit()
56  {
57  super.EEInit();
58 
59  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
60  {
62  m_UTSSettings.m_Updateable = true;
63  m_UTSSettings.m_UpdateInterval = 1;
64  m_UTSSettings.m_TemperatureMin = 0;
65  m_UTSSettings.m_TemperatureMax = 300;
66  m_UTSSettings.m_RangeFull = 0.5;
67  m_UTSSettings.m_RangeMax = 1;
68  m_UTSSettings.m_TemperatureCap = 5;
69 
70  m_UTSLConstant = new UniversalTemperatureSourceLambdaConstant();
71  m_UTSource = new UniversalTemperatureSource(this, m_UTSSettings, m_UTSLConstant);
72  }
73 
74  }
75 
76  override vector GetUniversalTemperatureSourcePosition()
77  {
78  if (GetHierarchyRoot())
79  {
80  return GetHierarchyRoot().GetPosition();
81  }
82 
83  return super.GetPosition();
84  }
85 
86  override void EEDelete(EntityAI parent)
87  {
88  super.EEDelete(parent);
89  if ( m_LoopSoundEntity != NULL && GetGame() != NULL )
90  {
91  GetGame().ObjectDelete( m_LoopSoundEntity );
92  }
93 
94  StopAllParticles();
95  }
96 
97  override bool CanReceiveAttachment(EntityAI attachment, int slotId)
98  {
99  ItemBase att = ItemBase.Cast(GetInventory().FindAttachment(slotId));
100  if (att && att.IsFullQuantity())
101  return false;
102 
103  return super.CanReceiveAttachment(attachment, slotId);
104  }
105 
106  override bool CanPutInCargo( EntityAI parent )
107  {
108  if( !super.CanPutInCargo(parent) ) {return false;}
109  return CanBeTakenAsCargo();
110  }
111 
112  override bool CanReleaseAttachment(EntityAI attachment)
113  {
114  if( !super.CanReleaseAttachment( attachment ) )
115  return false;
116  return !GetCompEM().IsWorking();
117  }
118 
119  override bool CanRemoveFromCargo(EntityAI parent)
120  {
121  return CanBeTakenAsCargo();
122  }
123 
124  override bool CanPutAsAttachment (EntityAI parent)
125  {
126  return !GetCompEM().IsWorking();
127  }
128 
129  bool CanBeTakenAsCargo()
130  {
131  // Don't let players burn their pockets!
132  return !GetCompEM().IsWorking();
133  }
134 
135  override bool IsIgnited()
136  {
137  return GetCompEM().IsWorking();
138  }
139 
140  override bool CanIgniteItem(EntityAI ignite_target = NULL)
141  {
142  return GetCompEM().IsWorking();
143  }
144 
145  override bool HasFlammableMaterial()
146  {
147  return true;
148  }
149 
150  // Checkes if Torch can be ignited
151  override bool CanBeIgnitedBy(EntityAI igniter = NULL)
152  {
153  if ( !GetCompEM().CheckWetness() )
154  return false;
155 
156  ItemBase rag = GetRag();
157 
158  if (rag && GetCompEM().GetEnergy() < GetCompEM().GetEnergyUsage() * GetCompEM().GetUpdateInterval() )
159  {
160  if (IsRagDryEnough(rag))
161  return false;
162  }
163 
164  if ( !GetCompEM().CanWork() )
165  return false;
166 
167  if ( GetCompEM().GetEnergy() < 3 )
168  return false;
169 
170  PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
171  if (player)
172  {
173  if (this != player.GetItemInHands())//we are in player's inventory, but not in his hands
174  {
175  return false;
176  }
177  }
178 
179  return true;
180  }
181 
182  bool IsRagDryEnough(ItemBase rag)
183  {
184  float wetness = rag.GetWet();
185  bool is_dry_enough = wetness <= 1-GetCompEM().GetWetnessExposure();
186  return is_dry_enough;
187  }
188 
189  void UpdateCheckForReceivingUpgrade()
190  {
191  if ( GetGame().IsServer() || !GetGame().IsMultiplayer() )
192  {
193  m_CanReceiveUpgrade = GetRagQuantity() > 0 && m_RagsUpgradedCount < GetRagQuantity() || (m_BurnTimePerRagEx * (m_RagsUpgradedCount + GetRagQuantity()) - GetCompEM().GetEnergy()) > 1;
194  SetSynchDirty();
195  }
196  }
197 
198  override void OnIgnitedThis(EntityAI fire_source)
199  {
200  if ( !GetCompEM().HasEnoughStoredEnergy() )
201  {
202  ConsumeRag();
203  }
204 
205  GetCompEM().SwitchOn();
206  }
207 
208  override void OnSwitchOn()
209  {
210  if (!GetCompEM().HasEnoughStoredEnergy())
211  {
212  GetCompEM().SwitchOff();
213  }
214 
215  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
216  {
217  m_UTSource.SetActive(true);
218  }
219  }
220 
221  override void OnSwitchOff()
222  {
223  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
224  {
225  m_UTSource.SetActive(false);
226  }
227  }
228 
229  void SetTorchDecraftResult(string type)
230  {
231  m_DecraftResult = type; //not persistent for the moment
232  }
233 
234  bool ConsumeRag()
235  {
236  ItemBase rag = GetRag();
237 
238  if (rag)
239  {
240  if (rag.GetQuantity() <= 1)
241  {
242  LockRags(false); // Unlock attachment slot before deletion. Otherwise it will get stuck locked and unusable.
243  }
244 
245  rag.AddQuantity(-1);
246  rag.SetHealth(0);
247  //GetCompEM().AddEnergy( m_BurnTimePerRagEx );
248  return true;
249  }
250 
251  return false;
252  }
253 
254  void ConsumeLard(Lard lard)
255  {
256  if (lard)
257  {
258  float lard_quant = lard.GetQuantity();
259 
260  float available_lard_quant = lard_quant;
261 
262  if ( available_lard_quant > m_MaxConsumableLardQuantityEx )
263  available_lard_quant = m_MaxConsumableLardQuantityEx;
264 
265  float available_lard_coef = available_lard_quant / m_MaxConsumableLardQuantityEx;
266 
267  float add_energy = m_BurnTimePerFullLardEx * available_lard_coef;
268  float add_energy_coef = 1;
269 
270  float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
271 
272  if (add_energy > energy_limit )
273  {
274  add_energy_coef = energy_limit / add_energy;
275  add_energy = energy_limit;
276  available_lard_quant = available_lard_quant * add_energy_coef;
277  }
278 
279  GetCompEM().AddEnergy( add_energy );
280  lard.AddQuantity(-available_lard_quant);
281 
282  CalculateQuantity();
283 
284  UpdateCheckForReceivingUpgrade();
285  }
286  }
287 
288  void Upgrade(ItemBase source)
289  {
290  if (!GetRag())
291  {
292  return;
293  }
294  RuinRags();
295  LockRags(true);
296  float torchCurrentEnergy = GetCompEM().GetEnergy();
297  float sourceQuantity = 100000;//for upgrade from environment(gas pump)
298 
299  if (source)
300  {
301  sourceQuantity = source.GetQuantity();
302  }
303 
304  float maxOverallCapacity = GetRagQuantity() * 2 * m_BurnTimePerRagEx;
305  //float maxUpgradeCapacity = GetRagQuantity() * m_BurnTimePerRagEx;
306  float currentlyUpgraded = Math.Max(0, torchCurrentEnergy - (GetRagQuantity() * m_BurnTimePerRagEx));
307  //float freeUpgradeCapacity = maxUpgradeCapacity - currentlyUpgraded;
308  float freeUpgradeCapacity = maxOverallCapacity - torchCurrentEnergy;
309  float upgradeQuantity = Math.Min(freeUpgradeCapacity, sourceQuantity);
310  int upgradedRags = Math.Ceil((upgradeQuantity + currentlyUpgraded) / m_BurnTimePerRagEx);
311  upgradedRags = Math.Min(GetRagQuantity(), upgradedRags);
312  m_RagsUpgradedCount = upgradedRags;
313  GetCompEM().AddEnergy(upgradeQuantity);
314  m_ConsumeRagFlipFlop = 0;//consume fuel first
315  if (source)
316  {
317  source.AddQuantity(-upgradeQuantity);
318  }
319  CalculateQuantity();
320  UpdateCheckForReceivingUpgrade();
321  }
322 
323 
324 
325  void ConsumeFuelFromBottle(ItemBase vessel)
326  {
327  if (vessel)
328  {
329  float vessel_quant = vessel.GetQuantity();
330 
331  float available_vessel_quant = vessel_quant;
332 
333  if ( available_vessel_quant > m_MaxConsumableFuelQuantityEx )
334  available_vessel_quant = m_MaxConsumableFuelQuantityEx;
335 
336  float available_vessel_coef = available_vessel_quant / m_MaxConsumableFuelQuantityEx;
337 
338  float add_energy = m_BurnTimePerFullFuelDoseEx * available_vessel_coef;
339  float add_energy_coef = 1;
340 
341  float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
342 
343  if (add_energy > energy_limit )
344  {
345  add_energy_coef = energy_limit / add_energy;
346  add_energy = energy_limit;
347  available_vessel_quant = available_vessel_quant * add_energy_coef;
348  }
349 
350  GetCompEM().AddEnergy( add_energy );
351  vessel.AddQuantity(-available_vessel_quant);
352 
353  CalculateQuantity();
354 
355  UpdateCheckForReceivingUpgrade();
356  }
357  }
358 
359  void ConsumeFuelFromGasStation()
360  {
361  float add_energy = m_BurnTimePerFullFuelDoseEx;
362  float add_energy_coef = 1;
363 
364  float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
365 
366  if (add_energy > energy_limit )
367  {
368  add_energy_coef = energy_limit / add_energy;
369  add_energy = energy_limit;
370  }
371 
372  GetCompEM().AddEnergy( add_energy );
373  CalculateQuantity();
374  UpdateCheckForReceivingUpgrade();
375  }
376 
377  void RuinRags()
378  {
379  ItemBase rag = GetRag();
380 
381  if (rag)
382  {
383  rag.SetHealth(1); //does not actually ruin rags, combining would be impossible
384  }
385  }
386 
387  // Inventory manipulation
388  override void OnInventoryExit(Man player)
389  {
390  super.OnInventoryExit(player);
391 
392  StandUp();
393  }
394 
395  // Stands up the torch, if possible. Returns true on success.
396  bool StandUp()
397  {
398  string surface_type;
399  vector position = GetPosition();
400  GetGame().SurfaceGetType ( position[0], position[2], surface_type );
401  bool is_surface_soft = GetGame().IsSurfaceDigable(surface_type);
402 
403  if ( is_surface_soft && !IsRuined() )
404  {
405  vector ori_rotate = "0 0 0";
406  ori_rotate[0] = Math.RandomFloat(0, 360);
407  ori_rotate[1] = Math.RandomFloat(0, 10);
408  SetOrientation(ori_rotate);
409 
410  return true; // I am standing up
411  }
412 
413  return false; // I am NOT standing up
414  }
415 
416  void CalculateQuantity()
417  {
418  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
419  {
420  SetQuantityNormalized(GetCompEM().GetEnergy0To1());
421  }
422  }
423 
424  bool CanReceiveUpgrade()
425  {
426  return m_CanReceiveUpgrade;
427  }
428 
429  void CraftingInit(float quantity)
430  {
431  GetCompEM().SetEnergy(m_BurnTimePerRagEx * quantity);
432  m_CanReceiveUpgrade = true;
433  SetSynchDirty();
434  }
435 
436 
437  override void EEItemAttached( EntityAI item, string slot_name )
438  {
439  super.EEItemAttached( item, slot_name );
440  CalculateQuantity();
441  UpdateCheckForReceivingUpgrade();
442  }
443 
444 
445  override void EEItemDetached( EntityAI item, string slot_name )
446  {
447  super.EEItemDetached( item, slot_name );
448 
449  if (m_IsBeingDestructed)
450  {
451  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
452  {
453  EntityAI rags = EntityAI.Cast(GetGame().CreateObjectEx(item.GetType(), GetPosition(), ECE_PLACE_ON_SURFACE));
454  if( rags )
455  MiscGameplayFunctions.TransferItemProperties(item, rags);
456  }
457  return;
458  }
459 
460  CalculateQuantity();
461  UpdateCheckForReceivingUpgrade();
462  GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( TryTransformIntoStick, 100);
463  }
464 
465  bool CanTransformIntoStick()
466  {
467  if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && !IsIgnited() && !GetRag() && !IsSetForDeletion() )
468  return true;
469  else
470  return false;
471  }
472 
473  void TryTransformIntoStick()
474  {
475  PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
476  if ( m_IsBeingDestructed || (player && player.IsPlayerDisconnected()) )
477  return;
478 
479  if ( CanTransformIntoStick() )
480  {
481  m_IsBeingDestructed = true;
482  if (player)
483  {
484  // Transform object into wooden stick
485  StopAllParticles();
486 
487  TorchLambda lambda = new TorchLambda(this, m_DecraftResult);
488  player.ServerReplaceItemInHandsWithNew(lambda);
489  }
490  else
491  {
492  // Create wooden stick and delete Torch
493  vector pos = GetPosition();
494  vector ori = GetOrientation();
495 
496  if ( GetType() == "WoodenStick" )
497  ori = ori + Vector(0,90,0);
498 
499  ItemBase stick = ItemBase.Cast( GetGame().CreateObjectEx(m_DecraftResult, pos, ECE_PLACE_ON_SURFACE) );
500  ApplyResultModifications(stick);
501  stick.SetPosition(pos);
502  stick.PlaceOnSurface();
503 
504  if ( stick.GetType() == "LongWoodenStick" )
505  {
506  pos = stick.GetPosition() + Vector(0,-0.3,0);
507  stick.SetPosition(pos);
508  }
509 
510  stick.SetOrientation(ori);
511  GetGame().ObjectDelete(this);
512  }
513  }
514  }
515 
516 
517  override void OnWorkStart()
518  {
519  m_WasLit = true;
520  LockRags(true);
521  UpdateMaterial();
522  }
523 
524  void StopAllParticles()
525  {
526  if (m_FireParticle)
527  {
528  m_FireParticle.Stop();
529  }
530  }
531 
532  Rag GetRag()
533  {
534  return Rag.Cast( GetAttachmentByType(Rag) );
535  }
536 
537  void LockRags(bool do_lock)
538  {
539  ItemBase rag = GetRag();
540  if (rag)
541  {
542  if (do_lock)
543  {
544  rag.LockToParent();
545  }
546  else if (!m_RagsUpgradedCount)
547  {
548  rag.UnlockFromParent();
549  }
550  }
551  }
552 
553  void UpdateLight()
554  {
555  if (!m_Light)
556  {
557  m_Light = TorchLight.Cast( ScriptedLightBase.CreateLight( TorchLight, Vector(0,0,0), 1 ) );
558  m_Light.AttachOnObject(this, m_ParticleLocalPos + Vector (0,0.2,0));
559  }
560 
561  if (m_FireParticle)
562  {
563  Object direct_particle = m_FireParticle.GetDirectParticleEffect();
564 
565  if (direct_particle && direct_particle != m_Light.GetAttachmentParent())
566  {
567  m_Light.AttachOnObject(direct_particle, Vector(0,0.2,0));
568  }
569  }
570 
571  float update_interval = GetCompEM().GetUpdateInterval();
572 
573  if (GetQuantity() <= m_StartFadeOutOfLightAtQuantityEx)
574  {
575  float brightness_coef = GetQuantity() / m_StartFadeOutOfLightAtQuantityEx;
576  float radius_coef = GetQuantity() / m_StartFadeOutOfLightAtQuantityEx;
577 
578  if (radius_coef < m_StartFadeOutOfLightAtQuantityEx/10)
579  radius_coef = m_StartFadeOutOfLightAtQuantityEx/10;
580 
581  if (brightness_coef < m_StartFadeOutOfLightAtQuantityEx/10)
582  brightness_coef = m_StartFadeOutOfLightAtQuantityEx/10;
583 
584  m_Light.FadeBrightnessTo(m_Light.m_TorchBrightness * brightness_coef, update_interval);
585  m_Light.FadeRadiusTo(m_Light.m_TorchRadius * radius_coef, update_interval);
586  }
587  else
588  {
589  m_Light.FadeBrightnessTo(m_Light.m_TorchBrightness, update_interval);
590  m_Light.FadeRadiusTo(m_Light.m_TorchRadius, update_interval);
591  }
592  }
593 
594  override void OnItemInHandsPlayerSwimStart(PlayerBase player)
595  {
596  GetCompEM().SwitchOff();
597  }
598 
599 
600  override void OnWork( float consumed_energy )
601  {
602  UpdateMaterial();
603  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
604  {
605  if (GetCompEM().GetEnergy() < ((GetRagQuantity() + m_RagsUpgradedCount) - 1) * m_BurnTimePerRagEx)
606  {
607  if (m_RagsUpgradedCount==0)//always burn rag
608  {
609  ConsumeRag();
610  }
611  else if (m_ConsumeRagFlipFlop)//burn rag
612  {
613  ConsumeRag();
614  m_ConsumeRagFlipFlop = !m_ConsumeRagFlipFlop;
615  }
616  else//burn lard/fuel
617  {
618  m_RagsUpgradedCount--;
619  m_ConsumeRagFlipFlop = !m_ConsumeRagFlipFlop;
620  }
621  }
622  if (GetRag() && GetCompEM().GetEnergy() == 0 && GetRagQuantity() > 0)
623  {
624  GetRag().SetQuantity(0);
625  }
626  RuinRags();
627 
628  CalculateQuantity();
629 
630  UpdateCheckForReceivingUpgrade();
631 
632  AddWet( -m_WaterEvaporationByFireIntensityEx * GetCompEM().GetUpdateInterval() );
633 
634  Rag rag = GetRag();
635 
636  if ( rag )
637  {
638  rag.AddWet( -m_WaterEvaporationByFireIntensityEx * GetCompEM().GetUpdateInterval() );
639  }
640  }
641 
642  if ( !m_LoopSoundEntity && GetGame() && ( !GetGame().IsDedicatedServer() ) )
643  {
644  m_LoopSoundEntity = PlaySoundLoop(GetSoundName(), 50);
645  }
646 
647  // Effect scaling by fuel
648  if ( !GetGame().IsDedicatedServer() )
649  {
650  UpdateLight();
651  UpdateParticle();
652  }
653  }
654 
655 
656  string GetSoundName()
657  {
658  return "torchLoop";
659  }
660 
661  void UpdateParticle()
662  {
663  if ( GetQuantity() < 40 )
664  {
665  if (!m_FireParticle)
666  m_FireParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.TORCH_T1, this, m_ParticleLocalPos);
667 
668  float scale = GetQuantity() / 40;
669 
670  if (scale > 1)
671  scale = 1;
672 
673  if (scale < 0.25)
674  scale = 0.25;
675 
676  m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.SIZE, scale);
677  m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.VELOCITY, scale);
678  m_FireParticle.ScaleParticleParamFromOriginal(EmitorParam.VELOCITY_RND, scale);
679  }
680  else
681  {
682  if ( !m_FireParticle || m_FireParticle.GetParticleID() != ParticleList.TORCH_T2 )
683  {
684  // Executes once when fire particle starts or changes
685 
686  if (m_FireParticle)
687  m_FireParticle.Stop();
688 
689  m_FireParticle = ParticleManager.GetInstance().PlayOnObject(ParticleList.TORCH_T2, this, m_ParticleLocalPos);
690  }
691  }
692 
693  }
694 
695  override void OnWorkStop()
696  {
697  UpdateMaterial();
698  if (m_Light)
699  m_Light.FadeOut();
700 
701  if ( m_LoopSoundEntity && GetGame() && ( !GetGame().IsDedicatedServer() ) )
702  {
703  GetGame().ObjectDelete( m_LoopSoundEntity );
704  m_LoopSoundEntity = NULL;
705  }
706 
707  if ( m_FireParticle)
708  {
709  m_FireParticle.Stop();
710  m_FireParticle = NULL;
711  }
712 
713  CalculateQuantity();
714  UpdateCheckForReceivingUpgrade();
715 
716  LockRags(false);
717 
718  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
719  {
720  if (GetRag() && GetCompEM().GetEnergy() == 0 && GetRagQuantity() > 0)
721  {
722  GetRag().SetQuantity(0);
723  }
724  }
725 
726  TryTransformIntoStick();
727  }
728 
729  // COMBAT
730  // This needs refactor!
731  override int GetMeleeMode()
732  {
733  if ( GetCompEM().IsWorking() )
734  return 3; // ???
735  else
736  return 0; // ???
737  }
738 
739  override int GetMeleeHeavyMode()
740  {
741  if ( GetCompEM().IsWorking() )
742  return 4; // ???
743  else
744  return 1; // ???
745  }
746 
747  override int GetMeleeSprintMode()
748  {
749  if ( GetCompEM().IsWorking() )
750  return 5; // ???
751  else
752  return 2; // ???
753  }
754 
755  override void SetActions()
756  {
757  super.SetActions();
758 
760  }
761 
762  override void OnAttachmentQuantityChangedEx(ItemBase item, float delta)
763  {
764  super.OnAttachmentQuantityChangedEx(item, delta);
765  if (delta > 0)
766  {
767  GetCompEM().AddEnergy(m_BurnTimePerRagEx * delta);
768  CalculateQuantity();
769  UpdateCheckForReceivingUpgrade();
770  }
771  }
772 
773 
774  override bool DisassembleOnLastDetach()
775  {
776  return true;
777  }
778 
779  override void OnDebugSpawn()
780  {
781  GetInventory().CreateAttachment("Rag");
782  CraftingInit(GetRagQuantity());
783  CalculateQuantity();
784  }
785 
786  int GetRagQuantity()
787  {
788  if (GetRag())
789  {
790  return Math.Round(GetRag().GetQuantity());
791  }
792  return 0;
793  }
794 
795  string GetBurningMaterial()
796  {
797  return "";
798  }
799 
800  string GetBurntMaterial()
801  {
802  return "";
803  }
804 
805  void UpdateMaterial()
806  {
807  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
808  {
809  if (GetCompEM().IsWorking())
810  {
811  if (GetBurningMaterial())
812  {
813  SetObjectMaterial(0, GetBurningMaterial());
814  }
815  }
816  else if (m_WasLit)
817  {
818  if (GetBurntMaterial())
819  {
820  SetObjectMaterial(0, GetBurntMaterial());
821  }
822  }
823  }
824  }
825 
826 
827  override void OnStoreSave(ParamsWriteContext ctx)
828  {
829  super.OnStoreSave(ctx);
830  ctx.Write(m_WasLit);
831  }
832 
833 
834  override bool OnStoreLoad( ParamsReadContext ctx, int version )
835  {
836  if (!super.OnStoreLoad(ctx, version))
837  {
838  return false;
839  }
840  if (version >= 130)
841  {
842  if (!ctx.Read( m_WasLit ))
843  {
844  return false;
845  }
846  }
847  UpdateMaterial();
848  return true;
849  }
850 
851  void ApplyResultModifications(ItemBase result)
852  {
853  result.SetQuantity(1);
854  }
855 
856  //-------------
857  // DEBUG BELLOW
858  //-------------
859  #ifdef DEVELOPER
860  override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
861  {
862  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Ignite", FadeColors.LIGHT_GREY));
863  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
864 
865  super.GetDebugActions(outputList);
866  }
867 
868  override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
869  {
870  if (super.OnAction(action_id, player, ctx))
871  return true;
872  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
873  {
874  if (action_id == EActions.ACTIVATE_ENTITY)
875  {
876  OnIgnitedThis(null);
877  }
878 
879  }
880  return false;
881  }
882 
883  override string GetDebugText()
884  {
885  string debug_output;
886 
887  debug_output = super.GetDebugText();
888 
889  if( GetGame().IsDedicatedServer())
890  {
891  debug_output+="m_RagsUpgradedCount:"+m_RagsUpgradedCount+"\n";
892  debug_output+="m_ConsumeRagFlipFlop:"+m_ConsumeRagFlipFlop+"\n";
893  if (IsIgnited() && m_ConsumeRagFlipFlop)
894  {
895  debug_output+="Burning rag \n";
896  }
897  else if (IsIgnited())
898  {
899  debug_output+="Burning lard/fuel \n";
900  }
901  }
902  else
903  {
904 
905  }
906  return debug_output;
907  }
908  #endif
909 }
910 
911 
912 class Torch : FlammableBase
913 {
914  //legacy vars which cannot be moved/removed
915  static float m_BurnTimePerRag;
916  static float m_BurnTimePerFullLard;
917  static float m_BurnTimePerFullFuelDose;
918  static float m_MaxConsumableLardQuantity;
919  static float m_MaxConsumableFuelQuantity;
920  static float m_WaterEvaporationByFireIntensity = 0.001;
921  static int m_StartFadeOutOfLightAtQuantity = 3;
922 
923 
924  override void Init()
925  {
926  super.Init();
927 
928  //for legacy reasons
929  m_BurnTimePerRag = m_BurnTimePerRagEx;
930  m_BurnTimePerFullLard = m_BurnTimePerFullLardEx;
931  m_BurnTimePerFullFuelDose = m_BurnTimePerFullFuelDoseEx;
932  m_MaxConsumableLardQuantity = m_MaxConsumableLardQuantityEx;
933  m_MaxConsumableFuelQuantity = m_MaxConsumableFuelQuantityEx;
934  }
935 
936  override void SetActions()
937  {
938  super.SetActions();
939 
942  }
943 
944  // !Called on CHILD when it's attached to parent.
945  override void OnWasAttached( EntityAI parent, int slot_id )
946  {
947  super.OnWasAttached(parent, slot_id);
948  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
949  LockRags(true);
950  }
951 
952  // !Called on CHILD when it's detached from parent.
953  override void OnWasDetached( EntityAI parent, int slot_id )
954  {
955  super.OnWasDetached(parent, slot_id);
956  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
957  LockRags(false);
958  }
959 
960 
961  override void OnStoreSave(ParamsWriteContext ctx)
962  {
963  super.OnStoreSave(ctx);
964  ctx.Write(m_ConsumeRagFlipFlop);
965  ctx.Write(m_RagsUpgradedCount);
966  }
967 
968 
969  override bool OnStoreLoad( ParamsReadContext ctx, int version )
970  {
971  if (!super.OnStoreLoad(ctx, version))
972  {
973  return false;
974  }
975 
976  if (version >= 129)
977  {
978  if (!ctx.Read( m_ConsumeRagFlipFlop ))
979  {
980  return false;
981  }
982 
983  if (!ctx.Read( m_RagsUpgradedCount ))
984  {
985  return false;
986  }
987  }
988  UpdateCheckForReceivingUpgrade();
989  return true;
990  }
991 };
992 
994 {
995  override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
996  {
997  super.CopyOldPropertiesToNew(old_item, new_item);
998 
999  ItemBase stick;
1000  FlammableBase flammable = FlammableBase.Cast(old_item);
1001  Class.CastTo(stick, new_item);
1002  if (stick && flammable)
1003  {
1004  flammable.ApplyResultModifications(stick);
1005  }
1006  }
1007 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
m_UTSource
protected ref UniversalTemperatureSource m_UTSource
Definition: fireplacebase.c:224
OnWasAttached
override void OnWasAttached(EntityAI parent, int slot_id)
Definition: torch.c:945
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
ActionUpgradeTorchFromGasPump
Definition: actionupgradetorchfromgaspump.c:9
TorchLambda
Definition: torch.c:993
OnStoreLoad
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: torch.c:969
Init
override void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
Definition: torch.c:924
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
GetQuantity
override float GetQuantity()
Definition: itembase.c:3316
UniversalTemperatureSource
original Timer deletes m_params which is unwanted
Definition: universaltemperaturesource.c:25
SetActions
override void SetActions()
Definition: torch.c:936
EmitorParam
EmitorParam
Definition: envisual.c:113
m_UTSSettings
protected ref UniversalTemperatureSourceSettings m_UTSSettings
Definition: fireplacebase.c:225
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
UniversalTemperatureSourceSettings
Definition: universaltemperaturesource.c:1
OnWasDetached
override void OnWasDetached(EntityAI parent, int slot_id)
Definition: torch.c:953
ActionRefuelTorch
Definition: actionrefueltorch.c:1
ActionLightItemOnFire
ActionLightItemOnFireCB ActionContinuousBaseCB ActionLightItemOnFire()
Definition: actionlightitemonfire.c:11
GetDebugText
string GetDebugText()
Definition: modifierbase.c:68
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
ScriptedLightBase
Definition: pointlightbase.c:1
AddWet
override void AddWet(float value)
Definition: itembase.c:3592
GetDebugActions
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition: edible_base.c:744
m_BurnTimePerRag
FlammableBase m_BurnTimePerRag
EActions
EActions
Definition: eactions.c:1
OnAction
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition: edible_base.c:755
SetQuantityNormalized
void SetQuantityNormalized(float value, bool destroy_config=true, bool destroy_forced=false)
Sets quantity in normalized 0..1 form between the item's Min a Max values as defined by item's config...
Definition: itembase.c:3239
OnStoreSave
override void OnStoreSave(ParamsWriteContext ctx)
Definition: torch.c:961
GetEnergy
float GetEnergy()
Definition: itembase.c:3461
SAT_DEBUG_ACTION
const int SAT_DEBUG_ACTION
Definition: constants.c:424
ReplaceItemWithNewLambdaBase
base class for transformation operations (creating one item from another)
Definition: replaceitemwithnewlambdabase.c:4
FlammableBase
Definition: torch.c:1
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
GetOrientation
vector GetOrientation()
Definition: areadamagemanager.c:306