Xonotic
globalsound.qc File Reference
#include "globalsound.qh"
#include <common/ent_cs.qh>
#include <common/animdecide.qh>
+ Include dependency graph for globalsound.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

string _GetPlayerSoundSampleField (string type, bool voice)
 
void ClearPlayerSounds (entity this)
 
entity GetPlayerSound (string type)
 
string GetPlayerSoundSampleField (string type)
 
entity GetVoiceMessage (string type)
 
string GetVoiceMessageSampleField (string type)
 
float GlobalSound_pitch (float _pitch)
 
string GlobalSound_sample (string pair, float r)
 
bool LoadPlayerSounds (entity this, string f, bool strict)
 
void PrecacheGlobalSound (string sample)
 
void PrecachePlayerSounds (string f)
 
void UpdatePlayerSounds (entity this)
 

Variables

bool autocvar_g_debug_defaultsounds
 
string model_for_playersound
 
int skin_for_playersound
 

Function Documentation

◆ _GetPlayerSoundSampleField()

string _GetPlayerSoundSampleField ( string  type,
bool  voice 
)

Definition at line 208 of file globalsound.qc.

References entity(), GetPlayerSound(), GetPlayerSoundSampleField_notFound, and GetVoiceMessage().

Referenced by GetPlayerSoundSampleField(), and GetVoiceMessageSampleField().

209  {
211  entity e = voice ? GetVoiceMessage(type) : GetPlayerSound(type);
212  if (e) return e.m_playersoundfld;
214  return playersound_taunt.m_playersoundfld;
215  }
entity GetPlayerSound(string type)
Definition: globalsound.qc:202
entity() spawn
bool GetPlayerSoundSampleField_notFound
Definition: globalsound.qh:123
entity GetVoiceMessage(string type)
Definition: globalsound.qc:196
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearPlayerSounds()

void ClearPlayerSounds ( entity  this)

Definition at line 252 of file globalsound.qc.

References FOREACH, and strfree.

Referenced by UpdatePlayerSounds().

253  {
254  FOREACH(PlayerSounds, true, {
255  .string fld = it.m_playersoundfld;
256  if (this.(fld))
257  {
258  strfree(this.(fld));
259  }
260  });
261  }
#define strfree(this)
Definition: string.qh:56
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GetPlayerSound()

entity GetPlayerSound ( string  type)

Definition at line 202 of file globalsound.qc.

References FOREACH, and NULL.

Referenced by _GetPlayerSoundSampleField().

203  {
204  FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == false, return it);
205  return NULL;
206  }
#define NULL
Definition: post.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GetPlayerSoundSampleField()

string GetPlayerSoundSampleField ( string  type)

Definition at line 247 of file globalsound.qc.

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

248  {
249  return _GetPlayerSoundSampleField(type, false);
250  }
string _GetPlayerSoundSampleField(string type, bool voice)
Definition: globalsound.qc:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetVoiceMessage()

entity GetVoiceMessage ( string  type)

Definition at line 196 of file globalsound.qc.

References FOREACH, and NULL.

Referenced by _GetPlayerSoundSampleField(), and ClientCommand_voice().

197  {
198  FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it);
199  return NULL;
200  }
#define NULL
Definition: post.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GetVoiceMessageSampleField()

string GetVoiceMessageSampleField ( string  type)

Definition at line 217 of file globalsound.qc.

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

218  {
219  return _GetPlayerSoundSampleField(type, true);
220  }
string _GetPlayerSoundSampleField(string type, bool voice)
Definition: globalsound.qc:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GlobalSound_pitch()

float GlobalSound_pitch ( float  _pitch)

Definition at line 164 of file globalsound.qc.

Referenced by UpdatePlayerSounds().

165  {
166  // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b
167  float a = 1.5; // max pitch
168  float b = 0.75; // min pitch
169  float c = 100; // standard pitch (scale * 100)
170  float d = _pitch;
171  float pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b));
172 
173  return pitch_shift * 100;
174  }
+ Here is the caller graph for this function:

◆ GlobalSound_sample()

string GlobalSound_sample ( string  pair,
float  r 
)

Definition at line 150 of file globalsound.qc.

References car(), cdr(), floor(), and stof().

Referenced by Monster_Sound(), and UpdatePlayerSounds().

151  {
152  int n;
153  {
154  string s = cdr(pair);
155  if (s) n = stof(s);
156  else n = 0;
157  }
158  string sample = car(pair);
159  if (n > 0) sample = sprintf("%s%d.wav", sample, floor(r * n + 1)); // randomization
160  else sample = sprintf("%s.wav", sample);
161  return sample;
162  }
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadPlayerSounds()

bool LoadPlayerSounds ( entity  this,
string  f,
bool  strict 
)

Definition at line 263 of file globalsound.qc.

References argv(), fclose(), fgets(), FILE_READ, fopen(), GetPlayerSoundSampleField(), GetPlayerSoundSampleField_notFound, GetVoiceMessageSampleField(), LOG_TRACEF, LOG_WARNF, strcat(), strcpy, and tokenize_console.

Referenced by UpdatePlayerSounds().

