Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HitZoneStateSignal.c
Go to the documentation of this file.
2 {
3  ref array<ref SCR_HitZone> m_aScriptedHitZones = {};
4  int m_iSignalIdx;
5 
6  //------------------------------------------------------------------------------------------------
7  bool RegisterSignal(SCR_DamageManagerComponent hitZoneContainerComponent, SCR_HitZoneStateSignalData hitZoneStateSignalData, SignalsManagerComponent signalsManagerComponent)
8  {
9  array<string> hitZoneNames = hitZoneStateSignalData.m_aHitZoneNames;
10  if (!hitZoneNames || hitZoneNames.Count() == 0)
11  {
12  Print("AUDIO: SCR_HitZoneStateSignal: Missing HitZoneNames", LogLevel.WARNING);
13  return false;
14  }
15 
16  foreach (string hitZoneName : hitZoneNames)
17  {
18  HitZone hitZone = hitZoneContainerComponent.GetHitZoneByName(hitZoneName);
19  SCR_HitZone hitzone = SCR_HitZone.Cast(hitZone);
20  if (!hitzone)
21  continue;
22 
23  hitzone.GetOnDamageStateChanged().Insert(OnStateChanged);
24  m_aScriptedHitZones.Insert(hitzone);
25  }
26 
27  if (m_aScriptedHitZones.Count() == 0)
28  {
29  Print("AUDIO: SCR_HitZoneStateSignal: No HitZone found", LogLevel.WARNING);
30  return false;
31  }
32 
33  string signalName = hitZoneStateSignalData.m_sSignalName;
34  if (signalName.IsEmpty())
35  {
36  Print("AUDIO: SCR_HitZoneStateSignal: Missing signal name", LogLevel.WARNING);
37  return false;
38  }
39 
40  m_iSignalIdx = signalsManagerComponent.AddOrFindSignal(signalName);
41 
42  return true;
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  void UnregisterSignal()
47  {
48  foreach(SCR_HitZone hitzone : m_aScriptedHitZones)
49  {
50  hitzone.GetOnDamageStateChanged().Remove(OnStateChanged);
51  }
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  protected void OnStateChanged()
56  {
57  int max;
58 
59  foreach(SCR_HitZone hitzone : m_aScriptedHitZones)
60  {
61  int state = DamageStateToSignalValue(hitzone.GetDamageState());
62  if (state > max)
63  max = state;
64  }
65 
66  IEntity owner = m_aScriptedHitZones[0].GetOwner();
67  if (!owner)
68  return;
69 
70  SignalsManagerComponent signalsManager = SignalsManagerComponent.Cast(owner.GetRootParent().FindComponent(SignalsManagerComponent));
71  if (!signalsManager)
72  return;
73 
74  signalsManager.SetSignalValue(m_iSignalIdx, max);
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  static int DamageStateToSignalValue(EDamageState damageState)
79  {
80  switch(damageState)
81  {
82  case EDamageState.UNDAMAGED: {return 0;};
83  case EDamageState.INTERMEDIARY: {return 1;};
84  case EDamageState.STATE1: {return 2;};
85  case EDamageState.STATE2: {return 3;};
86  case EDamageState.STATE3: {return 4;};
87  case EDamageState.DESTROYED: {return 5;};
88  }
89 
90  return 0;
91  }
92 }
SCR_HitZoneStateSignalData
Definition: SCR_HitZoneStateSignalData.c:2
HitZone
Definition: HitZone.c:12
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_HitZoneStateSignal
Definition: SCR_HitZoneStateSignal.c:1
SCR_HitZone
Definition: SCR_HitZone.c:1