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)
#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)
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)
void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, float vol, int voicetype, bool fake)
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)

Definition at line 142 of file globalsound.qh.

◆ PlayerSound

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

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)
#define PlayerSound(this, def, chan, vol, voicetype)
string m_playersoundfld
string m_playersoundstr

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); \
#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); \
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 )

References entity().

◆ ClearPlayerSounds()

void ClearPlayerSounds ( entity this)

Definition at line 252 of file globalsound.qc.

253 {
254 FOREACH(PlayerSounds, true, {
255 .string fld = it.m_playersoundfld;
256 if (this.(fld))
257 {
258 strfree(this.(fld));
259 }
260 });
261 }
#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 247 of file globalsound.qc.

248 {
249 return _GetPlayerSoundSampleField(type, false);
250 }
string _GetPlayerSoundSampleField(string type, bool voice)

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

◆ GetVoiceMessage()

entity GetVoiceMessage ( string type)

Definition at line 196 of file globalsound.qc.

197 {
198 FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it);
199 return NULL;
200 }

References entity(), FOREACH, and NULL.

Referenced by _GetPlayerSoundSampleField(), and ClientCommand_voice().

◆ GetVoiceMessageSampleField()

string GetVoiceMessageSampleField ( string type)

Definition at line 217 of file globalsound.qc.

218 {
219 return _GetPlayerSoundSampleField(type, true);
220 }

References _GetPlayerSoundSampleField().

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

◆ GlobalSound_pitch()

float GlobalSound_pitch ( float _pitch)

Definition at line 164 of file globalsound.qc.

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 }

Referenced by _GlobalSound().

◆ GlobalSound_sample()

string GlobalSound_sample ( string pair,
float r )

Definition at line 150 of file globalsound.qc.

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 }
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 263 of file globalsound.qc.

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
#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 176 of file globalsound.qc.

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 }
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 222 of file globalsound.qc.

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 }
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 300 of file globalsound.qc.

301 {
302 if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return;
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
310 #endif
311 ) 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:1381
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().