264  {
265  int fh = fopen(f, FILE_READ);
266  if (fh < 0)
267  {
268  if (strict) LOG_WARNF("Player sound file not found: %s", f);
269  return false;
270  }
271  for (string s; (s = fgets(fh)); )
272  {
273  int n = tokenize_console(s);
274  if (n != 3)
275  {
276  if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
277  continue;
278  }
279  string key = argv(0);
280  var.string field = GetPlayerSoundSampleField(key);
283  {
284  LOG_TRACEF("Invalid sound info field in player sound file '%s': %s", f, key);
285  continue;
286  }
287  string file = argv(1);
288  string variants = argv(2);
289  strcpy(this.(field), strcat(file, " ", variants));
290  }
291  fclose(fh);
292  return true;
293  }
const float FILE_READ
Definition: csprogsdefs.qc:231
#define strcpy(this, s)
Definition: string.qh:49
#define LOG_WARNF(...)
Definition: log.qh:67
string GetPlayerSoundSampleField(string type)
Definition: globalsound.qc:247
string GetVoiceMessageSampleField(string type)
Definition: globalsound.qc:217
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
bool GetPlayerSoundSampleField_notFound
Definition: globalsound.qh:123
#define LOG_TRACEF(...)
Definition: log.qh:82
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrecacheGlobalSound()

void PrecacheGlobalSound ( string  sample)

Definition at line 176 of file globalsound.qc.

References car(), cdr(), precache_sound(), and stof().

Referenced by Monster_Sound_Precache(), PRECACHE(), PrecachePlayerSounds(), and STATIC_INIT().

177  {
178  int n;
179  {
180  string s = cdr(sample);
181  if (s) n = stof(s);
182  else n = 0;
183  }
184  sample = car(sample);
185  if (n > 0)
186  {
187  for (int i = 1; i <= n; ++i)
188  precache_sound(sprintf("%s%d.wav", sample, i));
189  }
190  else
191  {
192  precache_sound(sprintf("%s.wav", sample));
193  }
194  }
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrecachePlayerSounds()

void PrecachePlayerSounds ( string  f)

Definition at line 222 of file globalsound.qc.

References argv(), fclose(), fgets(), FILE_READ, fopen(), LOG_WARNF, PrecacheGlobalSound(), strcat(), and tokenize_console.

Referenced by PRECACHE(), and precache_playermodel().

223  {
224  int fh = fopen(f, FILE_READ);
225  if (fh < 0)
226  {
227  LOG_WARNF("Player sound file not found: %s", f);
228  return;
229  }
230  for (string s; (s = fgets(fh)); )
231  {
232  int n = tokenize_console(s);
233  if (n != 3)
234  {
235  if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
236  continue;
237  }
238  string file = argv(1);
239  string variants = argv(2);
240  PrecacheGlobalSound(strcat(file, " ", variants));
241  }
242  fclose(fh);
243  }
const float FILE_READ
Definition: csprogsdefs.qc:231
#define LOG_WARNF(...)
Definition: log.qh:67
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void PrecacheGlobalSound(string sample)
Definition: globalsound.qc:176
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdatePlayerSounds()

void UpdatePlayerSounds ( entity  this)

Definition at line 300 of file globalsound.qc.

References ANIMACTION_TAUNT, animdecide_setaction(), ATTEN_MIN, ATTEN_NONE, ATTEN_NORM, backtrace, classname, ClearPlayerSounds(), CS_CVAR, entity(), FOREACH_CLIENT, get_model_datafilename(), GlobalSound_pitch(), GlobalSound_sample(), IS_DEAD, IS_PLAYER, IS_REAL_CLIENT, LoadPlayerSounds(), model, model_for_playersound, MSG_ALL, MSG_BROADCAST, msg_entity, MSG_ONE, NULL, pusher, random(), SAME_TEAM, scale, skin, skin_for_playersound, strcpy, VOICETYPE_AUTOTAUNT, VOICETYPE_LASTATTACKER, VOICETYPE_LASTATTACKER_ONLY, VOICETYPE_PLAYERSOUND, VOICETYPE_TAUNT, VOICETYPE_TEAMRADIO, VOL_BASE, and X.

Referenced by FixPlayermodel(), and setplayermodel().

301  {
302  if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return;
303  strcpy(this.model_for_playersound, this.model);
304  this.skin_for_playersound = this.skin;
305  ClearPlayerSounds(this);
306  LoadPlayerSounds(this, "sound/player/default.sounds", true);
307  if (this.model == "null"
308  #ifdef SVQC
309  && autocvar_g_debug_globalsounds
310  #endif
311  ) return;
312  if (autocvar_g_debug_defaultsounds) return;
313  if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return;
314  LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true);
315  }
string get_model_datafilename(string m, float sk, string fil)
Definition: util.qc:1245
skin
Definition: ent_cs.qc:143
int skin_for_playersound
Definition: globalsound.qc:296
string model
Definition: csprogsdefs.qc:108
#define strcpy(this, s)
Definition: string.qh:49
bool LoadPlayerSounds(entity this, string f, bool strict)
Definition: globalsound.qc:263
void ClearPlayerSounds(entity this)
Definition: globalsound.qc:252
bool autocvar_g_debug_defaultsounds
Definition: globalsound.qc:298
string model_for_playersound
Definition: globalsound.qc:295
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ autocvar_g_debug_defaultsounds

bool autocvar_g_debug_defaultsounds

Definition at line 298 of file globalsound.qc.

◆ model_for_playersound

string model_for_playersound

Definition at line 295 of file globalsound.qc.

Referenced by UpdatePlayerSounds().

◆ skin_for_playersound

int skin_for_playersound

Definition at line 296 of file globalsound.qc.

Referenced by UpdatePlayerSounds().