Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
globalsound.qh File Reference
#include <server/chat.qh>
Include dependency graph for globalsound.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GlobalSound(this, def, chan, vol, voicetype)
#define GlobalSound_string(this, def, chan, vol, voicetype)
#define PlayerSound(this, def, chan, vol, voicetype, pitchscale)
#define REGISTER_GLOBALSOUND(id, str)
#define REGISTER_PLAYERSOUND(id)
#define REGISTER_VOICEMSG(id, vt, listed)
#define VoiceMessage(this, def, msg)

Functions

void _GlobalSound (entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake, float pitchscale)
void ClearPlayerSounds (entity this)
string GetPlayerSoundSampleField (string type)
entity GetVoiceMessage (string type)
string GetVoiceMessageSampleField (string type)
float GlobalSound_pitch (float _pitch)
string GlobalSound_sample (string pair, float r)
float LoadPlayerSounds (entity this, string f, bool strict)
 PRECACHE (GlobalSounds)
void PrecacheGlobalSound (string samplestring)
void PrecachePlayerSounds (string f)
 REPLICATE_INIT (float, cvar_cl_autotaunt)
 REPLICATE_INIT (float, cvar_cl_voice_directional_taunt_attenuation)
 REPLICATE_INIT (int, cvar_cl_voice_directional)
 STATIC_INIT (allvoicesamples)
 STATIC_INIT (GlobalSounds_renumber)
 STATIC_INIT (PlayerSounds_renumber)
void UpdatePlayerSounds (entity this)

Variables

string allvoicesamples
bool autocvar_g_debug_globalsounds = false
 Use new sound handling.
bool autocvar_sv_autotaunt
bool autocvar_sv_taunt
bool GetPlayerSoundSampleField_notFound
bool instanceOfVoiceMessage
string m_globalsoundstr
string m_playersoundfld
string m_playersoundstr
int m_playersoundvt
const int VOICETYPE_AUTOTAUNT = 14
const int VOICETYPE_LASTATTACKER = 12
const int VOICETYPE_LASTATTACKER_ONLY = 13
const int VOICETYPE_PLAYERSOUND = 10
const int VOICETYPE_TAUNT = 15
const int VOICETYPE_TEAMRADIO = 11

Macro Definition Documentation

◆ GlobalSound

#define GlobalSound ( this,
def,
chan,
vol,
voicetype )
Value:
_GlobalSound(this, def, NULL, string_null, chan, vol, voicetype, false, 1)
void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, float vol, int voicetype, bool fake, float pitchscale)
string string_null
Definition nil.qh:9
#define NULL
Definition post.qh:14

Definition at line 141 of file globalsound.qh.

Referenced by PM_check_hitground(), and PM_Footsteps().

◆ GlobalSound_string

#define GlobalSound_string ( this,
def,
chan,
vol,
voicetype )
Value:
_GlobalSound(this, NULL, NULL, def, chan, vol, voicetype, false, 1)

Definition at line 142 of file globalsound.qh.

◆ PlayerSound

#define PlayerSound ( this,
def,
chan,
vol,
voicetype,
pitchscale )
Value:
_GlobalSound(this, NULL, def, string_null, chan, vol, voicetype, false, pitchscale)

Definition at line 143 of file globalsound.qh.

Referenced by DrownPlayer(), MUTATOR_HOOKFUNCTION(), PlayerDamage(), PlayerJump(), PlayerPreThink(), and PM_dodging().

◆ REGISTER_GLOBALSOUND

#define REGISTER_GLOBALSOUND ( id,
str )
Value:
REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
{ \
this.m_globalsoundstr = str; \
}
int m_id
Definition effect.qh:19
string m_globalsoundstr
#define GlobalSound(this, def, chan, vol, voicetype)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define REGISTER(...)
Register a new entity with a registry.
Definition registry.qh:87

Definition at line 98 of file globalsound.qh.

98#define REGISTER_GLOBALSOUND(id, str) \
99 REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
100 { \
101 this.m_globalsoundstr = str; \
102 }

◆ REGISTER_PLAYERSOUND

#define REGISTER_PLAYERSOUND ( id)
Value:
.string _playersound_##id; \
REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
{ \
this.m_playersoundstr = #id; \
this.m_playersoundfld = _playersound_##id; \
}
void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten, float _pitch)
string m_playersoundfld
string m_playersoundstr
#define PlayerSound(this, def, chan, vol, voicetype, pitchscale)

Definition at line 24 of file globalsound.qh.

