Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BellSoundComponent.c
Go to the documentation of this file.
3 {
4  [Attribute("", UIWidgets.EditBox, "")]
5  float m_fBellTime;
6 
7  [Attribute("", UIWidgets.EditBox, "")]
8  int m_iRepetitionCount;
9 }
10 
11 [ComponentEditorProps(category: "GameScripted/Sound", description: "Bell Sound Component")]
12 class SCR_BellSoundComponentClass : SoundComponentClass
13 {
14 }
15 
16 class SCR_BellSoundComponent : SoundComponent
17 {
18  [Attribute("", UIWidgets.Object, "Time settings")]
19  ref array<ref SCR_SoundBellTime> m_aSoundBellTime;
20 
21  private static GameSignalsManager m_GameSignalManager;
22  private int m_iTimeOfDaySignalIdx;
23 
24  private const float TRIGGER_INTERVAL = 850;
25 
26  protected float m_fTimer;
27  protected float m_fTimeOfDayValueLast;
28 
29  protected int m_iBellTimeIdx = -1;
30  protected int m_iSoundBellTimeCount;
31  protected int m_iRepetitionCount;
32 
33  private float m_fWorldTimeLast;
34 
35  //------------------------------------------------------------------------------------------------
36  override void UpdateSoundJob(IEntity owner, float timeSlice)
37  {
38  // UpdateSoundJob only once pref frame
39  float worldTime = owner.GetWorld().GetWorldTime();
40 
41  if (m_fWorldTimeLast == worldTime)
42  return;
43 
44  float dt = worldTime - m_fWorldTimeLast;
45  float timeOfDay = m_GameSignalManager.GetSignalValue(m_iTimeOfDaySignalIdx) * 24;
46 
47  if (m_iRepetitionCount != 0)
48  {
49  m_fTimer += dt;
50 
51  if (m_fTimer > TRIGGER_INTERVAL)
52  {
53  //Play sound
54  string eventName;
55 
56  if (m_iRepetitionCount == 1)
57  {
58  eventName = SCR_SoundEvent.SOUND_BELL_END;
59  }
60  else if (m_iRepetitionCount%2 == 0)
61  {
62  eventName = SCR_SoundEvent.SOUND_BELL_A;
63  }
64  else
65  {
66  eventName = SCR_SoundEvent.SOUND_BELL_B;
67  }
68 
69  SoundEvent(eventName);
70 
72  m_fTimer = 0;
73  }
74  }
75  else
76  {
77  // Get m_iBellTimeIdx
78  if (m_iBellTimeIdx == - 1)
79  {
80  m_iBellTimeIdx = 0;
81 
82  for (int i = 0; i < m_iSoundBellTimeCount; i++)
83  {
84  if (m_aSoundBellTime[i].m_fBellTime > timeOfDay)
85  {
86  m_iBellTimeIdx = i;
87  break;
88  }
89  }
90  }
91 
92  // OnFrame check if sound should be triggered
93  if (m_aSoundBellTime[m_iBellTimeIdx].m_fBellTime < timeOfDay && m_aSoundBellTime[m_iBellTimeIdx].m_fBellTime >= m_fTimeOfDayValueLast)
94  {
95  m_iRepetitionCount = m_aSoundBellTime[m_iBellTimeIdx].m_iRepetitionCount;
96  m_iBellTimeIdx = -1;
97  }
98  }
99 
100  // Set Last values
101  m_fTimeOfDayValueLast = timeOfDay;
102  m_fWorldTimeLast = worldTime;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  override void OnUpdateSoundJobBegin(IEntity owner)
107  {
108  m_fTimeOfDayValueLast = m_GameSignalManager.GetSignalValue(m_iTimeOfDaySignalIdx) * 24;
109  m_iRepetitionCount = 0;
110  m_iBellTimeIdx = -1;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void OnPostInit(IEntity owner)
115  {
116  super.OnPostInit(owner);
117 
118  // Set Init
119  SetEventMask(owner, EntityEvent.INIT);
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override void OnInit(IEntity owner)
124  {
125  // Get m_aSoundBellTime count
126  m_iSoundBellTimeCount = m_aSoundBellTime.Count();
127 
128  // Disable OnFrame if no time is defined
129  if (m_iSoundBellTimeCount == 0)
130  {
131  SetScriptedMethodsCall(false);
132  return;
133  }
134 
135  // Get GameSignalsManager
136  m_GameSignalManager = GetGame().GetSignalsManager();
137 
138  m_iTimeOfDaySignalIdx = m_GameSignalManager.AddOrFindSignal("TimeOfDay");
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  // constructor
146  void SCR_BellSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
147  {
148  SetScriptedMethodsCall(true);
149  }
150 }
SCR_BellSoundComponent
Definition: SCR_BellSoundComponent.c:16
ComponentEditorProps
class SCR_SoundBellTime ComponentEditorProps(category:"GameScripted/Sound", description:"Bell Sound Component")
Definition: SCR_BellSoundComponent.c:11
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SoundComponentClass
Definition: SoundComponent.c:12
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
SoundEvent
SoundComponentClass SimpleSoundComponentClass SoundEvent(string eventName)
Play a sound from the owner entity's position.
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_iRepetitionCount
int m_iRepetitionCount
Definition: SCR_BellSoundComponent.c:6
SCR_SoundBellTime
Definition: SCR_BellSoundComponent.c:2
GameSignalsManager
Definition: GameSignalsManager.c:7
m_fBellTime
float m_fBellTime
Definition: SCR_BellSoundComponent.c:3
SetScriptedMethodsCall
proto external void SetScriptedMethodsCall(bool state)
Set flag for script callbacks.
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180