Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CommunicationSoundComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/ScriptWizard", description: "")]
3 {
4 }
5 
6 enum ECP_VehicleRoles
7 {
8  DRIVER,
9  GUNNER,
10  COMMANDER,
11  PILOT,
12  COPILOT,
13  OPERATOR,
14  PASSANGER // TODO: PASSENGER
15 }
16 
17 enum ECP_Characters
18 {
19  MAN,
20  SOLDIER,
22  SNIPER,
23  RECON,
24  AT_SOLDIER,
25  OFFICER,
26  RADIO_MAN
27 }
28 
29 enum ECP_VehicleTypes
30 {
31  VEHICLE,
32  CAR,
33  TRUCK,
34  APC,
35  FUEL_TRUCK,
36  COMM_TRUCK,
38  MORTAR,
39  HELICOPTER,
40 }
41 
42 enum SCR_ECommunicationSoundEventPriority
43 {
44  SOUND_NONE = 0,
45  SOUND_BREATH = 10,
46  SOUND_PAIN_RELIEVE = 80,
47  SOUND_HIT = 90,
48  SOUND_DEATH = 98,
49  SOUND_KNOCKOUT = 99
50 }
51 
52 class SCR_CommunicationSoundComponent : CommunicationSoundComponent
53 {
54  protected SignalsManagerComponent m_SignalsManagerComponent;
55  private static const int SUBTITLES_MAX_DISTANCE = 20;
56  static const int DEFAULT_EVENT_PRIORITY_DELAY = 100;
57  private static const string DAMAGE_TYPE_SIGNAL_NAME = "DamageType";
58  private static const string HIT_SCREAM_INTENSITY_SIGNAL_NAME = "HitScreamIntensity";
59 
60  protected string m_sDelayedSoundEvent;
61  protected SCR_ECommunicationSoundEventPriority m_eDelayedSoundEventPriority;
62  protected EDamageType m_eEDamageType;
63  protected int m_iHitScreamIntensity;
64 
65  protected int m_iDamageTypeSignalIdx;
66  protected int m_iHitScreamIntensitySignalIdx;
67 
68  protected static bool m_bShowSubtitles;
69 
70  //------------------------------------------------------------------------------------------------
73  void ShowSubtitles(array<string> metadata)
74  {
75  int size = metadata.Count();
76 
77  if (size > 10)
78  {
79  Print("Too many metadata. Metadata size = " + size.ToString(), LogLevel.ERROR);
80  return;
81  }
82 
83  // Get text
84  int textIdx = -1;
85 
86  for (int i = size - 1; i >= 0; i--)
87  {
88  if (!metadata[i].IsEmpty())
89  {
90  textIdx = i;
91  break;
92  }
93  }
94 
95  // Do not show subtitles if metadata is empty
96  if (textIdx == -1)
97  return;
98 
99  // Get parameters
100  string param[9];
101  int paramIndex;
102 
103  for (int i = 0; i < textIdx; i++)
104  {
105  if (!metadata[i].IsEmpty())
106  {
107  param[paramIndex] = metadata[i];
108  paramIndex++;
109  }
110  }
111 
112  // Show subtitles
113  // Subtitles printed to the chat - old way
114  string localizedText = WidgetManager.Translate(metadata[textIdx], param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7], param[8]);
115 
116  SCR_ChatComponent.RadioProtocolMessage(localizedText);
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  // Inserted to OnUserSettingsChangedInvoker() on SCR_UISoundEntity
121  static void SetSubtitiles()
122  {
123  BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_GameplaySettings");
124  if (settings)
125  settings.Get("m_bShowRadioProtocolText", m_bShowSubtitles);
126  }
127 
128  //------------------------------------------------------------------------------------------------
134  void SetCallsignSignals(int company, int platoon, int squad, int character, int characterRole)
135  {
137  return;
138 
139  m_SignalsManagerComponent.SetSignalValue(m_SignalsManagerComponent.AddOrFindSignal("CompanyCaller"), company);
140  m_SignalsManagerComponent.SetSignalValue(m_SignalsManagerComponent.AddOrFindSignal("PlattonCaller"), platoon);
141  m_SignalsManagerComponent.SetSignalValue(m_SignalsManagerComponent.AddOrFindSignal("SquadCaller"), squad);
142  m_SignalsManagerComponent.SetSignalValue(m_SignalsManagerComponent.AddOrFindSignal("SoldierCaller"), character -1);
143  }
144 
145  //------------------------------------------------------------------------------------------------
149  void SoundEventHit(bool critical, EDamageType damageType)
150  {
151  if (critical)
152  m_iHitScreamIntensity += 1;
153 
154  SCR_ECommunicationSoundEventPriority priority = SCR_ECommunicationSoundEventPriority.SOUND_HIT + m_iHitScreamIntensity;
155  if (priority >= SCR_ECommunicationSoundEventPriority.SOUND_DEATH)
156  priority = SCR_ECommunicationSoundEventPriority.SOUND_DEATH - 1;
157 
158  DelayedSoundEventPriority(SCR_SoundEvent.SOUND_HIT, priority, DEFAULT_EVENT_PRIORITY_DELAY, damageType);
159  }
160 
161  //------------------------------------------------------------------------------------------------
167  void DelayedSoundEventPriority(string eventName, SCR_ECommunicationSoundEventPriority priority, int delayMS, EDamageType damageType = EDamageType.TRUE)
168  {
169  if (priority < m_eDelayedSoundEventPriority)
170  return;
171 
172  m_sDelayedSoundEvent = eventName;
173  m_eDelayedSoundEventPriority = priority;
174  m_eEDamageType = damageType;
175 
176  ScriptCallQueue queue = GetGame().GetCallqueue();
177 
178  int remainingTime = queue.GetRemainingTime(PlayDelayedSoundEventPriority);
179 
180  if (delayMS < remainingTime)
181  {
182  queue.Remove(PlayDelayedSoundEventPriority);
183  remainingTime = 0;
184  }
185 
186  if (remainingTime <= 0)
187  queue.CallLater(PlayDelayedSoundEventPriority, delayMS);
188  }
189 
190  //------------------------------------------------------------------------------------------------
193  void PlayDelayedSoundEventPriority()
194  {
196  {
197  m_SignalsManagerComponent.SetSignalValue(m_iDamageTypeSignalIdx, m_eEDamageType);
198  m_SignalsManagerComponent.SetSignalValue(m_iHitScreamIntensitySignalIdx, m_iHitScreamIntensity);
199  }
200 
201  SoundEventPriority(m_sDelayedSoundEvent, m_eDelayedSoundEventPriority, true);
202 
203  m_sDelayedSoundEvent = string.Empty;
204  m_eDelayedSoundEventPriority = SCR_ECommunicationSoundEventPriority.SOUND_NONE;
205  m_eEDamageType = EDamageType.TRUE;
206 
207  // Also reset hit scream intensity
208  m_iHitScreamIntensity = 0;
209  }
210 
211  //------------------------------------------------------------------------------------------------
215  void SoundEventDeath(bool silent)
216  {
217  GetGame().GetCallqueue().Remove(DelayedSoundEventPriority);
218 
219  if (silent)
220  SoundEvent(SCR_SoundEvent.SOUND_KNOCKOUT);
221  else
222  SoundEvent(SCR_SoundEvent.SOUND_DEATH);
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  override void OnPostInit(IEntity owner)
227  {
228  SCR_CallsignBaseComponent callsignBaseComponent = SCR_CallsignBaseComponent.Cast(owner.FindComponent(SCR_CallsignBaseComponent));
229  if (callsignBaseComponent)
230  callsignBaseComponent.GetOnCallsignChanged().Insert(SetCallsignSignals);
231 
232  m_SignalsManagerComponent = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
234  {
235  m_iDamageTypeSignalIdx = m_SignalsManagerComponent.AddOrFindSignal(DAMAGE_TYPE_SIGNAL_NAME);
236  m_iHitScreamIntensitySignalIdx = m_SignalsManagerComponent.AddOrFindSignal(HIT_SCREAM_INTENSITY_SIGNAL_NAME);
237  }
238  }
239 
240  //------------------------------------------------------------------------------------------------
241  override void HandleMetadata(array<string> metadata, int priority, float distance)
242  {
243  // Hotfix: Disabled "subtitles"
244  /*
245  if (m_bShowSubtitles && distance < SUBTITLES_MAX_DISTANCE)
246  ShowSubtitles(metadata);
247  */
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  override void OnSoundEventFinished(string eventName, AudioHandle handle, int priority, bool terminated)
252  {
253  // do nothing
254  }
255 
256  //------------------------------------------------------------------------------------------------
257  // constructor
261  void SCR_CommunicationSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
262  {
264  }
265 
266  //------------------------------------------------------------------------------------------------
267  // destructor
268  void ~SCR_CommunicationSoundComponent()
269  {
270  SCR_CallsignBaseComponent callsignBaseComponent = SCR_CallsignBaseComponent.Cast(GetOwner().FindComponent(SCR_CallsignBaseComponent));
271  if (callsignBaseComponent)
272  callsignBaseComponent.GetOnCallsignChanged().Remove(SetCallsignSignals);
273  }
274 }
OFFICER
SCR_CommunicationSoundComponentClass OFFICER
SUPPLY_TRUCK
SCR_CommunicationSoundComponentClass SUPPLY_TRUCK
SoundEventPriority
proto external void SoundEventPriority(string eventName, int priority, bool ignoreQueue=false)
Add a soundevent with priority to the priority queue which will be played in order of priority.
CAR
SCR_CommunicationSoundComponentClass CAR
DRIVER
SCR_CommunicationSoundComponentClass DRIVER
COMMANDER
SCR_CommunicationSoundComponentClass COMMANDER
FUEL_TRUCK
SCR_CommunicationSoundComponentClass FUEL_TRUCK
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
APC
SCR_CommunicationSoundComponentClass APC
OnSoundEventFinished
event void OnSoundEventFinished(string eventName, AudioHandle handle, int priority, bool terminated)
RECON
SCR_CommunicationSoundComponentClass RECON
SOUND_HIT
SCR_CommunicationSoundComponentClass SOUND_HIT
PILOT
SCR_CommunicationSoundComponentClass PILOT
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
MORTAR
SCR_CommunicationSoundComponentClass MORTAR
SOUND_PAIN_RELIEVE
SCR_CommunicationSoundComponentClass SOUND_PAIN_RELIEVE
SCR_CallsignBaseComponent
Component of assigning and storing squad names.
Definition: SCR_CallsignBaseComponent.c:11
VEHICLE
SCR_CommunicationSoundComponentClass VEHICLE
Definition: SCR_QRFGroupConfig.c:5
SoundEvent
SoundComponentClass SimpleSoundComponentClass SoundEvent(string eventName)
Play a sound from the owner entity's position.
OPERATOR
SCR_CommunicationSoundComponentClass OPERATOR
MACHINE_GUNNER
SCR_CommunicationSoundComponentClass MACHINE_GUNNER
GUNNER
SCR_CommunicationSoundComponentClass GUNNER
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
SNIPER
SCR_CommunicationSoundComponentClass SNIPER
SOLDIER
SCR_CommunicationSoundComponentClass SOLDIER
COPILOT
SCR_CommunicationSoundComponentClass COPILOT
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AIConfigComponent.c:72
TRUCK
SCR_CommunicationSoundComponentClass TRUCK
CommunicationSoundComponentClass
Definition: CommunicationSoundComponent.c:12
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_SignalsManagerComponent
protected SignalsManagerComponent m_SignalsManagerComponent
Definition: SCR_SignalsDebugComponent.c:22
HELICOPTER
SCR_CommunicationSoundComponentClass HELICOPTER
MAN
SCR_CommunicationSoundComponentClass MAN
EDamageType
EDamageType
Definition: EDamageType.c:12
HandleMetadata
event protected void HandleMetadata(array< string > metadata, int priority, float distance)
SOUND_NONE
SCR_CommunicationSoundComponentClass SOUND_NONE
AT_SOLDIER
SCR_CommunicationSoundComponentClass AT_SOLDIER
SOUND_DEATH
SCR_CommunicationSoundComponentClass SOUND_DEATH
COMM_TRUCK
SCR_CommunicationSoundComponentClass COMM_TRUCK
SetScriptedMethodsCall
proto external void SetScriptedMethodsCall(bool state)
Set flag for script callbacks.
SOUND_BREATH
SCR_CommunicationSoundComponentClass SOUND_BREATH
SCR_CommunicationSoundComponentClass
Definition: SCR_CommunicationSoundComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180