24#define REGISTER_PLAYERSOUND(id) \
25 .string _playersound_##id; \
26 REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
27 { \
28 this.m_playersoundstr = #id; \
29 this.m_playersoundfld = _playersound_##id; \
30 }

◆ REGISTER_VOICEMSG

#define REGISTER_VOICEMSG ( id,
vt,
listed )
Value:
.string _playersound_##id; \
REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
{ \
this.instanceOfVoiceMessage = listed; \
this.m_playersoundstr = #id; \
this.m_playersoundfld = _playersound_##id; \
this.m_playersoundvt = vt; \
}
int m_playersoundvt
#define VoiceMessage(this, def, msg)
bool instanceOfVoiceMessage

Definition at line 54 of file globalsound.qh.

54#define REGISTER_VOICEMSG(id, vt, listed) \
55 .string _playersound_##id; \
56 REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
57 { \
58 this.instanceOfVoiceMessage = listed; \
59 this.m_playersoundstr = #id; \
60 this.m_playersoundfld = _playersound_##id; \
61 this.m_playersoundvt = vt; \
62 }

◆ VoiceMessage

#define VoiceMessage ( this,
def,
msg )
Value:
MACRO_BEGIN \
entity VM = def; \
int voicetype = VM.m_playersoundvt; \
bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \
int flood = Say(this, ownteam, NULL, msg, true); \
bool fake; \
if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
else if (flood > 0) fake = false; \
else break; \
_GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake, 1); \
#define true
Definition csprogsdefs.qh:5
#define false
Definition csprogsdefs.qh:6
const int VOICETYPE_TEAMRADIO
#define MACRO_END
Definition macro.qh:7
entity this
Definition self.qh:72
int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodcontrol)
message "": do not say, just test flood control return value: 1 = accept 0 = reject -1 = fake accept
Definition chat.qc:27
const float VOL_BASEVOICE
Definition sound.qh:37
const int CH_VOICE
Definition sound.qh:10
if(frag_attacker.flagcarried)
Definition sv_ctf.qc:2325
#define IS_OBSERVER(v)
Definition utils.qh:11
#define IS_SPEC(v)
Definition utils.qh:10

Definition at line 144 of file globalsound.qh.

144 #define VoiceMessage(this, def, msg) \
145 MACRO_BEGIN \
146 entity VM = def; \
147 int voicetype = VM.m_playersoundvt; \
148 bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \
149 int flood = Say(this, ownteam, NULL, msg, true); \
150 bool fake; \
151 if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
152 else if (flood > 0) fake = false; \
153 else break; \
154 _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake, 1); \
155 MACRO_END

Referenced by ClientCommand_voice().

Function Documentation

◆ _GlobalSound()

void _GlobalSound ( entity this,
entity gs,
entity ps,
string sample,
float chan,
float vol,
float voicetype,
bool fake,
float pitchscale )

References entity().

◆ ClearPlayerSounds()

void ClearPlayerSounds ( entity this)

Definition at line 272 of file globalsound.qc.

273 {
274 FOREACH(PlayerSounds, true, {
275 .string fld = it.m_playersoundfld;
276 if (this.(fld))
277 {
278 strfree(this.(fld));
279 }
280 });
281 }
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define strfree(this)
Definition string.qh:59

References entity(), FOREACH, and strfree.

Referenced by UpdatePlayerSounds().

◆ GetPlayerSoundSampleField()

string GetPlayerSoundSampleField ( string type)

Definition at line 267 of file globalsound.qc.

268 {
269 return _GetPlayerSoundSampleField(type, false);
270 }
string _GetPlayerSoundSampleField(string type, bool voice)

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

◆ GetVoiceMessage()

entity GetVoiceMessage ( string type)

Definition at line 216 of file globalsound.qc.

217 {
218 FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it);
219 return NULL;
220 }

References entity(), FOREACH, and NULL.

Referenced by _GetPlayerSoundSampleField(), and ClientCommand_voice().

◆ GetVoiceMessageSampleField()

string GetVoiceMessageSampleField ( string type)

Definition at line 237 of file globalsound.qc.

238 {
239 return _GetPlayerSoundSampleField(type, true);
240 }

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds(), target_speaker_use_activator(), and target_speaker_use_on().

◆ GlobalSound_pitch()

float GlobalSound_pitch ( float _pitch)

Definition at line 184 of file globalsound.qc.

185 {
186 // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b
187 float a = 1.5; // max pitch
188 float b = 0.75; // min pitch
189 float c = 100; // standard pitch (scale * 100)
190 float d = _pitch;
191 float pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b));
192
193 return pitch_shift * 100;
194 }

Referenced by _GlobalSound().

◆ GlobalSound_sample()

string GlobalSound_sample ( string pair,
float r )

Definition at line 170 of file globalsound.qc.

171 {
172 int n;
173 {
174 string s = cdr(pair);
175 if (s) n = stof(s);
176 else n = 0;
177 }
178 string sample = car(pair);
179 if (n > 0) sample = sprintf("%s%d.wav", sample, floor(r * n + 1)); // randomization
180 else sample = sprintf("%s.wav", sample);
181 return sample;
182 }
float stof(string val,...)
float floor(float f)
ERASEABLE string car(string s)
returns first word
Definition string.qh:259
ERASEABLE string cdr(string s)
returns all but first word
Definition string.qh:268

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

Referenced by _GlobalSound(), globalsound(), Monster_Sound(), NET_HANDLE(), NET_HANDLE(), and playersound().

◆ LoadPlayerSounds()

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

Definition at line 283 of file globalsound.qc.

284 {
285 int fh = fopen(f, FILE_READ);
286 if (fh < 0)
287 {
288 if (strict) LOG_WARNF("Player sound file not found: %s", f);
289 return false;
290 }
291 for (string s; (s = fgets(fh)); )
292 {
293 int n = tokenize_console(s);
294 if (n != 3)
295 {
296 if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
297 continue;
298 }
299 string key = argv(0);
300 var .string field = GetPlayerSoundSampleField(key);
303 {
304 LOG_TRACEF("Invalid sound info field in player sound file '%s': %s", f, key);
305 continue;
306 }
307 string file = argv(1);
308 string variants = argv(2);
309 strcpy(this.(field), strcat(file, " ", variants));
310 }
311 fclose(fh);
312 return true;
313 }
const float FILE_READ
#define tokenize_console
string GetVoiceMessageSampleField(string type)
string GetPlayerSoundSampleField(string type)
bool GetPlayerSoundSampleField_notFound
#define LOG_WARNF(...)
Definition log.qh:62
#define LOG_TRACEF(...)
Definition log.qh:77
string fgets(float fhandle)
void fclose(float fhandle)
float fopen(string filename, float mode)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define strcpy(this, s)
Definition string.qh:52

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

Referenced by UpdatePlayerSounds().

◆ PRECACHE()

PRECACHE ( GlobalSounds )

Definition at line 113 of file globalsound.qh.

114{
115 FOREACH(GlobalSounds, true, PrecacheGlobalSound(it.m_globalsoundstr));
116}
void PrecacheGlobalSound(string samplestring)

References FOREACH, and PrecacheGlobalSound().

◆ PrecacheGlobalSound()

void PrecacheGlobalSound ( string samplestring)

Definition at line 196 of file globalsound.qc.

197 {
198 int n;
199 {
200 string s = cdr(sample);
201 if (s) n = stof(s);
202 else n = 0;
203 }
204 sample = car(sample);
205 if (n > 0)
206 {
207 for (int i = 1; i <= n; ++i)
208 precache_sound(sprintf("%s%d.wav", sample, i));
209 }
210 else
211 {
212 precache_sound(sprintf("%s.wav", sample));
213 }
214 }
string precache_sound(string sample)

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

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

◆ PrecachePlayerSounds()

void PrecachePlayerSounds ( string f)

Definition at line 242 of file globalsound.qc.

243 {
244 int fh = fopen(f, FILE_READ);
245 if (fh < 0)
246 {
247 LOG_WARNF("Player sound file not found: %s", f);
248 return;
249 }
250 for (string s; (s = fgets(fh)); )
251 {
252 int n = tokenize_console(s);
253 if (n != 3)
254 {
255 if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
256 continue;
257 }
258 string file = argv(1);
259 string variants = argv(2);
260 PrecacheGlobalSound(strcat(file, " ", variants));
261 }
262 fclose(fh);
263 }
void PrecacheGlobalSound(string sample)

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

Referenced by PRECACHE(), and precache_playermodel().

◆ REPLICATE_INIT() [1/3]

REPLICATE_INIT ( float ,
cvar_cl_autotaunt  )

◆ REPLICATE_INIT() [2/3]

REPLICATE_INIT ( float ,
cvar_cl_voice_directional_taunt_attenuation  )

◆ REPLICATE_INIT() [3/3]

REPLICATE_INIT ( int ,
cvar_cl_voice_directional  )

◆ STATIC_INIT() [1/3]

STATIC_INIT ( allvoicesamples )

Definition at line 160 of file globalsound.qh.

161{
162 FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr));
164}
string allvoicesamples
string substring(string s, float start, float length)
string strzone(string s)

References allvoicesamples, FOREACH, strcat(), strzone(), and substring().

◆ STATIC_INIT() [2/3]

STATIC_INIT ( GlobalSounds_renumber )

Definition at line 107 of file globalsound.qh.

108{
109 FOREACH(GlobalSounds, true, it.m_id = i);
110}

References FOREACH, and STATIC_INIT.

◆ STATIC_INIT() [3/3]

STATIC_INIT ( PlayerSounds_renumber )

Definition at line 35 of file globalsound.qh.

36{
37 FOREACH(PlayerSounds, true, it.m_id = i);
38}

References FOREACH, and STATIC_INIT.

◆ UpdatePlayerSounds()

void UpdatePlayerSounds ( entity this)

Definition at line 320 of file globalsound.qc.

321 {
322 if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return;
324 this.skin_for_playersound = this.skin;
325 ClearPlayerSounds(this);
326 LoadPlayerSounds(this, "sound/player/default.sounds", true);
327 if (this.model == "null"
328 #ifdef SVQC
330 #endif
331 ) return;
333 if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return;
334 LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true);
335 }
string get_model_datafilename(string m, float sk, string fil)
Definition util.qc:1487
float skin
model
Definition ent_cs.qc:139
bool LoadPlayerSounds(entity this, string f, bool strict)
int skin_for_playersound
bool autocvar_g_debug_defaultsounds
void ClearPlayerSounds(entity this)
string model_for_playersound
bool autocvar_g_debug_globalsounds
Use new sound handling.
Definition globalsound.qh:9

References autocvar_g_debug_defaultsounds, autocvar_g_debug_globalsounds, ClearPlayerSounds(), entity(), get_model_datafilename(), LoadPlayerSounds(), model, model_for_playersound, skin, skin_for_playersound, and strcpy.

Referenced by FixPlayermodel(), NET_HANDLE(), and setplayermodel().

Variable Documentation

◆ allvoicesamples

string allvoicesamples

Definition at line 159 of file globalsound.qh.

Referenced by ClientCommand_voice(), and STATIC_INIT().

◆ autocvar_g_debug_globalsounds

bool autocvar_g_debug_globalsounds = false

Use new sound handling.

TODO: use when sounds play correctly on clients

Definition at line 9 of file globalsound.qh.

Referenced by FixPlayermodel(), globalsound(), playersound(), PutObserverInServer(), setplayermodel(), and UpdatePlayerSounds().

◆ autocvar_sv_autotaunt

bool autocvar_sv_autotaunt

Definition at line 11 of file globalsound.qh.

Referenced by _GlobalSound().

◆ autocvar_sv_taunt

bool autocvar_sv_taunt

Definition at line 10 of file globalsound.qh.

Referenced by _GlobalSound().

◆ GetPlayerSoundSampleField_notFound

bool GetPlayerSoundSampleField_notFound

◆ instanceOfVoiceMessage

bool instanceOfVoiceMessage

Definition at line 52 of file globalsound.qh.

◆ m_globalsoundstr

string m_globalsoundstr

Definition at line 96 of file globalsound.qh.

◆ m_playersoundfld

string m_playersoundfld

Definition at line 17 of file globalsound.qh.

◆ m_playersoundstr

string m_playersoundstr

Definition at line 16 of file globalsound.qh.

◆ m_playersoundvt

int m_playersoundvt

Definition at line 53 of file globalsound.qh.

◆ VOICETYPE_AUTOTAUNT

const int VOICETYPE_AUTOTAUNT = 14

Definition at line 68 of file globalsound.qh.

Referenced by _GlobalSound(), and PlayerPreThink().

◆ VOICETYPE_LASTATTACKER

const int VOICETYPE_LASTATTACKER = 12

Definition at line 66 of file globalsound.qh.

Referenced by _GlobalSound().

◆ VOICETYPE_LASTATTACKER_ONLY

const int VOICETYPE_LASTATTACKER_ONLY = 13

Definition at line 67 of file globalsound.qh.

Referenced by _GlobalSound(), and PlayerPreThink().

◆ VOICETYPE_PLAYERSOUND

const int VOICETYPE_PLAYERSOUND = 10

◆ VOICETYPE_TAUNT

const int VOICETYPE_TAUNT = 15

Definition at line 69 of file globalsound.qh.

Referenced by _GlobalSound().

◆ VOICETYPE_TEAMRADIO

const int VOICETYPE_TEAMRADIO = 11

Definition at line 65 of file globalsound.qh.

Referenced by _GlobalSound().